Page 1 of 1

-define jpeg:q-table not respected

Posted: 2019-05-12T14:15:34-07:00
by elmo
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114
Copyright: © 1999-2017 ImageMagick Studio LLC
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib

Running on WSL (Bash on Windows)
I'm using convert like this:

convert pic1.jpg -filter Box -resize 120x160 -define jpeg:q-table=/path/to/xml out.jpg

but the custom quantization table is not being used (and it seems like a different table is used *not* the default one).

Re: -define jpeg:q-table not respected

Posted: 2019-05-15T02:10:04-07:00
by elmo
I've tracked down the problem:

-define jpeg-qtable uses the standard jpeg library's jpeg_add_quant_table() function which scales the provided quantization table by the jpeg quality using the function: q value = round(provided_table_value * scale / 100).

There is no provision to define a verbatim quantization table.

Re: -define jpeg:q-table not respected

Posted: 2019-05-15T04:00:52-07:00
by elmo
The solution is to use the ImageMagick flag -quality 50. The jpeg library converts this to a value of 100 via the function jpeg_quality_scaling(). This value of 100 will be passed to jpeg_add_quant_table(), negating the effect of the scaling (see the scaling function I posted earlier). I have not yet tested this, but it should work in theory.

IMHO this should be mentioned in the documentation. The expectation when providing a quantization table is that it will be used verbatim.