/**
   * Performs median filtering on a specified rectangle. The sources are cobbled.
   *
   * @param sources an array of source Rasters, guaranteed to provide all necessary source data for
   *     computing the output.
   * @param dest a WritableRaster tile containing the area to be computed.
   * @param destRect the rectangle within dest to be processed.
   */
  protected void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect) {
    Raster source = sources[0];
    Rectangle srcRect = mapDestRect(destRect, 0);

    int formatTag = MediaLibAccessor.findCompatibleTag(sources, dest);

    MediaLibAccessor srcAccessor = new MediaLibAccessor(source, srcRect, formatTag);
    MediaLibAccessor dstAccessor = new MediaLibAccessor(dest, destRect, formatTag);
    int numBands = getSampleModel().getNumBands();

    int cmask = (1 << numBands) - 1;
    mediaLibImage[] srcML = srcAccessor.getMediaLibImages();
    mediaLibImage[] dstML = dstAccessor.getMediaLibImages();
    for (int i = 0; i < dstML.length; i++) {
      switch (dstAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_INT:
          if (maskSize == 3) {
            // Call appropriate Medialib accelerated function
            Image.MinFilter3x3(dstML[i], srcML[i]);
          } else if (maskSize == 5) {
            // Call appropriate Medialib accelerated function
            Image.MinFilter5x5(dstML[i], srcML[i]);
          } else if (maskSize == 7) {
            // Call appropriate Medialib accelerated function
            Image.MinFilter7x7(dstML[i], srcML[i]);
          }

          break;
        case DataBuffer.TYPE_FLOAT:
        case DataBuffer.TYPE_DOUBLE:
          if (maskSize == 3) {
            // Call appropriate Medialib accelerated function
            Image.MinFilter3x3_Fp(dstML[i], srcML[i]);
          } else if (maskSize == 5) {
            // Call appropriate Medialib accelerated function
            Image.MinFilter5x5_Fp(dstML[i], srcML[i]);
          } else if (maskSize == 7) {
            // Call appropriate Medialib accelerated function
            Image.MinFilter7x7_Fp(dstML[i], srcML[i]);
          }
          break;
        default:
          String className = this.getClass().getName();
          throw new RuntimeException(JaiI18N.getString("Generic2"));
      }
    }

    if (dstAccessor.isDataCopy()) {
      dstAccessor.copyDataToRaster();
    }
  }
Esempio n. 2
0
  /** Renders a "Mosaic" operation node. */
  public RenderedImage create(ParameterBlock paramBlock, RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

    // Return if not mediaLib-compatible.
    if (!MediaLibAccessor.isMediaLibCompatible(paramBlock, layout)
        || !MediaLibAccessor.hasSameNumBands(paramBlock, layout)) {
      return null;
    }

    // Get sources.
    Vector sources = paramBlock.getSources();

    // Get target SampleModel.
    SampleModel targetSM = null;
    if (sources.size() > 0) {
      targetSM = ((RenderedImage) sources.get(0)).getSampleModel();
    } else if (layout != null && layout.isValid(ImageLayout.SAMPLE_MODEL_MASK)) {
      targetSM = layout.getSampleModel(null);
    }

    if (targetSM != null) {
      // Return if target data type is floating point. Other more
      // extensive type checking is done in MosaicOpImage constructor.
      int dataType = targetSM.getDataType();
      if (dataType == DataBuffer.TYPE_FLOAT || dataType == DataBuffer.TYPE_DOUBLE) {
        return null;
      }
    }

    return new MlibMosaicOpImage(
        sources,
        layout,
        renderHints,
        (MosaicType) paramBlock.getObjectParameter(0),
        (PlanarImage[]) paramBlock.getObjectParameter(1),
        (ROI[]) paramBlock.getObjectParameter(2),
        (double[][]) paramBlock.getObjectParameter(3),
        (double[]) paramBlock.getObjectParameter(4));
  }
Esempio n. 3
0
  /**
   * Creates a new instance of <code>MlibWarpOpImage</code> in the rendered image mode.
   *
   * @param args The source images.
   * @param hints May contain rendering hints and destination image layout.
   */
  public RenderedImage create(ParameterBlock args, RenderingHints hints) {
    /* Get ImageLayout and TileCache from RenderingHints. */
    ImageLayout layout = RIFUtil.getImageLayoutHint(hints);

    RenderedImage source = args.getRenderedSource(0);

    if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
        || !MediaLibAccessor.hasSameNumBands(args, layout)
        ||
        // Medialib cannot deal with source image having tiles with any
        // dimension greater than or equal to 32768
        source.getTileWidth() >= 32768
        || source.getTileHeight() >= 32768) {
      return null;
    }

    /* Get BorderExtender from hints if any. */
    BorderExtender extender = RIFUtil.getBorderExtenderHint(hints);

    Warp warp = (Warp) args.getObjectParameter(0);
    Interpolation interp = (Interpolation) args.getObjectParameter(1);
    double[] backgroundValues = (double[]) args.getObjectParameter(2);

    int filter = -1;
    if (interp instanceof InterpolationNearest) {
      filter = Constants.MLIB_NEAREST;
    } else if (interp instanceof InterpolationBilinear) {
      filter = Constants.MLIB_BILINEAR;
    } else if (interp instanceof InterpolationBicubic) {
      filter = Constants.MLIB_BICUBIC;
    } else if (interp instanceof InterpolationBicubic2) {
      filter = Constants.MLIB_BICUBIC2;
    } else if (interp instanceof InterpolationTable) {;
      // filter =  Constants.MLIB_TABLE; not defined yet;
    } else {
      /* Other kinds of interpolation cannot be handled via mlib. */
      return null;
    }

    if (warp instanceof WarpGrid) {
      if (interp instanceof InterpolationTable) {
        return new MlibWarpGridTableOpImage(
            source, extender, hints, layout, (WarpGrid) warp, interp, backgroundValues);
      } else {
        return new MlibWarpGridOpImage(
            source, extender, hints, layout, (WarpGrid) warp, interp, filter, backgroundValues);
      }

    } else if (warp instanceof WarpPolynomial) {
      if (interp instanceof InterpolationTable) {
        return new MlibWarpPolynomialTableOpImage(
            source, extender, hints, layout, (WarpPolynomial) warp, interp, backgroundValues);
      } else {
        return new MlibWarpPolynomialOpImage(
            source,
            extender,
            hints,
            layout,
            (WarpPolynomial) warp,
            interp,
            filter,
            backgroundValues);
      }
    } else {
      return null;
    }
  }