[Image-SIG] return Imaging to Python
Fredrik Lundh
fredrik@pythonware.com
Thu, 24 Jun 1999 15:24:30 +0200
Huiying Shen <hshen@ski.org> wrote:
> I am writing an C-extension which takes Imaging as input from Python
> interpreter as well as return Imaging back to Python environment. I am
> having problem with the latter. VC++5.0 says: The instruction at
> 0x1e1388a9" referenced at "0x00000048". The memory could not be read.
>
> I used the identical code to generate a Python list in C and return it
> to python just fine.
an Imaging object is just an ordinary C struct,
it's not a valid Python type (it doesn't have the
PyObject_HEAD stuff required by Python). the
Python bindings are defined in _imaging.c, and
are currently not exported to external users.
to work around this, you can:
1) link your stuff with the _imaging module,
and call PyImagingNew to wrap an Imaging
pointer in a Python-compatible Imaging-
Object (see the _imaging.c sources for
details).
or:
2) create the new image in Python code,
and pass its "id" attribute to your extension.
an example:
def myoperation(imIn, arg):
imIn.load()
imOut = Image.new(imIn.mode, imIn.size, None)
mymodule.myoperation(imIn.im.id, imOut.im.id, arg)
return imOut
I usually use approach 2 for PIL extensions.
</F>