Search in sources :

Example 26 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class IPWReader method get8BitLookupTable.

/* @see loci.formats.IFormatReader#get8BitLookupTable() */
@Override
public byte[][] get8BitLookupTable() throws FormatException, IOException {
    FormatTools.assertId(currentId, true, 1);
    RandomAccessInputStream stream = poi.getDocumentStream(imageFiles.get(0));
    TiffParser tp = new TiffParser(stream);
    IFD firstIFD = tp.getFirstIFD();
    int[] bits = firstIFD.getBitsPerSample();
    if (bits[0] <= 8) {
        int[] colorMap = tp.getColorMap(firstIFD);
        if (colorMap == null) {
            return null;
        }
        byte[][] table = new byte[3][colorMap.length / 3];
        int next = 0;
        for (int j = 0; j < table.length; j++) {
            for (int i = 0; i < table[0].length; i++) {
                table[j][i] = (byte) (colorMap[next++] >> 8);
            }
        }
        return table;
    }
    return null;
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 27 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class IPWReader method openBytes.

/**
 * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
 */
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    if (poi == null) {
        initPOIService();
    }
    RandomAccessInputStream stream = poi.getDocumentStream(imageFiles.get(no));
    TiffParser tp = new TiffParser(stream);
    IFD ifd = tp.getFirstIFD();
    tp.getSamples(ifd, buf, x, y, w, h);
    stream.close();
    return buf;
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 28 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class SEQReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    CoreMetadata m = core.get(0);
    m.sizeZ = 0;
    m.sizeT = 0;
    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    for (IFD ifd : ifds) {
        if (level != MetadataLevel.MINIMUM) {
            short[] tag1 = (short[]) ifd.getIFDValue(IMAGE_PRO_TAG_1);
            if (tag1 != null) {
                StringBuilder seqId = new StringBuilder();
                for (int i = 0; i < tag1.length; i++) {
                    seqId.append(tag1[i]);
                }
                addGlobalMeta("Image-Pro SEQ ID", seqId.toString());
            }
        }
        int tag2 = ifds.get(0).getIFDIntValue(IMAGE_PRO_TAG_2);
        if (tag2 != -1) {
            // should be one of these for every image plane
            m.sizeZ++;
            addGlobalMeta("Frame Rate", tag2);
        }
        addGlobalMeta("Number of images", getSizeZ());
    }
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (getSizeT() == 0)
        m.sizeT = 1;
    if (getSizeZ() == 1 && getSizeT() == 1) {
        m.sizeZ = ifds.size();
    }
    // default values
    addGlobalMeta("frames", getSizeZ());
    addGlobalMeta("channels", super.getSizeC());
    addGlobalMeta("slices", getSizeT());
    // parse the description to get channels, slices and times where applicable
    String descr = ifds.get(0).getComment();
    metadata.remove("Comment");
    if (descr != null) {
        String[] lines = descr.split("\n");
        for (String token : lines) {
            token = token.trim();
            int eq = token.indexOf('=');
            if (eq == -1)
                eq = token.indexOf(':');
            if (eq != -1) {
                String label = token.substring(0, eq);
                String data = token.substring(eq + 1);
                addGlobalMeta(label, data);
                if (label.equals("channels"))
                    m.sizeC = Integer.parseInt(data);
                else if (label.equals("frames")) {
                    m.sizeT = Integer.parseInt(data);
                } else if (label.equals("slices")) {
                    m.sizeZ = Integer.parseInt(data);
                }
            }
        }
    }
    if (isRGB() && getSizeC() != 3)
        m.sizeC *= 3;
    m.dimensionOrder = "XY";
    int maxNdx = 0, max = 0;
    int[] dims = { getSizeZ(), getSizeC(), getSizeT() };
    String[] axes = { "Z", "C", "T" };
    for (int i = 0; i < dims.length; i++) {
        if (dims[i] > max) {
            max = dims[i];
            maxNdx = i;
        }
    }
    m.dimensionOrder += axes[maxNdx];
    if (maxNdx != 1) {
        if (getSizeC() > 1) {
            m.dimensionOrder += 'C';
            m.dimensionOrder += (maxNdx == 0 ? axes[2] : axes[0]);
        } else
            m.dimensionOrder += (maxNdx == 0 ? axes[2] : axes[0]) + "C";
    } else {
        if (getSizeZ() > getSizeT())
            m.dimensionOrder += "ZT";
        else
            m.dimensionOrder += "TZ";
    }
}
Also used : IFD(loci.formats.tiff.IFD) CoreMetadata(loci.formats.CoreMetadata)

Example 29 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class SEQReader method isThisType.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    TiffParser parser = new TiffParser(stream);
    parser.setDoCaching(false);
    IFD ifd = parser.getFirstIFD();
    if (ifd == null)
        return false;
    parser.fillInIFD(ifd);
    Object tag1 = ifd.get(IMAGE_PRO_TAG_1);
    Object tag3 = ifd.get(IMAGE_PRO_TAG_3);
    return (tag1 != null && (tag1 instanceof short[])) || (tag3 != null && (tag3 instanceof int[]));
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 30 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class EPSReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    CoreMetadata m = core.get(0);
    LOGGER.info("Verifying EPS format");
    String line = readLine();
    if (!line.trim().startsWith("%!PS")) {
        // read the TIFF preview
        isTiff = true;
        in.order(true);
        in.seek(20);
        int offset = in.readInt();
        int len = in.readInt();
        byte[] b = new byte[len];
        in.seek(offset);
        in.read(b);
        in = new RandomAccessInputStream(b);
        TiffParser tp = new TiffParser(in);
        ifds = tp.getIFDs();
        IFD firstIFD = ifds.get(0);
        map = tp.getColorMap(firstIFD);
        m.sizeX = (int) firstIFD.getImageWidth();
        m.sizeY = (int) firstIFD.getImageLength();
        m.sizeZ = 1;
        m.sizeT = 1;
        m.sizeC = firstIFD.getSamplesPerPixel();
        if (map != null && getSizeC() == 1) {
            m.sizeC = 3;
        }
        if (getSizeC() == 2)
            m.sizeC = 4;
        m.littleEndian = firstIFD.isLittleEndian();
        m.interleaved = true;
        m.rgb = getSizeC() > 1;
        m.pixelType = firstIFD.getPixelType();
        m.imageCount = 1;
        m.dimensionOrder = "XYCZT";
        m.metadataComplete = true;
        m.indexed = false;
        m.falseColor = false;
        MetadataStore store = makeFilterMetadata();
        MetadataTools.populatePixels(store, this);
        return;
    }
    LOGGER.info("Finding image data");
    binary = false;
    String image = "image";
    int lineNum = 1;
    line = readLine().trim();
    while (line != null && !line.equals("%%EOF")) {
        if (line.endsWith(image)) {
            if (!line.startsWith(image)) {
                if (line.indexOf("colorimage") != -1)
                    m.sizeC = 3;
                String[] t = line.split(" ");
                try {
                    int newX = Integer.parseInt(t[0]);
                    int newY = Integer.parseInt(t[1]);
                    if (t.length > 2 && Integer.parseInt(t[2]) >= 8) {
                        m.sizeX = newX;
                        m.sizeY = newY;
                        start = lineNum;
                    }
                } catch (NumberFormatException exc) {
                    LOGGER.debug("Could not parse image dimensions", exc);
                    if (t.length > 3) {
                        m.sizeC = Integer.parseInt(t[3]);
                    }
                }
            }
            break;
        } else if (line.startsWith("%%")) {
            if (line.startsWith("%%BoundingBox:")) {
                line = line.substring(14).trim();
                String[] t = line.split(" ");
                try {
                    int originX = Integer.parseInt(t[0].trim());
                    int originY = Integer.parseInt(t[1].trim());
                    m.sizeX = Integer.parseInt(t[2].trim()) - originX;
                    m.sizeY = Integer.parseInt(t[3].trim()) - originY;
                    addGlobalMeta("X-coordinate of origin", originX);
                    addGlobalMeta("Y-coordinate of origin", originY);
                } catch (NumberFormatException e) {
                    throw new FormatException("Files without image data are not supported.");
                }
            } else if (line.startsWith("%%BeginBinary")) {
                binary = true;
            } else {
                // parse key/value pairs
                int ndx = line.indexOf(':');
                if (ndx != -1) {
                    String key = line.substring(0, ndx);
                    String value = line.substring(ndx + 1);
                    addGlobalMeta(key, value);
                }
            }
        } else if (line.startsWith("%ImageData:")) {
            line = line.substring(11);
            String[] t = line.split(" ");
            m.sizeX = Integer.parseInt(t[0]);
            m.sizeY = Integer.parseInt(t[1]);
            m.sizeC = Integer.parseInt(t[3]);
            for (int i = 4; i < t.length; i++) {
                image = t[i].trim();
                if (image.length() > 1) {
                    image = image.substring(1, image.length() - 1);
                }
            }
        }
        lineNum++;
        line = readLine().trim();
    }
    LOGGER.info("Populating metadata");
    if (getSizeC() == 0)
        m.sizeC = 1;
    m.sizeZ = 1;
    m.sizeT = 1;
    m.dimensionOrder = "XYCZT";
    m.pixelType = FormatTools.UINT8;
    m.rgb = getSizeC() == 3;
    m.interleaved = true;
    m.littleEndian = true;
    m.imageCount = 1;
    // Populate metadata store
    // The metadata store we're working with.
    MetadataStore store = getMetadataStore();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Aggregations

IFD (loci.formats.tiff.IFD)121 TiffParser (loci.formats.tiff.TiffParser)74 RandomAccessInputStream (loci.common.RandomAccessInputStream)51 CoreMetadata (loci.formats.CoreMetadata)33 FormatException (loci.formats.FormatException)32 MetadataStore (loci.formats.meta.MetadataStore)21 IFDList (loci.formats.tiff.IFDList)21 PhotoInterp (loci.formats.tiff.PhotoInterp)18 IOException (java.io.IOException)17 Location (loci.common.Location)15 ArrayList (java.util.ArrayList)14 Timestamp (ome.xml.model.primitives.Timestamp)11 Length (ome.units.quantity.Length)10 Time (ome.units.quantity.Time)8 TiffIFDEntry (loci.formats.tiff.TiffIFDEntry)7 TiffRational (loci.formats.tiff.TiffRational)6 File (java.io.File)5 TiffReader (loci.formats.in.TiffReader)5 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)5 PositiveInteger (ome.xml.model.primitives.PositiveInteger)5