libjpeg output scaling

后端 未结 2 935
灰色年华
灰色年华 2021-01-21 04:39

Does libjpeg allows/have routines to scale the output image?

I have an image which needs to be resized when saving to and loading from, Providing width1, height1 on inp

2条回答
  •  花落未央
    2021-01-21 05:29

    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.

提交回复
热议问题