[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cairo
Subject:    [cairo] [PATCH pixman 03/11] pixman-filter: Correct Simpsons integration
From:       Bill Spitzak <spitzak () gmail ! com>
Date:       2014-09-27 2:06:02
Message-ID: 1411783570-24329-4-git-send-email-spitzak () gmail ! com
[Download RAW message or body]

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

-- 
cairo mailing list
cairo@cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic