app, libgimpconfig: GimpFilterTool color_picked() now uses GeglColor.

In particular, the Curves, Levels and Operation tools method implemented
are updated. Also GeglColor arguments in GEGL operations are not
transformed into GimpRGB arguments anymore in GIMP. GeglColor GParamSpec
stay GeglColor now.
This commit is contained in:
Jehan 2023-12-23 23:11:43 +09:00
parent 0239d05409
commit 924dbb44a8
11 changed files with 72 additions and 138 deletions

View File

@ -24,7 +24,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "operations-types.h"
@ -370,20 +369,6 @@ gimp_operation_config_sync_node (GObject *config,
g_object_get_property (G_OBJECT (config), gimp_pspec->name,
&value);
if (GEGL_IS_PARAM_SPEC_COLOR (gegl_pspec))
{
GimpRGB gimp_color;
GeglColor *gegl_color;
gimp_value_get_rgb (&value, &gimp_color);
g_value_unset (&value);
gegl_color = gimp_gegl_color_new (&gimp_color, NULL);
g_value_init (&value, gegl_pspec->value_type);
g_value_take_object (&value, gegl_color);
}
gegl_node_set_property (node, gegl_pspec->name,
&value);
@ -529,20 +514,6 @@ gimp_operation_config_config_notify (GObject *config,
g_value_init (&value, gimp_pspec->value_type);
g_object_get_property (config, gimp_pspec->name, &value);
if (GEGL_IS_PARAM_SPEC_COLOR (gegl_pspec))
{
GimpRGB gimp_color;
GeglColor *gegl_color;
gimp_value_get_rgb (&value, &gimp_color);
g_value_unset (&value);
gegl_color = gimp_gegl_color_new (&gimp_color, NULL);
g_value_init (&value, gegl_pspec->value_type);
g_value_take_object (&value, gegl_color);
}
handler = g_signal_handler_find (node,
G_SIGNAL_MATCH_DETAIL |
G_SIGNAL_MATCH_FUNC |
@ -581,32 +552,6 @@ gimp_operation_config_node_notify (GeglNode *node,
g_value_init (&value, gegl_pspec->value_type);
gegl_node_get_property (node, gegl_pspec->name, &value);
if (GEGL_IS_PARAM_SPEC_COLOR (gegl_pspec))
{
GeglColor *gegl_color;
GimpRGB gimp_color;
gegl_color = g_value_dup_object (&value);
g_value_unset (&value);
if (gegl_color)
{
gegl_color_get_rgba (gegl_color,
&gimp_color.r,
&gimp_color.g,
&gimp_color.b,
&gimp_color.a);
g_object_unref (gegl_color);
}
else
{
gimp_rgba_set (&gimp_color, 0.0, 0.0, 0.0, 1.0);
}
g_value_init (&value, gimp_pspec->value_type);
gimp_value_set_rgb (&value, &gimp_color);
}
handler = g_signal_handler_find (config,
G_SIGNAL_MATCH_DETAIL |
G_SIGNAL_MATCH_FUNC |

View File

@ -601,31 +601,40 @@ gimp_levels_config_stretch_channel (GimpLevelsConfig *config,
}
static gdouble
gimp_levels_config_input_from_color (GimpHistogramChannel channel,
const GimpRGB *color)
gimp_levels_config_input_from_color (GimpLevelsConfig *config,
GimpHistogramChannel channel,
GeglColor *color)
{
gdouble rgba[4];
/* TODO: should I get colors within a specific space? */
if (config->trc == GIMP_TRC_LINEAR)
gegl_color_get_pixel (color, babl_format ("RGBA double"), rgba);
else
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), rgba);
switch (channel)
{
case GIMP_HISTOGRAM_VALUE:
return MAX (MAX (color->r, color->g), color->b);
return MAX (MAX (rgba[0], rgba[1]), rgba[2]);
case GIMP_HISTOGRAM_RED:
return color->r;
return rgba[0];
case GIMP_HISTOGRAM_GREEN:
return color->g;
return rgba[1];
case GIMP_HISTOGRAM_BLUE:
return color->b;
return rgba[2];
case GIMP_HISTOGRAM_ALPHA:
return color->a;
return rgba[3];
case GIMP_HISTOGRAM_RGB:
return MIN (MIN (color->r, color->g), color->b);
return MIN (MIN (rgba[0], rgba[1]), rgba[2]);
case GIMP_HISTOGRAM_LUMINANCE:
return GIMP_RGB_LUMINANCE (color->r, color->g, color->b);
return GIMP_RGB_LUMINANCE (rgba[0], rgba[1], rgba[2]);
}
return 0.0;
@ -634,9 +643,9 @@ gimp_levels_config_input_from_color (GimpHistogramChannel channel,
void
gimp_levels_config_adjust_by_colors (GimpLevelsConfig *config,
GimpHistogramChannel channel,
const GimpRGB *black,
const GimpRGB *gray,
const GimpRGB *white)
GeglColor *black,
GeglColor *gray,
GeglColor *white)
{
g_return_if_fail (GIMP_IS_LEVELS_CONFIG (config));
@ -644,16 +653,14 @@ gimp_levels_config_adjust_by_colors (GimpLevelsConfig *config,
if (black)
{
config->low_input[channel] = gimp_levels_config_input_from_color (channel,
black);
config->low_input[channel] = gimp_levels_config_input_from_color (config, channel, black);
g_object_notify (G_OBJECT (config), "low-input");
}
if (white)
{
config->high_input[channel] = gimp_levels_config_input_from_color (channel,
white);
config->high_input[channel] = gimp_levels_config_input_from_color (config, channel, white);
g_object_notify (G_OBJECT (config), "high-input");
}
@ -664,11 +671,13 @@ gimp_levels_config_adjust_by_colors (GimpLevelsConfig *config,
gdouble inten;
gdouble out_light;
gdouble lightness;
gdouble rgba[4];
/* Calculate lightness value */
lightness = GIMP_RGB_LUMINANCE (gray->r, gray->g, gray->b);
gegl_color_get_pixel (gray, babl_format ("RGBA double"), rgba);
lightness = GIMP_RGB_LUMINANCE (rgba[0], rgba[1], rgba[2]);
input = gimp_levels_config_input_from_color (channel, gray);
input = gimp_levels_config_input_from_color (config, channel, gray);
range = config->high_input[channel] - config->low_input[channel];
if (range <= 0)

View File

@ -74,9 +74,9 @@ void gimp_levels_config_stretch_channel (GimpLevelsConfig *config,
GimpHistogramChannel channel);
void gimp_levels_config_adjust_by_colors (GimpLevelsConfig *config,
GimpHistogramChannel channel,
const GimpRGB *black,
const GimpRGB *gray,
const GimpRGB *white);
GeglColor *black,
GeglColor *gray,
GeglColor *white);
GimpCurvesConfig *
gimp_levels_config_to_curves_config (GimpLevelsConfig *config);

View File

@ -362,21 +362,22 @@ gimp_prop_widget_new_from_pspec (GObject *config,
gimp_prop_gui_bind_label (widget, widget);
}
else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
{
gboolean has_alpha;
gboolean has_alpha = TRUE;
GtkWidget *button;
has_alpha = gimp_param_spec_rgb_has_alpha (pspec);
/* TODO: need an alpha argument to GeglParamSpecColor. */
/*has_alpha = gimp_param_spec_rgb_has_alpha (pspec);*/
widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
button = gimp_prop_color_button_new (config, pspec->name,
g_param_spec_get_nick (pspec),
128, 24,
has_alpha ?
GIMP_COLOR_AREA_SMALL_CHECKS :
GIMP_COLOR_AREA_FLAT);
button = gimp_prop_gegl_color_button_new (config, pspec->name,
g_param_spec_get_nick (pspec),
128, 24,
has_alpha ?
GIMP_COLOR_AREA_SMALL_CHECKS :
GIMP_COLOR_AREA_FLAT);
gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
gtk_box_pack_start (GTK_BOX (widget), button, TRUE, TRUE, 0);

View File

@ -84,7 +84,7 @@ typedef void (* GimpPickerCallback) (gpointer
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color);
GeglColor *color);
typedef void (* GimpControllerLineCallback) (gpointer data,
GeglRectangle *area,

View File

@ -99,7 +99,7 @@ static void gimp_curves_tool_color_picked (GimpFilterTool *filte
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color);
GeglColor *color);
static void gimp_curves_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog,
@ -787,28 +787,31 @@ gimp_curves_tool_color_picked (GimpFilterTool *filter_tool,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color)
GeglColor *color)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (filter_tool);
GimpCurvesConfig *config = GIMP_CURVES_CONFIG (filter_tool->config);
GimpDrawable *drawable = GIMP_TOOL (tool)->drawables->data;
GimpRGB rgb = *color;
gdouble rgb[4];
/* TODO: double-check this code. What RGB values do we want exactly? Right
* now, we use sRGB space values.
*/
if (config->trc == GIMP_TRC_LINEAR)
babl_process (babl_fish (babl_format ("R'G'B'A double"),
babl_format ("RGBA double")),
&rgb, &rgb, 1);
gegl_color_get_pixel (color, babl_format ("RGBA double"), rgb);
else
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), rgb);
tool->picked_color[GIMP_HISTOGRAM_RED] = rgb.r;
tool->picked_color[GIMP_HISTOGRAM_GREEN] = rgb.g;
tool->picked_color[GIMP_HISTOGRAM_BLUE] = rgb.b;
tool->picked_color[GIMP_HISTOGRAM_RED] = rgb[0];
tool->picked_color[GIMP_HISTOGRAM_GREEN] = rgb[1];
tool->picked_color[GIMP_HISTOGRAM_BLUE] = rgb[2];
if (gimp_drawable_has_alpha (drawable))
tool->picked_color[GIMP_HISTOGRAM_ALPHA] = rgb.a;
tool->picked_color[GIMP_HISTOGRAM_ALPHA] = rgb[3];
else
tool->picked_color[GIMP_HISTOGRAM_ALPHA] = -1;
tool->picked_color[GIMP_HISTOGRAM_VALUE] = MAX (MAX (rgb.r, rgb.g), rgb.b);
tool->picked_color[GIMP_HISTOGRAM_VALUE] = MAX (MAX (rgb[0], rgb[1]), rgb[2]);
gimp_curve_view_set_xpos (GIMP_CURVE_VIEW (tool->graph),
tool->picked_color[config->channel]);

View File

@ -862,9 +862,6 @@ gimp_filter_tool_color_picked (GimpColorTool *color_tool,
GeglColor *color)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
GimpRGB rgb;
gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL);
if (filter_tool->active_picker)
{
@ -882,7 +879,7 @@ gimp_filter_tool_color_picked (GimpColorTool *color_tool,
filter_tool->pick_identifier,
coords->x,
coords->y,
sample_format, &rgb);
sample_format, color);
return;
}
@ -892,7 +889,7 @@ gimp_filter_tool_color_picked (GimpColorTool *color_tool,
filter_tool->pick_identifier,
coords->x,
coords->y,
sample_format, &rgb);
sample_format, color);
}
static void

View File

@ -98,7 +98,7 @@ struct _GimpFilterToolClass
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color);
GeglColor *color);
};

View File

@ -95,7 +95,7 @@ static void gimp_levels_tool_color_picked (GimpFilterTool *filter_tool
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color);
GeglColor *color);
static void gimp_levels_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog,
@ -776,7 +776,7 @@ static void
levels_input_adjust_by_color (GimpLevelsConfig *config,
guint value,
GimpHistogramChannel channel,
const GimpRGB *color)
GeglColor *color)
{
switch (value & 0xF)
{
@ -800,18 +800,12 @@ gimp_levels_tool_color_picked (GimpFilterTool *color_tool,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color)
GeglColor *color)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
GimpLevelsConfig *config = GIMP_LEVELS_CONFIG (filter_tool->config);
GimpRGB rgb = *color;
guint value = GPOINTER_TO_UINT (identifier);
if (config->trc == GIMP_TRC_LINEAR)
babl_process (babl_fish (babl_format ("R'G'B'A double"),
babl_format ("RGBA double")),
&rgb, &rgb, 1);
if (value & PICK_ALL_CHANNELS &&
gimp_babl_format_get_base_type (sample_format) == GIMP_RGB)
{
@ -838,12 +832,12 @@ gimp_levels_tool_color_picked (GimpFilterTool *color_tool,
channel <= GIMP_HISTOGRAM_BLUE;
channel++)
{
levels_input_adjust_by_color (config, value, channel, &rgb);
levels_input_adjust_by_color (config, value, channel, color);
}
}
else
{
levels_input_adjust_by_color (config, value, config->channel, &rgb);
levels_input_adjust_by_color (config, value, config->channel, color);
}
}

View File

@ -90,7 +90,7 @@ static void gimp_operation_tool_color_picked (GimpFilterTool *filte
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color);
GeglColor *color);
static void gimp_operation_tool_halt (GimpOperationTool *op_tool);
static void gimp_operation_tool_commit (GimpOperationTool *op_tool);
@ -339,7 +339,7 @@ gimp_operation_tool_color_picked (GimpFilterTool *filter_tool,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color)
GeglColor *color)
{
gchar **pspecs = g_strsplit (identifier, ":", 2);
@ -495,7 +495,6 @@ gimp_operation_tool_sync_op (GimpOperationTool *op_tool,
else if (sync_colors)
{
GeglColor *color = NULL;
GimpRGB rgb;
if (HAS_KEY (pspec, "role", "color-primary"))
color = gimp_context_get_foreground (GIMP_CONTEXT (options));
@ -503,10 +502,7 @@ gimp_operation_tool_sync_op (GimpOperationTool *op_tool,
color = gimp_context_get_background (GIMP_CONTEXT (options));
if (color != NULL)
{
gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL);
g_object_set (filter_tool->config, pspec->name, &rgb, NULL);
}
g_object_set (filter_tool->config, pspec->name, color, NULL);
}
}

View File

@ -280,29 +280,18 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
}
else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
{
GeglColor *gegl_color;
GimpRGB gimp_color;
gdouble r = 0.0;
gdouble g = 0.0;
gdouble b = 0.0;
gdouble a = 1.0;
GeglColor *color;
GValue value = G_VALUE_INIT;
g_value_init (&value, GEGL_TYPE_COLOR);
g_param_value_set_default (pspec, &value);
gegl_color = g_value_get_object (&value);
if (gegl_color)
gegl_color_get_rgba (gegl_color, &r, &g, &b, &a);
gimp_rgba_set (&gimp_color, r, g, b, a);
color = g_value_dup_object (&value);
g_value_unset (&value);
copy = gimp_param_spec_rgb (name, nick, blurb,
TRUE,
&gimp_color,
flags);
copy = gegl_param_spec_color (name, nick, blurb,
/*TRUE,*/
color, flags);
g_object_unref (color);
}
else if (G_IS_PARAM_SPEC_PARAM (pspec))
{