Search in sources :

Example 46 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class LociFunctions method getSeriesName.

public void getSeriesName(String[] seriesName) {
    MetadataRetrieve retrieve = (MetadataRetrieve) r.getMetadataStore();
    seriesName[0] = retrieve.getImageName(r.getSeries());
}
Also used : MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 47 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class APNGWriter method saveBytes.

// -- IFormatWriter API methods --
/**
 * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int)
 */
@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    checkParams(no, buf, x, y, w, h);
    if (!isFullPlane(x, y, w, h)) {
        throw new FormatException("APNGWriter does not yet support saving image tiles.");
    }
    MetadataRetrieve meta = getMetadataRetrieve();
    int width = meta.getPixelsSizeX(series).getValue().intValue();
    int height = meta.getPixelsSizeY(series).getValue().intValue();
    out.seek(footerPointer);
    if (!initialized[series][no]) {
        writeFCTL(width, height);
        if (numFrames == 0)
            writePLTE();
        initialized[series][no] = true;
    }
    writePixels(numFrames == 0 ? "IDAT" : "fdAT", buf, x, y, w, h);
    numFrames++;
    writeFooter();
}
Also used : MetadataRetrieve(loci.formats.meta.MetadataRetrieve) FormatException(loci.formats.FormatException)

Example 48 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class APNGWriter method writePixels.

private void writePixels(String chunk, byte[] stream, int x, int y, int width, int height) throws FormatException, IOException {
    MetadataRetrieve r = getMetadataRetrieve();
    int sizeC = getSamplesPerPixel();
    String type = r.getPixelsType(series).toString();
    int pixelType = FormatTools.pixelTypeFromString(type);
    boolean signed = FormatTools.isSigned(pixelType);
    if (!isFullPlane(x, y, width, height)) {
        throw new FormatException("APNGWriter does not support writing tiles.");
    }
    ByteArrayOutputStream s = new ByteArrayOutputStream();
    s.write(chunk.getBytes(Constants.ENCODING));
    if (chunk.equals("fdAT")) {
        s.write(DataTools.intToBytes(nextSequenceNumber++, false));
    }
    DeflaterOutputStream deflater = new DeflaterOutputStream(s);
    int planeSize = stream.length / sizeC;
    int rowLen = stream.length / height;
    int bytesPerPixel = stream.length / (width * height * sizeC);
    byte[] rowBuf = new byte[rowLen];
    for (int i = 0; i < height; i++) {
        deflater.write(0);
        if (interleaved) {
            if (littleEndian) {
                for (int col = 0; col < width * sizeC; col++) {
                    int offset = (i * sizeC * width + col) * bytesPerPixel;
                    int pixel = DataTools.bytesToInt(stream, offset, bytesPerPixel, littleEndian);
                    DataTools.unpackBytes(pixel, rowBuf, col * bytesPerPixel, bytesPerPixel, false);
                }
            } else
                System.arraycopy(stream, i * rowLen, rowBuf, 0, rowLen);
        } else {
            int max = (int) Math.pow(2, bytesPerPixel * 8 - 1);
            for (int col = 0; col < width; col++) {
                for (int c = 0; c < sizeC; c++) {
                    int offset = c * planeSize + (i * width + col) * bytesPerPixel;
                    int pixel = DataTools.bytesToInt(stream, offset, bytesPerPixel, littleEndian);
                    if (signed) {
                        if (pixel < max)
                            pixel += max;
                        else
                            pixel -= max;
                    }
                    int output = (col * sizeC + c) * bytesPerPixel;
                    DataTools.unpackBytes(pixel, rowBuf, output, bytesPerPixel, false);
                }
            }
        }
        deflater.write(rowBuf);
    }
    deflater.finish();
    byte[] b = s.toByteArray();
    // write chunk length
    out.writeInt(b.length - 4);
    out.write(b);
    // write checksum
    out.writeInt(crc(b));
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) FormatException(loci.formats.FormatException)

Example 49 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class EPSWriter method saveBytes.

// -- IFormatWriter API methods --
/**
 * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int)
 */
@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    checkParams(no, buf, x, y, w, h);
    MetadataRetrieve meta = getMetadataRetrieve();
    int sizeX = meta.getPixelsSizeX(series).getValue().intValue();
    int nChannels = getSamplesPerPixel();
    if (!initialized[series][no]) {
        initialized[series][no] = true;
        writeHeader();
        if (!isFullPlane(x, y, w, h)) {
            // write a dummy plane that will be overwritten in sections
            int planeSize = w * h * nChannels;
            for (int i = 0; i < planeSize; i++) {
                out.writeBytes(DUMMY_PIXEL);
            }
        }
    }
    int planeSize = w * h;
    final StringBuilder buffer = new StringBuilder();
    int offset = y * sizeX * nChannels * 2;
    out.seek(planeOffset + offset);
    for (int row = 0; row < h; row++) {
        out.skipBytes(nChannels * x * 2);
        for (int col = 0; col < w * nChannels; col++) {
            int i = row * w * nChannels + col;
            int index = interleaved || nChannels == 1 ? i : (i % nChannels) * planeSize + (i / nChannels);
            String s = Integer.toHexString(buf[index]);
            // only want last 2 characters of s
            if (s.length() > 1)
                buffer.append(s.substring(s.length() - 2));
            else {
                buffer.append("0");
                buffer.append(s);
            }
        }
        out.writeBytes(buffer.toString());
        buffer.delete(0, buffer.length());
        out.skipBytes(nChannels * (sizeX - w - x) * 2);
    }
    // write footer
    out.seek(out.length());
    out.writeBytes("\nshowpage\n");
}
Also used : MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 50 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class ImageIOWriter method saveBytes.

// -- IFormatWriter API methods --
/**
 * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int)
 */
@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    checkParams(no, buf, x, y, w, h);
    MetadataRetrieve meta = getMetadataRetrieve();
    BufferedImage image = AWTImageTools.makeImage(buf, interleaved, meta, series);
    savePlane(no, image, x, y, w, h);
}
Also used : MetadataRetrieve(loci.formats.meta.MetadataRetrieve) BufferedImage(java.awt.image.BufferedImage)

Aggregations

MetadataRetrieve (loci.formats.meta.MetadataRetrieve)64 FormatException (loci.formats.FormatException)11 MetadataStore (loci.formats.meta.MetadataStore)11 Length (ome.units.quantity.Length)10 ServiceFactory (loci.common.services.ServiceFactory)8 DependencyException (loci.common.services.DependencyException)7 OMEXMLService (loci.formats.services.OMEXMLService)6 RandomAccessInputStream (loci.common.RandomAccessInputStream)5 Time (ome.units.quantity.Time)5 PositiveInteger (ome.xml.model.primitives.PositiveInteger)5 ServiceException (loci.common.services.ServiceException)4 MissingLibraryException (loci.formats.MissingLibraryException)4 Test (org.testng.annotations.Test)4 IndexColorModel (java.awt.image.IndexColorModel)3 Location (loci.common.Location)3 RandomAccessOutputStream (loci.common.RandomAccessOutputStream)3 ImageReader (loci.formats.ImageReader)3 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2