I'm writing a python script for a program that has exposed its C++ API using SWIG. A SWIG exposed function has an interface like this:
void writePixelsRect(JoxColor* colors, int left, int top, int width, int height);
JoxColor is a POD struct looking like this:
struct JoxColor {
float r, g, b, a;
};
I can easily create a single JoxColor in Python and invoke a call to writePixelsRect like this:
c = JoxApi.JoxColor()
c.r = r
c.g = g
c.b = b
c.a = a
JoxApi.writePixelsRect(c, x, y, 1, 1)
Repeatedly calling writePixelsRect with a 1x1 pixel rectangle is very slow so I want to create an array of JoxColor from python so I can write bigger rectangles at the time. Is this possible with SWIG types?
Note that I don't have access to the source code for the C++ library exposing JoxColor and writePixelsRect so I can't add a help function for this. I also don't want to introduce new C++ code in the system since it would force the users of my python script to compile the C++ code on whatever platform they are running. I do have access to ctypes in the python environment so if I could somehow typecast a float array created in ctypes to the type of JoxColor* for SWIG it would work for me.