use of java.awt.image.DataBufferInt in project Lucee by lucee.
the class Image method jpgImage.
private static BufferedImage jpgImage(BufferedImage src) {
int w = src.getWidth();
int h = src.getHeight();
SampleModel srcSM = src.getSampleModel();
WritableRaster srcWR = src.getRaster();
java.awt.image.DataBuffer srcDB = srcWR.getDataBuffer();
ColorModel rgb = new DirectColorModel(32, 0xff0000, 65280, 255);
int[] bitMasks = new int[] { 0xff0000, 65280, 255 };
SampleModel csm = new SinglePixelPackedSampleModel(3, w, h, bitMasks);
int[] data = new int[w * h];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int[] pix = null;
int[] sample = srcSM.getPixel(j, i, pix, srcDB);
if (sample[3] == 0 && sample[2] == 0 && sample[1] == 0 && sample[0] == 0)
data[i * w + j] = 0xffffff;
else
data[i * w + j] = sample[0] << 16 | sample[1] << 8 | sample[2];
}
}
java.awt.image.DataBuffer db = new DataBufferInt(data, w * h * 3);
WritableRaster wr = Raster.createWritableRaster(csm, db, new Point(0, 0));
return new BufferedImage(rgb, wr, false, null);
}
use of java.awt.image.DataBufferInt in project jlineup by otto-de.
the class ImageService method bufferedImagesEqualQuick.
// A very fast byte buffer based image comparison for images containing INT or BYTE type representations
public static boolean bufferedImagesEqualQuick(BufferedImage image1, BufferedImage image2) {
DataBuffer dataBuffer1 = image1.getRaster().getDataBuffer();
DataBuffer dataBuffer2 = image2.getRaster().getDataBuffer();
if (dataBuffer1 instanceof DataBufferByte && dataBuffer2 instanceof DataBufferByte) {
DataBufferByte dataBufferBytes1 = (DataBufferByte) dataBuffer1;
DataBufferByte dataBufferBytes2 = (DataBufferByte) dataBuffer2;
for (int bank = 0; bank < dataBufferBytes1.getNumBanks(); bank++) {
byte[] bytes1 = dataBufferBytes1.getData(bank);
byte[] bytes2 = dataBufferBytes2.getData(bank);
if (!Arrays.equals(bytes1, bytes2)) {
return false;
}
}
} else if (dataBuffer1 instanceof DataBufferInt && dataBuffer2 instanceof DataBufferInt) {
DataBufferInt dataBufferInt1 = (DataBufferInt) dataBuffer1;
DataBufferInt dataBufferInt2 = (DataBufferInt) dataBuffer2;
for (int bank = 0; bank < dataBufferInt1.getNumBanks(); bank++) {
int[] ints1 = dataBufferInt1.getData(bank);
int[] ints2 = dataBufferInt2.getData(bank);
if (!Arrays.equals(ints1, ints2)) {
return false;
}
}
} else {
return false;
}
return true;
}
Aggregations