gimp r24667 - in trunk: . app/base app/gegl app/tools



Author: mitch
Date: Tue Jan 22 09:49:40 2008
New Revision: 24667
URL: http://svn.gnome.org/viewvc/gimp?rev=24667&view=rev

Log:
2008-01-22  Michael Natterer  <mitch gimp org>

	* 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.



Added:
   trunk/app/gegl/gimphuesaturationconfig.c
   trunk/app/gegl/gimphuesaturationconfig.h
Modified:
   trunk/ChangeLog
   trunk/app/base/hue-saturation.c
   trunk/app/base/hue-saturation.h
   trunk/app/gegl/Makefile.am
   trunk/app/gegl/gegl-types.h
   trunk/app/gegl/gimpoperationhuesaturation.c
   trunk/app/gegl/gimpoperationhuesaturation.h
   trunk/app/tools/gimphuesaturationtool.c
   trunk/app/tools/gimphuesaturationtool.h

Modified: trunk/app/base/hue-saturation.c
==============================================================================
--- trunk/app/base/hue-saturation.c	(original)
+++ trunk/app/base/hue-saturation.c	Tue Jan 22 09:49:40 2008
@@ -37,19 +37,13 @@
   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;
+  for (partition = GIMP_ALL_HUES; partition <= GIMP_MAGENTA_HUES; partition++)
+    {
+      hs->hue[partition]        = 0.0;
+      hs->lightness[partition]  = 0.0;
+      hs->saturation[partition] = 0.0;
+    }
 }
 
 void
@@ -65,6 +59,7 @@
   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);

Modified: trunk/app/base/hue-saturation.h
==============================================================================
--- trunk/app/base/hue-saturation.h	(original)
+++ trunk/app/base/hue-saturation.h	Tue Jan 22 09:49:40 2008
@@ -34,8 +34,6 @@
 
 
 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,

Modified: trunk/app/gegl/Makefile.am
==============================================================================
--- trunk/app/gegl/Makefile.am	(original)
+++ trunk/app/gegl/Makefile.am	Tue Jan 22 09:49:40 2008
@@ -10,6 +10,8 @@
 	\
 	gimpcolorizeconfig.c		\
 	gimpcolorizeconfig.h		\
+	gimphuesaturationconfig.c	\
+	gimphuesaturationconfig.h	\
 	gimplevelsconfig.c		\
 	gimplevelsconfig.h		\
 	\

Modified: trunk/app/gegl/gegl-types.h
==============================================================================
--- trunk/app/gegl/gegl-types.h	(original)
+++ trunk/app/gegl/gegl-types.h	Tue Jan 22 09:49:40 2008
@@ -42,6 +42,7 @@
 /*  operation config objects  */
 
 typedef struct _GimpColorizeConfig         GimpColorizeConfig;
+typedef struct _GimpHueSaturationConfig    GimpHueSaturationConfig;
 typedef struct _GimpLevelsConfig           GimpLevelsConfig;
 
 

Added: trunk/app/gegl/gimphuesaturationconfig.c
==============================================================================
--- (empty file)
+++ trunk/app/gegl/gimphuesaturationconfig.c	Tue Jan 22 09:49:40 2008
@@ -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 <mitch gimp org>
+ *
+ * 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 <gegl.h>
+
+#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;
+}

Added: trunk/app/gegl/gimphuesaturationconfig.h
==============================================================================
--- (empty file)
+++ trunk/app/gegl/gimphuesaturationconfig.h	Tue Jan 22 09:49:40 2008
@@ -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 <mitch gimp org>
+ *
+ * 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__ */

Modified: trunk/app/gegl/gimpoperationhuesaturation.c
==============================================================================
--- trunk/app/gegl/gimpoperationhuesaturation.c	(original)
+++ trunk/app/gegl/gimpoperationhuesaturation.c	Tue Jan 22 09:49:40 2008
@@ -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 @@
   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 @@
 
   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 @@
 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 @@
 
   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 @@
 
   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 @@
 }
 
 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 @@
 }
 
 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 @@
 }
 
 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 @@
                                        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 @@
           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 @@
 
   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);
+}

Modified: trunk/app/gegl/gimpoperationhuesaturation.h
==============================================================================
--- trunk/app/gegl/gimpoperationhuesaturation.h	(original)
+++ trunk/app/gegl/gimpoperationhuesaturation.h	Tue Jan 22 09:49:40 2008
@@ -40,13 +40,7 @@
 {
   GeglOperationPointFilter  parent_instance;
 
-  GimpHueRange              range;
-
-  gdouble                   hue[7];
-  gdouble                   saturation[7];
-  gdouble                   lightness[7];
-
-  gdouble                   overlap;
+  GimpHueSaturationConfig  *config;
 };
 
 struct _GimpOperationHueSaturationClass
@@ -57,5 +51,10 @@
 
 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__ */

Modified: trunk/app/tools/gimphuesaturationtool.c
==============================================================================
--- trunk/app/tools/gimphuesaturationtool.c	(original)
+++ trunk/app/tools/gimphuesaturationtool.c	Tue Jan 22 09:49:40 2008
@@ -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 @@
 
 #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 @@
 {
   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 @@
       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 @@
 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);
-
-      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);
-    }
+  gimp_hue_saturation_config_to_cruft (hs_tool->config, hs_tool->hue_saturation);
 
-  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 @@
 {
   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 @@
 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];
-
-      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]];
+      GimpRGB color = default_colors[i];
 
-      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 @@
     {
       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 @@
 {
   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 @@
                             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 @@
                                   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 @@
                                    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 @@
                                 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);
 

Modified: trunk/app/tools/gimphuesaturationtool.h
==============================================================================
--- trunk/app/tools/gimphuesaturationtool.h	(original)
+++ trunk/app/tools/gimphuesaturationtool.h	Tue Jan 22 09:49:40 2008
@@ -36,17 +36,18 @@
 
 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]