Search in sources :

Example 11 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project digilib by robcast.

the class JAIDocuImage method loadSubimage.

/* Load an image file into the Object. */
public void loadSubimage(ImageInput ii, Rectangle region, int subsample) throws FileOpException {
    logger.debug("loadSubimage");
    this.input = ii;
    if (ii.hasFile()) {
        img = JAI.create("fileload", ii.getFile().getAbsolutePath());
    } else if (ii.hasInputStream()) {
        img = JAI.create("stream", ii.getInputStream());
    } else {
        throw new FileOpException("unable to get data for image!");
    }
    if ((region.width < img.getWidth()) || (region.height < img.getHeight())) {
        // setup Crop
        ParameterBlock cp = new ParameterBlock();
        cp.addSource(img);
        cp.add((float) region.x);
        cp.add((float) region.y);
        cp.add((float) region.width);
        cp.add((float) region.height);
        logger.debug("loadSubimage: crop");
        img = JAI.create("crop", cp);
    }
    if (subsample > 1) {
        float sc = 1f / subsample;
        ParameterBlockJAI sp = new ParameterBlockJAI("scale");
        sp.addSource(img);
        sp.setParameter("xScale", sc);
        sp.setParameter("yScale", sc);
        sp.setParameter("interpolation", Interpolation.getInstance(Interpolation.INTERP_NEAREST));
        // scale
        logger.debug("loadSubimage: scale");
        img = JAI.create("scale", sp);
    }
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileOpException(digilib.io.FileOpException)

Example 12 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project digilib by robcast.

the class JAIDocuImage method mirror.

/*
	 * mirrors the current image works only horizontal and vertical
	 */
public void mirror(double angle) throws ImageOpException {
    RenderedImage mirImg;
    // only mirroring by right angles
    TransposeType rotOp = null;
    if (Math.abs(angle) < epsilon) {
        // 0 degree
        rotOp = TransposeDescriptor.FLIP_HORIZONTAL;
    } else if (Math.abs(angle - 90) < epsilon) {
        // 90 degree
        rotOp = TransposeDescriptor.FLIP_VERTICAL;
    } else if (Math.abs(angle - 180) < epsilon) {
        // 180 degree
        rotOp = TransposeDescriptor.FLIP_HORIZONTAL;
    } else if (Math.abs(angle - 270) < epsilon) {
        // 270 degree
        rotOp = TransposeDescriptor.FLIP_VERTICAL;
    } else if (Math.abs(angle - 360) < epsilon) {
        // 360 degree
        rotOp = TransposeDescriptor.FLIP_HORIZONTAL;
    }
    // use Transpose operation
    ParameterBlock param = new ParameterBlock();
    param.addSource(img);
    param.add(rotOp);
    mirImg = JAI.create("transpose", param);
    if (mirImg == null) {
        throw new ImageOpException("Unable to flip");
    }
    img = mirImg;
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) TransposeType(javax.media.jai.operator.TransposeType) RenderedImage(java.awt.image.RenderedImage)

Example 13 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project digilib by robcast.

the class JAIDocuImage method crop.

/* crops the current image */
public void crop(int x_off, int y_off, int width, int height) throws ImageOpException {
    // setup Crop
    ParameterBlock param = new ParameterBlock();
    param.addSource(img);
    param.add((float) x_off);
    param.add((float) y_off);
    param.add((float) width);
    param.add((float) height);
    RenderedImage croppedImg = JAI.create("crop", param);
    logger.debug("CROP: " + x_off + "," + y_off + ", " + width + "," + height + " ->" + croppedImg.getWidth() + "x" + croppedImg.getHeight());
    img = croppedImg;
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) RenderedImage(java.awt.image.RenderedImage)

Example 14 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project digilib by robcast.

the class JAIImageLoaderDocuImage method writeImage.

/* Write the current image to an OutputStream. */
public void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException {
    logger.debug("writeImage");
    try {
        // setup output
        ParameterBlock pb3 = new ParameterBlock();
        pb3.addSource(img);
        pb3.add(ostream);
        if (mt == "image/jpeg") {
            pb3.add("JPEG");
        } else if (mt == "image/png") {
            pb3.add("PNG");
        } else {
            // unknown mime type
            throw new ImageOpException("Unknown mime type: " + mt);
        }
        // render output
        JAI.create("ImageWrite", pb3);
    } catch (RuntimeException e) {
        throw new FileOpException("Error writing image.");
    }
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) FileOpException(digilib.io.FileOpException)

Example 15 with ParameterBlock

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

the class Image method translate.

public void translate(int xtrans, int ytrans, Object interpolation) throws ExpressionException {
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, interpolation);
    if (interpolation != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
        hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1)));
    }
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image());
    BufferedImage img = JAI.create("translate", pb).getAsBufferedImage();
    Graphics2D graphics = img.createGraphics();
    graphics.clearRect(0, 0, img.getWidth(), img.getHeight());
    AffineTransform at = new AffineTransform();
    at.setToIdentity();
    graphics.drawImage(image(), new AffineTransformOp(at, hints), xtrans, ytrans);
    graphics.dispose();
    image(img);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) AffineTransform(java.awt.geom.AffineTransform) RenderingHints(java.awt.RenderingHints) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) AffineTransformOp(java.awt.image.AffineTransformOp)

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