[Pixman] [PATCH pixman 05/15] pixman-filter: Correct Simpsons integration

Bill Spitzak spitzak at gmail.com
Tue Dec 23 17:52:02 PST 2014


Simpsons uses cubic curve fitting, with 3 samples defining each cubic. This
makes the weights of the samples be in a pattern of 1,4,2,4,2...4,1, and then
dividing the result by 3.

The previous code was using weights of 1,2,6,6...6,2,1 which produced about 2x
the correct value, as it was still dividing by 3. The filter normalization
removed this error. Also this is effectively a linear interpolation except for
the ends.
---
 pixman/pixman-filter.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/pixman/pixman-filter.c b/pixman/pixman-filter.c
index 15f9069..7c1da0d 100644
--- a/pixman/pixman-filter.c
+++ b/pixman/pixman-filter.c
@@ -204,11 +204,14 @@ integral (pixman_kernel_t reconstruct, double x1,
 	{
 	    double a1 = x1 + h * i;
 	    double a2 = x2 + h * i;
+	    s += 4 * SAMPLE(a1, a2);
+	}
 
-	    s += 2 * SAMPLE (a1, a2);
-
-	    if (i >= 2 && i < N_SEGMENTS - 1)
-		s += 4 * SAMPLE (a1, a2);
+	for (i = 2; i < N_SEGMENTS; i += 2)
+	{
+	    double a1 = x1 + h * i;
+	    double a2 = x2 + h * i;
+	    s += 2 * SAMPLE(a1, a2);
 	}
 
 	s += SAMPLE (x1 + width, x2 + width);
-- 
1.7.9.5



More information about the Pixman mailing list