Search in sources :

Example 1 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project Lucee by lucee.

the class Image method crop.

public void crop(float x, float y, float width, float height) throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(x);
    params.add(y);
    float w = getWidth();
    float h = getHeight();
    if (w < x + width)
        params.add(w - x);
    else
        params.add(width);
    if (h < y + height)
        params.add(h - y);
    else
        params.add(height);
    image(JAI.create("crop", params).getAsBufferedImage());
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock)

Example 2 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock 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 3 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project Lucee by lucee.

the class Image method addBorder.

/**
 * add a border to image
 * @param thickness
 * @param color
 * @param borderType
 */
public void addBorder(int thickness, Color color, int borderType) throws ExpressionException {
    ColorModel cm = image().getColorModel();
    if (((cm instanceof IndexColorModel)) && (cm.hasAlpha()) && (!cm.isAlphaPremultiplied())) {
        image(paletteToARGB(image()));
        cm = image().getColorModel();
    }
    BufferedImage alpha = null;
    if ((cm.getNumComponents() > 3) && (cm.hasAlpha())) {
        alpha = getAlpha(image());
        image(removeAlpha(image()));
    }
    if (alpha != null) {
        ParameterBlock params1 = new ParameterBlock();
        params1.addSource(alpha);
        // left
        params1.add(thickness);
        // right
        params1.add(thickness);
        // top
        params1.add(thickness);
        // bottom
        params1.add(thickness);
        params1.add(new BorderExtenderConstant(new double[] { 255D }));
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE));
        alpha = JAI.create("border", params1, hints).getAsBufferedImage();
    }
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    // left
    params.add(thickness);
    // right
    params.add(thickness);
    // top
    params.add(thickness);
    // bottom
    params.add(thickness);
    params.add(toBorderExtender(borderType, color));
    image(JAI.create("border", params).getAsBufferedImage());
    if (alpha != null) {
        image(addAlpha(image(), alpha, thickness, thickness));
    }
}
Also used : 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) BorderExtenderConstant(javax.media.jai.BorderExtenderConstant) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) IndexColorModel(java.awt.image.IndexColorModel)

Example 4 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project Lucee by lucee.

the class Image method blur.

public void blur(int blurFactor) throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(blurFactor);
    RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1));
    image(JAI.create("boxfilter", params, hint).getAsBufferedImage());
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) RenderingHints(java.awt.RenderingHints)

Example 5 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project Lucee by lucee.

the class Image method invert.

public void invert() throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    image(JAI.create("invert", params).getAsBufferedImage());
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock)

Aggregations

ParameterBlock (java.awt.image.renderable.ParameterBlock)29 RenderingHints (java.awt.RenderingHints)5 RenderedImage (java.awt.image.RenderedImage)5 FileOpException (digilib.io.FileOpException)3 BufferedImage (java.awt.image.BufferedImage)3 Point (java.awt.Point)2 ColorModel (java.awt.image.ColorModel)2 ComponentColorModel (java.awt.image.ComponentColorModel)2 DirectColorModel (java.awt.image.DirectColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 PackedColorModel (java.awt.image.PackedColorModel)2 BorderExtender (javax.media.jai.BorderExtender)2 BorderExtenderConstant (javax.media.jai.BorderExtenderConstant)2 PlanarImage (javax.media.jai.PlanarImage)2 TransposeType (javax.media.jai.operator.TransposeType)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 DataBufferByte (java.awt.image.DataBufferByte)1