Mercurial > geeqie
annotate src/histogram.c @ 1303:9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
author | zas_ |
---|---|
date | Sat, 21 Feb 2009 10:33:56 +0000 |
parents | 8d1f9739c06a |
children | edeb07e1da5d |
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 typedef enum { | |
28 HISTMAP_CHANNEL_R = 0, | |
29 HISTMAP_CHANNEL_G, | |
30 HISTMAP_CHANNEL_B, | |
31 HISTMAP_CHANNEL_AVG, | |
32 HISTMAP_CHANNEL_MAX, | |
33 HISTMAP_CHANNELS | |
34 } HistMapChannels; | |
35 | |
36 struct _HistMap { | |
37 gulong histmap[HISTMAP_SIZE * HISTMAP_CHANNELS]; | |
38 gulong area; | |
39 }; | |
442 | 40 |
290 | 41 struct _Histogram { |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
42 gint channel_mode; |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
43 gint log_mode; |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
44 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
|
45 guint hgrid; /* number of horizontal divisions, 0 for none */ |
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; |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
56 histogram->vgrid = 5; |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
57 histogram->hgrid = 3; |
273
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 return histogram; |
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 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
62 void histogram_free(Histogram *histogram) |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
63 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
64 g_free(histogram); |
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 |
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_set_channel(Histogram *histogram, gint chan) |
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; |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
71 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
|
72 return chan; |
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_get_channel(Histogram *histogram) |
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 return histogram->channel_mode; |
273
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_set_mode(Histogram *histogram, gint mode) |
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 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
|
85 return mode; |
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_get_mode(Histogram *histogram) |
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 return histogram->log_mode; |
273
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 const gchar *histogram_label(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 const gchar *t1 = ""; |
999 | 97 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
98 if (!histogram) return NULL; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
99 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
100 if (histogram->log_mode) |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
101 switch (histogram->channel_mode) |
442 | 102 { |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
103 case HCHAN_R: t1 = _("logarithmical histogram on red"); break; |
442 | 104 case HCHAN_G: t1 = _("logarithmical histogram on green"); break; |
105 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break; | |
106 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break; | |
107 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break; | |
108 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break; | |
109 } | |
999 | 110 else |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
111 switch (histogram->channel_mode) |
442 | 112 { |
113 case HCHAN_R: t1 = _("linear histogram on red"); break; | |
114 case HCHAN_G: t1 = _("linear histogram on green"); break; | |
115 case HCHAN_B: t1 = _("linear histogram on blue"); break; | |
116 case HCHAN_VAL: t1 = _("linear histogram on value"); break; | |
117 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break; | |
118 case HCHAN_MAX: t1 = _("linear histogram on max value"); break; | |
119 } | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
120 return t1; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
121 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
122 |
1294 | 123 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
|
124 { |
462 | 125 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
|
126 guchar *s_pix; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
127 |
1294 | 128 HistMap *histmap; |
129 | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
130 w = gdk_pixbuf_get_width(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
131 h = gdk_pixbuf_get_height(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
132 srs = gdk_pixbuf_get_rowstride(imgpixbuf); |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
133 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
|
134 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
|
135 |
1294 | 136 histmap = g_new0(HistMap, 1); |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
137 |
462 | 138 step = 3 + !!(has_alpha); |
1294 | 139 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
|
140 { |
1294 | 141 guchar *sp = s_pix + (i * srs); /* 8bit */ |
142 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
|
143 { |
1294 | 144 guint avg = (sp[0] + sp[1] + sp[2]) / 3; |
145 guint max = sp[0]; | |
146 if (sp[1] > max) max = sp[1]; | |
147 if (sp[2] > max) max = sp[2]; | |
462 | 148 |
1294 | 149 histmap->histmap[sp[0] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]++; |
150 histmap->histmap[sp[1] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]++; | |
151 histmap->histmap[sp[2] * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]++; | |
152 histmap->histmap[avg * HISTMAP_CHANNELS + HISTMAP_CHANNEL_AVG]++; | |
153 histmap->histmap[max * HISTMAP_CHANNELS + HISTMAP_CHANNEL_MAX]++; | |
154 sp += step; | |
462 | 155 } |
156 } | |
1294 | 157 histmap->area = w * h; |
158 return histmap; | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
159 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
160 |
1298 | 161 const HistMap *histmap_get(FileData *fd) |
1294 | 162 { |
163 if (fd->histmap) return fd->histmap; | |
164 | |
165 if (fd->pixbuf) | |
166 { | |
167 fd->histmap = histmap_read(fd->pixbuf); | |
168 return fd->histmap; | |
169 } | |
170 return NULL; | |
171 } | |
172 | |
1302
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
173 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
|
174 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
175 static gint c = 160; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
176 static gint alpha = 250; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
177 guint i; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
178 float add; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
179 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
180 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
|
181 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
182 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
|
183 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
184 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
|
185 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
186 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
|
187 |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
188 pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height, c, c, c, alpha); |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
189 } |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
190 } |
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 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
|
193 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
194 static gint c = 160; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
195 static gint alpha = 250; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
196 guint i; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
197 float add; |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
198 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
199 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
|
200 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
201 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
|
202 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
203 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
|
204 { |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
205 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
|
206 |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
207 pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos, c, c, c, alpha); |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
208 } |
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 |
1298 | 211 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
|
212 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
213 /* FIXME: use the coordinates correctly */ |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
214 gint i; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
215 gulong max = 0; |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
999
diff
changeset
|
216 gdouble logmax; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
217 |
1294 | 218 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
|
219 |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
220 /* Draw the grid */ |
8d1f9739c06a
Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents:
1298
diff
changeset
|
221 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
|
222 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
|
223 |
463 | 224 for (i = 0; i < 1024; i++) { |
1294 | 225 #if 0 |
226 /* this is probably broken for MAX or VAL mode */ | |
287 | 227 gint flag = 0; |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
228 |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
229 switch (histogram->channel_mode) |
999 | 230 { |
1294 | 231 case HCHAN_RGB: if ((i % HISTMAP_CHANNELS) < 3) flag = 1; break; |
232 case HCHAN_R: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_R) flag = 1; break; | |
233 case HCHAN_G: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_G) flag = 1; break; | |
234 case HCHAN_B: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_B) flag = 1; break; | |
235 case HCHAN_VAL: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_AVG) flag = 1; break; | |
236 case HCHAN_MAX: if ((i % HISTMAP_CHANNELS) == HISTMAP_CHANNEL_MAX) flag = 1; break; | |
999 | 237 } |
1294 | 238 if (flag && histmap->histmap[i] > max) max = histmap->histmap[i]; |
239 #else | |
240 if (histmap->histmap[i] > max) max = histmap->histmap[i]; | |
241 #endif | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
242 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
243 |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
244 logmax = log(max); |
463 | 245 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
|
246 { |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
247 gint j; |
290 | 248 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
|
249 gint rplus = 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
250 gint gplus = 0; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
251 gint bplus = 0; |
1294 | 252 gint ii = i * HISTMAP_SIZE / width; |
253 gint combine = (HISTMAP_SIZE - 1) / width + 1; | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
254 |
290 | 255 for (j = 0; j < combine; j++) |
256 { | |
1294 | 257 v[0] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_R]; // r |
258 v[1] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_G]; // g | |
259 v[2] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + HISTMAP_CHANNEL_B]; // b | |
260 v[3] += histmap->histmap[(ii + j) * HISTMAP_CHANNELS + | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
261 ((histogram->channel_mode == HCHAN_VAL) ? HISTMAP_CHANNEL_AVG : HISTMAP_CHANNEL_MAX)]; // value, max |
1294 | 262 } |
263 | |
264 for (j = 0; j < 4; j++) | |
265 { | |
266 v[j] /= combine; | |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
267 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
268 |
463 | 269 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
|
270 { |
463 | 271 gint max2 = 0; |
272 gint k; | |
273 | |
274 for (k = 1; k < 4; k++) | |
275 if (v[k] > v[max2]) max2 = k; | |
276 | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
277 if (histogram->channel_mode >= HCHAN_RGB |
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
278 || max2 == histogram->channel_mode) |
463 | 279 { |
280 gulong pt; | |
281 gint r = rplus; | |
282 gint g = gplus; | |
283 gint b = bplus; | |
284 | |
285 switch (max2) | |
286 { | |
287 case HCHAN_R: rplus = r = 255; break; | |
288 case HCHAN_G: gplus = g = 255; break; | |
289 case HCHAN_B: bplus = b = 255; break; | |
290 } | |
291 | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
292 switch (histogram->channel_mode) |
463 | 293 { |
294 case HCHAN_RGB: | |
295 if (r == 255 && g == 255 && b == 255) | |
296 { | |
297 r = 0; b = 0; g = 0; | |
298 } | |
299 break; | |
300 case HCHAN_R: b = 0; g = 0; break; | |
301 case HCHAN_G: r = 0; b = 0; break; | |
302 case HCHAN_B: r = 0; g = 0; break; | |
303 case HCHAN_MAX: | |
304 case HCHAN_VAL: r = 0; b = 0; g = 0; break; | |
305 } | |
306 | |
307 if (v[max2] == 0) | |
308 pt = 0; | |
1303
9669104eb58a
Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents:
1302
diff
changeset
|
309 else if (histogram->log_mode) |
463 | 310 pt = ((float)log(v[max2])) / logmax * (height - 1); |
311 else | |
312 pt = ((float)v[max2])/ max * (height - 1); | |
313 | |
442 | 314 pixbuf_draw_line(pixbuf, |
290 | 315 x, y, width, height, |
463 | 316 x + i, y + height, x + i, y + height - pt, |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
317 r, g, b, 255); |
463 | 318 } |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
319 v[max2] = -1; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
320 } |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
321 } |
463 | 322 |
273
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
323 return TRUE; |
e0e2c2b72c5a
reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff
changeset
|
324 } |
1294 | 325 |
326 void histogram_notify_cb(FileData *fd, NotifyType type, gpointer data) | |
327 { | |
328 if (type != NOTIFY_TYPE_INTERNAL && fd->histmap) | |
329 { | |
330 g_free(fd->histmap); | |
331 fd->histmap = NULL; | |
332 } | |
333 } | |
334 | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
335 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |