List Info

Thread: Quicker image transfer, tobuffer?




Quicker image transfer, tobuffer?
user name
2006-07-07 06:27:51
It looks like the Pygame will soon be wanting quicker
methods for sharing image
data than the traditional tostring/fromstring. Both PIL and
Pygame now have a
"frombuffer" command, which speeds up this
transaction by avoiding one of the
two copies of pixel data.

We're explorating the idea of "tobuffer"
communication, that would allow
copy-free transfer of images between libraries.

We're pushing  much more of our library to ctypes. This is
a Google Summer of
Code project, and we have already succeeded at getting a PIL
Image tostring
mapped into the SDL_Surface structure without any C code on
our side. 

Moving more of the Pygame library to Python/ctypes has us
looking to lean on
outside libraries for the heavy drawing and filtering work.

If we could get a data pointer to the pixel data into Python
we could perform
the zero copy image transfer with no C extension. Obviously
there are potential
issues when two image libraries are mapping to the same
pixel data. On the SDL
side we have the advantage that the SDL_Surface structures
understand the
concept of not "owning" the pixel data.

It's been awhile since I looked at the python Buffer object
API. Would there be
any direct problems providing a Image.tobuffer() call to
match tostring()? The
other option could be to rely on ctypes to return a
ctypes.c_ubytes_Array back
to pythonspace. I believe we could have just as good results
with the array data
type already including in the python standard lib.

Obviously we will benefit from the same sort of techniques
going back and forth
with the PyopenGL libraries, but I thought it would be smart
to start the
process with PIL.

_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig
Quicker image transfer, tobuffer?
user name
2006-07-11 00:09:41
Pete Shinners wrote:
> It looks like the Pygame will soon be wanting quicker
methods for sharing image
> data than the traditional tostring/fromstring. Both PIL
and Pygame now have a
> "frombuffer" command, which speeds up this
transaction by avoiding one of the
> two copies of pixel data.

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.

The goal of the numpy team is to get this integrated into
the python 
standard library, so that any package that deals with arrays
of data can 
communicate easily with other such packages.

There are a lot of folks already transferring data back and
forth 
between numpy arrays, PIL images, PyGame, OpenGL, wxPython,
etc. It 
would be a really great thing to get a few more packages
sharing the 
same protocol.

Please join the numpy team in this, it will really benefit
the Python 
community to have one way of exchanging this kind of data.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barkernoaa.gov
_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig
Quicker image transfer, tobuffer?
user name
2006-07-11 06:56:14
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 the __array_struct__ CObject thing new, btw?

</F>

_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )