
Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
>>TYPE_USHORT_565_RGB format
>
> reading that literally, each pixel is an unsigned 16 bit short.
>
> The top 5 bits are red, the middle 6 bits are green, and the low order
> 5 bits are blue.
Thanks Roedy. I actually figured it out. The red, green, and blue are
still kept in separate int's.
I thought too from the description that they would just take up two
int's, one to holder the upper bounds of the ushort and one to hold the
lower bounds.
It ends up that each separate bit value needs to be saved off in its own
int. That's why the size was throwing me off. It ended up working like:
int[] pixelData = new int[(int)(rawData * 1.5)]; // 2 bytes into three ints
int pixel = 0;
for (int i = 0; i < pixelData.length; i += 3)
{
pixel = [two bytes into an int];
pixelData[i] = [red masked portion from pixel];
pixelData[i+1] = [green masked portion from pixel];
pixelData[i+2] = [blue portion from pixel];
}
It ended up having much poorer performance than using an ARGB type. I
think because on rendering it had to do the conversion to full RGB. I
ended up going back to storing my data in ARGB format and doing the
calculations before calling setPixels to convert the 5 or 6 bit values
to its correct 0-255 range. It seems like more work up front but then
better performance by the rendering engine later on.
Roedy Green - 09 Dec 2005 17:02 GMT
>Thanks Roedy. I actually figured it out. The red, green, and blue are
>still kept in separate int's.
>
>I thought too from the description that they would just take up two
>int's, one to holder the upper bounds of the ushort and one to hold the
>lower bounds.
Internally the pixels are likely stored in an array of shorts. It is
just when you access a pixel at a time does it split them out into r g
b for you. I would hazard a guess there is some means to
import/export a large number of pixels as a ushort array.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Boudewijn Dijkstra - 09 Dec 2005 20:26 GMT
>>>TYPE_USHORT_565_RGB format
>>
[quoted text clipped - 26 lines]
> It ended up having much poorer performance than using an ARGB type. I think
> because on rendering it had to do the conversion to full RGB.
No wonder, because now you're performing two conversions. I think you'll be
better off directly converting the 565 bytes into ARGB int pixels, which can
be directly used to build a BufferedImage. This should save a lot of memory
operations. Assuming big-endian:
int raw, pixel, j = 0;
for (int i = 0; i < pixelData.length; i++)
{
raw = rawData[j++];
pixel = ((raw & 0xf8) << 24) | ((raw & 0x07) << 13);
raw = rawData[j++];
pixel |= ((raw & 0xe0) << 5) | ((raw & 0x1f) << 3);
pixelData[i] = pixel;
}
Alternatively, you could convert your byte array into a short array and let
Java do the rest of the conversion work for you.