[wxPython-users] speed up display of image data from 3rd party C++ extension

Christopher Barker Chris.Barker at noaa.gov
Thu Feb 15 15:17:59 PST 2007


F. Oliver Gathmann wrote:
>> No, it wouldn't. That's the whole point of the buffer interface, when
>> you create a Bitmap from a buffer, it uses the buffer data directly,
>> it does not make a copy.
> That's what I thought initially, too. But if you look at the code, the
> various implementations of wx.BitmapFromBuffer (file _gdi_wrap.cpp in
> the gtk/mac/msw subfolders in the wxPython source folder) allocate a new
> bitmap and use "wxNativePixelData::Iterator" to set each pixel in the
> new bitmap from the buffer source.

Thanks for the info -- shows you what I know!

> And in the docs it says:
> 
>     Unlike `wx.ImageFromBuffer` the bitmap created with this function
>     does not share the memory buffer with the buffer object.  This is
>     because the native pixel buffer format varies on different
>     platforms, and so instead an efficient as possible copy of the
>     data is made from the buffer objects to the bitmap's native pixel
>     buffer.  For direct access to a bitmap's pixel buffer see
>     `wx.NativePixelData` and `wx.AlphaPixelData`.

I was wondering how that could work. But what if it does happen to 
match? Is wx.NativePixelData available form Python? I wonder if the 
numpy array could help here in the future, as you'd have a data 
description with the data. You still wouldn't know if it was RGBA or 
ARGB, though, I suppose...

> So, I  guess I will be investigating the route that Robin suggested -
> write a small extension that uses the wxPython API

That'll really still give you the same problem. If your platform isn't 
using the same bitmap format as you, you still need the copy -- it may 
well be that wx.BitmapFromBuffer is about as efficient as you can get.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list