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



Author: mitch
Date: Wed Jan 23 08:48:29 2008
New Revision: 24682
URL: http://svn.gnome.org/viewvc/gimp?rev=24682&view=rev

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

	* app/gegl/gimpoperationlevels.[ch]
	(gimp_operation_levels_map_input): new utility function which maps
	a single value.

	* app/tools/gimplevelstool.[ch] (levels_update_adjustments): use the
	new function to create the input arrays for gimp_color_bar_set_buffer().

	Removed the Levels struct from the GimpLevelsTool struct and only
	use it in map() when needed.

	* app/base/levels.[ch]: remove obsolete API and struct members.



Modified:
   trunk/ChangeLog
   trunk/app/base/levels.c
   trunk/app/base/levels.h
   trunk/app/gegl/gimpoperationlevels.c
   trunk/app/gegl/gimpoperationlevels.h
   trunk/app/tools/gimplevelstool.c
   trunk/app/tools/gimplevelstool.h

Modified: trunk/app/base/levels.c
==============================================================================
--- trunk/app/base/levels.c	(original)
+++ trunk/app/base/levels.c	Wed Jan 23 08:48:29 2008
@@ -51,40 +51,6 @@
     }
 }
 
-void
-levels_calculate_transfers (Levels *levels)
-{
-  gdouble inten;
-  gint    i, j;
-
-  g_return_if_fail (levels != NULL);
-
-  /*  Recalculate the levels arrays  */
-  for (j = 0; j < 5; j++)
-    {
-      for (i = 0; i < 256; i++)
-        {
-          /*  determine input intensity  */
-          if (levels->high_input[j] != levels->low_input[j])
-            {
-              inten = ((gdouble) (i - levels->low_input[j]) /
-                       (double) (levels->high_input[j] - levels->low_input[j]));
-            }
-          else
-            {
-              inten = (gdouble) (i - levels->low_input[j]);
-            }
-
-          inten = CLAMP (inten, 0.0, 1.0);
-
-          if (levels->gamma[j] != 0.0)
-            inten = pow (inten, (1.0 / levels->gamma[j]));
-
-          levels->input[j][i] = (guchar) (inten * 255.0 + 0.5);
-        }
-    }
-}
-
 gfloat
 levels_lut_func (Levels *levels,
                  gint    n_channels,

Modified: trunk/app/base/levels.h
==============================================================================
--- trunk/app/base/levels.h	(original)
+++ trunk/app/base/levels.h	Wed Jan 23 08:48:29 2008
@@ -29,17 +29,14 @@
 
   gint    low_output[5];
   gint    high_output[5];
-
-  guchar  input[5][256]; /* this is used only by the gui */
 };
 
 
-void     levels_init                (Levels *levels);
-void     levels_calculate_transfers (Levels *levels);
-gfloat   levels_lut_func            (Levels *levels,
-                                     gint    n_channels,
-                                     gint    channel,
-                                     gfloat  value);
+void     levels_init     (Levels *levels);
+gfloat   levels_lut_func (Levels *levels,
+                          gint    n_channels,
+                          gint    channel,
+                          gfloat  value);
 
 
 #endif  /*  __LEVELS_H__  */

Modified: trunk/app/gegl/gimpoperationlevels.c
==============================================================================
--- trunk/app/gegl/gimpoperationlevels.c	(original)
+++ trunk/app/gegl/gimpoperationlevels.c	Wed Jan 23 08:48:29 2008
@@ -225,3 +225,31 @@
 
   return TRUE;
 }
+
+
+/*  public functions  */
+
+gdouble
+gimp_operation_levels_map_input (GimpLevelsConfig     *config,
+                                 GimpHistogramChannel  channel,
+                                 gdouble               value)
+{
+  g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), 0.0);
+
+  /*  determine input intensity  */
+  if (config->high_input[channel] != config->low_input[channel])
+    value = ((value - config->low_input[channel]) /
+             (config->high_input[channel] - config->low_input[channel]));
+  else
+    value = (value - config->low_input[channel]);
+
+  value = CLAMP (value, 0.0, 1.0);
+
+  if (config->gamma[channel] != 0.0)
+    {
+      value = pow (value, 1.0 / config->gamma[channel]);
+    }
+
+  return value;
+}
+

Modified: trunk/app/gegl/gimpoperationlevels.h
==============================================================================
--- trunk/app/gegl/gimpoperationlevels.h	(original)
+++ trunk/app/gegl/gimpoperationlevels.h	Wed Jan 23 08:48:29 2008
@@ -50,7 +50,11 @@
 };
 
 
-GType   gimp_operation_levels_get_type (void) G_GNUC_CONST;
+GType     gimp_operation_levels_get_type  (void) G_GNUC_CONST;
+
+gdouble   gimp_operation_levels_map_input (GimpLevelsConfig     *config,
+                                           GimpHistogramChannel  channel,
+                                           gdouble               value);
 
 
 #endif /* __GIMP_OPERATION_LEVELS_H__ */

Modified: trunk/app/tools/gimplevelstool.c
==============================================================================
--- trunk/app/tools/gimplevelstool.c	(original)
+++ trunk/app/tools/gimplevelstool.c	Wed Jan 23 08:48:29 2008
@@ -38,6 +38,7 @@
 #include "base/levels.h"
 
 #include "gegl/gimplevelsconfig.h"
+#include "gegl/gimpoperationlevels.h"
 
 #include "core/gimpdrawable.h"
 #include "core/gimpdrawable-histogram.h"
@@ -180,13 +181,10 @@
   GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool);
 
   tool->lut           = gimp_lut_new ();
-  tool->levels        = g_slice_new0 (Levels);
   tool->hist          = NULL;
   tool->channel       = GIMP_HISTOGRAM_VALUE;
   tool->active_picker = NULL;
 
-  levels_init (tool->levels);
-
   im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
   im_tool->apply_data = tool->lut;
 }
@@ -196,15 +194,14 @@
 {
   GimpLevelsTool *tool = GIMP_LEVELS_TOOL (object);
 
-  gimp_lut_free (tool->lut);
-  g_slice_free (Levels, tool->levels);
-
   if (tool->config)
     {
       g_object_unref (tool->config);
       tool->config = NULL;
     }
 
+  gimp_lut_free (tool->lut);
+
   if (tool->hist)
     {
       gimp_histogram_free (tool->hist);
@@ -285,12 +282,13 @@
 gimp_levels_tool_map (GimpImageMapTool *image_map_tool)
 {
   GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
+  Levels          levels;
 
-  gimp_levels_config_to_levels_cruft (tool->config, tool->levels, tool->color);
+  gimp_levels_config_to_levels_cruft (tool->config, &levels, tool->color);
 
   gimp_lut_setup (tool->lut,
                   (GimpLutFunc) levels_lut_func,
-                  tool->levels,
+                  &levels,
                   gimp_drawable_bytes (image_map_tool->drawable));
 }
 
@@ -830,28 +828,52 @@
 static void
 levels_update_input_bar (GimpLevelsTool *tool)
 {
-  /*  Recalculate the transfer arrays  */
-  gimp_levels_config_to_levels_cruft (tool->config, tool->levels, tool->color);
-  levels_calculate_transfers (tool->levels);
-
   switch (tool->channel)
     {
     case GIMP_HISTOGRAM_VALUE:
     case GIMP_HISTOGRAM_ALPHA:
     case GIMP_HISTOGRAM_RGB:
-      gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->input_bar),
-                                  tool->levels->input[tool->channel],
-                                  tool->levels->input[tool->channel],
-                                  tool->levels->input[tool->channel]);
+      {
+        guchar v[256];
+        gint   i;
+
+        for (i = 0; i < 256; i++)
+          {
+            v[i] = gimp_operation_levels_map_input (tool->config,
+                                                    tool->channel,
+                                                    i / 255.0) * 255.999;
+          }
+
+        gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->input_bar),
+                                    v, v, v);
+      }
       break;
 
     case GIMP_HISTOGRAM_RED:
     case GIMP_HISTOGRAM_GREEN:
     case GIMP_HISTOGRAM_BLUE:
-      gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->input_bar),
-                                  tool->levels->input[GIMP_HISTOGRAM_RED],
-                                  tool->levels->input[GIMP_HISTOGRAM_GREEN],
-                                  tool->levels->input[GIMP_HISTOGRAM_BLUE]);
+      {
+        guchar r[256];
+        guchar g[256];
+        guchar b[256];
+        gint   i;
+
+        for (i = 0; i < 256; i++)
+          {
+            r[i] = gimp_operation_levels_map_input (tool->config,
+                                                    GIMP_HISTOGRAM_RED,
+                                                    i / 255.0) * 255.999;
+            g[i] = gimp_operation_levels_map_input (tool->config,
+                                                    GIMP_HISTOGRAM_GREEN,
+                                                    i / 255.0) * 255.999;
+            b[i] = gimp_operation_levels_map_input (tool->config,
+                                                    GIMP_HISTOGRAM_BLUE,
+                                                    i / 255.0) * 255.999;
+          }
+
+        gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->input_bar),
+                                    r, g, b);
+      }
       break;
     }
 }

Modified: trunk/app/tools/gimplevelstool.h
==============================================================================
--- trunk/app/tools/gimplevelstool.h	(original)
+++ trunk/app/tools/gimplevelstool.h	Wed Jan 23 08:48:29 2008
@@ -40,7 +40,6 @@
 
   GimpLevelsConfig     *config;
   GimpLut              *lut;
-  Levels               *levels;
 
   /* dialog */
   gboolean              color;



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