diff --git a/ChangeLog b/ChangeLog index be6d84bd7d..99bb634fe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-05-11 Sven Neumann + + * app/core/gimpcurve.[ch]: keep a boolean flag to identify an + identity mapping. Set it to TRUE when the curve is reset. + + * app/core/gimpcurve-map.c (gimp_curve_map_value): optimize for + the case where the curve is an identity mapping. + 2008-05-12 Simon Budig * app/vectors/gimpvectors.[ch] diff --git a/app/core/gimpcurve-map.c b/app/core/gimpcurve-map.c index 8f1aa15c41..522a8c4381 100644 --- a/app/core/gimpcurve-map.c +++ b/app/core/gimpcurve-map.c @@ -34,6 +34,11 @@ gimp_curve_map_value (GimpCurve *curve, { g_return_val_if_fail (GIMP_IS_CURVE (curve), 0.0); + if (curve->identity) + { + return value; + } + if (value < 0.0) { return curve->samples[0]; @@ -42,7 +47,7 @@ gimp_curve_map_value (GimpCurve *curve, { return curve->samples[curve->n_samples - 1]; } - else /* interpolate the curve */ + else /* interpolate the curve */ { gint index = floor (value * (gdouble) (curve->n_samples - 1)); gdouble f = value * (gdouble) (curve->n_samples - 1) - index; diff --git a/app/core/gimpcurve.c b/app/core/gimpcurve.c index d314a93b71..9ff889762a 100644 --- a/app/core/gimpcurve.c +++ b/app/core/gimpcurve.c @@ -161,6 +161,7 @@ gimp_curve_class_init (GimpCurveClass *klass) static void gimp_curve_init (GimpCurve *curve) { + curve->identity = FALSE; } static void @@ -316,7 +317,11 @@ gimp_curve_get_description (GimpViewable *viewable, static void gimp_curve_dirty (GimpData *data) { - gimp_curve_calculate (GIMP_CURVE (data)); + GimpCurve *curve = GIMP_CURVE (data); + + curve->identity = FALSE; + + gimp_curve_calculate (curve); GIMP_DATA_CLASS (parent_class)->dirty (data); } @@ -410,6 +415,8 @@ gimp_curve_reset (GimpCurve *curve, g_object_thaw_notify (G_OBJECT (curve)); gimp_data_dirty (GIMP_DATA (curve)); + + curve->identity = TRUE; } void @@ -660,6 +667,23 @@ gimp_curve_set_curve (GimpCurve *curve, gimp_data_dirty (GIMP_DATA (curve)); } +/** + * gimp_curve_is_identity: + * @curve: a #GimpCurve object + * + * If this function returns %TRUE, then the curve maps each value to + * itself. If it returns %FALSE, then this assumption can not be made. + * + * Return value: %TRUE if the curve is an identity mapping, %FALSE otherwise. + **/ +gboolean +gimp_curve_is_identity (GimpCurve *curve) +{ + g_return_val_if_fail (GIMP_IS_CURVE (curve), FALSE); + + return curve->identity; +} + void gimp_curve_get_uchar (GimpCurve *curve, gint n_samples, @@ -684,10 +708,10 @@ gimp_curve_get_uchar (GimpCurve *curve, static void gimp_curve_calculate (GimpCurve *curve) { - gint i; gint *points; - gint num_pts; - gint p1, p2, p3, p4; + gint i; + gint num_pts; + gint p1, p2, p3, p4; if (GIMP_DATA (curve)->freeze_count > 0) return; @@ -721,6 +745,10 @@ gimp_curve_calculate (GimpCurve *curve) for (i = boundary; i < curve->n_samples; i++) curve->samples[i] = point.y; } + else + { + curve->identity = TRUE; + } for (i = 0; i < num_pts - 1; i++) { diff --git a/app/core/gimpcurve.h b/app/core/gimpcurve.h index 38b1aa8692..8fce84b68e 100644 --- a/app/core/gimpcurve.h +++ b/app/core/gimpcurve.h @@ -45,6 +45,8 @@ struct _GimpCurve gint n_samples; gdouble *samples; + + gboolean identity; /* whether the curve is an identiy mapping */ }; struct _GimpCurveClass @@ -87,6 +89,8 @@ void gimp_curve_set_curve (GimpCurve *curve, gdouble x, gdouble y); +gboolean gimp_curve_is_identity (GimpCurve *curve); + void gimp_curve_get_uchar (GimpCurve *curve, gint n_samples, guchar *samples);