[Image-SIG] Quicker image transfer, tobuffer?

Travis Oliphant oliphant.travis at ieee.org
Tue Jul 11 20:37:25 CEST 2006


Fredrik Lundh wrote:
> Christopher Barker wrote:
> 
> 
>>This is crying out to be a use for the new "array interface" proposed 
>>(and used) by numpy:
>>
>>http://numeric.scipy.org/array_interface.html
>>
>>Essentially, the idea is similar to a buffer, but with more information 
>>carried along with it. Rather than an arbitrary array of bytes, the 
>>interface provides a pointer to the data, and also information about the 
>>size, layout and type of the data.
> 
> 
> unfortunately, the "array interface" model isn't even close to be able 
> to describe a PIL image memory (the "Imaging" structure)...
> 

Is this because PIL images are basically "arrays of pointers" to data? 
  Actually, the Python side of the interface should still work as long 
as the PIL objects support the Sequence Interface.  Of course this is 
not really "sharing" memory and it's debatable whether the tostring 
approach is not better anyway in that case.   Even in this case,
the PIL could handle non-contiguous Images by internally performing a 
tostring and supplying the string as the __array_interface__['data'] 
member and setting the read-only flag so that the consumer knows they 
don't have the ability to change the actual data.

There ought to be a way to at least make the conversion process 
automatic even if there is no way to "share memory" because of the 
different memory model concepts.

On the other hand, it seems that some PIL images are "block memory 
based".    Those that are "block memory" based should be easy to share 
memory with using the __array_struct__ approach.

> is the __array_struct__ CObject thing new, btw?

The __array_struct__ has been there since last summer (2005).  It's the 
default way that the array packages share data with each other.   Only 
PIL Images with the ->block member not NULL could be shared this way 
(but at least those could be shared).

Perhaps together we could come up with ways that the data could be 
shared.

For example, could the PIL be changed to support the block-memory 
approach that other packages use.  What is the advantage of using an 
array of pointers to pointers over the block-memory approach?

As we in the NumPy world push for some ability for Python 2.6 to 
understand arrays, the input of the PIL community would be useful.

Best regards,

-Travis Oliphant
NumPy developer



More information about the Image-SIG mailing list