[gegl/soc-2011-warp: 29/31] warp: store the lookup table as double and perform a linear interpolation when fetching a value
- From: Michael Murà <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2011-warp: 29/31] warp: store the lookup table as double and perform a linear interpolation when fetching a value
- Date: Thu, 4 Aug 2011 16:07:43 +0000 (UTC)
commit b4e557af67cae16ba0dcd5883cedbdbc78d5fee1
Author: Michael Murà <batolettre gmail com>
Date: Wed Aug 3 02:22:12 2011 +0200
warp: store the lookup table as double and perform a linear interpolation when fetching a value
operations/workshop/warp.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/operations/workshop/warp.c b/operations/workshop/warp.c
index 5afc608..876e180 100644
--- a/operations/workshop/warp.c
+++ b/operations/workshop/warp.c
@@ -51,14 +51,8 @@ static void path_changed (GeglPath *path,
gpointer userdata);
#include "gegl-chant.h"
-#ifdef HAVE_RINT
-#define RINT(x) rint(x)
-#else
-#define RINT(x) floor ((x) + 0.5)
-#endif
-
typedef struct {
- gfloat *lookup;
+ gdouble *lookup;
GeglBuffer *buffer;
gdouble last_x;
gdouble last_y;
@@ -146,7 +140,7 @@ calc_lut (GeglChantO *o)
length = ceil (0.5 * o->size + 1.0);
- priv->lookup = g_malloc (length * sizeof (gfloat));
+ priv->lookup = g_malloc (length * sizeof (gdouble));
if ((1.0 - o->hardness) < 0.0000004)
exponent = 1000000.0;
@@ -175,9 +169,21 @@ get_stamp_force (GeglChantO *o,
radius = sqrt(x*x+y*y);
if (radius < 0.5 * o->size + 1)
- return priv->lookup[(gint) RINT (radius)];
- else
- return 0.0;
+ {
+ /* linear interpolation */
+ gdouble a, ratio;
+ gdouble before, after;
+
+ a = floor (radius);
+ ratio = (radius - a);
+
+ before = priv->lookup[(gint) a];
+ after = priv->lookup[(gint) a + 1];
+
+ return ratio * before + (1.0 - ratio) * after;
+ }
+
+ return 0.0;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]