Index: scale-region.c
===================================================================
--- scale-region.c	(revision 26457)
+++ scale-region.c	(working copy)
@@ -603,16 +603,16 @@
             {
               yfrac = y / scaley;
               sy0   = (gint) yfrac;
-              sy1   = sy0 + 1;
-              sy1   = (sy1 >= src_height) ? src_height - 1 : sy1;
+              sy0 = CLAMP(sy0, 0, src_height - 1);
+              sy1 = CLAMP(sy1+1, 0, src_height - 1);
               yfrac = yfrac - sy0;
 
               for (x = x0; x <= x1; x++)
                 {
                   xfrac = x / scalex;
                   sx0   = (gint) xfrac;
-                  sx1   = sx0 + 1;
-                  sx1   = (sx1 >= src_width) ? src_width - 1 : sx1;
+                  sx0 = CLAMP(sx0, 0, src_width - 1);
+                  sx1 = CLAMP(sx0+1, 0, src_width - 1);
                   xfrac = xfrac - sx0;
 
                   switch (interpolation)
@@ -809,10 +809,8 @@
     {
       for (x = x0 - 1; x <= x0 + 2; x++, i++)
         {
-          x1 = ABS(x);
-          y1 = ABS(y);
-          x1 = (x1 < src_width)  ? x1 : 2 * src_width - x1 - 1;
-          y1 = (y1 < src_height) ? y1 : 2 * src_height - y1 - 1;
+          x1 = CLAMP(x, 0, src_width - 1);
+          y1 = CLAMP(y, 0, src_height - 1);
           read_pixel_data_1 (srcTM, x1, y1, pixels + (i * src_bpp));
         }
     }
@@ -939,10 +937,8 @@
     {
       for (x = x0 - 2; x <= x0 + 3; x++, i++)
         {
-          x1 = ABS(x);
-          y1 = ABS(y);
-          x1 = (x1 < src_width)  ? x1 : 2 * src_width - x1 - 1;
-          y1 = (y1 < src_height) ? y1 : 2 * src_height - y1 - 1;
+          x1 = CLAMP(x, 0, src_width - 1);
+          y1 = CLAMP(y, 0, src_height - 1);
           read_pixel_data_1 (srcTM, x1, y1, pixels + (i * src_bpp));
         }
     }
@@ -1331,8 +1327,8 @@
   for (y = y1 - 1, i = 0; y <= y1 + 2; y++)
     for (x = x1 - 1; x <= x1 + 2; x++, i++)
       {
-        x0 = (x < src_width)  ? ABS(x) : 2 * src_width  - x - 1;
-        y0 = (y < src_height) ? ABS(y) : 2 * src_height - y - 1;
+        x0 = CLAMP(x, 0, src_width - 1);
+        y0 = CLAMP(y, 0, src_height - 1);
         read_pixel_data_1 (srcTM, x0, y0, ps + (i * src_bpp));
       }
 
@@ -1508,8 +1504,8 @@
     {
       for (x = x1 - 2; x <= x1 + 3; x++, i++)
         {
-          x0 = (x < src_width)  ? ABS(x) : 2 * src_width  - x - 1;
-          y0 = (y < src_height) ? ABS(y) : 2 * src_height - y - 1;
+          x0 = CLAMP(x, 0, src_width - 1);
+          y0 = CLAMP(y, 0, src_height - 1);
           read_pixel_data_1 (srcTM, x0, y0, pixels + (i * src_bpp));
         }
     }
@@ -1595,17 +1591,16 @@
     {
       yfrac = (y / scaley);
       sy0   = (gint) yfrac;
-      sy1   = sy0 + 1;
-      sy1   = (sy1 < src_height) ? ABS(sy1) : 2 * src_height - sy1 - 1;
-
+      sy0 = CLAMP(sy0, 0, src_height - 1);
+      sy1 = CLAMP(sy0+1, 0, src_height - 1);
       yfrac =  yfrac - sy0;
 
       for (x = 0; x < dstPR->w; x++)
         {
           xfrac = (x / scalex);
           sx0   = (gint) xfrac;
-          sx1   = sx0 + 1;
-          sx1   = (sx1 < src_width) ? ABS(sx1) : 2 * src_width - sx1 - 1;
+          sx0 = CLAMP(sx0, 0, src_width - 1);
+          sx1 = CLAMP(sx1+1, 0, src_width - 1);
           xfrac =  xfrac - sx0;
 
           switch (interpolation)
