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);
}
}
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;
}
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;
}
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;
}
Aggregations