[gegl] matrix.c: use the same clamping in matrix3_transform_point as in transform_generic



commit ef629c62b553df527e57e7fa54caa4e7db6e0e3c
Author: Nicolas Robidoux <nrobidoux git gnome org>
Date:   Sun Dec 16 20:12:29 2012 -0500

    matrix.c: use the same clamping in matrix3_transform_point as in transform_generic

 gegl/gegl-matrix.c                    |   18 ++++++++++++++----
 operations/transform/transform-core.c |    9 ++++-----
 2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/gegl/gegl-matrix.c b/gegl/gegl-matrix.c
index 4355313..d06460a 100644
--- a/gegl/gegl-matrix.c
+++ b/gegl/gegl-matrix.c
@@ -211,16 +211,26 @@ gegl_matrix3_originate (GeglMatrix3 *matrix,
 }
 
 void
-gegl_matrix3_transform_point (GeglMatrix3  *matrix,
+gegl_matrix3_transform_point (GeglMatrix3 *matrix,
                               gdouble     *x,
                               gdouble     *y)
 {
-  gdouble xp, yp, w;
+  gdouble xp, yp, w, cw;
   
   w = (*x * matrix->coeff [2][0] + *y * matrix->coeff [2][1] + matrix->coeff [2][2]);
 
-  xp = (*x * matrix->coeff [0][0] + *y * matrix->coeff [0][1] + matrix->coeff [0][2]) /w;
-  yp = (*x * matrix->coeff [1][0] + *y * matrix->coeff [1][1] + matrix->coeff [1][2]) /w;
+/*
+ * Attempt at making near degenerate cases be handled somewhat
+ * gracefully: Set a floor, above 0, for w.
+ */
+#define PERSPECTIVE_TRANSFORM_EPSILON ((gdouble) 1.e-6)
+#define CLAMP_PERSPECTIVE_TRANSFORM(w) \
+  ( (w) > PERSPECTIVE_TRANSFORM_EPSILON ? (w) : PERSPECTIVE_TRANSFORM_EPSILON )
+
+  cw = CLAMP_PERSPECTIVE_TRANSFORM(w);
+
+  xp = (*x * matrix->coeff [0][0] + *y * matrix->coeff [0][1] + matrix->coeff [0][2]) / cw;
+  yp = (*x * matrix->coeff [1][0] + *y * matrix->coeff [1][1] + matrix->coeff [1][2]) / cw;
 
   *x = xp;
   *y = yp;
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index 184e210..137e991 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -1074,15 +1074,14 @@ transform_generic (GeglBuffer  *dest,
       v_start = inverse.coeff [1][0] * (roi->x + (gdouble) 0.5)  +
                 inverse.coeff [1][1] * (roi->y + (gdouble) 0.5)  +
                 inverse.coeff [1][2];
-
       w_start = inverse.coeff [2][0] * (roi->x + (gdouble) 0.5)  +
                 inverse.coeff [2][1] * (roi->y + (gdouble) 0.5)  +
                 inverse.coeff [2][2];
 
-      /*
-       * Attempt at making degenerate cases be handled somewhat
-       * gracefully: Set a floor, above 0, for w.
-       */
+/*
+ * Attempt at making near degenerate cases be handled somewhat
+ * gracefully: Set a floor, above 0, for w.
+ */
 #define PERSPECTIVE_TRANSFORM_EPSILON ((gdouble) 1.e-6)
 #define CLAMP_PERSPECTIVE_TRANSFORM(w) \
   ( (w) > PERSPECTIVE_TRANSFORM_EPSILON ? (w) : PERSPECTIVE_TRANSFORM_EPSILON )



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]