use of java.awt.image.DataBuffer in project jdk8u_jdk by JetBrains.
the class PNGImageReader method createRaster.
private WritableRaster createRaster(int width, int height, int bands, int scanlineStride, int bitDepth) {
DataBuffer dataBuffer;
WritableRaster ras = null;
Point origin = new Point(0, 0);
if ((bitDepth < 8) && (bands == 1)) {
dataBuffer = new DataBufferByte(height * scanlineStride);
ras = Raster.createPackedRaster(dataBuffer, width, height, bitDepth, origin);
} else if (bitDepth <= 8) {
dataBuffer = new DataBufferByte(height * scanlineStride);
ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands, bandOffsets[bands], origin);
} else {
dataBuffer = new DataBufferUShort(height * scanlineStride);
ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands, bandOffsets[bands], origin);
}
return ras;
}
use of java.awt.image.DataBuffer 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;
}
use of java.awt.image.DataBuffer in project tigervnc by TigerVNC.
the class ModifiablePixelBuffer method maskRect.
// Copy pixel data to the buffer through a mask
// pixels is a pointer to the pixel to be copied to r.tl.
// maskPos specifies the pixel offset in the mask to start from.
// mask_ is a pointer to the mask bits at (0,0).
// pStride and mStride are the strides of the pixel and mask buffers.
public void maskRect(Rect r, Object pixels, byte[] mask_) {
Rect cr = getRect().intersect(r);
if (cr.is_empty())
return;
WritableRaster data = getBufferRW(cr);
// FIXME
ColorModel cm = format.getColorModel();
SampleModel sm = cm.createCompatibleSampleModel(r.width(), r.height());
DataBuffer db = null;
ByteBuffer src = ByteBuffer.wrap((byte[]) pixels).order(format.getByteOrder());
Buffer dst;
switch(sm.getTransferType()) {
case TYPE_INT:
dst = IntBuffer.allocate(src.remaining()).put(src.asIntBuffer());
db = new DataBufferInt(((IntBuffer) dst).array(), r.area());
break;
case TYPE_BYTE:
db = new DataBufferByte(src.array(), r.area());
break;
case TYPE_SHORT:
dst = ShortBuffer.allocate(src.remaining()).put(src.asShortBuffer());
db = new DataBufferShort(((ShortBuffer) dst).array(), r.area());
break;
}
assert (db != null);
Raster raster = Raster.createRaster(sm, db, new java.awt.Point(0, 0));
ColorConvertOp converter = format.getColorConvertOp(cm.getColorSpace());
WritableRaster t = data.createCompatibleWritableRaster();
converter.filter(raster, t);
int w = cr.width();
int h = cr.height();
Point offset = new Point(cr.tl.x - r.tl.x, cr.tl.y - r.tl.y);
int maskBytesPerRow = (w + 7) / 8;
synchronized (image) {
for (int y = 0; y < h; y++) {
int cy = offset.y + y;
for (int x = 0; x < w; x++) {
int cx = offset.x + x;
int byte_ = cy * maskBytesPerRow + y / 8;
int bit = 7 - cx % 8;
if ((mask_[byte_] & (1 << bit)) != 0)
data.setDataElements(x + cx, y + cy, t.getDataElements(x + cx, y + cy, null));
}
}
}
commitBufferRW(r);
}
Aggregations