Mercurial > geeqie
comparison src/histogram.c @ 1303:9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
author | zas_ |
---|---|
date | Sat, 21 Feb 2009 10:33:56 +0000 |
parents | 8d1f9739c06a |
children | edeb07e1da5d |
comparison
equal
deleted
inserted
replaced
1302:8d1f9739c06a | 1303:9669104eb58a |
---|---|
37 gulong histmap[HISTMAP_SIZE * HISTMAP_CHANNELS]; | 37 gulong histmap[HISTMAP_SIZE * HISTMAP_CHANNELS]; |
38 gulong area; | 38 gulong area; |
39 }; | 39 }; |
40 | 40 |
41 struct _Histogram { | 41 struct _Histogram { |
42 gint histogram_chan; | 42 gint channel_mode; |
43 gint histogram_logmode; | 43 gint log_mode; |
44 guint histogram_vgrid; /* number of vertical divisions, 0 for none */ | 44 guint vgrid; /* number of vertical divisions, 0 for none */ |
45 guint histogram_hgrid; /* number of horizontal divisions, 0 for none */ | 45 guint hgrid; /* number of horizontal divisions, 0 for none */ |
46 | 46 |
47 }; | 47 }; |
48 | 48 |
49 Histogram *histogram_new(void) | 49 Histogram *histogram_new(void) |
50 { | 50 { |
51 Histogram *histogram; | 51 Histogram *histogram; |
52 | 52 |
53 histogram = g_new0(Histogram, 1); | 53 histogram = g_new0(Histogram, 1); |
54 histogram->histogram_chan = options->histogram.last_channel_mode; | 54 histogram->channel_mode = options->histogram.last_channel_mode; |
55 histogram->histogram_logmode = options->histogram.last_log_mode; | 55 histogram->log_mode = options->histogram.last_log_mode; |
56 histogram->histogram_vgrid = 5; | 56 histogram->vgrid = 5; |
57 histogram->histogram_hgrid = 3; | 57 histogram->hgrid = 3; |
58 | 58 |
59 return histogram; | 59 return histogram; |
60 } | 60 } |
61 | 61 |
62 void histogram_free(Histogram *histogram) | 62 void histogram_free(Histogram *histogram) |
66 | 66 |
67 | 67 |
68 gint histogram_set_channel(Histogram *histogram, gint chan) | 68 gint histogram_set_channel(Histogram *histogram, gint chan) |
69 { | 69 { |
70 if (!histogram) return 0; | 70 if (!histogram) return 0; |
71 options->histogram.last_channel_mode = histogram->histogram_chan = chan; | 71 options->histogram.last_channel_mode = histogram->channel_mode = chan; |
72 return chan; | 72 return chan; |
73 } | 73 } |
74 | 74 |
75 gint histogram_get_channel(Histogram *histogram) | 75 gint histogram_get_channel(Histogram *histogram) |
76 { | 76 { |
77 if (!histogram) return 0; | 77 if (!histogram) return 0; |
78 return histogram->histogram_chan; | 78 return histogram->channel_mode; |
79 } | 79 } |
80 | 80 |
81 gint histogram_set_mode(Histogram *histogram, gint mode) | 81 gint histogram_set_mode(Histogram *histogram, gint mode) |
82 { | 82 { |
83 if (!histogram) return 0; | 83 if (!histogram) return 0; |
84 options->histogram.last_log_mode = histogram->histogram_logmode = mode; | 84 options->histogram.last_log_mode = histogram->log_mode = mode; |
85 return mode; | 85 return mode; |
86 } | 86 } |
87 | 87 |
88 gint histogram_get_mode(Histogram *histogram) | 88 gint histogram_get_mode(Histogram *histogram) |
89 { | 89 { |
90 if (!histogram) return 0; | 90 if (!histogram) return 0; |
91 return histogram->histogram_logmode; | 91 return histogram->log_mode; |
92 } | 92 } |
93 | 93 |
94 const gchar *histogram_label(Histogram *histogram) | 94 const gchar *histogram_label(Histogram *histogram) |
95 { | 95 { |
96 const gchar *t1 = ""; | 96 const gchar *t1 = ""; |
97 | 97 |
98 if (!histogram) return NULL; | 98 if (!histogram) return NULL; |
99 | 99 |
100 if (histogram->histogram_logmode) | 100 if (histogram->log_mode) |
101 switch (histogram->histogram_chan) | 101 switch (histogram->channel_mode) |
102 { | 102 { |
103 case HCHAN_R: t1 = _("logarithmical histogram on red"); break; | 103 case HCHAN_R: t1 = _("logarithmical histogram on red"); break; |
104 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; | 104 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; |
105 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; | 105 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; |
106 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break; | 106 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break; |
107 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; | 107 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; |
108 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; | 108 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; |
109 } | 109 } |
110 else | 110 else |
111 switch (histogram->histogram_chan) | 111 switch (histogram->channel_mode) |
112 { | 112 { |
113 case HCHAN_R: t1 = _("linear histogram on red"); break; | 113 case HCHAN_R: t1 = _("linear histogram on red"); break; |
114 case HCHAN_G: t1 = _("linear histogram on green"); break; | 114 case HCHAN_G: t1 = _("linear histogram on green"); break; |
115 case HCHAN_B: t1 = _("linear histogram on blue"); break; | 115 case HCHAN_B: t1 = _("linear histogram on blue"); break; |
116 case HCHAN_VAL: t1 = _("linear histogram on value"); break; | 116 case HCHAN_VAL: t1 = _("linear histogram on value"); break; |
175 static gint c = 160; | 175 static gint c = 160; |
176 static gint alpha = 250; | 176 static gint alpha = 250; |
177 guint i; | 177 guint i; |
178 float add; | 178 float add; |
179 | 179 |
180 if (histogram->histogram_vgrid == 0) return; | 180 if (histogram->vgrid == 0) return; |
181 | 181 |
182 add = width / (float)histogram->histogram_vgrid; | 182 add = width / (float)histogram->vgrid; |
183 | 183 |
184 for (i = 1; i < histogram->histogram_vgrid; i++) | 184 for (i = 1; i < histogram->vgrid; i++) |
185 { | 185 { |
186 gint xpos = x + (int)(i * add + 0.5); | 186 gint xpos = x + (int)(i * add + 0.5); |
187 | 187 |
188 pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height, c, c, c, alpha); | 188 pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height, c, c, c, alpha); |
189 } | 189 } |
194 static gint c = 160; | 194 static gint c = 160; |
195 static gint alpha = 250; | 195 static gint alpha = 250; |
196 guint i; | 196 guint i; |
197 float add; | 197 float add; |
198 | 198 |
199 if (histogram->histogram_hgrid == 0) return; | 199 if (histogram->hgrid == 0) return; |
200 | 200 |
201 add = height / (float)histogram->histogram_hgrid; | 201 add = height / (float)histogram->hgrid; |
202 | 202 |
203 for (i = 1; i < histogram->histogram_hgrid; i++) | 203 for (i = 1; i < histogram->hgrid; i++) |
204 { | 204 { |
205 gint ypos = y + (int)(i * add + 0.5); | 205 gint ypos = y + (int)(i * add + 0.5); |
206 | 206 |
207 pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos, c, c, c, alpha); | 207 pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos, c, c, c, alpha); |
208 } | 208 } |
224 for (i = 0; i < 1024; i++) { | 224 for (i = 0; i < 1024; i++) { |
225 #if 0 | 225 #if 0 |
226 /* this is probably broken for MAX or VAL mode */ | 226 /* this is probably broken for MAX or VAL mode */ |
227 gint flag = 0; | 227 gint flag = 0; |
228 | 228 |
229 switch (histogram->histogram_chan) | 229 switch (histogram->channel_mode) |
230 { | 230 { |
231 case HCHAN_RGB: if ((i % HISTMAP_CHANNELS) < 3) flag = 1; break; | 231 case HCHAN_RGB: if ((i % HISTMAP_CHANNELS) < 3) flag = 1; break; |
232 case HCHAN_R: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_R) flag = 1; break; | 232 case HCHAN_R: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_R) flag = 1; break; |
233 case HCHAN_G: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_G) flag = 1; break; | 233 case HCHAN_G: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_G) flag = 1; break; |
234 case HCHAN_B: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_B) flag = 1; break; | 234 case HCHAN_B: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_B) flag = 1; break; |
256 { | 256 { |
257 v[0] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]; // r | 257 v[0] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]; // r |
258 v[1] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]; // g | 258 v[1] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]; // g |
259 v[2] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]; // b | 259 v[2] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]; // b |
260 v[3] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + | 260 v[3] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + |
261 ((histogram->histogram_chan == HCHAN_VAL) ? HISTMAP_CHANNEL_AVG : HISTMAP_CHANNEL_MAX)]; // value, max | 261 ((histogram->channel_mode == HCHAN_VAL) ? HISTMAP_CHANNEL_AVG : HISTMAP_CHANNEL_MAX)]; // value, max |
262 } | 262 } |
263 | 263 |
264 for (j = 0; j < 4; j++) | 264 for (j = 0; j < 4; j++) |
265 { | 265 { |
266 v[j] /= combine; | 266 v[j] /= combine; |
272 gint k; | 272 gint k; |
273 | 273 |
274 for (k = 1; k < 4; k++) | 274 for (k = 1; k < 4; k++) |
275 if (v[k] > v[max2]) max2 = k; | 275 if (v[k] > v[max2]) max2 = k; |
276 | 276 |
277 if (histogram->histogram_chan >= HCHAN_RGB | 277 if (histogram->channel_mode >= HCHAN_RGB |
278 || max2 == histogram->histogram_chan) | 278 || max2 == histogram->channel_mode) |
279 { | 279 { |
280 gulong pt; | 280 gulong pt; |
281 gint r = rplus; | 281 gint r = rplus; |
282 gint g = gplus; | 282 gint g = gplus; |
283 gint b = bplus; | 283 gint b = bplus; |
287 case HCHAN_R: rplus = r = 255; break; | 287 case HCHAN_R: rplus = r = 255; break; |
288 case HCHAN_G: gplus = g = 255; break; | 288 case HCHAN_G: gplus = g = 255; break; |
289 case HCHAN_B: bplus = b = 255; break; | 289 case HCHAN_B: bplus = b = 255; break; |
290 } | 290 } |
291 | 291 |
292 switch (histogram->histogram_chan) | 292 switch (histogram->channel_mode) |
293 { | 293 { |
294 case HCHAN_RGB: | 294 case HCHAN_RGB: |
295 if (r == 255 && g == 255 && b == 255) | 295 if (r == 255 && g == 255 && b == 255) |
296 { | 296 { |
297 r = 0; b = 0; g = 0; | 297 r = 0; b = 0; g = 0; |
304 case HCHAN_VAL: r = 0; b = 0; g = 0; break; | 304 case HCHAN_VAL: r = 0; b = 0; g = 0; break; |
305 } | 305 } |
306 | 306 |
307 if (v[max2] == 0) | 307 if (v[max2] == 0) |
308 pt = 0; | 308 pt = 0; |
309 else if (histogram->histogram_logmode) | 309 else if (histogram->log_mode) |
310 pt = ((float)log(v[max2])) / logmax * (height - 1); | 310 pt = ((float)log(v[max2])) / logmax * (height - 1); |
311 else | 311 else |
312 pt = ((float)v[max2])/ max * (height - 1); | 312 pt = ((float)v[max2])/ max * (height - 1); |
313 | 313 |
314 pixbuf_draw_line(pixbuf, | 314 pixbuf_draw_line(pixbuf, |