From 1a67f2b54996caf0c87890fbb9d9bbc87be581c7 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 13 May 2008 07:20:23 +0000 Subject: [PATCH] simplified the general case. 2008-05-13 Sven Neumann * app/core/gimpcurve-map.c (gimp_curve_map_value): simplified the general case. svn path=/trunk/; revision=25647 --- ChangeLog | 7 ++++++- app/core/gimpcurve-map.c | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99bb634fe8..93a8fff252 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2008-05-11 Sven Neumann +2008-05-13 Sven Neumann + + * app/core/gimpcurve-map.c (gimp_curve_map_value): simplified the + general case. + +2008-05-13 Sven Neumann * app/core/gimpcurve.[ch]: keep a boolean flag to identify an identity mapping. Set it to TRUE when the curve is reset. diff --git a/app/core/gimpcurve-map.c b/app/core/gimpcurve-map.c index 522a8c4381..c0c96206be 100644 --- a/app/core/gimpcurve-map.c +++ b/app/core/gimpcurve-map.c @@ -49,10 +49,19 @@ gimp_curve_map_value (GimpCurve *curve, } else /* interpolate the curve */ { - gint index = floor (value * (gdouble) (curve->n_samples - 1)); - gdouble f = value * (gdouble) (curve->n_samples - 1) - index; + gdouble f; + gint index; - return (1.0 - f) * curve->samples[index] + f * curve->samples[index + 1]; + /* map value to the sample space */ + value = value * (curve->n_samples - 1); + + /* determine the indices of the closest sample points */ + index = (gint) value; + + /* calculate the position between the sample points */ + f = value - index; + + return (1.0 - f) * curve->samples[index] + f * curve->samples[index + 1]; } }