bit manipulation frustration

Peter Schneider-Kamp peter at schneider-kamp.de
Sun Jul 23 03:57:58 EDT 2000


Courageous wrote:
> 
> Say for example I want to increase or decrease R,
> G, or B values. Or, say, I want to convert to 32
> bit color bitmaps?

>>> def toRGB(v):
...   i = (ord(v[1]) << 8) + ord(v[0])
...   return [i >> 11, (i >> 5) & 63, i & 31]
...
>>> def fromRGB(rgb):
...   i = (rgb[0] << 11) + (rgb[1] << 5) + rgb[2]
...   return chr(i & 255)+chr(i >> 8)
...

This converts a two character string into an rgb triple
and back.

Hope that helps,
Peter
--
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de




More information about the Python-list mailing list