The Independent JPEG Group's JPEG software v5a
diff --git a/jdmerge.c b/jdmerge.c
index a0b9cae..a5a864e 100644
--- a/jdmerge.c
+++ b/jdmerge.c
@@ -82,7 +82,7 @@
 start_pass_merged_upsample (j_decompress_ptr cinfo)
 {
   my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
-  INT32 i, x2;
+  INT32 i, x;
   SHIFT_TEMPS
 
   /* Mark the spare buffer empty */
@@ -106,21 +106,20 @@
     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
 				(MAXJSAMPLE+1) * SIZEOF(INT32));
 
-  for (i = 0; i <= MAXJSAMPLE; i++) {
+  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
     /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
-    /* The Cb or Cr value we are thinking of is x = i - MAXJSAMPLE/2 */
-    x2 = 2*i - MAXJSAMPLE;	/* twice x */
+    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
     /* Cr=>R value is nearest int to 1.40200 * x */
     upsample->Cr_r_tab[i] = (int)
-		    RIGHT_SHIFT(FIX(1.40200/2) * x2 + ONE_HALF, SCALEBITS);
+		    RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
     /* Cb=>B value is nearest int to 1.77200 * x */
     upsample->Cb_b_tab[i] = (int)
-		    RIGHT_SHIFT(FIX(1.77200/2) * x2 + ONE_HALF, SCALEBITS);
+		    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
     /* Cr=>G value is scaled-up -0.71414 * x */
-    upsample->Cr_g_tab[i] = (- FIX(0.71414/2)) * x2;
+    upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
     /* Cb=>G value is scaled-up -0.34414 * x */
     /* We also add in ONE_HALF so that need not do it in inner loop */
-    upsample->Cb_g_tab[i] = (- FIX(0.34414/2)) * x2 + ONE_HALF;
+    upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
   }
 }