I'm currently working on a project involving lots of image processing.
Most of the graphics intensive work is done in C++ using the boost::python
wrapping mechanism, while all of the GUI is written in wxPython.
When it comes to displaying the image, I currently return it to Python as
a string. The Python code then passes that string to wxImage::SetData and
the wxImage is later displayed.
This works fine, except the string, which is often very large, must be
copied from C++ into a Python string. I would like to avoid this copy. I
have tried allocating a Python string from within the C++ and filling that
with the data and then returning it. However, it seems that the data is
deallocated almost immediately, no matter how many times I call Py_INCREF
on it.
The second approach I would like to try is to create a wxImage directly in
C++ and return that. However, since I'm not using SWIG, I'm not entirely
sure how to do this so that the returned object will look to Python just
like a _Python_ wxImage. boost::python does allow returning unmodified
'PyObject *'s so this should be theoretically possible, right?
Any assistance would be greatly appreciated.
···
--
Michael Droettboom
mdboom@peabody.jhu.edu
410.625.7596
Computer Music Research
Peabody Conservatory of Music
Johns Hopkins University