Lawrence D'Oliveiro wrote:

> Ideally I'd like to create a PNG file with just two bits per pixel, with
> four colour-table entries of my choice. I'm using PyCairo
> <http://www.cairographics.org/pycairo/> to do the drawing, but that
> doesn't seem to support colour-table images as far as I can tell. So I'm
> trying to figure out how to use PIL
> <http://www.pythonware.com/library/pil/handbook/index.htm> to save the
> images to PNG files with a suitable format.

For those who are interested, I finally gave up on PIL and resorted to direct 
calls to libpng via ctypes. This successfully lets me write 1-bit-per-pixel PNG 
images with colour tables of my choice.

One issue I found is that the png_set_packing call doesn't seem to work on my 
Gentoo AMD64 system. And Cairo and libpng use a different order for sub-byte 
pixels on little-endian platforms. So I have to do rearrangement of bits within 
each byte. Which is a bit slow in Python.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to