[Image-SIG] Applying a palette to an image
Fredrik Johansson
fredrik.johansson at gmail.com
Fri Oct 22 20:23:20 CEST 2004
Hi,
Is there a way to apply a custom palette to an RGB-mode image using
PIL? I've looked at .putpalette and .convert and it seems there is
only support for either converting to the special web-safe palette or
generating a new palette based on the colors in the image.
I am writing a game editing application that is able to load images
from conventional files and convert them into a specialized format,
mapping colors to the game's pre-defined palette. Going from file to
raw bytes via PIL, and then through a routine that shuffles pixels
around to the specialized format, is fast enough even though the last
step is coded in Python. However, matching colors from a palette with
Python when starting from a 24-bit image is a serious bottleneck.
If there is any way this can be done with PIL that I've missed (I
wouldn't be surprised), information would be much appreciated. In case
there isn't, I might have to put the palette lookup code in a C
extension, which would be somewhat inconvenient. In that case, I'd
also take the opportunity to request humbly that this feature be
included in future versions of PIL.
Thanks,
Fredrik Johansson
More information about the Image-SIG
mailing list