annotate src/histogram.c @ 1298:c37f36b97173

added histogram pane
author nadvornik
date Sun, 15 Feb 2009 19:25:55 +0000
parents 7ac9664242b2
children 8d1f9739c06a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
1 /*
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
2 * Geeqie
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1055
diff changeset
3 * Copyright (C) 2008 - 2009 The Geeqie Team
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
4 *
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
5 * Author: Vladimir Nadvornik
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
6 * based on a patch by Uwe Ohse
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
7 *
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
9 * Please read the included file COPYING for more information.
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
11 */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
12
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 273
diff changeset
13 #include "main.h"
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
14 #include "histogram.h"
284
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
15
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
16 #include "pixbuf_util.h"
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
17
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
18 #include <math.h>
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
19
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
20 /*
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
21 *----------------------------------------------------------------------------
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
22 * image histogram
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
23 *----------------------------------------------------------------------------
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
24 */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
25
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
26 #define HISTMAP_SIZE 256
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
27 typedef enum {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
28 HISTMAP_CHANNEL_R = 0,
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
29 HISTMAP_CHANNEL_G,
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
30 HISTMAP_CHANNEL_B,
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
31 HISTMAP_CHANNEL_AVG,
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
32 HISTMAP_CHANNEL_MAX,
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
33 HISTMAP_CHANNELS
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
34 } HistMapChannels;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
35
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
36 struct _HistMap {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
37 gulong histmap[HISTMAP_SIZE * HISTMAP_CHANNELS];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
38 gulong area;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
39 };
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
40
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
41 struct _Histogram {
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
42 gint histogram_chan;
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
43 gint histogram_logmode;
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
44 };
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
45
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
46
609
b690cecbf5b8 Use function(void) instead of function() for declaring functions which
zas_
parents: 475
diff changeset
47 Histogram *histogram_new(void)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
48 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
49 Histogram *histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
50
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
51 histogram = g_new0(Histogram, 1);
612
21864cc96369 Preserve last histogram modes.
zas_
parents: 609
diff changeset
52 histogram->histogram_chan = options->histogram.last_channel_mode;
21864cc96369 Preserve last histogram modes.
zas_
parents: 609
diff changeset
53 histogram->histogram_logmode = options->histogram.last_log_mode;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
54
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
55 return histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
56 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
57
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
58 void histogram_free(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
59 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
60 g_free(histogram);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
61 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
62
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
63
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
64 gint histogram_set_channel(Histogram *histogram, gint chan)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
65 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
66 if (!histogram) return 0;
612
21864cc96369 Preserve last histogram modes.
zas_
parents: 609
diff changeset
67 options->histogram.last_channel_mode = histogram->histogram_chan = chan;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
68 return chan;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
69 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
70
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
71 gint histogram_get_channel(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
72 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
73 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
74 return histogram->histogram_chan;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
75 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
76
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
77 gint histogram_set_mode(Histogram *histogram, gint mode)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
78 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
79 if (!histogram) return 0;
612
21864cc96369 Preserve last histogram modes.
zas_
parents: 609
diff changeset
80 options->histogram.last_log_mode = histogram->histogram_logmode = mode;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
81 return mode;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
82 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
83
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
84 gint histogram_get_mode(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
85 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
86 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
87 return histogram->histogram_logmode;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
88 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
89
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
90 const gchar *histogram_label(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
91 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
92 const gchar *t1 = "";
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
93
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
94 if (!histogram) return NULL;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
95
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
96 if (histogram->histogram_logmode)
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
97 switch (histogram->histogram_chan)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
98 {
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
99 case HCHAN_R: t1 = _("logarithmical histogram on red"); break;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
100 case HCHAN_G: t1 = _("logarithmical histogram on green"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
101 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
102 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
103 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
104 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
105 }
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
106 else
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
107 switch (histogram->histogram_chan)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
108 {
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
109 case HCHAN_R: t1 = _("linear histogram on red"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
110 case HCHAN_G: t1 = _("linear histogram on green"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
111 case HCHAN_B: t1 = _("linear histogram on blue"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
112 case HCHAN_VAL: t1 = _("linear histogram on value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
113 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
114 case HCHAN_MAX: t1 = _("linear histogram on max value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
115 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
116 return t1;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
117 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
118
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
119 static HistMap *histmap_read(GdkPixbuf *imgpixbuf)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
120 {
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
121 gint w, h, i, j, srs, has_alpha, step;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
122 guchar *s_pix;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
123
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
124 HistMap *histmap;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
125
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
126 w = gdk_pixbuf_get_width(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
127 h = gdk_pixbuf_get_height(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
128 srs = gdk_pixbuf_get_rowstride(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
129 s_pix = gdk_pixbuf_get_pixels(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
130 has_alpha = gdk_pixbuf_get_has_alpha(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
131
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
132 histmap = g_new0(HistMap, 1);
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
133
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
134 step = 3 + !!(has_alpha);
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
135 for (i = 0; i < h; i++)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
136 {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
137 guchar *sp = s_pix + (i * srs); /* 8bit */
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
138 for (j = 0; j < w; j++)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
139 {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
140 guint avg = (sp[0] + sp[1] + sp[2]) / 3;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
141 guint max = sp[0];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
142 if (sp[1] > max) max = sp[1];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
143 if (sp[2] > max) max = sp[2];
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
144
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
145 histmap->histmap[sp[0] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]++;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
146 histmap->histmap[sp[1] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]++;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
147 histmap->histmap[sp[2] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]++;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
148 histmap->histmap[avg * HISTMAP_CHANNELS + HISTMAP_CHANNEL_AVG]++;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
149 histmap->histmap[max * HISTMAP_CHANNELS + HISTMAP_CHANNEL_MAX]++;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
150 sp += step;
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
151 }
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
152 }
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
153 histmap->area = w * h;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
154 return histmap;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
155 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
156
1298
c37f36b97173 added histogram pane
nadvornik
parents: 1294
diff changeset
157 const HistMap *histmap_get(FileData *fd)
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
158 {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
159 if (fd->histmap) return fd->histmap;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
160
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
161 if (fd->pixbuf)
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
162 {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
163 fd->histmap = histmap_read(fd->pixbuf);
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
164 return fd->histmap;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
165 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
166 return NULL;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
167 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
168
1298
c37f36b97173 added histogram pane
nadvornik
parents: 1294
diff changeset
169 gint histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
170 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
171 /* FIXME: use the coordinates correctly */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
172 gint i;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
173 gulong max = 0;
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 999
diff changeset
174 gdouble logmax;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
175
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
176 if (!histogram || !histmap) return 0;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
177
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
178 for (i = 0; i < 1024; i++) {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
179 #if 0
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
180 /* this is probably broken for MAX or VAL mode */
287
fd5c62403498 int -> gint
zas_
parents: 284
diff changeset
181 gint flag = 0;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
182
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
183 switch (histogram->histogram_chan)
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
184 {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
185 case HCHAN_RGB: if ((i % HISTMAP_CHANNELS) < 3) flag = 1; break;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
186 case HCHAN_R: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_R) flag = 1; break;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
187 case HCHAN_G: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_G) flag = 1; break;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
188 case HCHAN_B: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_B) flag = 1; break;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
189 case HCHAN_VAL: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_AVG) flag = 1; break;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
190 case HCHAN_MAX: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_MAX) flag = 1; break;
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
191 }
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
192 if (flag && histmap->histmap[i] > max) max = histmap->histmap[i];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
193 #else
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
194 if (histmap->histmap[i] > max) max = histmap->histmap[i];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
195 #endif
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
196 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
197
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
198 logmax = log(max);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
199 for (i = 0; i < width; i++)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
200 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
201 gint j;
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
202 glong v[4] = {0, 0, 0, 0};
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
203 gint rplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
204 gint gplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
205 gint bplus = 0;
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
206 gint ii = i * HISTMAP_SIZE / width;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
207 gint combine = (HISTMAP_SIZE - 1) / width + 1;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
208
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
209 for (j = 0; j < combine; j++)
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
210 {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
211 v[0] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]; // r
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
212 v[1] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]; // g
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
213 v[2] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]; // b
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
214 v[3] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS +
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
215 ((histogram->histogram_chan == HCHAN_VAL) ? HISTMAP_CHANNEL_AVG : HISTMAP_CHANNEL_MAX)]; // value, max
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
216 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
217
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
218 for (j = 0; j < 4; j++)
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
219 {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
220 v[j] /= combine;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
221 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
222
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
223 for (j = 0; j < 4; j++)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
224 {
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
225 gint max2 = 0;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
226 gint k;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
227
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
228 for (k = 1; k < 4; k++)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
229 if (v[k] > v[max2]) max2 = k;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
230
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
231 if (histogram->histogram_chan >= HCHAN_RGB
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
232 || max2 == histogram->histogram_chan)
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
233 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
234 gulong pt;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
235 gint r = rplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
236 gint g = gplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
237 gint b = bplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
238
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
239 switch (max2)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
240 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
241 case HCHAN_R: rplus = r = 255; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
242 case HCHAN_G: gplus = g = 255; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
243 case HCHAN_B: bplus = b = 255; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
244 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
245
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
246 switch (histogram->histogram_chan)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
247 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
248 case HCHAN_RGB:
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
249 if (r == 255 && g == 255 && b == 255)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
250 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
251 r = 0; b = 0; g = 0;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
252 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
253 break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
254 case HCHAN_R: b = 0; g = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
255 case HCHAN_G: r = 0; b = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
256 case HCHAN_B: r = 0; g = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
257 case HCHAN_MAX:
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
258 case HCHAN_VAL: r = 0; b = 0; g = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
259 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
260
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
261 if (v[max2] == 0)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
262 pt = 0;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
263 else if (histogram->histogram_logmode)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
264 pt = ((float)log(v[max2])) / logmax * (height - 1);
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
265 else
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
266 pt = ((float)v[max2])/ max * (height - 1);
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
267
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
268 pixbuf_draw_line(pixbuf,
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
269 x, y, width, height,
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
270 x + i, y + height, x + i, y + height - pt,
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
271 r, g, b, 255);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
272 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
273 v[max2] = -1;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
274 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
275 }
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
276
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
277 return TRUE;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
278 }
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
279
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
280 void histogram_notify_cb(FileData *fd, NotifyType type, gpointer data)
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
281 {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
282 if (type != NOTIFY_TYPE_INTERNAL && fd->histmap)
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
283 {
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
284 g_free(fd->histmap);
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
285 fd->histmap = NULL;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
286 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
287 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
288
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1000
diff changeset
289 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */