keep a boolean flag to identify an identity mapping. Set it to TRUE when

2008-05-11  Sven Neumann  <sven@gimp.org>

	* 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.


svn path=/trunk/; revision=25646
This commit is contained in:
Sven Neumann 2008-05-13 07:10:48 +00:00 committed by Sven Neumann
parent 80039486aa
commit 06603cb0d4
4 changed files with 50 additions and 5 deletions

View File

@ -1,3 +1,11 @@
2008-05-11 Sven Neumann <sven@gimp.org>
* 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 <simon@gimp.org>
* app/vectors/gimpvectors.[ch]

View File

@ -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;

View File

@ -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++)
{

View File

@ -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);