libjpeg output scaling

半城伤御伤魂 提交于 2019-12-01 22:05:23

Yes, libjpeg does support image scaling, but with some limitations.

Libjpeg version 8c and higher supports M/8 scaling where M is an integer between 1 and 16. The more commonly used libjpeg version 6b supports M of 1, 2, 4, and 8 only (i.e. power-of-2 downscaling).

Supply the scaling numerator and denominator to the decompression object using scale_num and scale_denom. See jpeg_decompress_struct in jpeglib.h. You can refer to djpeg.c for a usage example.

This is much faster, and potentially higher quality, than decoding the whole image and then downscaling.

Ravachol

No, you need to scale it either by yourself (linear interpolation is the easiest and fastest but gives square shaped pixels, bilinear/trilinear/bicubic are trickiers but give smoother results), or by using a library that will do the dirty work for you (check OpenCV, SDL, imagemagick, libpipi, etc.)

More on this here, here.

Actual code for a simple nearest neighbor interpolation (unoptimized) :

dest[dx+dy*dest_width] = src[(dx*src_width/dest_width)+(dy*src_height/dest_height)*src_width]

Just iterate dx and dy according to the dest_width and dest_height. But really, use a library for this.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!