Search in sources :

Example 16 with CoreMetadata

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

the class NDPIReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see loci.formats.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    ifds = tiffParser.getIFDs();
    // fix the offsets for > 4 GB files
    RandomAccessInputStream stream = new RandomAccessInputStream(currentId);
    for (int i = 0; i < ifds.size(); i++) {
        IFD ifd = ifds.get(i);
        long[] stripOffsets = ifd.getStripOffsets();
        boolean neededAdjustment = false;
        for (int j = 0; j < stripOffsets.length; j++) {
            long prevOffset = i == 0 ? 0 : ifds.get(i - 1).getStripOffsets()[0];
            long prevByteCount = i == 0 ? 0 : ifds.get(i - 1).getStripByteCounts()[0];
            long currentOffset = (int) stripOffsets[j];
            while (currentOffset < prevOffset || currentOffset < prevOffset + prevByteCount) {
                long newOffset = currentOffset + 0x100000000L;
                if (newOffset < stream.length() && ((j > 0 && (currentOffset < stripOffsets[j - 1])) || (i > 0 && currentOffset < prevOffset + prevByteCount))) {
                    stripOffsets[j] = newOffset;
                    currentOffset = stripOffsets[j];
                    neededAdjustment = true;
                }
            }
        }
        if (neededAdjustment) {
            ifd.putIFDValue(IFD.STRIP_OFFSETS, stripOffsets);
        }
        neededAdjustment = false;
        long[] stripByteCounts = ifd.getStripByteCounts();
        for (int j = 0; j < stripByteCounts.length; j++) {
            long currentCount = (int) stripByteCounts[j];
            long newByteCount = currentCount + 0x100000000L;
            if (currentCount < 0 || neededAdjustment || newByteCount + stripOffsets[j] < in.length()) {
                if (newByteCount < ifd.getImageWidth() * ifd.getImageLength()) {
                    stripByteCounts[j] = newByteCount;
                    neededAdjustment = true;
                }
            }
        }
        if (neededAdjustment) {
            ifd.putIFDValue(IFD.STRIP_BYTE_COUNTS, stripByteCounts);
        }
    }
    stream.close();
    for (int i = 1; i < ifds.size(); i++) {
        IFD ifd = ifds.get(i);
        if (ifd.getImageWidth() == ifds.get(0).getImageWidth() && ifd.getImageLength() == ifds.get(0).getImageLength()) {
            sizeZ++;
        } else if (sizeZ == 1) {
            boolean isPyramid;
            Object source_lens_value = ifd.getIFDValue(SOURCE_LENS);
            if (source_lens_value != null) {
                float source_lens = (Float) source_lens_value;
                // A value of -1 correspond to the macro image and a value of -2
                // correspond to the map image
                isPyramid = (source_lens != -1 && source_lens != -2);
            } else {
                // Assume the last IFD is the macro image
                isPyramid = i < ifds.size() - 1;
            }
            if (isPyramid)
                pyramidHeight++;
        }
    }
    // repopulate core metadata
    int seriesCount = pyramidHeight + (ifds.size() - pyramidHeight * sizeZ);
    for (int i = 0; i < ifds.size(); i++) {
        IFD ifd = ifds.get(i);
        ifd.remove(THUMB_TAG_2);
        ifds.set(i, ifd);
        TiffIFDEntry markerTag = (TiffIFDEntry) ifd.get(MARKER_TAG);
        if (markerTag != null) {
            if (markerTag.getValueOffset() > in.length()) {
                // can't rely upon the MARKER_TAG to be detected correctly
                ifds.get(i).remove(MARKER_TAG);
            } else {
                Object value = tiffParser.getIFDValue(markerTag);
                ifds.get(i).putIFDValue(MARKER_TAG, value);
            }
        }
        tiffParser.fillInIFD(ifds.get(i));
        int[] bpp = ifds.get(i).getBitsPerSample();
        for (int q = 0; q < bpp.length; q++) {
            if (bpp[q] < 8) {
                bpp[q] = 8;
            }
        }
        ifds.get(i).putIFDValue(IFD.BITS_PER_SAMPLE, bpp);
    }
    core.clear();
    for (int s = 0; s < seriesCount; s++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        if (s == 0) {
            ms.resolutionCount = pyramidHeight;
        }
    }
    for (int s = 0; s < core.size(); s++) {
        IFD ifd = ifds.get(getIFDIndex(s, 0));
        PhotoInterp p = ifd.getPhotometricInterpretation();
        int samples = ifd.getSamplesPerPixel();
        CoreMetadata ms = core.get(s);
        ms.rgb = samples > 1 || p == PhotoInterp.RGB;
        ms.sizeX = (int) ifd.getImageWidth();
        ms.sizeY = (int) ifd.getImageLength();
        ms.sizeZ = s < pyramidHeight ? sizeZ : 1;
        ms.sizeT = 1;
        ms.sizeC = ms.rgb ? samples : 1;
        ms.littleEndian = ifd.isLittleEndian();
        ms.indexed = p == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
        ms.imageCount = ms.sizeZ * ms.sizeT;
        ms.pixelType = ifd.getPixelType();
        ms.metadataComplete = true;
        ms.interleaved = ms.sizeX > MAX_SIZE && ms.sizeY > MAX_SIZE;
        ms.falseColor = false;
        ms.dimensionOrder = "XYCZT";
        ms.thumbnail = s != 0;
    }
    String metadataTag = ifds.get(0).getIFDStringValue(METADATA_TAG);
    if (metadataTag != null) {
        String[] entries = metadataTag.split("\n");
        for (String entry : entries) {
            int eq = entry.indexOf('=');
            if (eq < 0) {
                continue;
            }
            String key = entry.substring(0, eq).trim();
            String value = entry.substring(eq + 1).trim();
            addGlobalMeta(key, value);
            if (key.equals("Objective.Lens.Magnificant")) {
                // not a typo
                magnification = new Double(value);
            } else if (key.equals("NDP.S/N")) {
                serialNumber = value;
            } else if (key.equals("Product")) {
                instrumentModel = value;
            }
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata) TiffIFDEntry(loci.formats.tiff.TiffIFDEntry) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 17 with CoreMetadata

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

the class NiftiReader method populatePixelType.

// -- Helper methods --
private void populatePixelType(int dataType) throws FormatException {
    CoreMetadata m = core.get(0);
    switch(dataType) {
        case 1:
        case 2:
            m.pixelType = FormatTools.UINT8;
            break;
        case 4:
            m.pixelType = FormatTools.INT16;
            break;
        case 8:
            m.pixelType = FormatTools.INT32;
            break;
        case 16:
            m.pixelType = FormatTools.FLOAT;
            break;
        case 64:
            m.pixelType = FormatTools.DOUBLE;
            break;
        case 128:
            m.pixelType = FormatTools.UINT8;
            m.sizeC = 3;
        case 256:
            m.pixelType = FormatTools.INT8;
            break;
        case 512:
            m.pixelType = FormatTools.UINT16;
            break;
        case 768:
            m.pixelType = FormatTools.UINT32;
            break;
        case 2304:
            m.pixelType = FormatTools.UINT8;
            m.sizeC = 4;
        default:
            throw new FormatException("Unsupported data type: " + dataType);
    }
}
Also used : CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 18 with CoreMetadata

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

the class NikonReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    original = ifds.get(0);
    if (cfaPattern != null) {
        original.putIFDValue(IFD.COLOR_MAP, (int[]) cfaPattern);
    }
    ifds.set(0, original);
    CoreMetadata m = core.get(0);
    m.imageCount = 1;
    m.sizeT = 1;
    if (ifds.get(0).getSamplesPerPixel() == 1) {
        m.interleaved = true;
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) CoreMetadata(loci.formats.CoreMetadata)

Example 19 with CoreMetadata

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

the class NikonReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    // reset image dimensions
    // the actual image data is stored in IFDs referenced by the SubIFD tag
    // in the 'real' IFD
    CoreMetadata m = core.get(0);
    m.imageCount = ifds.size();
    IFD firstIFD = ifds.get(0);
    PhotoInterp photo = firstIFD.getPhotometricInterpretation();
    int samples = firstIFD.getSamplesPerPixel();
    m.rgb = samples > 1 || photo == PhotoInterp.RGB || photo == PhotoInterp.CFA_ARRAY;
    if (photo == PhotoInterp.CFA_ARRAY)
        samples = 3;
    m.sizeX = (int) firstIFD.getImageWidth();
    m.sizeY = (int) firstIFD.getImageLength();
    m.sizeZ = 1;
    m.sizeC = isRGB() ? samples : 1;
    m.sizeT = ifds.size();
    m.pixelType = firstIFD.getPixelType();
    m.indexed = false;
    // now look for the EXIF IFD pointer
    IFDList exifIFDs = tiffParser.getExifIFDs();
    if (exifIFDs.size() > 0) {
        IFD exifIFD = exifIFDs.get(0);
        tiffParser.fillInIFD(exifIFD);
        for (Integer key : exifIFD.keySet()) {
            int tag = key.intValue();
            String name = IFD.getIFDTagName(tag);
            if (tag == IFD.CFA_PATTERN) {
                byte[] cfa = (byte[]) exifIFD.get(key);
                int[] colorMap = new int[cfa.length];
                for (int i = 0; i < cfa.length; i++) colorMap[i] = (int) cfa[i];
                addGlobalMeta(name, colorMap);
                cfaPattern = colorMap;
            } else {
                addGlobalMeta(name, exifIFD.get(key));
                if (name.equals("MAKER_NOTE")) {
                    byte[] b = (byte[]) exifIFD.get(key);
                    int extra = new String(b, 0, 10, Constants.ENCODING).startsWith("Nikon") ? 10 : 0;
                    byte[] buf = new byte[b.length];
                    System.arraycopy(b, extra, buf, 0, buf.length - extra);
                    RandomAccessInputStream makerNote = new RandomAccessInputStream(buf);
                    TiffParser tp = new TiffParser(makerNote);
                    IFD note = null;
                    try {
                        note = tp.getFirstIFD();
                    } catch (Exception e) {
                        LOGGER.debug("Failed to parse first IFD", e);
                    }
                    if (note != null) {
                        for (Integer nextKey : note.keySet()) {
                            int nextTag = nextKey.intValue();
                            addGlobalMeta(name, note.get(nextKey));
                            if (nextTag == 150) {
                                b = (byte[]) note.get(nextKey);
                                RandomAccessInputStream s = new RandomAccessInputStream(b);
                                byte check1 = s.readByte();
                                byte check2 = s.readByte();
                                lossyCompression = check1 != 0x46;
                                vPredictor = new int[4];
                                for (int q = 0; q < vPredictor.length; q++) {
                                    vPredictor[q] = s.readShort();
                                }
                                curve = new int[16385];
                                int bps = ifds.get(0).getBitsPerSample()[0];
                                int max = 1 << bps & 0x7fff;
                                int step = 0;
                                int csize = s.readShort();
                                if (csize > 1) {
                                    step = max / (csize - 1);
                                }
                                if (check1 == 0x44 && check2 == 0x20 && step > 0) {
                                    for (int i = 0; i < csize; i++) {
                                        curve[i * step] = s.readShort();
                                    }
                                    for (int i = 0; i < max; i++) {
                                        int n = i % step;
                                        curve[i] = (curve[i - n] * (step - n) + curve[i - n + step] * n) / step;
                                    }
                                    s.seek(562);
                                    split = s.readShort();
                                } else {
                                    int maxValue = (int) Math.pow(2, bps) - 1;
                                    Arrays.fill(curve, maxValue);
                                    int nElements = (int) (s.length() - s.getFilePointer()) / 2;
                                    if (nElements < 100) {
                                        for (int i = 0; i < curve.length; i++) {
                                            curve[i] = (short) i;
                                        }
                                    } else {
                                        for (int q = 0; q < nElements; q++) {
                                            curve[q] = s.readShort();
                                        }
                                    }
                                }
                                s.close();
                            } else if (nextTag == WHITE_BALANCE_RGB_COEFFS) {
                                whiteBalance = (TiffRational[]) note.get(nextKey);
                            }
                        }
                    }
                    makerNote.close();
                }
            }
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) IOException(java.io.IOException) IFDList(loci.formats.tiff.IFDList) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 20 with CoreMetadata

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

the class OIRReader method parseImageProperties.

private void parseImageProperties(Element root) throws FormatException {
    CoreMetadata m = core.get(0);
    Element general = getFirstChild(root, "commonimage:general");
    if (general != null) {
        Element creationDate = getFirstChild(general, "base:creationDateTime");
        if (creationDate != null) {
            String date = creationDate.getTextContent();
            acquisitionDate = new Timestamp(date);
        }
    }
    Element lsm = getFirstChild(root, "commonimage:lsm");
    if (lsm != null) {
        NodeList laserNodes = lsm.getElementsByTagName("commonimage:laser");
        for (int i = 0; i < laserNodes.getLength(); i++) {
            Element laser = (Element) laserNodes.item(i);
            Element idNode = getFirstChild(laser, "commonimage:id");
            Element nameNode = getFirstChild(laser, "commonimage:name");
            Laser l = new Laser();
            if (idNode != null) {
                l.id = idNode.getTextContent();
            }
            if (nameNode != null) {
                l.name = nameNode.getTextContent();
            }
            lasers.add(l);
        }
    }
    Element imageInfo = getFirstChild(root, "commonimage:imageInfo");
    if (imageInfo != null) {
        Element width = getFirstChild(imageInfo, "commonimage:width");
        Element height = getFirstChild(imageInfo, "commonimage:height");
        if (width != null && getSizeX() == 0) {
            m.sizeX = Integer.parseInt(width.getTextContent());
        }
        if (height != null && getSizeY() == 0) {
            m.sizeY = Integer.parseInt(height.getTextContent());
        }
        NodeList axisNodes = imageInfo.getElementsByTagName("commonimage:axis");
        if (axisNodes != null) {
            for (int i = 0; i < axisNodes.getLength(); i++) {
                parseAxis((Element) axisNodes.item(i));
            }
        }
        NodeList channelNodes = imageInfo.getElementsByTagName("commonphase:channel");
        for (int i = 0; i < channelNodes.getLength(); i++) {
            Channel c = new Channel();
            Element channelNode = (Element) channelNodes.item(i);
            c.id = channelNode.getAttribute("id");
            int index = Integer.parseInt(channelNode.getAttribute("order")) - 1;
            Element name = getFirstChild(channelNode, "commonphase:name");
            if (name != null) {
                c.name = name.getTextContent();
            }
            Element pinhole = getFirstChild(channelNode, "fvCommonphase:pinholeDiameter");
            if (pinhole != null) {
                Double pinholeSize = DataTools.parseDouble(pinhole.getTextContent());
                if (pinholeSize != null) {
                    c.pinhole = new Length(pinholeSize, UNITS.MICROMETER);
                }
            }
            Element startWavelength = getFirstChild(channelNode, "opticalelement:startWavelength");
            Element endWavelength = getFirstChild(channelNode, "opticalelement:endWavelength");
            if (startWavelength != null) {
                Double wave = DataTools.parseDouble(startWavelength.getTextContent());
                if (wave != null) {
                    c.excitation = FormatTools.getExcitationWavelength(wave);
                }
            }
            if (endWavelength != null) {
                Double wave = DataTools.parseDouble(endWavelength.getTextContent());
                if (wave != null) {
                    c.emission = FormatTools.getEmissionWavelength(wave);
                }
            }
            Element imageDefinition = getFirstChild(channelNode, "commonphase:imageDefinition");
            if (imageDefinition != null) {
                Element depth = getFirstChild(imageDefinition, "commonphase:depth");
                Element bitCount = getFirstChild(imageDefinition, "commonphase:bitCounts");
                if (depth != null) {
                    int bytes = Integer.parseInt(depth.getTextContent());
                    m.pixelType = FormatTools.pixelTypeFromBytes(bytes, false, false);
                }
                if (bitCount != null) {
                    m.bitsPerPixel = Integer.parseInt(bitCount.getTextContent());
                }
            }
            Element length = getFirstChild(channelNode, "commonphase:length");
            Element pixelUnit = getFirstChild(channelNode, "commonphase:pixelUnit");
            if (length != null) {
                Element xLength = getFirstChild(length, "commonparam:x");
                Element xUnit = getFirstChild(pixelUnit, "commonphase:x");
                if (xLength != null) {
                    Double x = DataTools.parseDouble(xLength.getTextContent());
                    String unit = null;
                    if (xUnit != null) {
                        unit = xUnit.getTextContent();
                    }
                    physicalSizeX = FormatTools.getPhysicalSize(x, unit);
                }
                Element yLength = getFirstChild(length, "commonparam:y");
                Element yUnit = getFirstChild(pixelUnit, "commonphase:y");
                if (yLength != null) {
                    Double y = DataTools.parseDouble(yLength.getTextContent());
                    String unit = null;
                    if (yUnit != null) {
                        unit = yUnit.getTextContent();
                    }
                    physicalSizeY = FormatTools.getPhysicalSize(y, unit);
                }
                Element zLength = getFirstChild(length, "commonparam:z");
                Element zUnit = getFirstChild(pixelUnit, "commonphase:z");
                if (zLength != null) {
                    Double z = DataTools.parseDouble(zLength.getTextContent());
                    String unit = null;
                    if (zUnit != null) {
                        unit = zUnit.getTextContent();
                    }
                    physicalSizeZ = FormatTools.getPhysicalSize(z, unit);
                }
            }
            while (index > channels.size()) {
                channels.add(null);
            }
            if (index == channels.size()) {
                channels.add(c);
            } else {
                channels.set(index, c);
            }
        }
    }
    for (int i = 0; i < channels.size(); i++) {
        if (channels.get(i) == null) {
            channels.remove(i);
            i--;
        }
    }
    Element acquisition = getFirstChild(root, "commonimage:acquisition");
    if (acquisition == null) {
        acquisition = getFirstChild(root, "lsmimage:acquisition");
    }
    if (acquisition != null) {
        Element microscopeConfiguration = getFirstChild(acquisition, "commonimage:microscopeConfiguration");
        if (microscopeConfiguration != null) {
            NodeList objectiveLenses = microscopeConfiguration.getElementsByTagName("commonimage:objectiveLens");
            if (objectiveLenses != null) {
                for (int i = 0; i < objectiveLenses.getLength(); i++) {
                    Element lens = (Element) objectiveLenses.item(i);
                    Objective objective = new Objective();
                    Element lensName = getFirstChild(lens, "opticalelement:displayName");
                    Element magnification = getFirstChild(lens, "opticalelement:magnification");
                    Element na = getFirstChild(lens, "opticalelement:naValue");
                    Element wd = getFirstChild(lens, "opticalelement:wdValue");
                    Element refraction = getFirstChild(lens, "opticalelement:refraction");
                    Element immersion = getFirstChild(lens, "opticalelement:immersion");
                    if (lensName != null) {
                        objective.name = lensName.getTextContent();
                    }
                    if (magnification != null) {
                        objective.magnification = DataTools.parseDouble(magnification.getTextContent());
                    }
                    if (na != null) {
                        objective.na = DataTools.parseDouble(na.getTextContent());
                    }
                    if (wd != null) {
                        objective.wd = DataTools.parseDouble(wd.getTextContent());
                    }
                    if (refraction != null) {
                        objective.ri = DataTools.parseDouble(refraction.getTextContent());
                    }
                    if (immersion != null) {
                        objective.immersion = getImmersion(immersion.getTextContent());
                    }
                    objectives.add(objective);
                }
            }
        }
        Element imagingParam = getFirstChild(acquisition, "commonimage:imagingParam");
        if (imagingParam == null) {
            imagingParam = getFirstChild(acquisition, "lsmimage:imagingParam");
        }
        if (imagingParam != null) {
            NodeList axes = imagingParam.getElementsByTagName("commonparam:axis");
            if (axes != null) {
                for (int i = 0; i < axes.getLength(); i++) {
                    Element dimensionAxis = (Element) axes.item(i);
                    if (dimensionAxis.hasAttribute("enable") && dimensionAxis.getAttribute("enable").equals("true") && (!dimensionAxis.hasAttribute("paramEnable") || dimensionAxis.getAttribute("paramEnable").equals("true"))) {
                        parseAxis(dimensionAxis);
                    }
                }
            }
            NodeList pmts = imagingParam.getElementsByTagName("lsmparam:pmt");
            if (pmts != null) {
                for (int i = 0; i < pmts.getLength(); i++) {
                    Element pmt = (Element) pmts.item(i);
                    Detector detector = new Detector();
                    detector.id = pmt.getAttribute("detectorId");
                    detector.channelId = pmt.getAttribute("channelId");
                    Element voltage = getFirstChild(pmt, "lsmparam:voltage");
                    Element offset = getFirstChild(pmt, "lsmparam:offset");
                    Element gain = getFirstChild(pmt, "lsmparam:gain");
                    if (voltage != null) {
                        detector.voltage = DataTools.parseDouble(voltage.getTextContent());
                    }
                    if (offset != null) {
                        detector.offset = DataTools.parseDouble(offset.getTextContent());
                    }
                    if (gain != null) {
                        detector.gain = DataTools.parseDouble(gain.getTextContent());
                    }
                    detectors.add(detector);
                }
            }
            NodeList mainLasers = imagingParam.getElementsByTagName("lsmparam:mainLaser");
            if (mainLasers != null) {
                for (int i = 0; i < mainLasers.getLength(); i++) {
                    Element mainLaser = (Element) mainLasers.item(i);
                    String id = mainLaser.getAttribute("laserDataId");
                    Laser currentLaser = null;
                    for (int laser = 0; laser < lasers.size(); laser++) {
                        if (id.startsWith(lasers.get(laser).id)) {
                            currentLaser = lasers.get(laser);
                            break;
                        }
                    }
                    if (currentLaser == null) {
                        continue;
                    }
                    currentLaser.dataId = id;
                    Element power = getFirstChild(mainLaser, "commonparam:power");
                    Element transmissivity = getFirstChild(mainLaser, "commonparam:transmissivity");
                    if (power != null) {
                        currentLaser.power = DataTools.parseDouble(power.getTextContent());
                    }
                    if (transmissivity != null) {
                        currentLaser.transmissivity = DataTools.parseDouble(transmissivity.getTextContent());
                    }
                }
            }
            Element resolution = getFirstChild(imagingParam, "commonparam:pixelResolution");
            if (resolution != null) {
                Element x = getFirstChild(resolution, "commonparam:x");
                Element y = getFirstChild(resolution, "commonparam:y");
                Element z = getFirstChild(resolution, "commonparam:z");
                if (x != null && physicalSizeX == null) {
                    Double xValue = DataTools.parseDouble(x.getTextContent());
                    physicalSizeX = FormatTools.getPhysicalSize(xValue, null);
                }
                if (y != null && physicalSizeY == null) {
                    Double yValue = DataTools.parseDouble(y.getTextContent());
                    physicalSizeY = FormatTools.getPhysicalSize(yValue, null);
                }
                if (z != null && physicalSizeZ == null) {
                    Double zValue = DataTools.parseDouble(z.getTextContent());
                    physicalSizeZ = FormatTools.getPhysicalSize(zValue, null);
                }
            }
        }
        NodeList imagingMainLasers = acquisition.getElementsByTagName("lsmimage:imagingMainLaser");
        if (imagingMainLasers != null) {
            for (int i = 0; i < imagingMainLasers.getLength(); i++) {
                Element mainLaser = (Element) imagingMainLasers.item(i);
                String id = mainLaser.getAttribute("id");
                String enable = mainLaser.getAttribute("enable");
                if ("true".equals(enable)) {
                    Element wavelength = getFirstChild(mainLaser, "commonimage:wavelength");
                    if (wavelength != null) {
                        for (Laser l : lasers) {
                            if (id.equals(l.dataId)) {
                                l.wavelength = DataTools.parseDouble(wavelength.getTextContent());
                            }
                        }
                    }
                }
            }
        }
        NodeList channelLinkages = acquisition.getElementsByTagName("commonphase:channel");
        // if not, clear and re-populate the channel list
        for (int c = 0; c < channels.size(); c++) {
            String id = channels.get(c).id;
            boolean hasUID = false;
            for (String uid : pixelBlocks.keySet()) {
                if (uid.indexOf(id) >= 0) {
                    hasUID = true;
                    break;
                }
            }
            if (!hasUID) {
                channels.remove(c);
                c--;
            }
        }
        boolean appendChannels = channels.size() == 0;
        if (channelLinkages != null && channelLinkages.getLength() > 0) {
            for (int i = 0; i < channelLinkages.getLength(); i++) {
                Element channel = (Element) channelLinkages.item(i);
                parseChannel(channel, appendChannels);
            }
        } else {
            // so far seems to only be needed for the oldest (software version 1.2.x) files
            channelLinkages = acquisition.getElementsByTagName("lsmimage:channel");
            for (int i = 0; i < channelLinkages.getLength(); i++) {
                Element channel = (Element) channelLinkages.item(i);
                parseChannel(channel, appendChannels);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) Length(ome.units.quantity.Length)

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