[Pyrex] PyRex + PIL
G. Kunze
pyrex at ham.vanillev.la
Fri May 5 21:46:41 CEST 2006
Hi,
I recently (yesterday) started playing around with PyRex. I've succeeded
in wrapping a small C library using the tutorial and some other
info/examples I've found on the web and I must say it's great, a lot
easier than I expected.
Now I'm trying to add features to the wrapper, the library needs small
bitmaps, I currently provide the library those bitmaps with a small
extension type containing a byte-array and supporting get_pixel and
set_pixel methods. Needless to say, this is very slow and not very
useful. Therefore I wanted to be able to pass Image-objects from the
Python Image Library to the library wrapper and have it use it's raster
data.
Since the library wants the data contained in Imaging->image exactly, I
figure I don't even have to memcpy it. So now I'm trying to include the
Image extension type of the PIL library in my wrapper, and failing.
Getting an extension type from the PIL library seems to be quite a bit
more complex than the complexobject-example in the documentation. This
is the information I have extracted from the PIL sources (my C skills
have rusted over the years of my Python addiction):
The 'Image'-class is an ordinary Python-class (not an extension type)
which contains an attribute 'im' which is the extension type 'ImagingCore'.
The PyTypeObject is 'Imaging_Type', and the associated structure
containing the PyObject-struct is 'ImagingObject'. This is defined in
_imaging.c.
'ImagingObject' contains an 'Imaging'-type, the 'Imaging'-type is
defined in 'libImaging/Imaging.h' and is a typedef-ed
'ImagingMemoryInstance'-pointer, also declared in the same header file.
The 'ImagingMemoryInstance' contains the 'image'-pointer I want to use.
However I try to map these findings onto PyRex, I can't seem to get it
to work. I was hoping someone has already used the PIL in his/her
project and could give me an example of how to do it. Or shouldn't this
be the case I'd really like some tips on how to proceed.
Regards,
G. Kunze
More information about the Pyrex
mailing list