예제 #1
0
  /**
   * Returns a tile for reading.
   *
   * @param tileX The X index of the tile.
   * @param tileY The Y index of the tile.
   * @return The tile as a <code>Raster</code>.
   */
  public Raster computeTile(int tileX, int tileY) {
    // STATISTICAL ELABORATIONS
    // selection of the format tags
    RasterFormatTag[] formatTags = getFormatTags();
    // Selection of the RasterAccessor parameters
    Raster source = getSourceImage(0).getTile(tileX, tileY);
    // Control if the Period is bigger than the tile dimension, in that case, the
    // statistics are not updated
    if (xPeriod > getTileWidth() || yPeriod > getTileHeight()) {
      return source;
    }

    Rectangle srcRect = getSourceImage(0).getBounds().intersection(source.getBounds());
    // creation of the RasterAccessor
    RasterAccessor src =
        new RasterAccessor(source, srcRect, formatTags[0], getSourceImage(0).getColorModel());

    // ROI calculations if roiAccessor is used
    RasterAccessor roi = null;
    RandomIter roiIter = null;
    if (useROIAccessor) {
      // Note that the getExtendedData() method is not called because the input images are padded.
      // For each image there is a check if the rectangle is contained inside the source image;
      // if this not happen, the data is taken from the padded image.
      Raster roiRaster = null;
      if (srcROIImage.getBounds().contains(srcRect)) {
        roiRaster = srcROIImage.getData(srcRect);
      } else {
        roiRaster = srcROIImgExt.getData(srcRect);
      }

      // creation of the rasterAccessor
      roi =
          new RasterAccessor(
              roiRaster,
              srcRect,
              RasterAccessor.findCompatibleTags(new RenderedImage[] {srcROIImage}, srcROIImage)[0],
              srcROIImage.getColorModel());
    } else if (hasROI) {
      roiIter = RandomIterFactory.create(srcROIImage, srcROIImage.getBounds(), true, true);
    }

    // Computation of the statistics
    switch (src.getDataType()) {
      case DataBuffer.TYPE_BYTE:
        byteLoop(src, srcRect, roi, stats, roiIter);
        break;
      case DataBuffer.TYPE_USHORT:
        ushortLoop(src, srcRect, roi, stats, roiIter);
        break;
      case DataBuffer.TYPE_SHORT:
        shortLoop(src, srcRect, roi, stats, roiIter);
        break;
      case DataBuffer.TYPE_INT:
        intLoop(src, srcRect, roi, stats, roiIter);
        break;
      case DataBuffer.TYPE_FLOAT:
        floatLoop(src, srcRect, roi, stats, roiIter);
        break;
      case DataBuffer.TYPE_DOUBLE:
        doubleLoop(src, srcRect, roi, stats, roiIter);
        break;
    }

    return source;
  }
예제 #2
0
  public TiledImage cutFrame(
      RenderedImage image,
      double resdpi,
      int frameWidthPix,
      int frameHeightPix,
      boolean reverseImage,
      int frameNum,
      double scaleMult,
      boolean rescale,
      boolean correctrotation) {
    noCut = false;
    if (farEdge == null || farEdge.stdDev > worstEdgeStdDevAllowed) {
      System.out.println(
          "WARNING: far film edge for frame "
              + frameNum
              + " has a stdDev of "
              + (farEdge == null ? "null" : Double.toString(farEdge.stdDev))
              + " and will not be used.");

      if (sprocketEdge == null || sprocketEdge.stdDev > worstEdgeStdDevAllowed) {
        System.out.println(
            "WARNING: near film edge for frame "
                + frameNum
                + " has a stdDev of "
                + (sprocketEdge == null ? "null" : Double.toString(sprocketEdge.stdDev))
                + " and will not be used.");
        noCut = true;
        return null;
      } else
        preMapSetupUsingSprocketEdge(
            frameWidthPix, frameHeightPix, scaleMult, reverseImage, rescale, correctrotation);
    } else
      preMapSetupUsingFarEdge(
          frameWidthPix, frameHeightPix, scaleMult, reverseImage, rescale, correctrotation);

    outOfBounds = false;

    //      double resdpmm = resdpi / FilmSpec.mmPerInch;
    //      double [] spec = FilmSpec.filmModel(filmType);

    TiledImage ret =
        new TiledImage(
            0,
            0,
            frameWidthPix,
            frameHeightPix,
            0,
            0,
            image.getSampleModel().createCompatibleSampleModel(frameWidthPix, frameHeightPix),
            image.getColorModel());

    RenderedImage[] srcs = new RenderedImage[1];
    srcs[0] = image;
    RasterFormatTag[] tags = RasterAccessor.findCompatibleTags(srcs, ret);
    RasterFormatTag srctag = tags[0];
    RasterFormatTag dsttag = tags[1];

    Raster srcraster = image.getData();
    RasterAccessor srcra =
        new RasterAccessor(srcraster, srcraster.getBounds(), srctag, image.getColorModel());

    Raster dstraster = ret.getWritableTile(0, 0);
    RasterAccessor dstra =
        new RasterAccessor(dstraster, dstraster.getBounds(), dsttag, ret.getColorModel());

    int srcwidth = srcra.getWidth();
    int srcheight = srcra.getHeight();
    //      int srcbandcount = srcra.getNumBands();
    byte bandedsrc[][] = srcra.getByteDataArrays();
    int srcBandOffsets[] = srcra.getBandOffsets();
    int srcPixelStride = srcra.getPixelStride();
    int srcScanLineStride = srcra.getScanlineStride();

    int dstwidth = dstra.getWidth();
    int dstheight = dstra.getHeight();
    int dstbandcount = dstra.getNumBands();
    byte bandeddst[][] = dstra.getByteDataArrays();
    int dstBandOffsets[] = dstra.getBandOffsets();
    int dstPixelStride = dstra.getPixelStride();
    int dstScanLineStride = dstra.getScanlineStride();

    for (int band = 0; band < dstbandcount; band++) {
      byte dst[] = bandeddst[band];
      byte src[] = bandedsrc[band];
      int srcBegCurBand = srcBandOffsets[band];
      int dstBegCurRow = dstBandOffsets[band];
      for (int dstRow = 0; dstRow < dstheight; dstRow++) {
        int dstpos = dstBegCurRow;

        for (int dstCol = 0; dstCol < dstwidth; dstCol++) {
          Point srclocation = map(dstRow, dstCol, frameWidthPix, frameHeightPix, reverseImage);

          if (leftmostCol > srclocation.x) leftmostCol = srclocation.x;
          if (rightmostCol < srclocation.x) rightmostCol = srclocation.x;
          if (topmostRow > srclocation.y) topmostRow = srclocation.y;
          if (bottommostRow < srclocation.y) bottommostRow = srclocation.y;

          if (srclocation.y < 0
              || srclocation.y >= srcheight
              || srclocation.x < 0
              || srclocation.x >= srcwidth) {
            dst[dstpos] = (byte) 0;
            outOfBounds = true;
          } else
            dst[dstpos] =
                src[
                    srcBegCurBand
                        + ((srclocation.y * srcScanLineStride) + (srclocation.x * srcPixelStride))];

          dstpos += dstPixelStride;
        }

        dstBegCurRow += dstScanLineStride;
      }
    }

    frameCut = true;
    return ret;
  }