Search in sources :

Example 1 with BorderExtender

use of javax.media.jai.BorderExtender in project Lucee by lucee.

the class Image method rotate.

public void rotate(float x, float y, float angle, int interpolation) throws ExpressionException {
    if (x == -1)
        x = (float) getWidth() / 2;
    if (y == -1)
        y = (float) getHeight() / 2;
    angle = (float) Math.toRadians(angle);
    ColorModel cmSource = image().getColorModel();
    if (cmSource instanceof IndexColorModel && cmSource.hasAlpha() && !cmSource.isAlphaPremultiplied()) {
        image(paletteToARGB(image()));
        cmSource = image().getColorModel();
    }
    BufferedImage alpha = null;
    if (cmSource.hasAlpha() && !cmSource.isAlphaPremultiplied()) {
        alpha = getAlpha(image());
        image(removeAlpha(image()));
    }
    Interpolation interp = Interpolation.getInstance(0);
    if (INTERPOLATION_BICUBIC == interpolation)
        interp = Interpolation.getInstance(1);
    else if (INTERPOLATION_BILINEAR == interpolation)
        interp = Interpolation.getInstance(2);
    if (alpha != null) {
        ParameterBlock params = new ParameterBlock();
        params.addSource(alpha);
        params.add(x);
        params.add(y);
        params.add(angle);
        params.add(interp);
        params.add(new double[] { 0.0 });
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, (RenderingHints.VALUE_INTERPOLATION_BICUBIC));
        hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, new BorderExtenderConstant(new double[] { 255.0 })));
        hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE));
        alpha = JAI.create("rotate", params, hints).getAsBufferedImage();
    }
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(x);
    params.add(y);
    params.add(angle);
    params.add(interp);
    params.add(new double[] { 0.0 });
    BorderExtender extender = new BorderExtenderConstant(new double[] { 0.0 });
    RenderingHints hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
    hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE));
    image(JAI.create("rotate", params, hints).getAsBufferedImage());
    if (alpha != null)
        image(addAlpha(image(), alpha, 0, 0));
}
Also used : Interpolation(javax.media.jai.Interpolation) ParameterBlock(java.awt.image.renderable.ParameterBlock) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) PackedColorModel(java.awt.image.PackedColorModel) ColorModel(java.awt.image.ColorModel) BorderExtender(javax.media.jai.BorderExtender) BorderExtenderConstant(javax.media.jai.BorderExtenderConstant) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) IndexColorModel(java.awt.image.IndexColorModel)

Example 2 with BorderExtender

use of javax.media.jai.BorderExtender in project Lucee by lucee.

the class Image method paste.

public void paste(Image topImage, int x, int y) throws ExpressionException {
    RenderingHints interp = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    BorderExtender extender = BorderExtender.createInstance(1);
    Graphics2D g = getGraphics();
    g.addRenderingHints(new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender));
    g.drawImage(topImage.image(), (new AffineTransformOp(AffineTransform.getTranslateInstance(x, y), interp)), 0, 0);
}
Also used : BorderExtender(javax.media.jai.BorderExtender) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 3 with BorderExtender

use of javax.media.jai.BorderExtender in project Lucee by lucee.

the class Image method shear.

public void shear(float shear, ShearDir direction, Object interpolation) throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(shear);
    params.add(direction);
    params.add(0.0F);
    params.add(0.0F);
    RenderingHints hints = null;
    if (interpolation == RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)
        params.add(Interpolation.getInstance(0));
    else if (interpolation == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
        params.add(Interpolation.getInstance(1));
        BorderExtender extender = BorderExtender.createInstance(1);
        hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
    } else if (interpolation == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
        params.add(Interpolation.getInstance(2));
        BorderExtender extender = BorderExtender.createInstance(1);
        hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
    }
    // TODO
    Color bg = getGraphics().getBackground();
    params.add(new double[] { bg.getRed(), bg.getGreen(), bg.getBlue() });
    image(JAI.create("shear", params, hints).getAsBufferedImage());
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) BorderExtender(javax.media.jai.BorderExtender) Color(java.awt.Color) RenderingHints(java.awt.RenderingHints)

Aggregations

RenderingHints (java.awt.RenderingHints)3 BorderExtender (javax.media.jai.BorderExtender)3 ParameterBlock (java.awt.image.renderable.ParameterBlock)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 BufferedImage (java.awt.image.BufferedImage)1 ColorModel (java.awt.image.ColorModel)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 DirectColorModel (java.awt.image.DirectColorModel)1 IndexColorModel (java.awt.image.IndexColorModel)1 PackedColorModel (java.awt.image.PackedColorModel)1 BorderExtenderConstant (javax.media.jai.BorderExtenderConstant)1 Interpolation (javax.media.jai.Interpolation)1