Search code examples
imagescalingdecodinglibpnglibjpeg-turbo

DownScaling Images when decoding with libPng


libjpeg-turbo, supports the ability to downscale an image whilst decoding as long as appropriate values are provided for scale numerator and denominator. So, if used within an app, an appropriate request can be made to deal with the fact that we may be displaying an image on a low resolution screen. This will result in faster decoding.

With this in mind, I wanted to see if the same was true for libPng but, I can't see any parameters that would allow me to request downscaling. I have done some searching on the internet but couldn't find anything, not even in the libpng docs.

Am I missing something or does libpng not support downscaling when decoding?


Solution

  • Libpng does not support downscaling while decoding. It is possible to achieve a power-of-two downscaling by ignoring the later passes of an interlaced PNG, however (read only the first pass for 1/8 scale, the first 3 passes for 1/4 scale, and the first 5 passes for 1/2 scale), but this is in effect downsampling rather than downscaling so it would be of low quality. There is a demonstration of that distributed with libpng (contrib/gregbook/rpng2-x.c), using an option to pause after each pass.