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

Bill Spitzak <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <1410400925-8536-3-git-send-email-spitzak__27465.0449668572$1410401036$gmane$org@gmail.com>
Samples are multiplied in a 1,4,2,4,2,4,1 pattern, previous version
did 1,2,4,4,4,2,1.

I also reduced the number of samples greatly as there is no
numerical difference with the filter functions.
---
 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

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.