Use fetch_nearest() instead of having duplicated code
authorSøren Sandmann Pedersen <sandmann@redhat.com>
Wed, 5 Nov 2008 22:23:45 +0000 (17:23 -0500)
committerSøren Sandmann Pedersen <sandmann@redhat.com>
Wed, 5 Nov 2008 22:23:45 +0000 (17:23 -0500)
pixman/pixman-transformed.c

index cfdc48c..2a374f6 100644 (file)
@@ -87,123 +87,58 @@ do_fetch (bits_image_t *pict, int x, int y, fetchPixelProc32 fetch,
 /*
  * Fetching Algorithms
  */
-static void
-fbFetchTransformed_Nearest_Normal(bits_image_t * pict, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits, pixman_bool_t affine, pixman_vector_t v, pixman_vector_t unit)
+static uint32_t
+fetch_nearest (bits_image_t            *pict,
+              fetchPixelProc32          fetch,
+              pixman_bool_t             affine,
+              pixman_repeat_t           repeat,
+              pixman_bool_t             has_src_clip,
+              const pixman_vector_t    *v)
 {
-    fetchPixelProc32   fetch;
-    pixman_bool_t src_clip;
-    int x, y, i;
-
-    /* initialize the two function pointers */
-    fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict);
-
-    src_clip = pict->common.src_clip != &(pict->common.full_region);
-
-    for ( i = 0; i < width; ++i)
+    if (!v->vector[2])
     {
-        if (!mask || mask[i] & maskBits)
-        {
-            if (!v.vector[2])
-            {
-                *(buffer + i) = 0;
-            }
-            else
-            {
-                if (!affine)
-                {
-                    y = MOD(DIV(v.vector[1],v.vector[2]), pict->height);
-                    x = MOD(DIV(v.vector[0],v.vector[2]), pict->width);
-                }
-                else
-                {
-                    y = MOD(v.vector[1]>>16, pict->height);
-                    x = MOD(v.vector[0]>>16, pict->width);
-                }
-
-                *(buffer + i) = do_fetch (pict, x, y, fetch, src_clip, TRUE);
-            }
-        }
-
-        v.vector[0] += unit.vector[0];
-        v.vector[1] += unit.vector[1];
-        v.vector[2] += unit.vector[2];
+       return 0;
     }
-}
-
-static void
-fbFetchTransformed_Nearest_Pad(bits_image_t * pict, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits, pixman_bool_t affine, pixman_vector_t v, pixman_vector_t unit)
-{
-    pixman_bool_t src_clip;
-    fetchPixelProc32 fetch;
-    int x, y, i;
-
-    /* initialize the two function pointers */
-    fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict);
-
-    src_clip = pict->common.src_clip != &(pict->common.full_region);
-
-    for (i = 0; i < width; ++i)
+    else
     {
-        if (!mask || mask[i] & maskBits)
-        {
-            if (!v.vector[2])
-            {
-                *(buffer + i) = 0;
-            }
-            else
-            {
-                if (!affine)
-                {
-                    y = CLIP(DIV(v.vector[1], v.vector[2]), 0, pict->height-1);
-                    x = CLIP(DIV(v.vector[0], v.vector[2]), 0, pict->width-1);
-                }
-                else
-                {
-                    y = CLIP(v.vector[1]>>16, 0, pict->height-1);
-                    x = CLIP(v.vector[0]>>16, 0, pict->width-1);
-                }
-
-                *(buffer + i) = do_fetch (pict, x, y, fetch, src_clip, TRUE);
-            }
-        }
-
-        v.vector[0] += unit.vector[0];
-        v.vector[1] += unit.vector[1];
-        v.vector[2] += unit.vector[2];
-    }
-}
-
-static void
-fbFetchTransformed_Nearest_General(bits_image_t * pict, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits, pixman_bool_t affine, pixman_vector_t v, pixman_vector_t unit)
-{
-    fetchPixelProc32   fetch;
-    pixman_bool_t src_clip;
-    int x, y, i;
+       int x, y;
+       pixman_bool_t inside_bounds;
 
-    fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict);
+       if (!affine)
+       {
+           x = DIV(v->vector[0], v->vector[2]);
+           y = DIV(v->vector[1], v->vector[2]);
+       }
+       else
+       {
+           x = v->vector[0]>>16;
+           y = v->vector[1]>>16;
+       }
 
-    src_clip = pict->common.src_clip != &(pict->common.full_region);
+       switch (repeat)
+       {
+       case PIXMAN_REPEAT_NORMAL:
+           x = MOD (x, pict->width);
+           y = MOD (y, pict->height);
+           inside_bounds = TRUE;
+           break;
+           
+       case PIXMAN_REPEAT_PAD:
+           x = CLIP (x, 0, pict->width-1);
+           y = CLIP (y, 0, pict->height-1);
+           inside_bounds = TRUE;
+           break;
+           
+       case PIXMAN_REPEAT_REFLECT: /* Thanks Trolltech for not implementing reflect for images */
+       case PIXMAN_REPEAT_NONE:
+           inside_bounds = FALSE;
+           break;
 
-    for (i = 0; i < width; ++i) {
-        if (!mask || mask[i] & maskBits)
-        {
-            if (!v.vector[2]) {
-                *(buffer + i) = 0;
-            } else {
-                if (!affine) {
-                    y = DIV(v.vector[1],v.vector[2]);
-                    x = DIV(v.vector[0],v.vector[2]);
-                } else {
-                    y = v.vector[1]>>16;
-                    x = v.vector[0]>>16;
-                }
+       default:
+           return 0;
+       }
 
-                *(buffer + i) = do_fetch (pict, x, y, fetch, src_clip, FALSE);
-            }
-        }
-        v.vector[0] += unit.vector[0];
-        v.vector[1] += unit.vector[1];
-        v.vector[2] += unit.vector[2];
+       return do_fetch (pict, x, y, fetch, has_src_clip, inside_bounds);
     }
 }
 
@@ -450,22 +385,29 @@ ACCESS(fbFetchTransformed)(bits_image_t * pict, int x, int y, int width,
 
     if (pict->common.filter == PIXMAN_FILTER_NEAREST || pict->common.filter == PIXMAN_FILTER_FAST)
     {
+       fetchPixelProc32   fetch;
+       pixman_bool_t src_clip;
+       int i;
+
        /* Round down to closest integer, ensuring that 0.5 rounds to 0, not 1 */
        adjust (&v, &unit, pixman_fixed_1 / 2 - pixman_fixed_e);
+
+       /* initialize the two function pointers */
+       fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict);
        
-        if (pict->common.repeat == PIXMAN_REPEAT_NORMAL)
-        {
-            fbFetchTransformed_Nearest_Normal(pict, width, buffer, mask, maskBits, affine, v, unit);
-        }
-        else if (pict->common.repeat == PIXMAN_REPEAT_PAD)
-        {
-            fbFetchTransformed_Nearest_Pad(pict, width, buffer, mask, maskBits, affine, v, unit);
-        }
-        else
-        {
-            fbFetchTransformed_Nearest_General(pict, width, buffer, mask, maskBits, affine, v, unit);
-        }
-    } else if (pict->common.filter == PIXMAN_FILTER_BILINEAR   ||
+       src_clip = pict->common.src_clip != &(pict->common.full_region);
+       
+       for ( i = 0; i < width; ++i)
+       {
+           if (!mask || mask[i] & maskBits)
+               *(buffer + i) = fetch_nearest (pict, fetch, affine, pict->common.repeat, src_clip, &v);
+           
+           v.vector[0] += unit.vector[0];
+           v.vector[1] += unit.vector[1];
+           v.vector[2] += unit.vector[2];
+       }
+    }
+    else if (pict->common.filter == PIXMAN_FILTER_BILINEAR     ||
               pict->common.filter == PIXMAN_FILTER_GOOD        ||
               pict->common.filter == PIXMAN_FILTER_BEST)
     {