tiny-skia icon indicating copy to clipboard operation
tiny-skia copied to clipboard

Add basic mimpmap downscaling support

Open jermy opened this issue 1 year ago • 2 comments

This is small patch to fix quality issues when scaling images down. It'll create a number of mipmap/half-scaled versions of a given source as required and use the next largest version as the source for bilinear or bicubic scaling.

This uses the same downsampling functions as Skia, but similarly doesn't run SIMD versions of these. As they are integer-based, these should be reasonably quick.

This addresses issue #13, but probably wants some work and tests before merging.

jermy avatar Dec 24 '24 12:12 jermy

Thanks a lot 🎉

RazrFalcon avatar Dec 24 '24 13:12 RazrFalcon

@waywardmonkeys any idea of what sort of tests would be useful in this case? I'm imagining just integration tests, but if there are sensible unit tests I could add those? (I think compute_required_levels is the only non-complicated function).

Integration tests would involve some source and expected PNGs so might be a little tricky to keep the size down, but I'm guessing would include:

  • That a resized image looks like the same as it currently does if FilterQuality::Nearest is used
  • That a "better" image is produced if FilterQuality::Bicubic or FilterQuality::Bilinear are used
  • That a 1x1 image scaled down doesn't cause a crash
  • That all of the downsample functions are used - I think a source image of 21x19 scaled down to less than 1x1 (ie. 2% size) would be the smallest source image to invoke all of these in one pass

jermy avatar Jan 06 '25 12:01 jermy