Package loci.formats.tiff

Examples of loci.formats.tiff.IFD


  @Override
  public boolean isThisType(RandomAccessInputStream stream)
      throws IOException {
    TiffParser tiffParser = new TiffParser(stream);
    if (! tiffParser.isValidHeader()) return false;
    IFD ifd = tiffParser.getFirstIFD();
    if (ifd == null) return false;
    tiffParser.fillInIFD(ifd);
    for (int tag: MINIMAL_TAGS)
      try {
        if (ifd.getIFDStringValue(tag) == null) return false;
      } catch (FormatException e) {
        return false;
      }
    return true;
  }
View Full Code Here


      LOGGER.info("Populating metadata");

      /*
       * The first IFD contains file-scope metadata
       */
      final IFD ifd0 = tiffParser.getFirstIFD();
      tiffParser.fillInIFD(ifd0);
      final int channelCount = ifd0.getIFDIntValue(CHANNEL_COUNT_TAG);
      final String channelNamesString = ifd0.getIFDStringValue(CHANNEL_NAMES_TAG);
      channelNames = channelNamesString.split("\\|");
      if (channelNames.length != channelCount) {
        throw new FormatException(String.format(
            "Channel count (%d) does not match number of channel names (%d) in string \"%s\"",
            channelCount, channelNames.length, channelNamesString));
      }
      LOGGER.debug(String.format(
          "Found %d channels: %s",
          channelCount, channelNamesString.replace('|', ',')));
      final String channelDescsString = ifd0.getIFDStringValue(CHANNEL_DESCS_TAG);
      channelDescs =  channelDescsString.split("\\|");
      if (channelDescs.length != channelCount) {
        throw new FormatException(String.format(
            "Channel count (%d) does not match number of channel descriptions (%d) in string \"%s\"",
            channelCount, channelDescs.length, channelDescsString));
      }
      /*
       * Scan the remaining IFDs
       *
       * Unfortunately, each image can have a different width and height
       * and the images and masks have a different bit depth, so in the
       * OME scheme of things, we get one series per plane.
       */
      for (int idxOff=1; idxOff<ifdOffsets.length;idxOff++) {
        // TODO: Record the channel names
        final long offset = ifdOffsets[idxOff];
        final boolean first=(idxOff == 1);
        final IFD ifd = tiffParser.getIFD(offset);
        tiffParser.fillInIFD(ifd);
          CoreMetadata ms = first?core.get(0):new CoreMetadata();
          ms.rgb = false;
          ms.interleaved = false;
          ms.littleEndian = ifd0.isLittleEndian();
          ms.sizeX = (int) ifd.getImageWidth() / channelCount;
          ms.sizeY = (int) ifd.getImageLength();
          ms.sizeZ = 1;
          ms.sizeC = channelCount;
          ms.sizeT = 1;
          ms.indexed = false;
          ms.dimensionOrder = "XYCZT";
          ms.bitsPerPixel = ifd.getIFDIntValue(IFD.BITS_PER_SAMPLE);
          ms.pixelType = (ms.bitsPerPixel == 8)?FormatTools.UINT8:FormatTools.UINT16;
          ms.imageCount = channelCount;
          ms.resolutionCount = 1;
          ms.thumbnail = false;
          ms.metadataComplete = true;
View Full Code Here

      throws FormatException, IOException {
    if (no > getChannelCount()) {
      throw new FormatException("Only one plane per series");
    }
    final int idx = getSeries() + 1;
    final IFD ifd = tiffParser.getIFD(ifdOffsets[idx]);
    final int imageWidth = (int)(ifd.getImageWidth());
    final int imageHeight = (int)(ifd.getImageLength());
    final int wOff = x + no * imageWidth / getChannelCount();
    if ((y+h > imageHeight) || (x+w > imageWidth / getChannelCount()) ) {
      throw new FormatException("Requested tile dimensions extend beyond those of the image.");
    }
    final int compression = ifd.getIFDIntValue(IFD.COMPRESSION);
    byte [] tempBuffer; /* NB - these images are very small */
    switch(compression) {
    case GREYSCALE_COMPRESSION:
      tempBuffer = openGreyscaleBytes(ifd, imageWidth, imageHeight);
      break;
    case BITMASK_COMPRESSION:
      tempBuffer = openBitmaskBytes(ifd, imageWidth, imageHeight);
      break;
    default:
      throw new FormatException(String.format("Unknown compression code: %d", compression));
    }
    final int bytesPerSample = ifd.getIFDIntValue(IFD.BITS_PER_SAMPLE) / 8;
    for (int yy=y; yy<y+h; yy++) {
      final int srcOff = bytesPerSample * (wOff + yy * imageWidth);
      final int destOff = bytesPerSample * (yy-y) * w;
      System.arraycopy(tempBuffer, srcOff, buf, destOff, w * bytesPerSample);
    }
 
View Full Code Here

   */
  public void saveBytes(int no, byte[] buf, IFD ifd, int x, int y, int w, int h)
    throws IOException, FormatException
  {
    if (checkParams) checkParams(no, buf, x, y, w, h);
    if (ifd == null) ifd = new IFD();
    MetadataRetrieve retrieve = getMetadataRetrieve();
    int type = FormatTools.pixelTypeFromString(
        retrieve.getPixelsType(series).toString());
    int index = no;
    // This operation is synchronized
View Full Code Here

   * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int)
   */
  public void saveBytes(int no, byte[] buf, int x, int y, int w, int h)
    throws FormatException, IOException
  {
    IFD ifd = new IFD();
    if (!sequential) {
      TiffParser parser = new TiffParser(currentId);
      try {
        long[] ifdOffsets = parser.getIFDOffsets();
        if (no < ifdOffsets.length) {
View Full Code Here

        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 =
View Full Code Here

    in = new RandomAccessInputStream(file);
    boolean littleEndian = in.read() == TiffConstants.LITTLE;
    in.order(littleEndian);

    tiffParser = new TiffParser(in);
    IFD ifd = tiffParser.getFirstIFD();
    RandomAccessInputStream ras = getCZTag(ifd);
    if (ras == null) return 1;
    ras.order(littleEndian);

    ras.seek(264);
View Full Code Here

  }

  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);
View Full Code Here

TOP

Related Classes of loci.formats.tiff.IFD

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.