[gthumb] histogram: use an enumerable type to specify the channel
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] histogram: use an enumerable type to specify the channel
- Date: Thu, 20 Jan 2011 20:19:57 +0000 (UTC)
commit 0ee76ebbf702222ba7bc4d7605c330612fc54d22
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Jan 17 21:39:26 2011 +0100
histogram: use an enumerable type to specify the channel
extensions/file_tools/gth-file-tool-enhance.c | 6 ++-
extensions/file_tools/gth-file-tool-equalize.c | 6 ++--
gthumb/gth-histogram.c | 30 +++++++++---------
gthumb/gth-histogram.h | 39 ++++++++++++++----------
4 files changed, 45 insertions(+), 36 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-enhance.c b/extensions/file_tools/gth-file-tool-enhance.c
index a790599..0d3a8da 100644
--- a/extensions/file_tools/gth-file-tool-enhance.c
+++ b/extensions/file_tools/gth-file-tool-enhance.c
@@ -119,7 +119,7 @@ adjust_levels_init (GthPixbufTask *pixop)
data->levels = g_new0 (Levels, 1);
- for (channel = 0; channel < MAX_N_CHANNELS + 1; channel++) {
+ for (channel = 0; channel < GTH_HISTOGRAM_N_CHANNELS + 1; channel++) {
data->levels->gamma[channel] = 1.0;
data->levels->low_input[channel] = 0;
data->levels->high_input[channel] = 255;
@@ -127,7 +127,7 @@ adjust_levels_init (GthPixbufTask *pixop)
data->levels->high_output[channel] = 255;
}
- for (channel = 1; channel < MAX_N_CHANNELS; channel++)
+ for (channel = 1; channel < GTH_HISTOGRAM_N_CHANNELS; channel++)
levels_channel_auto (data->levels, data->hist, channel);
}
@@ -209,7 +209,9 @@ adjust_levels_release (GthPixbufTask *pixop,
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (data->viewer_page), pixop->dest, TRUE);
g_object_unref (data->hist);
+ data->hist = NULL;
g_free (data->levels);
+ data->levels = NULL;
}
diff --git a/extensions/file_tools/gth-file-tool-equalize.c b/extensions/file_tools/gth-file-tool-equalize.c
index 117b955..6d6850d 100644
--- a/extensions/file_tools/gth-file-tool-equalize.c
+++ b/extensions/file_tools/gth-file-tool-equalize.c
@@ -84,8 +84,8 @@ equalize_init (GthPixbufTask *pixop)
data->histogram = gth_histogram_new ();
gth_histogram_calculate (data->histogram, pixop->src);
- data->part = g_new0 (int *, MAX_N_CHANNELS + 1);
- for (i = 0; i < MAX_N_CHANNELS + 1; i++)
+ data->part = g_new0 (int *, GTH_HISTOGRAM_N_CHANNELS + 1);
+ for (i = 0; i < GTH_HISTOGRAM_N_CHANNELS + 1; i++)
data->part[i] = g_new0 (int, 257);
equalize_histogram_setup (data->histogram, data->part);
}
@@ -126,7 +126,7 @@ equalize_release (GthPixbufTask *pixop,
if (error == NULL)
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (data->viewer_page), pixop->dest, TRUE);
- for (i = 0; i < MAX_N_CHANNELS + 1; i++)
+ for (i = 0; i < GTH_HISTOGRAM_N_CHANNELS + 1; i++)
g_free (data->part[i]);
g_free (data->part);
g_object_unref (data->histogram);
diff --git a/gthumb/gth-histogram.c b/gthumb/gth-histogram.c
index a64be96..71fbfae 100644
--- a/gthumb/gth-histogram.c
+++ b/gthumb/gth-histogram.c
@@ -24,9 +24,6 @@
#include "gth-histogram.h"
-#define MAX_N_CHANNELS 4
-
-
/* Signals */
enum {
CHANGED,
@@ -49,9 +46,12 @@ static void
gth_histogram_finalize (GObject *object)
{
GthHistogram *self;
+ int i;
self = GTH_HISTOGRAM (object);
+ for (i = 0; i < GTH_HISTOGRAM_N_CHANNELS + 1; i++)
+ g_free (self->priv->values[i]);
g_free (self->priv->values);
g_free (self->priv->values_max);
@@ -90,10 +90,10 @@ gth_histogram_init (GthHistogram *self)
int i;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_HISTOGRAM, GthHistogramPrivate);
- self->priv->values = g_new0 (int *, MAX_N_CHANNELS + 1);
- for (i = 0; i < MAX_N_CHANNELS + 1; i++)
+ self->priv->values = g_new0 (int *, GTH_HISTOGRAM_N_CHANNELS + 1);
+ for (i = 0; i < GTH_HISTOGRAM_N_CHANNELS + 1; i++)
self->priv->values[i] = g_new0 (int, 256);
- self->priv->values_max = g_new0 (int, MAX_N_CHANNELS + 1);
+ self->priv->values_max = g_new0 (int, GTH_HISTOGRAM_N_CHANNELS + 1);
}
@@ -136,7 +136,7 @@ histogram_reset_values (GthHistogram *self)
{
int i;
- for (i = 0; i < MAX_N_CHANNELS + 1; i++) {
+ for (i = 0; i < GTH_HISTOGRAM_N_CHANNELS + 1; i++) {
memset (self->priv->values[i], 0, sizeof (int) * 256);
self->priv->values_max[i] = 0;
}
@@ -234,9 +234,9 @@ gth_histogram_get_count (GthHistogram *self,
double
-gth_histogram_get_value (GthHistogram *self,
- int channel,
- int bin)
+gth_histogram_get_value (GthHistogram *self,
+ GthHistogramChannel channel,
+ int bin)
{
g_return_val_if_fail (self != NULL, 0.0);
@@ -248,9 +248,9 @@ gth_histogram_get_value (GthHistogram *self,
double
-gth_histogram_get_channel (GthHistogram *self,
- int channel,
- int bin)
+gth_histogram_get_channel (GthHistogram *self,
+ GthHistogramChannel channel,
+ int bin)
{
g_return_val_if_fail (self != NULL, 0.0);
@@ -262,8 +262,8 @@ gth_histogram_get_channel (GthHistogram *self,
double
-gth_histogram_get_channel_max (GthHistogram *self,
- int channel)
+gth_histogram_get_channel_max (GthHistogram *self,
+ GthHistogramChannel channel)
{
g_return_val_if_fail (self != NULL, 0.0);
diff --git a/gthumb/gth-histogram.h b/gthumb/gth-histogram.h
index 323e0ec..7ac61a4 100644
--- a/gthumb/gth-histogram.h
+++ b/gthumb/gth-histogram.h
@@ -38,7 +38,14 @@ typedef struct _GthHistogram GthHistogram;
typedef struct _GthHistogramPrivate GthHistogramPrivate;
typedef struct _GthHistogramClass GthHistogramClass;
-#define MAX_N_CHANNELS 4
+typedef enum {
+ GTH_HISTOGRAM_CHANNEL_VALUE = 0,
+ GTH_HISTOGRAM_CHANNEL_RED,
+ GTH_HISTOGRAM_CHANNEL_GREEN,
+ GTH_HISTOGRAM_CHANNEL_BLUE,
+ GTH_HISTOGRAM_CHANNEL_ALPHA,
+ GTH_HISTOGRAM_N_CHANNELS
+} GthHistogramChannel;
struct _GthHistogram
{
@@ -56,21 +63,21 @@ struct _GthHistogramClass {
GType gth_histogram_get_type (void) G_GNUC_CONST;
GthHistogram * gth_histogram_new (void);
-void gth_histogram_calculate (GthHistogram *self,
- const GdkPixbuf *pixbuf);
-double gth_histogram_get_count (GthHistogram *self,
- int start,
- int end);
-double gth_histogram_get_value (GthHistogram *self,
- int channel,
- int bin);
-double gth_histogram_get_channel (GthHistogram *self,
- int channel,
- int bin);
-double gth_histogram_get_channel_max (GthHistogram *self,
- int channel);
-double gth_histogram_get_max (GthHistogram *self);
-int gth_histogram_get_nchannels (GthHistogram *self);
+void gth_histogram_calculate (GthHistogram *self,
+ const GdkPixbuf *pixbuf);
+double gth_histogram_get_count (GthHistogram *self,
+ int start,
+ int end);
+double gth_histogram_get_value (GthHistogram *self,
+ GthHistogramChannel channel,
+ int bin);
+double gth_histogram_get_channel (GthHistogram *self,
+ GthHistogramChannel channel,
+ int bin);
+double gth_histogram_get_channel_max (GthHistogram *self,
+ GthHistogramChannel channel);
+double gth_histogram_get_max (GthHistogram *self);
+int gth_histogram_get_nchannels (GthHistogram *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]