For those interested, here is the conversion code I use to convert an ID into a colour:
Not really complicated, is it?
Here's the code for the other direction: converting a colour to an id.
Code:
// Move bits around
int result = (((id & 0x200)>>1) | ((id & 0x40)<<3) | ((id & 0x8)<<7) | ((id & 0x1)<<11) |
((id & 0x400)>>6) | ((id & 0x80)>>2) | ((id & 0x10)<<2) | ((id & 0x2)<<6) |
((id & 0x800)>>11) | ((id & 0x100)>>7) | ((id & 0x20)>>3) | ((id & 0x4)<<1));
// Distribute over R, G and B.
result = ((result & 0xF00) << 3) | ((result & 0xF0) << 2) | ((result & 0xF) << 1);
Not really complicated, is it?
Here's the code for the other direction: converting a colour to an id.
Code:
// Compact distributed bits
rgb = ((rgb & 0xF00000) >> 12) | ((rgb & 0xF000) >> 8) | ((rgb & 0xF0) >> 4);
// And move them to their correct places.
rgb = (((rgb & 0x8)>>1) | ((rgb & 0x4)<<3) | ((rgb & 0x2)<<7) | ((rgb & 0x1)<<11) |
((rgb & 0x80)>>6) | ((rgb & 0x40)>>2) | ((rgb & 0x20)<<2) | ((rgb & 0x10)<<6) |
((rgb& 0x800)>>11) | ((rgb & 0x400)>>7) | ((rgb & 0x200)>>3) | ((rgb & 0x100)<<1));