High quality scaling

783 views
Skip to first unread message

Livestock Dev

unread,
Feb 4, 2020, 8:30:51 AM2/4/20
to skia-discuss
Hi Everybody,

I'm doing some work on images using Skia, and so far I'm quite of fond of how easy it is to use Skia.
That said, I have two issues that I would very much appreciate if anyone could help with:

1. Scaling down produces blurry images. This is the code that I'm using to resize the image:
(Skia/sk_paint_set_filter_quality paint Skia/HIGH_SK_FILTER_QUALITY)
(Skia/sk_paint_set_antialias paint false)
(Skia/sk_paint_set_dither paint false)
(Skia/sk_canvas_draw_image_rect canvas picture-img nil picture-rect paint)

How to scale down such that the quality is on par with Chrome? 

2. At least one of the images gets different colors when it's loaded with Skia and then exported back to jpg. When opening the same image in GIMP, it shows that the image has an embedded color profile and offers to keep it or to convert it to GIMP's color profile. I guess that this embedded color profile is what creates the color issue in the file created by Skia. How should I approach this?

Thanks in advance!

Best regards,
Michael

Peter Verswyvelen

unread,
Feb 5, 2020, 3:28:54 AM2/5/20
to skia-discuss
I also would like to know :-)

Anyway, by looking at the source code, it seems Skia doesn't yet provide a "highest" quality downsampler/upsampler yet.

Actually, the newest version has a work-in-progress API to do cascaded downscaling: https://cs.chromium.org/chromium/src/third_party/skia/src/image/SkSurface.cpp?q=asyncRescaleAndReadPixels

But that doesn't seem to use high quality filters like Lanczos3.

The "best" quality standalone image resampler I could find is https://github.com/avaneev/avir, but because of the heavy processing, it runs rather slowly. I was able to make it run 3x faster in the common case of 8-bit sRGB->linear->sRGB scaling by using a lookup table, and I think it is possible to make it run even faster by using streaming writes and SIMD double pumping, not sure. It would be nice if Skia had a similar option for doing very high quality image resampling, especially for image processing in the cloud. E.g. Microsoft's WIC has a "fant" downscaler that offers reasonable quality, especially when scaling in linear color space.

Livestock Dev

unread,
Feb 5, 2020, 7:20:02 AM2/5/20
to skia-discuss
Hi Peter,

With my current use case speed of processing is less important. 
So I wonder which opensource lib today gives the highest quality scaling? AVIR?

Peter Verswyvelen

unread,
Feb 5, 2020, 7:49:32 AM2/5/20
to skia-discuss
Hi Michael,

I wasn't able to find a better image resampler than AVIR, however, as the author states, AVIR is an orthogonal resampler (so first it scales horizontally, then vertically, O[N] complexity?), not an EWA (Elliptical Weighted Average) resampler (it scaled in both dimensions at the same time, O[N^2] complexity?), so it can suffer from aliasing diagonally as far as I understand.

ImageMagick has EWA support, but that is a lot slower, but could provide even higher quality.

I'm not an expert myself, from my research it seems very few people can call themselves "experts" in this complicated field, and it's all about trade-offs.

See also:

Peter

PS: This might get off-topic, not related to Skia anymore?
Reply all
Reply to author
Forward
0 new messages