speed up display of image data from 3rd party C++ extension, contd.

Hello!

A while ago, I asked on this list how to speed up image display by
directly converting C++ image objects from a third-party image
processing library into wxBitmaps
(http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss:61405:200702:gdepckoidchkjaacmnaj).

The code below is the (fairly straightforward) result of following
Robin's advice to use the wx Python API to pass a newly created bitmap
filled with the data from my custom source image back to Python.
Everything compiles and runs fine - but when I try to blit this bitmap
to the screen, nothing happens (the screen remains blank). If I convert
the bitmap (in Python!) to a wxImage and back to a wxBitmap, everything
works as expected, so the data seem to be there - somehow. Does anybody
have an idea what's going on here?

Thanks,

Oliver

template<class IMAGE>
PyObject *
convertGrayToWxBitmap(IMAGE const & image)
{
  int iWidth = image.width();
  int iHeight = image.height();

  wxBitmap * oBmp = new wxBitmap(iWidth, iHeight, 24);
  wxNativePixelData oPixData(*oBmp, wxPoint(0,0), wxSize(iWidth, iHeight));
  if (!oPixData)
  {
    // raise an exception...
    wxPyErr_SetString(PyExc_RuntimeError,
                      "Failed to gain raw access to bitmap data.");
    return NULL;
  }

  typename IMAGE::ConstIterator oSrcYIterator = image.upperLeft();

  wxNativePixelData::Iterator oPixIterator(oPixData);
  for (int y=0; y<iHeight; y++, oSrcYIterator.y++)
  {
    wxNativePixelData::Iterator oRowStartIterator = oPixIterator;
    typename IMAGE::ConstIterator oSrcXIterator = oSrcYIterator;
    for (int x=0; x<iWidth; x++, oSrcXIterator.x++, oPixIterator++)
    {
      unsigned char iPixelValue = (unsigned char)*oSrcXIterator;
      oPixIterator.Red() = iPixelValue;
      oPixIterator.Green() = iPixelValue;
      oPixIterator.Blue() = iPixelValue;
    }
    oPixIterator = oRowStartIterator;
    oPixIterator.OffsetY(oPixData, 1);
  }

  PyObject* oPyBmp = wxPyMake_wxObject(oBmp, true);
  wxASSERT(oPyBmp != NULL);
  return oPyBmp;
}

···

--
--------------------------------------------------------------------
F. Oliver Gathmann, Ph.D.
Director IT Unit
Cenix BioScience GmbH
Tatzberg 47 phone: +49 (351) 4173-136
D-01307 Dresden, Germany fax: +49 (351) 4173-109

fingerprint: 8E0E 9A64 A07E 0D1A D302 34C2 421A AE9F 4E13 A009
public key: http://www.cenix-bioscience.com/public_keys/gathmann.gpg
--------------------------------------------------------------------