Image rendering Optimization

57 views
Skip to first unread message

L2000

unread,
May 22, 2025, 6:55:46 AM5/22/25
to skia-discuss
Hi Team,

I have a requirement of drawing High Quality image Image of size 6000x4000 pixels.
And I'm trying to draw it in 300x200 pixels. In the entire process , scaling pixels with SkSamplingOptions(kLinear, kLinear) is consuming too much of time.

I’m using pixmap.scalePixels(dstPixmap, SkSamplingOptions(SkFilterMode::kLinear,SkMipmapMode::kLinear); It is taking approximately 510ms for drawing a 6.3MB JPG image.

And SkSamplingOptions(SkFilterMode::kNearest,SkMipmapMode::kNone) is taking approximately 2-3ms for same image. But the image is completely blurred.

High Quality image : (using SkSamplingOptions(SkFilterMode::kLinear,SkMipmapMode::kLinear))
HighQuality_Image.png
Blurred Pixelated Image : (using SkSamplingOptions(SkFilterMode::kNearest,SkMipmapMode::kNone))
Blurred_Image.png
Is there any other way to draw same High Quality image faster?

Thanks,
Priya

K. Moon

unread,
May 22, 2025, 9:43:21 AM5/22/25
to skia-d...@googlegroups.com
I'm guessing the slowest part of the first version of your code is creating the mipmaps for your image, which requires repeatedly scaling it down by 2x.

If you're repeatedly drawing the same image, you should use an SkImage as the source, rather than an SkPixmap. This will allow Skia to cache the mipmaps.

Another thing you could try is skipping mipmaps entirely, although quality will suffer when scaling down; it's probably not worth it in this application. SkNearest will also be a bit faster than SkLinear for mipmapping.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skia-discuss/7419c699-284a-4696-890a-fa5f9a1d9ed8n%40googlegroups.com.

L2000

unread,
May 23, 2025, 8:57:30 AM5/23/25
to skia-discuss
Thanks for the reply. I have tried using SkImage as well, but did not find any improvement in time. Below is what I did,

Created a pixmap using byte array "shared_ptr<uint8_t>"
SkImageInfo imageInfo = SkImageInfo::Make(imgWidth, imgHeight ,colorType, alphaType);
SkPixmap pixmap(imageInfo, byteArray, imgWidth * samplesPerPixel);
sk_sp<SkImage> image = SkImages::RasterFromPixmapCopy(pixmap);
canvas->drawImageRect(image, SkRect::MakeXYWH(x, y, width, height), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest));

1 .If pixmap is the reason, is there any better way to create the SkImage from byte array?
2. Also canvas->drawImageRect() is only consuming 500-550ms of time. Is there any better alternative to draw High Quality image.


K. Moon

unread,
May 23, 2025, 9:55:15 AM5/23/25
to skia-d...@googlegroups.com
Are you measuring the time to do this once, or repeatedly? Using an SkImage only helps if you draw the image more than once. If you're doing all of these steps every time, you're not going to save any time.

Reply all
Reply to author
Forward
0 new messages