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