Search in sources :

Example 1 with JPEGTileDecoder

use of loci.formats.codec.JPEGTileDecoder in project bioformats by openmicroscopy.

the class HamamatsuVMSReader 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);
    IniParser parser = new IniParser();
    IniList layout = parser.parseINI(new BufferedReader(new InputStreamReader(in, Constants.ENCODING)));
    IniTable slideInfo = layout.getTable("Virtual Microscope Specimen");
    int nLayers = Integer.parseInt(slideInfo.get("NoLayers"));
    nRows = Integer.parseInt(slideInfo.get("NoJpegRows"));
    nCols = Integer.parseInt(slideInfo.get("NoJpegColumns"));
    String imageFile = slideInfo.get("ImageFile");
    mapFile = slideInfo.get("MapFile");
    String optimisationFile = slideInfo.get("OptimisationFile");
    macroFile = slideInfo.get("MacroImage");
    Double physicalWidth = new Double(slideInfo.get("PhysicalWidth"));
    Double physicalHeight = new Double(slideInfo.get("PhysicalHeight"));
    Double magnification = new Double(slideInfo.get("SourceLens"));
    Double macroWidth = new Double(slideInfo.get("PhysicalMacroWidth"));
    Double macroHeight = new Double(slideInfo.get("PhysicalMacroHeight"));
    for (String key : slideInfo.keySet()) {
        addGlobalMeta(key, slideInfo.get(key));
    }
    Location dir = new Location(id).getAbsoluteFile().getParentFile();
    if (imageFile != null) {
        imageFile = new Location(dir, imageFile).getAbsolutePath();
        files.add(imageFile);
    }
    tileFiles = new String[nLayers][nRows][nCols];
    tileFiles[0][0][0] = imageFile;
    for (int layer = 0; layer < nLayers; layer++) {
        for (int row = 0; row < nRows; row++) {
            for (int col = 0; col < nCols; col++) {
                String f = slideInfo.get("ImageFile(" + col + "," + row + ")");
                if (f != null) {
                    f = new Location(dir, f).getAbsolutePath();
                    tileFiles[layer][row][col] = f;
                    files.add(f);
                }
            }
        }
    }
    if (mapFile != null) {
        mapFile = new Location(dir, mapFile).getAbsolutePath();
        files.add(mapFile);
    }
    if (optimisationFile != null) {
        optimisationFile = new Location(dir, optimisationFile).getAbsolutePath();
        files.add(optimisationFile);
    }
    if (macroFile != null) {
        macroFile = new Location(dir, macroFile).getAbsolutePath();
        files.add(macroFile);
    }
    int seriesCount = 3;
    core.clear();
    for (int i = 0; i < seriesCount; i++) {
        String file = null;
        switch(i) {
            case 0:
                file = tileFiles[0][nRows - 1][nCols - 1];
                break;
            case 1:
                file = macroFile;
                break;
            case 2:
                file = mapFile;
                break;
        }
        int[] dims;
        try (RandomAccessInputStream s = new RandomAccessInputStream(file);
            JPEGTileDecoder decoder = new JPEGTileDecoder()) {
            dims = decoder.preprocess(s);
        }
        CoreMetadata m = new CoreMetadata();
        if (i == 0) {
            m.sizeX = (MAX_JPEG_SIZE * (nCols - 1)) + dims[0];
            m.sizeY = (MAX_JPEG_SIZE * (nRows - 1)) + dims[1];
        } else {
            m.sizeX = dims[0];
            m.sizeY = dims[1];
        }
        m.sizeZ = 1;
        m.sizeC = 3;
        m.sizeT = 1;
        m.rgb = true;
        m.imageCount = 1;
        m.dimensionOrder = "XYCZT";
        m.pixelType = FormatTools.UINT8;
        m.interleaved = m.sizeX > MAX_SIZE && m.sizeY > MAX_SIZE;
        m.thumbnail = i > 0;
        core.add(m);
    }
    CoreMetadata ms0 = core.get(0);
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    String path = new Location(currentId).getAbsoluteFile().getName();
    store.setImageName(path + " full resolution", 0);
    store.setImageName(path + " macro", 1);
    store.setImageName(path + " map", 2);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(physicalWidth / ms0.sizeX);
        Length sizeY = FormatTools.getPhysicalSizeY(physicalHeight / ms0.sizeY);
        Length macroSizeX = FormatTools.getPhysicalSizeX(macroWidth / core.get(1).sizeX);
        Length macroSizeY = FormatTools.getPhysicalSizeY(macroHeight / core.get(1).sizeY);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (macroSizeX != null) {
            store.setPixelsPhysicalSizeX(macroSizeX, 1);
        }
        if (macroSizeY != null) {
            store.setPixelsPhysicalSizeY(macroSizeY, 1);
        }
        String instrumentID = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrumentID, 0);
        store.setImageInstrumentRef(instrumentID, 0);
        String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
        store.setObjectiveID(objectiveID, 0, 0);
        store.setObjectiveNominalMagnification(magnification, 0, 0);
        store.setObjectiveSettingsID(objectiveID, 0);
    }
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) IniList(loci.common.IniList) CoreMetadata(loci.formats.CoreMetadata) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) IniTable(loci.common.IniTable) JPEGTileDecoder(loci.formats.codec.JPEGTileDecoder) BufferedReader(java.io.BufferedReader) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 2 with JPEGTileDecoder

use of loci.formats.codec.JPEGTileDecoder in project bioformats by openmicroscopy.

the class TileJPEGReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
public void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    int[] dimensions;
    try (JPEGTileDecoder decoder = new JPEGTileDecoder()) {
        dimensions = decoder.preprocess(in);
    }
    CoreMetadata m = core.get(0);
    m.interleaved = true;
    m.littleEndian = false;
    m.sizeX = dimensions[0];
    m.sizeY = dimensions[1];
    m.sizeZ = 1;
    m.sizeT = 1;
    reopenFile();
    m.sizeC = 3;
    m.rgb = getSizeC() > 1;
    m.imageCount = 1;
    m.pixelType = FormatTools.UINT8;
    m.dimensionOrder = "XYCZT";
    m.metadataComplete = true;
    m.indexed = false;
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) JPEGTileDecoder(loci.formats.codec.JPEGTileDecoder) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Aggregations

RandomAccessInputStream (loci.common.RandomAccessInputStream)2 CoreMetadata (loci.formats.CoreMetadata)2 JPEGTileDecoder (loci.formats.codec.JPEGTileDecoder)2 MetadataStore (loci.formats.meta.MetadataStore)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 IniList (loci.common.IniList)1 IniParser (loci.common.IniParser)1 IniTable (loci.common.IniTable)1 Location (loci.common.Location)1 Length (ome.units.quantity.Length)1