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