I’d like to create a specific class from CBitmap in order to load a bitmap with a specific scalefactor.
My purpose is to easily provide various sizes for the UI, but only from a big one.
Firstly I hope that when the scale factor is set before loading the bitmap, the memory and the drawing would be done from a resized picture, not the full size one.
But I have a problem with IPlatformBitmap, I don’t know how to create it from the ressourceDescription. Just copy/past the original cbitmap code doesn’t work (incomplete type ‘VSTGUI::IPlatformBitmap’ named in nested name specifier)
Any idea ?
I would not go this route. Painting sub images on macOS is slow. Why don’t you want to use it as is? You can just add all the different scale factors to it with CBitmap:: addBitmap().
Hi Arne,
Thanks for your answer. Firstly, I found the compiling error, I forgot to include iplatformbitmap.h in the .cpp file. This solution seems to work so far, but I can’t tell anything yet about how it’s slow or not. Here the code I added to CBitmap
XBitmap::XBitmap (const CResourceDescription& desc, double Scalefactor)
{
resourceDesc = desc;
SharedPointer platformBitmap = owned (IPlatformBitmap::create ());
if (platformBitmap)
{
platformBitmap->setScaleFactor(Scalefactor);
if (platformBitmap->load (desc))
{
bitmaps.push_back (platformBitmap);
}
}
}
About adding bitmap for each factor, that’s a solution if I can work on the graphic element with only the biggest GUI and not to have to scale down manually each image.
So if that’s the case, I just don’t see the difference. The added image would be loaded with an other scalefactor, but still full size in the memory (if I correctly understood) and then downsized when redrawn.
OK, it looks like I misunderstood what you want to achieve.
Your implementation will force the CPU to rescale the image every time when it is drawn and the scale factor of the target is different than of the image.
So far, the code is working as I expected, the GUI size can be easily changed to any value by simply changing the scale factor, but obviously wasting CPU is not what I want !
Is there a way to downscale the image when loading and not when drawing ?
It seems that there is other users who want to do so (like in the thread slighty-blurry-gui-witch-certain-zoom-factors)
But maybe I misunderstood something with the scale factor
Best way is to pre render the bitmaps. If you have a UI designer than you should order bitmaps for the different scale factor where you want your plug-in to be looking good at. This should always be preferred than to downscale a bitmap.
Thanks for this answer Arne.
So it seems that what I want to do it is not possible right now.
Having bitmaps for several scale factors is what I did for years, but it’s quite annoying and asking more work when a new size is needed or a simple change in the GUI is done. That’s why I wanted to simplifying this workflow using the scale factor (especially for offering the user to choose freely it’s GUI size)
I was thinking about something that I don’t know if this is possible
When the GUI is loaded:
1- Loading a full size bitmap (A) with a specific scale factor (f)
2- create a bitmap (B) with a size corresponding to the downscale image
3- Drawing the downscale bitmap (A) to that created new sized bitmap (B)
4- returning the bitmap B (with a scale factor of 1.0) instead of (f)
This way, after loading the GUI will always work with an adapted bitmap without needing to downscale when drawing. All the CPU would be need at launch.
So the question is if the point 3- is possible to do
sorry for bothering you!
I’m scratching my head trying to implement a bilinear Scale filter on an CBitmap, but I can’t sort this out.
Do you have any simple sample code ?
Thanks in advance
I’m almost done, but I can’t find how to get the scaled bitmap after running the filter.
The ScaleBase filter is creating an output bitmap (line 698), but there is no getOutputBitmap as there is a getInputBitmap.
I try to create my own CBitmap and pass it through the setProperty, but it’s not taken into account.
I’m sure I miss something with the getProperty function, but can sort it out;
How do I get a CBitmap from getProperty(BitmapFilter::Standard::Property::kOutputBitmap) ?