Search in sources :

Example 36 with IFD

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

the class VectraReader method initMetadataStore.

/* @see loci.formats.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    for (int i = 0; i < getSeriesCount(); i++) {
        int coreIndex = seriesToCoreIndex(i);
        store.setImageName(getImageName(coreIndex), i);
        store.setImageDescription("", i);
        int ifdIndex = getIFDIndex(coreIndex, 0);
        IFD ifd = ifds.get(ifdIndex);
        double x = ifd.getXResolution();
        double y = ifd.getYResolution();
        store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(x), i);
        store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(y), i);
    }
    for (int c = 0; c < getSizeC(); c++) {
        String xml = getIFDComment(c);
        try {
            Element root = XMLTools.parseDOM(xml).getDocumentElement();
            NodeList children = root.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                if (!(children.item(i) instanceof Element)) {
                    continue;
                }
                Element e = (Element) children.item(i);
                String name = e.getNodeName();
                String value = e.getTextContent();
                if (name.equals("ScanProfile")) {
                    try {
                        Document profileRoot = XMLTools.createDocument();
                        Node tmp = profileRoot.importNode(e, true);
                        profileRoot.appendChild(tmp);
                        profileXML = XMLTools.getXML(profileRoot);
                        // scan profile XML is usually too long to be saved
                        // when original metadata filtering is enabled, but there
                        // is an API method below to retrieve it
                        addGlobalMeta(name, profileXML);
                    } catch (Exception ex) {
                        LOGGER.debug("Could not preserve scan profile metadata", ex);
                    }
                } else {
                    addGlobalMetaList(name, value);
                }
                if (name.equals("Name")) {
                    if (hasFlattenedResolutions()) {
                        for (int series = 0; series < pyramidDepth; series++) {
                            store.setChannelName(value, series, c);
                        }
                    } else {
                        store.setChannelName(value, 0, c);
                    }
                } else if (name.equals("Color")) {
                    String[] components = value.split(",");
                    Color color = new Color(Integer.parseInt(components[0]), Integer.parseInt(components[1]), Integer.parseInt(components[2]), 255);
                    if (hasFlattenedResolutions()) {
                        for (int series = 0; series < pyramidDepth; series++) {
                            store.setChannelColor(color, series, c);
                        }
                    } else {
                        store.setChannelColor(color, 0, c);
                    }
                } else if (name.equals("Objective") && c == 0) {
                    String instrument = MetadataTools.createLSID("Instrument", 0);
                    String objective = MetadataTools.createLSID("Objective", 0, 0);
                    store.setInstrumentID(instrument, 0);
                    store.setObjectiveID(objective, 0, 0);
                    store.setObjectiveModel(value, 0, 0);
                    try {
                        String mag = value.toLowerCase().replace("x", "");
                        Double magFactor = DataTools.parseDouble(mag);
                        store.setObjectiveNominalMagnification(magFactor, 0, 0);
                    } catch (NumberFormatException ex) {
                        LOGGER.info("Could not determine magnification: {}", value);
                    }
                    for (int series = 0; series < getSeriesCount(); series++) {
                        store.setImageInstrumentRef(instrument, series);
                        store.setObjectiveSettingsID(objective, series);
                    }
                } else if (name.equals("ExposureTime")) {
                    Time exposure = new Time(DataTools.parseDouble(value), UNITS.MICROSECOND);
                    store.setPlaneExposureTime(exposure, 0, c);
                    store.setPlaneTheZ(new NonNegativeInteger(0), 0, c);
                    store.setPlaneTheT(new NonNegativeInteger(0), 0, c);
                    store.setPlaneTheC(new NonNegativeInteger(c), 0, c);
                }
            }
        } catch (ParserConfigurationException | SAXException | IOException e) {
            LOGGER.warn("Could not parse XML for channel {}", c);
            LOGGER.debug("", e);
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Color(ome.xml.model.primitives.Color) Time(ome.units.quantity.Time) IOException(java.io.IOException) Document(org.w3c.dom.Document) FormatException(loci.formats.FormatException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) MetadataStore(loci.formats.meta.MetadataStore) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 37 with IFD

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

the class VectraReader method isThisType.

// -- IFormatReader API methods --
/* (non-Javadoc)
   * @see loci.formats.FormatReader#isThisType(java.lang.String, boolean)
   */
@Override
public boolean isThisType(String name, boolean open) {
    if (!open) {
        return checkSuffix(name, "qptiff");
    }
    try (RandomAccessInputStream stream = new RandomAccessInputStream(name)) {
        TiffParser tiffParser = new TiffParser(stream);
        tiffParser.setDoCaching(false);
        if (!tiffParser.isValidHeader()) {
            return false;
        }
        IFD ifd = tiffParser.getFirstIFD();
        if (ifd == null) {
            return false;
        }
        tiffParser.fillInIFD(ifd);
        String software = ifd.getIFDTextValue(IFD.SOFTWARE);
        return software != null && software.startsWith(SOFTWARE_CHECK);
    } catch (IOException e) {
        LOGGER.debug("I/O exception during isThisType() evaluation.", e);
        return false;
    }
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException)

Example 38 with IFD

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

the class SVSReader method isThisType.

/* (non-Javadoc)
   * @see loci.formats.FormatReader#isThisType(java.lang.String, boolean)
   */
@Override
public boolean isThisType(String name, boolean open) {
    boolean isThisType = super.isThisType(name, open);
    if (!isThisType && open) {
        RandomAccessInputStream stream = null;
        try {
            stream = new RandomAccessInputStream(name);
            TiffParser tiffParser = new TiffParser(stream);
            tiffParser.setDoCaching(false);
            if (!tiffParser.isValidHeader()) {
                return false;
            }
            IFD ifd = tiffParser.getFirstIFD();
            if (ifd == null) {
                return false;
            }
            Object description = ifd.get(IFD.IMAGE_DESCRIPTION);
            if (description != null) {
                String imageDescription = null;
                if (description instanceof TiffIFDEntry) {
                    Object value = tiffParser.getIFDValue((TiffIFDEntry) description);
                    if (value != null) {
                        imageDescription = value.toString();
                    }
                } else if (description instanceof String) {
                    imageDescription = (String) description;
                }
                if (imageDescription != null && imageDescription.startsWith(APERIO_IMAGE_DESCRIPTION_PREFIX)) {
                    return true;
                }
            }
            return false;
        } catch (IOException e) {
            LOGGER.debug("I/O exception during isThisType() evaluation.", e);
            return false;
        } finally {
            try {
                if (stream != null) {
                    stream.close();
                }
            } catch (IOException e) {
                LOGGER.debug("I/O exception during stream closure.", e);
            }
        }
    }
    return isThisType;
}
Also used : TiffIFDEntry(loci.formats.tiff.TiffIFDEntry) IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException)

Example 39 with IFD

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

the class SlidebookTiffReader method isThisType.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    TiffParser tp = new TiffParser(stream);
    IFD ifd = tp.getFirstIFD();
    if (ifd == null)
        return false;
    String software = ifd.getIFDTextValue(IFD.SOFTWARE);
    if (software == null)
        return false;
    return software.equals(SLIDEBOOK_MAGIC_STRING) && ifd.getComment().length() == 0 && (ifd.containsKey(X_POS_TAG) || ifd.containsKey(Y_POS_TAG) || ifd.containsKey(Z_POS_TAG) || ifd.containsKey(CHANNEL_TAG) || ifd.containsKey(PHYSICAL_SIZE_TAG) || ifd.containsKey(MAGNIFICATION_TAG));
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 40 with IFD

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

the class SlidebookTiffReader method getFirstChannel.

private String getFirstChannel(String path) throws FormatException, IOException {
    RandomAccessInputStream s = new RandomAccessInputStream(path);
    TiffParser parser = new TiffParser(s);
    IFD ifd = parser.getFirstIFD();
    Object channel = ifd.getIFDValue(CHANNEL_TAG);
    s.close();
    parser.getStream().close();
    return channel == null ? null : channel.toString();
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

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