[gimp/gimp-2-8] app: make handling of coordinates more robust against broken input drivers



commit 0e2bce2b82eec153244aa874a1648f73be11798e
Author: Michael Natterer <mitch gimp org>
Date:   Wed Sep 5 11:29:45 2012 +0200

    app: make handling of coordinates more robust against broken input drivers
    
    Initialize the axes[] array with zeros and change pressure curve
    mapping to not try to "interpolate" shit like NaN and crash.
    (cherry picked from commit c7b9728cc8b9c5af28ac04e021246ab23d8f1eba)

 app/core/gimpcurve-map.c            |   38 +++++++++++++++++++++++++---------
 app/widgets/gimpdeviceinfo-coords.c |    2 +-
 2 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/app/core/gimpcurve-map.c b/app/core/gimpcurve-map.c
index 3d02c49..e6e0e29 100644
--- a/app/core/gimpcurve-map.c
+++ b/app/core/gimpcurve-map.c
@@ -29,6 +29,17 @@
 #include "gimpcurve-map.h"
 
 
+#if defined (HAVE_FINITE)
+#define FINITE(x) finite(x)
+#elif defined (HAVE_ISFINITE)
+#define FINITE(x) isfinite(x)
+#elif defined (G_OS_WIN32)
+#define FINITE(x) _finite(x)
+#else
+#error "no FINITE() implementation available?!"
+#endif
+
+
 enum
 {
   CURVE_NONE   = 0,
@@ -204,18 +215,17 @@ gimp_curve_map_value_inline (GimpCurve *curve,
 {
   if (curve->identity)
     {
-      return value;
-    }
+      if (FINITE (value))
+        return CLAMP (value, 0.0, 1.0);
 
-  if (value < 0.0)
-    {
-      return curve->samples[0];
-    }
-  else if (value >= 1.0)
-    {
-      return curve->samples[curve->n_samples - 1];
+      return 0.0;
     }
-  else  /* interpolate the curve */
+
+  /*  check for known values first, so broken values like NaN
+   *  delivered by broken drivers don't run into the interpolation
+   *  code
+   */
+  if (value > 0.0 && value < 1.0) /* interpolate the curve */
     {
       gdouble f;
       gint    index;
@@ -231,4 +241,12 @@ gimp_curve_map_value_inline (GimpCurve *curve,
 
       return (1.0 - f) * curve->samples[index] + f * curve->samples[index + 1];
     }
+  else if (value >= 1.0)
+    {
+      return curve->samples[curve->n_samples - 1];
+    }
+  else
+    {
+      return curve->samples[0];
+    }
 }
diff --git a/app/widgets/gimpdeviceinfo-coords.c b/app/widgets/gimpdeviceinfo-coords.c
index dfb39f6..0b72a2b 100644
--- a/app/widgets/gimpdeviceinfo-coords.c
+++ b/app/widgets/gimpdeviceinfo-coords.c
@@ -111,7 +111,7 @@ gimp_device_info_get_device_coords (GimpDeviceInfo *info,
                                     GdkWindow      *window,
                                     GimpCoords     *coords)
 {
-  gdouble axes[GDK_AXIS_LAST];
+  gdouble axes[GDK_AXIS_LAST] = { 0, };
 
   *coords = default_coords;
 



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