On 8/17/06, Christopher Barker <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I seem to be talking to myself here, but if someone (including myself)
> wants to pick this up in the future, it'll be good to have it in the
> archives.
>
> Christopher Barker wrote:
> >> There is also the
> >> wx.Image.SetDataBuffer method, which will have the wxImage use the
> >> buffer passed in without making a copy, but if the buffer doesn't
> >> live as long as the image does it will likely cause a crash.
> >
> > This would probably be the easiest way to get top performance at the
> > moment. If we can make the Agg data a buffer, and somehow do the
> > reference counting right so it doesn't get deleted while the wxImage is
> > still around (that may not be hard -- the wxImage has to be converted to
> > a wxBitmap to be drawn anyway)
>
> I've been suing this for another use, and Robin just added an improved
> version of new wx.Image factory function I wrote for just this purpose:
>
> def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None):
>      """
>      Creates a `wx.Image` from the data in dataBuffer.  The dataBuffer
>      parameter must be a Python object that implements the buffer
>      interface, such as a string, array, etc.  The dataBuffer object is
>      expected to contain a series of RGB bytes and be width*height*3
>      bytes long.  A buffer object can optionally be supplied for the
>      image's alpha channel data, and it is expected to be width*height
>      bytes long.
>
>      A reference to the data and alpha buffer objects are kept with the
>      wx.Image, so that they won't get deleted until after the wx.Image
>      is deleted.  However please be aware that it is not guaranteed that
>      an object won't move its memory buffer to a new location when it
>      needs to resize its contents.  If that happens then the wx.Image
>      will end up referring to an invalid memory location and could cause
>      the application to crash.  Therefore care should be taken to not
>      manipulate the objects used for the data and alpha buffers in a
>      way that would cause them to change size.
>      """
>      image = wx.EmptyImage(width, height)
>      image.SetDataBuffer(dataBuffer)
>      if alphaBuffer is not None:
>          image.SetAlphaBuffer(alphaBuffer)
>      image._buffer = dataBuffer
>      image._alpha = alphaBuffer
>      return image
>
> Does the aggDrawer already implement a Python buffer object? If so,
> using this would be easy. If not, then it probably should, unless we go
> straight to the numpy array protocol.

I haven't had time to thoroughly absorb all your post.  From skimming
it looks like we could do a similar approach as the qtagg blitting.
If you look at the else clause in the FigureCanvasQTAgg.paintEvent
method, you'll see we added a to_string method to the BufferRegion
object.  Using this string buffer we create a QImage and blit it.  It
includes the alpha channel.  I'll paste the block of interest to save
you a little digging.

            bbox = self.replot
            w, h = int(bbox.width()), int(bbox.height())
            l, t = bbox.ll().x().get(), bbox.ur().y().get()
            reg = self.copy_from_bbox(bbox)
            stringBuffer = reg.to_string()
            qImage = qt.QImage(stringBuffer, w, h, 32, None, 0,
qt.QImage.IgnoreEndian)
            self.pixmap.convertFromImage(qImage, qt.QPixmap.Color)
            p.drawPixmap(qt.QPoint(l, self.renderer.height-t), self.pixmap)

- Charlie

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to