[Tutor] PIL's palette
denise.hartley at gmail.com
Thu Jul 14 01:11:32 CEST 2005
I am trying to figure out what a palette actually is, how it works,
and what PIL's "putpalette()" does with a given data set (it has to be
a string, I believe). PIL's documentation says very close to nothing
at all, and googling it has given me several other examples of doing
what I already know how to do, but without explaining why or what it's
actually doing (i.e., making it transferrable to other, different
situations). The example is this:
lut = 
for i in range(256):
lut.extend([255-i, i/2, i])
# lut.extend([i, i, i])
The first example I found had only the lut.extend([255-i, i/2, i])
command, the second had the one below it (which is now commented out).
I've tried them both, on an image which is black and blue.
The first one (lut.extend([255-i, i/2, i])) gives an image that is red
and red (you can still see the shading between the two objects so you
can kind of see they're both there, but everything's red).
The second, they're both black.
Does anyone know of a good tutorial or explanation (ideally with an
example or two) of what this palette actually is doing? It seems to
be a 768-long list of values (0-255), but when you take those 768
values and "associate" them with an image via putpalette... what are
they doing? I need to understand what is happening to my pixels when
the putpalette() is called, so I can understand how to do it
differently and apply it to do what I want.
Thanks for any suggestions/pointers!
More information about the Tutor