[Pixman] [PATCH v14 15/22] pixman-filter: Use array index instead of pointers

spitzak at gmail.com spitzak at gmail.com
Mon Mar 7 01:06:50 UTC 2016


From: Bill Spitzak <spitzak at gmail.com>

This removes some confusion and at least one bug: the error on a 1-wide filter is now
added to the sample, rather than after the end of the filter.

Signed-off-by: Bill Spitzak <spitzak at gmail.com>
---
 pixman/pixman-filter.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/pixman/pixman-filter.c b/pixman/pixman-filter.c
index 8dfb49b..36dd811 100644
--- a/pixman/pixman-filter.c
+++ b/pixman/pixman-filter.c
@@ -238,13 +238,11 @@ create_1d_filter (int              width,
 		  int              n_phases,
 		  pixman_fixed_t *p)
 {
-    double step;
+    double step = 1.0 / n_phases;
     double rwidth2 = filters[reconstruct].width / 2.0;
     double swidth2 = size * filters[sample].width / 2.0;
     int i;
 
-    step = 1.0 / n_phases;
-
     for (i = 0; i < n_phases; ++i)
     {
 	double frac = step / 2.0 + i * step;
@@ -271,23 +269,23 @@ create_1d_filter (int              width,
 				 sample, 1.0 / size, pos,
 				 ilow, ihigh);
 	    total += c;
-	    *p++ = (pixman_fixed_t)(c * 65536.0 + 0.5);
+	    p[x] = (pixman_fixed_t)(c * 65536.0 + 0.5);
 	}
 
 	/* Normalize */
-	p -= width;
-        total = 1 / total;
-        new_total = 0;
+	total = 1 / total;
+	new_total = 0;
 	for (x = 0; x < width; ++x)
 	{
-	    pixman_fixed_t t = (*p) * total + 0.5;
-
+	    pixman_fixed_t t = p[x] * total + 0.5;
 	    new_total += t;
-	    *p++ = t;
+	    p[x] = t;
 	}
 
 	if (new_total != pixman_fixed_1)
-	    *(p - width / 2) += (pixman_fixed_1 - new_total);
+	    p[width / 2] += (pixman_fixed_1 - new_total);
+
+	p += width;
     }
 }
 
-- 
1.9.1



More information about the Pixman mailing list