-define jpeg:q-table not respected

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
elmo
Posts: 5
Joined: 2019-05-12T14:07:04-07:00
Authentication code: 1152

-define jpeg:q-table not respected

Post by elmo » 2019-05-12T14:15:34-07:00

Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
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).

elmo
Posts: 5
Joined: 2019-05-12T14:07:04-07:00
Authentication code: 1152

Re: -define jpeg:q-table not respected

Post by elmo » 2019-05-15T02:10:04-07:00

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.
Last edited by elmo on 2019-05-15T04:02:08-07:00, edited 1 time in total.

elmo
Posts: 5
Joined: 2019-05-12T14:07:04-07:00
Authentication code: 1152

Re: -define jpeg:q-table not respected

Post by elmo » 2019-05-15T04:00:52-07:00

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.

Post Reply