Search in sources :

Example 66 with CoreMetadata

use of loci.formats.CoreMetadata in project bioformats by openmicroscopy.

the class VGSAMReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    CoreMetadata m = core.get(0);
    in.seek(348);
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    in.skipBytes(4);
    int bpp = in.readInt();
    addGlobalMeta("Bytes per pixel", bpp);
    m.pixelType = FormatTools.pixelTypeFromBytes(bpp, false, bpp == 4);
    m.littleEndian = false;
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = 1;
    m.rgb = false;
    m.interleaved = false;
    m.dimensionOrder = "XYZCT";
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Example 67 with CoreMetadata

use of loci.formats.CoreMetadata in project bioformats by openmicroscopy.

the class VectraReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see loci.formats.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    ifds = tiffParser.getIFDs();
    thumbnailIFDs = null;
    for (IFD ifd : ifds) {
        tiffParser.fillInIFD(ifd);
    }
    // count number of channels
    CoreMetadata m = core.get(0);
    m.sizeC = 1;
    if (ifds.get(0).getSamplesPerPixel() == 1) {
        long width = ifds.get(0).getImageWidth();
        long height = ifds.get(0).getImageLength();
        int ifd = 1;
        while (ifds.get(ifd).getImageWidth() == width && ifds.get(ifd).getImageLength() == height) {
            m.sizeC++;
            ifd++;
        }
    }
    for (int start = m.sizeC + 1; start < ifds.size(); start += m.sizeC) {
        IFD ifd = ifds.get(start);
        if (ifd.getIFDIntValue(IFD.NEW_SUBFILE_TYPE) == 1) {
            pyramidDepth++;
        } else
            break;
    }
    int coreSize = ifds.size() - (pyramidDepth * (m.sizeC - 1));
    // repopulate core metadata
    core.clear();
    for (int s = 0; s < coreSize; s++) {
        CoreMetadata ms = new CoreMetadata(m);
        if (s == 0) {
            ms.resolutionCount = pyramidDepth;
        }
        core.add(ms);
    }
    for (int s = 0; s < core.size(); s++) {
        CoreMetadata ms = core.get(s);
        int index = getIFDIndex(s, 0);
        IFD ifd = ifds.get(index);
        PhotoInterp p = ifd.getPhotometricInterpretation();
        int samples = ifd.getSamplesPerPixel();
        ms.rgb = samples > 1 || p == PhotoInterp.RGB;
        ms.sizeX = (int) ifd.getImageWidth();
        ms.sizeY = (int) ifd.getImageLength();
        ms.sizeZ = 1;
        ms.sizeT = 1;
        if (ms.rgb) {
            ms.sizeC = samples;
        }
        ms.littleEndian = ifd.isLittleEndian();
        ms.indexed = p == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
        ms.imageCount = ms.sizeC / samples;
        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 68 with CoreMetadata

use of loci.formats.CoreMetadata in project bioformats by openmicroscopy.

the class VarianFDFReader method parseFDF.

// -- Helper methods --
private void parseFDF(String file) throws FormatException, IOException {
    in = new RandomAccessInputStream(file);
    CoreMetadata m = core.get(0);
    boolean storedFloats = false;
    boolean multifile = false;
    String data = in.readString(Character.toString((char) 0x0c));
    String[] lines = data.split("\n");
    for (String line : lines) {
        line = line.trim();
        if (line.length() == 0)
            break;
        if (line.startsWith("#"))
            continue;
        int space = line.indexOf(' ');
        int eq = line.indexOf('=');
        String type = line.substring(0, space).trim();
        String var = line.substring(space, eq).trim();
        String value = line.substring(eq + 1, line.indexOf(';')).trim();
        if (var.equals("*storage")) {
            storedFloats = value.equals("\"float\"");
        }
        if (var.equals("bits")) {
            m.bitsPerPixel = Integer.parseInt(value);
            if (value.equals("8")) {
                m.pixelType = FormatTools.UINT8;
            } else if (value.equals("16")) {
                m.pixelType = FormatTools.UINT16;
            } else if (value.equals("32")) {
                if (storedFloats) {
                    m.pixelType = FormatTools.FLOAT;
                } else
                    m.pixelType = FormatTools.UINT32;
            } else
                throw new FormatException("Unsupported bits: " + value);
        } else if (var.equals("matrix[]")) {
            String[] values = parseArray(value);
            m.sizeX = (int) Double.parseDouble(values[0]);
            m.sizeY = (int) Double.parseDouble(values[1]);
            if (values.length > 2) {
                m.sizeZ = (int) Double.parseDouble(values[2]);
            }
        } else if (var.equals("slices")) {
            m.sizeZ = Integer.parseInt(value);
            multifile = true;
        } else if (var.equals("echoes")) {
            m.sizeT = Integer.parseInt(value);
            multifile = true;
        } else if (var.equals("span[]")) {
            String[] values = parseArray(value);
            if (values.length > 0) {
                pixelSizeX = computePhysicalSize(getSizeX(), values[0], units[0]);
            }
            if (values.length > 1) {
                pixelSizeY = computePhysicalSize(getSizeY(), values[1], units[1]);
            }
            if (values.length > 2) {
                pixelSizeZ = computePhysicalSize(getSizeZ(), values[2], units[2]);
            }
        } else if (var.equals("origin[]")) {
            String[] values = parseArray(value);
            if (values.length > 0) {
                final double size = computePhysicalSize(1, values[0], units[0]);
                originX = new Length(size, UNITS.REFERENCEFRAME);
                addGlobalMeta("X position for position #1", originX);
            }
            if (values.length > 1) {
                final double size = computePhysicalSize(1, values[1], units[1]);
                originY = new Length(size, UNITS.REFERENCEFRAME);
                addGlobalMeta("Y position for position #1", originY);
            }
            if (values.length > 2) {
                final double size = computePhysicalSize(1, values[2], units[2]);
                originZ = new Length(size, UNITS.REFERENCEFRAME);
                addGlobalMeta("Z position for position #1", originZ);
            }
        } else if (var.equals("*abscissa[]")) {
            units = parseArray(value);
        } else if (var.equals("bigendian")) {
            m.littleEndian = value.equals("0");
            in.order(isLittleEndian());
        }
        addGlobalMeta(var, value);
    }
    if (multifile && files.isEmpty()) {
        Location thisFile = new Location(file).getAbsoluteFile();
        Location parent = thisFile.getParentFile();
        String[] list = parent.list(true);
        Arrays.sort(list);
        for (String f : list) {
            if (checkSuffix(f, "fdf") && f.length() == thisFile.getName().length()) {
                files.add(new Location(parent, f).getAbsolutePath());
            }
        }
    }
}
Also used : Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) Location(loci.common.Location)

Example 69 with CoreMetadata

use of loci.formats.CoreMetadata in project bioformats by openmicroscopy.

the class VarianFDFReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    CoreMetadata m = core.get(0);
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = 1;
    parseFDF(id);
    m.imageCount = getSizeZ() * getSizeC() * getSizeT();
    m.dimensionOrder = "XYTZC";
    if (files.size() > getImageCount()) {
        int rem = files.size() / getImageCount();
        m.sizeT *= rem;
        m.imageCount = getSizeZ() * getSizeC() * getSizeT();
    }
    pixelOffsets = new long[getImageCount()];
    int planeSize = FormatTools.getPlaneSize(this);
    for (int i = 0; i < pixelOffsets.length; i++) {
        if (files.size() > 1) {
            in.close();
            in = new RandomAccessInputStream(files.get(i));
            pixelOffsets[i] = in.length() - planeSize;
        } else {
            pixelOffsets[i] = in.length() - (planeSize * (getImageCount() - i));
        }
    }
    boolean minMetadata = getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM;
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, !minMetadata);
    if (!minMetadata) {
        Length sizeX = FormatTools.getPhysicalSizeX(pixelSizeX);
        Length sizeY = FormatTools.getPhysicalSizeY(pixelSizeY);
        Length sizeZ = FormatTools.getPhysicalSizeZ(pixelSizeZ);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
        for (int i = 0; i < getImageCount(); i++) {
            store.setPlanePositionX(originX, 0, i);
            store.setPlanePositionY(originY, 0, i);
            store.setPlanePositionZ(originZ, 0, i);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Example 70 with CoreMetadata

use of loci.formats.CoreMetadata in project bioformats by openmicroscopy.

the class VolocityClippingReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    CoreMetadata m = core.get(0);
    m.littleEndian = in.read() == 'I';
    in.order(isLittleEndian());
    in.skipBytes(4);
    String magicString = in.readString(4);
    if (!magicString.equals(CLIPPING_MAGIC_STRING)) {
        throw new FormatException("Found invalid magic string: " + magicString);
    }
    int check = in.readInt();
    while (check != 0x208 && check != AISF) {
        in.seek(in.getFilePointer() - 3);
        check = in.readInt();
    }
    if (check == AISF) {
        m.littleEndian = false;
        in.order(isLittleEndian());
        in.skipBytes(28);
    }
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    m.sizeZ = in.readInt();
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = getSizeZ() * getSizeT();
    m.dimensionOrder = "XYCZT";
    m.pixelType = FormatTools.UINT8;
    pixelOffset = in.getFilePointer() + 65;
    if (getSizeX() * getSizeY() * 100 >= in.length()) {
        while (in.getFilePointer() < in.length()) {
            try {
                byte[] b = new LZOCodec().decompress(in, null);
                if (b.length > 0 && (b.length % (getSizeX() * getSizeY())) == 0) {
                    int bytes = b.length / (getSizeX() * getSizeY());
                    m.pixelType = FormatTools.pixelTypeFromBytes(bytes, false, false);
                    break;
                }
            } catch (EOFException e) {
            }
            pixelOffset++;
            in.seek(pixelOffset);
        }
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) LZOCodec(loci.formats.codec.LZOCodec) EOFException(java.io.EOFException) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Aggregations

CoreMetadata (loci.formats.CoreMetadata)211 MetadataStore (loci.formats.meta.MetadataStore)130 RandomAccessInputStream (loci.common.RandomAccessInputStream)108 FormatException (loci.formats.FormatException)87 Length (ome.units.quantity.Length)74 Location (loci.common.Location)55 ArrayList (java.util.ArrayList)50 Timestamp (ome.xml.model.primitives.Timestamp)44 IFD (loci.formats.tiff.IFD)33 Time (ome.units.quantity.Time)30 IOException (java.io.IOException)21 TiffParser (loci.formats.tiff.TiffParser)19 PhotoInterp (loci.formats.tiff.PhotoInterp)17 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)16 IFDList (loci.formats.tiff.IFDList)15 DependencyException (loci.common.services.DependencyException)14 ServiceFactory (loci.common.services.ServiceFactory)13 PositiveInteger (ome.xml.model.primitives.PositiveInteger)13 IniList (loci.common.IniList)9 HashMap (java.util.HashMap)8