app: pass a GimpGradient to gimp_drawable_blend(), not a GimpBlendMode

The blend mode is now only a PDB compat enum, translate between
GimpBlendMode and the built-in gradients in the gimp-edit-blend PDB
wrapper.
This commit is contained in:
Michael Natterer 2014-04-30 09:17:42 +02:00
parent 626da25cf9
commit b60e1779cd
5 changed files with 60 additions and 73 deletions

View File

@ -59,9 +59,7 @@ typedef struct
#endif
gdouble offset;
gdouble sx, sy;
GimpBlendMode blend_mode;
GimpGradientType gradient_type;
GimpRGB fg, bg;
gdouble dist;
gdouble vec[2];
GimpRepeatMode repeat;
@ -145,7 +143,7 @@ static void gradient_fill_region (GimpImage *image,
GimpContext *context,
GeglBuffer *buffer,
const GeglRectangle *buffer_region,
GimpBlendMode blend_mode,
GimpGradient *gradient,
GimpGradientType gradient_type,
gdouble offset,
GimpRepeatMode repeat,
@ -166,7 +164,7 @@ static void gradient_fill_region (GimpImage *image,
void
gimp_drawable_blend (GimpDrawable *drawable,
GimpContext *context,
GimpBlendMode blend_mode,
GimpGradient *gradient,
GimpLayerModeEffects paint_mode,
GimpGradientType gradient_type,
gdouble opacity,
@ -183,13 +181,14 @@ gimp_drawable_blend (GimpDrawable *drawable,
gdouble endy,
GimpProgress *progress)
{
GimpImage *image;
GeglBuffer *buffer;
gint x, y, width, height;
GimpImage *image;
GeglBuffer *buffer;
gint x, y, width, height;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
image = gimp_item_get_image (GIMP_ITEM (drawable));
@ -205,7 +204,7 @@ gimp_drawable_blend (GimpDrawable *drawable,
gradient_fill_region (image, drawable, context,
buffer, GEGL_RECTANGLE (0, 0, width, height),
blend_mode, gradient_type, offset, repeat, reverse,
gradient, gradient_type, offset, repeat, reverse,
supersample, max_depth, threshold, dither,
(startx - x), (starty - y),
(endx - x), (endy - y),
@ -757,7 +756,7 @@ gradient_render_pixel (gdouble x,
color->r = color->g = color->b = 0;
color->a = GIMP_OPACITY_TRANSPARENT;
}
else if (rbd->blend_mode == GIMP_BLEND_CUSTOM)
else
{
#ifdef USE_GRADIENT_CACHE
*color = rbd->gradient_cache[(gint) (factor * (rbd->gradient_cache_size - 1))];
@ -766,25 +765,6 @@ gradient_render_pixel (gdouble x,
factor, rbd->reverse, color);
#endif
}
else
{
/* Blend values */
if (rbd->reverse)
factor = 1.0 - factor;
color->r = rbd->fg.r + (rbd->bg.r - rbd->fg.r) * factor;
color->g = rbd->fg.g + (rbd->bg.g - rbd->fg.g) * factor;
color->b = rbd->fg.b + (rbd->bg.b - rbd->fg.b) * factor;
color->a = rbd->fg.a + (rbd->bg.a - rbd->fg.a) * factor;
if (rbd->blend_mode == GIMP_BLEND_FG_BG_HSV)
{
GimpHSV hsv = *((GimpHSV *) color);
gimp_hsv_to_rgb (&hsv, color);
}
}
}
static void
@ -827,7 +807,7 @@ gradient_fill_region (GimpImage *image,
GimpContext *context,
GeglBuffer *buffer,
const GeglRectangle *buffer_region,
GimpBlendMode blend_mode,
GimpGradient *gradient,
GimpGradientType gradient_type,
gdouble offset,
GimpRepeatMode repeat,
@ -846,7 +826,7 @@ gradient_fill_region (GimpImage *image,
GIMP_TIMER_START();
rbd.gradient = gimp_context_get_gradient (context);
rbd.gradient = gradient;
rbd.context = context;
rbd.reverse = reverse;
@ -873,43 +853,6 @@ gradient_fill_region (GimpImage *image,
else
rbd.gradient = g_object_ref (rbd.gradient);
gimp_context_get_foreground (context, &rbd.fg);
gimp_context_get_background (context, &rbd.bg);
switch (blend_mode)
{
case GIMP_BLEND_FG_BG_RGB:
break;
case GIMP_BLEND_FG_BG_HSV:
/* Convert to HSV */
{
GimpHSV fg_hsv;
GimpHSV bg_hsv;
gimp_rgb_to_hsv (&rbd.fg, &fg_hsv);
gimp_rgb_to_hsv (&rbd.bg, &bg_hsv);
memcpy (&rbd.fg, &fg_hsv, sizeof (GimpRGB));
memcpy (&rbd.bg, &bg_hsv, sizeof (GimpRGB));
}
break;
case GIMP_BLEND_FG_TRANSPARENT:
/* Color does not change, just the opacity */
rbd.bg = rbd.fg;
rbd.bg.a = GIMP_OPACITY_TRANSPARENT;
break;
case GIMP_BLEND_CUSTOM:
break;
default:
g_assert_not_reached ();
break;
}
/* Calculate type-specific parameters */
switch (gradient_type)
@ -958,7 +901,6 @@ gradient_fill_region (GimpImage *image,
rbd.offset = offset;
rbd.sx = sx;
rbd.sy = sy;
rbd.blend_mode = blend_mode;
rbd.gradient_type = gradient_type;
rbd.repeat = repeat;

View File

@ -21,7 +21,7 @@
void gimp_drawable_blend (GimpDrawable *drawable,
GimpContext *context,
GimpBlendMode blend_mode,
GimpGradient *gradient,
GimpLayerModeEffects paint_mode,
GimpGradientType gradient_type,
gdouble opacity,

View File

@ -32,6 +32,7 @@
#include "pdb-types.h"
#include "core/gimp-edit.h"
#include "core/gimp-gradients.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpdrawable-blend.h"
@ -782,12 +783,34 @@ edit_blend_invoker (GimpProcedure *procedure,
if (success)
{
GimpGradient *gradient;
if (progress)
gimp_progress_start (progress, _("Blending"), FALSE);
switch (blend_mode)
{
case GIMP_BLEND_FG_BG_RGB:
gradient = gimp_gradients_get_fg_bg_rgb (context->gimp);
break;
case GIMP_BLEND_FG_BG_HSV:
gradient = gimp_gradients_get_fg_bg_hsv_cw (context->gimp);
break;
case GIMP_BLEND_FG_TRANSPARENT:
gradient = gimp_gradients_get_fg_transparent (context->gimp);
break;
case GIMP_BLEND_CUSTOM:
default:
gradient = gimp_context_get_gradient (context);
break;
}
gimp_drawable_blend (drawable,
context,
blend_mode,
gradient,
paint_mode,
gradient_type,
opacity / 100.0,

View File

@ -252,7 +252,7 @@ gimp_blend_tool_button_release (GimpTool *tool,
gimp_drawable_blend (drawable,
context,
GIMP_BLEND_CUSTOM,
gimp_context_get_gradient (context),
gimp_context_get_paint_mode (context),
options->gradient_type,
gimp_context_get_opacity (context),

View File

@ -838,7 +838,7 @@ HELP
);
%invoke = (
headers => [ qw("core/gimpdrawable-blend.h") ],
headers => [ qw("core/gimp-gradients.h" "core/gimpdrawable-blend.h") ],
code => <<'CODE'
{
success = (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
@ -856,12 +856,34 @@ HELP
if (success)
{
GimpGradient *gradient;
if (progress)
gimp_progress_start (progress, _("Blending"), FALSE);
switch (blend_mode)
{
case GIMP_BLEND_FG_BG_RGB:
gradient = gimp_gradients_get_fg_bg_rgb (context->gimp);
break;
case GIMP_BLEND_FG_BG_HSV:
gradient = gimp_gradients_get_fg_bg_hsv_cw (context->gimp);
break;
case GIMP_BLEND_FG_TRANSPARENT:
gradient = gimp_gradients_get_fg_transparent (context->gimp);
break;
case GIMP_BLEND_CUSTOM:
default:
gradient = gimp_context_get_gradient (context);
break;
}
gimp_drawable_blend (drawable,
context,
blend_mode,
gradient,
paint_mode,
gradient_type,
opacity / 100.0,