Reinterpret a CGImageRef using PyObjC in Python
- by Michael Rondinelli
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?