app: port some of the paint and fill code to GeglColor.

This commit is contained in:
Jehan 2023-12-22 14:11:23 +09:00
parent ae31cf0b18
commit c892de85df
9 changed files with 42 additions and 68 deletions

View File

@ -527,61 +527,44 @@ gimp_enum_get_value_name (GType enum_type,
gboolean
gimp_get_fill_params (GimpContext *context,
GimpFillType fill_type,
GimpRGB *rgb,
GeglColor **color,
GimpPattern **pattern,
GError **error)
{
GeglColor *color;
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
g_return_val_if_fail (rgb != NULL, FALSE);
g_return_val_if_fail (color != NULL, FALSE);
g_return_val_if_fail (pattern != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
*color = NULL;
*pattern = NULL;
switch (fill_type)
{
case GIMP_FILL_FOREGROUND:
color = gimp_context_get_foreground (context);
gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL);
*color = gegl_color_duplicate (gimp_context_get_foreground (context));
break;
case GIMP_FILL_BACKGROUND:
color = gimp_context_get_background (context);
gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL);
*color = gegl_color_duplicate (gimp_context_get_background (context));
break;
case GIMP_FILL_CIELAB_MIDDLE_GRAY:
{
const float cielab_pixel[3] = {50, 0, 0};
float pixel[3] = {0, 0, 0};
GimpImage *image = gimp_context_get_image (context);
GimpImageBaseType base_type;
const Babl *format;
const float cielab_pixel[3] = {50.f, 0.f, 0.f};
base_type = gimp_image_get_base_type (image);
if (base_type == GIMP_INDEXED)
base_type = GIMP_RGB;
format = gimp_image_get_format (image, base_type,
GIMP_PRECISION_FLOAT_NON_LINEAR, FALSE,
gimp_image_get_layer_space (image));
babl_process (babl_fish (babl_format ("CIE Lab float"), format),
cielab_pixel, pixel, 1);
gimp_rgba_set (rgb, pixel[0], pixel[1], pixel[2], GIMP_OPACITY_OPAQUE);
*color = gegl_color_new (NULL);
gegl_color_set_pixel (*color, babl_format ("CIE Lab float"), cielab_pixel);
}
break;
case GIMP_FILL_WHITE:
gimp_rgba_set (rgb, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
*color = gegl_color_new ("white");
break;
case GIMP_FILL_TRANSPARENT:
gimp_rgba_set (rgb, 0.0, 0.0, 0.0, GIMP_OPACITY_TRANSPARENT);
*color = gegl_color_new ("transparent");
break;
case GIMP_FILL_PATTERN:
@ -593,10 +576,9 @@ gimp_get_fill_params (GimpContext *context,
_("No patterns available for this operation."));
/* fall back to BG fill */
color = gimp_context_get_background (context);
gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL);
*color = gegl_color_duplicate (gimp_context_get_background (context));
return FALSE;
return TRUE;
}
break;

View File

@ -63,7 +63,7 @@ const gchar* gimp_enum_get_value_name (GType enum_type,
gboolean gimp_get_fill_params (GimpContext *context,
GimpFillType fill_type,
GimpRGB *color,
GeglColor **color,
GimpPattern **pattern,
GError **error);

View File

@ -55,7 +55,7 @@ gimp_drawable_fill (GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type)
{
GimpRGB color;
GeglColor *color;
GimpPattern *pattern;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
@ -72,22 +72,24 @@ gimp_drawable_fill (GimpDrawable *drawable,
gimp_drawable_fill_buffer (drawable,
gimp_drawable_get_buffer (drawable),
&color, pattern, 0, 0);
color, pattern, 0, 0);
gimp_drawable_update (drawable, 0, 0, -1, -1);
g_clear_object (&color);
}
void
gimp_drawable_fill_buffer (GimpDrawable *drawable,
GeglBuffer *buffer,
const GimpRGB *color,
GeglColor *color,
GimpPattern *pattern,
gint pattern_offset_x,
gint pattern_offset_y)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GEGL_IS_BUFFER (buffer));
g_return_if_fail (color != NULL || pattern != NULL);
g_return_if_fail (GEGL_IS_COLOR (color) || pattern != NULL);
g_return_if_fail (pattern == NULL || GIMP_IS_PATTERN (pattern));
if (pattern)
@ -131,19 +133,16 @@ gimp_drawable_fill_buffer (GimpDrawable *drawable,
}
else
{
GimpRGB image_color;
GeglColor *gegl_color;
if (! gimp_drawable_has_alpha (drawable))
{
color = gegl_color_duplicate (color);
gimp_color_set_alpha (color, 1.0);
}
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
color, &image_color);
gegl_buffer_set_color (buffer, NULL, color);
if (! gimp_drawable_has_alpha (drawable))
gimp_rgb_set_alpha (&image_color, 1.0);
gegl_color = gimp_gegl_color_new (&image_color,
gimp_drawable_get_space (drawable));
gegl_buffer_set_color (buffer, NULL, gegl_color);
g_object_unref (gegl_color);
g_object_unref (color);
}
}

View File

@ -28,7 +28,7 @@ void gimp_drawable_fill (GimpDrawable *drawable,
GimpFillType fill_type);
void gimp_drawable_fill_buffer (GimpDrawable *drawable,
GeglBuffer *buffer,
const GimpRGB *color,
GeglColor *color,
GimpPattern *pattern,
gint pattern_offset_x,
gint pattern_offset_y);

View File

@ -645,12 +645,14 @@ gimp_drawable_resize (GimpItem *item,
{
/* Clear the new buffer if needed */
GimpRGB color;
GeglColor *color;
GimpPattern *pattern;
gimp_get_fill_params (context, fill_type, &color, &pattern, NULL);
gimp_drawable_fill_buffer (drawable, new_buffer,
&color, pattern, 0, 0);
if (gimp_get_fill_params (context, fill_type, &color, &pattern, NULL))
gimp_drawable_fill_buffer (drawable, new_buffer,
color, pattern, 0, 0);
g_clear_object (&color);
}
if (intersect && copy_width && copy_height)

View File

@ -579,26 +579,22 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options,
case GIMP_FILL_STYLE_FG_COLOR:
{
GeglColor *color;
GimpRGB rgb;
color = gimp_context_get_foreground (GIMP_CONTEXT (options));
gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL);
gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, color);
gimp_drawable_fill_buffer (drawable, buffer, &rgb, NULL, 0, 0);
gimp_drawable_fill_buffer (drawable, buffer, color, NULL, 0, 0);
}
break;
case GIMP_FILL_STYLE_BG_COLOR:
{
GeglColor *color;
GimpRGB rgb;
color = gimp_context_get_background (GIMP_CONTEXT (options));
gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL);
gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, color);
gimp_drawable_fill_buffer (drawable, buffer, &rgb, NULL, 0, 0);
gimp_drawable_fill_buffer (drawable, buffer, color, NULL, 0, 0);
}
break;

View File

@ -357,7 +357,7 @@ gimp_gegl_buffer_resize (GeglBuffer *buffer,
gint new_height,
gint offset_x,
gint offset_y,
GimpRGB *color,
GeglColor *color,
GimpPattern *pattern,
gint pattern_offset_x,
gint pattern_offset_y)
@ -426,11 +426,7 @@ gimp_gegl_buffer_resize (GeglBuffer *buffer,
}
else if (color)
{
GeglColor *gegl_color;
gegl_color = gimp_gegl_color_new (color, gegl_buffer_get_format (buffer));
gegl_buffer_set_color (new_buffer, NULL, gegl_color);
g_object_unref (gegl_color);
gegl_buffer_set_color (new_buffer, NULL, color);
}
}

View File

@ -62,7 +62,7 @@ GeglBuffer * gimp_gegl_buffer_resize (GeglBuffer *buff
gint new_height,
gint offset_x,
gint offset_y,
GimpRGB *color,
GeglColor *color,
GimpPattern *pattern,
gint pattern_offset_x,
gint pattern_offset_y);

View File

@ -1006,7 +1006,7 @@ gimp_paint_core_expand_drawable (GimpPaintCore *core,
if (new_width != drawable_width || *new_off_x ||
new_height != drawable_height || *new_off_y)
{
GimpRGB color;
GeglColor *color;
GimpPattern *pattern;
GimpContext *context = GIMP_CONTEXT (options);
GimpFillType fill_type = options->expand_fill_type;
@ -1084,19 +1084,18 @@ gimp_paint_core_expand_drawable (GimpPaintCore *core,
core->canvas_buffer = new_buffer;
gimp_get_fill_params (context, fill_type, &color, &pattern, NULL);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&color, &color);
if (! gimp_drawable_has_alpha (drawable))
gimp_rgb_set_alpha (&color, 1.0);
gimp_color_set_alpha (color, 1.0);
undo_buffer = g_hash_table_lookup (core->undo_buffers, drawable);
g_object_ref (undo_buffer);
new_buffer = gimp_gegl_buffer_resize (undo_buffer, new_width, new_height,
-(*new_off_x), -(*new_off_y), &color,
-(*new_off_x), -(*new_off_y), color,
pattern, 0, 0);
g_hash_table_insert (core->undo_buffers, drawable, new_buffer);
g_object_unref (undo_buffer);
g_clear_object (&color);
/* Restore context to its original state */
if (!context_has_image)