RGB565

   RGB565 is color format, or a way of representing [1]colors with just 2
   [2]bytes (unlike traditional 24 bit RGB formats that use 3 bytes, one for
   each component), that is 16 [3]bits (giving a total of 65536 distinct
   colors), by using 5 bits (highest) for red, 6 bits for green (to which
   human eye is most sensitive) and 5 bits for blue; it can also be seen as a
   color [4]palette. It is similar to [5]rgb332 -- it's basically a mid way
   between RGB332 and full 24bit RGB against which it saves one byte per
   pixel, but compared to RGB332 [6]byte sex comes to play here. Practically
   speaking you will rarely need anything more than this, 65 thousand colors
   are absolutely sufficient for everything.

   Yet another similar format to this one is [7]RGB555 which sacrifices one
   useful bit for gaining the nice property of having the same size of each
   component.

   Here is a [8]C code for the basic conversions to/from this format:

 unsigned int rgbTo565(unsigned char red, unsigned char green,
   unsigned char blue)
 {
   return (((unsigned int) (red / 8)) << 11) |
     (((unsigned int) (green / 4)) << 5) | (blue / 8);
 }

 void rgbFrom565(unsigned int colorIndex, unsigned char *red,
   unsigned char *green, unsigned char *blue)
 {
   unsigned char value = colorIndex >> 11;
   *red = value != 31 ? value * 8 : 255;
  
   value = (colorIndex >> 5) & 0x3f;
   *green = value != 63 ? value * 4 : 255;
  
   value = colorIndex & 0x1f;
   *blue = value != 31 ? value * 8 : 255;
 }

   There exist nice tricks you can do with colors represented this way, like
   quickly divide all three R, G and B components by a power of two just by
   doing one bit shift and logical [9]AND to zero the highest bits of the
   components, or approximating addition of colors with logical [10]OR and so
   on -- for details see the article on [11]RGB332.

Links:
1. color.md
2. byte.md
3. bit.md
4. palette.md
5. rgb332.md
6. byte_sex.md
7. rgb555.md
8. c.md
9. and.md
10. or.md
11. rgb332.md