Index: libjpeg6b-6b/jidctint.c =================================================================== --- libjpeg6b-6b.orig/jidctint.c 2006-08-08 20:33:20.052838141 -0700 +++ libjpeg6b-6b/jidctint.c 2006-08-08 20:33:37.314720833 -0700 @@ -156,7 +156,6 @@ ISLOW_MULT_TYPE * quantptr; int * wsptr; JSAMPROW outptr; - JSAMPLE *range_limit = IDCT_range_limit(cinfo); int ctr; int workspace[DCTSIZE2]; /* buffers data between passes */ SHIFT_TEMPS @@ -288,8 +287,7 @@ if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { /* AC terms all zero */ - JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) - & RANGE_MASK]; + JSAMPLE dcval = IDCT_range_limit((int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)); outptr[0] = dcval; outptr[1] = dcval; @@ -357,30 +355,22 @@ /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; - outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0, - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK]; + outptr[0] = IDCT_range_limit((int) DESCALE(tmp10 + tmp3, + CONST_BITS+PASS1_BITS+3)); + outptr[7] = IDCT_range_limit((int) DESCALE(tmp10 - tmp3, + CONST_BITS+PASS1_BITS+3)); + outptr[1] = IDCT_range_limit((int) DESCALE(tmp11 + tmp2, + CONST_BITS+PASS1_BITS+3)); + outptr[6] = IDCT_range_limit((int) DESCALE(tmp11 - tmp2, + CONST_BITS+PASS1_BITS+3)); + outptr[2] = IDCT_range_limit((int) DESCALE(tmp12 + tmp1, + CONST_BITS+PASS1_BITS+3)); + outptr[5] = IDCT_range_limit((int) DESCALE(tmp12 - tmp1, + CONST_BITS+PASS1_BITS+3)); + outptr[3] = IDCT_range_limit((int) DESCALE(tmp13 + tmp0, + CONST_BITS+PASS1_BITS+3)); + outptr[4] = IDCT_range_limit((int) DESCALE(tmp13 - tmp0, + CONST_BITS+PASS1_BITS+3)); wsptr += DCTSIZE; /* advance pointer to next row */ } Index: libjpeg6b-6b/jdct.h =================================================================== --- libjpeg6b-6b.orig/jdct.h 2006-08-08 20:33:18.032617801 -0700 +++ libjpeg6b-6b/jdct.h 2006-08-08 20:33:37.314720833 -0700 @@ -68,14 +68,17 @@ * Each IDCT routine is responsible for range-limiting its results and * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could * be quite far out of range if the input data is corrupt, so a bulletproof - * range-limiting step is required. We use a mask-and-table-lookup method - * to do the combined operations quickly. See the comments with - * prepare_range_limit_table (in jdmaster.c) for more info. + * range-limiting step is required. */ -#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE) +static inline unsigned IDCT_range_limit(int x) +{ + if (x <= -CENTERJSAMPLE) return 0; + if (x >= CENTERJSAMPLE) return MAXJSAMPLE; + return x + CENTERJSAMPLE; +} -#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ +//#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ /* Short forms of external names for systems with brain-damaged linkers. */ Index: libjpeg6b-6b/jidctflt.c =================================================================== --- libjpeg6b-6b.orig/jidctflt.c 2006-08-08 20:33:18.052619982 -0700 +++ libjpeg6b-6b/jidctflt.c 2006-08-08 20:33:37.326722142 -0700 @@ -76,7 +76,6 @@ FLOAT_MULT_TYPE * quantptr; FAST_FLOAT * wsptr; JSAMPROW outptr; - JSAMPLE *range_limit = IDCT_range_limit(cinfo); int ctr; FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ SHIFT_TEMPS @@ -218,22 +217,14 @@ /* Final output stage: scale down by a factor of 8 and range-limit */ - outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) - & RANGE_MASK]; - outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) - & RANGE_MASK]; - outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) - & RANGE_MASK]; - outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) - & RANGE_MASK]; - outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) - & RANGE_MASK]; - outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) - & RANGE_MASK]; - outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) - & RANGE_MASK]; - outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) - & RANGE_MASK]; + outptr[0] = IDCT_range_limit((int) DESCALE((INT32) (tmp0 + tmp7), 3)); + outptr[7] = IDCT_range_limit((int) DESCALE((INT32) (tmp0 - tmp7), 3)); + outptr[1] = IDCT_range_limit((int) DESCALE((INT32) (tmp1 + tmp6), 3)); + outptr[6] = IDCT_range_limit((int) DESCALE((INT32) (tmp1 - tmp6), 3)); + outptr[2] = IDCT_range_limit((int) DESCALE((INT32) (tmp2 + tmp5), 3)); + outptr[5] = IDCT_range_limit((int) DESCALE((INT32) (tmp2 - tmp5), 3)); + outptr[4] = IDCT_range_limit((int) DESCALE((INT32) (tmp3 + tmp4), 3)); + outptr[3] = IDCT_range_limit((int) DESCALE((INT32) (tmp3 - tmp4), 3)); wsptr += DCTSIZE; /* advance pointer to next row */ } Index: libjpeg6b-6b/jidctfst.c =================================================================== --- libjpeg6b-6b.orig/jidctfst.c 2006-08-08 20:33:18.084623473 -0700 +++ libjpeg6b-6b/jidctfst.c 2006-08-08 20:33:37.326722142 -0700 @@ -176,7 +176,6 @@ IFAST_MULT_TYPE * quantptr; int * wsptr; JSAMPROW outptr; - JSAMPLE *range_limit = IDCT_range_limit(cinfo); int ctr; int workspace[DCTSIZE2]; /* buffers data between passes */ SHIFT_TEMPS /* for DESCALE */ @@ -293,8 +292,7 @@ if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { /* AC terms all zero */ - JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) - & RANGE_MASK]; + JSAMPLE dcval = IDCT_range_limit(IDESCALE(wsptr[0], PASS1_BITS+3)); outptr[0] = dcval; outptr[1] = dcval; @@ -344,22 +342,14 @@ /* Final output stage: scale down by a factor of 8 and range-limit */ - outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) - & RANGE_MASK]; - outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) - & RANGE_MASK]; - outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) - & RANGE_MASK]; - outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) - & RANGE_MASK]; - outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) - & RANGE_MASK]; - outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) - & RANGE_MASK]; - outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) - & RANGE_MASK]; - outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) - & RANGE_MASK]; + outptr[0] = IDCT_range_limit(IDESCALE(tmp0 + tmp7, PASS1_BITS+3)); + outptr[7] = IDCT_range_limit(IDESCALE(tmp0 - tmp7, PASS1_BITS+3)); + outptr[1] = IDCT_range_limit(IDESCALE(tmp1 + tmp6, PASS1_BITS+3)); + outptr[6] = IDCT_range_limit(IDESCALE(tmp1 - tmp6, PASS1_BITS+3)); + outptr[2] = IDCT_range_limit(IDESCALE(tmp2 + tmp5, PASS1_BITS+3)); + outptr[5] = IDCT_range_limit(IDESCALE(tmp2 - tmp5, PASS1_BITS+3)); + outptr[4] = IDCT_range_limit(IDESCALE(tmp3 + tmp4, PASS1_BITS+3)); + outptr[3] = IDCT_range_limit(IDESCALE(tmp3 - tmp4, PASS1_BITS+3)); wsptr += DCTSIZE; /* advance pointer to next row */ } Index: libjpeg6b-6b/jidctred.c =================================================================== --- libjpeg6b-6b.orig/jidctred.c 2006-08-08 20:33:18.108626091 -0700 +++ libjpeg6b-6b/jidctred.c 2006-08-08 20:33:37.330722578 -0700 @@ -125,7 +125,6 @@ ISLOW_MULT_TYPE * quantptr; int * wsptr; JSAMPROW outptr; - JSAMPLE *range_limit = IDCT_range_limit(cinfo); int ctr; int workspace[DCTSIZE*4]; /* buffers data between passes */ SHIFT_TEMPS @@ -202,8 +201,7 @@ if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { /* AC terms all zero */ - JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) - & RANGE_MASK]; + JSAMPLE dcval = IDCT_range_limit((int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)); outptr[0] = dcval; outptr[1] = dcval; @@ -244,18 +242,14 @@ /* Final output stage */ - outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2, - CONST_BITS+PASS1_BITS+3+1) - & RANGE_MASK]; - outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2, - CONST_BITS+PASS1_BITS+3+1) - & RANGE_MASK]; - outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0, - CONST_BITS+PASS1_BITS+3+1) - & RANGE_MASK]; - outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0, - CONST_BITS+PASS1_BITS+3+1) - & RANGE_MASK]; + outptr[0] = IDCT_range_limit((int) DESCALE(tmp10 + tmp2, + CONST_BITS+PASS1_BITS+3+1)); + outptr[3] = IDCT_range_limit((int) DESCALE(tmp10 - tmp2, + CONST_BITS+PASS1_BITS+3+1)); + outptr[1] = IDCT_range_limit((int) DESCALE(tmp12 + tmp0, + CONST_BITS+PASS1_BITS+3+1)); + outptr[2] = IDCT_range_limit((int) DESCALE(tmp12 - tmp0, + CONST_BITS+PASS1_BITS+3+1)); wsptr += DCTSIZE; /* advance pointer to next row */ } @@ -277,7 +271,6 @@ ISLOW_MULT_TYPE * quantptr; int * wsptr; JSAMPROW outptr; - JSAMPLE *range_limit = IDCT_range_limit(cinfo); int ctr; int workspace[DCTSIZE*2]; /* buffers data between passes */ SHIFT_TEMPS @@ -334,8 +327,7 @@ #ifndef NO_ZERO_ROW_TEST if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) { /* AC terms all zero */ - JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) - & RANGE_MASK]; + JSAMPLE dcval = IDCT_range_limit((int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)); outptr[0] = dcval; outptr[1] = dcval; @@ -358,12 +350,10 @@ /* Final output stage */ - outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0, - CONST_BITS+PASS1_BITS+3+2) - & RANGE_MASK]; - outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0, - CONST_BITS+PASS1_BITS+3+2) - & RANGE_MASK]; + outptr[0] = IDCT_range_limit((int) DESCALE(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3+2)); + outptr[1] = IDCT_range_limit((int) DESCALE(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3+2)); wsptr += DCTSIZE; /* advance pointer to next row */ } @@ -382,7 +372,6 @@ { int dcval; ISLOW_MULT_TYPE * quantptr; - JSAMPLE *range_limit = IDCT_range_limit(cinfo); SHIFT_TEMPS /* We hardly need an inverse DCT routine for this: just take the @@ -392,7 +381,7 @@ dcval = DEQUANTIZE(coef_block[0], quantptr[0]); dcval = (int) DESCALE((INT32) dcval, 3); - output_buf[0][output_col] = range_limit[dcval & RANGE_MASK]; + output_buf[0][output_col] = IDCT_range_limit(dcval); } #endif /* IDCT_SCALING_SUPPORTED */ Index: libjpeg6b-6b/jdcolor.c =================================================================== --- libjpeg6b-6b.orig/jdcolor.c 2006-08-08 20:34:55.771277398 -0700 +++ libjpeg6b-6b/jdcolor.c 2006-08-08 20:36:00.378323018 -0700 @@ -128,7 +128,6 @@ register JDIMENSION col; JDIMENSION num_cols = cinfo->output_width; /* copy these pointers into registers if possible */ - register JSAMPLE * range_limit = cinfo->sample_range_limit; register int * Crrtab = cconvert->Cr_r_tab; register int * Cbbtab = cconvert->Cb_b_tab; register INT32 * Crgtab = cconvert->Cr_g_tab; @@ -146,11 +145,11 @@ cb = GETJSAMPLE(inptr1[col]); cr = GETJSAMPLE(inptr2[col]); /* Range-limiting is essential due to noise introduced by DCT losses. */ - outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; - outptr[RGB_GREEN] = range_limit[y + + outptr[RGB_RED] = jsample_range_limit(y + Crrtab[cr]); + outptr[RGB_GREEN] = jsample_range_limit(y + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], - SCALEBITS))]; - outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; + SCALEBITS))); + outptr[RGB_BLUE] = jsample_range_limit(y + Cbbtab[cb]); outptr += RGB_PIXELSIZE; } } @@ -253,7 +252,6 @@ register JDIMENSION col; JDIMENSION num_cols = cinfo->output_width; /* copy these pointers into registers if possible */ - register JSAMPLE * range_limit = cinfo->sample_range_limit; register int * Crrtab = cconvert->Cr_r_tab; register int * Cbbtab = cconvert->Cb_b_tab; register INT32 * Crgtab = cconvert->Cr_g_tab; @@ -272,11 +270,11 @@ cb = GETJSAMPLE(inptr1[col]); cr = GETJSAMPLE(inptr2[col]); /* Range-limiting is essential due to noise introduced by DCT losses. */ - outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ - outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ + outptr[0] = jsample_range_limit(MAXJSAMPLE - (y + Crrtab[cr])); /* red */ + outptr[1] = jsample_range_limit(MAXJSAMPLE - (y + /* green */ ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], - SCALEBITS)))]; - outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ + SCALEBITS)))); + outptr[2] = jsample_range_limit(MAXJSAMPLE - (y + Cbbtab[cb])); /* blue */ /* K passes through unchanged */ outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ outptr += 4; Index: libjpeg6b-6b/jpegint.h =================================================================== --- libjpeg6b-6b.orig/jpegint.h 2006-08-08 20:33:54.912640142 -0700 +++ libjpeg6b-6b/jpegint.h 2006-08-08 20:37:36.076694448 -0700 @@ -390,3 +390,10 @@ struct jvirt_barray_control { long dummy; }; #endif #endif /* INCOMPLETE_TYPES_BROKEN */ + +static inline int jsample_range_limit(int x) +{ + if (x < 0) return 0; + if (x > MAXJSAMPLE) return MAXJSAMPLE; + return x; +} Index: libjpeg6b-6b/jdmaster.c =================================================================== --- libjpeg6b-6b.orig/jdmaster.c 2006-08-08 20:39:01.998001091 -0700 +++ libjpeg6b-6b/jdmaster.c 2006-08-08 20:39:39.858102112 -0700 @@ -202,78 +202,6 @@ /* - * Several decompression processes need to range-limit values to the range - * 0..MAXJSAMPLE; the input value may fall somewhat outside this range - * due to noise introduced by quantization, roundoff error, etc. These - * processes are inner loops and need to be as fast as possible. On most - * machines, particularly CPUs with pipelines or instruction prefetch, - * a (subscript-check-less) C table lookup - * x = sample_range_limit[x]; - * is faster than explicit tests - * if (x < 0) x = 0; - * else if (x > MAXJSAMPLE) x = MAXJSAMPLE; - * These processes all use a common table prepared by the routine below. - * - * For most steps we can mathematically guarantee that the initial value - * of x is within MAXJSAMPLE+1 of the legal range, so a table running from - * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial - * limiting step (just after the IDCT), a wildly out-of-range value is - * possible if the input data is corrupt. To avoid any chance of indexing - * off the end of memory and getting a bad-pointer trap, we perform the - * post-IDCT limiting thus: - * x = range_limit[x & MASK]; - * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit - * samples. Under normal circumstances this is more than enough range and - * a correct output will be generated; with bogus input data the mask will - * cause wraparound, and we will safely generate a bogus-but-in-range output. - * For the post-IDCT step, we want to convert the data from signed to unsigned - * representation by adding CENTERJSAMPLE at the same time that we limit it. - * So the post-IDCT limiting table ends up looking like this: - * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE, - * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), - * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), - * 0,1,...,CENTERJSAMPLE-1 - * Negative inputs select values from the upper half of the table after - * masking. - * - * We can save some space by overlapping the start of the post-IDCT table - * with the simpler range limiting table. The post-IDCT table begins at - * sample_range_limit + CENTERJSAMPLE. - * - * Note that the table is allocated in near data space on PCs; it's small - * enough and used often enough to justify this. - */ - -LOCAL(void) -prepare_range_limit_table (j_decompress_ptr cinfo) -/* Allocate and fill in the sample_range_limit table */ -{ - JSAMPLE * table; - int i; - - table = (JSAMPLE *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE)); - table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ - cinfo->sample_range_limit = table; - /* First segment of "simple" table: limit[x] = 0 for x < 0 */ - MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE)); - /* Main part of "simple" table: limit[x] = x */ - for (i = 0; i <= MAXJSAMPLE; i++) - table[i] = (JSAMPLE) i; - table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ - /* End of simple table, rest of first half of post-IDCT table */ - for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) - table[i] = MAXJSAMPLE; - /* Second half of post-IDCT table */ - MEMZERO(table + (2 * (MAXJSAMPLE+1)), - (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE)); - MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), - cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE)); -} - - -/* * Master selection of decompression modules. * This is done once at jpeg_start_decompress time. We determine * which modules will be used and give them appropriate initialization calls. @@ -294,7 +222,6 @@ /* Initialize dimensions and other stuff */ jpeg_calc_output_dimensions(cinfo); - prepare_range_limit_table(cinfo); /* Width of an output scanline must be representable as JDIMENSION. */ samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components; Index: libjpeg6b-6b/jdmerge.c =================================================================== --- libjpeg6b-6b.orig/jdmerge.c 2006-08-08 20:39:02.054007157 -0700 +++ libjpeg6b-6b/jdmerge.c 2006-08-08 20:41:10.711943850 -0700 @@ -234,7 +234,6 @@ JSAMPROW inptr0, inptr1, inptr2; JDIMENSION col; /* copy these pointers into registers if possible */ - register JSAMPLE * range_limit = cinfo->sample_range_limit; int * Crrtab = upsample->Cr_r_tab; int * Cbbtab = upsample->Cb_b_tab; INT32 * Crgtab = upsample->Cr_g_tab; @@ -255,14 +254,14 @@ cblue = Cbbtab[cb]; /* Fetch 2 Y values and emit 2 pixels */ y = GETJSAMPLE(*inptr0++); - outptr[RGB_RED] = range_limit[y + cred]; - outptr[RGB_GREEN] = range_limit[y + cgreen]; - outptr[RGB_BLUE] = range_limit[y + cblue]; + outptr[RGB_RED] = jsample_range_limit(y + cred); + outptr[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr[RGB_BLUE] = jsample_range_limit(y + cblue); outptr += RGB_PIXELSIZE; y = GETJSAMPLE(*inptr0++); - outptr[RGB_RED] = range_limit[y + cred]; - outptr[RGB_GREEN] = range_limit[y + cgreen]; - outptr[RGB_BLUE] = range_limit[y + cblue]; + outptr[RGB_RED] = jsample_range_limit(y + cred); + outptr[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr[RGB_BLUE] = jsample_range_limit(y + cblue); outptr += RGB_PIXELSIZE; } /* If image width is odd, do the last output column separately */ @@ -273,9 +272,9 @@ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cblue = Cbbtab[cb]; y = GETJSAMPLE(*inptr0); - outptr[RGB_RED] = range_limit[y + cred]; - outptr[RGB_GREEN] = range_limit[y + cgreen]; - outptr[RGB_BLUE] = range_limit[y + cblue]; + outptr[RGB_RED] = jsample_range_limit(y + cred); + outptr[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr[RGB_BLUE] = jsample_range_limit(y + cblue); } } @@ -296,7 +295,6 @@ JSAMPROW inptr00, inptr01, inptr1, inptr2; JDIMENSION col; /* copy these pointers into registers if possible */ - register JSAMPLE * range_limit = cinfo->sample_range_limit; int * Crrtab = upsample->Cr_r_tab; int * Cbbtab = upsample->Cb_b_tab; INT32 * Crgtab = upsample->Cr_g_tab; @@ -319,24 +317,24 @@ cblue = Cbbtab[cb]; /* Fetch 4 Y values and emit 4 pixels */ y = GETJSAMPLE(*inptr00++); - outptr0[RGB_RED] = range_limit[y + cred]; - outptr0[RGB_GREEN] = range_limit[y + cgreen]; - outptr0[RGB_BLUE] = range_limit[y + cblue]; + outptr0[RGB_RED] = jsample_range_limit(y + cred); + outptr0[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr0[RGB_BLUE] = jsample_range_limit(y + cblue); outptr0 += RGB_PIXELSIZE; y = GETJSAMPLE(*inptr00++); - outptr0[RGB_RED] = range_limit[y + cred]; - outptr0[RGB_GREEN] = range_limit[y + cgreen]; - outptr0[RGB_BLUE] = range_limit[y + cblue]; + outptr0[RGB_RED] = jsample_range_limit(y + cred); + outptr0[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr0[RGB_BLUE] = jsample_range_limit(y + cblue); outptr0 += RGB_PIXELSIZE; y = GETJSAMPLE(*inptr01++); - outptr1[RGB_RED] = range_limit[y + cred]; - outptr1[RGB_GREEN] = range_limit[y + cgreen]; - outptr1[RGB_BLUE] = range_limit[y + cblue]; + outptr1[RGB_RED] = jsample_range_limit(y + cred); + outptr1[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr1[RGB_BLUE] = jsample_range_limit(y + cblue); outptr1 += RGB_PIXELSIZE; y = GETJSAMPLE(*inptr01++); - outptr1[RGB_RED] = range_limit[y + cred]; - outptr1[RGB_GREEN] = range_limit[y + cgreen]; - outptr1[RGB_BLUE] = range_limit[y + cblue]; + outptr1[RGB_RED] = jsample_range_limit(y + cred); + outptr1[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr1[RGB_BLUE] = jsample_range_limit(y + cblue); outptr1 += RGB_PIXELSIZE; } /* If image width is odd, do the last output column separately */ @@ -347,13 +345,13 @@ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cblue = Cbbtab[cb]; y = GETJSAMPLE(*inptr00); - outptr0[RGB_RED] = range_limit[y + cred]; - outptr0[RGB_GREEN] = range_limit[y + cgreen]; - outptr0[RGB_BLUE] = range_limit[y + cblue]; + outptr0[RGB_RED] = jsample_range_limit(y + cred); + outptr0[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr0[RGB_BLUE] = jsample_range_limit(y + cblue); y = GETJSAMPLE(*inptr01); - outptr1[RGB_RED] = range_limit[y + cred]; - outptr1[RGB_GREEN] = range_limit[y + cgreen]; - outptr1[RGB_BLUE] = range_limit[y + cblue]; + outptr1[RGB_RED] = jsample_range_limit(y + cred); + outptr1[RGB_GREEN] = jsample_range_limit(y + cgreen); + outptr1[RGB_BLUE] = jsample_range_limit(y + cblue); } } Index: libjpeg6b-6b/jquant1.c =================================================================== --- libjpeg6b-6b.orig/jquant1.c 2006-08-08 20:39:02.098011924 -0700 +++ libjpeg6b-6b/jquant1.c 2006-08-08 20:42:44.362089100 -0700 @@ -630,7 +630,6 @@ int row; JDIMENSION col; JDIMENSION width = cinfo->output_width; - JSAMPLE *range_limit = cinfo->sample_range_limit; SHIFT_TEMPS for (row = 0; row < num_rows; row++) { @@ -671,11 +670,10 @@ */ cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4); /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. - * The maximum error is +- MAXJSAMPLE; this sets the required size - * of the range_limit array. + * The maximum error is +- MAXJSAMPLE. */ cur += GETJSAMPLE(*input_ptr); - cur = GETJSAMPLE(range_limit[cur]); + cur = GETJSAMPLE(jsample_range_limit(cur)); /* Select output value, accumulate into output code for this pixel */ pixcode = GETJSAMPLE(colorindex_ci[cur]); *output_ptr += (JSAMPLE) pixcode; Index: libjpeg6b-6b/jquant2.c =================================================================== --- libjpeg6b-6b.orig/jquant2.c 2006-08-08 20:39:02.134015824 -0700 +++ libjpeg6b-6b/jquant2.c 2006-08-08 20:42:38.277429923 -0700 @@ -964,7 +964,6 @@ int row; JDIMENSION col; JDIMENSION width = cinfo->output_width; - JSAMPLE *range_limit = cinfo->sample_range_limit; int *error_limit = cquantize->error_limiter; JSAMPROW colormap0 = cinfo->colormap[0]; JSAMPROW colormap1 = cinfo->colormap[1]; @@ -1014,15 +1013,14 @@ cur1 = error_limit[cur1]; cur2 = error_limit[cur2]; /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. - * The maximum error is +- MAXJSAMPLE (or less with error limiting); - * this sets the required size of the range_limit array. + * The maximum error is +- MAXJSAMPLE (or less with error limiting). */ cur0 += GETJSAMPLE(inptr[0]); cur1 += GETJSAMPLE(inptr[1]); cur2 += GETJSAMPLE(inptr[2]); - cur0 = GETJSAMPLE(range_limit[cur0]); - cur1 = GETJSAMPLE(range_limit[cur1]); - cur2 = GETJSAMPLE(range_limit[cur2]); + cur0 = GETJSAMPLE(jsample_range_limit(cur0)); + cur1 = GETJSAMPLE(jsample_range_limit(cur1)); + cur2 = GETJSAMPLE(jsample_range_limit(cur2)); /* Index into the cache with adjusted pixel value */ cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT]; /* If we have not seen this color before, find nearest colormap */