]> granicus.if.org Git - imagemagick/commitdiff
Add Raw low level Cosine Windowing Filter
authoranthony <anthony@git.imagemagick.org>
Tue, 8 May 2012 01:22:41 +0000 (01:22 +0000)
committeranthony <anthony@git.imagemagick.org>
Tue, 8 May 2012 01:22:41 +0000 (01:22 +0000)
MagickCore/option.c
MagickCore/resample.h
MagickCore/resize.c

index f8c81dab0a4e3e206caf37359d26850f61234eff..c8ecdfd36f74830be59454268115c3e327e6d8ef 100644 (file)
@@ -1015,6 +1015,7 @@ static const OptionInfo
     { "Bohman", BohmanFilter, UndefinedOptionFlag, MagickFalse },
     { "Box", BoxFilter, UndefinedOptionFlag, MagickFalse },
     { "Catrom", CatromFilter, UndefinedOptionFlag, MagickFalse },
+    { "Cosine", CosineFilter, UndefinedOptionFlag, MagickFalse },
     { "Cubic", CubicFilter, UndefinedOptionFlag, MagickFalse },
     { "Gaussian", GaussianFilter, UndefinedOptionFlag, MagickFalse },
     { "Hamming", HammingFilter, UndefinedOptionFlag, MagickFalse },
index 6e1f8617e3c6a7f32aeeb38161f1db2431849d02..7701612520251d95af7d6dd28b8348d384d792fe 100644 (file)
@@ -59,6 +59,7 @@ typedef enum
   Lanczos2SharpFilter,
   RobidouxFilter,
   RobidouxSharpFilter,
+  CosineFilter,
   SentinelFilter  /* a count of all the filters, not a real filter */
 } FilterTypes;
 
index 13979e08d46cb4886d7478f76b515abae736d5ec..21d5a2b277431096628940461f6303fdbb0c9e89 100644 (file)
@@ -138,8 +138,6 @@ static MagickRealType
 %
 */
 
-#define MagickPIL ((MagickRealType) 3.14159265358979323846264338327950288420L)
-
 static MagickRealType Blackman(const MagickRealType x,
   const ResizeFilter *magick_unused(resize_filter))
 {
@@ -150,7 +148,7 @@ static MagickRealType Blackman(const MagickRealType x,
     Refactored by Chantal Racette and Nicolas Robidoux to one trig call and
     five flops.
   */
-  const MagickRealType cosine=cos((double) (MagickPIL*x));
+  const MagickRealType cosine=cos((double) (MagickPI*x));
   return(0.34+cosine*(0.5+cosine*0.16));
 }
 
@@ -165,9 +163,9 @@ static MagickRealType Bohman(const MagickRealType x,
     taking advantage of the fact that the support of Bohman is 1.0 (so that we
     know that sin(pi x) >= 0).
   */
-  const MagickRealType cosine=cos((double) (MagickPIL*x));
+  const MagickRealType cosine=cos((double) (MagickPI*x));
   const MagickRealType sine=sqrt(1.0-cosine*cosine);
-  return((1.0-x)*cosine+(1.0/MagickPIL)*sine);
+  return((1.0-x)*cosine+(1.0/MagickPI)*sine);
 }
 
 static MagickRealType Box(const MagickRealType magick_unused(x),
@@ -181,6 +179,16 @@ static MagickRealType Box(const MagickRealType magick_unused(x),
   return(1.0);
 }
 
+static MagickRealType Cosine(const MagickRealType x,
+  const ResizeFilter *magick_unused(resize_filter))
+{
+  /*
+    Cosine window function:
+      cos((pi/2)*x).
+  */
+  return((MagickRealType)cos((double) (MagickPI2*x)));
+}
+
 static MagickRealType CubicBC(const MagickRealType x,
   const ResizeFilter *resize_filter)
 {
@@ -265,7 +273,7 @@ static MagickRealType Hanning(const MagickRealType x,
     Cosine window function:
       0.5+0.5*cos(pi*x).
   */
-  const MagickRealType cosine=cos((double) (MagickPIL*x));
+  const MagickRealType cosine=cos((double) (MagickPI*x));
   return(0.5+0.5*cosine);
 }
 
@@ -276,7 +284,7 @@ static MagickRealType Hamming(const MagickRealType x,
     Offset cosine window function:
      .54 + .46 cos(pi x).
   */
-  const MagickRealType cosine=cos((double) (MagickPIL*x));
+  const MagickRealType cosine=cos((double) (MagickPI*x));
   return(0.54+0.46*cosine);
 }
 
@@ -292,8 +300,8 @@ static MagickRealType Jinc(const MagickRealType x,
     really it is more accurately named "Jinc".
   */
   if (x == 0.0)
-    return(0.5*MagickPIL);
-  return(BesselOrderOne(MagickPIL*x)/x);
+    return(0.5*MagickPI);
+  return(BesselOrderOne(MagickPI*x)/x);
 }
 
 static MagickRealType Kaiser(const MagickRealType x,
@@ -365,7 +373,7 @@ static MagickRealType Sinc(const MagickRealType x,
   */
   if (x != 0.0)
     {
-      const MagickRealType alpha=(MagickRealType) (MagickPIL*x);
+      const MagickRealType alpha=(MagickRealType) (MagickPI*x);
       return(sin((double) alpha)/alpha);
     }
   return((MagickRealType) 1.0);
@@ -400,7 +408,7 @@ static MagickRealType SincFast(const MagickRealType x,
   */
   if (x > 4.0)
     {
-      const MagickRealType alpha=(MagickRealType) (MagickPIL*x);
+      const MagickRealType alpha=(MagickRealType) (MagickPI*x);
       return(sin((double) alpha)/alpha);
     }
   {
@@ -740,6 +748,7 @@ MagickPrivate ResizeFilter *AcquireResizeFilter(const Image *image,
     { Lanczos2SharpFilter, Lanczos2SharpFilter },
     { RobidouxFilter,      BoxFilter      },  /* Cubic Keys tuned for EWA     */
     { RobidouxSharpFilter, BoxFilter      },  /* Sharper Cubic Keys for EWA   */
+    { SincFastFilter,      CosineFilter   },  /* low level cosine window      */
   };
   /*
     Table mapping the filter/window from the above table to an actual function.
@@ -798,7 +807,8 @@ MagickPrivate ResizeFilter *AcquireResizeFilter(const Image *image,
                             0.37821575509399867, 0.31089212245300067 },
     /* RobidouxSharp: Sharper version of Robidoux */
     { CubicBC,   2.0, 1.105822933719019,
-                            0.2620145123990142,  0.3689927438004929  }
+                            0.2620145123990142,  0.3689927438004929  },
+    { Cosine,    1.0, 1.0, 0.0, 0.0 }  /* Low level cosine window     */
   };
   /*
     The known zero crossings of the Jinc() or more accurately the Jinc(x*PI)