Search in sources :

Example 86 with CoreMetadata

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

the class BurleighReader 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 = true;
    in.order(isLittleEndian());
    int version = (int) in.readFloat() - 1;
    m.sizeX = in.readShort();
    m.sizeY = in.readShort();
    double xSize = 0d, ySize = 0d, zSize = 0d;
    pixelsOffset = version == 1 ? 8 : 260;
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        double timePerPixel = 0d;
        int mode = 0, gain = 0, mag = 0;
        double sampleVolts = 0d, tunnelCurrent = 0d;
        if (version == 1) {
            in.seek(in.length() - 40);
            in.skipBytes(12);
            xSize = in.readInt();
            ySize = in.readInt();
            zSize = in.readInt();
            timePerPixel = in.readShort() * 50;
            mag = in.readShort();
            switch(mag) {
                case 3:
                    mag = 10;
                    break;
                case 4:
                    mag = 50;
                    break;
                case 5:
                    mag = 250;
                    break;
            }
            xSize /= mag;
            ySize /= mag;
            zSize /= mag;
            mode = in.readShort();
            gain = in.readShort();
            sampleVolts = in.readFloat() / 1000;
            tunnelCurrent = in.readFloat();
        } else if (version == 2) {
            in.skipBytes(14);
            xSize = in.readInt();
            ySize = in.readInt();
            zSize = in.readInt();
            mode = in.readShort();
            in.skipBytes(4);
            gain = in.readShort();
            timePerPixel = in.readShort() * 50;
            in.skipBytes(12);
            sampleVolts = in.readFloat();
            tunnelCurrent = in.readFloat();
            addGlobalMeta("Force", in.readFloat());
        }
        addGlobalMeta("Version", version);
        addGlobalMeta("Image mode", mode);
        addGlobalMeta("Z gain", gain);
        addGlobalMeta("Time per pixel (s)", timePerPixel);
        addGlobalMeta("Sample volts", sampleVolts);
        addGlobalMeta("Tunnel current", tunnelCurrent);
        addGlobalMeta("Magnification", mag);
    }
    m.pixelType = FormatTools.UINT16;
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = 1;
    m.dimensionOrder = "XYZCT";
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(xSize / getSizeX());
        Length sizeY = FormatTools.getPhysicalSizeY(ySize / getSizeY());
        Length sizeZ = FormatTools.getPhysicalSizeZ(zSize / getSizeZ());
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Example 87 with CoreMetadata

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

the class CellH5Reader method parseStructure.

private void parseStructure() throws FormatException {
    seriesCount = 0;
    core.clear();
    // read experiment structure and collect coordinates
    String path_to_plate = CellH5Constants.PREFIX_PATH + CellH5Constants.PLATE;
    LOGGER.info("Plate :" + path_to_plate);
    for (String plate : jhdf.getMember(path_to_plate)) {
        String path_to_well = path_to_plate + plate + CellH5Constants.WELL;
        LOGGER.info("Well :" + path_to_well);
        for (String well : jhdf.getMember(path_to_well)) {
            String path_to_site = path_to_well + well + CellH5Constants.SITE;
            LOGGER.info("Site :" + path_to_site);
            for (String site : jhdf.getMember(path_to_site)) {
                CellH5PositionList.add(new CellH5Coordinate(plate, well, site));
            }
        }
    }
    if (CellH5PositionList.size() == 0) {
        throw new FormatException("No series found in file...");
    }
    List<String> seriesNames = new ArrayList<String>();
    List<String> seriesPlate = new ArrayList<String>();
    List<String> seriesWell = new ArrayList<String>();
    List<String> seriesSite = new ArrayList<String>();
    for (CellH5Coordinate coord : CellH5PositionList) {
        if (jhdf.exists(coord.pathToImageData)) {
            CoreMetadata m = new CoreMetadata();
            core.add(m);
            setSeries(seriesCount);
            LOGGER.debug(coord.pathToImageData);
            int[] ctzyx = jhdf.getShape(coord.pathToImageData);
            m.sizeC = ctzyx[0];
            m.sizeT = ctzyx[1];
            m.sizeZ = ctzyx[2];
            m.sizeY = ctzyx[3];
            m.sizeX = ctzyx[4];
            m.resolutionCount = 1;
            m.thumbnail = false;
            m.imageCount = getSizeC() * getSizeT() * getSizeZ();
            m.dimensionOrder = "XYZTC";
            m.rgb = false;
            m.thumbSizeX = 128;
            m.thumbSizeY = 128;
            m.orderCertain = false;
            m.littleEndian = true;
            m.interleaved = false;
            m.indexed = true;
            int bpp = jhdf.getElementSize(coord.pathToImageData);
            if (bpp == 1) {
                m.pixelType = FormatTools.UINT8;
            } else if (bpp == 2) {
                m.pixelType = FormatTools.UINT16;
            } else if (bpp == 4) {
                m.pixelType = FormatTools.INT32;
            } else {
                throw new FormatException("Pixel type not understood. Only 8, " + "16 and 32 bit images supported");
            }
            seriesNames.add(String.format("P_%s, W_%s_%s", coord.plate, coord.well, coord.site));
            seriesPlate.add(coord.plate);
            seriesWell.add(coord.well);
            seriesSite.add(coord.site);
            CellH5PathsToImageData.add(coord.pathToImageData);
            seriesCount++;
        }
    }
    for (CellH5Coordinate coord : CellH5PositionList) {
        if (jhdf.exists(coord.pathToSegmentationData)) {
            CoreMetadata m = new CoreMetadata();
            core.add(m);
            setSeries(seriesCount);
            LOGGER.debug(coord.pathToSegmentationData);
            int[] ctzyx = jhdf.getShape(coord.pathToSegmentationData);
            m.sizeC = ctzyx[0];
            m.sizeT = ctzyx[1];
            m.sizeZ = ctzyx[2];
            m.sizeY = ctzyx[3];
            m.sizeX = ctzyx[4];
            m.resolutionCount = 1;
            m.thumbnail = false;
            m.imageCount = getSizeC() * getSizeT() * getSizeZ();
            m.dimensionOrder = "XYZTC";
            m.rgb = false;
            m.thumbSizeX = 128;
            m.thumbSizeY = 128;
            m.orderCertain = false;
            m.littleEndian = true;
            m.interleaved = false;
            m.indexed = true;
            int bpp = jhdf.getElementSize(coord.pathToSegmentationData);
            if (bpp == 1) {
                m.pixelType = FormatTools.UINT8;
            } else if (bpp == 2) {
                m.pixelType = FormatTools.UINT16;
            } else if (bpp == 4) {
                m.pixelType = FormatTools.INT32;
            } else {
                throw new FormatException("Pixel type not understood. Only 8, " + "16 and 32 bit images supported");
            }
            seriesNames.add(String.format("P_%s, W_%s_%s label image", coord.plate, coord.well, coord.site));
            seriesPlate.add(coord.plate);
            seriesWell.add(coord.well);
            seriesSite.add(coord.site);
            CellH5PathsToImageData.add(coord.pathToSegmentationData);
            seriesCount++;
        }
    }
    if (seriesCount == 0) {
        throw new FormatException("No image data found...");
    }
    store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    for (int s = 0; s < seriesNames.size(); s++) {
        String image_id = MetadataTools.createLSID("Image", s);
        store.setImageName(seriesNames.get(s), s);
        String plate_id = MetadataTools.createLSID("Plate", 0);
        store.setPlateID(plate_id, 0);
        store.setPlateName(seriesPlate.get(s), 0);
        String well_id = MetadataTools.createLSID("Well", 0);
        store.setWellID(well_id, 0, 0);
        String cellh5WellCoord = seriesWell.get(s);
        String wellRowLetter = cellh5WellCoord.substring(0, 1);
        String wellColNumber = cellh5WellCoord.substring(1);
        int wellRowLetterIndex = "ABCDEFGHIJKLMNOP".indexOf(wellRowLetter);
        int wellColNumberIndex = -1;
        try {
            wellColNumberIndex = Integer.parseInt(wellColNumber);
        } catch (NumberFormatException e) {
        // 
        }
        if (wellRowLetterIndex > -1 && wellColNumberIndex > 0) {
            store.setWellRow(new NonNegativeInteger(wellRowLetterIndex), 0, 0);
            store.setWellColumn(new NonNegativeInteger(wellColNumberIndex - 1), 0, 0);
        } else {
            store.setWellRow(new NonNegativeInteger(0), 0, 0);
            store.setWellColumn(new NonNegativeInteger(0), 0, 0);
        }
        store.setWellExternalIdentifier(cellh5WellCoord, 0, 0);
        String site_id = MetadataTools.createLSID("WellSample", 0);
        store.setWellSampleID(site_id, 0, 0, 0);
        store.setWellSampleIndex(NonNegativeInteger.valueOf(seriesSite.get(s)), 0, 0, 0);
        store.setWellSampleImageRef(image_id, 0, 0, 0);
    }
    setSeries(0);
    parseCellObjects();
}
Also used : NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) ArrayList(java.util.ArrayList) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 88 with CoreMetadata

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

the class CellSensReader method parseETSFile.

private void parseETSFile(String file, int s) throws FormatException, IOException {
    fileMap.put(core.size() - 1, file);
    RandomAccessInputStream etsFile = new RandomAccessInputStream(file);
    etsFile.order(true);
    CoreMetadata ms = core.get(getCoreIndex());
    // read the volume header
    String magic = etsFile.readString(4).trim();
    if (!magic.equals("SIS")) {
        throw new FormatException("Unknown magic bytes: " + magic);
    }
    int headerSize = etsFile.readInt();
    int version = etsFile.readInt();
    nDimensions.add(etsFile.readInt());
    long additionalHeaderOffset = etsFile.readLong();
    int additionalHeaderSize = etsFile.readInt();
    // reserved
    etsFile.skipBytes(4);
    long usedChunkOffset = etsFile.readLong();
    int nUsedChunks = etsFile.readInt();
    // reserved
    etsFile.skipBytes(4);
    // read the additional header
    etsFile.seek(additionalHeaderOffset);
    String moreMagic = etsFile.readString(4).trim();
    if (!moreMagic.equals("ETS")) {
        throw new FormatException("Unknown magic bytes: " + moreMagic);
    }
    // extra version number
    etsFile.skipBytes(4);
    int pixelType = etsFile.readInt();
    ms.sizeC = etsFile.readInt();
    int colorspace = etsFile.readInt();
    compressionType.add(etsFile.readInt());
    int compressionQuality = etsFile.readInt();
    tileX.add(etsFile.readInt());
    tileY.add(etsFile.readInt());
    int tileZ = etsFile.readInt();
    // pixel info hints
    etsFile.skipBytes(4 * 17);
    byte[] color = new byte[ms.sizeC * FormatTools.getBytesPerPixel(convertPixelType(pixelType))];
    etsFile.read(color);
    backgroundColor.put(getCoreIndex(), color);
    // background color
    etsFile.skipBytes(4 * 10 - color.length);
    // component order
    etsFile.skipBytes(4);
    boolean usePyramid = etsFile.readInt() != 0;
    ms.rgb = ms.sizeC > 1;
    // read the used chunks
    etsFile.seek(usedChunkOffset);
    tileOffsets.add(new Long[nUsedChunks]);
    ArrayList<TileCoordinate> tmpTiles = new ArrayList<TileCoordinate>();
    for (int chunk = 0; chunk < nUsedChunks; chunk++) {
        etsFile.skipBytes(4);
        int dimensions = nDimensions.get(nDimensions.size() - 1);
        TileCoordinate t = new TileCoordinate(dimensions);
        for (int i = 0; i < dimensions; i++) {
            t.coordinate[i] = etsFile.readInt();
        }
        tileOffsets.get(tileOffsets.size() - 1)[chunk] = etsFile.readLong();
        int nBytes = etsFile.readInt();
        etsFile.skipBytes(4);
        tmpTiles.add(t);
    }
    int maxResolution = 0;
    if (usePyramid) {
        for (TileCoordinate t : tmpTiles) {
            if (t.coordinate[t.coordinate.length - 1] > maxResolution) {
                maxResolution = t.coordinate[t.coordinate.length - 1];
            }
        }
    }
    maxResolution++;
    int[] maxX = new int[maxResolution];
    int[] maxY = new int[maxResolution];
    int[] maxZ = new int[maxResolution];
    int[] maxC = new int[maxResolution];
    int[] maxT = new int[maxResolution];
    HashMap<String, Integer> dimOrder = pyramids.get(s).dimensionOrdering;
    for (TileCoordinate t : tmpTiles) {
        int resolution = usePyramid ? t.coordinate[t.coordinate.length - 1] : 0;
        Integer tv = dimOrder.get("T");
        Integer zv = dimOrder.get("Z");
        Integer cv = dimOrder.get("C");
        int tIndex = tv == null ? -1 : tv + 2;
        int zIndex = zv == null ? -1 : zv + 2;
        int cIndex = cv == null ? -1 : cv + 2;
        if (usePyramid && tIndex == t.coordinate.length - 1) {
            tv = null;
            tIndex = -1;
        }
        if (usePyramid && zIndex == t.coordinate.length - 1) {
            zv = null;
            zIndex = -1;
        }
        int upperLimit = usePyramid ? t.coordinate.length - 1 : t.coordinate.length;
        if ((tIndex < 0 || tIndex >= upperLimit) && (zIndex < 0 || zIndex >= upperLimit) && (cIndex < 0 || cIndex >= upperLimit)) {
            tIndex--;
            zIndex--;
            cIndex--;
            if (dimOrder.containsKey("T")) {
                dimOrder.put("T", tIndex - 2);
            }
            if (dimOrder.containsKey("Z")) {
                dimOrder.put("Z", zIndex - 2);
            }
            if (dimOrder.containsKey("C")) {
                dimOrder.put("C", cIndex - 2);
            }
        }
        if (tv == null && zv == null) {
            if (t.coordinate.length > 4 && cv == null) {
                cIndex = 2;
                dimOrder.put("C", cIndex - 2);
            }
            if (t.coordinate.length > 4) {
                if (cv == null) {
                    tIndex = 3;
                } else {
                    tIndex = cIndex + 2;
                }
                if (tIndex < t.coordinate.length) {
                    dimOrder.put("T", tIndex - 2);
                } else {
                    tIndex = -1;
                }
            }
            if (t.coordinate.length > 5) {
                if (cv == null) {
                    zIndex = 4;
                } else {
                    zIndex = cIndex + 1;
                }
                if (zIndex < t.coordinate.length) {
                    dimOrder.put("Z", zIndex - 2);
                } else {
                    zIndex = -1;
                }
            }
        }
        if (t.coordinate[0] > maxX[resolution]) {
            maxX[resolution] = t.coordinate[0];
        }
        if (t.coordinate[1] > maxY[resolution]) {
            maxY[resolution] = t.coordinate[1];
        }
        if (tIndex >= 0 && t.coordinate[tIndex] > maxT[resolution]) {
            maxT[resolution] = t.coordinate[tIndex];
        }
        if (zIndex >= 0 && t.coordinate[zIndex] > maxZ[resolution]) {
            maxZ[resolution] = t.coordinate[zIndex];
        }
        if (cIndex >= 0 && t.coordinate[cIndex] > maxC[resolution]) {
            maxC[resolution] = t.coordinate[cIndex];
        }
    }
    if (pyramids.get(s).width != null) {
        ms.sizeX = pyramids.get(s).width;
    }
    if (pyramids.get(s).height != null) {
        ms.sizeY = pyramids.get(s).height;
    }
    ms.sizeZ = maxZ[0] + 1;
    if (maxC[0] > 0) {
        ms.sizeC *= (maxC[0] + 1);
    }
    ms.sizeT = maxT[0] + 1;
    if (ms.sizeZ == 0) {
        ms.sizeZ = 1;
    }
    ms.imageCount = ms.sizeZ * ms.sizeT;
    if (maxC[0] > 0) {
        ms.imageCount *= (maxC[0] + 1);
    }
    if (maxY[0] >= 1) {
        rows.add(maxY[0] + 1);
    } else {
        rows.add(1);
    }
    if (maxX[0] >= 1) {
        cols.add(maxX[0] + 1);
    } else {
        cols.add(1);
    }
    ArrayList<TileCoordinate> map = new ArrayList<TileCoordinate>();
    for (int i = 0; i < tmpTiles.size(); i++) {
        map.add(tmpTiles.get(i));
    }
    tileMap.add(map);
    ms.pixelType = convertPixelType(pixelType);
    if (usePyramid) {
        int finalResolution = 1;
        int initialCoreSize = core.size();
        for (int i = 1; i < maxResolution; i++) {
            CoreMetadata newResolution = new CoreMetadata(ms);
            int previousX = core.get(core.size() - 1).sizeX;
            int previousY = core.get(core.size() - 1).sizeY;
            int maxSizeX = tileX.get(tileX.size() - 1) * (maxX[i] < 1 ? 1 : maxX[i] + 1);
            int maxSizeY = tileY.get(tileY.size() - 1) * (maxY[i] < 1 ? 1 : maxY[i] + 1);
            newResolution.sizeX = previousX / 2;
            if (previousX % 2 == 1 && newResolution.sizeX < maxSizeX) {
                newResolution.sizeX++;
            } else if (newResolution.sizeX > maxSizeX) {
                newResolution.sizeX = maxSizeX;
            }
            newResolution.sizeY = previousY / 2;
            if (previousY % 2 == 1 && newResolution.sizeY < maxSizeY) {
                newResolution.sizeY++;
            } else if (newResolution.sizeY > maxSizeY) {
                newResolution.sizeY = maxSizeY;
            }
            newResolution.sizeZ = maxZ[i] + 1;
            if (maxC[i] > 0 && newResolution.sizeC != (maxC[i] + 1)) {
                newResolution.sizeC *= (maxC[i] + 1);
            }
            newResolution.sizeT = maxT[i] + 1;
            if (newResolution.sizeZ == 0) {
                newResolution.sizeZ = 1;
            }
            newResolution.imageCount = newResolution.sizeZ * newResolution.sizeT;
            if (maxC[i] > 0) {
                newResolution.imageCount *= (maxC[i] + 1);
            }
            newResolution.metadataComplete = true;
            newResolution.dimensionOrder = "XYCZT";
            core.add(newResolution);
            rows.add(maxY[i] >= 1 ? maxY[i] + 1 : 1);
            cols.add(maxX[i] >= 1 ? maxX[i] + 1 : 1);
            fileMap.put(core.size() - 1, file);
            finalResolution = core.size() - initialCoreSize + 1;
            tileX.add(tileX.get(tileX.size() - 1));
            tileY.add(tileY.get(tileY.size() - 1));
            compressionType.add(compressionType.get(compressionType.size() - 1));
            tileMap.add(map);
            nDimensions.add(nDimensions.get(nDimensions.size() - 1));
            tileOffsets.add(tileOffsets.get(tileOffsets.size() - 1));
            backgroundColor.put(core.size() - 1, color);
        }
        ms.resolutionCount = finalResolution;
    }
    etsFile.close();
}
Also used : ArrayList(java.util.ArrayList) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 89 with CoreMetadata

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

the class AIMReader 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 = true;
    in.order(isLittleEndian());
    // check for newer version of AIM format with wider offsets
    String version = in.readString(16);
    boolean widerOffsets = version.startsWith("AIMDATA_V030");
    if (widerOffsets) {
        in.seek(96);
        m.sizeX = (int) in.readLong();
        m.sizeY = (int) in.readLong();
        m.sizeZ = (int) in.readLong();
        in.seek(280);
    } else {
        in.seek(56);
        m.sizeX = in.readInt();
        m.sizeY = in.readInt();
        m.sizeZ = in.readInt();
        in.seek(160);
    }
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = getSizeZ();
    m.pixelType = FormatTools.INT16;
    m.dimensionOrder = "XYZCT";
    String processingLog = in.readCString();
    pixelOffset = in.getFilePointer();
    String date = null;
    Double xSize = null, xLength = null;
    Double ySize = null, yLength = null;
    Double zSize = null, zLength = null;
    String[] lines = processingLog.split("\n");
    for (String line : lines) {
        line = line.trim();
        int split = line.indexOf("  ");
        if (split > 0) {
            String key = line.substring(0, split).trim();
            String value = line.substring(split).trim();
            addGlobalMeta(key, value);
            if (key.equals("Original Creation-Date")) {
                date = DateTools.formatDate(value, "dd-MMM-yyyy HH:mm:ss", ".");
            } else if (key.equals("Orig-ISQ-Dim-p")) {
                String[] tokens = value.split(" ");
                for (String token : tokens) {
                    token = token.trim();
                    if (token.length() > 0) {
                        if (xSize == null) {
                            xSize = new Double(token);
                        } else if (ySize == null) {
                            ySize = new Double(token);
                        } else if (zSize == null) {
                            zSize = new Double(token);
                        }
                    }
                }
            } else if (key.equals("Orig-ISQ-Dim-um")) {
                String[] tokens = value.split(" ");
                for (String token : tokens) {
                    token = token.trim();
                    if (token.length() > 0) {
                        if (xLength == null) {
                            xLength = new Double(token);
                        } else if (yLength == null) {
                            yLength = new Double(token);
                        } else if (zLength == null) {
                            zLength = new Double(token);
                        }
                    }
                }
            }
        }
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        if (xSize != null && xLength != null) {
            Double size = xLength / xSize;
            Length physicalSize = FormatTools.getPhysicalSizeX(size);
            if (physicalSize != null) {
                store.setPixelsPhysicalSizeX(physicalSize, 0);
            }
        }
        if (ySize != null && yLength != null) {
            Double size = yLength / ySize;
            Length physicalSize = FormatTools.getPhysicalSizeY(size);
            if (physicalSize != null) {
                store.setPixelsPhysicalSizeY(physicalSize, 0);
            }
        }
        if (zSize != null && zLength != null) {
            Double size = zLength / zSize;
            Length physicalSize = FormatTools.getPhysicalSizeZ(size);
            if (physicalSize != null) {
                store.setPixelsPhysicalSizeZ(physicalSize, 0);
            }
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

Example 90 with CoreMetadata

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

the class ARFReader 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);
    // parse file header
    LOGGER.info("Reading file header");
    byte endian1 = in.readByte();
    byte endian2 = in.readByte();
    boolean little;
    if (endian1 == 1 && endian2 == 0)
        little = true;
    else if (endian1 == 0 && endian2 == 1)
        little = false;
    else
        throw new FormatException("Undefined endianness");
    in.order(little);
    // 'AR' signature
    in.skipBytes(2);
    int version = in.readUnsignedShort();
    int width = in.readUnsignedShort();
    int height = in.readUnsignedShort();
    int bitsPerPixel = in.readUnsignedShort();
    int numImages = version == 2 ? in.readUnsignedShort() : 1;
    // NB: The next 510 bytes are unused 'application dependent' data,
    // followed by raw image data with no padding.
    // populate core metadata
    CoreMetadata m = core.get(0);
    m.sizeX = width;
    m.sizeY = height;
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = numImages;
    int bpp = bitsPerPixel / 8;
    if ((bitsPerPixel % 8) != 0)
        bpp++;
    m.pixelType = FormatTools.pixelTypeFromBytes(bpp, false, false);
    m.bitsPerPixel = bitsPerPixel;
    m.imageCount = numImages;
    m.dimensionOrder = "XYCZT";
    m.orderCertain = true;
    m.littleEndian = little;
    m.rgb = false;
    m.interleaved = false;
    m.indexed = false;
    m.metadataComplete = true;
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // populate original metadata
        addGlobalMeta("Endianness", little ? "little" : "big");
        addGlobalMeta("Version", version);
        addGlobalMeta("Width", width);
        addGlobalMeta("Height", height);
        addGlobalMeta("Bits per pixel", bitsPerPixel);
        addGlobalMeta("Image count", numImages);
    }
    // populate OME metadata
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) 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