summaryrefslogtreecommitdiff
path: root/jpeg
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-11-02 16:19:02 +0000
committerRobin Watts <robin.watts@artifex.com>2016-11-02 16:29:39 +0000
commitdc62c90930512f4b571f68c9110022b234cbd411 (patch)
tree8defc914a5023aee263e72c0c194c88fdd5b2e01 /jpeg
parent8dcec8cc076a0cf8350ca7a6ec1d3136812e2a24 (diff)
downloadghostpdl-dc62c90930512f4b571f68c9110022b234cbd411.tar.gz
Bug 697186: Tweak to previous JPEG fix.
Only clamp the DC coefficient. This shouldn't make a difference in any real world cases, but is more correct.
Diffstat (limited to 'jpeg')
-rw-r--r--jpeg/jidctint.c90
1 files changed, 60 insertions, 30 deletions
diff --git a/jpeg/jidctint.c b/jpeg/jidctint.c
index 3ab5ee9eb..53f2d5da8 100644
--- a/jpeg/jidctint.c
+++ b/jpeg/jidctint.c
@@ -219,7 +219,8 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
inptr[DCTSIZE*7] == 0) {
/* AC terms all zero */
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(dcval);
+ if (ctr == DCTSIZE)
+ CLAMP_DC(dcval);
dcval <<= PASS1_BITS;
wsptr[DCTSIZE*0] = dcval;
@@ -249,7 +250,8 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z2);
+ if (ctr == DCTSIZE)
+ CLAMP_DC(z2);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
z2 <<= CONST_BITS;
z3 <<= CONST_BITS;
@@ -467,7 +469,8 @@ jpeg_idct_7x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp13 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp13);
+ if (ctr == 0)
+ CLAMP_DC(tmp13);
tmp13 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp13 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -617,7 +620,8 @@ jpeg_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -739,7 +743,8 @@ jpeg_idct_5x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp12);
+ if (ctr == 0)
+ CLAMP_DC(tmp12);
tmp12 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp12 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -855,7 +860,8 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
tmp10 = (tmp0 + tmp2) << PASS1_BITS;
@@ -960,7 +966,8 @@ jpeg_idct_3x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -1135,7 +1142,8 @@ jpeg_idct_9x9 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -1308,7 +1316,8 @@ jpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z3);
+ if (ctr == 0)
+ CLAMP_DC(z3);
z3 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z3 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -1504,7 +1513,8 @@ jpeg_idct_11x11 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp10);
+ if (ctr == 0)
+ CLAMP_DC(tmp10);
tmp10 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp10 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -1699,7 +1709,8 @@ jpeg_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z3);
+ if (ctr == 0)
+ CLAMP_DC(z3);
z3 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z3 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -1916,7 +1927,8 @@ jpeg_idct_13x13 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z1);
+ if (ctr == 0)
+ CLAMP_DC(z1);
z1 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z1 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -2145,7 +2157,8 @@ jpeg_idct_14x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z1);
+ if (ctr == 0)
+ CLAMP_DC(z1);
z1 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z1 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -2372,7 +2385,8 @@ jpeg_idct_15x15 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z1);
+ if (ctr == 0)
+ CLAMP_DC(z1);
z1 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z1 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -2615,7 +2629,8 @@ jpeg_idct_16x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += 1 << (CONST_BITS-PASS1_BITS-1);
@@ -2893,7 +2908,8 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
inptr[DCTSIZE*7] == 0) {
/* AC terms all zero */
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(dcval);
+ if (ctr == DCTSIZE)
+ CLAMP_DC(dcval);
dcval <<= PASS1_BITS;
wsptr[DCTSIZE*0] = dcval;
@@ -2923,7 +2939,8 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z2);
+ if (ctr == DCTSIZE)
+ CLAMP_DC(z2);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
z2 <<= CONST_BITS;
z3 <<= CONST_BITS;
@@ -3157,7 +3174,8 @@ jpeg_idct_14x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp23 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp23);
+ if (ctr == 0)
+ CLAMP_DC(tmp23);
tmp23 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp23 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -3355,7 +3373,8 @@ jpeg_idct_12x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp10);
+ if (ctr == 0)
+ CLAMP_DC(tmp10);
tmp10 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp10 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -3534,7 +3553,8 @@ jpeg_idct_10x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp12);
+ if (ctr == 0)
+ CLAMP_DC(tmp12);
tmp12 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp12 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -3699,7 +3719,8 @@ jpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
tmp10 = (tmp0 + tmp2) << PASS1_BITS;
@@ -3856,7 +3877,8 @@ jpeg_idct_6x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -3967,7 +3989,8 @@ jpeg_idct_4x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp10);
+ if (ctr == 0)
+ CLAMP_DC(tmp10);
/* Odd part */
@@ -4105,7 +4128,8 @@ jpeg_idct_8x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -4328,7 +4352,8 @@ jpeg_idct_7x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z1);
+ if (ctr == 0)
+ CLAMP_DC(z1);
z1 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z1 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -4514,7 +4539,8 @@ jpeg_idct_6x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z3);
+ if (ctr == 0)
+ CLAMP_DC(z3);
z3 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z3 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -4681,7 +4707,8 @@ jpeg_idct_5x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(z3);
+ if (ctr == 0)
+ CLAMP_DC(z3);
z3 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
z3 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -4850,7 +4877,8 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
inptr[DCTSIZE*7] == 0) {
/* AC terms all zero */
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(dcval);
+ if (ctr == 4)
+ CLAMP_DC(dcval);
dcval <<= PASS1_BITS;
wsptr[4*0] = dcval;
@@ -5022,7 +5050,8 @@ jpeg_idct_3x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
@@ -5130,7 +5159,8 @@ jpeg_idct_2x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- CLAMP_DC(tmp0);
+ if (ctr == 0)
+ CLAMP_DC(tmp0);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
tmp10 = (tmp0 + tmp2) << CONST_BITS;