Search in sources :

Example 11 with TiffParser

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

the class PCIReader method getOptimalTileHeight.

/* @see loci.formats.IFormatReader#getOptimalTileHeight() */
@Override
public int getOptimalTileHeight() {
    FormatTools.assertId(currentId, true, 1);
    String file = imageFiles.get(0);
    try {
        if (poi == null) {
            initPOIService();
        }
        RandomAccessInputStream s = poi.getDocumentStream(file);
        TiffParser tp = new TiffParser(s);
        if (tp.isValidHeader()) {
            IFD ifd = tp.getFirstIFD();
            s.close();
            return (int) ifd.getTileLength();
        }
        s.close();
    } catch (FormatException e) {
        LOGGER.debug("Could not retrieve tile height", e);
    } catch (IOException e) {
        LOGGER.debug("Could not retrieve tile height", e);
    }
    return super.getOptimalTileHeight();
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException) FormatException(loci.formats.FormatException)

Example 12 with TiffParser

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

the class LEOReader 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;
    return ifd.containsKey(LEO_TAG);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 13 with TiffParser

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

the class MIASReader method isThisType.

/* @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;
    Object s = ifd.getIFDValue(IFD.SOFTWARE);
    if (s == null)
        return false;
    String software = null;
    if (s instanceof String[])
        software = ((String[]) s)[0];
    else
        software = s.toString();
    return software.startsWith("eaZYX") || software.startsWith("SCIL_Image") || software.startsWith("IDL");
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 14 with TiffParser

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

the class FEITiffReader 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;
    return ifd.containsKey(SFEG_TAG) || ifd.containsKey(HELIOS_TAG) || ifd.containsKey(TITAN_TAG);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 15 with TiffParser

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

the class FlexReader method parseFlexFile.

/**
 * Parses XML metadata from the Flex file corresponding to the given well.
 * If the 'firstFile' flag is set, then the core metadata is also
 * populated.
 */
private void parseFlexFile(int currentWell, int wellRow, int wellCol, int field, boolean firstFile, MetadataStore store) throws FormatException, IOException {
    LOGGER.info("Parsing .flex file (well {}{}, field {})", (char) (wellRow + 'A'), wellCol + 1, field);
    FlexFile file = lookupFile(wellRow, wellCol, field < 0 ? 0 : field);
    if (file == null)
        return;
    int originalFieldCount = fieldCount;
    if (xPositions == null)
        xPositions = new ArrayList<Double>();
    if (yPositions == null)
        yPositions = new ArrayList<Double>();
    if (xSizes == null)
        xSizes = new ArrayList<Double>();
    if (ySizes == null)
        ySizes = new ArrayList<Double>();
    if (cameraIDs == null)
        cameraIDs = new ArrayList<String>();
    if (lightSourceIDs == null)
        lightSourceIDs = new ArrayList<String>();
    if (objectiveIDs == null)
        objectiveIDs = new ArrayList<String>();
    if (lightSourceCombinationIDs == null) {
        lightSourceCombinationIDs = new HashMap<String, List<String>>();
    }
    if (lightSourceCombinationRefs == null) {
        lightSourceCombinationRefs = new ArrayList<String>();
    }
    if (cameraRefs == null)
        cameraRefs = new ArrayList<String>();
    if (objectiveRefs == null)
        objectiveRefs = new ArrayList<String>();
    if (binnings == null)
        binnings = new ArrayList<String>();
    if (filterSets == null)
        filterSets = new ArrayList<String>();
    if (filterSetMap == null)
        filterSetMap = new HashMap<String, FilterGroup>();
    // parse factors from XML
    LOGGER.debug("Parsing XML from {}", file.file);
    int nOffsets = file.offsets != null ? file.offsets.length : 0;
    IFD ifd = null;
    if (nOffsets == 0) {
        ifd = file.ifds.get(0);
    } else {
        RandomAccessInputStream ras = new RandomAccessInputStream(file.file);
        try {
            TiffParser parser = new TiffParser(ras);
            ifd = parser.getFirstIFD();
        } finally {
            ras.close();
        }
    }
    String xml = XMLTools.sanitizeXML(ifd.getIFDStringValue(FLEX));
    final List<String> n = new ArrayList<String>();
    final List<String> f = new ArrayList<String>();
    DefaultHandler handler = new FlexHandler(n, f, store, firstFile, currentWell, field);
    LOGGER.info("Parsing XML in .flex file");
    xml = xml.trim();
    // some files have a trailing ">" or "%", which needs to be removed
    if (xml.endsWith(">>") || xml.endsWith("%")) {
        xml = xml.substring(0, xml.length() - 1);
    }
    XMLTools.parseXML(xml.getBytes(Constants.ENCODING), handler);
    channelNames = n.toArray(new String[n.size()]);
    if (firstFile) {
        populateCoreMetadata(wellRow, wellCol, field < 0 ? 0 : field, n);
    }
    int totalPlanes = getSeriesCount() * getImageCount();
    LOGGER.info("Populating pixel scaling factors");
    // verify factor count
    int nsize = n.size();
    int fsize = f.size();
    if (nsize != fsize || nsize != totalPlanes) {
        LOGGER.warn("mismatch between image count, names and factors " + "(count={}, names={}, factors={})", new Object[] { totalPlanes, nsize, fsize });
    }
    if (firstFile) {
        for (String ns : n) {
            addGlobalMetaList("Name", ns);
        }
        for (String fs : f) {
            addGlobalMetaList("Factor", fs);
        }
    }
    // parse factor values
    file.factors = new double[totalPlanes];
    int max = 0;
    boolean oneFactors = true;
    for (int i = 0; i < fsize; i++) {
        String factor = f.get(i);
        double q = 1;
        try {
            q = Double.parseDouble(factor);
        } catch (NumberFormatException exc) {
            LOGGER.warn("invalid factor #{}: {}", i, factor);
        }
        if (i < file.factors.length) {
            file.factors[i] = q;
            if (q > file.factors[max])
                max = i;
            if (oneFactors && q != 1d) {
                oneFactors = false;
            }
        }
    }
    if (fsize < file.factors.length) {
        Arrays.fill(file.factors, fsize, file.factors.length, 1);
    }
    // determine pixel type
    if (file.factors[max] > 256) {
        core.get(0).pixelType = FormatTools.UINT32;
    } else if (file.factors[max] > 1) {
        core.get(0).pixelType = FormatTools.UINT16;
    }
    for (int i = 1; i < core.size(); i++) {
        core.get(i).pixelType = getPixelType();
    }
    if (!firstFile) {
        fieldCount = originalFieldCount;
    }
    if (oneFactors) {
        file.factors = null;
    }
}
Also used : HashMap(java.util.HashMap) IFD(loci.formats.tiff.IFD) ArrayList(java.util.ArrayList) DefaultHandler(org.xml.sax.helpers.DefaultHandler) ArrayList(java.util.ArrayList) IFDList(loci.formats.tiff.IFDList) List(java.util.List) 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