python 2.6: how to modify a PIL image from C without copying forth and back

News123 news123 at free.fr
Wed Mar 3 09:43:21 CET 2010


Hi Tim,

Tim Roberts wrote:
> News123 <news123 at free.fr> wrote:
>> I created a grayscale image with PIL.
>>
>> Now I would like to write a C function, which reads a;most all pixels
>> and will modify a few of them.
>>
>> My current approach is:
>> - transform the image to a string()
>> - create a byte array huge enough to contain the resulting image
>> - call my c_function, which copies over the entire image in order
>>   to modify a few pixels
>> How can I achieve this with the least amount of copies?
> 
> If it were me, I'd be tempted to go peek at the source code for PIL, then
> pass the Image object to my C routine and poke at the innards to find the
> buffer with the pixels.

Yes, this might be an option
Somehow though it didn't feel right for me to depend on internal non
documented data types, which might change between releases of PIL.

N



More information about the Python-list mailing list