mozjpeg icon indicating copy to clipboard operation
mozjpeg copied to clipboard

Severe artifact for quality <= 54

Open akobel opened this issue 6 years ago • 3 comments

Hi,

encoding the following image with -quality 54 or less yields a severe artifact at the "ü" character; with -quality 55 or higher, everything is as expected.

The issue occurs with the current git HEAD, 3.2 (the mozjpeg-opt from Arch Linux' user repository), and 3.3.1 (built with an adapted build script). The build instructions for the Arch packages are pretty straightforward: unpack the release tarball and call autoreconf -fiv, configure --with-jpeg8 and make. My build from git HEAD was a plain mkdir build; cd build; cmake ..; make on an Arch Linux machine; CMake output is attached. The make log was clean. As far as I know, I have only Arch's standard repositories' versions of any relevant libraries, freshly updated.

This is a crop from a larger file, where the same problem occurs at several positions; but all have the same structure, that is, a sharp black vertical line in one block. I didn't investigate with rotations etc.

Input: (PNG instead of PNM for the sake of uploading): in

cjpeg-static -quality 54 -outfile moz54.jpg in.pnm: moz54

cjpeg-static -quality 55 -outfile moz55.jpg in.pnm: moz55

build.log

akobel avatar Mar 08 '19 16:03 akobel

Hi, I run into this bug as well. It seems to be related to overshoot deringing and the SIMD-optimized DCT functions.

mozcjpeg -quality 50 block.pnm >with-artifact.jpg
mozcjpeg -quality 50 -noovershoot block.pnm >without-artifact.jpg
mozcjpeg -quality 50 -dct float block.pnm >without-artifact.jpg
mozcjpeg -quality 50 -dct fast block.pnm >without-artifact.jpg

I instrumented this line to print workspace before/after and found that the different DCT functions return different results for the same input: https://github.com/mozilla/mozjpeg/blob/cfb713852354b139ca25a8c382de4166a67d41a1/jcdctmgr.c#L714

Running it with different DCTs:

% mozcjpeg -quality 50 -dct int block.pnm >/dev/null
Bef: -128 -128 -128 -118 158 158 158 158 -128 -128 -128 -120 158 158 158 158 -128 -128 -128 -122 158 158 158 158 -128 -128 -128 -128 158 158 158 158 -128 -128 -128 -128 120 158 158 158 -128 -128 -128 -127 116 158 158 158 -128 -128 -128 -128 123 158 158 158 -128 -128 -128 -124 158 158 158 158
Aft: 874 8130 113 2799 -86 -1777 47 1450 106 -18 -139 49 106 -74 -58 87 72 -9 -95 27 72 -41 -39 48 -100 26 130 -75 -100 112 54 -133 38 -11 -49 31 38 -46 -21 56 3 -4 -3 10 3 -15 -1 18 18 -1 -23 4 18 -6 -10 7 -30 9 39 -26 -30 38 16 -45
Bef: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Aft: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bef: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Aft: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
% mozcjpeg -quality 50 -dct fast block.pnm >/dev/null
Bef: -128 -128 -128 -118 158 158 158 158 -128 -128 -128 -120 158 158 158 158 -128 -128 -128 -122 158 158 158 158 -128 -128 -128 -128 158 158 158 158 -128 -128 -128 -128 120 158 158 158 -128 -128 -128 -127 116 158 158 158 -128 -128 -128 -128 123 158 158 158 -128 -128 -128 -124 158 158 158 158 
Aft: 874 -11452 142 3311 -86 -1407 30 396 145 -34 -253 80 145 -83 -45 31 94 -19 -162 44 94 -45 -28 18 -116 43 200 -101 -116 104 39 -40 38 -16 -64 37 38 -37 -12 16 2 -5 -4 9 2 -10 -1 4 10 -1 -16 4 10 -3 -2 2 -7 4 13 -8 -7 9 3 -3 
Bef: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
Aft: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
Bef: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
Aft: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

As you see, the results are very different after the 1st element.

Given that, I think the bug is in https://github.com/mozilla/mozjpeg/blob/master/simd/x86_64/jfdctint-avx2.asm, as it returns different results than the fast or float versions. block.pnm.gz

tigermonkey avatar Oct 21 '19 12:10 tigermonkey

I just ran into this problem. Both input and output images are attached below.

For this specific file, the artifacting occurs at quality 57 and below. It only seems to occur for BW text, and it really is severe.

-version output: mozjpeg version 4.0.2 (build 20210218). Built on Linux Mint 20.1 (Ubuntu 20.04 base) using the build instructions in the BUILD file.

veikk0 avatar Mar 16 '21 17:03 veikk0

Just ran into this problem as well. I built mozjpeg from current git.

Input:

zeichnung

Compressing with mozjpeg: cjpeg-mozjpeg -q 50 ./zeichnung.png > zeichnung.jpg

Output:

zeichnung

maikmerten avatar Aug 08 '23 13:08 maikmerten