Page 1 of 2

possible bug default jpg quality or doc error

Posted: 2010-07-30T09:45:52-07:00
by fmw42
IM 6.6.3.1 Q16 Mac OSX Tiger

There is a conflict between the actual default quality achieved (92) in converting to a jpg and the default value of 85 stated at http://www.imagemagick.org/script/comma ... hp#quality as

"For the JPEG and MPEG image formats, quality is 0 (lowest image quality and highest compression) to 100 (best quality but least effective compression). The default is to use the estimate quality of your input image otherwise 85. "

Any non-jpg image I convert to JPG seems to have a quality of 92 listed in the verbose information

For example:

convert logo: logo.jpg

identify -verbose logo.jpg
...
Quality: 92

Is this a bug in converting to JPG, a bug in verbose info, or simply a needed documentation change? Do I misunderstand something?


This issue was originally raised at viewtopic.php?f=1&t=16688

Re: possible bug default jpg quality or doc error

Posted: 2010-07-30T14:49:08-07:00
by Drarakel
fmw42 wrote:Is this [...] a bug in verbose info
The verbose info is alright.

Re: possible bug default jpg quality or doc error

Posted: 2010-07-31T16:28:29-07:00
by magick
We patched the documentation to reflect a default JPEG quality of 92. Thanks.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-01T01:54:55-07:00
by Drarakel
Can the other things in the quality paragraph be updated, too?

- for JPEG and MPEG, quality is 1 to 100 (or is this a bug? - for PNG, quality 0 doesn't work as expected either)
- the default quality setting for PNG is 75
- with JPEG-2000, the default quality is 100
(After a short test, it seems that a 16:1 compression can be achieved with quality 75 approx. And in the paragraph about the jp2:rate setting, it's specified that quality 75 would result in a rate value of 0.06641, which would be 15:1 - not sure if that's right.)

In the "Common Image Formats" section, there's also a reference to the old JPG quality 85 (search for "is about 85%"):
http://www.imagemagick.org/Usage/formats/#jpg

Thanks!

Again from the "quality" documentation - is this really working?
When writing a JNG image with transparency, two quality values are required, one for the main image and one for the grayscale image that conveys the alpha channel. These are written as a single integer equal to the main image quality plus 1000 times the opacity quality. For example, if you want to use quality 85 for the main image and quality 90 to compress the opacity data, use -quality 90085.
When I try to specify a quality like that, I always end up with zlib compression level 9 and JPG quality 100 (from the debug output).

Re: possible bug default jpg quality or doc error

Posted: 2010-08-01T10:27:34-07:00
by el_supremo
I always end up with zlib compression level 9 and JPG quality 100 (from the debug output)
The debugging seems to be hard coded to do that except that I don't get compression level 9, I always get level 8.
In png.c starting at line 8468 I've marked the ones which are hardcoded:

Code: Select all

if (logging != MagickFalse)
	{
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
		  "    JNG width:%15lu",(unsigned long) image->columns);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
		  "    JNG height:%14lu",(unsigned long) image->rows);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
		  "    JNG color type:%10d",jng_color_type);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
>>		  "    JNG sample depth:%8d",8);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
>>		  "    JNG compression:%9d",8);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
>>		  "    JNG interlace:%11d",0);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
		  "    JNG alpha depth:%9d",jng_alpha_sample_depth);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
		  "    JNG alpha compression:%3d",jng_alpha_compression_method);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
>>		  "    JNG alpha filter:%8d",0);
		(void) LogMagickEvent(CoderEvent,GetMagickModule(),
>>		  "    JNG alpha interlace:%5d",0);
	}
I think the jpg quality is also hardcoded but for a different reason. If lossless JPG is supported then it always prints a quality of 100.
In jpeg.c at line 1927:

Code: Select all

#if !defined(C_LOSSLESS_SUPPORTED)
      jpeg_set_quality(&jpeg_info,100,MagickTrue);
      if (image->debug != MagickFalse)
        (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Quality: 100");
There's one other place which would print anything other than the real quality but it would print "Quality: 100 (lossless)".

Pete

Re: possible bug default jpg quality or doc error

Posted: 2010-08-01T20:15:51-07:00
by anthony
Drarakel wrote:- the default quality setting for PNG is 75
Default quality for PNG should probably be 95. Remember PNG quality is NOT a value from 0 to 100 but a 0-9 compression and a 0-9 encoding type. 9 compression is the highest compression without loss of data.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-01T20:39:42-07:00
by fmw42
Anthony wrote:Default quality for PNG should probably be 95. Remember PNG quality is NOT a value from 0 to 100 but a 0-9 compression and a 0-9 encoding type. 9 compression is the highest compression without loss of data.
Interesting, when I do


convert logo: logo.png
identify -verbose logo.png

There is no quality listed, only the compression!
...
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Compose: Over
Page geometry: 640x480+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2010-08-01T20:34:05-07:00
date:modify: 2010-08-01T20:34:05-07:00
signature: e7339242ec91155fb698eadf06f8e72d8e09f03453d700ed311e446174b75469
Artifacts:
verbose: true
Tainted: False
Filesize: 95KB
Number pixels: 307K
Pixels per second: 6.144M
User time: 0.030u
Elapsed time: 0:01.050
Version: ImageMagick 6.6.3-2 2010-08-01 Q16 http://www.imagemagick.org

So how does one determine the quality value?

Re: possible bug default jpg quality or doc error

Posted: 2010-08-01T21:14:55-07:00
by anthony
Like JPEG you probably can not read the quality setting used for the ZIP compressor when the PNG was saved.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-02T12:29:49-07:00
by Drarakel
fmw42 wrote:So how does one determine the quality value?
The compression level (the first number in IM) is not a number that you can find out about by looking at the output file, I guess. (But you can list the used setting when creating the file with "-debug coder".)
The filter type (the second number) however can be retrieved from the output. pngout for example will display it.
anthony wrote:Default quality for PNG should probably be 95.
All I'm saying is that the default that ImageMagick currently uses for PNG is 75. And it would be good if these things could be reflected in the documentation.
el_supremo wrote:The debugging seems to be hard coded to do that except that I don't get compression level 9, I always get level 8.
We're talking about different things here. You're referring to these settings that start with "JNG...". Maybe "JNG compression" (8) defines the general compression type (Deflate). I don't know..
But I was talking about the PNG compression level. AFAIK, in JNG the normal image is compressed as JPG and the alpha layer is compressed as PNG (so, lossless). And this compression level from the PNG part is set to 9 when one tries to specify this long 'two quality values' number:
2010-08-02T20:48:47+02:00 0:00.125 0.078u 6.6.3 Coder Magick[1564]: png.c/WriteOnePNGImage/7420/Coder
Compression level: 9

I now think that these long numbers don't work for JNG (at least currently not in the format from the documentation). Everything that's greater than 100 just results in the maximum quality for each part. (One gets the same maximum quality when one specifies a too high quality number with .JPG as output file, for example.) The JPG part gets set to quality 100 (sampling-factor 1x1), and the PNG part gets stored with compression level 9. (It seems that the filter type is 1 then. But I'm not sure about the filter types in JNG, as I don't know if there's a way to extract just the PNG data out of the JNG.. And the debug messages don't show the filter type unless it's filter type 5. And filter type 5 doesn't seem to work in JNG - seems that filter type 0 is used instead of 5..? :?)

The quality can be specified for JNG - but on my system, it only works with one (normal) quality number. Of course, the PNG part then uses the same 'quality' number as the JPG part.
And when no quality is specified, the default values from the two parts are used. The debug messages show '0' as JPG quality, but the real value is 92 then, and the PNG part uses the PNG default of 75 (but in JNG, 75 seems to be the same as 70).

Re: possible bug default jpg quality or doc error

Posted: 2010-08-09T03:38:24-07:00
by Drarakel
I noticed that the documentation has been updated. Thanks!


Most of the things are correct now - but not all:

First - there's still this reference to the old JPG default quality here:
http://www.imagemagick.org/Usage/formats/#jpg
The default quality setting, when no JPEG quality is set, either by the user, or from the source image format file, is about 85%, which is very reasonable.
And a few remaining details in the "-quality" documentation:
http://www.imagemagick.org/script/comma ... hp#quality
For the MNG and PNG image formats, the quality value sets the zlib compression level (quality / 10) and filter-type (quality % 10). Compression levels range from 0 (fastest compression) to 100 (best but slowest).
The second sentence could be deleted or rephrased. There is no '0' or '100' PNG quality value in ImageMagick. '100' will result in PNG quality 90, and '0' will result in 75.
Theoretically, a value of '0' or '00' (huffman-only with filter none) should work - but it only results in the default PNG quality (75). It seems that '05' will do a compression with huffman-only and filter none (and for Huffman with adaptive filtering, one has to use e.g. '06' in IM).
The default is quality is 92, which means nearly the best compression with adaptive filtering. The quality setting has no effect on the appearance of PNG and MNG images, since the compression is always lossless.
The first sentence can be deleted.

And I still think that this paragraph should be overhauled - or deleted (as it doesn't work at the moment):
When writing a JNG image with transparency, two quality values are required, one for the main image and one for the grayscale image that conveys the alpha channel. These are written as a single integer equal to the main image quality plus 1000 times the opacity quality. For example, if you want to use quality 85 for the main image and quality 90 to compress the opacity data, use -quality 90085.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-09T09:09:21-07:00
by fmw42
Many of these things are in Anthony's docs, so you need to get his attention.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-09T16:10:05-07:00
by Drarakel
Well, you created this thread, didn't you? :) And it's still about this "-quality" paragraph (with one exception).

This wrong sentence, for example, is a result of the first update in this thread:
http://www.imagemagick.org/script/comma ... hp#quality
The default is quality is 92, which means nearly the best compression with adaptive filtering.
If the above two or three remaining things can be corrected, this part of the documentation will be quite perfect.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-09T16:44:22-07:00
by fmw42
I have sent Anthony email to look at your comments again and see about updating his docs. I really don't understand all the issue beyond the default jpg quality that is now 92.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-09T17:17:01-07:00
by anthony
Drarakel wrote:Most of the things are correct now - but not all:

First - there's still this reference to the old JPG default quality here:
http://www.imagemagick.org/Usage/formats/#jpg
The default quality setting, when no JPEG quality is set, either by the user, or from the source image format file, is about 85%, which is very reasonable.
Fixed. update on offical page shortly.

Re: possible bug default jpg quality or doc error

Posted: 2010-08-09T17:30:15-07:00
by anthony
If you would like to send me a re-write of the command line options page -quality,
http://www.imagemagick.org/script/comma ... hp#quality
I will see it added to the documentation (with appropriate formatting).


It probably should start with something like...
The -quantity setting is a number defining the internal compression level and style used when writing a image file format. The exact meaning of the setting is dependant on the exact format that is being written.
After that it should split to setting meaning for writing individual image file formats.