use of java.awt.image.PixelGrabber in project Lucee by lucee.
the class ImageCombiningFilter method filter.
public ImageProducer filter(Image image1, Image image2, int x, int y, int w, int h) {
int[] pixels1 = new int[w * h];
int[] pixels2 = new int[w * h];
int[] pixels3 = new int[w * h];
PixelGrabber pg1 = new PixelGrabber(image1, x, y, w, h, pixels1, 0, w);
PixelGrabber pg2 = new PixelGrabber(image2, x, y, w, h, pixels2, 0, w);
try {
pg1.grabPixels();
pg2.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return null;
}
if ((pg1.status() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return null;
}
if ((pg2.status() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return null;
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
int k = j * w + i;
pixels3[k] = filterRGB(x + i, y + j, pixels1[k], pixels2[k]);
}
}
return new MemoryImageSource(w, h, pixels3, 0, w);
}
use of java.awt.image.PixelGrabber in project Lucee by lucee.
the class ImageUtils method createImage.
/**
* Cretae a BufferedImage from an ImageProducer.
* @param producer the ImageProducer
* @return a new TYPE_INT_ARGB BufferedImage
*/
public static BufferedImage createImage(ImageProducer producer) {
PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException("Image fetch interrupted");
}
if ((pg.status() & ImageObserver.ABORT) != 0)
throw new RuntimeException("Image fetch aborted");
if ((pg.status() & ImageObserver.ERROR) != 0)
throw new RuntimeException("Image fetch error");
BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[]) pg.getPixels(), 0, pg.getWidth());
return p;
}
Aggregations