[wxPython-users] Re: Improve performance
Christopher Barker
Chris.Barker at noaa.gov
Mon Aug 28 16:08:34 PDT 2006
Robin Dunn wrote:
> There is an overloaded method that can take a C array of wxPoints. That
> class is designed to have the same memory layout as the Windows API
> POINT, which is a simple struct of two integers, so I expect that we
> could force it to take a 2 dimensional array of integers and be ok.
That would be great.
>> http://numpy.scipy.org/array_interface.shtml
>
> Will this protocol be in numpy 1.0? Is it in numarray?
A version of it is in numpy, and the latest version of both Numeric and
numarray. However, both of those are on their way out anyway. Using this
interface wouldn't break anything that already works.
A goal for the summer was to finalize the interface, and submit it for
possible inclusion in the standard lib. In any case, something very much
like it will definitely be in numpy 1.0 when it comes out (I think
they're at 1.0b4 now)
> You may want to take a look at my CVS commits for the last couple weeks.
Our firewall has started blocking cvs and svn. While I argue with out
sysadmins, I can't get it :-(
> I've now got some raw bitmap access code in place. Both 2.6 and 2.7
> will have wx.BitmapFromBuffer and wx.BitmapFromBufferRGBA factory
> functions which can copy from a buffer object directly into the bitmap's
> pixel buffer, and 2.7 will also have wx.NativePixelData and
> wx.AlphaPixelData which allow direct access to the pixel buffer from
> Python.
Very very nice! this will be a great help to matplotlib. Also my weird
alpha blending kludge....
> (The latter needed a bug fix that I'm not sure (yet) can be
> backported to 2.6...) For example, I can now do this (in a PyShell):
>
> >>> import wx
> >>> import numarray
> >>> f = wx.Frame(None)
> >>> p = wx.Panel(f)
> >>> dc = wx.ClientDC(p)
> >>> f.Show()
> >>> dim=100
> >>> R=0; G=1; B=2; A=3
> >>> arr = numarray.array(shape=(dim, dim, 4), typecode='u1')
> >>> for row in xrange(dim):
> ... for col in xrange(dim):
> ... arr[row,col,R] = 0
> ... arr[row,col,G] = 0
> ... arr[row,col,B] = 255
> ... arr[row,col,A] = int(col * 255.0 / dim)
> ...
> >>> bmp = wx.BitmapFromBufferRGBA(dim, dim, arr)
> >>> dc.DrawBitmap(bmp, 20, 20, True)
by the way, on of the points of the num* packages is that you don't have
to loop to work with data in the array:
>>> arr[:,:,R] = 0
>>> arr[:,:,G] = 0
>>> arr[:,:,B] = 255
>>> alpha = numarray.arange(dim) * 255 / dim
>>> arr[:,:,A] = alpha
Much faster.
> BTW, I seem to recall you mentioning that there was some doubt whether
> the buffer protocol would be included in numpy, is that still true?
I have no idea about the buffer protocol. I suppose now that there is
the array interface, they might remove it, but it seems like a good idea
to me to keep it. We'd have to ask on the numpy list. Or just test the
latest numpy. Is there an easy way to test? OK, I just tested it with
the latest numpy, and wx.ImageFromBuffer. Darn, it doesn't work. I get:
File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py",
line 2814, in SetDataBuffer
return _core_.Image_SetDataBuffer(*args, **kwargs)
TypeError: non-character array cannot be interpreted as character buffer
It might be that I am using the wring data type but I tried all the
possible options I could think of. Code enclosed. It works with
numarray, but not numpy. I'll post a question to the numpy list.
This really looks great, Robin. Thanks.
-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.Barker at noaa.gov
More information about the wxpython-users
mailing list