comparison src/histogram.c @ 442:4b2d7f9af171

Big whitespaces cleanup: - drop whitespaces at end of lines - convert eight spaces to tab at start of lines - drop spurious spaces mixed with tabs - remove empty lines at end of files
author zas_
date Sun, 20 Apr 2008 13:04:57 +0000
parents 4bbde8a38ad4
children 65475285957d
comparison
equal deleted inserted replaced
441:08eb7137cd94 442:4b2d7f9af171
21 * image histogram 21 * image histogram
22 *---------------------------------------------------------------------------- 22 *----------------------------------------------------------------------------
23 */ 23 */
24 24
25 #define HISTOGRAM_SIZE 256 25 #define HISTOGRAM_SIZE 256
26 26
27 struct _Histogram { 27 struct _Histogram {
28 gulong histmap[HISTOGRAM_SIZE*4]; 28 gulong histmap[HISTOGRAM_SIZE*4];
29 gint histogram_chan; 29 gint histogram_chan;
30 gint histogram_logmode; 30 gint histogram_logmode;
31 }; 31 };
33 33
34 Histogram *histogram_new() 34 Histogram *histogram_new()
35 { 35 {
36 Histogram *histogram; 36 Histogram *histogram;
37 37
38 histogram = g_new0(Histogram, 1); 38 histogram = g_new0(Histogram, 1);
39 histogram->histogram_chan = HCHAN_RGB; 39 histogram->histogram_chan = HCHAN_RGB;
40 histogram->histogram_logmode = 1; 40 histogram->histogram_logmode = 1;
41 41
42 return histogram; 42 return histogram;
43 } 43 }
78 { 78 {
79 const gchar *t1 = ""; 79 const gchar *t1 = "";
80 if (!histogram) return NULL; 80 if (!histogram) return NULL;
81 81
82 if (histogram->histogram_logmode) 82 if (histogram->histogram_logmode)
83 switch (histogram->histogram_chan) { 83 switch (histogram->histogram_chan)
84 {
84 case HCHAN_R: t1 = _("logarithmical histogram on red"); break; 85 case HCHAN_R: t1 = _("logarithmical histogram on red"); break;
85 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; 86 case HCHAN_G: t1 = _("logarithmical histogram on green"); break;
86 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; 87 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break;
87 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break; 88 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break;
88 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; 89 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break;
89 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; 90 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break;
90 } 91 }
91 else 92 else
92 switch (histogram->histogram_chan) { 93 switch (histogram->histogram_chan)
93 case HCHAN_R: t1 = _("linear histogram on red"); break; 94 {
94 case HCHAN_G: t1 = _("linear histogram on green"); break; 95 case HCHAN_R: t1 = _("linear histogram on red"); break;
95 case HCHAN_B: t1 = _("linear histogram on blue"); break; 96 case HCHAN_G: t1 = _("linear histogram on green"); break;
96 case HCHAN_VAL: t1 = _("linear histogram on value"); break; 97 case HCHAN_B: t1 = _("linear histogram on blue"); break;
97 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break; 98 case HCHAN_VAL: t1 = _("linear histogram on value"); break;
98 case HCHAN_MAX: t1 = _("linear histogram on max value"); break; 99 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break;
99 } 100 case HCHAN_MAX: t1 = _("linear histogram on max value"); break;
101 }
100 return t1; 102 return t1;
101 } 103 }
102 104
103 gulong histogram_read(Histogram *histogram, GdkPixbuf *imgpixbuf) 105 gulong histogram_read(Histogram *histogram, GdkPixbuf *imgpixbuf)
104 { 106 {
181 v[0] += histogram->histmap[ii + j + 0*HISTOGRAM_SIZE]; // r 183 v[0] += histogram->histmap[ii + j + 0*HISTOGRAM_SIZE]; // r
182 v[1] += histogram->histmap[ii + j + 1*HISTOGRAM_SIZE]; // g 184 v[1] += histogram->histmap[ii + j + 1*HISTOGRAM_SIZE]; // g
183 v[2] += histogram->histmap[ii + j + 2*HISTOGRAM_SIZE]; // b 185 v[2] += histogram->histmap[ii + j + 2*HISTOGRAM_SIZE]; // b
184 v[3] += histogram->histmap[ii + j + 3*HISTOGRAM_SIZE]; // value, max 186 v[3] += histogram->histmap[ii + j + 3*HISTOGRAM_SIZE]; // value, max
185 } 187 }
186 188
187 for (j=0; j<4; j++) 189 for (j=0; j<4; j++)
188 { 190 {
189 gint r = rplus; 191 gint r = rplus;
190 gint g = gplus; 192 gint g = gplus;
191 gint b = bplus; 193 gint b = bplus;
193 gint k; 195 gint k;
194 gulong pt; 196 gulong pt;
195 197
196 for (k=1; k<4; k++) 198 for (k=1; k<4; k++)
197 if (v[k] > v[max2]) max2 = k; 199 if (v[k] > v[max2]) max2 = k;
198 200
199 switch (max2) 201 switch (max2)
200 { 202 {
201 case HCHAN_R: rplus = r = 255; break; 203 case HCHAN_R: rplus = r = 255; break;
202 case HCHAN_G: gplus = g = 255; break; 204 case HCHAN_G: gplus = g = 255; break;
203 case HCHAN_B: bplus = b = 255; break; 205 case HCHAN_B: bplus = b = 255; break;
208 case HCHAN_MAX: r = 0; b = 0; g = 0; break; 210 case HCHAN_MAX: r = 0; b = 0; g = 0; break;
209 case HCHAN_VAL: r = 0; b = 0; g = 0; break; 211 case HCHAN_VAL: r = 0; b = 0; g = 0; break;
210 case HCHAN_R: g = 0; b = 0; break; 212 case HCHAN_R: g = 0; b = 0; break;
211 case HCHAN_G: r = 0; b = 0; break; 213 case HCHAN_G: r = 0; b = 0; break;
212 case HCHAN_B: r = 0; g = 0; break; 214 case HCHAN_B: r = 0; g = 0; break;
213 case HCHAN_RGB: 215 case HCHAN_RGB:
214 if (r == 255 && g == 255 && b == 255) { 216 if (r == 255 && g == 255 && b == 255) {
215 r = 0; 217 r = 0;
216 g = 0; 218 g = 0;
217 b = 0; 219 b = 0;
218 } 220 }
219 break; 221 break;
220 } 222 }
221 223
222 if (v[max2] == 0) 224 if (v[max2] == 0)
223 pt = 0; 225 pt = 0;
224 else if (histogram->histogram_logmode) 226 else if (histogram->histogram_logmode)
225 pt = ((float)log(v[max2])) / logmax * (height - 1); 227 pt = ((float)log(v[max2])) / logmax * (height - 1);
226 else 228 else
227 pt = ((float)v[max2])/ max * (height - 1); 229 pt = ((float)v[max2])/ max * (height - 1);
228 if (histogram->histogram_chan >= HCHAN_RGB 230 if (histogram->histogram_chan >= HCHAN_RGB
229 || max2 == histogram->histogram_chan) 231 || max2 == histogram->histogram_chan)
230 pixbuf_draw_line(pixbuf, 232 pixbuf_draw_line(pixbuf,
231 x, y, width, height, 233 x, y, width, height,
232 x + i, y + height, x + i, y + height-pt, 234 x + i, y + height, x + i, y + height-pt,
233 r, g, b, 255); 235 r, g, b, 255);
234 v[max2] = -1; 236 v[max2] = -1;
235 } 237 }
236 } 238 }
237 return TRUE; 239 return TRUE;