[Pixman] [PATCH pixman 03/11] pixman-filter: Correct Simpsons integration

Bill Spitzak spitzak at gmail.com
Fri Sep 26 19:06:02 PDT 2014


Samples are multiplied in a 1,4,2,4,2...4,1 pattern, previous version
did 1,2,6,6...6,2,1 which produced 2x the correct integrated value
(this was corrected by the normalization) and also just did simple
numeric integration and not Simpsons.

I also reduced the number of samples a lot as it is plenty accurate
at a much lower number.
---
 pixman/pixman-filter.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/pixman/pixman-filter.c b/pixman/pixman-filter.c
index b2bf53f..a9af72c 100644
--- a/pixman/pixman-filter.c
+++ b/pixman/pixman-filter.c
@@ -190,7 +190,7 @@ integral (pixman_kernel_t kernel1, double x1,
     else
     {
 	/* Integration via Simpson's rule */
-#define N_SEGMENTS 128
+#define N_SEGMENTS 16
 #define SAMPLE(a1, a2)							\
 	(filters[kernel1].func ((a1)) * filters[kernel2].func ((a2) * scale))
 	
@@ -204,11 +204,14 @@ integral (pixman_kernel_t kernel1, 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