Custom palette in bmp2c.go file
-
Hi everyone,
I would like to custom the bmp2c tool in order to make my own palette (like adding some blue for my icons, etc.), so I am looking for information about the color conversion that is performed. In the bmp2c.go file, the function
getPaletteIndex()
calls theto16BitColor()
and performs aswitch
depending on its result (see below).func getPaletteIndex(r, g, b, a uint32) int { // 0x0000, 0xffff, 0x20e4, 0xffdf, 0x18e3, 0xf79e, 0xc986, 0xd30c, // 0xc103, 0xff52, 0xfffb, 0x4569, 0x9492, 0x0000, 0x0000, 0x0000 switch to16BitColor(r, g, b, a) { case 0xffff: // e.g. 0xffffff return 1 case 0x20e4: // e.g. 0x201c20 return 2 case 0xffdf: // e.g. 0xf8f8f8 return 3 case 0x18e3: // e.g. 0x181c18 return 4 case 0xf79e: // e.g. 0xf0f0f0 return 5 case 0xc986: // e.g. 0xc83030 return 6 case 0xd30c: // e.g. 0xd06060 return 7 case 0xc103: // e.g. 0xc02018 return 8 case 0xff52: // e.g. 0xf8e890 return 9 case 0xfffb: // e.g. 0xf8fcd8 return 10 case 0x4569: // e.g. 0x40ac48 return 11 case 0x9492: // e.g. 0x909090 return 12 default: return 0 } } func to16BitColor(r, g, b, a uint32) uint16 { return uint16((r&0xF8)<<8) | uint16((g&0xFC)<<3) | uint16((b&0xF8)>>3) }
As
to16BitColor
converts r, g, b into a singleuint16_t
, there sould be a multitude of possible outputs for thisswitch
: 2^16 = 65,536 colors! So, why are there only 13 outputs? I mean, from a 24-bit image.bpm taken as input, how is it possible that all the colors (2^24 !) can match these 13 outputs?I have already looked into the image library of golang here which is used in the file (especially the
At()
andbmp.Decode()
functions) but I did not find the answer I was looking for (also, I am not familiar with Go!).Is there anyone having worked on the bmp2c.go file who could help me?
-
Moved to the developers forum.