Search in sources :

Example 41 with IFD

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

the class ExtractFlexMetadata method main.

public static void main(String[] args) throws Exception {
    File dir;
    if (args.length != 1 || !(dir = new File(args[0])).canRead()) {
        System.out.println("Usage: java ExtractFlexMetadata dir");
        return;
    }
    for (File file : dir.listFiles()) {
        if (file.getName().endsWith(".flex")) {
            String id = file.getPath();
            int dot = id.lastIndexOf(".");
            String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".xml";
            RandomAccessInputStream in = new RandomAccessInputStream(id);
            TiffParser parser = new TiffParser(in);
            IFD firstIFD = parser.getIFDs().get(0);
            String xml = firstIFD.getIFDTextValue(FlexReader.FLEX);
            in.close();
            FileWriter writer = new FileWriter(new File(outId));
            writer.write(xml);
            writer.close();
            System.out.println("Writing header of: " + id);
        }
    }
    System.out.println("Done");
}
Also used : IFD(loci.formats.tiff.IFD) FileWriter(java.io.FileWriter) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) File(java.io.File)

Example 42 with IFD

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

the class FV1000Reader 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);
    int nFiles = getSeries() == 0 ? tiffs.size() : previewNames.size();
    int image = no % (getImageCount() / nFiles);
    int file = no / (getImageCount() / nFiles);
    int[] coords = getZCTCoords(image);
    lastChannel = coords[1];
    RandomAccessInputStream plane = getPlane(getSeries(), no);
    if (plane == null)
        return buf;
    TiffParser tp = new TiffParser(plane);
    int index = getSeries() == 0 ? file : tiffs.size() + file;
    IFDList ifdList = ifds.get(index);
    if (image >= ifdList.size())
        return buf;
    IFD ifd = ifdList.get(image);
    if (getSizeY() != ifd.getImageLength()) {
        tp.getSamples(ifd, buf, x, getIndex(coords[0], 0, coords[2]), w, 1);
    } else
        tp.getSamples(ifd, buf, x, y, w, h);
    plane.close();
    plane = null;
    tp = null;
    return buf;
}
Also used : IFD(loci.formats.tiff.IFD) IFDList(loci.formats.tiff.IFDList) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 43 with IFD

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

the class DNGReader 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;
    boolean hasEPSTag = ifd.containsKey(TIFF_EPS_STANDARD);
    if (!hasEPSTag) {
        hasEPSTag = ifd.containsKey(CANON_TAG);
    }
    String make = ifd.getIFDTextValue(IFD.MAKE);
    String model = ifd.getIFDTextValue(IFD.MODEL);
    String software = ifd.getIFDTextValue(IFD.SOFTWARE);
    return make != null && make.indexOf("Canon") != -1 && hasEPSTag && (model == null || !model.endsWith("S1 IS")) && (software == null || software.indexOf("Canon") != -1);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 44 with IFD

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

the class DNGReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    // reset image dimensions
    // the actual image data is stored in IFDs referenced by the SubIFD tag
    // in the 'real' IFD
    CoreMetadata m = core.get(0);
    m.imageCount = ifds.size();
    IFD firstIFD = ifds.get(0);
    PhotoInterp photo = firstIFD.getPhotometricInterpretation();
    int samples = firstIFD.getSamplesPerPixel();
    m.rgb = samples > 1 || photo == PhotoInterp.RGB || photo == PhotoInterp.CFA_ARRAY;
    if (photo == PhotoInterp.CFA_ARRAY)
        samples = 3;
    m.sizeX = (int) firstIFD.getImageWidth();
    m.sizeY = (int) firstIFD.getImageLength();
    m.sizeZ = 1;
    m.sizeC = isRGB() ? samples : 1;
    m.sizeT = ifds.size();
    m.pixelType = FormatTools.UINT16;
    m.indexed = false;
    // now look for the EXIF IFD pointer
    IFDList exifIFDs = tiffParser.getExifIFDs();
    if (exifIFDs.size() > 0) {
        IFD exifIFD = exifIFDs.get(0);
        tiffParser.fillInIFD(exifIFD);
        for (Integer key : exifIFD.keySet()) {
            int tag = key.intValue();
            String name = IFD.getIFDTagName(tag);
            if (tag == IFD.CFA_PATTERN) {
                byte[] cfa = (byte[]) exifIFD.get(key);
                int[] colorMap = new int[cfa.length];
                for (int i = 0; i < cfa.length; i++) colorMap[i] = (int) cfa[i];
                addGlobalMeta(name, colorMap);
                cfaPattern = colorMap;
            } else {
                addGlobalMeta(name, exifIFD.get(key));
                if (name.equals("MAKER_NOTE")) {
                    byte[] b = (byte[]) exifIFD.get(key);
                    int offset = DataTools.bytesToInt(b, b.length - 4, isLittleEndian());
                    byte[] buf = new byte[b.length + offset - 8];
                    System.arraycopy(b, b.length - 8, buf, 0, 8);
                    System.arraycopy(b, 0, buf, offset, b.length - 8);
                    RandomAccessInputStream makerNote = new RandomAccessInputStream(buf);
                    TiffParser tp = new TiffParser(makerNote);
                    IFD note = null;
                    try {
                        note = tp.getFirstIFD();
                    } catch (Exception e) {
                        LOGGER.debug("Failed to parse first IFD", e);
                    }
                    if (note != null) {
                        for (Integer nextKey : note.keySet()) {
                            int nextTag = nextKey.intValue();
                            addGlobalMeta(name, note.get(nextKey));
                            if (nextTag == WHITE_BALANCE_RGB_COEFFS) {
                                if (note.get(nextTag) instanceof TiffRational[]) {
                                    TiffRational[] wb = (TiffRational[]) note.get(nextTag);
                                    whiteBalance = new double[wb.length];
                                    for (int i = 0; i < wb.length; i++) {
                                        whiteBalance[i] = wb[i].doubleValue();
                                    }
                                } else {
                                    // use a default white balance table
                                    whiteBalance = new double[3];
                                    whiteBalance[0] = 2.391381;
                                    whiteBalance[1] = 0.929156;
                                    whiteBalance[2] = 1.298254;
                                }
                            }
                        }
                    }
                    makerNote.close();
                }
            }
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) TiffRational(loci.formats.tiff.TiffRational) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) IOException(java.io.IOException) IFDList(loci.formats.tiff.IFDList) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 45 with IFD

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

the class APLReader 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 (parser == null) {
        parser = new TiffParser[getSeriesCount()];
    }
    if (parser[getSeries()] == null) {
        parser[getSeries()] = new TiffParser(tiffFiles[getSeries()]);
        parser[getSeries()].setDoCaching(false);
    }
    IFD ifd = ifds[getSeries()].get(no);
    return parser[getSeries()].getSamples(ifd, buf, x, y, w, h);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

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