gimp r24659 - in trunk: . app/base app/core
- From: mitch svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r24659 - in trunk: . app/base app/core
- Date: Mon, 21 Jan 2008 12:55:18 +0000 (GMT)
Author: mitch
Date: Mon Jan 21 12:55:18 2008
New Revision: 24659
URL: http://svn.gnome.org/viewvc/gimp?rev=24659&view=rev
Log:
2008-01-21 Michael Natterer <mitch gimp org>
* app/core/gimpdrawable-levels.c: port to GEGL and use the new
code path when use-gegl is TRUE.
* app/base/levels.[ch]: remove stretch and pick APIs which are not
used any longer.
Modified:
trunk/ChangeLog
trunk/app/base/levels.c
trunk/app/base/levels.h
trunk/app/core/gimpdrawable-levels.c
Modified: trunk/app/base/levels.c
==============================================================================
--- trunk/app/base/levels.c (original)
+++ trunk/app/base/levels.c Mon Jan 21 12:55:18 2008
@@ -27,7 +27,6 @@
#include "base-types.h"
-#include "gimphistogram.h"
#include "levels.h"
@@ -44,177 +43,11 @@
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
- levels_channel_reset (levels, channel);
- }
-}
-
-void
-levels_channel_reset (Levels *levels,
- GimpHistogramChannel channel)
-{
- g_return_if_fail (levels != NULL);
-
- levels->gamma[channel] = 1.0;
- levels->low_input[channel] = 0;
- levels->high_input[channel] = 255;
- levels->low_output[channel] = 0;
- levels->high_output[channel] = 255;
-}
-
-void
-levels_stretch (Levels *levels,
- GimpHistogram *hist,
- gboolean is_color)
-{
- GimpHistogramChannel channel;
-
- g_return_if_fail (levels != NULL);
- g_return_if_fail (hist != NULL);
-
- if (is_color)
- {
- /* Set the overall value to defaults */
- levels_channel_reset (levels, GIMP_HISTOGRAM_VALUE);
-
- for (channel = GIMP_HISTOGRAM_RED;
- channel <= GIMP_HISTOGRAM_BLUE;
- channel++)
- levels_channel_stretch (levels, hist, channel);
- }
- else
- {
- levels_channel_stretch (levels, hist, GIMP_HISTOGRAM_VALUE);
- }
-}
-
-void
-levels_channel_stretch (Levels *levels,
- GimpHistogram *hist,
- GimpHistogramChannel channel)
-{
- gint i;
- gdouble count, new_count, percentage, next_percentage;
-
- g_return_if_fail (levels != NULL);
- g_return_if_fail (hist != NULL);
-
- levels->gamma[channel] = 1.0;
- levels->low_output[channel] = 0;
- levels->high_output[channel] = 255;
-
- count = gimp_histogram_get_count (hist, channel, 0, 255);
-
- if (count == 0.0)
- {
- levels->low_input[channel] = 0;
- levels->high_input[channel] = 0;
- }
- else
- {
- /* Set the low input */
- new_count = 0.0;
-
- for (i = 0; i < 255; i++)
- {
- new_count += gimp_histogram_get_value (hist, channel, i);
- percentage = new_count / count;
- next_percentage =
- (new_count + gimp_histogram_get_value (hist,
- channel,
- i + 1)) / count;
- if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
- {
- levels->low_input[channel] = i + 1;
- break;
- }
- }
- /* Set the high input */
- new_count = 0.0;
- for (i = 255; i > 0; i--)
- {
- new_count += gimp_histogram_get_value (hist, channel, i);
- percentage = new_count / count;
- next_percentage =
- (new_count + gimp_histogram_get_value (hist,
- channel,
- i - 1)) / count;
- if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
- {
- levels->high_input[channel] = i - 1;
- break;
- }
- }
- }
-}
-
-static gint
-levels_input_from_color (GimpHistogramChannel channel,
- guchar *color)
-{
- switch (channel)
- {
- case GIMP_HISTOGRAM_VALUE:
- return MAX (MAX (color[RED_PIX], color[GREEN_PIX]), color[BLUE_PIX]);
- case GIMP_HISTOGRAM_RED:
- return color[RED_PIX];
- case GIMP_HISTOGRAM_GREEN:
- return color[GREEN_PIX];
- case GIMP_HISTOGRAM_BLUE:
- return color[BLUE_PIX];
- case GIMP_HISTOGRAM_ALPHA:
- return color[ALPHA_PIX];
- case GIMP_HISTOGRAM_RGB:
- return MIN (MIN (color[RED_PIX], color[GREEN_PIX]), color[BLUE_PIX]);
- }
-
- return 0; /* just to please the compiler */
-}
-
-void
-levels_adjust_by_colors (Levels *levels,
- GimpHistogramChannel channel,
- guchar *black,
- guchar *gray,
- guchar *white)
-{
- g_return_if_fail (levels != NULL);
-
- if (black)
- levels->low_input[channel] = levels_input_from_color (channel, black);
-
- if (white)
- levels->high_input[channel] = levels_input_from_color (channel, white);
-
- if (gray)
- {
- gint input;
- gint range;
- gdouble inten;
- gdouble out_light;
- guchar lightness;
-
- /* Calculate lightness value */
- lightness = GIMP_RGB_LUMINANCE (gray[0], gray[1], gray[2]);
-
- input = levels_input_from_color (channel, gray);
-
- range = levels->high_input[channel] - levels->low_input[channel];
- if (range <= 0)
- return;
-
- input -= levels->low_input[channel];
- if (input < 0)
- return;
-
- /* Normalize input and lightness */
- inten = (gdouble) input / (gdouble) range;
- out_light = (gdouble) lightness/ (gdouble) range;
-
- if (out_light <= 0)
- return;
-
- /* Map selected color to corresponding lightness */
- levels->gamma[channel] = log (inten) / log (out_light);
+ levels->gamma[channel] = 1.0;
+ levels->low_input[channel] = 0;
+ levels->high_input[channel] = 255;
+ levels->low_output[channel] = 0;
+ levels->high_output[channel] = 255;
}
}
Modified: trunk/app/base/levels.h
==============================================================================
--- trunk/app/base/levels.h (original)
+++ trunk/app/base/levels.h Mon Jan 21 12:55:18 2008
@@ -34,25 +34,12 @@
};
-void levels_init (Levels *levels);
-void levels_channel_reset (Levels *levels,
- GimpHistogramChannel channel);
-void levels_stretch (Levels *levels,
- GimpHistogram *hist,
- gboolean is_color);
-void levels_channel_stretch (Levels *levels,
- GimpHistogram *hist,
- GimpHistogramChannel channel);
-void levels_adjust_by_colors (Levels *levels,
- GimpHistogramChannel channel,
- guchar *black,
- guchar *gray,
- guchar *white);
-void levels_calculate_transfers (Levels *levels);
-gfloat levels_lut_func (Levels *levels,
- gint n_channels,
- gint channel,
- gfloat value);
+void levels_init (Levels *levels);
+void levels_calculate_transfers (Levels *levels);
+gfloat levels_lut_func (Levels *levels,
+ gint n_channels,
+ gint channel,
+ gfloat value);
#endif /* __LEVELS_H__ */
Modified: trunk/app/core/gimpdrawable-levels.c
==============================================================================
--- trunk/app/core/gimpdrawable-levels.c (original)
+++ trunk/app/core/gimpdrawable-levels.c Mon Jan 21 12:55:18 2008
@@ -18,24 +18,28 @@
#include "config.h"
-#include <string.h>
-
-#include <glib-object.h>
+#include <gegl.h>
#include "core-types.h"
#include "base/gimphistogram.h"
#include "base/gimplut.h"
#include "base/levels.h"
-#include "base/lut-funcs.h"
#include "base/pixel-processor.h"
#include "base/pixel-region.h"
+#include "gegl/gimplevelsconfig.h"
+
+/* temp */
+#include "config/gimpcoreconfig.h"
#include "gimp.h"
+#include "gimpimage.h"
+
#include "gimpcontext.h"
#include "gimpdrawable.h"
#include "gimpdrawable-histogram.h"
#include "gimpdrawable-levels.h"
+#include "gimpdrawable-operation.h"
#include "gimp-intl.h"
@@ -49,12 +53,8 @@
gint32 low_output,
gint32 high_output)
{
- gint x, y, width, height;
- PixelRegion srcPR, destPR;
- Levels levels;
- GimpLut *lut;
+ GimpLevelsConfig *config;
- /* parameter checking */
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (! gimp_drawable_is_indexed (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
@@ -73,54 +73,83 @@
g_return_if_fail (channel == GIMP_HISTOGRAM_VALUE ||
channel == GIMP_HISTOGRAM_ALPHA);
- if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
- return;
+ config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
- /* FIXME: hack */
- if (gimp_drawable_is_gray (drawable) &&
- channel == GIMP_HISTOGRAM_ALPHA)
- channel = 1;
-
- lut = gimp_lut_new ();
-
- levels_init (&levels);
-
- levels.low_input[channel] = low_input;
- levels.high_input[channel] = high_input;
- levels.gamma[channel] = gamma;
- levels.low_output[channel] = low_output;
- levels.high_output[channel] = high_output;
-
- /* setup the lut */
- gimp_lut_setup (lut,
- (GimpLutFunc) levels_lut_func,
- &levels,
- gimp_drawable_bytes (drawable));
-
- pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
- x, y, width, height, FALSE);
- pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
- x, y, width, height, TRUE);
+ g_object_set (config,
+ "channel", channel,
+ NULL);
+
+ g_object_set (config,
+ "low-input", low_input / 255.0,
+ "high-input", high_input / 255.0,
+ "gamma", gamma,
+ "low-output", low_output / 255.0,
+ "high-output", high_output / 255.0,
+ NULL);
+
+ if (GIMP_ITEM (drawable)->image->gimp->config->use_gegl)
+ {
+ GeglNode *levels;
+
+ levels = g_object_new (GEGL_TYPE_NODE,
+ "operation", "gimp-levels",
+ NULL);
+
+ gegl_node_set (levels,
+ "config", config,
+ NULL);
+
+ gimp_drawable_apply_operation (drawable, levels, TRUE,
+ NULL, _("Levels"));
+
+ g_object_unref (levels);
+ }
+ else
+ {
+ PixelRegion srcPR, destPR;
+ Levels levels;
+ GimpLut *lut;
+ gint x, y;
+ gint width, height;
+
+ if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
+ return;
+
+ gimp_levels_config_to_levels_cruft (config, &levels,
+ gimp_drawable_is_rgb (drawable));
+
+ lut = gimp_lut_new ();
+ gimp_lut_setup (lut,
+ (GimpLutFunc) levels_lut_func,
+ &levels,
+ gimp_drawable_bytes (drawable));
+
+ pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
+ x, y, width, height, FALSE);
+ pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
+ x, y, width, height, TRUE);
+
+ pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process,
+ lut, 2, &srcPR, &destPR);
- pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process,
- lut, 2, &srcPR, &destPR);
+ gimp_lut_free (lut);
- gimp_lut_free (lut);
+ gimp_drawable_merge_shadow (drawable, TRUE, _("Levels"));
- gimp_drawable_merge_shadow (drawable, TRUE, _("Levels"));
- gimp_drawable_update (drawable, x, y, width, height);
-}
+ gimp_drawable_update (drawable, x, y, width, height);
+ }
+ g_object_unref (config);
+}
void
gimp_drawable_levels_stretch (GimpDrawable *drawable,
GimpContext *context)
{
- gint x, y, width, height;
- PixelRegion srcPR, destPR;
- Levels levels;
- GimpLut *lut;
- GimpHistogram *hist;
+ GimpLevelsConfig *config;
+ GimpHistogram *histogram;
+ gint x, y;
+ gint width, height;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (! gimp_drawable_is_indexed (drawable));
@@ -130,33 +159,62 @@
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
return;
- /* Build the histogram */
- hist = gimp_histogram_new ();
+ config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
+
+ histogram = gimp_histogram_new ();
+ gimp_drawable_calculate_histogram (drawable, histogram);
+
+ gimp_levels_config_stretch (config, histogram,
+ gimp_drawable_is_rgb (drawable));
+
+ gimp_histogram_free (histogram);
+
+ if (GIMP_ITEM (drawable)->image->gimp->config->use_gegl)
+ {
+ GeglNode *levels;
+
+ levels = g_object_new (GEGL_TYPE_NODE,
+ "operation", "gimp-levels",
+ NULL);
+
+ gegl_node_set (levels,
+ "config", config,
+ NULL);
+
+ gimp_drawable_apply_operation (drawable, levels, TRUE,
+ NULL, _("Levels"));
+
+ g_object_unref (levels);
+ }
+ else
+ {
+ PixelRegion srcPR, destPR;
+ Levels levels;
+ GimpLut *lut;
+
+ gimp_levels_config_to_levels_cruft (config, &levels,
+ gimp_drawable_is_rgb (drawable));
+
+ lut = gimp_lut_new ();
+ gimp_lut_setup (lut,
+ (GimpLutFunc) levels_lut_func,
+ &levels,
+ gimp_drawable_bytes (drawable));
+
+ pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
+ x, y, width, height, FALSE);
+ pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
+ x, y, width, height, TRUE);
- gimp_drawable_calculate_histogram (drawable, hist);
+ pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process,
+ lut, 2, &srcPR, &destPR);
- /* Calculate the levels */
- levels_init (&levels);
- levels_stretch (&levels, hist, ! gimp_drawable_is_gray (drawable));
-
- /* Set up the lut */
- lut = gimp_lut_new ();
- gimp_lut_setup (lut,
- (GimpLutFunc) levels_lut_func,
- &levels,
- gimp_drawable_bytes (drawable));
-
- pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
- x, y, width, height, FALSE);
- pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
- x, y, width, height, TRUE);
+ gimp_lut_free (lut);
- pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process,
- lut, 2, &srcPR, &destPR);
+ gimp_drawable_merge_shadow (drawable, TRUE, _("Levels"));
- gimp_lut_free (lut);
- gimp_histogram_free (hist);
+ gimp_drawable_update (drawable, x, y, width, height);
+ }
- gimp_drawable_merge_shadow (drawable, TRUE, _("Levels"));
- gimp_drawable_update (drawable, x, y, width, height);
+ g_object_unref (config);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]