mozjpeg
mozjpeg copied to clipboard
output from `-quality 75` doesn't match default, no flag output.
usage.txt suggests the default quality is 75 https://github.com/mozilla/mozjpeg/blob/master/usage.txt#L73
but running cjpeg -quality 75 foo.jpg > foo.q75.jpg
produces different output to cjpeg foo.jpg > foo.default.jpg
What else does setting the quality flag change in the output?
Also... when I specify the quality flag, then gm identify verbose
it doesn't match what I passed to cjpeg...
$ cjpeg -quality 75 master.732.jpg > master.732.q75.jpg
$ gm identify -verbose master.732.q75.jpg | grep Quality
JPEG-Quality: 40
But running it without a quality flag does indeed produce images that gm
thinks are at quality 75
$ gm identify -verbose master.732.default.jpg | grep Quality
JPEG-Quality: 75
so I'm a bit confused. Can anyone explain how the quality flag works?
JPEG doesn't store quality as a single number. GraphicsMagic/ImageMagick's identify function does a trick that is based on assumption that the stock libjpeg was used, and it's not compatible with other quantization tables.
That quality output is not related to actual, human-perceived quality.
I suggest opening bug against gm/ImageMagick and ask them to tune the identify function to support other quantization tables.
Thanks! I guess my real question is does specifying the -quality
flag change anything else? If 75 is the default then my assumption was that specifying -quality 75
is the same as not specifying it.
I'm just learning, and trying to get my head around this:
cjpeg pug.jpg -quality 75 pug.mozjpeg.q75.jpg
cjpeg pug.jpg > pug.mozjpeg.default.jpg
diff pug.mozjpeg.default.jpg pug.mozjpeg.q75.jpg
Binary files pug.mozjpeg.default.jpg and pug.mozjpeg.q75.jpg differ
I've stripped the exif data, but they still differ. Does mozjpeg
use the -quality
to change some other settings, or am i just misunderstanding how it works?
Oh, it may be a bug.
In cjpeg when you use -quality
, then set_quality_ratings()
is called and it calls a LOCAL jpeg_default_qtables()
, which sets quantization tables based on the new JINT_BASE_QUANT_TBL_IDX
option.
Otherwise jpeg_set_defaults()
is used, which calls jpeg_set_quality(cinfo, 75, TRUE);
and jpeg_set_linear_quality
, which relies on cinfo->master->quant_tbl_master_idx
being set previously.
@pornel many thanks for the explanation!
Is there a flag to encourage mozjpeg to use the new quantization tables even when the -quality
flag is used?
When you use -quality
you get the new quantization tables. It's only the default quality that also unintentionally defaults to the old tables.
:+1: got it.
@pornel This issue seems resolved but earlier you wrote "Oh, it may be a bug." Is there a bug here? If so, can you write out an explanation of what it is?
If I remember correctly, the code that sets the default quality and code that sets quality explicitly have quite different implementations and they find qtable to use differently.
Should they use the same implementation? Specifically, should we just change things so that default quality is set exactly the same as if the user had passed "-quality 75"?
Yes, I think qtables should be selected the same way whether you set quality or not, and it'd be nice if there was a DRY implementation for it.
@pornel Want to do this for v3.2?
I can do it, but I can't promise I'll have time to do it for v3.2
You need to use cjpeg -quant-table 0 -quality 75 to match it. See https://github.com/mozilla/mozjpeg/issues/395.