[gthumb] enhance colors: use a faster algorithm and rename to "adjust contrast"



commit 606e2cb2141e5140fb0a2bd6e995f635863ea2fa
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Aug 24 14:04:40 2012 +0200

    enhance colors: use a faster algorithm and rename to "adjust contrast"

 data/icons/hicolor/16x16/actions/Makefile.am       |    2 +-
 .../{tool-enhance.png => tool-adjust-contrast.png} |  Bin 729 -> 729 bytes
 data/icons/hicolor/22x22/actions/Makefile.am       |    2 +-
 .../{tool-enhance.png => tool-adjust-contrast.png} |  Bin 852 -> 852 bytes
 extensions/file_tools/Makefile.am                  |    4 +-
 extensions/file_tools/callbacks.c                  |    4 +-
 .../file_tools/gth-file-tool-adjust-contrast.c     |  289 ++++++++++++++++
 .../file_tools/gth-file-tool-adjust-contrast.h     |   51 +++
 extensions/file_tools/gth-file-tool-enhance.c      |  355 --------------------
 extensions/file_tools/gth-file-tool-enhance.h      |   51 ---
 extensions/file_tools/main.c                       |    4 +-
 gthumb/gth-histogram.c                             |   50 +++-
 gthumb/gth-histogram.h                             |    2 +
 po/POTFILES.in                                     |    7 +-
 14 files changed, 395 insertions(+), 426 deletions(-)
---
diff --git a/data/icons/hicolor/16x16/actions/Makefile.am b/data/icons/hicolor/16x16/actions/Makefile.am
index 90661eb..a4828c7 100644
--- a/data/icons/hicolor/16x16/actions/Makefile.am
+++ b/data/icons/hicolor/16x16/actions/Makefile.am
@@ -25,9 +25,9 @@ icons_DATA = 				\
 	site-picasaweb.png		\
 	site-twentythree.png		\
 	tool-adjust-colors.png		\
+	tool-adjust-contrast.png	\
 	tool-crop.png			\
 	tool-desaturate.png		\
-	tool-enhance.png		\
 	tool-flip.png			\
 	tool-invert.png			\
 	tool-mirror.png			\
diff --git a/data/icons/hicolor/16x16/actions/tool-enhance.png b/data/icons/hicolor/16x16/actions/tool-adjust-contrast.png
similarity index 100%
rename from data/icons/hicolor/16x16/actions/tool-enhance.png
rename to data/icons/hicolor/16x16/actions/tool-adjust-contrast.png
diff --git a/data/icons/hicolor/22x22/actions/Makefile.am b/data/icons/hicolor/22x22/actions/Makefile.am
index 07b740f..df634a9 100644
--- a/data/icons/hicolor/22x22/actions/Makefile.am
+++ b/data/icons/hicolor/22x22/actions/Makefile.am
@@ -15,9 +15,9 @@ icons_DATA = 				\
 	share.png			\
 	tag.png				\
 	tool-adjust-colors.png		\
+	tool-adjust-contrast.png	\
 	tool-crop.png			\
 	tool-desaturate.png		\
-	tool-enhance.png		\
 	tool-red-eye.png		\
 	tool-resize.png			\
 	tool-rotate.png			\
diff --git a/data/icons/hicolor/22x22/actions/tool-enhance.png b/data/icons/hicolor/22x22/actions/tool-adjust-contrast.png
similarity index 100%
rename from data/icons/hicolor/22x22/actions/tool-enhance.png
rename to data/icons/hicolor/22x22/actions/tool-adjust-contrast.png
diff --git a/extensions/file_tools/Makefile.am b/extensions/file_tools/Makefile.am
index ca57dd3..041ad7c 100644
--- a/extensions/file_tools/Makefile.am
+++ b/extensions/file_tools/Makefile.am
@@ -11,9 +11,9 @@ HEADER_FILES = 				\
 	cairo-blur.h			\
 	cairo-rotate.h			\
 	gth-file-tool-adjust-colors.h	\
+	gth-file-tool-adjust-contrast.h	\
 	gth-file-tool-crop.h		\
 	gth-file-tool-desaturate.h	\
-	gth-file-tool-enhance.h		\
 	gth-file-tool-equalize.h	\
 	gth-file-tool-flip.h		\
 	gth-file-tool-mirror.h		\
@@ -60,9 +60,9 @@ libfile_tools_la_SOURCES = 		\
 	cairo-blur.c			\
 	cairo-rotate.c			\
 	gth-file-tool-adjust-colors.c	\
+	gth-file-tool-adjust-contrast.c	\
 	gth-file-tool-crop.c		\
 	gth-file-tool-desaturate.c	\
-	gth-file-tool-enhance.c		\
 	gth-file-tool-equalize.c	\
 	gth-file-tool-flip.c		\
 	gth-file-tool-mirror.c		\
diff --git a/extensions/file_tools/callbacks.c b/extensions/file_tools/callbacks.c
index 9b5e41d..c3d222b 100644
--- a/extensions/file_tools/callbacks.c
+++ b/extensions/file_tools/callbacks.c
@@ -26,8 +26,8 @@
 #include <gdk/gdkkeysyms.h>
 #include <gthumb.h>
 #include <extensions/image_viewer/gth-image-viewer-page.h>
+#include "gth-file-tool-adjust-contrast.h"
 #include "gth-file-tool-crop.h"
-#include "gth-file-tool-enhance.h"
 #include "gth-file-tool-flip.h"
 #include "gth-file-tool-mirror.h"
 #include "gth-file-tool-resize.h"
@@ -67,7 +67,7 @@ file_tools__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
 
 	switch (event->keyval) {
 	case GDK_KEY_h:
-		tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_ENHANCE);
+		tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST);
 		break;
 	case GDK_KEY_l:
 		tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_FLIP);
diff --git a/extensions/file_tools/gth-file-tool-adjust-contrast.c b/extensions/file_tools/gth-file-tool-adjust-contrast.c
new file mode 100644
index 0000000..e3a9a3c
--- /dev/null
+++ b/extensions/file_tools/gth-file-tool-adjust-contrast.c
@@ -0,0 +1,289 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2012 Free Software Foundation, Inc.
+ *
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <math.h>
+#include <gthumb.h>
+#include <extensions/image_viewer/gth-image-viewer-page.h>
+#include "gth-file-tool-adjust-contrast.h"
+
+
+#define HISTOGRAM_CROP 0.005
+
+
+G_DEFINE_TYPE (GthFileToolAdjustContrast, gth_file_tool_adjust_contrast, GTH_TYPE_FILE_TOOL)
+
+
+typedef struct {
+	GtkWidget        *viewer_page;
+	cairo_surface_t  *source;
+	cairo_surface_t  *destination;
+	int              *lowest;
+	int              *highest;
+	double           *factor;
+} AdjustContrastData;
+
+
+static void
+adjust_contrast_before (GthAsyncTask *task,
+			gpointer      user_data)
+{
+	gth_task_progress (GTH_TASK (task), _("Contrast correction"), NULL, TRUE, 0.0);
+}
+
+
+static void
+adjust_contrast_setup (AdjustContrastData *adjust_data)
+{
+	GthHistogram  *histogram;
+	long         **cumulative;
+	int            c, v;
+	glong          n_pixels;
+	double         lower_threshold;
+	double         higher_threshold;
+
+	/* histogram */
+
+	histogram = gth_histogram_new ();
+	gth_histogram_calculate_for_image (histogram, adjust_data->source);
+	cumulative = gth_histogram_get_cumulative (histogram);
+
+	/* lowest and highest values for each channel */
+
+	adjust_data->lowest = g_new (int, GTH_HISTOGRAM_N_CHANNELS);
+	adjust_data->highest = g_new (int, GTH_HISTOGRAM_N_CHANNELS);
+
+	n_pixels = cairo_image_surface_get_width (adjust_data->source) * cairo_image_surface_get_height (adjust_data->source);
+	lower_threshold = HISTOGRAM_CROP * n_pixels;
+	higher_threshold = (1.0 - HISTOGRAM_CROP) * n_pixels;
+
+	for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++) {
+		gboolean lowest_set = FALSE;
+
+		for (v = 0; v < 256; v++) {
+			if (! lowest_set && (cumulative[c][v] >= lower_threshold)) {
+				adjust_data->lowest[c] = v;
+				lowest_set = TRUE;
+			}
+
+			if (cumulative[c][v] <= higher_threshold)
+				adjust_data->highest[c] = v;
+		}
+	}
+
+	/* stretch factor */
+
+	adjust_data->factor = g_new (double, GTH_HISTOGRAM_N_CHANNELS);
+	for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++) {
+		if (adjust_data->highest[c] != adjust_data->lowest[c])
+			adjust_data->factor[c] = 255.0 / ((double) adjust_data->highest[c] - adjust_data->lowest[c]);
+		else
+			adjust_data->factor[c] = 0.0;
+	}
+
+	/**/
+
+	gth_cumulative_histogram_free (cumulative);
+	g_object_unref (histogram);
+}
+
+
+static guchar
+adjust_contrast_func (AdjustContrastData *adjust_data,
+		      int                 n_channel,
+		      guchar              value)
+{
+	if (value <= adjust_data->lowest[n_channel])
+		return 0;
+	else if (value >= adjust_data->highest[n_channel])
+		return 255;
+	else
+		return (int) (adjust_data->factor[n_channel] * (value - adjust_data->lowest[n_channel]));
+}
+
+
+static gpointer
+adjust_contrast_exec (GthAsyncTask *task,
+		      gpointer      user_data)
+{
+	AdjustContrastData *adjust_data = user_data;
+	cairo_format_t      format;
+	int                 width;
+	int                 height;
+	int                 source_stride;
+	int                 destination_stride;
+	unsigned char      *p_source_line;
+	unsigned char      *p_destination_line;
+	unsigned char      *p_source;
+	unsigned char      *p_destination;
+	gboolean            cancelled;
+	double              progress;
+	gboolean            terminated;
+	int                 x, y;
+	unsigned char       red, green, blue, alpha;
+
+	/* initialize some extra data */
+
+	adjust_contrast_setup (adjust_data);
+
+	/* convert the image */
+
+	format = cairo_image_surface_get_format (adjust_data->source);
+	width = cairo_image_surface_get_width (adjust_data->source);
+	height = cairo_image_surface_get_height (adjust_data->source);
+	source_stride = cairo_image_surface_get_stride (adjust_data->source);
+
+	adjust_data->destination = cairo_image_surface_create (format, width, height);
+	cairo_surface_flush (adjust_data->destination);
+	destination_stride = cairo_image_surface_get_stride (adjust_data->destination);
+	p_source_line = cairo_image_surface_get_data (adjust_data->source);
+	p_destination_line = cairo_image_surface_get_data (adjust_data->destination);
+	for (y = 0; y < height; y++) {
+		gth_async_task_get_data (task, NULL, &cancelled, NULL);
+		if (cancelled)
+			return NULL;
+
+		progress = (double) y / height;
+		gth_async_task_set_data (task, NULL, NULL, &progress);
+
+		p_source = p_source_line;
+		p_destination = p_destination_line;
+		for (x = 0; x < width; x++) {
+			CAIRO_GET_RGBA (p_source, red, green, blue, alpha);
+			red   = adjust_contrast_func (adjust_data, GTH_HISTOGRAM_CHANNEL_RED, red);
+			green = adjust_contrast_func (adjust_data, GTH_HISTOGRAM_CHANNEL_GREEN, green);
+			blue  = adjust_contrast_func (adjust_data, GTH_HISTOGRAM_CHANNEL_BLUE, blue);
+			CAIRO_SET_RGBA (p_destination, red, green, blue, alpha);
+
+			p_source += 4;
+			p_destination += 4;
+		}
+		p_source_line += source_stride;
+		p_destination_line += destination_stride;
+	}
+
+	cairo_surface_mark_dirty (adjust_data->destination);
+	terminated = TRUE;
+	gth_async_task_set_data (task, &terminated, NULL, NULL);
+
+	return NULL;
+}
+
+
+static void
+adjust_contrast_after (GthAsyncTask *task,
+		       GError       *error,
+		       gpointer      user_data)
+{
+	AdjustContrastData *adjust_data = user_data;
+
+	if (error == NULL)
+		gth_image_viewer_page_set_image (GTH_IMAGE_VIEWER_PAGE (adjust_data->viewer_page), adjust_data->destination, TRUE);
+
+	g_free (adjust_data->lowest);
+	adjust_data->lowest = NULL;
+
+	g_free (adjust_data->highest);
+	adjust_data->highest = NULL;
+}
+
+
+static void
+adjust_contrast_data_free (gpointer user_data)
+{
+	AdjustContrastData *adjust_contrast_data = user_data;
+
+	g_object_unref (adjust_contrast_data->viewer_page);
+	cairo_surface_destroy (adjust_contrast_data->destination);
+	cairo_surface_destroy (adjust_contrast_data->source);
+	g_free (adjust_contrast_data);
+}
+
+
+static void
+gth_file_tool_adjust_contrast_activate (GthFileTool *base)
+{
+	GtkWidget          *window;
+	GtkWidget          *viewer_page;
+	GtkWidget          *viewer;
+	cairo_surface_t    *image;
+	AdjustContrastData *adjust_contrast_data;
+	GthTask            *task;
+
+	window = gth_file_tool_get_window (base);
+	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+	if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+		return;
+
+	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+	image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer));
+	if (image == NULL)
+		return;
+
+	adjust_contrast_data = g_new0 (AdjustContrastData, 1);
+	adjust_contrast_data->viewer_page = g_object_ref (viewer_page);
+	adjust_contrast_data->source = cairo_surface_reference (image);
+	adjust_contrast_data->lowest = NULL;
+	adjust_contrast_data->highest = NULL;
+	adjust_contrast_data->factor = NULL;
+	task = gth_async_task_new (adjust_contrast_before,
+				   adjust_contrast_exec,
+				   adjust_contrast_after,
+				   adjust_contrast_data,
+				   adjust_contrast_data_free);
+	gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
+
+	g_object_unref (task);
+}
+
+
+static void
+gth_file_tool_adjust_contrast_update_sensitivity (GthFileTool *base)
+{
+	GtkWidget *window;
+	GtkWidget *viewer_page;
+
+	window = gth_file_tool_get_window (base);
+	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+	if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+		gtk_widget_set_sensitive (GTK_WIDGET (base), FALSE);
+	else
+		gtk_widget_set_sensitive (GTK_WIDGET (base), TRUE);
+}
+
+
+static void
+gth_file_tool_adjust_contrast_init (GthFileToolAdjustContrast *self)
+{
+	gth_file_tool_construct (GTH_FILE_TOOL (self), "tool-adjust-contrast", _("Adjust Contrast"), NULL, TRUE);
+	gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Automatic contrast correction"));
+}
+
+
+static void
+gth_file_tool_adjust_contrast_class_init (GthFileToolAdjustContrastClass *klass)
+{
+	GthFileToolClass *file_tool_class;
+
+	file_tool_class = GTH_FILE_TOOL_CLASS (klass);
+	file_tool_class->update_sensitivity = gth_file_tool_adjust_contrast_update_sensitivity;
+	file_tool_class->activate = gth_file_tool_adjust_contrast_activate;
+}
diff --git a/extensions/file_tools/gth-file-tool-adjust-contrast.h b/extensions/file_tools/gth-file-tool-adjust-contrast.h
new file mode 100644
index 0000000..1fda109
--- /dev/null
+++ b/extensions/file_tools/gth-file-tool-adjust-contrast.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2012 Free Software Foundation, Inc.
+ *
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_FILE_TOOL_ADJUST_CONTRAST_H
+#define GTH_FILE_TOOL_ADJUST_CONTRAST_H
+
+#include <gthumb.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST (gth_file_tool_adjust_contrast_get_type ())
+#define GTH_FILE_TOOL_ADJUST_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST, GthFileToolAdjustContrast))
+#define GTH_FILE_TOOL_ADJUST_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST, GthFileToolAdjustContrastClass))
+#define GTH_IS_FILE_TOOL_ADJUST_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST))
+#define GTH_IS_FILE_TOOL_ADJUST_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST))
+#define GTH_FILE_TOOL_ADJUST_CONTRAST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST, GthFileToolAdjustContrastClass))
+
+typedef struct _GthFileToolAdjustContrast GthFileToolAdjustContrast;
+typedef struct _GthFileToolAdjustContrastClass GthFileToolAdjustContrastClass;
+
+struct _GthFileToolAdjustContrast {
+	GthFileTool parent_instance;
+};
+
+struct _GthFileToolAdjustContrastClass {
+	GthFileToolClass parent_class;
+};
+
+GType  gth_file_tool_adjust_contrast_get_type  (void);
+
+G_END_DECLS
+
+#endif /* GTH_FILE_TOOL_ADJUST_CONTRAST_H */
diff --git a/extensions/file_tools/main.c b/extensions/file_tools/main.c
index 0dbf986..472a5f3 100644
--- a/extensions/file_tools/main.c
+++ b/extensions/file_tools/main.c
@@ -25,9 +25,9 @@
 #include <gthumb.h>
 #include "callbacks.h"
 #include "gth-file-tool-adjust-colors.h"
+#include "gth-file-tool-adjust-contrast.h"
 #include "gth-file-tool-crop.h"
 #include "gth-file-tool-desaturate.h"
-#include "gth-file-tool-enhance.h"
 #include "gth-file-tool-equalize.h"
 #include "gth-file-tool-flip.h"
 #include "gth-file-tool-mirror.h"
@@ -51,7 +51,7 @@ gthumb_extension_activate (void)
 	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_UNDO);
 	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_REDO);
 
-	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_ENHANCE);
+	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST);
 	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_ADJUST_COLORS);
 	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_SHARPEN);
 	gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_EQUALIZE);
diff --git a/gthumb/gth-histogram.c b/gthumb/gth-histogram.c
index 30c50b8..08b798d 100644
--- a/gthumb/gth-histogram.c
+++ b/gthumb/gth-histogram.c
@@ -166,25 +166,25 @@ gth_histogram_calculate_for_image (GthHistogram    *self,
 
 			/* count values for each RGB channel */
 
-			values[1][red] += 1;
-			values[2][green] += 1;
-			values[3][blue] += 1;
+			values[GTH_HISTOGRAM_CHANNEL_RED][red] += 1;
+			values[GTH_HISTOGRAM_CHANNEL_GREEN][green] += 1;
+			values[GTH_HISTOGRAM_CHANNEL_BLUE][blue] += 1;
 			if (has_alpha)
-				values[4][alpha] += 1;
+				values[GTH_HISTOGRAM_CHANNEL_ALPHA][alpha] += 1;
 
 			/* count value for Value channel */
 
 			max = MAX (MAX (red, green), blue);
-			values[0][max] += 1;
+			values[GTH_HISTOGRAM_CHANNEL_VALUE][max] += 1;
 
 			/* track max value for each channel */
 
-			values_max[0] = MAX (values_max[0], values[0][max]);
-			values_max[1] = MAX (values_max[1], values[1][red]);
-			values_max[2] = MAX (values_max[2], values[2][green]);
-			values_max[3] = MAX (values_max[3], values[3][blue]);
+			values_max[GTH_HISTOGRAM_CHANNEL_VALUE] = MAX (values_max[GTH_HISTOGRAM_CHANNEL_VALUE], values[GTH_HISTOGRAM_CHANNEL_VALUE][max]);
+			values_max[GTH_HISTOGRAM_CHANNEL_RED] = MAX (values_max[GTH_HISTOGRAM_CHANNEL_RED], values[GTH_HISTOGRAM_CHANNEL_RED][red]);
+			values_max[GTH_HISTOGRAM_CHANNEL_GREEN] = MAX (values_max[GTH_HISTOGRAM_CHANNEL_GREEN], values[GTH_HISTOGRAM_CHANNEL_GREEN][green]);
+			values_max[GTH_HISTOGRAM_CHANNEL_BLUE] = MAX (values_max[GTH_HISTOGRAM_CHANNEL_BLUE], values[GTH_HISTOGRAM_CHANNEL_BLUE][blue]);
 			if (has_alpha)
-				values_max[4] = MAX (values_max[4], values[4][alpha]);
+				values_max[GTH_HISTOGRAM_CHANNEL_ALPHA] = MAX (values_max[GTH_HISTOGRAM_CHANNEL_ALPHA], values[GTH_HISTOGRAM_CHANNEL_ALPHA][alpha]);
 
 			pixel += 4;
 		}
@@ -275,3 +275,33 @@ gth_histogram_get_nchannels (GthHistogram *self)
 	g_return_val_if_fail (self != NULL, 0.0);
 	return self->priv->n_channels - 1;
 }
+
+
+long **
+gth_histogram_get_cumulative (GthHistogram *self)
+{
+	long **cumulative;
+	int    c, v;
+
+	cumulative = g_new (long *, GTH_HISTOGRAM_N_CHANNELS);
+	for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++) {
+		cumulative[c] = g_new (long, 256);
+		cumulative[c][0] = gth_histogram_get_value (self, c, 0);
+		for (v = 1; v < 256; v++) {
+			cumulative[c][v] = gth_histogram_get_value (self, c, v) + cumulative[c][v - 1];
+		}
+	}
+
+	return cumulative;
+}
+
+
+void
+gth_cumulative_histogram_free (long **cumulative)
+{
+	int c;
+
+	for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++)
+		g_free (cumulative[c]);
+	g_free (cumulative);
+}
diff --git a/gthumb/gth-histogram.h b/gthumb/gth-histogram.h
index 7155bcf..63c191f 100644
--- a/gthumb/gth-histogram.h
+++ b/gthumb/gth-histogram.h
@@ -79,6 +79,8 @@ double         gth_histogram_get_channel_max      (GthHistogram        *self,
 						   GthHistogramChannel  channel);
 double         gth_histogram_get_max              (GthHistogram        *self);
 int            gth_histogram_get_nchannels        (GthHistogram        *self);
+long **        gth_histogram_get_cumulative       (GthHistogram        *self);
+void           gth_cumulative_histogram_free      (long               **cumulative);
 
 G_END_DECLS
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 35d3019..a553983 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -280,12 +280,12 @@ extensions/file_tools/callbacks.h
 [type: gettext/ini]extensions/file_tools/file_tools.extension.in.in
 extensions/file_tools/gth-file-tool-adjust-colors.c
 extensions/file_tools/gth-file-tool-adjust-colors.h
+extensions/file_tools/gth-file-tool-adjust-contrast.c
+extensions/file_tools/gth-file-tool-adjust-contrast.h
 extensions/file_tools/gth-file-tool-crop.c
 extensions/file_tools/gth-file-tool-crop.h
 extensions/file_tools/gth-file-tool-desaturate.c
 extensions/file_tools/gth-file-tool-desaturate.h
-extensions/file_tools/gth-file-tool-enhance.c
-extensions/file_tools/gth-file-tool-enhance.h
 extensions/file_tools/gth-file-tool-equalize.c
 extensions/file_tools/gth-file-tool-equalize.h
 extensions/file_tools/gth-file-tool-flip.c
@@ -316,6 +316,8 @@ extensions/file_tools/gth-image-line-tool.c
 extensions/file_tools/gth-image-line-tool.h
 extensions/file_tools/gth-image-rotator.c
 extensions/file_tools/gth-image-rotator.h
+extensions/file_tools/gth-preview-tool.c
+extensions/file_tools/gth-preview-tool.h
 extensions/file_tools/main.c
 extensions/file_tools/preferences.h
 [type: gettext/ini]extensions/file_viewer/file_viewer.extension.in.in
@@ -680,6 +682,7 @@ gthumb/eggfileformatchooser.h
 gthumb/egg-macros.h
 gthumb/gedit-message-area.c
 gthumb/gedit-message-area.h
+gthumb/gfixed.h
 gthumb/gio-utils.c
 gthumb/gio-utils.h
 gthumb/glib-utils.c



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