[Pixman] [PATCH pixman 3/4] Changed PIXMAN_KERNEL enums

Bill Spitzak spitzak at gmail.com
Thu Jul 31 15:16:50 PDT 2014


Added TENT filter.

Renamed IMPULSE to NEAREST as this is the term used elsewhere

Renamed other values to match what they are now producing.

Add back-compatibility #define for old names.
---
 demos/scale.c          |    9 +++++----
 pixman/pixman-filter.c |   51 ++++++++++++++++++++++++++++++++++++------------
 pixman/pixman.h        |   17 +++++++++++-----
 3 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/demos/scale.c b/demos/scale.c
index 0b6c715..bfd34f6 100644
--- a/demos/scale.c
+++ b/demos/scale.c
@@ -71,13 +71,14 @@ typedef struct
 static const named_int_t filters[] =
 {
     { "Box",			PIXMAN_KERNEL_BOX },
-    { "Impulse",		PIXMAN_KERNEL_IMPULSE },
+    { "Nearest",		PIXMAN_KERNEL_NEAREST },
     { "Linear",			PIXMAN_KERNEL_LINEAR },
-    { "Cubic",			PIXMAN_KERNEL_CUBIC },
-    { "Lanczos2",		PIXMAN_KERNEL_LANCZOS2 },
+    { "Tent",			PIXMAN_KERNEL_TENT },
+    { "Mitchell",		PIXMAN_KERNEL_MITCHELL },
+    { "Catmull-Rom",		PIXMAN_KERNEL_CATMULL_ROM },
     { "Lanczos3",		PIXMAN_KERNEL_LANCZOS3 },
     { "Lanczos3 Stretched",	PIXMAN_KERNEL_LANCZOS3_STRETCHED },
-    { "Gaussian",		PIXMAN_KERNEL_GAUSSIAN },
+    { "Notch",			PIXMAN_KERNEL_NOTCH },
 };
 
 static const named_int_t repeats[] =
diff --git a/pixman/pixman-filter.c b/pixman/pixman-filter.c
index 253ed90..9446c55 100644
--- a/pixman/pixman-filter.c
+++ b/pixman/pixman-filter.c
@@ -53,20 +53,20 @@ typedef struct
     kernel_width_func_t	width;
 } filter_info_t;
 
-/* PIXMAN_KERNEL_IMPULSE: Returns pixel nearest the center.  This
+/* PIXMAN_KERNEL_NEAREST: Returns pixel nearest the center.  This
  * matches PIXMAN_FILTER_NEAREST. This is useful if you wish to
  * combine the result of nearest in one direction with another filter
  * in the other.
  */
 
 static double
-impulse_kernel (double x, double r)
+nearest_kernel (double x, double r)
 {
     return 1;
 }
 
 static int
-impulse_width (double r)
+nearest_width (double r)
 {
     return 1;
 }
@@ -250,17 +250,42 @@ nice_width (double r)
     return MAX (2.0, ceil (r * 8));
 }
 
+/* PIXMAN_KERNEL_TENT: Triangle of width 2r. Lots of software uses
+ * this as a "better" filter, twice the size of a box but smaller than
+ * a cubic.
+ *
+ * When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and
+ * PIXMAN_KERNEL_TENT all produce the same filter, allowing them to be
+ * exchanged at this point.
+ */
+
+static double
+tent_kernel (double x, double r)
+{
+    if (r < 1.0)
+	return box_kernel(x, r);
+    else
+	return MAX (1.0 - fabs(x / r), 0.0);
+}
+
+static int
+tent_width (double r)
+{
+    return r < 1.0 ? 2 : ceil(2 * r);
+}
+
 
 static const filter_info_t filters[] =
 {
-    { PIXMAN_KERNEL_IMPULSE,	        impulse_kernel,   impulse_width },
-    { PIXMAN_KERNEL_BOX,	        box_kernel,       box_width },
-    { PIXMAN_KERNEL_LINEAR,	        linear_kernel,    linear_width },
-    { PIXMAN_KERNEL_CUBIC,		mitchell_kernel,  cubic_width },
-    { PIXMAN_KERNEL_GAUSSIAN,	        notch_kernel,     cubic_width },
-    { PIXMAN_KERNEL_LANCZOS2,	        cubic_kernel,     cubic_width },
-    { PIXMAN_KERNEL_LANCZOS3,	        lanczos3_kernel,  lanczos3_width },
-    { PIXMAN_KERNEL_LANCZOS3_STRETCHED, nice_kernel,      nice_width },
+    { PIXMAN_KERNEL_NEAREST,		nearest_kernel,   nearest_width },
+    { PIXMAN_KERNEL_BOX,		box_kernel,       box_width },
+    { PIXMAN_KERNEL_LINEAR,		linear_kernel,    linear_width },
+    { PIXMAN_KERNEL_MITCHELL,		mitchell_kernel,  cubic_width },
+    { PIXMAN_KERNEL_NOTCH,		notch_kernel,     cubic_width },
+    { PIXMAN_KERNEL_CATMULL_ROM,	cubic_kernel,     cubic_width },
+    { PIXMAN_KERNEL_LANCZOS3,		lanczos3_kernel,  lanczos3_width },
+    { PIXMAN_KERNEL_LANCZOS3_STRETCHED,	nice_kernel,      nice_width },
+    { PIXMAN_KERNEL_TENT,		tent_kernel,	  tent_width }
 };
 
 
@@ -275,7 +300,7 @@ static void get_filter(pixman_kernel_t filter, double r,
     double step = 1.0 / n_phases;
     kernel_func_t func = filters[filter].func;
 
-    /* special-case the impulse filter: */
+    /* special-case the nearest filter: */
     if (width <= 1)
     {
 	for (i = 0; i < n_phases; ++i)
@@ -342,7 +367,7 @@ pixman_filter_create_separable_convolution (int             *n_values,
      * The old version did have a quirk that may be relied on and is
      * useful: If the reconstruct was BOX then the result was "boxy"
      * pixels, which is the result of a filter of scale < 1.  Both
-     * this and IMPULSE (which was broken) produce this effect.  If
+     * this and NEAREST (which was broken) produce this effect.  If
      * BOX reconstruct is really wanted, use LINEAR for it as it is
      * the same at scale=1.
      */
diff --git a/pixman/pixman.h b/pixman/pixman.h
index 509ba5e..61ca567 100644
--- a/pixman/pixman.h
+++ b/pixman/pixman.h
@@ -834,16 +834,23 @@ pixman_format_code_t pixman_image_get_format	     (pixman_image_t		   *image);
 
 typedef enum
 {
-    PIXMAN_KERNEL_IMPULSE,
+    PIXMAN_KERNEL_NEAREST,
     PIXMAN_KERNEL_BOX,
     PIXMAN_KERNEL_LINEAR,
-    PIXMAN_KERNEL_CUBIC,
-    PIXMAN_KERNEL_GAUSSIAN,
-    PIXMAN_KERNEL_LANCZOS2,
+    PIXMAN_KERNEL_MITCHELL,
+    PIXMAN_KERNEL_NOTCH,
+    PIXMAN_KERNEL_CATMULL_ROM,
     PIXMAN_KERNEL_LANCZOS3,
-    PIXMAN_KERNEL_LANCZOS3_STRETCHED       /* Jim Blinn's 'nice' filter */
+    PIXMAN_KERNEL_LANCZOS3_STRETCHED,	/* Jim Blinn's 'nice' filter */
+    PIXMAN_KERNEL_TENT
 } pixman_kernel_t;
 
+/* Back-compatibility enums, do not use: */
+#define PIXMAN_KERNEL_IMPULSE	PIXMAN_KERNEL_NEAREST
+#define PIXMAN_KERNEL_CUBIC	PIXMAN_KERNEL_MITCHELL
+#define PIXMAN_KERNEL_LANCZOS2	PIXMAN_KERNEL_CATMULL_ROM
+#define PIXMAN_KERNEL_GAUSSIAN	PIXMAN_KERNEL_NOTCH
+
 /* Create the parameter list for a SEPARABLE_CONVOLUTION filter
  * with the given kernels and scale parameters.
  */
-- 
1.7.9.5



More information about the Pixman mailing list