Python/SWIG handling of pointers to an image buffer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Python/SWIG handling of pointers to an image buffer

Kyle Douglass-2
Hi all,
I am a bit confused about how image data is passed from the C++ core layer and converted into a Numpy datatype in the Python wrapper. In the SWIG configuration file, I believe that image data is copied from a camera device's buffer to a Numpy datatype in the definition of an output typemap of a void pointer (void*). https://github.com/micro-manager/micro-manager/blob/mm2/MMCorePy_wrap/MMCorePy.i#L58

The C++ method GetImageBuffer(), however, returns a pointer to an unsigned char (unsigned char*), not void*. https://github.com/micro-manager/micro-manager/blob/mm2/MMCore/Devices/CameraInstance.h#L40

To add to my confusion, the Java SWIG configuration defines a typemap(out) for both void* and unsigned char*. https://github.com/micro-manager/micro-manager/blob/mm2/MMCoreJ_wrap/MMCoreJ.i

Does SWIG automatically interpret return types of unsigned char* as void*? If yes, why are there two typemap(out)'s in the MMCoreJ SWIG configuration, one for void* and one for unsigned char*?

Thanks!
Kyle


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Python/SWIG handling of pointers to an image buffer

Kyle Douglass-2
I think the jet lag is getting to me ;)

The answer to my question is that GetImageBuffer() is in the Camera device API but not the core API. The methods that return images in the Core API all return void pointers, so the Python wrapper really is converting the return types of popNextImage(), getLastImage(), etc. correctly; SWIG is not automatically converting unsigned char*'s to void*'s.

I still don't know why the Java wrapper defines a typemap(out) for unsigned char*'s since no core API method returns a pointer to this datatype, but I am willing to live with this little mystery.

Best regards,
Kyle

On Tue, Jan 8, 2019 at 10:23 PM Kyle Douglass <[hidden email]> wrote:
Hi all,
I am a bit confused about how image data is passed from the C++ core layer and converted into a Numpy datatype in the Python wrapper. In the SWIG configuration file, I believe that image data is copied from a camera device's buffer to a Numpy datatype in the definition of an output typemap of a void pointer (void*). https://github.com/micro-manager/micro-manager/blob/mm2/MMCorePy_wrap/MMCorePy.i#L58

The C++ method GetImageBuffer(), however, returns a pointer to an unsigned char (unsigned char*), not void*. https://github.com/micro-manager/micro-manager/blob/mm2/MMCore/Devices/CameraInstance.h#L40

To add to my confusion, the Java SWIG configuration defines a typemap(out) for both void* and unsigned char*. https://github.com/micro-manager/micro-manager/blob/mm2/MMCoreJ_wrap/MMCoreJ.i

Does SWIG automatically interpret return types of unsigned char* as void*? If yes, why are there two typemap(out)'s in the MMCoreJ SWIG configuration, one for void* and one for unsigned char*?

Thanks!
Kyle


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general