Package loci.formats.tiff

Examples of loci.formats.tiff.IFDList


      in = new RandomAccessInputStream(getLSMFileFromSeries(getSeries()));
      in.order(!isLittleEndian());
      tiffParser = new TiffParser(in);
    }

    IFDList ifds = ifdsList.get(getSeries());

    if (splitPlanes && getSizeC() > 1 && ifds.size() == getSizeZ() * getSizeT())
    {
      int bpp = FormatTools.getBytesPerPixel(getPixelType());
      int plane = no / getSizeC();
      int c = no % getSizeC();
      Region region = new Region(x, y, w, h);

      if (prevPlane != plane || prevBuf == null ||
        prevBuf.length < w * h * bpp * getSizeC() || !region.equals(prevRegion))
      {
        prevBuf = new byte[w * h * bpp * getSizeC()];
        tiffParser.getSamples(ifds.get(plane), prevBuf, x, y, w, h);
        prevPlane = plane;
        prevRegion = region;
      }
      ImageTools.splitChannels(
        prevBuf, buf, c, getSizeC(), bpp, false, false, w * h * bpp);
      prevChannel = c;
    }
    else {
      tiffParser.getSamples(ifds.get(no), buf, x, y, w, h);
      prevChannel = getZCTCoords(no)[1];
    }
    if (getSeriesCount() > 1) in.close();
    return buf;
  }
View Full Code Here


      Object zeissTag = null;
      for (int s=0; s<count; s++, realSeries++) {
        CoreMetadata ms = core.get(realSeries);
        ms.littleEndian = littleEndian;

        IFDList ifds = new IFDList();
        while (ifds.size() < ifdsPerSeries) {
          tp.setDoCaching(offset == 0);
          IFD ifd = tp.getIFD(ifdOffsets[offset]);
          if (offset == 0) zeissTag = ifd.get(ZEISS_ID);
          if (offset > 0 && ifds.size() == 0) {
            ifd.putIFDValue(ZEISS_ID, zeissTag);
          }
          ifds.add(ifd);
          if (zeissTag != null) offset += 2;
          else offset++;
        }

        for (IFD ifd : ifds) {
          tp.fillInIFD(ifd);
        }

        ifdsList.set(realSeries, ifds);
      }
      stream.close();
    }

    MetadataStore store = makeFilterMetadata();

    lut = new byte[ifdsList.size()][][];

    long[] previousStripOffsets = null;

    for (int series=0; series<ifdsList.size(); series++) {
      // IFD ordering is ZPT, so reset state if we have multiple timepoints
      // this prevents offsets from being confused when the first offset in
      // the next series is legitimately smaller than the last offset in
      // the previous series
      if (series > 0 && getSizeT() > 1) {
        previousStripOffsets = null;
      }

      IFDList ifds = ifdsList.get(series);
      for (IFD ifd : ifds) {
        // check that predictor is set to 1 if anything other
        // than LZW compression is used
        if (ifd.getCompression() != TiffCompression.LZW) {
          ifd.putIFDValue(IFD.PREDICTOR, 1);
        }
      }

      // fix the offsets for > 4 GB files
      RandomAccessInputStream s =
        new RandomAccessInputStream(getLSMFileFromSeries(series));
      for (int i=0; i<ifds.size(); i++) {
        long[] stripOffsets = ifds.get(i).getStripOffsets();

        if (stripOffsets == null || (i != 0 && previousStripOffsets == null)) {
          throw new FormatException(
            "Strip offsets are missing; this is an invalid file.");
        }
        else if (i == 0 && previousStripOffsets == null) {
          previousStripOffsets = stripOffsets;
          continue;
        }

        boolean neededAdjustment = false;
        for (int j=0; j<stripOffsets.length; j++) {
          if (j >= previousStripOffsets.length) break;
          if (stripOffsets[j] < previousStripOffsets[j]) {
            stripOffsets[j] = (previousStripOffsets[j] & ~0xffffffffL) |
              (stripOffsets[j] & 0xffffffffL);
            if (stripOffsets[j] < previousStripOffsets[j]) {
              long newOffset = stripOffsets[j] + 0x100000000L;
              if (newOffset < s.length()) {
                stripOffsets[j] = newOffset;
              }
            }
            neededAdjustment = true;
          }
          if (neededAdjustment) {
            ifds.get(i).putIFDValue(IFD.STRIP_OFFSETS, stripOffsets);
          }
        }
        previousStripOffsets = stripOffsets;
      }
      s.close();
View Full Code Here

    return ras;
  }

  protected void initMetadata(int series) throws FormatException, IOException {
    setSeries(series);
    IFDList ifds = ifdsList.get(series);
    IFD ifd = ifds.get(0);

    in.close();
    in = new RandomAccessInputStream(getLSMFileFromSeries(series));
    in.order(isLittleEndian());

    tiffParser = new TiffParser(in);

    PhotoInterp photo = ifd.getPhotometricInterpretation();
    int samples = ifd.getSamplesPerPixel();

    CoreMetadata ms = core.get(series);
    ms.sizeX = (int) ifd.getImageWidth();
    ms.sizeY = (int) ifd.getImageLength();
    ms.rgb = samples > 1 || photo == PhotoInterp.RGB;
    ms.interleaved = false;
    ms.sizeC = isRGB() ? samples : 1;
    ms.pixelType = ifd.getPixelType();
    ms.imageCount = ifds.size();
    ms.sizeZ = getImageCount();
    ms.sizeT = 1;

    LOGGER.info("Reading LSM metadata for series #{}", series);

    MetadataStore store = makeFilterMetadata();

    int instrument = getEffectiveSeries(series);

    String imageName = getLSMFileFromSeries(series);
    if (imageName.indexOf(".") != -1) {
      imageName = imageName.substring(0, imageName.lastIndexOf("."));
    }
    if (imageName.indexOf(File.separator) != -1) {
      imageName =
        imageName.substring(imageName.lastIndexOf(File.separator) + 1);
    }
    if (lsmFilenames.length != getSeriesCount()) {
      imageName += " #" + (getPosition(series) + 1);
    }

    // link Instrument and Image
    store.setImageID(MetadataTools.createLSID("Image", series), series);
    String instrumentID = MetadataTools.createLSID("Instrument", instrument);
    store.setInstrumentID(instrumentID, instrument);
    store.setImageInstrumentRef(instrumentID, series);

    RandomAccessInputStream ras = getCZTag(ifd);
    if (ras == null) {
      imageNames.add(imageName);
      return;
    }

    ras.seek(16);

    ms.sizeZ = ras.readInt();
    ras.skipBytes(4);
    ms.sizeT = ras.readInt();

    int dataType = ras.readInt();
    switch (dataType) {
      case 2:
        addSeriesMeta("DataType", "12 bit unsigned integer");
        break;
      case 5:
        addSeriesMeta("DataType", "32 bit float");
        break;
      case 0:
        addSeriesMeta("DataType", "varying data types");
        break;
      default:
        addSeriesMeta("DataType", "8 bit unsigned integer");
    }

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      ras.seek(0);
      addSeriesMeta("MagicNumber ", ras.readInt());
      addSeriesMeta("StructureSize", ras.readInt());
      addSeriesMeta("DimensionX", ras.readInt());
      addSeriesMeta("DimensionY", ras.readInt());

      ras.seek(32);
      addSeriesMeta("ThumbnailX", ras.readInt());
      addSeriesMeta("ThumbnailY", ras.readInt());

      // pixel sizes are stored in meters, we need them in microns
      pixelSizeX = ras.readDouble() * 1000000;
      pixelSizeY = ras.readDouble() * 1000000;
      pixelSizeZ = ras.readDouble() * 1000000;

      addSeriesMeta("VoxelSizeX", new Double(pixelSizeX));
      addSeriesMeta("VoxelSizeY", new Double(pixelSizeY));
      addSeriesMeta("VoxelSizeZ", new Double(pixelSizeZ));

      originX = ras.readDouble() * 1000000;
      originY = ras.readDouble() * 1000000;
      originZ = ras.readDouble() * 1000000;

      addSeriesMeta("OriginX", originX);
      addSeriesMeta("OriginY", originY);
      addSeriesMeta("OriginZ", originZ);
    }
    else ras.seek(88);

    int scanType = ras.readShort();
    switch (scanType) {
      case 0:
        addSeriesMeta("ScanType", "x-y-z scan");
        ms.dimensionOrder = "XYZCT";
        break;
      case 1:
        addSeriesMeta("ScanType", "z scan (x-z plane)");
        ms.dimensionOrder = "XYZCT";
        break;
      case 2:
        addSeriesMeta("ScanType", "line scan");
        ms.dimensionOrder = "XYZCT";
        break;
      case 3:
        addSeriesMeta("ScanType", "time series x-y");
        ms.dimensionOrder = "XYTCZ";
        break;
      case 4:
        addSeriesMeta("ScanType", "time series x-z");
        ms.dimensionOrder = "XYZTC";
        break;
      case 5:
        addSeriesMeta("ScanType", "time series 'Mean of ROIs'");
        ms.dimensionOrder = "XYTCZ";
        break;
      case 6:
        addSeriesMeta("ScanType", "time series x-y-z");
        ms.dimensionOrder = "XYZTC";
        break;
      case 7:
        addSeriesMeta("ScanType", "spline scan");
        ms.dimensionOrder = "XYCTZ";
        break;
      case 8:
        addSeriesMeta("ScanType", "spline scan x-z");
        ms.dimensionOrder = "XYCZT";
        break;
      case 9:
        addSeriesMeta("ScanType", "time series spline plane x-z");
        ms.dimensionOrder = "XYTCZ";
        break;
      case 10:
        addSeriesMeta("ScanType", "point mode");
        ms.dimensionOrder = "XYZCT";
        break;
      default:
        addSeriesMeta("ScanType", "x-y-z scan");
        ms.dimensionOrder = "XYZCT";
    }

    ms.indexed = lut != null && lut[series] != null;
    if (isIndexed()) {
      ms.rgb = false;
    }
    if (getSizeC() == 0) ms.sizeC = 1;

    if (isRGB()) {
      // shuffle C to front of order string
      ms.dimensionOrder = getDimensionOrder().replaceAll("C", "");
      ms.dimensionOrder = getDimensionOrder().replaceAll("XY", "XYC");
    }

    if (getEffectiveSizeC() == 0) {
      ms.imageCount = getSizeZ() * getSizeT();
    }
    else {
      ms.imageCount = getSizeZ() * getSizeT() * getEffectiveSizeC();
    }

    if (getImageCount() != ifds.size()) {
      int diff = getImageCount() - ifds.size();
      ms.imageCount = ifds.size();
      if (diff % getSizeZ() == 0) {
        ms.sizeT -= (diff / getSizeZ());
      }
      else if (diff % getSizeT() == 0) {
        ms.sizeZ -= (diff / getSizeT());
      }
      else if (getSizeZ() > 1) {
        ms.sizeZ = ifds.size();
        ms.sizeT = 1;
      }
      else if (getSizeT() > 1) {
        ms.sizeT = ifds.size();
        ms.sizeZ = 1;
      }
    }

    if (getSizeZ() == 0) ms.sizeZ = getImageCount();
View Full Code Here

TOP

Related Classes of loci.formats.tiff.IFDList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.