byte[] rawData =(byte[])(buffer.getData());
try {
imageLock.lock();
BufferType bufferType = backBuffer.getBufferType();
if(bufferType == BufferTypes.RGB_3Byte) {
// Handle a RGB_3Byte buffer efficiently
byte[] data = (byte[])backBuffer.getBuffer();
int width = backBuffer.getWidth();
int ip = 0;
for ( int y = inHeight - 1; y >= 0; y-- ) {
for ( int x = 0; x < inWidth; x++) {
int indexBase = (y * width + x) * 3;
data[indexBase + 2] = rawData[ip++];
data[indexBase + 1] = rawData[ip++];
data[indexBase] = rawData[ip++];
}
}
} else if(bufferType == BufferTypes.RGBA_4Byte) {
// Handle a RGBA_4Byte buffer efficiently
byte[] data = (byte[])backBuffer.getBuffer();
int width = backBuffer.getWidth();
int ip = 0;
for ( int y = inHeight - 1; y >= 0; y-- ) {
for ( int x = 0; x < inWidth; x++) {
int indexBase = (y * width + x) * 4;
data[indexBase + 2] = rawData[ip++];
data[indexBase + 1] = rawData[ip++];
data[indexBase] = rawData[ip++];
data[indexBase + 3] = (byte)255;
}
}
} else {
// Handling an unknown buffer will be pretty inefficient!
int ip = 0;
Color4f color = new Color4f();
color.w = 1.0f;
float v = 1.0f / 255;
for ( int y = inHeight - 1; y >= 0; y-- ) {
for ( int x = 0; x < inWidth; x++) {
color.z = v * (int)rawData[ip++];
color.y = v * (int)rawData[ip++];
color.x = v * (int)rawData[ip++];
bufferType.setColor(backBuffer, x, y, color);
}
}
}
updated = true;