annotate src/histogram.c @ 284:84c4618cd1cb

Fix missing header files inclusions.
author zas_
date Tue, 08 Apr 2008 23:25:46 +0000
parents 9995c5fb202a
children fd5c62403498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
3 *
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
4 * Author: Vladimir Nadvornik
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
5 * 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
6 *
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
7 * 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
8 * 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
9 * 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
10 */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
11
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 273
diff changeset
12 #include "main.h"
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
13 #include "histogram.h"
284
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
14
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
15 #include "pixbuf_util.h"
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
16
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
17 #include <math.h>
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
18
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 * image histogram
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
22 *----------------------------------------------------------------------------
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
26 Histogram *histogram_new()
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
27 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
28 Histogram *histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
29
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
30 histogram = g_new0(Histogram, 1);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
31 histogram->histogram_chan = HCHAN_RGB;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
32 histogram->histogram_logmode = 1;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
33
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
34 return histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
35 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
36
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
37 void histogram_free(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
38 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
39 g_free(histogram);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
40 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
41
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
42
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
43 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
44 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
45 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
46 histogram->histogram_chan = chan;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
47 return chan;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
48 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
49
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
50 gint histogram_get_channel(Histogram *histogram)
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 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
53 return histogram->histogram_chan;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
56 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
57 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
58 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
59 histogram->histogram_logmode = mode;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
60 return mode;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
63 gint histogram_get_mode(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
64 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
65 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
66 return histogram->histogram_logmode;
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 const gchar *histogram_label(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 const gchar *t1 = "";
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
72 if (!histogram) return NULL;
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 if (histogram->histogram_logmode)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
75 switch (histogram->histogram_chan) {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
76 case HCHAN_R: t1 = _("logarithmical histogram on red"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
77 case HCHAN_G: t1 = _("logarithmical histogram on green"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
78 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
79 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
80 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
81 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break;
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 else
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
84 switch (histogram->histogram_chan) {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
85 case HCHAN_R: t1 = _("linear histogram on red"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
86 case HCHAN_G: t1 = _("linear histogram on green"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
87 case HCHAN_B: t1 = _("linear histogram on blue"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
88 case HCHAN_VAL: t1 = _("linear histogram on value"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
89 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
90 case HCHAN_MAX: t1 = _("linear histogram on max value"); break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
91 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
92 return t1;
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 gulong histogram_read(Histogram *histogram, GdkPixbuf *imgpixbuf)
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 gint w, h, i, j, srs, has_alpha;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
98 guchar *s_pix;
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 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
101
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
102 w = gdk_pixbuf_get_width(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
103 h = gdk_pixbuf_get_height(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
104 srs = gdk_pixbuf_get_rowstride(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
105 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
106 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
107
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
108 for (i = 0; i < 256*4; i++) histogram->histmap[i] = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
109
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
110 for (i = 0; i < h; i++)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
111 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
112 guchar *sp = s_pix + (i * srs); /* 8bit */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
113 for (j = 0; j < w; j++)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
114 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
115 histogram->histmap[sp[0]+0]++;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
116 histogram->histmap[sp[1]+256]++;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
117 histogram->histmap[sp[2]+512]++;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
118 if (histogram->histogram_chan == HCHAN_MAX)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
119 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
120 guchar t = sp[0];
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
121 if (sp[1]>t) t = sp[1];
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
122 if (sp[2]>t) t = sp[2];
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
123 histogram->histmap[t+768]++;
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 else
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
126 histogram->histmap[768+(sp[0]+sp[1]+sp[2])/3]++;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
127 sp += 3;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
128 if (has_alpha) sp++;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
129 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
130 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
131
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
132 return w*h;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
133 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
134
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
135
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
136 int histogram_draw(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
137 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
138 /* FIXME: use the coordinates correctly */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
139 gint i;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
140 gulong max = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
141 double logmax;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
142
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
143 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
144
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
145 for (i=0; i<1024; i++) {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
146 int flag = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
147
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
148 switch (histogram->histogram_chan)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
149 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
150 case HCHAN_RGB: if ((i%4) != 3 ) flag = 1; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
151 case HCHAN_R: if ((i%4) == 0) flag = 1; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
152 case HCHAN_G: if ((i%4) == 1) flag = 1; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
153 case HCHAN_B: if ((i%4) == 2) flag = 1; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
154 case HCHAN_VAL: if ((i%4) == 3) flag = 1; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
155 case HCHAN_MAX: if ((i%4) == 3) flag = 1; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
156 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
157 if (flag && histogram->histmap[i] > max) max = histogram->histmap[i];
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
158 }
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 logmax = log(max);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
161 for (i=0; i<256; i++)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
162 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
163 gint j;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
164 glong v[4];
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
165 gint rplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
166 gint gplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
167 gint bplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
168
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
169 v[0] = histogram->histmap[i+0*256]; // r
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
170 v[1] = histogram->histmap[i+1*256]; // g
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
171 v[2] = histogram->histmap[i+2*256]; // b
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
172 v[3] = histogram->histmap[i+3*256]; // value, max
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
173
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
174 for (j=0; j<4; j++)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
175 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
176 gint r = rplus;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
177 gint g = gplus;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
178 gint b = bplus;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
179 gint max2 = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
180 gint k;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
181 gulong pt;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
182
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
183 for (k=1; k<4; k++)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
184 if (v[k] > v[max2]) max2 = k;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
185
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
186 switch (max2)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
187 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
188 case HCHAN_R: rplus = r = 255; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
189 case HCHAN_G: gplus = g = 255; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
190 case HCHAN_B: bplus = b = 255; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
191 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
192
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
193 switch(histogram->histogram_chan)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
194 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
195 case HCHAN_MAX: r = 0; b = 0; g = 0; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
196 case HCHAN_VAL: r = 0; b = 0; g = 0; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
197 case HCHAN_R: g = 0; b = 0; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
198 case HCHAN_G: r = 0; b = 0; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
199 case HCHAN_B: r = 0; g = 0; break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
200 case HCHAN_RGB:
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
201 if (r == 255 && g == 255 && b == 255) {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
202 r = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
203 g = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
204 b = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
205 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
206 break;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
207 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
208
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
209 if (v[max2] == 0)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
210 pt = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
211 else if (histogram->histogram_logmode)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
212 pt = ((float)log(v[max2]))/logmax*255;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
213 else
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
214 pt = ((float)v[max2])/max*255;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
215 if (histogram->histogram_chan >= HCHAN_RGB
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
216 || max2 == histogram->histogram_chan)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
217 pixbuf_draw_line(pixbuf,
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
218 0+5, height-255, 256, 256,
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
219 i+5, height, i+5, height-pt,
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
220 r, g, b, 255);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
221 v[max2] = -1;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
222 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
223 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
224 return TRUE;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
225 }