ilyakurdyukov / jpeg-quantsmooth

JPEG artifacts removal based on quantization coefficients.
GNU Lesser General Public License v2.1
245 stars 21 forks source link

JPEGQS_UPSAMPLE_UV has become broken #28

Closed pjanx closed 9 months ago

pjanx commented 9 months ago

Reproducable on Arch Linux, observed roughly since libjpeg-turbo 2.1.90 (pre-3.0):

make SIMD=select clean example LDFLAGS="-lm $(pkg-config --libs libjpeg)"
./example test.jpg test.bmp

Sample input (YCbCr 4:2:0) and output (converted to PNG): test test

It is the JPEGQS_UPSAMPLE_UV flag that decides whether output becomes garbage. YCbCr 4:4:4 is fine.

pjanx commented 9 months ago
diff --git a/quantsmooth.h b/quantsmooth.h
index 8411b6a..541bd0c 100644
--- a/quantsmooth.h
+++ b/quantsmooth.h
@@ -46,10 +46,16 @@ struct jpeg_decomp_master {
        void (*finish_output_pass) (j_decompress_ptr);
        boolean is_dummy_pass;
 #ifdef LIBJPEG_TURBO_VERSION
+#if LIBJPEG_TURBO_VERSION_NUMBER >= 2001090
+       boolean lossless;
+#endif
        JDIMENSION first_iMCU_col, last_iMCU_col;
        JDIMENSION first_MCU_col[MAX_COMPONENTS];
        JDIMENSION last_MCU_col[MAX_COMPONENTS];
        boolean jinit_upsampler_no_alloc;
+#if LIBJPEG_TURBO_VERSION_NUMBER >= 2000090
+       JDIMENSION last_good_iMCU_row;
+#endif
 #endif
 };
 #endif

The trailing field is there since 42825b68d570fb07fe820ac62ad91017e61e9a25, the boolean is part of the lossless libjpeg megamerge.

ilyakurdyukov commented 9 months ago

JPEGQS_UPSAMPLE_UV decides to change 4:2:0 to 4:4:4, apparently the libjpeg-turbo API has changed.

ilyakurdyukov commented 9 months ago

The trailing field is there since 42825b68d570fb07fe820ac62ad91017e61e9a25 (2.0.4).

How is this hash related to the version?

I checked the source archives, the last_good_iMCU_row field appeared in libjpeg-turbo-2.0.90, but it is not yet in libjpeg-turbo-2.0.6.

pjanx commented 9 months ago

It seems I got lost in the merge octopus, the 2.0.4 tag just appeared before the hash in linear git log. You're right in that it doesn't appear in the 2.0 series at all.

ilyakurdyukov commented 9 months ago

I committed the fix.

pjanx commented 9 months ago

You have a minor typo there, 2000090 (2.0.90) instead of 2001090 (2.1.90).

ilyakurdyukov commented 9 months ago

There is no typo, the last field appeared in version 2.0.90, you can check it in this source archive.