python 2.6: how to modify a PIL image from C without copying forth and back
Stefan Behnel
stefan_ml at behnel.de
Wed Mar 3 05:10:21 EST 2010
News123, 03.03.2010 10:37:
> Stefan Behnel wrote:
>> Take a look at Cython instead, it will allow you to access PIL's image
>> buffer directly, instead of copying the data. It will also simplify and
>> speed up your C wrapper code.
>
> I don't know Cython. Having looked at the web site I'm not entirely
> sure, I understood your suggestion.
>
> Do you mean
> - to stay with Python 2.6 and to implement only my extension in Cython.
Absolutely.
> This might be very attractive. If yes, can you recommend some url's /
> tutorials / etc. which might help to implement a cython extension for
> python2.6. which reads and modifies a pixel of a PIL image.
Check out the tutorial on the web site, and ask on the cython-users mailing
list about integration with PIL. I'm sure you'll get some useful examples.
Here's something closely related, although it doesn't really use PIL (but
the mechanisms are the same):
http://wiki.cython.org/examples/mandelbrot
> or do you mean
> - to switch entirely from Python 2.6 to Cython. I would be reluctant to
> do so, as I have already a lot of existing code. and I do not have the
> time to check the entire code base for portability issues
The nice thing about Cython is that you always have a normal CPython
interpreter running, so you can split your code between the interpreter and
the compiler at any level of granularity. However, the advice was really to
write your image processing algorithm in Cython, not your entire program.
Stefan
More information about the Python-list
mailing list