6 * This original version, although fast and a true inverse of
7 * cmap2rgb, in the sense that rgb2cmap(cmap2rgb(c))
8 * returned the original color, does a terrible job for RGB
9 * triples that do not appear in the color map, so it has been
10 * replaced by the much slower version below, that loops
11 * over the color map looking for the nearest point in RGB
12 * space. There is no visual psychology reason for that
13 * criterion, but it's easy to implement and the results are
17 rgb2cmap(int cr, int cg, int cb)
42 return ((((r<<2)+v)<<4)+(((g<<2)+b+v-r)&15));
47 rgb2cmap(int cr, int cg, int cb)
60 sq = (r-cr)*(r-cr)+(g-cg)*(g-cg)+(b-cb)*(b-cb);
72 int j, num, den, r, g, b, v, rgb;
86 rgb = (v<<16)|(v<<8)|v;
90 rgb = ((r*num/den)<<16)|((g*num/den)<<8)|(b*num/den);
98 return (cmap2rgb(c)<<8)|0xFF;