I am writing an ImageEncoder
that writes a TGA
image. I have been able to successfully write the TGA
file, but instead of ending up with [RRRRRGGGGGBBBBBA]
I get [RGBBBBBA]
here is the relevant code:
int lastRow = minY + height;
for (int row = minY; row < lastRow; row += 8) {
int rows = Math.min(8, lastRow - row);
int size = rows * width * numBands;
// Grab the pixels
Raster src = im.getData(new Rectangle(minX, row, width, rows));
src.getPixels(minX, row, width, rows, pixels);
for (int i = 0; i < size; i++) {
//output.write(pixels[i] & 0xFF);
//corrected
//before conversion (source image) pixel in RGBA8888 format.
int o = (int) pixels[i];
//Need to convert here...
short converted = ?;
//need to write out RGB5551
output.write(converted);
}
}
To clarify what I am trying to accomplish... I have a source image in png format the color depth is RGBA8888. I need to convert this image to tga format with color depth RGBA5551. The for loop above is where I am accessing the individual pixels. So what I am asking is: How do I correctly read the 32-bit int (RGBA8888) and convert it to a 16-bit short (RGBA5551)?