Le Vendredi 17 Mars 2006 13:43, Eduardo M KALINOWSKI a écrit : > yeajchao wrote: > >Hello all > > I am chinese,I am sorry for my terriblly poor English ! > > > > I have confused about GdkColor > > > > In general,the RGB color mode ,the red or green or blue's value is > > from 0 to 255 > > But ,the GdkColor ,the value is from 0 to 65535 > > > > My question is ,how to map (0--255) to (0--65535) > > > > For example ,i have a general color (245,222,179) > > map it to GdkColor ,what is the value ? > > Let's use some basic maths: > > 245 x > --- = ----- > 255 65535 > > Solving for x, we discover that > > x = 245*65535 / 255 = 62965 > > And that's the value for red. Similar calculations will provide the values > for green and blue. > > BTW, using hexadecimal base this "conversion" gets simpler. Try for > yourself.
A range of [0-255] is stored on 8 bits, and [0-65535] on 16 bits. So a bit shift is simpler and faster: chan_16bits = chan_8bits << 8 chan_8bits = chan16bits >> 8 Note this is not absolutely correct because the 8 bit value 0xff (255) will become 0xff00 (and should be 0xffff), but this won't probably be noticiable (because most video cards are limited to 8 bits channels, and anyway most human people wouldn't see the difference:). If you want a perfect mapping, you can do this: chan_16bits = (chan_8bits << 8) | chan_8bits I'm not sure it's really 'perfect', but I use it and it works ;) Bye -- Cédric Lucantis _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list