I have some hundred thumbnail images, and I search a way to merge them using JAI. Additionally they have to streched first by a perspective transformation. Fot the transformation I found this working well: Fast Perspective transform in Java Advanced Imaging API
I have written some testcode to do some of the stuff with a Graphics2D Object, but I guess it will be more efficient in JAI.
THX!
-marco
PlanarImage img1 = PlanarImage.wrapRenderedImage(bufIn1);
PlanarImage img2 = PlanarImage.wrapRenderedImage(bufIn2);
int numBands = img1.getSampleModel().getNumBands();
ColorSpace cs = ColorSpace.getInstance(numBands == 1 ?ColorSpace.CS_GRAY : ColorSpace.CS_sRGB);
ColorModel cm =RasterFactory.createComponentColorModel(DataBuffer.TYPE_BYTE,cs, true, false,Transparency.BITMASK);
SampleModel sm =RasterFactory.createComponentSampleModel(img1.getSampleModel(),DataBuffer.TYPE_BYTE,img1.getTileWidth(),img1.getTileHeight(),numBands + 1);
ImageLayout il = new ImageLayout();
il.setSampleModel(sm).setColorModel(cm);
RenderingHints rh = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il);
ParameterBlock pb;
Dimension d;
WarpPerspective wp;
RenderedOp srca;
//make background for single image
pb = new ParameterBlock();
pb.add(new Float(img1.getWidth())).add(new Float(img1.getHeight()));
pb.add(new Byte[]{new Byte((byte)0xFF)});
RenderedOp alpha = JAI.create("constant", pb);
pb = new ParameterBlock();
pb.addSource(img1).addSource(img1);
pb.add(alpha).add(alpha).add(Boolean.FALSE);
pb.add(CompositeDescriptor.DESTINATION_ALPHA_LAST);
srca = JAI.create("composite", pb, rh);
d = new Dimension(img1.getWidth(),img1.getHeight());
wp = new WarpPerspective(PerspectiveTransform.getQuadToQuad(
0 , 0, d.width, 0, d.width, d.height, 0, d.height,
0 , 0, d.width, 0, d.width, d.height/2, 0, d.height));
pb = (new ParameterBlock()).addSource(srca);
pb.add(wp);
pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST)); //INTERP_BICUBIC
PlanarImage i1 = (PlanarImage)JAI.create("warp",pb);
pb = new ParameterBlock().addSource(img2).addSource(img2);
pb.add(alpha).add(alpha).add(Boolean.FALSE);
pb.add(CompositeDescriptor.DESTINATION_ALPHA_LAST);
srca = JAI.create("composite", pb, rh);
d = new Dimension(img1.getWidth(),img1.getHeight());
wp = new WarpPerspective(PerspectiveTransform.getQuadToQuad(
0 , 0, d.width, 0, d.width, d.height, 0, d.height,
0 , 0, d.width, 0, d.width*2, d.height, 0, d.height/2));
pb = (new ParameterBlock()).addSource(srca);
pb.add(wp);
pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST)); //INTERP_BICUBIC
PlanarImage i2 = (PlanarImage)JAI.create("warp",pb);
BufferedImage masterImage = new BufferedImage(1000, 1000, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = masterImage.createGraphics();
g.setBackground(FastSurfaceImageRenderable.transparencyColor);
g.clearRect(0, 0, subImage.getWidth(), subImage.getHeight());
g.drawImage(i1.getAsBufferedImage(), 0, 0, 100, 100, null);
g.drawImage(i2.getAsBufferedImage(), 50, 50, 200, 100, null);
g.dispose();