[Image-SIG] Paletted image with alpha

Don Laursen gomtuu at gmail.com
Sun Nov 16 06:30:02 CET 2008


I wrote an application that views 3D mesh files from a Playstation
game (Final Fantasy Tactics). I've been using PIL to read the texture
data, and it's been working fine.

Recently, though, I decided to try to make a texture editor. Since I
don't actually want to write image-editing software, I decided to
export the images so they can be edited and then re-imported. But I've
run into a problem.

The texture for a mesh is stored as a 4-bits-per-pixel bitmap. Each
polygon in the mesh has a palette number associated with it, and the
appropriate palette is applied to the texture when a polygon is
rendered to the screen. The palettes are 16 colors, each color having
5 bits each for R, G, and B and 1 bit for A. The fact that
transparency is encoded as an alpha value in palette entries is what's
giving me trouble. To make the images easy to edit, I'm applying a
palette (whichever one the user selects from among the mesh's 16
palettes) before I export them, but I need to be able to preserve the
palette's alpha information in the exported file and during the
editing process. If I don't, then either the transparency information
will be lost, or two colors that are both transparent will get
combined into a single transparent color, which will mess up the image
when rendered with one of the other palettes. (Two colors that are
transparent in one palette are very likely to be separate opaque
colors in another palette.)

According to Wikipedia, PNG is supposed to support alpha data in
palettes, but I don't see support for that in PIL. PIL does have a PA
mode, but I haven't been able to convert P or RGBA images to PA. I get
this error:

  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 677, in convert
    im = im.convert(mode, dither)
ValueError: conversion from RGB to PA not supported

It says that even when I convert the image to P mode first.

The Im and Tiff formats in PIL both appear to have support for PA
mode, so if I can convert the image to PA, I'm guessing I can save it
as one of those. But does anyone know if any image editors have
support for alpha data in palettes? I can't remember ever seeing such
a thing.

Any help would be appreciated,

More information about the Image-SIG mailing list