From ddf2dca558514f57e0de3b203cddd8bd6da2283e Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 13 May 2008 20:52:24 +0000 Subject: [PATCH] First prototype of a button in the levels tool dialog that will jump the 2008-05-13 Michael Natterer First prototype of a button in the levels tool dialog that will jump the the curves tool with the same settings: * app/gegl/gimplevelsconfig.[ch]: add new function gimp_levels_config_to_curves_config() which converts a GimpLevelsConfig to a GimpCurvesConfig. Still lacks support for gamma. * app/tools/gimplevelstool.c: add "Edit this Settings as Curves" button and jump to curves when clicked. Still ugly. svn path=/trunk/; revision=25654 --- ChangeLog | 13 +++++++++ app/gegl/gimplevelsconfig.c | 55 +++++++++++++++++++++++++++++++++++ app/gegl/gimplevelsconfig.h | 3 ++ app/tools/gimplevelstool.c | 58 +++++++++++++++++++++++++++++++++++-- 4 files changed, 126 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d62172323d..eef0275e0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-05-13 Michael Natterer + + First prototype of a button in the levels tool dialog that will + jump the the curves tool with the same settings: + + * app/gegl/gimplevelsconfig.[ch]: add new function + gimp_levels_config_to_curves_config() which converts a + GimpLevelsConfig to a GimpCurvesConfig. Still lacks support + for gamma. + + * app/tools/gimplevelstool.c: add "Edit this Settings as Curves" + button and jump to curves when clicked. Still ugly. + 2008-05-13 Sven Neumann * app/core/gimpcurve-map.c (gimp_curve_map_pixels): use memcpy() diff --git a/app/gegl/gimplevelsconfig.c b/app/gegl/gimplevelsconfig.c index 4836bf84fb..312d0ca920 100644 --- a/app/gegl/gimplevelsconfig.c +++ b/app/gegl/gimplevelsconfig.c @@ -38,6 +38,9 @@ /* temp cruft */ #include "base/levels.h" +#include "core/gimpcurve.h" + +#include "gimpcurvesconfig.h" #include "gimplevelsconfig.h" #include "gimp-intl.h" @@ -522,6 +525,58 @@ gimp_levels_config_adjust_by_colors (GimpLevelsConfig *config, g_object_thaw_notify (G_OBJECT (config)); } +GimpCurvesConfig * +gimp_levels_config_to_curves_config (GimpLevelsConfig *config) +{ + GimpCurvesConfig *curves; + GimpHistogramChannel channel; + + g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), NULL); + + curves = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); + + for (channel = GIMP_HISTOGRAM_VALUE; + channel <= GIMP_HISTOGRAM_ALPHA; + channel++) + { + GimpCurve *curve = curves->curve[channel]; + gint border_point; + gint point; + + if (config->low_input[channel] > 0.0 || + config->low_output[channel] > 0.0) + { + border_point = gimp_curve_get_closest_point (curve, 0.0); + point = gimp_curve_get_closest_point (curve, + config->low_input[channel]); + + gimp_curve_set_point (curve, point, + config->low_input[channel], + config->low_output[channel]); + + if (point != border_point) + gimp_curve_set_point (curve, border_point, -1, -1); + } + + if (config->high_input[channel] < 1.0 || + config->high_output[channel] < 1.0) + { + border_point = gimp_curve_get_closest_point (curve, 1.0); + point = gimp_curve_get_closest_point (curve, + config->high_input[channel]); + + gimp_curve_set_point (curve, point, + config->high_input[channel], + config->high_output[channel]); + + if (point != border_point) + gimp_curve_set_point (curve, border_point, -1, -1); + } + } + + return curves; +} + gboolean gimp_levels_config_load_cruft (GimpLevelsConfig *config, gpointer fp, diff --git a/app/gegl/gimplevelsconfig.h b/app/gegl/gimplevelsconfig.h index be7301995e..023b969aa9 100644 --- a/app/gegl/gimplevelsconfig.h +++ b/app/gegl/gimplevelsconfig.h @@ -73,6 +73,9 @@ void gimp_levels_config_adjust_by_colors (GimpLevelsConfig *config, const GimpRGB *gray, const GimpRGB *white); +GimpCurvesConfig * + gimp_levels_config_to_curves_config (GimpLevelsConfig *config); + gboolean gimp_levels_config_load_cruft (GimpLevelsConfig *config, gpointer fp, GError **error); diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c index 5dab7f752b..9c5b136de8 100644 --- a/app/tools/gimplevelstool.c +++ b/app/tools/gimplevelstool.c @@ -34,6 +34,9 @@ #include "gegl/gimplevelsconfig.h" #include "gegl/gimpoperationlevels.h" +#include "core/gimp.h" +#include "core/gimpcontainer.h" +#include "core/gimpcontext.h" #include "core/gimpdrawable.h" #include "core/gimpdrawable-histogram.h" #include "core/gimpimage.h" @@ -47,6 +50,7 @@ #include "gimphistogramoptions.h" #include "gimplevelstool.h" +#include "tool_manager.h" #include "gimp-intl.h" @@ -119,6 +123,9 @@ static void levels_high_output_changed (GtkAdjustment *adjustment static void levels_input_picker_toggled (GtkWidget *widget, GimpLevelsTool *tool); +static void levels_to_curves_callback (GtkWidget *widget, + GimpLevelsTool *tool); + G_DEFINE_TYPE (GimpLevelsTool, gimp_levels_tool, GIMP_TYPE_IMAGE_MAP_TOOL) @@ -620,11 +627,11 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) /* all channels frame */ frame = gimp_frame_new (_("All Channels")); - gtk_box_pack_end (GTK_BOX (image_map_tool->main_vbox), frame, - FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame, + FALSE, FALSE, 0); gtk_widget_show (frame); - hbox = gtk_hbox_new (FALSE, 0); + hbox = gtk_hbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (frame), hbox); gtk_widget_show (hbox); @@ -673,6 +680,17 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) G_CALLBACK (gimp_levels_tool_dialog_unmap), tool); + button = gtk_button_new_from_stock (GIMP_STOCK_TOOL_LEVELS); + gtk_button_set_label (GTK_BUTTON (button), + _("Edit this Settings as Curves")); + gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), button, + FALSE, FALSE, 0); + gtk_widget_show (button); + + g_signal_connect (button, "clicked", + G_CALLBACK (levels_to_curves_callback), + tool); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->channel_menu), config->channel); } @@ -1113,3 +1131,37 @@ gimp_levels_tool_color_picked (GimpColorTool *color_tool, value, tool->config->channel, color); } } + +static void +levels_to_curves_callback (GtkWidget *widget, + GimpLevelsTool *tool) +{ + GimpCurvesConfig *curves; + GimpDisplay *display; + GimpContext *user_context; + GimpToolInfo *tool_info; + GimpTool *new_tool; + + curves = gimp_levels_config_to_curves_config (tool->config); + + display = GIMP_TOOL (tool)->display; + + user_context = gimp_get_user_context (display->gimp); + + tool_info = gimp_container_get_child_by_name (display->gimp->tool_info_list, + "gimp-curves-tool"); + + g_object_ref (tool); + + gimp_context_set_tool (user_context, tool_info); + tool_manager_initialize_active (display->gimp, display); + + new_tool = tool_manager_get_active (display->gimp); + + gimp_config_copy (GIMP_CONFIG (curves), + GIMP_CONFIG (GIMP_IMAGE_MAP_TOOL (new_tool)->config), + 0); + + g_object_unref (tool); + g_object_unref (curves); +}