added gimp_gradient_flatten() which creates a copy of a gradient with all

2006-09-20  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpgradient.[ch]: added gimp_gradient_flatten() which
	creates a copy of a gradient with all colors that refer to FG or
	BG turned into constant colors.

	* app/core/gimpdrawable-blend.c (gradient_fill_region): create a
	flat copy of the gradient if it contains FG/BG colors. Avoids
	gazillions of context color lookups while rendering, depending on
	gradient and blend complexity.
This commit is contained in:
Michael Natterer 2006-09-19 22:17:06 +00:00 committed by Michael Natterer
parent 46fd26d0eb
commit ca6afdf530
4 changed files with 87 additions and 1 deletions

View File

@ -1,3 +1,14 @@
2006-09-20 Michael Natterer <mitch@gimp.org>
* app/core/gimpgradient.[ch]: added gimp_gradient_flatten() which
creates a copy of a gradient with all colors that refer to FG or
BG turned into constant colors.
* app/core/gimpdrawable-blend.c (gradient_fill_region): create a
flat copy of the gradient if it contains FG/BG colors. Avoids
gazillions of context color lookups while rendering, depending on
gradient and blend complexity.
2006-09-19 Sven Neumann <sven@gimp.org>
* plug-ins/pygimp/gimpfu.py: allow to pass a (domain, path) tuple

View File

@ -871,6 +871,11 @@ gradient_fill_region (GimpImage *image,
rbd.context = context;
rbd.reverse = reverse;
if (gimp_gradient_has_fg_bg_segments (rbd.gradient))
rbd.gradient = gimp_gradient_flatten (rbd.gradient, context);
else
rbd.gradient = g_object_ref (rbd.gradient);
gimp_context_get_foreground (context, &rbd.fg);
gimp_context_get_background (context, &rbd.bg);
@ -1012,6 +1017,8 @@ gradient_fill_region (GimpImage *image,
if (dither)
g_rand_free (rbd.seed);
}
g_object_unref (rbd.gradient);
}
static void

View File

@ -517,6 +517,72 @@ gimp_gradient_has_fg_bg_segments (GimpGradient *gradient)
return FALSE;
}
GimpGradient *
gimp_gradient_flatten (GimpGradient *gradient,
GimpContext *context)
{
GimpGradient *flat;
GimpGradientSegment *seg;
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
flat = GIMP_GRADIENT (gimp_data_duplicate (GIMP_DATA (gradient)));
for (seg = flat->segments; seg; seg = seg->next)
{
switch (seg->left_color_type)
{
case GIMP_GRADIENT_COLOR_FIXED:
break;
case GIMP_GRADIENT_COLOR_FOREGROUND:
case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
gimp_context_get_foreground (context, &seg->left_color);
if (seg->left_color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
gimp_rgb_set_alpha (&seg->left_color, 0.0);
break;
case GIMP_GRADIENT_COLOR_BACKGROUND:
case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
gimp_context_get_background (context, &seg->left_color);
if (seg->left_color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
gimp_rgb_set_alpha (&seg->left_color, 0.0);
break;
}
seg->left_color_type = GIMP_GRADIENT_COLOR_FIXED;
switch (seg->right_color_type)
{
case GIMP_GRADIENT_COLOR_FIXED:
break;
case GIMP_GRADIENT_COLOR_FOREGROUND:
case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
gimp_context_get_foreground (context, &seg->right_color);
if (seg->right_color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
gimp_rgb_set_alpha (&seg->right_color, 0.0);
break;
case GIMP_GRADIENT_COLOR_BACKGROUND:
case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
gimp_context_get_background (context, &seg->right_color);
if (seg->right_color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
gimp_rgb_set_alpha (&seg->right_color, 0.0);
break;
}
seg->right_color_type = GIMP_GRADIENT_COLOR_FIXED;
}
return flat;
}
/* gradient segment functions */

View File

@ -84,6 +84,8 @@ GimpGradientSegment * gimp_gradient_get_segment_at (GimpGradient *grad,
gdouble pos);
gboolean gimp_gradient_has_fg_bg_segments (GimpGradient *gradient);
GimpGradient * gimp_gradient_flatten (GimpGradient *gradient,
GimpContext *context);
/* gradient segment functions */