diff --git a/ChangeLog b/ChangeLog index bb55fa15dd..413fb959aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-01-22 Michael Natterer + + * app/gegl/Makefile.am + * app/gegl/gegl-types.h + * app/gegl/gimphuesaturationconfig.[ch]: new config object. + + * app/gegl/gimpoperationhuesaturation.[ch]: remove all properties + and add a "config" property. Also add API to map a single GimpRGB + needed by the hue-saturation tool's color areas. + + * app/tools/gimphuesaturationtool.[ch]: switch to using + GimpHueSaturationConfig, use the old HueSaturation struct only in + map(). + + * app/base/hue-saturation.[ch]: remove API that's no longer needed. + 2008-01-22 Øyvind Kolås * app/gegl/gimpoperationcolorbalance.h: diff --git a/app/base/hue-saturation.c b/app/base/hue-saturation.c index bf07346628..a6918524da 100644 --- a/app/base/hue-saturation.c +++ b/app/base/hue-saturation.c @@ -37,19 +37,13 @@ hue_saturation_init (HueSaturation *hs) g_return_if_fail (hs != NULL); hs->overlap = 0.0; + for (partition = GIMP_ALL_HUES; partition <= GIMP_MAGENTA_HUES; partition++) - hue_saturation_partition_reset (hs, partition); -} - -void -hue_saturation_partition_reset (HueSaturation *hs, - GimpHueRange partition) -{ - g_return_if_fail (hs != NULL); - - hs->hue[partition] = 0.0; - hs->lightness[partition] = 0.0; - hs->saturation[partition] = 0.0; + { + hs->hue[partition] = 0.0; + hs->lightness[partition] = 0.0; + hs->saturation[partition] = 0.0; + } } void @@ -65,6 +59,7 @@ hue_saturation_calculate_transfers (HueSaturation *hs) for (hue = 0; hue < 6; hue++) for (i = 0; i < 256; i++) { + /* Hue */ value = (hs->hue[0] + hs->hue[hue + 1]) * 255.0 / 360.0; if ((i + value) < 0) hs->hue_transfer[hue][i] = 255 + (i + value); diff --git a/app/base/hue-saturation.h b/app/base/hue-saturation.h index ce88d37323..da56931989 100644 --- a/app/base/hue-saturation.h +++ b/app/base/hue-saturation.h @@ -34,8 +34,6 @@ struct _HueSaturation void hue_saturation_init (HueSaturation *hs); -void hue_saturation_partition_reset (HueSaturation *hs, - GimpHueRange partition); void hue_saturation_calculate_transfers (HueSaturation *hs); void hue_saturation (HueSaturation *hs, PixelRegion *srcPR, diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am index 6bcbd52370..87f1dc2334 100644 --- a/app/gegl/Makefile.am +++ b/app/gegl/Makefile.am @@ -10,6 +10,8 @@ libappgegl_a_SOURCES = \ \ gimpcolorizeconfig.c \ gimpcolorizeconfig.h \ + gimphuesaturationconfig.c \ + gimphuesaturationconfig.h \ gimplevelsconfig.c \ gimplevelsconfig.h \ \ diff --git a/app/gegl/gegl-types.h b/app/gegl/gegl-types.h index 55fb951248..355c848f68 100644 --- a/app/gegl/gegl-types.h +++ b/app/gegl/gegl-types.h @@ -42,6 +42,7 @@ typedef struct _GimpOperationTileSource GimpOperationTileSource; /* operation config objects */ typedef struct _GimpColorizeConfig GimpColorizeConfig; +typedef struct _GimpHueSaturationConfig GimpHueSaturationConfig; typedef struct _GimpLevelsConfig GimpLevelsConfig; diff --git a/app/gegl/gimphuesaturationconfig.c b/app/gegl/gimphuesaturationconfig.c new file mode 100644 index 0000000000..8a31092bf1 --- /dev/null +++ b/app/gegl/gimphuesaturationconfig.c @@ -0,0 +1,240 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimphuesaturationconfig.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 "gegl-types.h" + +/* temp cruft */ +#include "base/hue-saturation.h" + +#include "gimphuesaturationconfig.h" + + +enum +{ + PROP_0, + PROP_RANGE, + PROP_HUE, + PROP_SATURATION, + PROP_LIGHTNESS, + PROP_OVERLAP +}; + + +static void gimp_hue_saturation_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); +static void gimp_hue_saturation_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + + +G_DEFINE_TYPE (GimpHueSaturationConfig, gimp_hue_saturation_config, + G_TYPE_OBJECT) + +#define parent_class gimp_hue_saturation_config_parent_class + + +static void +gimp_hue_saturation_config_class_init (GimpHueSaturationConfigClass * klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = gimp_hue_saturation_config_set_property; + object_class->get_property = gimp_hue_saturation_config_get_property; + + g_object_class_install_property (object_class, PROP_RANGE, + g_param_spec_enum ("range", + "range", + "The affected range", + GIMP_TYPE_HUE_RANGE, + GIMP_ALL_HUES, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, PROP_HUE, + g_param_spec_double ("hue", + "Hue", + "Hue", + -1.0, 1.0, 0.0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, PROP_SATURATION, + g_param_spec_double ("saturation", + "Saturation", + "Saturation", + -1.0, 1.0, 0.0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, PROP_LIGHTNESS, + g_param_spec_double ("lightness", + "Lightness", + "Lightness", + -1.0, 1.0, 0.0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, PROP_OVERLAP, + g_param_spec_double ("overlap", + "Overlap", + "Overlap", + 0.0, 1.0, 0.0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); +} + +static void +gimp_hue_saturation_config_init (GimpHueSaturationConfig *self) +{ + gimp_hue_saturation_config_reset (self); +} + +static void +gimp_hue_saturation_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpHueSaturationConfig *self = GIMP_HUE_SATURATION_CONFIG (object); + + switch (property_id) + { + case PROP_RANGE: + g_value_set_enum (value, self->range); + break; + + case PROP_HUE: + g_value_set_double (value, self->hue[self->range]); + break; + + case PROP_SATURATION: + g_value_set_double (value, self->saturation[self->range]); + break; + + case PROP_LIGHTNESS: + g_value_set_double (value, self->lightness[self->range]); + break; + + case PROP_OVERLAP: + g_value_set_double (value, self->overlap); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_hue_saturation_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpHueSaturationConfig *self = GIMP_HUE_SATURATION_CONFIG (object); + + switch (property_id) + { + case PROP_RANGE: + self->range = g_value_get_enum (value); + break; + + case PROP_HUE: + self->hue[self->range] = g_value_get_double (value); + break; + + case PROP_SATURATION: + self->saturation[self->range] = g_value_get_double (value); + break; + + case PROP_LIGHTNESS: + self->lightness[self->range] = g_value_get_double (value); + break; + + case PROP_OVERLAP: + self->overlap = g_value_get_double (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +/* public functions */ + +void +gimp_hue_saturation_config_reset (GimpHueSaturationConfig *config) +{ + GimpHueRange range; + + g_return_if_fail (GIMP_IS_HUE_SATURATION_CONFIG (config)); + + config->range = GIMP_ALL_HUES; + + for (range = GIMP_ALL_HUES; range <= GIMP_MAGENTA_HUES; range++) + { + gimp_hue_saturation_config_reset_range (config, range); + } + + config->overlap = 0.0; +} + +void +gimp_hue_saturation_config_reset_range (GimpHueSaturationConfig *config, + GimpHueRange range) +{ + g_return_if_fail (GIMP_IS_HUE_SATURATION_CONFIG (config)); + + config->hue[range] = 0.0; + config->saturation[range] = 0.0; + config->lightness[range] = 0.0; +} + + +/* temp cruft */ + +void +gimp_hue_saturation_config_to_cruft (GimpHueSaturationConfig *config, + HueSaturation *hs) +{ + GimpHueRange range; + + g_return_if_fail (GIMP_IS_HUE_SATURATION_CONFIG (config)); + g_return_if_fail (hs != NULL); + + for (range = GIMP_ALL_HUES; range <= GIMP_MAGENTA_HUES; range++) + { + hs->hue[range] = config->hue[range] * 180; + hs->saturation[range] = config->saturation[range] * 100; + hs->lightness[range] = config->lightness[range] * 100; + } + + hs->overlap = config->overlap * 100; +} diff --git a/app/gegl/gimphuesaturationconfig.h b/app/gegl/gimphuesaturationconfig.h new file mode 100644 index 0000000000..466cc9c2ab --- /dev/null +++ b/app/gegl/gimphuesaturationconfig.h @@ -0,0 +1,66 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimphuesaturationconfig.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_HUE_SATURATION_CONFIG_H__ +#define __GIMP_HUE_SATURATION_CONFIG_H__ + + +#define GIMP_TYPE_HUE_SATURATION_CONFIG (gimp_hue_saturation_config_get_type ()) +#define GIMP_HUE_SATURATION_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HUE_SATURATION_CONFIG, GimpHueSaturationConfig)) +#define GIMP_HUE_SATURATION_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_HUE_SATURATION_CONFIG, GimpHueSaturationConfigClass)) +#define GIMP_IS_HUE_SATURATION_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HUE_SATURATION_CONFIG)) +#define GIMP_IS_HUE_SATURATION_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_HUE_SATURATION_CONFIG)) +#define GIMP_HUE_SATURATION_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HUE_SATURATION_CONFIG, GimpHueSaturationConfigClass)) + + +typedef struct _GimpHueSaturationConfigClass GimpHueSaturationConfigClass; + +struct _GimpHueSaturationConfig +{ + GObject parent_instance; + + GimpHueRange range; + + gdouble hue[7]; + gdouble saturation[7]; + gdouble lightness[7]; + + gdouble overlap; +}; + +struct _GimpHueSaturationConfigClass +{ + GObjectClass parent_class; +}; + + +GType gimp_hue_saturation_config_get_type (void) G_GNUC_CONST; + +void gimp_hue_saturation_config_reset (GimpHueSaturationConfig *config); +void gimp_hue_saturation_config_reset_range (GimpHueSaturationConfig *config, + GimpHueRange range); + +/* temp cruft */ +void gimp_hue_saturation_config_to_cruft (GimpHueSaturationConfig *config, + HueSaturation *hs); + + +#endif /* __GIMP_HUE_SATURATION_CONFIG_H__ */ diff --git a/app/gegl/gimpoperationhuesaturation.c b/app/gegl/gimpoperationhuesaturation.c index 706b2c40a5..02f352348c 100644 --- a/app/gegl/gimpoperationhuesaturation.c +++ b/app/gegl/gimpoperationhuesaturation.c @@ -28,20 +28,18 @@ #include "gegl-types.h" +#include "gimphuesaturationconfig.h" #include "gimpoperationhuesaturation.h" enum { PROP_0, - PROP_RANGE, - PROP_HUE, - PROP_SATURATION, - PROP_LIGHTNESS, - PROP_OVERLAP + PROP_CONFIG }; +static void gimp_operation_hue_saturation_finalize (GObject *object); static void gimp_operation_hue_saturation_get_property (GObject *object, guint property_id, GValue *value, @@ -70,6 +68,7 @@ gimp_operation_hue_saturation_class_init (GimpOperationHueSaturationClass * klas GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass); GeglOperationPointFilterClass *point_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass); + object_class->finalize = gimp_operation_hue_saturation_finalize; object_class->set_property = gimp_operation_hue_saturation_set_property; object_class->get_property = gimp_operation_hue_saturation_get_property; @@ -77,44 +76,11 @@ gimp_operation_hue_saturation_class_init (GimpOperationHueSaturationClass * klas gegl_operation_class_set_name (operation_class, "gimp-hue-saturation"); - g_object_class_install_property (object_class, PROP_RANGE, - g_param_spec_enum ("range", - "range", - "The affected range", - GIMP_TYPE_HUE_RANGE, - GIMP_ALL_HUES, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, PROP_HUE, - g_param_spec_double ("hue", - "Hue", - "Hue", - -1.0, 1.0, 0.0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, PROP_SATURATION, - g_param_spec_double ("saturation", - "Saturation", - "Saturation", - -1.0, 1.0, 0.0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, PROP_LIGHTNESS, - g_param_spec_double ("lightness", - "Lightness", - "Lightness", - -1.0, 1.0, 0.0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, PROP_OVERLAP, - g_param_spec_double ("overlap", - "Overlap", - "Overlap", - 0.0, 1.0, 0.0, + g_object_class_install_property (object_class, PROP_CONFIG, + g_param_spec_object ("config", + "Config", + "The config object", + GIMP_TYPE_HUE_SATURATION_CONFIG, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); } @@ -122,18 +88,20 @@ gimp_operation_hue_saturation_class_init (GimpOperationHueSaturationClass * klas static void gimp_operation_hue_saturation_init (GimpOperationHueSaturation *self) { - GimpHueRange range; +} - self->range = GIMP_ALL_HUES; +static void +gimp_operation_hue_saturation_finalize (GObject *object) +{ + GimpOperationHueSaturation *self = GIMP_OPERATION_HUE_SATURATION (object); - for (range = GIMP_ALL_HUES; range <= GIMP_MAGENTA_HUES; range++) + if (self->config) { - self->hue[range] = 0.0; - self->saturation[range] = 0.0; - self->lightness[range] = 0.0; + g_object_unref (self->config); + self->config = NULL; } - self->overlap = 0.0; + G_OBJECT_CLASS (parent_class)->finalize (object); } static void @@ -146,24 +114,8 @@ gimp_operation_hue_saturation_get_property (GObject *object, switch (property_id) { - case PROP_RANGE: - g_value_set_enum (value, self->range); - break; - - case PROP_HUE: - g_value_set_double (value, self->hue[self->range]); - break; - - case PROP_SATURATION: - g_value_set_double (value, self->saturation[self->range]); - break; - - case PROP_LIGHTNESS: - g_value_set_double (value, self->lightness[self->range]); - break; - - case PROP_OVERLAP: - g_value_set_double (value, self->overlap); + case PROP_CONFIG: + g_value_set_object (value, self->config); break; default: @@ -182,24 +134,10 @@ gimp_operation_hue_saturation_set_property (GObject *object, switch (property_id) { - case PROP_RANGE: - self->range = g_value_get_enum (value); - break; - - case PROP_HUE: - self->hue[self->range] = g_value_get_double (value); - break; - - case PROP_SATURATION: - self->saturation[self->range] = g_value_get_double (value); - break; - - case PROP_LIGHTNESS: - self->lightness[self->range] = g_value_get_double (value); - break; - - case PROP_OVERLAP: - self->overlap = g_value_get_double (value); + case PROP_CONFIG: + if (self->config) + g_object_unref (self->config); + self->config = g_value_dup_object (value); break; default: @@ -209,11 +147,11 @@ gimp_operation_hue_saturation_set_property (GObject *object, } static inline gdouble -map_hue (GimpOperationHueSaturation *self, - gint hue, - gdouble value) +map_hue (GimpHueSaturationConfig *config, + GimpHueRange range, + gdouble value) { - value += (self->hue[0] + self->hue[hue + 1]) / 2.0; + value += (config->hue[GIMP_ALL_HUES] + config->hue[range]) / 2.0; if (value < 0) return value + 1.0; @@ -224,13 +162,11 @@ map_hue (GimpOperationHueSaturation *self, } static inline gdouble -map_saturation (GimpOperationHueSaturation *self, - gint hue, - gdouble value) +map_saturation (GimpHueSaturationConfig *config, + GimpHueRange range, + gdouble value) { - gdouble v = self->saturation[0] + self->saturation[hue + 1]; - - // v = CLAMP (v, -1.0, 1.0); + gdouble v = config->saturation[GIMP_ALL_HUES] + config->saturation[range]; /* This change affects the way saturation is computed. With the old * code (different code for value < 0), increasing the saturation @@ -246,13 +182,11 @@ map_saturation (GimpOperationHueSaturation *self, } static inline gdouble -map_lightness (GimpOperationHueSaturation *self, - gint hue, - gdouble value) +map_lightness (GimpHueSaturationConfig *config, + GimpHueRange range, + gdouble value) { - gdouble v = (self->lightness[0] + self->lightness[hue + 1]) / 2.0; - - // v = CLAMP (v, -1.0, 1.0); + gdouble v = (config->lightness[GIMP_ALL_HUES] + config->lightness[range]) / 2.0; if (v < 0) return value * (v + 1.0); @@ -267,9 +201,10 @@ gimp_operation_hue_saturation_process (GeglOperation *operation, glong samples) { GimpOperationHueSaturation *self = GIMP_OPERATION_HUE_SATURATION (operation); + GimpHueSaturationConfig *config = self->config; gfloat *src = in_buf; gfloat *dest = out_buf; - gfloat overlap = self->overlap / 2.0; + gfloat overlap = config->overlap / 2.0; glong sample; for (sample = 0; sample < samples; sample++) @@ -331,22 +266,26 @@ gimp_operation_hue_saturation_process (GeglOperation *operation, secondary_hue = 0; } + /* transform into GimpHueRange values */ + hue++; + secondary_hue++; + if (use_secondary_hue) { - hsl.h = (map_hue (self, hue, hsl.h) * primary_intensity + - map_hue (self, secondary_hue, hsl.h) * secondary_intensity); + hsl.h = (map_hue (config, hue, hsl.h) * primary_intensity + + map_hue (config, secondary_hue, hsl.h) * secondary_intensity); - hsl.s = (map_saturation (self, hue, hsl.s) * primary_intensity + - map_saturation (self, secondary_hue, hsl.s) * secondary_intensity); + hsl.s = (map_saturation (config, hue, hsl.s) * primary_intensity + + map_saturation (config, secondary_hue, hsl.s) * secondary_intensity); - hsl.l = (map_lightness (self, hue, hsl.l) * primary_intensity + - map_lightness (self, secondary_hue, hsl.l) * secondary_intensity); + hsl.l = (map_lightness (config, hue, hsl.l) * primary_intensity + + map_lightness (config, secondary_hue, hsl.l) * secondary_intensity); } else { - hsl.h = map_hue (self, hue, hsl.h); - hsl.s = map_saturation (self, hue, hsl.s); - hsl.l = map_lightness (self, hue, hsl.l); + hsl.h = map_hue (config, hue, hsl.h); + hsl.s = map_saturation (config, hue, hsl.s); + hsl.l = map_lightness (config, hue, hsl.l); } gimp_hsl_to_rgb (&hsl, &rgb); @@ -362,3 +301,27 @@ gimp_operation_hue_saturation_process (GeglOperation *operation, return TRUE; } + + +/* public functions */ + +void +gimp_operation_hue_saturation_map (GimpHueSaturationConfig *config, + const GimpRGB *color, + GimpHueRange range, + GimpRGB *result) +{ + GimpHSL hsl; + + g_return_if_fail (GIMP_IS_HUE_SATURATION_CONFIG (config)); + g_return_if_fail (color != NULL); + g_return_if_fail (result != NULL); + + gimp_rgb_to_hsl (color, &hsl); + + hsl.h = map_hue (config, range, hsl.h); + hsl.s = map_saturation (config, range, hsl.s); + hsl.l = map_lightness (config, range, hsl.l); + + gimp_hsl_to_rgb (&hsl, result); +} diff --git a/app/gegl/gimpoperationhuesaturation.h b/app/gegl/gimpoperationhuesaturation.h index 13ba9efe61..e795aaa70d 100644 --- a/app/gegl/gimpoperationhuesaturation.h +++ b/app/gegl/gimpoperationhuesaturation.h @@ -40,13 +40,7 @@ struct _GimpOperationHueSaturation { GeglOperationPointFilter parent_instance; - GimpHueRange range; - - gdouble hue[7]; - gdouble saturation[7]; - gdouble lightness[7]; - - gdouble overlap; + GimpHueSaturationConfig *config; }; struct _GimpOperationHueSaturationClass @@ -57,5 +51,10 @@ struct _GimpOperationHueSaturationClass GType gimp_operation_hue_saturation_get_type (void) G_GNUC_CONST; +void gimp_operation_hue_saturation_map (GimpHueSaturationConfig *config, + const GimpRGB *color, + GimpHueRange range, + GimpRGB *result); + #endif /* __GIMP_OPERATION_HUE_SATURATION_H__ */ diff --git a/app/tools/gimphuesaturationtool.c b/app/tools/gimphuesaturationtool.c index df5452c7ce..28e04f87ac 100644 --- a/app/tools/gimphuesaturationtool.c +++ b/app/tools/gimphuesaturationtool.c @@ -28,6 +28,9 @@ #include "base/hue-saturation.h" +#include "gegl/gimphuesaturationconfig.h" +#include "gegl/gimpoperationhuesaturation.h" + #include "core/gimpdrawable.h" #include "core/gimpimage.h" #include "core/gimpimagemap.h" @@ -82,16 +85,6 @@ G_DEFINE_TYPE (GimpHueSaturationTool, gimp_hue_saturation_tool, #define parent_class gimp_hue_saturation_tool_parent_class -static gint default_colors[6][3] = -{ - { 255, 0, 0 }, - { 255, 255, 0 }, - { 0, 255, 0 }, - { 0, 255, 255 }, - { 0, 0, 255 }, - { 255, 0, 255 } -}; - void gimp_hue_saturation_tool_register (GimpToolRegisterCallback callback, @@ -147,6 +140,12 @@ gimp_hue_saturation_tool_finalize (GObject *object) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (object); + if (hs_tool->config) + { + g_object_unref (hs_tool->config); + hs_tool->config = NULL; + } + g_slice_free (HueSaturation, hs_tool->hue_saturation); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -172,8 +171,11 @@ gimp_hue_saturation_tool_initialize (GimpTool *tool, return FALSE; } - hue_saturation_init (hs_tool->hue_saturation); - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + gimp_hue_saturation_config_reset (hs_tool->config); + + g_object_set (hs_tool->config, + "range", hs_tool->hue_partition, + NULL); GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); @@ -186,34 +188,30 @@ gimp_hue_saturation_tool_initialize (GimpTool *tool, static GeglNode * gimp_hue_saturation_tool_get_operation (GimpImageMapTool *im_tool) { - return g_object_new (GEGL_TYPE_NODE, + GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (im_tool); + GeglNode *node; + + node = g_object_new (GEGL_TYPE_NODE, "operation", "gimp-hue-saturation", NULL); + + hs_tool->config = g_object_new (GIMP_TYPE_HUE_SATURATION_CONFIG, NULL); + + gegl_node_set (node, + "config", hs_tool->config, + NULL); + + return node; } static void gimp_hue_saturation_tool_map (GimpImageMapTool *image_map_tool) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (image_map_tool); - HueSaturation *hs = hs_tool->hue_saturation; - GimpHueRange range; - for (range = GIMP_ALL_HUES; range <= GIMP_MAGENTA_HUES; range++) - { - gegl_node_set (image_map_tool->operation, - "range", range, - NULL); + gimp_hue_saturation_config_to_cruft (hs_tool->config, hs_tool->hue_saturation); - gegl_node_set (image_map_tool->operation, - "hue", hs->hue[range] / 180.0, - "saturation", hs->saturation[range] / 100.0, - "lightness", hs->lightness[range] / 100.0, - NULL); - } - - gegl_node_set (image_map_tool->operation, - "overlap", hs->overlap / 100.0, - NULL); + hue_saturation_calculate_transfers (hs_tool->hue_saturation); } @@ -452,8 +450,11 @@ gimp_hue_saturation_tool_reset (GimpImageMapTool *image_map_tool) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (image_map_tool); - hue_saturation_init (hs_tool->hue_saturation); - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + gimp_hue_saturation_config_reset (hs_tool->config); + + g_object_set (hs_tool->config, + "range", hs_tool->hue_partition, + NULL); hue_saturation_update_sliders (hs_tool); hue_saturation_update_color_areas (hs_tool); @@ -462,39 +463,39 @@ gimp_hue_saturation_tool_reset (GimpImageMapTool *image_map_tool) static void hue_saturation_update_sliders (GimpHueSaturationTool *hs_tool) { - gtk_adjustment_set_value (GTK_ADJUSTMENT (hs_tool->hue_data), - hs_tool->hue_saturation->hue[hs_tool->hue_partition]); - gtk_adjustment_set_value (GTK_ADJUSTMENT (hs_tool->lightness_data), - hs_tool->hue_saturation->lightness[hs_tool->hue_partition]); - gtk_adjustment_set_value (GTK_ADJUSTMENT (hs_tool->saturation_data), - hs_tool->hue_saturation->saturation[hs_tool->hue_partition]); - gtk_adjustment_set_value (GTK_ADJUSTMENT (hs_tool->overlap_data), - hs_tool->hue_saturation->overlap); + GimpHueSaturationConfig *config = hs_tool->config; + + gtk_adjustment_set_value (hs_tool->hue_data, + config->hue[hs_tool->hue_partition] * 180.0); + gtk_adjustment_set_value (hs_tool->lightness_data, + config->lightness[hs_tool->hue_partition] * 100.0); + gtk_adjustment_set_value (hs_tool->saturation_data, + config->saturation[hs_tool->hue_partition] * 100.0); + gtk_adjustment_set_value (hs_tool->overlap_data, + config->overlap * 100.0); } static void hue_saturation_update_color_areas (GimpHueSaturationTool *hs_tool) { - gint rgb[3]; - GimpRGB color; - gint i; + static GimpRGB default_colors[6] = + { + { 1.0, 0, 0, }, + { 1.0, 1.0, 0, }, + { 0, 1.0, 0, }, + { 0, 1.0, 1.0, }, + { 0, 0, 1.0, }, + { 1.0, 0, 1.0, } + }; + + gint i; for (i = 0; i < 6; i++) { - rgb[RED_PIX] = default_colors[i][RED_PIX]; - rgb[GREEN_PIX] = default_colors[i][GREEN_PIX]; - rgb[BLUE_PIX] = default_colors[i][BLUE_PIX]; + GimpRGB color = default_colors[i]; - gimp_rgb_to_hsl_int (rgb, rgb + 1, rgb + 2); - - rgb[RED_PIX] = hs_tool->hue_saturation->hue_transfer[i][rgb[RED_PIX]]; - rgb[GREEN_PIX] = hs_tool->hue_saturation->saturation_transfer[i][rgb[GREEN_PIX]]; - rgb[BLUE_PIX] = hs_tool->hue_saturation->lightness_transfer[i][rgb[BLUE_PIX]]; - - gimp_hsl_to_rgb_int (rgb, rgb + 1, rgb + 2); - - gimp_rgb_set_uchar (&color, - (guchar) rgb[0], (guchar) rgb[1], (guchar) rgb[2]); + gimp_operation_hue_saturation_map (hs_tool->config, &color, i + 1, + &color); gimp_color_area_set_color (GIMP_COLOR_AREA (hs_tool->hue_partition_da[i]), &color); @@ -515,6 +516,10 @@ hue_saturation_partition_callback (GtkWidget *widget, { hs_tool->hue_partition = partition; + g_object_set (hs_tool->config, + "range", hs_tool->hue_partition, + NULL); + hue_saturation_update_sliders (hs_tool); } } @@ -525,9 +530,8 @@ hue_saturation_partition_reset_callback (GtkWidget *widget, { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (data); - hue_saturation_partition_reset (hs_tool->hue_saturation, - hs_tool->hue_partition); - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + gimp_hue_saturation_config_reset_range (hs_tool->config, + hs_tool->hue_partition); hue_saturation_update_sliders (hs_tool); hue_saturation_update_color_areas (hs_tool); @@ -540,12 +544,13 @@ hue_saturation_hue_changed (GtkAdjustment *adjustment, gpointer data) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (data); - GimpHueRange part = hs_tool->hue_partition; + gdouble value = adjustment->value / 180.0; - if (hs_tool->hue_saturation->hue[part] != adjustment->value) + if (hs_tool->config->hue[hs_tool->hue_partition] != value) { - hs_tool->hue_saturation->hue[part] = adjustment->value; - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + g_object_set (hs_tool->config, + "hue", value, + NULL); hue_saturation_update_color_areas (hs_tool); @@ -558,12 +563,13 @@ hue_saturation_lightness_changed (GtkAdjustment *adjustment, gpointer data) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (data); - GimpHueRange part = hs_tool->hue_partition; + gdouble value = adjustment->value / 100.0; - if (hs_tool->hue_saturation->lightness[part] != adjustment->value) + if (hs_tool->config->lightness[hs_tool->hue_partition] != value) { - hs_tool->hue_saturation->lightness[part] = adjustment->value; - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + g_object_set (hs_tool->config, + "lightness", value, + NULL); hue_saturation_update_color_areas (hs_tool); @@ -576,12 +582,13 @@ hue_saturation_saturation_changed (GtkAdjustment *adjustment, gpointer data) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (data); - GimpHueRange part = hs_tool->hue_partition; + gdouble value = adjustment->value / 100.0; - if (hs_tool->hue_saturation->saturation[part] != adjustment->value) + if (hs_tool->config->saturation[hs_tool->hue_partition] != value) { - hs_tool->hue_saturation->saturation[part] = adjustment->value; - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + g_object_set (hs_tool->config, + "saturation", value, + NULL); hue_saturation_update_color_areas (hs_tool); @@ -594,11 +601,13 @@ hue_saturation_overlap_changed (GtkAdjustment *adjustment, gpointer data) { GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (data); + gdouble value = adjustment->value / 100.0; - if (hs_tool->hue_saturation->overlap != adjustment->value) + if (hs_tool->config->overlap != value) { - hs_tool->hue_saturation->overlap = adjustment->value; - hue_saturation_calculate_transfers (hs_tool->hue_saturation); + g_object_set (hs_tool->config, + "overlap", value, + NULL); hue_saturation_update_color_areas (hs_tool); diff --git a/app/tools/gimphuesaturationtool.h b/app/tools/gimphuesaturationtool.h index 1c19fc6532..9b695d2740 100644 --- a/app/tools/gimphuesaturationtool.h +++ b/app/tools/gimphuesaturationtool.h @@ -36,17 +36,18 @@ typedef struct _GimpHueSaturationToolClass GimpHueSaturationToolClass; struct _GimpHueSaturationTool { - GimpImageMapTool parent_instance; + GimpImageMapTool parent_instance; - HueSaturation *hue_saturation; + GimpHueSaturationConfig *config; + HueSaturation *hue_saturation; /* dialog */ - GimpHueRange hue_partition; - GtkWidget *hue_partition_da[6]; - GtkAdjustment *overlap_data; - GtkAdjustment *hue_data; - GtkAdjustment *lightness_data; - GtkAdjustment *saturation_data; + GimpHueRange hue_partition; + GtkWidget *hue_partition_da[6]; + GtkAdjustment *overlap_data; + GtkAdjustment *hue_data; + GtkAdjustment *lightness_data; + GtkAdjustment *saturation_data; }; struct _GimpHueSaturationToolClass