We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to use processing to read in an image with 24 bit color. Then I want to reduce the color to 16 bit, compatible with an AdaFruit Hx tft display. But I just noticed that there appears to be no 16-bit data type that I can use for my 16-bit pixel colors. I suppose I can poke the colors into 2 bytes, but that is a bit more messy.
Is there, by chance, an undocumented 16-bit type. I've tried a few possibilities, with no luck.
Thanks in advance for any advice.
Answers
short
&char
.short
is signed whilechar
in the only Java datatype which is unsigned by default.char
for it. B-)https://Processing.org/reference/char.html
P.S.: Use map() in order to reduce default 0-255 8-bit range of a RGB attribute to 0-31 5-bit range:
https://Processing.org/reference/map_.html
A better idea: Instead of map(), use
>>> 3
for each RGB attribute. *-:)In this approach, the 3 least significant bits of each RGB are simply discarded. (:|
Ok, never thought of char as a 16-bit type, but this my first journey into Java. That will quickly solve my problem. This odd color scheme has 5 bits R, 6 bits G, 5 bits B. The idea of the extra bit for G appears to be that our eyes are more sensitive to green.
For R & B, use
>> 3
. For G,>> 2
. :ar!BufferedImage should get you somewhere?
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html
More specifically TYPE_USHORT_565_RGB: :-B
http://docs.Oracle.com/javase/8/docs/api/java/awt/image/BufferedImage.html#TYPE_USHORT_565_RGB