new to wxwindows, need advice on image blt performance issues

Hello,

   I'd like to use wxPython for a new project of mine. I have not written a line of wxWindows code, so I'd like to ask how the following works:

   How does one specify an image (from Python code) to be blitted to the display (using wxPython ?)...In wxWindows it seems there's a pixel data pointer you can use to initialize the bitmap bits, but there aren't any pointers in Python. What I want to do is have a C-module function called from Python to generate an image (it needs to be C because it has to have some high performance rendering code in it. ). This image would be passed back to Python somehow, and then blitted to a UI window using wxPython.

    1) How feasible is this, i.e. is it possible, and how much data copying is needed ?
    2) On a P4, would it be feasible to blit 15 frames / second of 1024x768 resolution (ignoring rendering time) ?

Chris wrote:

First, take a look at the Wiki Page:

http://wiki.wxpython.org/index.cgi/WorkingWithImages

There is some good stuff there that will get you started. It doesn't
directly cover your question, but it would be great if you would add to
the page when you have your app figured out.

   How does one specify an image (from Python code) to be blitted to the display (using wxPython ?)...

Use wxImage.ConvertToBitmap() and then select the bitmap into a
wxMemoryDC then to the display with a wxClientDC and wxDC.Blit(). You
could also try using wxDC.DrawBitmap, which should work, and be easier,
but I've had some problems with a wxClient.DrawBitmap() on windows (it's
always worked for me on GTK)

In wxWindows it seems there's a pixel data pointer you can use to
initialize the bitmap bits, but there aren't any pointers in Python.

Nope, for the most part, if wxWindows wants a pointer to a given type of
object, wxPython just want that object.

What I want to do is have a C-module function called from Python to
generate an image (it needs to be C because it has to have some high
performance rendering code in it. ). This image would be passed back to
Python somehow, and then blitted to a UI window using wxPython.

    1) How feasible is this, i.e. is it possible, and how much data copying is needed ?

Sure is, how much copying depends on how you do it. Here is one way,
though I've never tried this myself.

You can create a wxImage from your data with

wxImage.SetData(APythonStringWithYourData)

You'll have to create a Python string with your data in your C code,
which should be pretty straightforward.I htink the format is: "an array
of characters in RGBRGBRGB"

Then convert to Bitmap:

bitmap = wxImage.ConvertToBitmap()

Then select it into a wxMemory DC:

memDC = wxMemoryDC()
memDC.SelectObject(bitmap)

ScreenDC = wxClientDC
ScreenDC.Blit(xdest, ydest, width, height, memDC, xsrc, ysrc)

If you are copying the whole thing, most of those are 0

You can also do it without the wxMemory DC with:

ScreenDC.DrawBitmap(bitmap,x,y)

But as I said, I have had problems with that on windows.

If you have performance problem with all this converting, you may be
able to create the wxImage in C++, or even create the wxBitmap in C++,
or maybe use:

wxBitmapFromBits(bits, width, height, depth=-1)

Create a bitmap from an array of bits contained in a string.

OOPS, I just found this note in the docs:

"""You should only use this function for monochrome bitmaps (depth 1) in
portable programs: in this case the bits parameter should contain an XBM
image.

For other bit depths, the behaviour is platform dependent: under
Windows, the data is passed without any changes to the underlying
CreateBitmap() API. Under other platforms, only monochrome bitmaps may
be created using this constructor and wxImage should be used for
creating colour bitmaps from static data."""

So it looks like you're back to useing wxImage.

    2) On a P4, would it be feasible to blit 15 frames / second of 1024x768 resolution (ignoring rendering time) ?

Absolutely, though it depends on your video card as well.

-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@noaa.gov

Chris wrote:

Hello,

I'd like to use wxPython for a new project of mine. I have not
written a line of wxWindows code, so I'd like to ask how the
following works:

Already answered this on wx-users:

http://lists.wxwindows.org/cgi-bin/ezmlm-cgi?8:mss:33434:200303:jbefjhljppgnljcimgla

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!