Custom Quantization Tables using defineValue

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
cujsmith
Posts: 8
Joined: 2016-10-13T16:18:14-07:00
Authentication code: 1151

Custom Quantization Tables using defineValue

Post by cujsmith »

Hello, I think I found a bug. It could be attributed to user error, but I think I've ruled out that possibility.
The problem is in supplying a "quantization-table.xml" I wish to encode with the following QTs in a C++ program:

Code: Select all

Luminance Quantization Table
16, 12, 14, 17, 22, 30, 45, 72,
12, 13, 14, 17, 22, 31, 46, 74,
14, 14, 16, 19, 25, 35, 52, 83,
17, 17, 19, 23, 30, 41, 62, 100,
22, 22, 25, 30, 39, 54, 80, 129,
30, 31, 35, 41, 54, 74, 111, 178,
45, 46, 52, 62, 80, 111, 166, 267,
72, 74, 83, 100, 129, 178, 267, 428

Chrominance Quantization Table
17, 18, 22, 31, 50, 92, 193, 465,
18, 19, 24, 33, 54, 98, 207, 498,
22, 24, 29, 41, 66, 120, 253, 609,
31, 33, 41, 57, 92, 169, 355, 854,
50, 54, 66, 92, 148, 271, 570, 1370,
92, 98, 120, 169, 271, 498, 1046, 2516,
193, 207, 253, 355, 570, 1046, 2198, 5289,
465, 498, 609, 854, 1370, 2516, 5289, 12725
This is the c++ code I'm using:

Code: Select all

image.read( "in.jpg" );
image.defineValue("jpeg", "q-table", "quantization-table.xml");
image.write( "out.jpg" );
However, in my "out.jpg" I'm ending up with these QTs:

Code: Select all

Luminance Quantization Table
2, 2, 2, 2, 3, 4, 6, 10 
2, 2, 2, 2, 3, 4, 6, 10 
2, 2, 2, 3, 4, 5, 7, 12 
2, 2, 3, 3, 4, 6, 9, 14 
3, 3, 4, 4, 5, 8, 11, 18 
4, 4, 5, 6, 8, 10, 16, 25 
6, 6, 7, 9, 11, 16, 23, 37 
10, 10, 12, 14, 18, 25, 37, 60 

Chrominance Quantization Table
2, 3, 3, 4, 7, 13, 27, 65 
3, 3, 3, 5, 8, 14, 29, 70 
3, 3, 4, 6, 9, 17, 35, 85 
4, 5, 6, 8, 13, 24, 50 120 
7, 8, 9, 13, 21, 38, 80 192 
13, 14, 17, 24, 38, 70 146 352 
27, 29, 35, 50, 80 146 308 740 
65, 70, 85 120 192 352 740 1782 
Thanks for the help in advance!
elmo
Posts: 5
Joined: 2019-05-12T14:07:04-07:00
Authentication code: 1152

Re: Custom Quantization Tables using defineValue

Post by elmo »

You need to set the jpeg output quality to 50 otherwise the library scales the quantization tables. I've posted about this in a different thread.
Post Reply