app: GimpCurveView using GeglColor.

This commit is contained in:
Jehan
2023-12-22 01:17:02 +09:00
parent 20b9f9bc06
commit ae31cf0b18
4 changed files with 113 additions and 109 deletions

View File

@ -63,76 +63,75 @@
/* local function prototypes */ /* local function prototypes */
static gboolean gimp_curves_tool_initialize (GimpTool *tool, static gboolean gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *display, GimpDisplay *display,
GError **error); GError **error);
static void gimp_curves_tool_button_release (GimpTool *tool, static void gimp_curves_tool_button_release (GimpTool *tool,
const GimpCoords *coords, const GimpCoords *coords,
guint32 time, guint32 time,
GdkModifierType state, GdkModifierType state,
GimpButtonReleaseType release_type, GimpButtonReleaseType release_type,
GimpDisplay *display); GimpDisplay *display);
static gboolean gimp_curves_tool_key_press (GimpTool *tool, static gboolean gimp_curves_tool_key_press (GimpTool *tool,
GdkEventKey *kevent, GdkEventKey *kevent,
GimpDisplay *display); GimpDisplay *display);
static void gimp_curves_tool_oper_update (GimpTool *tool, static void gimp_curves_tool_oper_update (GimpTool *tool,
const GimpCoords *coords, const GimpCoords *coords,
GdkModifierType state, GdkModifierType state,
gboolean proximity, gboolean proximity,
GimpDisplay *display); GimpDisplay *display);
static gchar * gimp_curves_tool_get_operation (GimpFilterTool *filter_tool, static gchar * gimp_curves_tool_get_operation (GimpFilterTool *filter_tool,
gchar **description); gchar **description);
static void gimp_curves_tool_dialog (GimpFilterTool *filter_tool); static void gimp_curves_tool_dialog (GimpFilterTool *filter_tool);
static void gimp_curves_tool_reset (GimpFilterTool *filter_tool); static void gimp_curves_tool_reset (GimpFilterTool *filter_tool);
static void gimp_curves_tool_config_notify (GimpFilterTool *filter_tool, static void gimp_curves_tool_config_notify (GimpFilterTool *filter_tool,
GimpConfig *config, GimpConfig *config,
const GParamSpec *pspec); const GParamSpec *pspec);
static gboolean gimp_curves_tool_settings_import (GimpFilterTool *filter_tool, static gboolean gimp_curves_tool_settings_import (GimpFilterTool *filter_tool,
GInputStream *input, GInputStream *input,
GError **error); GError **error);
static gboolean gimp_curves_tool_settings_export (GimpFilterTool *filter_tool, static gboolean gimp_curves_tool_settings_export (GimpFilterTool *filter_tool,
GOutputStream *output, GOutputStream *output,
GError **error); GError **error);
static void gimp_curves_tool_color_picked (GimpFilterTool *filter_tool, static void gimp_curves_tool_color_picked (GimpFilterTool *filter_tool,
gpointer identifier, gpointer identifier,
gdouble x, gdouble x,
gdouble y, gdouble y,
const Babl *sample_format, const Babl *sample_format,
const GimpRGB *color); const GimpRGB *color);
static void gimp_curves_tool_export_setup (GimpSettingsBox *settings_box, static void gimp_curves_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog, GtkFileChooserDialog *dialog,
gboolean export, gboolean export,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static void gimp_curves_tool_update_channel (GimpCurvesTool *tool); static void gimp_curves_tool_update_channel (GimpCurvesTool *tool);
static void gimp_curves_tool_update_point (GimpCurvesTool *tool); static void gimp_curves_tool_update_point (GimpCurvesTool *tool);
static void curves_curve_dirty_callback (GimpCurve *curve, static void curves_curve_dirty_callback (GimpCurve *curve,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static void curves_channel_callback (GtkWidget *widget, static void curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static void curves_channel_reset_callback (GtkWidget *widget, static void curves_channel_reset_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static gboolean curves_menu_sensitivity (gint value, static gboolean curves_menu_sensitivity (gint value,
gpointer data); gpointer data);
static void curves_graph_selection_callback (GtkWidget *widget, static void curves_graph_selection_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static void curves_point_coords_callback (GtkWidget *widget, static void curves_point_coords_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static void curves_point_type_callback (GtkWidget *widget, static void curves_point_type_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static void curves_curve_type_callback (GtkWidget *widget, static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static gboolean curves_get_channel_color (GtkWidget *widget, static GeglColor * curves_get_channel_color (GtkWidget *widget,
GimpHistogramChannel channel, GimpHistogramChannel channel);
GimpRGB *color);
G_DEFINE_TYPE (GimpCurvesTool, gimp_curves_tool, GIMP_TYPE_FILTER_TOOL) G_DEFINE_TYPE (GimpCurvesTool, gimp_curves_tool, GIMP_TYPE_FILTER_TOOL)
@ -893,22 +892,17 @@ gimp_curves_tool_update_channel (GimpCurvesTool *tool)
channel <= GIMP_HISTOGRAM_ALPHA; channel <= GIMP_HISTOGRAM_ALPHA;
channel++) channel++)
{ {
GimpRGB curve_color; GeglColor *curve_color;
gboolean has_color;
has_color = curves_get_channel_color (tool->graph, channel, &curve_color); curve_color = curves_get_channel_color (tool->graph, channel);
if (channel == config->channel) if (channel == config->channel)
{ gimp_curve_view_set_curve (GIMP_CURVE_VIEW (tool->graph), curve, curve_color);
gimp_curve_view_set_curve (GIMP_CURVE_VIEW (tool->graph), curve,
has_color ? &curve_color : NULL);
}
else else
{ gimp_curve_view_add_background (GIMP_CURVE_VIEW (tool->graph),
gimp_curve_view_add_background (GIMP_CURVE_VIEW (tool->graph), config->curve[channel], curve_color);
config->curve[channel],
has_color ? &curve_color : NULL); g_clear_object (&curve_color);
}
} }
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->curve_type), gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->curve_type),
@ -1126,12 +1120,11 @@ curves_curve_type_callback (GtkWidget *widget,
} }
} }
static gboolean static GeglColor *
curves_get_channel_color (GtkWidget *widget, curves_get_channel_color (GtkWidget *widget,
GimpHistogramChannel channel, GimpHistogramChannel channel)
GimpRGB *color)
{ {
static const GimpRGB channel_colors[GIMP_HISTOGRAM_RGB] = static const gdouble channel_colors[GIMP_HISTOGRAM_RGB][4] =
{ {
{ 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 },
{ 1.0, 0.0, 0.0, 1.0 }, { 1.0, 0.0, 0.0, 1.0 },
@ -1140,34 +1133,36 @@ curves_get_channel_color (GtkWidget *widget,
{ 0.5, 0.5, 0.5, 1.0 } { 0.5, 0.5, 0.5, 1.0 }
}; };
GdkRGBA rgba; GeglColor *color;
GdkRGBA rgba;
if (channel == GIMP_HISTOGRAM_VALUE) if (channel == GIMP_HISTOGRAM_VALUE)
return FALSE; return NULL;
color = gegl_color_new (NULL);
if (channel == GIMP_HISTOGRAM_ALPHA) if (channel == GIMP_HISTOGRAM_ALPHA)
{ {
GtkStyleContext *style = gtk_widget_get_style_context (widget); GtkStyleContext *style = gtk_widget_get_style_context (widget);
gdouble lum; gdouble lum;
gdouble rgb[4];
gtk_style_context_get_color (style, gtk_style_context_get_state (style), gtk_style_context_get_color (style, gtk_style_context_get_state (style),
&rgba); &rgba);
lum = GIMP_RGB_LUMINANCE (rgba.red, rgba.green, rgba.blue); lum = GIMP_RGB_LUMINANCE (rgba.red, rgba.green, rgba.blue);
rgb[3] = 1.0;
if (lum > 0.5) if (lum > 0.5)
{ rgb[0] = rgb[1] = rgb[2] = lum - 0.3;
gimp_rgba_set (color, lum - 0.3, lum - 0.3, lum - 0.3, 1.0);
}
else else
{ rgb[0] = rgb[1] = rgb[2] = lum + 0.3;
gimp_rgba_set (color, lum + 0.3, lum + 0.3, lum + 0.3, 1.0);
}
return TRUE; gegl_color_set_pixel (color, babl_format ("R'G'B'A"), rgb);
return color;
} }
*color = channel_colors[channel]; gegl_color_set_pixel (color, babl_format ("R'G'B'A"), channel_colors[channel]);
return TRUE; return color;
} }

View File

@ -31,6 +31,8 @@
#include "widgets-types.h" #include "widgets-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimpcurve.h" #include "core/gimpcurve.h"
#include "core/gimpcurve-map.h" #include "core/gimpcurve-map.h"
@ -67,7 +69,7 @@ enum
typedef struct typedef struct
{ {
GimpCurve *curve; GimpCurve *curve;
GimpRGB color; GeglColor *color;
gboolean color_set; gboolean color_set;
} BGCurve; } BGCurve;
@ -609,11 +611,11 @@ gimp_curve_view_draw (GtkWidget *widget,
if (bg->color_set) if (bg->color_set)
{ {
cairo_set_source_rgba (cr, GeglColor *color = gegl_color_duplicate (bg->color);
bg->color.r,
bg->color.g, gimp_color_set_alpha (color, 0.5);
bg->color.b, gimp_cairo_set_source_color (cr, color, view->gimp->config->color_management, FALSE, widget);
0.5); g_object_unref (color);
} }
else else
{ {
@ -630,7 +632,7 @@ gimp_curve_view_draw (GtkWidget *widget,
/* Draw the curve */ /* Draw the curve */
if (view->curve_color) if (view->curve_color)
gimp_cairo_set_source_rgb (cr, view->curve_color); gimp_cairo_set_source_color (cr, view->curve_color, view->gimp->config->color_management, FALSE, widget);
else else
gdk_cairo_set_source_rgba (cr, &fg_color); gdk_cairo_set_source_rgba (cr, &fg_color);
@ -1278,7 +1280,7 @@ gimp_curve_view_new (void)
void void
gimp_curve_view_set_curve (GimpCurveView *view, gimp_curve_view_set_curve (GimpCurveView *view,
GimpCurve *curve, GimpCurve *curve,
const GimpRGB *color) GeglColor *color)
{ {
g_return_if_fail (GIMP_IS_CURVE_VIEW (view)); g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
g_return_if_fail (curve == NULL || GIMP_IS_CURVE (curve)); g_return_if_fail (curve == NULL || GIMP_IS_CURVE (curve));
@ -1310,11 +1312,9 @@ gimp_curve_view_set_curve (GimpCurveView *view,
view); view);
} }
if (view->curve_color) g_clear_object (&view->curve_color);
g_free (view->curve_color);
if (color) if (color)
view->curve_color = g_memdup2 (color, sizeof (GimpRGB)); view->curve_color = gegl_color_duplicate (color);
else else
view->curve_color = NULL; view->curve_color = NULL;
@ -1334,7 +1334,7 @@ gimp_curve_view_get_curve (GimpCurveView *view)
void void
gimp_curve_view_add_background (GimpCurveView *view, gimp_curve_view_add_background (GimpCurveView *view,
GimpCurve *curve, GimpCurve *curve,
const GimpRGB *color) GeglColor *color)
{ {
GList *list; GList *list;
BGCurve *bg; BGCurve *bg;
@ -1355,7 +1355,7 @@ gimp_curve_view_add_background (GimpCurveView *view,
if (color) if (color)
{ {
bg->color = *color; bg->color = gegl_color_duplicate (color);
bg->color_set = TRUE; bg->color_set = TRUE;
} }
@ -1386,6 +1386,7 @@ gimp_curve_view_remove_background (GimpCurveView *view,
g_signal_handlers_disconnect_by_func (bg->curve, g_signal_handlers_disconnect_by_func (bg->curve,
gimp_curve_view_curve_dirty, gimp_curve_view_curve_dirty,
view); view);
g_clear_object (&bg->color);
g_object_unref (bg->curve); g_object_unref (bg->curve);
view->bg_curves = g_list_remove (view->bg_curves, bg); view->bg_curves = g_list_remove (view->bg_curves, bg);
@ -1414,6 +1415,7 @@ gimp_curve_view_remove_all_backgrounds (GimpCurveView *view)
g_signal_handlers_disconnect_by_func (bg->curve, g_signal_handlers_disconnect_by_func (bg->curve,
gimp_curve_view_curve_dirty, gimp_curve_view_curve_dirty,
view); view);
g_clear_object (&bg->color);
g_object_unref (bg->curve); g_object_unref (bg->curve);
view->bg_curves = g_list_remove (view->bg_curves, bg); view->bg_curves = g_list_remove (view->bg_curves, bg);

View File

@ -39,7 +39,7 @@ struct _GimpCurveView
Gimp *gimp; /* only needed for copy & paste */ Gimp *gimp; /* only needed for copy & paste */
GimpCurve *curve; GimpCurve *curve;
GimpRGB *curve_color; GeglColor *curve_color;
GList *bg_curves; GList *bg_curves;
@ -97,12 +97,12 @@ GtkWidget * gimp_curve_view_new (void);
void gimp_curve_view_set_curve (GimpCurveView *view, void gimp_curve_view_set_curve (GimpCurveView *view,
GimpCurve *curve, GimpCurve *curve,
const GimpRGB *color); GeglColor *color);
GimpCurve * gimp_curve_view_get_curve (GimpCurveView *view); GimpCurve * gimp_curve_view_get_curve (GimpCurveView *view);
void gimp_curve_view_add_background (GimpCurveView *view, void gimp_curve_view_add_background (GimpCurveView *view,
GimpCurve *curve, GimpCurve *curve,
const GimpRGB *color); GeglColor *color);
void gimp_curve_view_remove_background (GimpCurveView *view, void gimp_curve_view_remove_background (GimpCurveView *view,
GimpCurve *curve); GimpCurve *curve);

View File

@ -63,7 +63,7 @@ struct
const gchar *use_property; const gchar *use_property;
const gchar *curve_property; const gchar *curve_property;
const gchar *label; const gchar *label;
const GimpRGB color; const gdouble color[4];
} }
inputs[] = inputs[] =
{ {
@ -76,7 +76,7 @@ inputs[] =
{ "use-fade", "fade-curve", N_("Fade"), { 0.5, 0.5, 0.5, 0.0 } } { "use-fade", "fade-curve", N_("Fade"), { 0.5, 0.5, 0.5, 0.0 } }
}; };
#define INPUT_COLOR(i) (inputs[(i)].color.a ? &inputs[(i)].color : NULL) #define INPUT_COLOR(i) (inputs[(i)].color[3] ? &inputs[(i)].color : NULL)
typedef struct _GimpDynamicsOutputEditorPrivate GimpDynamicsOutputEditorPrivate; typedef struct _GimpDynamicsOutputEditorPrivate GimpDynamicsOutputEditorPrivate;
@ -408,16 +408,18 @@ gimp_dynamics_output_editor_activate_input (GimpDynamicsOutputEditor *editor,
{ {
gboolean use_input; gboolean use_input;
GimpCurve *input_curve; GimpCurve *input_curve;
GeglColor *color = gegl_color_new (NULL);
g_object_get (private->output, g_object_get (private->output,
inputs[i].use_property, &use_input, inputs[i].use_property, &use_input,
inputs[i].curve_property, &input_curve, inputs[i].curve_property, &input_curve,
NULL); NULL);
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), INPUT_COLOR (i));
if (input == i) if (input == i)
{ {
gimp_curve_view_set_curve (GIMP_CURVE_VIEW (private->curve_view), gimp_curve_view_set_curve (GIMP_CURVE_VIEW (private->curve_view),
input_curve, INPUT_COLOR (i)); input_curve, color);
private->active_curve = input_curve; private->active_curve = input_curve;
gimp_curve_view_set_x_axis_label (GIMP_CURVE_VIEW (private->curve_view), gimp_curve_view_set_x_axis_label (GIMP_CURVE_VIEW (private->curve_view),
@ -426,10 +428,11 @@ gimp_dynamics_output_editor_activate_input (GimpDynamicsOutputEditor *editor,
else if (use_input) else if (use_input)
{ {
gimp_curve_view_add_background (GIMP_CURVE_VIEW (private->curve_view), gimp_curve_view_add_background (GIMP_CURVE_VIEW (private->curve_view),
input_curve, INPUT_COLOR (i)); input_curve, color);
} }
g_object_unref (input_curve); g_object_unref (input_curve);
g_object_unref (color);
} }
} }
@ -465,8 +468,12 @@ gimp_dynamics_output_editor_notify_output (GimpDynamicsOutput *output,
{ {
if (use_input) if (use_input)
{ {
GeglColor *color = gegl_color_new (NULL);
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), INPUT_COLOR (i));
gimp_curve_view_add_background (GIMP_CURVE_VIEW (private->curve_view), gimp_curve_view_add_background (GIMP_CURVE_VIEW (private->curve_view),
input_curve, INPUT_COLOR (i)); input_curve, color);
g_object_unref (color);
} }
else else
{ {