webmproject / sjpeg

SimpleJPEG: simple jpeg encoder
Apache License 2.0
70 stars 12 forks source link

Add an API to target a given file-size or PSNR #22

Open skal65535 opened 6 years ago

skal65535 commented 6 years ago

(opening this 'issue' as a vague reminder for an interesting TODO)

Similar to WebP API[1], it would useful to have an inner loop that dichotomizes toward a given, user-specified, target for PSNR or file-size.

Compared to an external script that would dichotomize on -quality, there's some savings to be had by not re-doing histogram collection or sample import for instance. Also the gradient descent could alternate trellis & adaptive-quantization (right now, the trellis pass is somewhat sub-optimal because there's no update pass on the Huffman codes).

Agreed, PSNR is not the ultimate metric to aim for, but targeting PSNR>40dB is usually a good threshold for lot of practical purpose.

[1] https://developers.google.com/speed/webp/docs/api#advanced_encoding_api

skal65535 commented 6 years ago

The branch 'dicho' should be a good first step in that direction. It adds some options to target size or psnr, e.g.: ./examples/sjpeg input.png -size xxxxx -o out.jpg ./examples/sjpeg input.png -psnr 38 -o out.jpg

Still needs to be tested for corner cases.