Mercurial > geeqie
annotate src/histogram.c @ 1099:b2d120fa5ee7
Use col tags with id in top and bottom navigation tables.
author | zas_ |
---|---|
date | Sat, 08 Nov 2008 17:24:02 +0000 |
parents | 1646720364cf |
children | 8b89e3ff286b |
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 |
475 | 3 * Copyright (C) 2008 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 |
290 | 26 #define HISTOGRAM_SIZE 256 |
442 | 27 |
290 | 28 struct _Histogram { |
29 gulong histmap[HISTOGRAM_SIZE*4]; | |
30 gint histogram_chan; | |
31 gint histogram_logmode; | |
32 }; | |
33 | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
34 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
475
diff
changeset
|
35 Histogram *histogram_new(void) |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
36 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
37 Histogram *histogram; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
38 |
442 | 39 histogram = g_new0(Histogram, 1); |
612 | 40 histogram->histogram_chan = options->histogram.last_channel_mode; |
41 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
|
42 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
43 return histogram; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
44 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
45 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
46 void histogram_free(Histogram *histogram) |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
47 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
48 g_free(histogram); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
49 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
50 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
51 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
52 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
|
53 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
54 if (!histogram) return 0; |
612 | 55 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
|
56 return chan; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
59 gint histogram_get_channel(Histogram *histogram) |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
60 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
61 if (!histogram) return 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
62 return histogram->histogram_chan; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
65 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
|
66 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
67 if (!histogram) return 0; |
612 | 68 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
|
69 return mode; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
72 gint histogram_get_mode(Histogram *histogram) |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
73 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
74 if (!histogram) return 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
75 return histogram->histogram_logmode; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
78 const gchar *histogram_label(Histogram *histogram) |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
79 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
80 const gchar *t1 = ""; |
999 | 81 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
82 if (!histogram) return NULL; |
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 if (histogram->histogram_logmode) |
999 | 85 switch (histogram->histogram_chan) |
442 | 86 { |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
87 case HCHAN_R: t1 = _("logarithmical histogram on red"); break; |
442 | 88 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; |
89 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; | |
90 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break; | |
91 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; | |
92 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; | |
93 } | |
999 | 94 else |
95 switch (histogram->histogram_chan) | |
442 | 96 { |
97 case HCHAN_R: t1 = _("linear histogram on red"); break; | |
98 case HCHAN_G: t1 = _("linear histogram on green"); break; | |
99 case HCHAN_B: t1 = _("linear histogram on blue"); break; | |
100 case HCHAN_VAL: t1 = _("linear histogram on value"); break; | |
101 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break; | |
102 case HCHAN_MAX: t1 = _("linear histogram on max value"); break; | |
103 } | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
104 return t1; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
105 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
106 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
107 gulong histogram_read(Histogram *histogram, GdkPixbuf *imgpixbuf) |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
108 { |
462 | 109 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
|
110 guchar *s_pix; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
111 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
112 if (!histogram) return 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
113 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
114 w = gdk_pixbuf_get_width(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
115 h = gdk_pixbuf_get_height(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
116 srs = gdk_pixbuf_get_rowstride(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
117 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
|
118 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
|
119 |
461
65475285957d
histogram_read(): use memset() to initialize histogram data instead of for() loop.
zas_
parents:
442
diff
changeset
|
120 memset(histogram->histmap, 0, sizeof(histogram->histmap)); |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
121 |
462 | 122 /* code duplication is here to speed up the calculation */ |
123 step = 3 + !!(has_alpha); | |
124 if (histogram->histogram_chan == HCHAN_MAX) | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
125 { |
462 | 126 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
|
127 { |
462 | 128 guchar *sp = s_pix + (i * srs); /* 8bit */ |
129 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
|
130 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
131 guchar t = sp[0]; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
132 if (sp[1]>t) t = sp[1]; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
133 if (sp[2]>t) t = sp[2]; |
462 | 134 |
135 histogram->histmap[sp[0] + 0 * HISTOGRAM_SIZE]++; | |
136 histogram->histmap[sp[1] + 1 * HISTOGRAM_SIZE]++; | |
137 histogram->histmap[sp[2] + 2 * HISTOGRAM_SIZE]++; | |
138 histogram->histmap[t + 3 * HISTOGRAM_SIZE]++; | |
139 sp += step; | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
140 } |
462 | 141 } |
142 } | |
143 else | |
144 { | |
145 for (i = 0; i < h; i++) | |
146 { | |
147 guchar *sp = s_pix + (i * srs); /* 8bit */ | |
148 for (j = 0; j < w; j++) | |
149 { | |
150 histogram->histmap[sp[0] + 0 * HISTOGRAM_SIZE]++; | |
151 histogram->histmap[sp[1] + 1 * HISTOGRAM_SIZE]++; | |
152 histogram->histmap[sp[2] + 2 * HISTOGRAM_SIZE]++; | |
153 histogram->histmap[3 * HISTOGRAM_SIZE + (sp[0]+sp[1]+sp[2])/3]++; | |
154 sp += step; | |
155 } | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
156 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
157 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
158 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
159 return w*h; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
160 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
161 |
287 | 162 gint histogram_draw(Histogram *histogram, 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
|
163 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
164 /* FIXME: use the coordinates correctly */ |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
165 gint i; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
166 gulong max = 0; |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
999
diff
changeset
|
167 gdouble logmax; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
168 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
169 if (!histogram) return 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
170 |
463 | 171 for (i = 0; i < 1024; i++) { |
287 | 172 gint flag = 0; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
173 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
174 switch (histogram->histogram_chan) |
999 | 175 { |
176 case HCHAN_RGB: if ((i%4) != 3) flag = 1; break; | |
177 case HCHAN_R: if ((i%4) == 0) flag = 1; break; | |
178 case HCHAN_G: if ((i%4) == 1) flag = 1; break; | |
179 case HCHAN_B: if ((i%4) == 2) flag = 1; break; | |
180 case HCHAN_VAL: if ((i%4) == 3) flag = 1; break; | |
181 case HCHAN_MAX: if ((i%4) == 3) flag = 1; break; | |
182 } | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
183 if (flag && histogram->histmap[i] > max) max = histogram->histmap[i]; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
184 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
185 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
186 logmax = log(max); |
463 | 187 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
|
188 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
189 gint j; |
290 | 190 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
|
191 gint rplus = 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
192 gint gplus = 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
193 gint bplus = 0; |
290 | 194 gint ii = i * HISTOGRAM_SIZE / width; |
195 gint combine = (HISTOGRAM_SIZE - 1) / width + 1; | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
196 |
290 | 197 for (j = 0; j < combine; j++) |
198 { | |
463 | 199 v[0] += histogram->histmap[ii + j + 0 * HISTOGRAM_SIZE]; // r |
200 v[1] += histogram->histmap[ii + j + 1 * HISTOGRAM_SIZE]; // g | |
201 v[2] += histogram->histmap[ii + j + 2 * HISTOGRAM_SIZE]; // b | |
202 v[3] += histogram->histmap[ii + j + 3 * HISTOGRAM_SIZE]; // value, max | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
203 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
204 |
463 | 205 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
|
206 { |
463 | 207 gint max2 = 0; |
208 gint k; | |
209 | |
210 for (k = 1; k < 4; k++) | |
211 if (v[k] > v[max2]) max2 = k; | |
212 | |
442 | 213 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
|
214 || max2 == histogram->histogram_chan) |
463 | 215 { |
216 gulong pt; | |
217 gint r = rplus; | |
218 gint g = gplus; | |
219 gint b = bplus; | |
220 | |
221 switch (max2) | |
222 { | |
223 case HCHAN_R: rplus = r = 255; break; | |
224 case HCHAN_G: gplus = g = 255; break; | |
225 case HCHAN_B: bplus = b = 255; break; | |
226 } | |
227 | |
228 switch (histogram->histogram_chan) | |
229 { | |
230 case HCHAN_RGB: | |
231 if (r == 255 && g == 255 && b == 255) | |
232 { | |
233 r = 0; b = 0; g = 0; | |
234 } | |
235 break; | |
236 case HCHAN_R: b = 0; g = 0; break; | |
237 case HCHAN_G: r = 0; b = 0; break; | |
238 case HCHAN_B: r = 0; g = 0; break; | |
239 case HCHAN_MAX: | |
240 case HCHAN_VAL: r = 0; b = 0; g = 0; break; | |
241 } | |
242 | |
243 if (v[max2] == 0) | |
244 pt = 0; | |
245 else if (histogram->histogram_logmode) | |
246 pt = ((float)log(v[max2])) / logmax * (height - 1); | |
247 else | |
248 pt = ((float)v[max2])/ max * (height - 1); | |
249 | |
442 | 250 pixbuf_draw_line(pixbuf, |
290 | 251 x, y, width, height, |
463 | 252 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
|
253 r, g, b, 255); |
463 | 254 } |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
255 v[max2] = -1; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
256 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
257 } |
463 | 258 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
259 return TRUE; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
260 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
261 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |