Mercurial > geeqie
annotate src/histogram.c @ 1316:732083928afb
Enclose macro parameters names with _ to differentiate them from variable names.
author | zas_ |
---|---|
date | Tue, 24 Feb 2009 18:00:45 +0000 |
parents | fcf0e7a6143e |
children | 1fc356f629fe |
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 | |
28 struct _HistMap { | |
1308 | 29 gulong r[HISTMAP_SIZE]; |
30 gulong g[HISTMAP_SIZE]; | |
31 gulong b[HISTMAP_SIZE]; | |
32 gulong max[HISTMAP_SIZE]; | |
1294 | 33 }; |
442 | 34 |
290 | 35 struct _Histogram { |
1304 | 36 gint channel_mode; /* drawing mode for histogram */ |
37 gint log_mode; /* logarithmical or not */ | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
38 guint vgrid; /* number of vertical divisions, 0 for none */ |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
39 guint hgrid; /* number of horizontal divisions, 0 for none */ |
1304 | 40 struct { |
41 int R; /* red */ | |
42 int G; /* green */ | |
43 int B; /* blue */ | |
44 int A; /* alpha */ | |
45 } grid_color; /* grid color */ | |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
46 |
290 | 47 }; |
48 | |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
475
diff
changeset
|
49 Histogram *histogram_new(void) |
273
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 Histogram *histogram; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
52 |
442 | 53 histogram = g_new0(Histogram, 1); |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
54 histogram->channel_mode = options->histogram.last_channel_mode; |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
55 histogram->log_mode = options->histogram.last_log_mode; |
1304 | 56 |
57 /* grid */ | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
58 histogram->vgrid = 5; |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
59 histogram->hgrid = 3; |
1304 | 60 histogram->grid_color.R = 160; |
61 histogram->grid_color.G = 160; | |
62 histogram->grid_color.B = 160; | |
63 histogram->grid_color.A = 250; | |
273
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 return histogram; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
68 void histogram_free(Histogram *histogram) |
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 g_free(histogram); |
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 |
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 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
|
75 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
76 if (!histogram) return 0; |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
77 options->histogram.last_channel_mode = histogram->channel_mode = chan; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
78 return chan; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
81 gint histogram_get_channel(Histogram *histogram) |
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 if (!histogram) return 0; |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
84 return histogram->channel_mode; |
273
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
87 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
|
88 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
89 if (!histogram) return 0; |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
90 options->histogram.last_log_mode = histogram->log_mode = mode; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
91 return mode; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
92 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
93 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
94 gint histogram_get_mode(Histogram *histogram) |
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) return 0; |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
97 return histogram->log_mode; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
98 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
99 |
1312
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
100 gint histogram_toggle_channel(Histogram *histogram) |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
101 { |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
102 if (!histogram) return 0; |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
103 return histogram_set_channel(histogram, (histogram_get_channel(histogram)+1)%HCHAN_COUNT); |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
104 } |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
105 |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
106 gint histogram_toggle_mode(Histogram *histogram) |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
107 { |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
108 if (!histogram) return 0; |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
109 return histogram_set_mode(histogram, !histogram_get_mode(histogram)); |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
110 } |
fcf0e7a6143e
Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents:
1310
diff
changeset
|
111 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
112 const gchar *histogram_label(Histogram *histogram) |
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 const gchar *t1 = ""; |
999 | 115 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
116 if (!histogram) return NULL; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
117 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
118 if (histogram->log_mode) |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
119 switch (histogram->channel_mode) |
442 | 120 { |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
121 case HCHAN_R: t1 = _("logarithmical histogram on red"); break; |
442 | 122 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; |
123 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; | |
124 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; | |
125 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; | |
126 } | |
999 | 127 else |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
128 switch (histogram->channel_mode) |
442 | 129 { |
130 case HCHAN_R: t1 = _("linear histogram on red"); break; | |
131 case HCHAN_G: t1 = _("linear histogram on green"); break; | |
132 case HCHAN_B: t1 = _("linear histogram on blue"); break; | |
133 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break; | |
134 case HCHAN_MAX: t1 = _("linear histogram on max value"); break; | |
135 } | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
136 return t1; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
137 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
138 |
1294 | 139 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
|
140 { |
462 | 141 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
|
142 guchar *s_pix; |
1294 | 143 HistMap *histmap; |
144 | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
145 w = gdk_pixbuf_get_width(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
146 h = gdk_pixbuf_get_height(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
147 srs = gdk_pixbuf_get_rowstride(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
148 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
|
149 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
|
150 |
1294 | 151 histmap = g_new0(HistMap, 1); |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
152 |
462 | 153 step = 3 + !!(has_alpha); |
1294 | 154 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
|
155 { |
1294 | 156 guchar *sp = s_pix + (i * srs); /* 8bit */ |
157 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
|
158 { |
1294 | 159 guint max = sp[0]; |
160 if (sp[1] > max) max = sp[1]; | |
161 if (sp[2] > max) max = sp[2]; | |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
162 |
1308 | 163 histmap->r[sp[0]]++; |
164 histmap->g[sp[1]]++; | |
165 histmap->b[sp[2]]++; | |
166 histmap->max[max]++; | |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
167 |
1294 | 168 sp += step; |
462 | 169 } |
170 } | |
1308 | 171 |
1294 | 172 return histmap; |
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 |
1298 | 175 const HistMap *histmap_get(FileData *fd) |
1294 | 176 { |
177 if (fd->histmap) return fd->histmap; | |
178 | |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
179 if (fd->pixbuf) |
1294 | 180 { |
181 fd->histmap = histmap_read(fd->pixbuf); | |
182 return fd->histmap; | |
183 } | |
184 return NULL; | |
185 } | |
186 | |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
187 static void histogram_vgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height) |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
188 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
189 guint i; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
190 float add; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
191 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
192 if (histogram->vgrid == 0) return; |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
193 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
194 add = width / (float)histogram->vgrid; |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
195 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
196 for (i = 1; i < histogram->vgrid; i++) |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
197 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
198 gint xpos = x + (int)(i * add + 0.5); |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
199 |
1304 | 200 pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height, |
201 histogram->grid_color.R, | |
202 histogram->grid_color.G, | |
203 histogram->grid_color.B, | |
204 histogram->grid_color.A); | |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
205 } |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
206 } |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
207 |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
208 static void histogram_hgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height) |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
209 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
210 guint i; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
211 float add; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
212 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
213 if (histogram->hgrid == 0) return; |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
214 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
215 add = height / (float)histogram->hgrid; |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
216 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
217 for (i = 1; i < histogram->hgrid; i++) |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
218 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
219 gint ypos = y + (int)(i * add + 0.5); |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
220 |
1304 | 221 pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos, |
222 histogram->grid_color.R, | |
223 histogram->grid_color.G, | |
224 histogram->grid_color.B, | |
225 histogram->grid_color.A); | |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
226 } |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
227 } |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
228 |
1298 | 229 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
|
230 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
231 /* FIXME: use the coordinates correctly */ |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
232 gint i; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
233 gulong max = 0; |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
999
diff
changeset
|
234 gdouble logmax; |
1308 | 235 gint combine = (HISTMAP_SIZE - 1) / width + 1; |
236 gint ypos = y + height; | |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
237 |
1294 | 238 if (!histogram || !histmap) return 0; |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
239 |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
240 /* Draw the grid */ |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
241 histogram_vgrid(histogram, pixbuf, x, y, width, height); |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
242 histogram_hgrid(histogram, pixbuf, x, y, width, height); |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
243 |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
244 for (i = 0; i < HISTMAP_SIZE; i++) |
1308 | 245 { |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
246 if (histmap->r[i] > max) max = histmap->r[i]; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
247 if (histmap->g[i] > max) max = histmap->g[i]; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
248 if (histmap->b[i] > max) max = histmap->b[i]; |
1308 | 249 } |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
250 |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
251 if (max > 0) |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
252 logmax = log(max); |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
253 else |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
254 logmax = 1.0; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
255 |
463 | 256 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
|
257 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
258 gint j; |
290 | 259 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
|
260 gint rplus = 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
261 gint gplus = 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
262 gint bplus = 0; |
1294 | 263 gint ii = i * HISTMAP_SIZE / width; |
1308 | 264 gint xpos = x + i; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
265 |
290 | 266 for (j = 0; j < combine; j++) |
267 { | |
1308 | 268 guint p = ii + j; |
269 v[0] += histmap->r[p]; | |
270 v[1] += histmap->g[p]; | |
271 v[2] += histmap->b[p]; | |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
272 v[3] += histmap->max[p]; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
273 } |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
274 |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
275 for (j = 0; combine > 1 && j < 4; j++) |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
276 v[j] /= combine; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
277 |
463 | 278 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
|
279 { |
463 | 280 gint k; |
1308 | 281 gint chanmax = 0; |
463 | 282 |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
283 for (k = 1; k < 3; k++) |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
284 if (v[k] > v[chanmax]) |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
285 chanmax = k; |
1308 | 286 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
287 if (histogram->channel_mode >= HCHAN_RGB |
1308 | 288 || chanmax == histogram->channel_mode) |
463 | 289 { |
290 gulong pt; | |
291 gint r = rplus; | |
292 gint g = gplus; | |
293 gint b = bplus; | |
294 | |
1308 | 295 switch (chanmax) |
463 | 296 { |
1308 | 297 case 0: rplus = r = 255; break; |
298 case 1: gplus = g = 255; break; | |
299 case 2: bplus = b = 255; break; | |
463 | 300 } |
301 | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
302 switch (histogram->channel_mode) |
463 | 303 { |
304 case HCHAN_RGB: | |
305 if (r == 255 && g == 255 && b == 255) | |
306 { | |
307 r = 0; b = 0; g = 0; | |
308 } | |
309 break; | |
1310
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
310 case HCHAN_R: b = 0; g = 0; break; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
311 case HCHAN_G: r = 0; b = 0; break; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
312 case HCHAN_B: r = 0; g = 0; break; |
ef05743535e3
Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents:
1308
diff
changeset
|
313 case HCHAN_MAX: r = 0; b = 0; g = 0; break; |
463 | 314 } |
315 | |
1308 | 316 if (v[chanmax] == 0) |
463 | 317 pt = 0; |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
318 else if (histogram->log_mode) |
1308 | 319 pt = ((gdouble)log(v[chanmax])) / logmax * (height - 1); |
463 | 320 else |
1308 | 321 pt = ((gdouble)v[chanmax]) / max * (height - 1); |
463 | 322 |
442 | 323 pixbuf_draw_line(pixbuf, |
290 | 324 x, y, width, height, |
1308 | 325 xpos, ypos, xpos, ypos - pt, |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
326 r, g, b, 255); |
463 | 327 } |
1308 | 328 |
329 v[chanmax] = -1; | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
330 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
331 } |
463 | 332 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
333 return TRUE; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
334 } |
1294 | 335 |
336 void histogram_notify_cb(FileData *fd, NotifyType type, gpointer data) | |
337 { | |
338 if (type != NOTIFY_TYPE_INTERNAL && fd->histmap) | |
339 { | |
340 g_free(fd->histmap); | |
341 fd->histmap = NULL; | |
342 } | |
343 } | |
344 | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
345 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |