Search in sources :

Example 26 with ParameterBlock

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

the class JAIDocuImage method writeImage.

/* Write the current image to an OutputStream. */
public void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException {
    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("encode", pb3);
    } catch (RuntimeException e) {
        // JAI likes to throw RuntimeExceptions
        throw new FileOpException("Error writing image: " + e);
    }
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) FileOpException(digilib.io.FileOpException)

Example 27 with ParameterBlock

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

the class JAIDocuImage method rotate.

/* rotates the current image */
public void rotate(double angle) throws ImageOpException {
    RenderedImage rotImg;
    // convert degrees to radians
    double rangle = Math.toRadians(angle);
    double x = img.getWidth() / 2;
    double y = img.getHeight() / 2;
    // optimize rotation by right angles
    TransposeType rotOp = null;
    if (Math.abs(angle - 0) < epsilon) {
        // 0 degree
        return;
    } else if (Math.abs(angle - 90) < epsilon) {
        // 90 degree
        rotOp = TransposeDescriptor.ROTATE_90;
    } else if (Math.abs(angle - 180) < epsilon) {
        // 180 degree
        rotOp = TransposeDescriptor.ROTATE_180;
    } else if (Math.abs(angle - 270) < epsilon) {
        // 270 degree
        rotOp = TransposeDescriptor.ROTATE_270;
    } else if (Math.abs(angle - 360) < epsilon) {
        // 360 degree
        return;
    }
    if (rotOp != null) {
        // use Transpose operation
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(img);
        pb.add(rotOp);
        rotImg = JAI.create("transpose", pb);
    } else {
        // setup "normal" rotation
        ParameterBlock param = new ParameterBlock();
        param.addSource(img);
        param.add((float) x);
        param.add((float) y);
        param.add((float) rangle);
        param.add(interpol);
        rotImg = JAI.create("rotate", param);
    }
    logger.debug("ROTATE: " + x + "," + y + ", " + angle + " (" + rangle + ")" + " ->" + rotImg.getWidth() + "x" + rotImg.getHeight());
    img = rotImg;
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) TransposeType(javax.media.jai.operator.TransposeType) RenderedImage(java.awt.image.RenderedImage)

Example 28 with ParameterBlock

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

the class JAIDocuImage method enhanceRGB.

/*
	 * (non-Javadoc)
	 * 
	 * @see digilib.image.DocuImage#enhanceRGB(float[], float[])
	 */
public void enhanceRGB(float[] rgbm, float[] rgba) throws ImageOpException {
    RenderedImage enhImg;
    int nb = rgbm.length;
    double[] ma = new double[nb];
    double[] aa = new double[nb];
    for (int i = 0; i < nb; i++) {
        ma[i] = rgbm[i];
        aa[i] = rgba[i];
    }
    // use Rescale operation
    ParameterBlock param = new ParameterBlock();
    param.addSource(img);
    param.add(ma);
    param.add(aa);
    enhImg = JAI.create("rescale", param);
    logger.debug("ENHANCE_RGB: *" + rgbm + ", +" + rgba + " ->" + enhImg.getWidth() + "x" + enhImg.getHeight());
    img = enhImg;
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) RenderedImage(java.awt.image.RenderedImage)

Example 29 with ParameterBlock

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

the class JAIDocuImage method enhance.

/* contrast and brightness enhancement */
public void enhance(float mult, float add) throws ImageOpException {
    RenderedImage enhImg;
    double[] ma = { mult };
    double[] aa = { add };
    // use Rescale operation
    ParameterBlock param = new ParameterBlock();
    param.addSource(img);
    param.add(ma);
    param.add(aa);
    enhImg = JAI.create("rescale", param);
    logger.debug("ENHANCE: *" + mult + ", +" + add + " ->" + enhImg.getWidth() + "x" + enhImg.getHeight());
    // DEBUG
    img = enhImg;
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) RenderedImage(java.awt.image.RenderedImage)

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