Is using Scale effect in render loop faster than pre-scaling bitmap?

Viewed 51

Currently I draw images next way:

  1. During load, using WIC, I obtain the original bitmap, store it as a property in object, that represents an image (ID2D1Bitmap *imageOriginal property).
  2. Then (still at load time), I create compatible render target with the size I need image to be.
  3. Draw image to the compatible target using scale effect.
  4. Allocate new bitmap as property of object that represents an image (ID2D1Bitmap *imageScaled property).
  5. Copy from compatible target to imageScaled.
  6. Free compatible target. Here image load ends.

When already created image object need to be resized, I repeat steps 2-6. In the result, in render loop I have to only draw imageScaled.

I currently thinking about of removing 2-6 steps and just draw scale effect with imageOriginal passed from each image object in the render loop every time.

I do not know what exactly Direct2d Scale effect does. If it actually every time does something similar to steps 2-6, then, probably I don't need to do it.

In the other hand, in my render loop there is basic skip algorithm for objects that are out of parent view, so they are not drawn at all. In current realization I may need to wait time for pre scale objects that possibly out of view, and they will not be drawn currently. With Scale effect in render loop realization this problem will be solved.

Does anyone know which solution will be the fastest?

1 Answers

After rewriting my code, currently it seems that using Scale in render loop is faster for a single image.

Again, before that, when setImage method of the object that represents UI an image is called, something like that was happening:

void ImageObject::setImage(const wchar_t *path)
{
     if(!wcscmp(this->path, path))
          return;
     SafeRelease(&this->originalImage);
     
     // Load original image via WIC

     this->scaledImage = RescaleImage(this->originalImage, this->width, this->height);
}

And in the main render loop:

void ImageObject::Render() 
// render loop iterates through ImageObject objects array and calls each object's Render method
{
// skip is cached variable simply equals 
// (this->x > this->parent->width || this->y > this->parent->height || etc)
     if(skip) 
         return;

     renderTarget->DrawBitmap(this->originalImage, rectangle);
}

Now it is like this:

void ImageObject::setImage(const wchar_t *path)
{
     if(!wcscmp(this->path, path))
          return;
     SafeRelease(&this->originalImage);
     
     // Obtain originalImage and that's it
}

void ImageObject::Render() 
{
     if(skip) 
         return;

     globalScale->SetInput(0, this->originalImage);
     globalScale->SetValue(D2D1_SCALE_PROP_SCALE, ...);

     renderTarget->DrawImage(globalScale, point);
}

First method actually supposed to be more faster, because in the render I need to just draw plain bitmap.

As I wrote in the post, I though the second method should work faster in case of big amount of images, when part of them are out of screen, but currently, with this method, drawing one image is faster than with image prescaling method.

Related