I tried it, but not with the function. I simply get the data pointer from Ruby and tried SUImageRepSetData() on it but it crashes.
I will try the specific function, but as far as I remember it does exactly same.
In our case, we need only to fast read so I never tried update the data. During some devcamp I’ve asked if we can have fast methods for updating the data, but, as always this are not the most important things
Maybe you can open a feature request on github issue tracker?
BTW, maybe the simplest way would be to create ImgRep in C, then convert it to Ruby and change the Ruby object in your Ruby code?
This is not that surprising, since the SketchUp Ruby API is a thin layer over the internal C++ logic, the same goes for the C API.
When it comes to performance it would really help to have a complete representative example of what you are doing. We can then run it through a profiler and see what is going on. Also without going via a profiler it’d be a lot easier to give a proper response to this. Hard to give generic performance response to a specific issue.
I have @image_rep in a tool. I use this ImageRep to texture objects I draw. I want to paint the texture in real-time. 120ms in SUImageRepSetData() for 2048x2048 texture is too much. The image is not used anywhere else - so nothing has to be updated until I manually view.load_texture(@image_rep).
In this case memcpy(dest,soure,size) would probably be enough. I just need to know the destination.
SUImageRepSetData() does the job alright. It replaces the existing image data with a copy of the supplied buffer. It is fine.
The performance is the only issue. Simple memory copy would work alright and way faster in this case, I believe, because the intention is to modify just the bitmap data. I am convinced Ruby and C use the same buffer internally. This buffer is intended to be used later for new texture creation.
Well, Ruby itself is written in C. The two APIs are wrapping the same C++ core functionalities.
But it is the API consumer (you, I or others) that is creating the array buffer in both cases. The buffer can be subsequently reused or discarded.
Well, the C API documentation indicates in ("headers\SketchUpAPI\model\image_rep.h") that SUImageRepRef is a struct. If we think that the order of it’s members is the same as the order of parameters in the SUImageRepSetData function then could you get a pointer to the last member of the struct ?
The Ruby examples show the packing of the array as "C*" (which is 8-bit unsigned char) before passing to Sketchup::ImageRep#set_data. The Ruby parameter type is String.
Perhaps the “slow” C API set data function is doing something similar that you may need to replicate ?