[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame.image.frombuffer problems




On Dec 31, 2005, at 2:45 AM, Peter Shinners wrote:

It isn't really a "raw PNG" file, the string is just the raw pixel representation of the image.


After browsing through the cairo source and pycairo source I know what
you mean by raw pixel representation now, so I guess I did learn
something.  :)


I'm confident in the pygame code to handle this. This is the way images
are currently transferred between python programs like pygame, pyopengl,
pil, and pymedia. The pygame tostring and fromstring are currently
working with these other packages.


I'm browsing the pycairo source now. The function you want is already
there, it is a method called "to_rgba" on the ImageSurface objects. This
returns the string buffer object you can use with
pygame.image.frombuffer() or pygame.image.fromstring()


pycairo does indeed have an ImageSurface.to_rgba method, but from
reading this[1]:

* It requires a patched version of cairo which provides:
* cairo_image_surface_get_data()
* cairo_image_surface_get_format()
* cairo_image_surface_get_stride()

I discovered I needed a patch.

After some digging around through the cairo mailing lists, I found the
patch[2] the comment was referring to but unfortunately the patch seems
to have never been applied.  While I am sure there is good reason for
not applying the patch, I am unable to find any discussion regarding
the patch.

I did, however, find a bug report[3] open on the topic, but it has been
stagnant for a while now.

I suppose I will patch my local cairo source myself and hope for the
best.  Wish me luck.  :)

[1]http://cvs.cairographics.org/pycairo/cairo/pycairo-surface.c? rev=1.62&view=markup
[2]http://lists.freedesktop.org/archives/cairo-commit/2005-October/ 005401.html
[3]https://bugs.freedesktop.org/show_bug.cgi?id=4687



You may also consider the ImageSurface.create_for_data() classmethod
which should allow you to get into cairo from pygame's fromstring()
function.


Do you mean "from pygame's tostring() function"?


Regards, __ Trevor Fancher http://fancher.org/

Attachment: smime.p7s
Description: S/MIME cryptographic signature