]> granicus.if.org Git - libjpeg-turbo/commitdiff
Use bias pattern for 4:4:0 (h1v2) fancy upsampling
authorJonathan Wright <jonathan.wright@arm.com>
Thu, 9 May 2019 12:46:53 +0000 (13:46 +0100)
committerDRC <information@libjpeg-turbo.org>
Tue, 2 Jul 2019 14:55:24 +0000 (09:55 -0500)
This commit modifies h1v2_fancy_upsample() so that it uses an ordered
dither pattern, similar to that of h2v1_fancy_upsample(), rounding up or
down the result for alternate pixels rather than always rounding down.
This ensures that the decompression error pattern for a 4:4:0 JPEG image
will be similar to the rotated decompression error pattern for a 4:2:2
JPEG image.  Thus, the final result will be similar regardless of
whether a 4:2:2 JPEG image is rotated or transposed before or after
decompression.

Closes #356

ChangeLog.md
jdsample.c

index d9f36090350183b312dfa6dc72d91cef46dead11..0b015c1fa14f72e648c683400ea3aeeda58fd529 100644 (file)
@@ -13,6 +13,14 @@ instruction exception, in rare cases, on CPUs that lack support for CPUID leaf
 07H (or on which the maximum CPUID leaf has been limited by way of a BIOS
 setting.)
 
+3. The 4:4:0 (h1v2) fancy (smooth) chroma upsampling algorithm in the
+decompressor now uses a similar bias pattern to that of the 4:2:2 (h2v1) fancy
+chroma upsampling algorithm, rounding up or down the upsampled result for
+alternate pixels rather than always rounding down.  This ensures that the final
+result will be similar regardless of whether a 4:2:2 JPEG image is rotated or
+transposed prior to decompression (in the frequency domain) or after
+decompression (in the spatial domain.)
+
 
 2.0.2
 =====
index 52ee9af49b36791e01e076f24fe5147f4eb12f3f..50a68b30131890bec2f56e350b4eda25aa66fd5b 100644 (file)
@@ -8,6 +8,7 @@
  * Copyright (C) 2010, 2015-2016, D. R. Commander.
  * Copyright (C) 2014, MIPS Technologies, Inc., California.
  * Copyright (C) 2015, Google, Inc.
+ * Copyright (C) 2019, Arm Limited.
  * For conditions of distribution and use, see the accompanying README.ijg
  * file.
  *
@@ -315,9 +316,9 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
   JSAMPARRAY output_data = *output_data_ptr;
   JSAMPROW inptr0, inptr1, outptr;
 #if BITS_IN_JSAMPLE == 8
-  int thiscolsum;
+  int thiscolsum, bias;
 #else
-  JLONG thiscolsum;
+  JLONG thiscolsum, bias;
 #endif
   JDIMENSION colctr;
   int inrow, outrow, v;
@@ -327,15 +328,18 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
     for (v = 0; v < 2; v++) {
       /* inptr0 points to nearest input row, inptr1 points to next nearest */
       inptr0 = input_data[inrow];
-      if (v == 0)               /* next nearest is row above */
+      if (v == 0) {             /* next nearest is row above */
         inptr1 = input_data[inrow - 1];
-      else                      /* next nearest is row below */
+        bias = 1;
+      } else {                  /* next nearest is row below */
         inptr1 = input_data[inrow + 1];
+        bias = 2;
+      }
       outptr = output_data[outrow++];
 
       for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
         thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
-        *outptr++ = (JSAMPLE)((thiscolsum + 1) >> 2);
+        *outptr++ = (JSAMPLE)((thiscolsum + bias) >> 2);
       }
     }
     inrow++;