views:

50

answers:

1

Hi, I'm doing something that's a little complicated to sum up in the title, so please bear with me.

I'm writing a Python module that provides an interface to my C++ library, which provides some specialized image manipulation functionality. It would be most convenient to be able to access image buffers as CGImageRefs from Python, so they could be manipulated further using Quartz (using PyObjC, which works well).

So I have a C++ function that provides a CGImageRef representation from my own image buffers, like this:

CGImageRef CreateCGImageRefForImageBuffer(shared_ptr<ImageBuffer> buffer);

I'm using Boost::Python to create my Python bridge. What is the easiest way for me to export this function so that I can use the CGImageRef from Python?

Problems: The CGImageRef type can't be exported directly because it is a pointer to an undefined struct. So I could make a wrapper function that wraps it in a PyCObject or something to get it to send the pointer to Python. But then how do I "cast" this object to a CGImageRef from Python? Is there a better way to go about this?

A: 

I think a wrapper is your only option since it is an undefined struct and Boost::Python demands to know the interface. Here is a starting point: http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/faq.html#xref

I would add the necessary member functions you need into the wrapper. I am doing something somewhat similar, seems to be working decently so far :).

spenthil