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