Tuesday, November 28, 2023
Home3D ModelingRuby ImageRep quickest picture information replace from C - SketchUp SDK

Ruby ImageRep quickest picture information replace from C – SketchUp SDK


I need to exchange present picture information inside SU Ruby ImageRep as quick as attainable. Ruby is just too sluggish in my particular case. I need merely to overwrite complete ImageRep uncooked information buffer.

I’ve executed an investigation however couldn’t discover a solution to get the pointer to the information.

ImageRep.information returns a duplicate of knowledge as a string. It’s not helpful.

I respect any suggestions on this.


For simplicity – CAPI extension working with a Dwell mannequin.

SU2023 purposes/ruby_api.h
SU_RESULT SUImageRepFromRuby(RUBY_VALUE ruby_imagerep, SUImageRepRef* imagerep);

Usually you shouldn’t change something from LiveAPI however perhaps it’ll be just right for you if you happen to solely change the content material of pixels, you’ll have to examine.

For positive you may learn pixels very quick utilizing SUImageRepRef, perhaps you too can replace the content material utilizing this manner.

Thanks.

I attempted it, however not with the operate. I merely get the information pointer from Ruby and tried SUImageRepSetData() on it nevertheless it crashes.
I’ll strive the precise operate, however so far as I bear in mind it does precisely similar.

SUImageRepFromRuby() helps on this regard that subsequent SUImageRepSetData() doesn’t crash on it. It’s not as quick as I want to, nevertheless it definitely a step in proper route.

Thanks and greetings from Lodz!



1 Like

In our case, we want solely to quick learn so I by no means tried replace the information. Throughout some devcamp I’ve requested if we will have quick strategies for updating the information, however, as at all times this aren’t an important issues :slight_smile:

Perhaps you may open a characteristic request on github subject tracker?

BTW, perhaps the best manner could be to create ImgRep in C, then convert it to Ruby and alter the Ruby object in your Ruby code?

SU_RESULT SUImageRepToRuby(SUImageRepRef imagerep, RUBY_VALUE* ruby_imagerep);

@thomthom Is there any variations between SUImageRepTo/FromRuby and getting the pointer from Ruby object?

I run a profiler and truly SUImageRepSetData() is sort of as sluggish as calling Ruby C capabilities.

I need to simply copy the uncooked information. The width, top, pixel measurement and padding don’t change.

It appears like SketchUp initializes/allocates every part from scratch.

This isn’t that shocking, for the reason that SketchUp Ruby API is a skinny layer over the interior C++ logic, the identical goes for the C API.

Relating to efficiency it could actually assist to have an entire consultant instance of what you might be doing. We are able to then run it via a profiler and see what’s going on. Additionally with out going through a profiler it’d be rather a lot simpler to provide a correct response to this. Laborious to provide generic efficiency response to a selected subject.

Have you ever checked what information you might be feeding it? Once more, it’d assist to have a reproducible instance.

I’ve @image_rep in a instrument. I take advantage of this ImageRep to texture objects I draw. I need to paint the feel in real-time. 120ms in SUImageRepSetData() for 2048×2048 texture is an excessive amount of. The picture is just not used wherever else – so nothing must be up to date till I manually view.load_texture(@image_rep).

On this case memcpy(dest,soure,measurement) would most likely be sufficient. I simply have to know the vacation spot.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments