SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

How to create a huge SUImageRef object?SUImageRepResize is too slow! #999

Open yuanningcz opened 1 week ago

yuanningcz commented 1 week ago

SketchUp version:2024 OS Platform: win10 x64 C API

I want to write a huge picture in a skp file. For example, width:100000 inches,height: 100000 inches。 Here is what I did:

        sRes = SUImageRepLoadFile(sImageRep, strTexFilePath.c_str());
        if (sRes != SU_ERROR_NONE) break;

        double fWidth = 10E5;
        double fHeight = 10E5;

        sRes = SUImageRepResize(sImageRep, fWdith, fHeight);
        if (sRes != SU_ERROR_NONE) break;

        SUImageRef sImage_Scale = SU_INVALID;
        sRes = SUImageCreateFromImageRep(&sImage_Scale, sImageRep);

        if (sRes != SU_ERROR_NONE) break;    

        SUTransformation transform = CubeToSkpHelper::GetSuTrans(withoutScaleMtx);
        SUImageSetTransform(sImage_Scale, &transform);

        sRes = SUEntitiesAddImage(parentEnt, sImage_Scale);

SUImageRepResize takes a very long time to complete。 Is there any other faster way to create a super large image in skp file?

thomthom commented 1 week ago

I want to write a huge picture in a skp file. For example, width:100000 inches,height: 100000 inches。

   double fWidth = 10E5;
   double fHeight = 10E5;

   sRes = SUImageRepResize(sImageRep, fWdith, fHeight);

Looks like you are conflating model units and pixel units here.

SUImagRepRef deals with pixels, not model units. You are creating an image that is 100000px x 100000px - here. If that's 8bpp that's ten gibabytes! If this is 24bpp that's thirty gigabytes. Does that code even complete? You don't run out of memory?

From the rest of your code it appear that you load an image file using SUImageRepRef and then try to create an Image entity; SUImageRef. Note that these are very different things. SUImageRepRef is a data structure to hold the pixel data. SUImageRef is a drawing element that displays that displays images in the model.

SUImageRef is essentially a specialized form of a Group or Component instance.

If you want the Image to be 100000x100000 inches in model space you create a transformation that scales the Image entity to that size. You don't resize the pixel data for that.