tonycoz / imager

Imager - image manipulation from perl.
http://imager.perl.org/
27 stars 3 forks source link

How to use the libjpeg-turbo advanced option with Imager ? #465

Open zeroheure opened 3 years ago

zeroheure commented 3 years ago

Is there a way to use the libjpeg-turbo advanced option with Imager ? libjpeg-turbo add some useful options to libjpeg. Some of them are really useful for current web images, like separate compression levels for luminance and chrominance or pre-defined quantization tables. I would like to pass these options in $img->write. Is it possible ?

tonycoz commented 3 years ago

There isn't yet, but it's something that could be added.

zeroheure commented 3 years ago

And is it curently possible, to force some of these options, like: jpeg_compression->'75,15' which would correspond to cjpeg -quality 75,15 option with libjpeg-turbo, or else passing a long string containing all options which wouldn't be parsed by Imager: -progressive -smooth 0 -dc-scan-opt 2 -optimize -sample 1x1 -tune-hvs-psnr

zeroheure commented 3 years ago

I am only a sysadmin, not a real programmer. But I can understand C code. Could you tell me in which file(s) things should be changed ?

tonycoz commented 3 years ago

JPEG/imjpeg.c mostly.

It would also need tests in JPEG/t.

tonycoz commented 2 years ago

Imager 1.015 now supports much more JPEG output configuration, including support for mozjpeg's compression profile, though Imager defaults to "fast" compression for backward compatibility.

I think the only option missing from your list is multiple qualities (some of those options are mozjpeg options rather than libjpeg-turbo.)

zeroheure commented 2 years ago

Wow thanks a lot! Actualy, multiple qualities is a libjpeg-turbo option. Look in libjpeg-turbo/main/usage.txt :

The -quality option has been extended in this version of cjpeg to support separate quality settings for luminance and chrominance (...) The -quality option accepts a comma-separated list of parameters, which respectively refer to the quality levels that should be assigned to the quantization table slots. (...) CAUTION: For this setting to be useful, be sure to pass an argument of -sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the default subsampling level (2x2, AKA "4:2:0") will be used.

zeroheure commented 2 years ago

I've asked DRC from libjpeg-turbo about luminance and chrominance params. As you can see in his answer, cjpeg doesn't use jpeg_set_quality but rather jpeg_add_quant_table.