Mercurial > geeqie
annotate src/histogram.c @ 1298:c37f36b97173
added histogram pane
author | nadvornik |
---|---|
date | Sun, 15 Feb 2009 19:25:55 +0000 |
parents | 7ac9664242b2 |
children | 8d1f9739c06a |
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 | 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 | 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 | 15 |
16 #include "pixbuf_util.h" | |
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 | 26 #define HISTMAP_SIZE 256 |
27 typedef enum { | |
28 HISTMAP_CHANNEL_R = 0, | |
29 HISTMAP_CHANNEL_G, | |
30 HISTMAP_CHANNEL_B, | |
31 HISTMAP_CHANNEL_AVG, | |
32 HISTMAP_CHANNEL_MAX, | |
33 HISTMAP_CHANNELS | |
34 } HistMapChannels; | |
35 | |
36 struct _HistMap { | |
37 gulong histmap[HISTMAP_SIZE * HISTMAP_CHANNELS]; | |
38 gulong area; | |
39 }; | |
442 | 40 |
290 | 41 struct _Histogram { |
42 gint histogram_chan; | |
43 gint histogram_logmode; | |
44 }; | |
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 | 51 histogram = g_new0(Histogram, 1); |
612 | 52 histogram->histogram_chan = options->histogram.last_channel_mode; |
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 | 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 | 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 | 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 | 97 switch (histogram->histogram_chan) |
442 | 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 | 100 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; |
101 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; | |
102 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break; | |
103 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; | |
104 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; | |
105 } | |
999 | 106 else |
107 switch (histogram->histogram_chan) | |
442 | 108 { |
109 case HCHAN_R: t1 = _("linear histogram on red"); break; | |
110 case HCHAN_G: t1 = _("linear histogram on green"); break; | |
111 case HCHAN_B: t1 = _("linear histogram on blue"); break; | |
112 case HCHAN_VAL: t1 = _("linear histogram on value"); break; | |
113 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break; | |
114 case HCHAN_MAX: t1 = _("linear histogram on max value"); break; | |
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 | 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 | 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 | 124 HistMap *histmap; |
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 | 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 | 134 step = 3 + !!(has_alpha); |
1294 | 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 | 137 guchar *sp = s_pix + (i * srs); /* 8bit */ |
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 | 140 guint avg = (sp[0] + sp[1] + sp[2]) / 3; |
141 guint max = sp[0]; | |
142 if (sp[1] > max) max = sp[1]; | |
143 if (sp[2] > max) max = sp[2]; | |
462 | 144 |
1294 | 145 histmap->histmap[sp[0] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]++; |
146 histmap->histmap[sp[1] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]++; | |
147 histmap->histmap[sp[2] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]++; | |
148 histmap->histmap[avg * HISTMAP_CHANNELS + HISTMAP_CHANNEL_AVG]++; | |
149 histmap->histmap[max * HISTMAP_CHANNELS + HISTMAP_CHANNEL_MAX]++; | |
150 sp += step; | |
462 | 151 } |
152 } | |
1294 | 153 histmap->area = w * h; |
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 | 157 const HistMap *histmap_get(FileData *fd) |
1294 | 158 { |
159 if (fd->histmap) return fd->histmap; | |
160 | |
161 if (fd->pixbuf) | |
162 { | |
163 fd->histmap = histmap_read(fd->pixbuf); | |
164 return fd->histmap; | |
165 } | |
166 return NULL; | |
167 } | |
168 | |
1298 | 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 | 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 | 178 for (i = 0; i < 1024; i++) { |
1294 | 179 #if 0 |
180 /* this is probably broken for MAX or VAL mode */ | |
287 | 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 | 184 { |
1294 | 185 case HCHAN_RGB: if ((i % HISTMAP_CHANNELS) < 3) flag = 1; break; |
186 case HCHAN_R: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_R) flag = 1; break; | |
187 case HCHAN_G: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_G) flag = 1; break; | |
188 case HCHAN_B: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_B) flag = 1; break; | |
189 case HCHAN_VAL: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_AVG) flag = 1; break; | |
190 case HCHAN_MAX: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_MAX) flag = 1; break; | |
999 | 191 } |
1294 | 192 if (flag && histmap->histmap[i] > max) max = histmap->histmap[i]; |
193 #else | |
194 if (histmap->histmap[i] > max) max = histmap->histmap[i]; | |
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 | 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 | 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 | 206 gint ii = i * HISTMAP_SIZE / width; |
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 | 209 for (j = 0; j < combine; j++) |
210 { | |
1294 | 211 v[0] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]; // r |
212 v[1] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]; // g | |
213 v[2] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]; // b | |
214 v[3] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + | |
215 ((histogram->histogram_chan == HCHAN_VAL) ? HISTMAP_CHANNEL_AVG : HISTMAP_CHANNEL_MAX)]; // value, max | |
216 } | |
217 | |
218 for (j = 0; j < 4; j++) | |
219 { | |
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 | 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 | 225 gint max2 = 0; |
226 gint k; | |
227 | |
228 for (k = 1; k < 4; k++) | |
229 if (v[k] > v[max2]) max2 = k; | |
230 | |
442 | 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 | 233 { |
234 gulong pt; | |
235 gint r = rplus; | |
236 gint g = gplus; | |
237 gint b = bplus; | |
238 | |
239 switch (max2) | |
240 { | |
241 case HCHAN_R: rplus = r = 255; break; | |
242 case HCHAN_G: gplus = g = 255; break; | |
243 case HCHAN_B: bplus = b = 255; break; | |
244 } | |
245 | |
246 switch (histogram->histogram_chan) | |
247 { | |
248 case HCHAN_RGB: | |
249 if (r == 255 && g == 255 && b == 255) | |
250 { | |
251 r = 0; b = 0; g = 0; | |
252 } | |
253 break; | |
254 case HCHAN_R: b = 0; g = 0; break; | |
255 case HCHAN_G: r = 0; b = 0; break; | |
256 case HCHAN_B: r = 0; g = 0; break; | |
257 case HCHAN_MAX: | |
258 case HCHAN_VAL: r = 0; b = 0; g = 0; break; | |
259 } | |
260 | |
261 if (v[max2] == 0) | |
262 pt = 0; | |
263 else if (histogram->histogram_logmode) | |
264 pt = ((float)log(v[max2])) / logmax * (height - 1); | |
265 else | |
266 pt = ((float)v[max2])/ max * (height - 1); | |
267 | |
442 | 268 pixbuf_draw_line(pixbuf, |
290 | 269 x, y, width, height, |
463 | 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 | 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 | 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 | 279 |
280 void histogram_notify_cb(FileData *fd, NotifyType type, gpointer data) | |
281 { | |
282 if (type != NOTIFY_TYPE_INTERNAL && fd->histmap) | |
283 { | |
284 g_free(fd->histmap); | |
285 fd->histmap = NULL; | |
286 } | |
287 } | |
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: */ |