bugfix: add bias pattern for h1v2_fancy_upsample
Adds an ordered dither pattern for h1v2_fancy_upsample such that 0.5
will be rounded up or down at alternate pixel locations. Currently
0.5 is always rounded down.
This ordered dither pattern is already used for h2v1_fancy_upsample
and h2v2_fancy_upsample.
Bug: 922430
Change-Id: Ib55ff5f6660b72d40a29b97ffa1ea1fb01ca9989
diff --git a/jdsample.c b/jdsample.c
index 52ee9af..3e98522 100644
--- a/jdsample.c
+++ b/jdsample.c
@@ -315,9 +315,9 @@
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 +327,18 @@
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++;