Search in sources :

Example 31 with TiffParser

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

the class TrestleReader method isThisType.

/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    TiffParser parser = new TiffParser(stream);
    IFD ifd = parser.getFirstIFD();
    if (ifd == null)
        return false;
    String copyright = ifd.getIFDTextValue(IFD.COPYRIGHT);
    if (copyright == null)
        return false;
    return copyright.indexOf("Trestle Corp.") >= 0;
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 32 with TiffParser

use of loci.formats.tiff.TiffParser 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 33 with TiffParser

use of loci.formats.tiff.TiffParser 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 34 with TiffParser

use of loci.formats.tiff.TiffParser 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 35 with TiffParser

use of loci.formats.tiff.TiffParser 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

TiffParser (loci.formats.tiff.TiffParser)96 IFD (loci.formats.tiff.IFD)74 RandomAccessInputStream (loci.common.RandomAccessInputStream)56 FormatException (loci.formats.FormatException)26 CoreMetadata (loci.formats.CoreMetadata)19 IOException (java.io.IOException)18 IFDList (loci.formats.tiff.IFDList)16 Location (loci.common.Location)15 MetadataStore (loci.formats.meta.MetadataStore)15 ArrayList (java.util.ArrayList)12 Timestamp (ome.xml.model.primitives.Timestamp)9 Length (ome.units.quantity.Length)8 PhotoInterp (loci.formats.tiff.PhotoInterp)6 File (java.io.File)5 HashMap (java.util.HashMap)5 ServiceException (loci.common.services.ServiceException)4 Time (ome.units.quantity.Time)4 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)4 List (java.util.List)3 ByteArrayHandle (loci.common.ByteArrayHandle)3