Examples of MetadataRetrieve


Examples of loci.formats.meta.MetadataRetrieve

   * depth, compression and units.
   */
  public void saveBytes(int no, byte[] buf, IFD ifd)
    throws IOException, FormatException
  {
    MetadataRetrieve r = getMetadataRetrieve();
    int w = r.getPixelsSizeX(series).getValue().intValue();
    int h = r.getPixelsSizeY(series).getValue().intValue();
    saveBytes(no, buf, ifd, 0, 0, w, h);
  }
View Full Code Here

Examples of loci.formats.meta.MetadataRetrieve

  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
    synchronized (this) {
      // This operation is synchronized against the TIFF saver.
      synchronized (tiffSaver) {
        index = prepareToWriteImage(no, buf, ifd, x, y, w, h);
        if (index == -1) {
          return;
        }
      }
    }

    tiffSaver.writeImage(buf, ifd, index, type, x, y, w, h,
      no == getPlaneCount() - 1 && getSeries() == retrieve.getImageCount() - 1);
  }
View Full Code Here

Examples of loci.formats.meta.MetadataRetrieve

   * ensure thread safety.
   */
  private int prepareToWriteImage(
      int no, byte[] buf, IFD ifd, int x, int y, int w, int h)
  throws IOException, FormatException {
    MetadataRetrieve retrieve = getMetadataRetrieve();
    Boolean bigEndian = retrieve.getPixelsBinDataBigEndian(series, 0);
    boolean littleEndian = bigEndian == null ?
      false : !bigEndian.booleanValue();

    // Ensure that no more than one thread manipulated the initialized array
    // at one time.
    synchronized (this) {
      if (no < initialized[series].length && !initialized[series][no]) {
        initialized[series][no] = true;

        RandomAccessInputStream tmp = new RandomAccessInputStream(currentId);
        if (tmp.length() == 0) {
          synchronized (this) {
            // write TIFF header
            tiffSaver.writeHeader();
          }
        }
        tmp.close();
      }
    }

    int c = getSamplesPerPixel();
    int type = FormatTools.pixelTypeFromString(
      retrieve.getPixelsType(series).toString());
    int bytesPerPixel = FormatTools.getBytesPerPixel(type);

    int blockSize = w * h * c * bytesPerPixel;
    if (blockSize > buf.length) {
      c = buf.length / (w * h * bytesPerPixel);
    }

    if (bytesPerPixel > 1 && c != 1 && c != 3) {
      // split channels
      checkParams = false;

      if (no == 0) {
        initialized[series] = new boolean[initialized[series].length * c];
      }

      for (int i=0; i<c; i++) {
        byte[] b = ImageTools.splitChannels(buf, i, c, bytesPerPixel,
          false, interleaved);

        saveBytes(no * c + i, b, (IFD) ifd.clone(), x, y, w, h);
      }
      checkParams = true;
      return -1;
    }

    formatCompression(ifd);
    byte[][] lut = (cm == null)?null:AWTImageTools.get8BitLookupTable(cm);
    if (lut != null) {
      int[] colorMap = new int[lut.length * lut[0].length];
      for (int i=0; i<lut.length; i++) {
        for (int j=0; j<lut[0].length; j++) {
          colorMap[i * lut[0].length + j] = (int) ((lut[i][j] & 0xff) << 8);
        }
      }
      ifd.putIFDValue(IFD.COLOR_MAP, colorMap);
    }

    int width = retrieve.getPixelsSizeX(series).getValue().intValue();
    int height = retrieve.getPixelsSizeY(series).getValue().intValue();
    ifd.put(new Integer(IFD.IMAGE_WIDTH), new Long(width));
    ifd.put(new Integer(IFD.IMAGE_LENGTH), new Long(height));

    PositiveFloat px = retrieve.getPixelsPhysicalSizeX(series);
    Double physicalSizeX = px == null ? null : px.getValue();
    if (physicalSizeX == null || physicalSizeX.doubleValue() == 0) {
      physicalSizeX = 0d;
    }
    else physicalSizeX = 1d / physicalSizeX;

    PositiveFloat py = retrieve.getPixelsPhysicalSizeY(series);
    Double physicalSizeY = py == null ? null : py.getValue();
    if (physicalSizeY == null || physicalSizeY.doubleValue() == 0) {
      physicalSizeY = 0d;
    }
    else physicalSizeY = 1d / physicalSizeY;
View Full Code Here

Examples of loci.formats.meta.MetadataRetrieve

    }
  }

  /* @see loci.formats.FormatWriter#getPlaneCount() */
  public int getPlaneCount() {
    MetadataRetrieve retrieve = getMetadataRetrieve();
    int c = getSamplesPerPixel();
    int type = FormatTools.pixelTypeFromString(
      retrieve.getPixelsType(series).toString());
    int bytesPerPixel = FormatTools.getBytesPerPixel(type);

    if (bytesPerPixel > 1 && c != 1 && c != 3) {
      return super.getPlaneCount() * c;
    }
View Full Code Here

Examples of loci.formats.meta.MetadataRetrieve

  private void setupTiffSaver() throws IOException {
    out.close();
    out = new RandomAccessOutputStream(currentId);
    tiffSaver = new TiffSaver(out, currentId);

    MetadataRetrieve retrieve = getMetadataRetrieve();
    Boolean bigEndian = retrieve.getPixelsBinDataBigEndian(series, 0);
    boolean littleEndian = bigEndian == null ?
      false : !bigEndian.booleanValue();

    tiffSaver.setWritingSequentially(sequential);
    tiffSaver.setLittleEndian(littleEndian);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.