Bug 15649 - connonical pycairo/pygame example is broken
Summary: connonical pycairo/pygame example is broken
Status: RESOLVED NOTOURBUG
Alias: None
Product: pycairo
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Steve Chaplin
QA Contact:
URL: http://www.pygame.org/wiki/CairoPygame
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-22 05:59 UTC by damien morton
Modified: 2008-07-16 18:12 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description damien morton 2008-04-22 05:59:02 UTC
Using Python 2.5.2, Cairo 1.4.2, PyCairo 1.4.12, PyGame 1.8

The following code (shown in the url mentioned above):

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
...
render to surface
...
buf = surface.get_data()
...
imsurf = pygame.image.frombuffer(buf, (w,h), "RGBA")
...


results in a TypeError "char buffer type not available"

changing the imsurf... line to :
imsurf = pygame.image.frombuffer(str(buf), (w,h), "RGBA") 

avoid the exception but results in a black image being shown
Comment 1 Steve Chaplin 2008-07-16 18:12:15 UTC
The code used to work, and pycairo has not been changed to stop it working.
It looks like pygame.image.frombuffer() used to accept readable buffers, and has been changed so it now only accepts character buffers.

However, if you look at the Python/C API reference manual, section 10.7 "Buffer Object Structures" where it describes the bf_getcharbuffer slot:
"... This notion of exporting the internal buffers as ``text'' is used to distinguish between objects that are binary in nature, and those which have character-based content. ..."

The pycairo image data is binary, not text or character-based data, so in my opinion, the character buffer slot should not be used to read binary image data.

I suggest opening a pygame bug report to request that pygame.image.frombuffer() stop reading binary image data as text-based characters.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.