[Pixman] [PATCH 1/3] gradient walker: Correct types and fix formatting

Søren Sandmann sandmann at cs.au.dk
Sat Oct 15 07:57:10 PDT 2011


From: Søren Sandmann Pedersen <ssp at redhat.com>

The type of pos in gradient_walker_reset() and gradient_walker_pixel()
is pixman_fixed_48_16_t and not pixman_fixed_32_32. The types of the
positions in the walker struct are pixman_fixed_t and not int32_t, and
need_reset is a boolean, not an integer. The spread field should be
called repeat and have the type pixman_repeat_t.

Also fix some formatting issues, make gradient_walker_reset() static,
and delete the pointless PIXMAN_GRADIENT_WALKER_NEED_RESET() macro.
---
 pixman/pixman-gradient-walker.c |   41 +++++++++++++++++++++-----------------
 pixman/pixman-private.h         |   16 +++++++-------
 2 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/pixman/pixman-gradient-walker.c b/pixman/pixman-gradient-walker.c
index dd666b4..53d0b30 100644
--- a/pixman/pixman-gradient-walker.c
+++ b/pixman/pixman-gradient-walker.c
@@ -31,7 +31,7 @@
 void
 _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
                               gradient_t *              gradient,
-                              unsigned int              spread)
+                              pixman_repeat_t		repeat)
 {
     walker->num_stops = gradient->n_stops;
     walker->stops     = gradient->stops;
@@ -42,29 +42,32 @@ _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
     walker->left_rb   = 0;
     walker->right_ag  = 0;
     walker->right_rb  = 0;
-    walker->spread    = spread;
+    walker->repeat    = repeat;
 
     walker->need_reset = TRUE;
 }
 
-void
-_pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
-                               pixman_fixed_32_32_t      pos)
+static void
+gradient_walker_reset (pixman_gradient_walker_t *walker,
+		       pixman_fixed_48_16_t      pos)
 {
     int32_t x, left_x, right_x;
-    pixman_color_t          *left_c, *right_c;
+    pixman_color_t *left_c, *right_c;
     int n, count = walker->num_stops;
-    pixman_gradient_stop_t *      stops = walker->stops;
+    pixman_gradient_stop_t *stops = walker->stops;
 
     static const pixman_color_t transparent_black = { 0, 0, 0, 0 };
 
-    switch (walker->spread)
+    switch (walker->repeat)
     {
     case PIXMAN_REPEAT_NORMAL:
 	x = (int32_t)pos & 0xFFFF;
 	for (n = 0; n < count; n++)
+	{
 	    if (x < stops[n].x)
 		break;
+	}
+
 	if (n == 0)
 	{
 	    left_x =  stops[count - 1].x - 0x10000;
@@ -92,8 +95,10 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
 
     case PIXMAN_REPEAT_PAD:
 	for (n = 0; n < count; n++)
+	{
 	    if (pos < stops[n].x)
 		break;
+	}
 
 	if (n == 0)
 	{
@@ -122,9 +127,12 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
 	x = (int32_t)pos & 0xFFFF;
 	if ((int32_t)pos & 0x10000)
 	    x = 0x10000 - x;
+
 	for (n = 0; n < count; n++)
+	{
 	    if (x < stops[n].x)
 		break;
+	}
 
 	if (n == 0)
 	{
@@ -169,8 +177,10 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
 
     default:  /* REPEAT_NONE */
 	for (n = 0; n < count; n++)
+	{
 	    if (pos < stops[n].x)
 		break;
+	}
 
 	if (n == 0)
 	{
@@ -201,8 +211,8 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
     walker->right_rb = ((right_c->red & 0xff00) << 8) | (right_c->blue >> 8);
 
     if (walker->left_x == walker->right_x                ||
-        ( walker->left_ag == walker->right_ag &&
-          walker->left_rb == walker->right_rb )   )
+        (walker->left_ag == walker->right_ag &&
+	 walker->left_rb == walker->right_rb))
     {
 	walker->stepper = 0;
     }
@@ -215,20 +225,15 @@ _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
     walker->need_reset = FALSE;
 }
 
-#define  PIXMAN_GRADIENT_WALKER_NEED_RESET(w, x)                         \
-    ( (w)->need_reset || (x) < (w)->left_x || (x) >= (w)->right_x)
-
-
-/* the following assumes that PIXMAN_GRADIENT_WALKER_NEED_RESET(w,x) is FALSE */
 uint32_t
 _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
-                               pixman_fixed_32_32_t      x)
+                               pixman_fixed_48_16_t      x)
 {
     int dist, idist;
     uint32_t t1, t2, a, color;
 
-    if (PIXMAN_GRADIENT_WALKER_NEED_RESET (walker, x))
-	_pixman_gradient_walker_reset (walker, x);
+    if (walker->need_reset || x < walker->left_x || x >= walker->right_x)
+	gradient_walker_reset (walker, x);
 
     dist  = ((int)(x - walker->left_x) * walker->stepper) >> 16;
     idist = 256 - dist;
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index cbd48f3..1443bfb 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -299,29 +299,29 @@ typedef struct
     uint32_t                left_rb;
     uint32_t                right_ag;
     uint32_t                right_rb;
-    int32_t                 left_x;
-    int32_t                 right_x;
-    int32_t                 stepper;
+    pixman_fixed_t	    left_x;
+    pixman_fixed_t          right_x;
+    pixman_fixed_t          stepper;
 
     pixman_gradient_stop_t *stops;
     int                     num_stops;
-    unsigned int            spread;
+    pixman_repeat_t	    repeat;
 
-    int                     need_reset;
+    pixman_bool_t           need_reset;
 } pixman_gradient_walker_t;
 
 void
 _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
                               gradient_t *              gradient,
-                              unsigned int              spread);
+			      pixman_repeat_t           repeat);
 
 void
 _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
-                               pixman_fixed_32_32_t      pos);
+                               pixman_fixed_48_16_t      pos);
 
 uint32_t
 _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
-                               pixman_fixed_32_32_t      x);
+                               pixman_fixed_48_16_t      x);
 
 /*
  * Edges
-- 
1.6.0.6



More information about the Pixman mailing list