gimp r24706 - in trunk: . app/gegl app/tools



Author: mitch
Date: Fri Jan 25 11:42:07 2008
New Revision: 24706
URL: http://svn.gnome.org/viewvc/gimp?rev=24706&view=rev

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

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpthresholdconfig.[ch]: new config object.

	* app/gegl/gimpoperationthreshold.[ch]: use it.

	* app/tools/gimpthresholdtool.[ch]: ditto.



Added:
   trunk/app/gegl/gimpthresholdconfig.c
   trunk/app/gegl/gimpthresholdconfig.h
Modified:
   trunk/ChangeLog
   trunk/app/gegl/Makefile.am
   trunk/app/gegl/gegl-types.h
   trunk/app/gegl/gimpoperationthreshold.c
   trunk/app/gegl/gimpoperationthreshold.h
   trunk/app/tools/gimpthresholdtool.c
   trunk/app/tools/gimpthresholdtool.h

Modified: trunk/app/gegl/Makefile.am
==============================================================================
--- trunk/app/gegl/Makefile.am	(original)
+++ trunk/app/gegl/Makefile.am	Fri Jan 25 11:42:07 2008
@@ -18,6 +18,8 @@
 	gimphuesaturationconfig.h	\
 	gimplevelsconfig.c		\
 	gimplevelsconfig.h		\
+	gimpthresholdconfig.c		\
+	gimpthresholdconfig.h		\
 	\
 	gimpoperationcolorbalance.c	\
 	gimpoperationcolorbalance.h	\

Modified: trunk/app/gegl/gegl-types.h
==============================================================================
--- trunk/app/gegl/gegl-types.h	(original)
+++ trunk/app/gegl/gegl-types.h	Fri Jan 25 11:42:07 2008
@@ -47,6 +47,7 @@
 typedef struct _GimpCurvesConfig           GimpCurvesConfig;
 typedef struct _GimpHueSaturationConfig    GimpHueSaturationConfig;
 typedef struct _GimpLevelsConfig           GimpLevelsConfig;
+typedef struct _GimpThresholdConfig        GimpThresholdConfig;
 
 
 #endif /* __GEGL_TYPES_H__ */

Modified: trunk/app/gegl/gimpoperationthreshold.c
==============================================================================
--- trunk/app/gegl/gimpoperationthreshold.c	(original)
+++ trunk/app/gegl/gimpoperationthreshold.c	Fri Jan 25 11:42:07 2008
@@ -28,16 +28,17 @@
 #include "gegl-types.h"
 
 #include "gimpoperationthreshold.h"
+#include "gimpthresholdconfig.h"
 
 
 enum
 {
   PROP_0,
-  PROP_LOW,
-  PROP_HIGH
+  PROP_CONFIG
 };
 
 
+static void     gimp_operation_threshold_finalize     (GObject       *object);
 static void     gimp_operation_threshold_get_property (GObject       *object,
                                                        guint          property_id,
                                                        GValue        *value,
@@ -66,6 +67,7 @@
   GeglOperationClass            *operation_class = GEGL_OPERATION_CLASS (klass);
   GeglOperationPointFilterClass *point_class     = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
 
+  object_class->finalize     = gimp_operation_threshold_finalize;
   object_class->set_property = gimp_operation_threshold_set_property;
   object_class->get_property = gimp_operation_threshold_get_property;
 
@@ -73,19 +75,11 @@
 
   gegl_operation_class_set_name (operation_class, "gimp-threshold");
 
-  g_object_class_install_property (object_class, PROP_LOW,
-                                   g_param_spec_double ("low",
-                                                        "Low",
-                                                        "Low threshold",
-                                                        0.0, 1.0, 0.5,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT));
-
-  g_object_class_install_property (object_class, PROP_HIGH,
-                                   g_param_spec_double ("high",
-                                                        "High",
-                                                        "High threshold",
-                                                        0.0, 1.0, 1.0,
+  g_object_class_install_property (object_class, PROP_CONFIG,
+                                   g_param_spec_object ("config",
+                                                        "Config",
+                                                        "The config object",
+                                                        GIMP_TYPE_THRESHOLD_CONFIG,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT));
 }
@@ -96,6 +90,20 @@
 }
 
 static void
+gimp_operation_threshold_finalize (GObject *object)
+{
+  GimpOperationThreshold *self = GIMP_OPERATION_THRESHOLD (object);
+
+  if (self->config)
+    {
+      g_object_unref (self->config);
+      self->config = NULL;
+    }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
 gimp_operation_threshold_get_property (GObject    *object,
                                        guint       property_id,
                                        GValue     *value,
@@ -105,12 +113,8 @@
 
   switch (property_id)
     {
-    case PROP_LOW:
-      g_value_set_double (value, self->low);
-      break;
-
-    case PROP_HIGH:
-      g_value_set_double (value, self->high);
+    case PROP_CONFIG:
+      g_value_set_object (value, self->config);
       break;
 
     default:
@@ -129,12 +133,10 @@
 
   switch (property_id)
     {
-    case PROP_LOW:
-      self->low = g_value_get_double (value);
-      break;
-
-    case PROP_HIGH:
-      self->high = 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:
@@ -149,11 +151,15 @@
                                   void          *out_buf,
                                   glong          samples)
 {
-  GimpOperationThreshold *self = GIMP_OPERATION_THRESHOLD (operation);
-  gfloat                 *src  = in_buf;
-  gfloat                 *dest = out_buf;
+  GimpOperationThreshold *self   = GIMP_OPERATION_THRESHOLD (operation);
+  GimpThresholdConfig    *config = self->config;
+  gfloat                 *src    = in_buf;
+  gfloat                 *dest   = out_buf;
   glong                   sample;
 
+  if (! config)
+    return FALSE;
+
   for (sample = 0; sample < samples; sample++)
     {
       gfloat value;
@@ -161,7 +167,7 @@
       value = MAX (src[RED_PIX], src[GREEN_PIX]);
       value = MAX (value, src[BLUE_PIX]);
 
-      value = (value >= self->low && value <= self->high) ? 1.0 : 0.0;
+      value = (value >= config->low && value <= config->high) ? 1.0 : 0.0;
 
       dest[RED_PIX]   = value;
       dest[GREEN_PIX] = value;

Modified: trunk/app/gegl/gimpoperationthreshold.h
==============================================================================
--- trunk/app/gegl/gimpoperationthreshold.h	(original)
+++ trunk/app/gegl/gimpoperationthreshold.h	Fri Jan 25 11:42:07 2008
@@ -27,10 +27,12 @@
 #include <operation/gegl-operation-point-filter.h>
 
 
-#define GIMP_TYPE_OPERATION_THRESHOLD           (gimp_operation_threshold_get_type ())
-#define GIMP_OPERATION_THRESHOLD(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThreshold))
-#define GIMP_OPERATION_THRESHOLD_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThresholdClass))
-#define GIMP_OPERATION_THRESHOLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThresholdClass))
+#define GIMP_TYPE_OPERATION_THRESHOLD            (gimp_operation_threshold_get_type ())
+#define GIMP_OPERATION_THRESHOLD(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThreshold))
+#define GIMP_OPERATION_THRESHOLD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThresholdClass))
+#define GIMP_IS_OPERATION_THRESHOLD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_THRESHOLD))
+#define GIMP_IS_OPERATION_THRESHOLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIMP_TYPE_OPERATION_THRESHOLD))
+#define GIMP_OPERATION_THRESHOLD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThresholdClass))
 
 
 typedef struct _GimpOperationThresholdClass GimpOperationThresholdClass;
@@ -39,8 +41,7 @@
 {
   GeglOperationPointFilter  parent_instance;
 
-  gdouble                   low;
-  gdouble                   high;
+  GimpThresholdConfig      *config;
 };
 
 struct _GimpOperationThresholdClass

Added: trunk/app/gegl/gimpthresholdconfig.c
==============================================================================
--- (empty file)
+++ trunk/app/gegl/gimpthresholdconfig.c	Fri Jan 25 11:42:07 2008
@@ -0,0 +1,160 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpthresholdconfig.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/threshold.h"
+
+#include "gimpthresholdconfig.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_LOW,
+  PROP_HIGH
+};
+
+
+static void   gimp_threshold_config_get_property (GObject      *object,
+                                                  guint         property_id,
+                                                  GValue       *value,
+                                                  GParamSpec   *pspec);
+static void   gimp_threshold_config_set_property (GObject      *object,
+                                                  guint         property_id,
+                                                  const GValue *value,
+                                                  GParamSpec   *pspec);
+
+
+G_DEFINE_TYPE (GimpThresholdConfig, gimp_threshold_config,
+               G_TYPE_OBJECT)
+
+#define parent_class gimp_threshold_config_parent_class
+
+
+static void
+gimp_threshold_config_class_init (GimpThresholdConfigClass * klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = gimp_threshold_config_set_property;
+  object_class->get_property = gimp_threshold_config_get_property;
+
+  g_object_class_install_property (object_class, PROP_LOW,
+                                   g_param_spec_double ("low",
+                                                        "Low",
+                                                        "Low threshold",
+                                                        0.0, 1.0, 0.5,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (object_class, PROP_HIGH,
+                                   g_param_spec_double ("high",
+                                                        "High",
+                                                        "High threshold",
+                                                        0.0, 1.0, 1.0,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT));
+}
+
+static void
+gimp_threshold_config_init (GimpThresholdConfig *self)
+{
+}
+
+static void
+gimp_threshold_config_get_property (GObject    *object,
+                                    guint       property_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  GimpThresholdConfig *self = GIMP_THRESHOLD_CONFIG (object);
+
+  switch (property_id)
+    {
+    case PROP_LOW:
+      g_value_set_double (value, self->low);
+      break;
+
+    case PROP_HIGH:
+      g_value_set_double (value, self->high);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_threshold_config_set_property (GObject      *object,
+                                    guint         property_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  GimpThresholdConfig *self = GIMP_THRESHOLD_CONFIG (object);
+
+  switch (property_id)
+    {
+    case PROP_LOW:
+      self->low = g_value_get_double (value);
+      break;
+
+    case PROP_HIGH:
+      self->high = g_value_get_double (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+
+/*  public functions  */
+
+void
+gimp_threshold_config_reset (GimpThresholdConfig *config)
+{
+  g_return_if_fail (GIMP_IS_THRESHOLD_CONFIG (config));
+
+  config->low  = 0.5;
+  config->high = 1.0;
+}
+
+
+/*  temp cruft  */
+
+void
+gimp_threshold_config_to_cruft (GimpThresholdConfig *config,
+                                Threshold           *cruft)
+{
+  g_return_if_fail (GIMP_IS_THRESHOLD_CONFIG (config));
+  g_return_if_fail (cruft != NULL);
+
+  cruft->low_threshold  = config->low  * 255.999;
+  cruft->high_threshold = config->high * 255.999;
+}

Added: trunk/app/gegl/gimpthresholdconfig.h
==============================================================================
--- (empty file)
+++ trunk/app/gegl/gimpthresholdconfig.h	Fri Jan 25 11:42:07 2008
@@ -0,0 +1,59 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpthresholdconfig.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_THRESHOLD_CONFIG_H__
+#define __GIMP_THRESHOLD_CONFIG_H__
+
+
+#define GIMP_TYPE_THRESHOLD_CONFIG            (gimp_threshold_config_get_type ())
+#define GIMP_THRESHOLD_CONFIG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_THRESHOLD_CONFIG, GimpThresholdConfig))
+#define GIMP_THRESHOLD_CONFIG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_THRESHOLD_CONFIG, GimpThresholdConfigClass))
+#define GIMP_IS_THRESHOLD_CONFIG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_THRESHOLD_CONFIG))
+#define GIMP_IS_THRESHOLD_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIMP_TYPE_THRESHOLD_CONFIG))
+#define GIMP_THRESHOLD_CONFIG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_THRESHOLD_CONFIG, GimpThresholdConfigClass))
+
+
+typedef struct _GimpThresholdConfigClass GimpThresholdConfigClass;
+
+struct _GimpThresholdConfig
+{
+  GObject  parent_instance;
+
+  gdouble  low;
+  gdouble  high;
+};
+
+struct _GimpThresholdConfigClass
+{
+  GObjectClass  parent_class;
+};
+
+
+GType   gimp_threshold_config_get_type (void) G_GNUC_CONST;
+
+void    gimp_threshold_config_reset    (GimpThresholdConfig *config);
+
+/*  temp cruft  */
+void    gimp_threshold_config_to_cruft (GimpThresholdConfig *config,
+                                        Threshold           *cruft);
+
+
+#endif /* __GIMP_THRESHOLD_CONFIG_H__ */

Modified: trunk/app/tools/gimpthresholdtool.c
==============================================================================
--- trunk/app/tools/gimpthresholdtool.c	(original)
+++ trunk/app/tools/gimpthresholdtool.c	Fri Jan 25 11:42:07 2008
@@ -28,6 +28,8 @@
 #include "base/gimphistogram.h"
 #include "base/threshold.h"
 
+#include "gegl/gimpthresholdconfig.h"
+
 #include "core/gimpdrawable.h"
 #include "core/gimpdrawable-histogram.h"
 #include "core/gimpimage.h"
@@ -116,9 +118,6 @@
   t_tool->threshold = g_slice_new0 (Threshold);
   t_tool->hist      = NULL;
 
-  t_tool->threshold->low_threshold  = 127;
-  t_tool->threshold->high_threshold = 255;
-
   im_tool->apply_func = (GimpImageMapApplyFunc) threshold;
   im_tool->apply_data = t_tool->threshold;
 }
@@ -128,6 +127,12 @@
 {
   GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (object);
 
+  if (t_tool->config)
+    {
+      g_object_unref (t_tool->config);
+      t_tool->config = NULL;
+    }
+
   g_slice_free (Threshold, t_tool->threshold);
 
   if (t_tool->hist)
@@ -160,9 +165,9 @@
   if (! t_tool->hist)
     t_tool->hist = gimp_histogram_new ();
 
-  t_tool->threshold->color          = gimp_drawable_is_rgb (drawable);
-  t_tool->threshold->low_threshold  = 127;
-  t_tool->threshold->high_threshold = 255;
+  gimp_threshold_config_reset (t_tool->config);
+
+  t_tool->threshold->color = gimp_drawable_is_rgb (drawable);
 
   GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
 
@@ -174,8 +179,8 @@
   gimp_histogram_view_set_histogram (t_tool->histogram_box->view,
                                      t_tool->hist);
   gimp_histogram_view_set_range (t_tool->histogram_box->view,
-                                 t_tool->threshold->low_threshold,
-                                 t_tool->threshold->high_threshold);
+                                 t_tool->config->low  * 255.999,
+                                 t_tool->config->high * 255.999);
   g_signal_handlers_unblock_by_func (t_tool->histogram_box->view,
                                      gimp_threshold_tool_histogram_range,
                                      t_tool);
@@ -186,11 +191,22 @@
 }
 
 static GeglNode *
-gimp_threshold_tool_get_operation (GimpImageMapTool *im_tool)
+gimp_threshold_tool_get_operation (GimpImageMapTool *image_map_tool)
 {
-  return g_object_new (GEGL_TYPE_NODE,
+  GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
+  GeglNode          *node;
+
+  node = g_object_new (GEGL_TYPE_NODE,
                        "operation", "gimp-threshold",
                        NULL);
+
+  t_tool->config = g_object_new (GIMP_TYPE_THRESHOLD_CONFIG, NULL);
+
+  gegl_node_set (node,
+                 "config", t_tool->config,
+                 NULL);
+
+  return node;
 }
 
 static void
@@ -198,10 +214,7 @@
 {
   GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
 
-  gegl_node_set (image_map_tool->operation,
-                 "low",  t_tool->threshold->low_threshold  / 255.0,
-                 "high", t_tool->threshold->high_threshold / 255.0,
-                 NULL);
+  gimp_threshold_config_to_cruft (t_tool->config, t_tool->threshold);
 }
 
 
@@ -265,7 +278,11 @@
 {
   GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
 
-  gimp_histogram_view_set_range (t_tool->histogram_box->view, 127.0, 255.0);
+  gimp_threshold_config_reset (t_tool->config);
+
+  gimp_histogram_view_set_range (t_tool->histogram_box->view,
+                                 t_tool->config->low  * 255.999,
+                                 t_tool->config->high * 255.999);
 }
 
 static void
@@ -274,11 +291,16 @@
                                      gint               end,
                                      GimpThresholdTool *t_tool)
 {
-  if (start != t_tool->threshold->low_threshold ||
-      end   != t_tool->threshold->high_threshold)
+  gdouble low  = start / 255.0;
+  gdouble high = end   / 255.0;
+
+  if (low  != t_tool->config->low ||
+      high != t_tool->config->high)
     {
-      t_tool->threshold->low_threshold  = start;
-      t_tool->threshold->high_threshold = end;
+      g_object_set (t_tool->config,
+                    "low",  low,
+                    "high", high,
+                    NULL);
 
       gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (t_tool));
     }
@@ -288,14 +310,12 @@
 gimp_threshold_tool_auto_clicked (GtkWidget         *button,
                                   GimpThresholdTool *t_tool)
 {
-  gdouble low_threshold;
-
-  low_threshold =
-    gimp_histogram_get_threshold (t_tool->hist,
-                                  (t_tool->threshold->color ?
-                                   GIMP_HISTOGRAM_RGB : GIMP_HISTOGRAM_VALUE),
-                                  0, 255);
+  gdouble low = gimp_histogram_get_threshold (t_tool->hist,
+                                              t_tool->threshold->color ?
+                                              GIMP_HISTOGRAM_RGB :
+                                              GIMP_HISTOGRAM_VALUE,
+                                              0, 255);
 
   gimp_histogram_view_set_range (t_tool->histogram_box->view,
-                                 low_threshold, 255.0);
+                                 low, 255.0);
 }

Modified: trunk/app/tools/gimpthresholdtool.h
==============================================================================
--- trunk/app/tools/gimpthresholdtool.h	(original)
+++ trunk/app/tools/gimpthresholdtool.h	Fri Jan 25 11:42:07 2008
@@ -36,13 +36,14 @@
 
 struct _GimpThresholdTool
 {
-  GimpImageMapTool  parent_instance;
+  GimpImageMapTool     parent_instance;
 
-  Threshold        *threshold;
+  GimpThresholdConfig *config;
+  Threshold           *threshold;
 
   /*  dialog  */
-  GimpHistogram    *hist;
-  GimpHistogramBox *histogram_box;
+  GimpHistogram       *hist;
+  GimpHistogramBox    *histogram_box;
 };
 
 struct _GimpThresholdToolClass



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