Commit 228dd93e authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

add gimp_image_map_tool_edit_as().

2008-05-17  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimpimagemaptool.[ch]: add gimp_image_map_tool_edit_as().

	* app/tools/gimplevelstool.c (levels_to_curves_callback): use it.

	* app/gegl/gimpbrightnesscontrastconfig.[ch]: add
	gimp_brightness_contrast_config_to_levels_config().

	* app/tools/gimpbrightnesscontrasttool.c: implement "Edit as Levels".


svn path=/trunk/; revision=25690
parent 425c734e
2008-05-17 Michael Natterer <mitch@gimp.org>
* app/tools/gimpimagemaptool.[ch]: add gimp_image_map_tool_edit_as().
* app/tools/gimplevelstool.c (levels_to_curves_callback): use it.
* app/gegl/gimpbrightnesscontrastconfig.[ch]: add
gimp_brightness_contrast_config_to_levels_config().
* app/tools/gimpbrightnesscontrasttool.c: implement "Edit as Levels".
2008-05-17 Øyvind Kolås <pippin@gimp.org>
* app/core/gimpdrawable-operation.c:
......
......@@ -23,11 +23,13 @@
#include <gegl.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
#include "gegl-types.h"
#include "gimpbrightnesscontrastconfig.h"
#include "gimplevelsconfig.h"
enum
......@@ -154,3 +156,47 @@ gimp_brightness_contrast_config_set_node (GimpBrightnessContrastConfig *config,
"contrast", contrast,
NULL);
}
GimpLevelsConfig *
gimp_brightness_contrast_config_to_levels_config (GimpBrightnessContrastConfig *config)
{
GimpLevelsConfig *levels;
gdouble brightness;
gdouble contrast;
gdouble value;
g_return_val_if_fail (GIMP_IS_BRIGHTNESS_CONTRAST_CONFIG (config), NULL);
levels = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
brightness = config->brightness / 2.0;
contrast = (config->contrast < 0 ?
(config->contrast + 1.0) :
config->contrast * 4.0 + 1.0);
value = -0.5 * contrast + brightness + 0.5;
if (value < 0.0)
{
value = 0.0;
levels->low_input[GIMP_HISTOGRAM_VALUE] =
(-0.5 - brightness) / contrast + 0.5;
}
levels->low_output[GIMP_HISTOGRAM_VALUE] = value;
value = 0.5 * contrast + brightness + 0.5;
if (value > 1.0)
{
value = 1.0;
levels->high_input[GIMP_HISTOGRAM_VALUE] =
(0.5 - brightness) / contrast + 0.5;
}
levels->high_output[GIMP_HISTOGRAM_VALUE] = value;
return levels;
}
......@@ -55,5 +55,8 @@ GType gimp_brightness_contrast_config_get_type (void) G_GNUC_CONST;
void gimp_brightness_contrast_config_set_node (GimpBrightnessContrastConfig *config,
GeglNode *node);
GimpLevelsConfig *
gimp_brightness_contrast_config_to_levels_config (GimpBrightnessContrastConfig *config);
#endif /* __GIMP_BRIGHTNESS_CONTRAST_CONFIG_H__ */
......@@ -37,6 +37,7 @@
#include "core/gimpimage.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-constructors.h"
#include "display/gimpdisplay.h"
......@@ -88,6 +89,9 @@ static void brightness_contrast_brightness_changed (GtkAdjustment
static void brightness_contrast_contrast_changed (GtkAdjustment *adj,
GimpBrightnessContrastTool *bc_tool);
static void brightness_contrast_to_levels_callback (GtkWidget *widget,
GimpBrightnessContrastTool *bc_tool);
G_DEFINE_TYPE (GimpBrightnessContrastTool, gimp_brightness_contrast_tool,
GIMP_TYPE_IMAGE_MAP_TOOL)
......@@ -292,6 +296,7 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *im_tool)
GimpBrightnessContrastConfig *config = bc_tool->config;
GtkWidget *table;
GtkWidget *slider;
GtkWidget *button;
GtkObject *data;
/* The table containing sliders */
......@@ -331,6 +336,16 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *im_tool)
g_signal_connect (data, "value-changed",
G_CALLBACK (brightness_contrast_contrast_changed),
bc_tool);
button = gimp_stock_button_new (GIMP_STOCK_TOOL_LEVELS,
_("Edit this Settings as Levels"));
gtk_box_pack_start (GTK_BOX (im_tool->main_vbox), button,
FALSE, FALSE, 0);
gtk_widget_show (button);
g_signal_connect (button, "clicked",
G_CALLBACK (brightness_contrast_to_levels_callback),
bc_tool);
}
static void
......@@ -386,3 +401,18 @@ brightness_contrast_contrast_changed (GtkAdjustment *adjustment,
NULL);
}
}
static void
brightness_contrast_to_levels_callback (GtkWidget *widget,
GimpBrightnessContrastTool *bc_tool)
{
GimpLevelsConfig *levels;
levels = gimp_brightness_contrast_config_to_levels_config (bc_tool->config);
gimp_image_map_tool_edit_as (GIMP_IMAGE_MAP_TOOL (bc_tool),
"gimp-levels-tool",
GIMP_CONFIG (levels));
g_object_unref (levels);
}
......@@ -54,6 +54,7 @@
#include "gimpcoloroptions.h"
#include "gimpimagemaptool.h"
#include "gimptoolcontrol.h"
#include "tool_manager.h"
#include "gimp-intl.h"
......@@ -1063,3 +1064,35 @@ gimp_image_map_tool_gegl_notify (GObject *config,
gimp_image_map_tool_preview (im_tool);
}
}
void
gimp_image_map_tool_edit_as (GimpImageMapTool *im_tool,
const gchar *new_tool_id,
GimpConfig *config)
{
GimpDisplay *display;
GimpContext *user_context;
GimpToolInfo *tool_info;
GimpTool *new_tool;
g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (im_tool));
g_return_if_fail (new_tool_id);
g_return_if_fail (GIMP_IS_CONFIG (config));
display = GIMP_TOOL (im_tool)->display;
user_context = gimp_get_user_context (display->gimp);
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (display->gimp->tool_info_list,
new_tool_id);
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 (config,
GIMP_CONFIG (GIMP_IMAGE_MAP_TOOL (new_tool)->config),
0);
}
......@@ -93,6 +93,9 @@ void gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool);
/* temp hack for the gegl tool */
void gimp_image_map_tool_create_map (GimpImageMapTool *image_map_tool);
void gimp_image_map_tool_edit_as (GimpImageMapTool *image_map_tool,
const gchar *new_tool_id,
GimpConfig *config);
#endif /* __GIMP_IMAGE_MAP_TOOL_H__ */
......@@ -34,9 +34,6 @@
#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"
......@@ -51,7 +48,6 @@
#include "gimphistogramoptions.h"
#include "gimplevelstool.h"
#include "tool_manager.h"
#include "gimp-intl.h"
......@@ -681,7 +677,7 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
G_CALLBACK (gimp_levels_tool_dialog_unmap),
tool);
button = gimp_stock_button_new (GIMP_STOCK_TOOL_LEVELS,
button = gimp_stock_button_new (GIMP_STOCK_TOOL_CURVES,
_("Edit this Settings as Curves"));
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), button,
FALSE, FALSE, 0);
......@@ -1137,31 +1133,12 @@ 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;
gimp_image_map_tool_edit_as (GIMP_IMAGE_MAP_TOOL (tool),
"gimp-curves-tool",
GIMP_CONFIG (curves));
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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment