Search in sources :

Example 21 with IFD

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

the class PCORAWReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    if (checkSuffix(id, "rec")) {
        paramFile = new Location(id).getAbsolutePath();
        String base = new Location(id).getAbsoluteFile().getAbsolutePath();
        base = base.substring(0, base.lastIndexOf("."));
        id = base + ".pcoraw";
        if (!new Location(id).exists()) {
            throw new FormatException("Could not find image file.");
        }
    }
    super.initFile(id);
    imageFile = new Location(id).getAbsolutePath();
    reader.close();
    reader.setMetadataStore(getMetadataStore());
    reader.setId(id);
    core = reader.getCoreMetadataList();
    metadata = reader.getGlobalMetadata();
    in = new RandomAccessInputStream(id);
    try {
        if (in.length() >= Math.pow(2, 32)) {
            // even though BigTIFF is likely being used, the offsets
            // are still recorded as though only 32 bits are available
            long add = 0;
            long prevOffset = 0;
            for (IFD ifd : reader.ifds) {
                long[] offsets = ifd.getStripOffsets();
                for (int i = 0; i < offsets.length; i++) {
                    offsets[i] += add;
                    if (offsets[i] < prevOffset) {
                        add += 0x100000000L;
                        offsets[i] += 0x100000000L;
                    }
                    prevOffset = offsets[i];
                }
                ifd.put(IFD.STRIP_OFFSETS, offsets);
            }
        }
    } finally {
        in.close();
    }
    if (paramFile == null) {
        String base = imageFile.substring(0, imageFile.lastIndexOf("."));
        base += ".rec";
        if (new Location(base).exists()) {
            paramFile = base;
        }
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    if (paramFile != null) {
        // parse extra metadata from the parameter file
        store.setInstrumentID(MetadataTools.createLSID("Instrument", 0), 0);
        String detector = MetadataTools.createLSID("Detector", 0, 0);
        store.setDetectorID(detector, 0, 0);
        String[] lines = DataTools.readFile(paramFile).split("\n");
        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];
            int sep = line.indexOf(':');
            if (sep < 0) {
                continue;
            }
            String key = line.substring(0, sep).trim();
            String value = line.substring(sep + 1).trim();
            addGlobalMeta(key, value);
            if (key.equals("Exposure / Delay")) {
                // set the exposure time
                String exp = value.substring(0, value.indexOf(' '));
                Double parsedExp = new Double(exp);
                Time exposure = null;
                if (parsedExp != null) {
                    exposure = new Time(parsedExp / 1000, UNITS.SECOND);
                }
                for (int plane = 0; plane < getImageCount(); plane++) {
                    store.setPlaneExposureTime(exposure, 0, plane);
                }
            } else if (key.equals("Camera serial number")) {
                // set the serial number
                store.setDetectorSerialNumber(value, 0, 0);
            } else if (key.equals("Binning horz./vert.")) {
                store.setDetectorSettingsID(detector, 0, 0);
                value = value.charAt(1) + value;
                value = value.substring(0, 3);
                store.setDetectorSettingsBinning(getBinning(value), 0, 0);
            } else if (key.equals("Comment")) {
                final StringBuilder description = new StringBuilder();
                for (int j = i + 1; j < lines.length; j++) {
                    lines[j] = lines[j].trim();
                    if (lines[j].length() > 0) {
                        description.append(lines[j]);
                        description.append(" ");
                    }
                }
                store.setImageDescription(description.toString().trim(), 0);
                break;
            }
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) Time(ome.units.quantity.Time) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 22 with IFD

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

the class PhotoshopTiffReader method isThisType.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    TiffParser tp = new TiffParser(stream);
    tp.setDoCaching(false);
    IFD ifd = tp.getFirstIFD();
    if (ifd == null)
        return false;
    return ifd.containsKey(IMAGE_SOURCE_DATA);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 23 with IFD

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

the class PrairieReader method isThisType.

@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    final int blockLen = (int) Math.min(1048608, stream.length());
    if (!FormatTools.validStream(stream, blockLen, false))
        return false;
    String s = stream.readString(blockLen);
    if (s.indexOf("xml") != -1 && s.indexOf("PV") != -1)
        return true;
    TiffParser tp = new TiffParser(stream);
    IFD ifd = tp.getFirstIFD();
    if (ifd == null)
        return false;
    String software = null;
    try {
        software = ifd.getIFDStringValue(IFD.SOFTWARE);
    } catch (FormatException exc) {
        // no software tag, or tag is wrong type
        return false;
    }
    if (software == null)
        return false;
    // not Prairie software
    if (software.indexOf("Prairie") < 0)
        return false;
    return ifd.containsKey(new Integer(PRAIRIE_TAG_1)) && ifd.containsKey(new Integer(PRAIRIE_TAG_2)) && ifd.containsKey(new Integer(PRAIRIE_TAG_3));
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) FormatException(loci.formats.FormatException)

Example 24 with IFD

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

the class PyramidTiffReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see loci.formats.in.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    int seriesCount = ifds.size();
    // repopulate core metadata
    core.clear();
    for (int s = 0; s < seriesCount; s++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        if (s == 0) {
            ms.resolutionCount = seriesCount;
        }
        IFD ifd = ifds.get(s);
        PhotoInterp p = ifd.getPhotometricInterpretation();
        int samples = ifd.getSamplesPerPixel();
        ms.rgb = samples > 1 || p == PhotoInterp.RGB;
        long numTileRows = ifd.getTilesPerColumn() - 1;
        long numTileCols = ifd.getTilesPerRow() - 1;
        ms.sizeX = (int) ifd.getImageWidth();
        ms.sizeY = (int) ifd.getImageLength();
        ms.sizeZ = 1;
        ms.sizeT = 1;
        ms.sizeC = ms.rgb ? samples : 1;
        ms.littleEndian = ifd.isLittleEndian();
        ms.indexed = p == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
        ms.imageCount = 1;
        ms.pixelType = ifd.getPixelType();
        ms.metadataComplete = true;
        ms.interleaved = false;
        ms.falseColor = false;
        ms.dimensionOrder = "XYCZT";
        ms.thumbnail = s > 0;
    }
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata)

Example 25 with IFD

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

the class IPWReader method getOptimalTileWidth.

/* @see loci.formats.IFormatReader#getOptimalTileWidth() */
@Override
public int getOptimalTileWidth() {
    FormatTools.assertId(currentId, true, 1);
    try {
        RandomAccessInputStream stream = poi.getDocumentStream(imageFiles.get(0));
        TiffParser tp = new TiffParser(stream);
        IFD ifd = tp.getFirstIFD();
        stream.close();
        return (int) ifd.getTileWidth();
    } catch (FormatException e) {
        LOGGER.debug("Could not retrieve tile width", e);
    } catch (IOException e) {
        LOGGER.debug("Could not retrieve tile height", e);
    }
    return super.getOptimalTileWidth();
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException) 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