Search in sources :

Example 11 with TiffRational

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

the class GelReader method initMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initMetadata() */
@Override
protected void initMetadata() throws FormatException, IOException {
    ifds = tiffParser.getIFDs();
    if (ifds.size() > 1) {
        IFDList tmpIFDs = ifds;
        ifds = new IFDList();
        for (int i = 0; i < tmpIFDs.size() / 2; i++) {
            IFD ifd = new IFD();
            ifds.add(ifd);
            ifd.putAll(tmpIFDs.get(i * 2 + 1));
            ifd.putAll(tmpIFDs.get(i * 2));
            tiffParser.fillInIFD(ifd);
        }
    }
    IFD firstIFD = ifds.get(0);
    tiffParser.fillInIFD(firstIFD);
    super.initStandardMetadata();
    fmt = firstIFD.getIFDLongValue(MD_FILETAG, LINEAR);
    if (fmt == SQUARE_ROOT)
        core.get(0).pixelType = FormatTools.FLOAT;
    TiffRational scale = (TiffRational) firstIFD.getIFDValue(MD_SCALE_PIXEL);
    if (scale == null)
        scale = new TiffRational(1, 1);
    core.get(0).imageCount = ifds.size();
    core.get(0).sizeT = getImageCount();
    // ignore MD_COLOR_TABLE
    String info = firstIFD.getIFDStringValue(MD_SAMPLE_INFO);
    String prepDate = firstIFD.getIFDStringValue(MD_PREP_DATE);
    String prepTime = firstIFD.getIFDStringValue(MD_PREP_TIME);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        String units = firstIFD.getIFDStringValue(MD_FILE_UNITS);
        String lab = firstIFD.getIFDStringValue(MD_LAB_NAME);
        addGlobalMeta("Scale factor", scale);
        addGlobalMeta("Lab name", lab);
        addGlobalMeta("Sample info", info);
        addGlobalMeta("Date prepared", prepDate);
        addGlobalMeta("Time prepared", prepTime);
        addGlobalMeta("File units", units);
        addGlobalMeta("Data format", fmt == SQUARE_ROOT ? "square root" : "linear");
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    String parsedDate = DateTools.formatDate(prepDate, FORMATS);
    String parsedTime = DateTools.formatDate(prepTime, FORMATS);
    if (parsedDate != null) {
        store.setImageAcquisitionDate(new Timestamp(parsedDate), 0);
    } else if (parsedTime != null) {
        store.setImageAcquisitionDate(new Timestamp(parsedTime), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Double pixelSize = new Double(scale.doubleValue());
        Length sizeX = FormatTools.getPhysicalSizeX(pixelSize);
        Length sizeY = FormatTools.getPhysicalSizeY(pixelSize);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) IFD(loci.formats.tiff.IFD) IFDList(loci.formats.tiff.IFDList) TiffRational(loci.formats.tiff.TiffRational) Timestamp(ome.xml.model.primitives.Timestamp)

Example 12 with TiffRational

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

the class GelReader 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 {
    IFD ifd = ifds.get(no);
    if (fmt == SQUARE_ROOT) {
        if (tiffParser == null) {
            initTiffParser();
        }
        float scale = ((TiffRational) ifd.getIFDValue(MD_SCALE_PIXEL)).floatValue();
        byte[] tmp = new byte[buf.length];
        // DO NOT call super.openBytes here. MinimalTiffReader will interpret
        // the pixels as half-floats, when really they are unsigned shorts.
        tiffParser.getSamples(ifds.get(no), tmp, x, y, w, h);
        int originalBytes = ifd.getBitsPerSample()[0] / 8;
        for (int i = 0; i < tmp.length / 4; i++) {
            long value = DataTools.bytesToShort(tmp, i * originalBytes, originalBytes, isLittleEndian());
            long square = value * value;
            float pixel = square * scale;
            DataTools.unpackBytes(Float.floatToIntBits(pixel), buf, i * 4, 4, isLittleEndian());
        }
    } else
        super.openBytes(no, buf, x, y, w, h);
    return buf;
}
Also used : IFD(loci.formats.tiff.IFD) TiffRational(loci.formats.tiff.TiffRational)

Aggregations

TiffRational (loci.formats.tiff.TiffRational)12 IFD (loci.formats.tiff.IFD)6 IFDList (loci.formats.tiff.IFDList)5 Test (org.testng.annotations.Test)5 IOException (java.io.IOException)3 FormatException (loci.formats.FormatException)3 PhotoInterp (loci.formats.tiff.PhotoInterp)3 Length (ome.units.quantity.Length)3 RandomAccessInputStream (loci.common.RandomAccessInputStream)2 CoreMetadata (loci.formats.CoreMetadata)2 MetadataStore (loci.formats.meta.MetadataStore)2 Timestamp (ome.xml.model.primitives.Timestamp)2 ArrayList (java.util.ArrayList)1 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1 TiffCompression (loci.formats.tiff.TiffCompression)1 TiffIFDEntry (loci.formats.tiff.TiffIFDEntry)1 TiffParser (loci.formats.tiff.TiffParser)1 Time (ome.units.quantity.Time)1