keon / awesome-bits

:computer: A curated list of awesome bitwise operations and tricks
3.06k stars 212 forks source link

Color conversoin seems wrong #8

Open jrmuizel opened 7 years ago

jrmuizel commented 7 years ago

Fast color conversion from R5G5B5 to R8G8B8 pixel format using shifts

R8 = (R5 << 3) | (R5 >> 2) G8 = (R5 << 3) | (R5 >> 2) B8 = (R5 << 3) | (R5 >> 2)

This looks to assign the same value to R8, G8 and B8

X-Ryl669 commented 2 years ago
In 16 bits: x16 must be uint16
R16 = R5 & 0xF800;
G16 = (R5 & 0x7E0) << 5;
B16 = R5 << 11; // Make sure to be uint16_t 

In 8 bits: R5 must be uint16
R8 = (R5 >> 11) << 3;
G8 = (R5 & 0x7E0) >> 3;
B8 = (R5 & 0x1F) << 3;