[gimp/metadata-browser] app: make handling of coordinates more robust against broken input drivers
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] app: make handling of coordinates more robust against broken input drivers
- Date: Thu, 13 Sep 2012 00:40:03 +0000 (UTC)
commit 7fbe8244226206ec414fde9d760be9ada6d2124a
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.
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 81a1c9d..b7cfce3 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 eb5ddbf..d974af2 100644
--- a/app/widgets/gimpdeviceinfo-coords.c
+++ b/app/widgets/gimpdeviceinfo-coords.c
@@ -112,7 +112,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]