diff --git a/ChangeLog b/ChangeLog index 2f8331bc67..84c62b8e9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-01-28 Michael Natterer + + * app/gegl/gegl-types.h + * app/gegl/Makefile.am + * app/gegl/gimpbrightnesscontrastconfig.[ch]: new config object. + + * app/tools/gimpbrightnesscontrasttool.[ch]: use it. + 2008-01-28 Sven Neumann * plug-ins/common/lcms.c (lcms_dialog): fixed crash on missing diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am index 6eb3d8067d..c3ad95e9f2 100644 --- a/app/gegl/Makefile.am +++ b/app/gegl/Makefile.am @@ -8,6 +8,8 @@ libappgegl_a_SOURCES = \ gimp-gegl-utils.c \ gimp-gegl-utils.h \ \ + gimpbrightnesscontrastconfig.c \ + gimpbrightnesscontrastconfig.h \ gimpcolorbalanceconfig.c \ gimpcolorbalanceconfig.h \ gimpcolorizeconfig.c \ diff --git a/app/gegl/gegl-types.h b/app/gegl/gegl-types.h index a6a0a41676..26804e7595 100644 --- a/app/gegl/gegl-types.h +++ b/app/gegl/gegl-types.h @@ -28,28 +28,29 @@ /* operations */ -typedef struct _GimpOperationColorBalance GimpOperationColorBalance; -typedef struct _GimpOperationColorize GimpOperationColorize; -typedef struct _GimpOperationCurves GimpOperationCurves; -typedef struct _GimpOperationDesaturate GimpOperationDesaturate; -typedef struct _GimpOperationHueSaturation GimpOperationHueSaturation; -typedef struct _GimpOperationLevels GimpOperationLevels; -typedef struct _GimpOperationPointFilter GimpOperationPointFilter; -typedef struct _GimpOperationPosterize GimpOperationPosterize; -typedef struct _GimpOperationThreshold GimpOperationThreshold; -typedef struct _GimpOperationTileSink GimpOperationTileSink; -typedef struct _GimpOperationTileSource GimpOperationTileSource; +typedef struct _GimpOperationColorBalance GimpOperationColorBalance; +typedef struct _GimpOperationColorize GimpOperationColorize; +typedef struct _GimpOperationCurves GimpOperationCurves; +typedef struct _GimpOperationDesaturate GimpOperationDesaturate; +typedef struct _GimpOperationHueSaturation GimpOperationHueSaturation; +typedef struct _GimpOperationLevels GimpOperationLevels; +typedef struct _GimpOperationPointFilter GimpOperationPointFilter; +typedef struct _GimpOperationPosterize GimpOperationPosterize; +typedef struct _GimpOperationThreshold GimpOperationThreshold; +typedef struct _GimpOperationTileSink GimpOperationTileSink; +typedef struct _GimpOperationTileSource GimpOperationTileSource; /* operation config objects */ -typedef struct _GimpColorBalanceConfig GimpColorBalanceConfig; -typedef struct _GimpColorizeConfig GimpColorizeConfig; -typedef struct _GimpCurvesConfig GimpCurvesConfig; -typedef struct _GimpHueSaturationConfig GimpHueSaturationConfig; -typedef struct _GimpLevelsConfig GimpLevelsConfig; -typedef struct _GimpPosterizeConfig GimpPosterizeConfig; -typedef struct _GimpThresholdConfig GimpThresholdConfig; +typedef struct _GimpBrightnessContrastConfig GimpBrightnessContrastConfig; +typedef struct _GimpColorBalanceConfig GimpColorBalanceConfig; +typedef struct _GimpColorizeConfig GimpColorizeConfig; +typedef struct _GimpCurvesConfig GimpCurvesConfig; +typedef struct _GimpHueSaturationConfig GimpHueSaturationConfig; +typedef struct _GimpLevelsConfig GimpLevelsConfig; +typedef struct _GimpPosterizeConfig GimpPosterizeConfig; +typedef struct _GimpThresholdConfig GimpThresholdConfig; #endif /* __GEGL_TYPES_H__ */ diff --git a/app/gegl/gimpbrightnesscontrastconfig.c b/app/gegl/gimpbrightnesscontrastconfig.c new file mode 100644 index 0000000000..8c03f7c236 --- /dev/null +++ b/app/gegl/gimpbrightnesscontrastconfig.c @@ -0,0 +1,159 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpbrightnesscontrastconfig.c + * Copyright (C) 2007 Michael Natterer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "libgimpconfig/gimpconfig.h" + +#include "gegl-types.h" + +#include "gimpbrightnesscontrastconfig.h" + + +enum +{ + PROP_0, + PROP_BRIGHTNESS, + PROP_CONTRAST +}; + + +static void gimp_brightness_contrast_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); +static void gimp_brightness_contrast_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + + +G_DEFINE_TYPE_WITH_CODE (GimpBrightnessContrastConfig, + gimp_brightness_contrast_config, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL)) + +#define parent_class gimp_brightness_contrast_config_parent_class + + +static void +gimp_brightness_contrast_config_class_init (GimpBrightnessContrastConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = gimp_brightness_contrast_config_set_property; + object_class->get_property = gimp_brightness_contrast_config_get_property; + + g_object_class_install_property (object_class, PROP_BRIGHTNESS, + g_param_spec_double ("brightness", + "Brightness", + "Brightness", + -1.0, 1.0, 0.0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, PROP_CONTRAST, + g_param_spec_double ("contrast", + "Contrast", + "Contrast", + -1.0, 1.0, 0.0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); +} + +static void +gimp_brightness_contrast_config_init (GimpBrightnessContrastConfig *self) +{ +} + +static void +gimp_brightness_contrast_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpBrightnessContrastConfig *self = GIMP_BRIGHTNESS_CONTRAST_CONFIG (object); + + switch (property_id) + { + case PROP_BRIGHTNESS: + g_value_set_double (value, self->brightness); + break; + + case PROP_CONTRAST: + g_value_set_double (value, self->contrast); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_brightness_contrast_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpBrightnessContrastConfig *self = GIMP_BRIGHTNESS_CONTRAST_CONFIG (object); + + switch (property_id) + { + case PROP_BRIGHTNESS: + self->brightness = g_value_get_double (value); + break; + + case PROP_CONTRAST: + self->contrast = g_value_get_double (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +/* public functions */ + +void +gimp_brightness_contrast_config_set_node (GimpBrightnessContrastConfig *config, + GeglNode *node) +{ + gdouble brightness; + gdouble contrast; + + g_return_if_fail (GIMP_IS_BRIGHTNESS_CONTRAST_CONFIG (config)); + g_return_if_fail (GEGL_IS_NODE (node)); + + brightness = config->brightness / 2.0; + contrast = (config->contrast < 0 ? + (config->contrast + 1.0) : + config->contrast * 4.0 + 1.0); + + gegl_node_set (node, + "brightness", brightness, + "contrast", contrast, + NULL); +} diff --git a/app/gegl/gimpbrightnesscontrastconfig.h b/app/gegl/gimpbrightnesscontrastconfig.h new file mode 100644 index 0000000000..3558915817 --- /dev/null +++ b/app/gegl/gimpbrightnesscontrastconfig.h @@ -0,0 +1,56 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpbrightnesscontrastconfig.h + * Copyright (C) 2007 Michael Natterer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_BRIGHTNESS_CONTRAST_CONFIG_H__ +#define __GIMP_BRIGHTNESS_CONTRAST_CONFIG_H__ + + +#define GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG (gimp_brightness_contrast_config_get_type ()) +#define GIMP_BRIGHTNESS_CONTRAST_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG, GimpBrightnessContrastConfig)) +#define GIMP_BRIGHTNESS_CONTRAST_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG, GimpBrightnessContrastConfigClass)) +#define GIMP_IS_BRIGHTNESS_CONTRAST_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG)) +#define GIMP_IS_BRIGHTNESS_CONTRAST_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG)) +#define GIMP_BRIGHTNESS_CONTRAST_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG, GimpBrightnessContrastConfigClass)) + + +typedef struct _GimpBrightnessContrastConfigClass GimpBrightnessContrastConfigClass; + +struct _GimpBrightnessContrastConfig +{ + GObject parent_instance; + + gdouble brightness; + gdouble contrast; +}; + +struct _GimpBrightnessContrastConfigClass +{ + GObjectClass parent_class; +}; + + +GType gimp_brightness_contrast_config_get_type (void) G_GNUC_CONST; + +void gimp_brightness_contrast_config_set_node (GimpBrightnessContrastConfig *config, + GeglNode *node); + + +#endif /* __GIMP_BRIGHTNESS_CONTRAST_CONFIG_H__ */ diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c index b413fa5551..7536273cd7 100644 --- a/app/tools/gimpbrightnesscontrasttool.c +++ b/app/tools/gimpbrightnesscontrasttool.c @@ -21,6 +21,7 @@ #include #include +#include "libgimpconfig/gimpconfig.h" #include "libgimpwidgets/gimpwidgets.h" #include "tools-types.h" @@ -28,6 +29,8 @@ #include "base/gimplut.h" #include "base/lut-funcs.h" +#include "gegl/gimpbrightnesscontrastconfig.h" + #include "core/gimpdrawable.h" #include "core/gimpimage.h" @@ -130,9 +133,7 @@ gimp_brightness_contrast_tool_init (GimpBrightnessContrastTool *bc_tool) { GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (bc_tool); - bc_tool->brightness = 0.0; - bc_tool->contrast = 0.0; - bc_tool->lut = gimp_lut_new (); + bc_tool->lut = gimp_lut_new (); im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process; im_tool->apply_data = bc_tool->lut; @@ -143,6 +144,12 @@ gimp_brightness_contrast_tool_finalize (GObject *object) { GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (object); + if (bc_tool->config) + { + g_object_unref (bc_tool->config); + bc_tool->config = NULL; + } + if (bc_tool->lut) { gimp_lut_free (bc_tool->lut); @@ -172,8 +179,7 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool, return FALSE; } - bc_tool->brightness = 0.0; - bc_tool->contrast = 0.0; + gimp_config_reset (GIMP_CONFIG (bc_tool->config)); GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); @@ -185,6 +191,10 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool, static GeglNode * gimp_brightness_contrast_tool_get_operation (GimpImageMapTool *im_tool) { + GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool); + + bc_tool->config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG, NULL); + return g_object_new (GEGL_TYPE_NODE, "operation", "brightness-contrast", NULL); @@ -194,22 +204,13 @@ static void gimp_brightness_contrast_tool_map (GimpImageMapTool *im_tool) { GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool); - gdouble brightness; - gdouble contrast; - brightness = bc_tool->brightness / 256.0; - contrast = (bc_tool->contrast < 0 ? - (bc_tool->contrast + 127.0) / 127.0 : - bc_tool->contrast * 4.0 / 127.0 + 1); - - gegl_node_set (im_tool->operation, - "brightness", brightness, - "contrast", contrast, - NULL); + gimp_brightness_contrast_config_set_node (bc_tool->config, + im_tool->operation); brightness_contrast_lut_setup (bc_tool->lut, - bc_tool->brightness / 255.0, - bc_tool->contrast / 127.0, + bc_tool->config->brightness / 2.0, + bc_tool->config->contrast, gimp_drawable_bytes (im_tool->drawable)); } @@ -223,10 +224,10 @@ gimp_brightness_contrast_tool_button_press (GimpTool *tool, { GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (tool); - bc_tool->x = coords->x - bc_tool->contrast; - bc_tool->y = coords->y + bc_tool->brightness; - bc_tool->dx = bc_tool->contrast; - bc_tool->dy = - bc_tool->brightness; + bc_tool->x = coords->x - bc_tool->config->contrast * 127.0; + bc_tool->y = coords->y + bc_tool->config->brightness * 127.0; + bc_tool->dx = bc_tool->config->contrast * 127.0; + bc_tool->dy = - bc_tool->config->brightness * 127.0; gimp_tool_control_activate (tool->control); tool->display = display; @@ -269,8 +270,8 @@ gimp_brightness_contrast_tool_motion (GimpTool *tool, bc_tool->dx = (coords->x - bc_tool->x); bc_tool->dy = - (coords->y - bc_tool->y); - bc_tool->brightness = CLAMP (bc_tool->dy, -127.0, 127.0); - bc_tool->contrast = CLAMP (bc_tool->dx, -127.0, 127.0); + bc_tool->config->brightness = CLAMP (bc_tool->dy, -127.0, 127.0) / 127.0; + bc_tool->config->contrast = CLAMP (bc_tool->dx, -127.0, 127.0) / 127.0; brightness_contrast_update_sliders (bc_tool); gimp_image_map_tool_preview (im_tool); @@ -302,7 +303,7 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *im_tool) /* Create the brightness scale widget */ data = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, _("_Brightness:"), SLIDER_WIDTH, -1, - bc_tool->brightness, + bc_tool->config->brightness * 127.0, -127.0, 127.0, 1.0, 10.0, 0, TRUE, 0.0, 0.0, NULL, NULL); @@ -317,7 +318,7 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *im_tool) /* Create the contrast scale widget */ data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1, _("Con_trast:"), SLIDER_WIDTH, -1, - bc_tool->contrast, + bc_tool->config->contrast * 127.0, -127.0, 127.0, 1.0, 10.0, 0, TRUE, 0.0, 0.0, NULL, NULL); @@ -335,8 +336,7 @@ gimp_brightness_contrast_tool_reset (GimpImageMapTool *im_tool) { GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool); - bc_tool->brightness = 0.0; - bc_tool->contrast = 0.0; + gimp_config_reset (GIMP_CONFIG (bc_tool->config)); brightness_contrast_update_sliders (bc_tool); } @@ -344,17 +344,24 @@ gimp_brightness_contrast_tool_reset (GimpImageMapTool *im_tool) static void brightness_contrast_update_sliders (GimpBrightnessContrastTool *bc_tool) { - gtk_adjustment_set_value (bc_tool->brightness_data, bc_tool->brightness); - gtk_adjustment_set_value (bc_tool->contrast_data, bc_tool->contrast); + gtk_adjustment_set_value (bc_tool->brightness_data, + bc_tool->config->brightness * 127.0); + gtk_adjustment_set_value (bc_tool->contrast_data, + bc_tool->config->contrast * 127.0); } static void brightness_contrast_brightness_changed (GtkAdjustment *adjustment, GimpBrightnessContrastTool *bc_tool) { - if (bc_tool->brightness != adjustment->value) + GimpBrightnessContrastConfig *config = bc_tool->config; + gdouble value = adjustment->value / 127.0; + + if (config->brightness != value) { - bc_tool->brightness = adjustment->value; + g_object_set (config, + "brightness", value, + NULL); gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (bc_tool)); } @@ -364,9 +371,14 @@ static void brightness_contrast_contrast_changed (GtkAdjustment *adjustment, GimpBrightnessContrastTool *bc_tool) { - if (bc_tool->contrast != adjustment->value) + GimpBrightnessContrastConfig *config = bc_tool->config; + gdouble value = adjustment->value / 127.0; + + if (config->contrast != value) { - bc_tool->contrast = adjustment->value; + g_object_set (config, + "contrast", value, + NULL); gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (bc_tool)); } diff --git a/app/tools/gimpbrightnesscontrasttool.h b/app/tools/gimpbrightnesscontrasttool.h index 7ad26f608d..a0203c4d6b 100644 --- a/app/tools/gimpbrightnesscontrasttool.h +++ b/app/tools/gimpbrightnesscontrasttool.h @@ -36,18 +36,17 @@ typedef struct _GimpBrightnessContrastToolClass GimpBrightnessContrastToolClass; struct _GimpBrightnessContrastTool { - GimpImageMapTool parent_instance; + GimpImageMapTool parent_instance; - gdouble x, y; - gdouble dx, dy; + GimpBrightnessContrastConfig *config; + GimpLut *lut; - gdouble brightness; - gdouble contrast; - GimpLut *lut; + gdouble x, y; + gdouble dx, dy; /* dialog */ - GtkAdjustment *brightness_data; - GtkAdjustment *contrast_data; + GtkAdjustment *brightness_data; + GtkAdjustment *contrast_data; }; struct _GimpBrightnessContrastToolClass