示例#1
0
文件: AffineRed.java 项目: srnsw/xena
  public AffineRed(CachableRed src, AffineTransform src2me, RenderingHints hints) {
    super(); // We _must_ call init...

    this.src2me = src2me;
    this.hints = hints;

    try {
      me2src = src2me.createInverse();
    } catch (NoninvertibleTransformException nite) {
      me2src = null;
    }

    // Calculate my bounds by applying the affine transform to
    // my input data..codec/
    Rectangle srcBounds = src.getBounds();
    // srcBounds.grow(-1,-1);
    Rectangle myBounds;
    myBounds = src2me.createTransformedShape(srcBounds).getBounds();

    // If the output buffer is not premultiplied in certain cases it
    // fails to properly divide out the Alpha (it always does
    // the affine on premultiplied data), hence you get ugly
    // back aliasing effects...
    ColorModel cm = fixColorModel(src);

    // fix my sample model so it makes sense given my size.
    SampleModel sm = fixSampleModel(src, cm, myBounds);

    Point2D pt = new Point2D.Float(src.getTileGridXOffset(), src.getTileGridYOffset());
    pt = src2me.transform(pt, null);

    // Finish initializing our base class...
    init(src, myBounds, cm, sm, (int) pt.getX(), (int) pt.getY(), null);
  }
示例#2
0
 /**
  * Multiply the alpha of one image with a mask image. The size of the resultant image is the
  * intersection of the two image bounds. If you want the end image to be the size of one or the
  * other please use the PadRed operator.
  *
  * @param src The image to convert to multiply the alpha of
  * @param alpha The mask image to multiply the alpha channel of src with.
  */
 public MultiplyAlphaRed(CachableRed src, CachableRed alpha) {
   super(
       makeList(src, alpha),
       makeBounds(src, alpha),
       fixColorModel(src),
       fixSampleModel(src),
       src.getTileGridXOffset(),
       src.getTileGridYOffset(),
       null);
 }
示例#3
0
 /**
  * Construct an instance of TranslateRed
  *
  * @param xloc The new x coordinate of cr.getMinX().
  * @param yloc The new y coordinate of cr.getMinY().
  */
 public TranslateRed(CachableRed cr, int xloc, int yloc) {
   super(
       cr,
       new Rectangle(xloc, yloc, cr.getWidth(), cr.getHeight()),
       cr.getColorModel(),
       cr.getSampleModel(),
       cr.getTileGridXOffset() + xloc - cr.getMinX(),
       cr.getTileGridYOffset() + yloc - cr.getMinY(),
       null);
   deltaX = xloc - cr.getMinX();
   deltaY = yloc - cr.getMinY();
 }
示例#4
0
  /**
   * Construct a blurred version of <tt>src</tt>, by blurring with a gaussian kernel with standard
   * Deviation of <tt>stdDev</tt> pixels.
   *
   * @param src The source image to blur
   * @param stdDevX The Standard Deviation of the Gaussian kernel in X
   * @param stdDevY The Standard Deviation of the Gaussian kernel in Y
   * @param rh Rendering hints.
   */
  public GaussianBlurRed8Bit(CachableRed src, double stdDevX, double stdDevY, RenderingHints rh) {
    super(); // Remember to call super.init()

    this.stdDevX = stdDevX;
    this.stdDevY = stdDevY;
    this.hints = rh;

    xinset = surroundPixels(stdDevX, rh);
    yinset = surroundPixels(stdDevY, rh);

    Rectangle myBounds = src.getBounds();
    myBounds.x += xinset;
    myBounds.y += yinset;
    myBounds.width -= 2 * xinset;
    myBounds.height -= 2 * yinset;
    if ((myBounds.width <= 0) || (myBounds.height <= 0)) {
      myBounds.width = 0;
      myBounds.height = 0;
    }

    ColorModel cm = fixColorModel(src);
    SampleModel sm = src.getSampleModel();
    int tw = sm.getWidth();
    int th = sm.getHeight();
    if (tw > myBounds.width) tw = myBounds.width;
    if (th > myBounds.height) th = myBounds.height;
    sm = cm.createCompatibleSampleModel(tw, th);

    init(
        src,
        myBounds,
        cm,
        sm,
        src.getTileGridXOffset() + xinset,
        src.getTileGridYOffset() + yinset,
        null);

    boolean highQuality =
        ((hints != null)
            && RenderingHints.VALUE_RENDER_QUALITY.equals(hints.get(RenderingHints.KEY_RENDERING)));

    // System.out.println("StdDev: " + stdDevX + "x" + stdDevY);
    if ((xinset != 0) && ((stdDevX < 2) || highQuality))
      convOp[0] = new ConvolveOp(makeQualityKernelX(xinset * 2 + 1));
    else dX = (int) Math.floor(DSQRT2PI * stdDevX + 0.5f);

    if ((yinset != 0) && ((stdDevY < 2) || highQuality))
      convOp[1] = new ConvolveOp(makeQualityKernelY(yinset * 2 + 1));
    else dY = (int) Math.floor(DSQRT2PI * stdDevY + 0.5f);
  }
示例#5
0
  /**
   * Construct a luminace image from src.
   *
   * @param src The image to convert to a luminance image
   */
  public Any2LsRGBRed(CachableRed src) {
    super(
        src,
        src.getBounds(),
        fixColorModel(src),
        fixSampleModel(src),
        src.getTileGridXOffset(),
        src.getTileGridYOffset(),
        null);

    ColorModel srcCM = src.getColorModel();
    if (srcCM == null) return;
    ColorSpace srcCS = srcCM.getColorSpace();
    if (srcCS == ColorSpace.getInstance(ColorSpace.CS_sRGB)) srcIssRGB = true;
  }
示例#6
0
  /**
   * Construct A Rendered Pad operation. If the pad is smaller than the original image size then
   * this devolves to a Crop.
   *
   * @param src The image to pad/crop
   * @param bounds The bounds of the result (same coord system as src).
   * @param padMode The pad mode to use (currently ignored).
   * @param hints The hints to use for drawing 'pad' area.
   */
  public PadRed(CachableRed src, Rectangle bounds, PadMode padMode, RenderingHints hints) {
    super(src, bounds, src.getColorModel(), fixSampleModel(src, bounds), bounds.x, bounds.y, null);

    this.padMode = padMode;

    if (DEBUG) {
      System.out.println(
          "Src: "
              + src
              + " Bounds: "
              + bounds
              + " Off: "
              + src.getTileGridXOffset()
              + ", "
              + src.getTileGridYOffset());
    }
    this.hints = hints;
  }