Search in sources :

Example 56 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream 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 57 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class VarianFDFReader 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 (files.size() > 1) {
        in = new RandomAccessInputStream(files.get(no));
        in.order(isLittleEndian());
    }
    in.seek(pixelOffsets[no]);
    readPlane(in, x, getSizeY() - y - h, w, h, buf);
    int bpp = FormatTools.getBytesPerPixel(getPixelType());
    byte[] rowBuf = new byte[w * bpp];
    for (int row = 0; row < h / 2; row++) {
        int src = row * rowBuf.length;
        int dest = (h - row - 1) * rowBuf.length;
        System.arraycopy(buf, src, rowBuf, 0, rowBuf.length);
        System.arraycopy(buf, dest, buf, src, rowBuf.length);
        System.arraycopy(rowBuf, 0, buf, dest, rowBuf.length);
    }
    if (files.size() > 1) {
        in.close();
    }
    return buf;
}
Also used : RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 58 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream 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 59 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream 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 60 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class VolocityClippingReader 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);
    in.seek(pixelOffset);
    if (FormatTools.getPlaneSize(this) * 2 + in.getFilePointer() < in.length()) {
        readPlane(in, x, y, w, h, buf);
        return buf;
    }
    byte[] b = new LZOCodec().decompress(in, null);
    RandomAccessInputStream s = new RandomAccessInputStream(b);
    s.seek(0);
    readPlane(s, x, y, w, h, buf);
    s.close();
    return buf;
}
Also used : LZOCodec(loci.formats.codec.LZOCodec) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Aggregations

RandomAccessInputStream (loci.common.RandomAccessInputStream)246 CoreMetadata (loci.formats.CoreMetadata)108 MetadataStore (loci.formats.meta.MetadataStore)97 FormatException (loci.formats.FormatException)75 TiffParser (loci.formats.tiff.TiffParser)56 IFD (loci.formats.tiff.IFD)51 Length (ome.units.quantity.Length)48 Location (loci.common.Location)47 IOException (java.io.IOException)46 ArrayList (java.util.ArrayList)30 Timestamp (ome.xml.model.primitives.Timestamp)28 Time (ome.units.quantity.Time)21 ByteArrayHandle (loci.common.ByteArrayHandle)18 IFDList (loci.formats.tiff.IFDList)16 CodecOptions (loci.formats.codec.CodecOptions)9 RandomAccessOutputStream (loci.common.RandomAccessOutputStream)8 ServiceException (loci.common.services.ServiceException)7 PhotoInterp (loci.formats.tiff.PhotoInterp)7 TiffSaver (loci.formats.tiff.TiffSaver)7 BufferedReader (java.io.BufferedReader)6