]> granicus.if.org Git - imagemagick/commitdiff
PIL should be MagickRealType + Bohman uses one less trig call
authornicolas <nicolas@git.imagemagick.org>
Mon, 20 Sep 2010 20:28:38 +0000 (20:28 +0000)
committernicolas <nicolas@git.imagemagick.org>
Mon, 20 Sep 2010 20:28:38 +0000 (20:28 +0000)
ChangeLog
magick/resize.c

index 2934ae3b1490b92ddeb688b413840886a740e5ed..a84238b36a8c044a3d5d03329a56bb60e9179385 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-09-20  6.6.4-5 Nicolas Robidoux <nicolas.robidoux@gmail...>
+  * Modified "magick/resize.c" so that PIL is a MagickRealType number. Earlier,
+    some computations were needlessly done in long double precision because PIL
+    forced an automatic upcast wherever it appeared.
+  * Modified "magick/resize.c" so that Bohman uses one trig call + one sqrt call
+    instead of two trig calls.
+
 2010-09-20  6.6.4-5 Anthony Thyssen <A.Thyssen@griffith...>
   * modified "magick/resample.c" to allow use of either EWA or HQEWA (default)
   * Removed LanczosFast from supported filters (SincFast*SincFast is faster)
index be12f16e88e546f17a9a72f7596d26b85577b91f..3457f00383037a6003e06cd7c26a29118b5df300 100644 (file)
@@ -133,7 +133,7 @@ static MagickRealType
 %
 */
 
-#define MagickPIL 3.14159265358979323846264338327950288420L
+#define MagickPIL ((MagickRealType) 3.14159265358979323846264338327950288420L)
 
 static MagickRealType Bessel(const MagickRealType x,
   const ResizeFilter *magick_unused(resize_filter))
@@ -168,9 +168,13 @@ static MagickRealType Bohman(const MagickRealType x,
   /*
     Bohman: 2rd Order cosine windowing function:
       (1-x) cos(pi x) + sin(pi x) / pi.
+    Refactored by Nicolas Robidoux to one trig call, one sqrt call,
+    and 7 flops, taking advantage of the fact that the support of
+    Bohman is 1 (so that we know that sin(pi x) >= 0).
   */
-  const double pix = (double) (MagickPIL*x);
-  return((MagickRealType) ((1.0-x)*cos(pix)+(1.0/MagickPIL)*sin(pix)));
+  const double cospix = cos((double) (MagickPIL*x));
+  const double sinpix = sqrt(1.0-cospix*cospix);
+  return((MagickRealType) ((1.0-x)*cospix+(1.0/MagickPIL)*sinpix));
 }
 
 static MagickRealType Box(const MagickRealType x,