555/565

Summary
555 and 565 are used to describe different allocations of bits inside a 16-bit integer representing a pixel, as used in Creatures sprite files such as BLK and C16. This is briefly discussed in the Creating Agent Art tutorial for Creatures 2.

Technical Information
In 555 format, the bits are allocated as follows:

0123 4567 0123 4567 -rrr rr--  (bitmask: 0x7C00) --gg ggg- (bitmask: 0x3E0) ---b bbbb (bitmask: 0x1F)

In 565 format, the bits are allocated as follows:

0123 4567 0123 4567 rrrr r---  (bitmask: 0xF800) -ggg ggg- (bitmask: 0x7E0) ---b bbbb (bitmask: 0x1F)

The following macros can be used in C or C++ to decode these values to normal 24-bit format:

/* Decoding macros by bd_ aka bdonlan. I release these into the public domain. */


 * 1) define RGB(r, g, b) ((r) &lt;&lt; 16 | (g) &lt;&lt; 8 | (b))

(RGB(                     \ ((uint32_t)(v) & 0x7c00) &gt;&gt; 7, \ ((uint32_t)(v) & 0x03e0) &gt;&gt; 2, \ ((uint32_t)(v) & 0x001f) &lt;&lt; 3 \ ))
 * 1) define DECODE_555(v)          \

(RGB(                     \ ((uint32_t)(v) & 0xf800) &gt;&gt; 8, \ ((uint32_t)(v) & 0x07e0) &gt;&gt; 3, \ ((uint32_t)(v) & 0x001f) &lt;&lt; 3  \ ))
 * 1) define DECODE_565(v)          \