annotate src/histogram.c @ 576:9dc0513837b5

dropped path_list functions, use filelist functions everywhere
author nadvornik
date Sun, 04 May 2008 21:54:20 +0000
parents 48c8e49b571c
children b690cecbf5b8
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
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 463
diff changeset
3 * Copyright (C) 2008 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
9995c5fb202a gqview.h -> main.h
zas_
parents: 273
diff changeset
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
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
15
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
16 #include "pixbuf_util.h"
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
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
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
26 #define HISTOGRAM_SIZE 256
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
27
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
28 struct _Histogram {
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
29 gulong histmap[HISTOGRAM_SIZE*4];
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
30 gint histogram_chan;
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
31 gint histogram_logmode;
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
32 };
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
33
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
34
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
35 Histogram *histogram_new()
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 Histogram *histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
38
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
39 histogram = g_new0(Histogram, 1);
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
40 histogram->histogram_chan = HCHAN_RGB;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
41 histogram->histogram_logmode = 1;
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 return histogram;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
46 void histogram_free(Histogram *histogram)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
47 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
48 g_free(histogram);
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
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 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
53 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
54 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
55 histogram->histogram_chan = chan;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
56 return chan;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
59 gint histogram_get_channel(Histogram *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 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
62 return histogram->histogram_chan;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
65 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
66 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
67 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
68 histogram->histogram_logmode = mode;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
69 return mode;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
72 gint histogram_get_mode(Histogram *histogram)
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) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
75 return histogram->histogram_logmode;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
78 const gchar *histogram_label(Histogram *histogram)
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 const gchar *t1 = "";
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
81 if (!histogram) return NULL;
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->histogram_logmode)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
84 switch (histogram->histogram_chan)
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
85 {
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
86 case HCHAN_R: t1 = _("logarithmical histogram on red"); break;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
87 case HCHAN_G: t1 = _("logarithmical histogram on green"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
88 case HCHAN_B: t1 = _("logarithmical histogram on blue"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
89 case HCHAN_VAL: t1 = _("logarithmical histogram on value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
90 case HCHAN_RGB: t1 = _("logarithmical histogram on RGB"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
91 case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
92 }
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
93 else
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
94 switch (histogram->histogram_chan)
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
95 {
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
96 case HCHAN_R: t1 = _("linear histogram on red"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
97 case HCHAN_G: t1 = _("linear histogram on green"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
98 case HCHAN_B: t1 = _("linear histogram on blue"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
99 case HCHAN_VAL: t1 = _("linear histogram on value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
100 case HCHAN_RGB: t1 = _("linear histogram on RGB"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
101 case HCHAN_MAX: t1 = _("linear histogram on max value"); break;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
102 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
103 return t1;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
104 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
105
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
106 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
107 {
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
108 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
109 guchar *s_pix;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
110
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
111 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
112
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
113 w = gdk_pixbuf_get_width(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
114 h = gdk_pixbuf_get_height(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
115 srs = gdk_pixbuf_get_rowstride(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
116 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
117 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
118
461
65475285957d histogram_read(): use memset() to initialize histogram data instead of for() loop.
zas_
parents: 442
diff changeset
119 memset(histogram->histmap, 0, sizeof(histogram->histmap));
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
120
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
121 /* code duplication is here to speed up the calculation */
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
122 step = 3 + !!(has_alpha);
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
123 if (histogram->histogram_chan == HCHAN_MAX)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
124 {
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
125 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
126 {
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
127 guchar *sp = s_pix + (i * srs); /* 8bit */
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
128 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
129 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
130 guchar t = sp[0];
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
131 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
132 if (sp[2]>t) t = sp[2];
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
133
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
134 histogram->histmap[sp[0] + 0 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
135 histogram->histmap[sp[1] + 1 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
136 histogram->histmap[sp[2] + 2 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
137 histogram->histmap[t + 3 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
138 sp += step;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
139 }
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
140 }
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
141 }
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
142 else
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
143 {
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
144 for (i = 0; i < h; i++)
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
145 {
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
146 guchar *sp = s_pix + (i * srs); /* 8bit */
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
147 for (j = 0; j < w; j++)
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
148 {
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
149 histogram->histmap[sp[0] + 0 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
150 histogram->histmap[sp[1] + 1 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
151 histogram->histmap[sp[2] + 2 * HISTOGRAM_SIZE]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
152 histogram->histmap[3 * HISTOGRAM_SIZE + (sp[0]+sp[1]+sp[2])/3]++;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
153 sp += step;
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
154 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
155 }
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
158 return w*h;
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
287
fd5c62403498 int -> gint
zas_
parents: 284
diff changeset
161 gint histogram_draw(Histogram *histogram, 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
162 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
163 /* FIXME: use the coordinates correctly */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
164 gint i;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
165 gulong max = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
166 double logmax;
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 if (!histogram) return 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
169
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
170 for (i = 0; i < 1024; i++) {
287
fd5c62403498 int -> gint
zas_
parents: 284
diff changeset
171 gint flag = 0;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
172
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
173 switch (histogram->histogram_chan)
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
174 {
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
175 case HCHAN_RGB: if ((i%4) != 3) flag = 1; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
176 case HCHAN_R: if ((i%4) == 0) flag = 1; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
177 case HCHAN_G: if ((i%4) == 1) flag = 1; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
178 case HCHAN_B: if ((i%4) == 2) flag = 1; break;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
179 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
180 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
181 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
182 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
183 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
184
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
185 logmax = log(max);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
186 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
187 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
188 gint j;
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
189 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
190 gint rplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
191 gint gplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
192 gint bplus = 0;
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
193 gint ii = i * HISTOGRAM_SIZE / width;
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
194 gint combine = (HISTOGRAM_SIZE - 1) / width + 1;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
195
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
196 for (j = 0; j < combine; j++)
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
197 {
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
198 v[0] += histogram->histmap[ii + j + 0 * HISTOGRAM_SIZE]; // r
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
199 v[1] += histogram->histmap[ii + j + 1 * HISTOGRAM_SIZE]; // g
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
200 v[2] += histogram->histmap[ii + j + 2 * HISTOGRAM_SIZE]; // b
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
201 v[3] += histogram->histmap[ii + j + 3 * HISTOGRAM_SIZE]; // value, max
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
202 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
203
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
204 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
205 {
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
206 gint max2 = 0;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
207 gint k;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
208
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
209 for (k = 1; k < 4; k++)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
210 if (v[k] > v[max2]) max2 = k;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
211
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
212 if (histogram->histogram_chan >= HCHAN_RGB
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
213 || max2 == histogram->histogram_chan)
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
214 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
215 gulong pt;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
216 gint r = rplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
217 gint g = gplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
218 gint b = bplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
219
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
220 switch (max2)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
221 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
222 case HCHAN_R: rplus = r = 255; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
223 case HCHAN_G: gplus = g = 255; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
224 case HCHAN_B: bplus = b = 255; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
225 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
226
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
227 switch (histogram->histogram_chan)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
228 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
229 case HCHAN_RGB:
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
230 if (r == 255 && g == 255 && b == 255)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
231 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
232 r = 0; b = 0; g = 0;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
233 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
234 break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
235 case HCHAN_R: b = 0; g = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
236 case HCHAN_G: r = 0; b = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
237 case HCHAN_B: r = 0; g = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
238 case HCHAN_MAX:
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
239 case HCHAN_VAL: r = 0; b = 0; g = 0; break;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
240 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
241
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
242 if (v[max2] == 0)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
243 pt = 0;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
244 else if (histogram->histogram_logmode)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
245 pt = ((float)log(v[max2])) / logmax * (height - 1);
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
246 else
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
247 pt = ((float)v[max2])/ max * (height - 1);
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
248
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
249 pixbuf_draw_line(pixbuf,
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
250 x, y, width, height,
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
251 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
252 r, g, b, 255);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
253 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
254 v[max2] = -1;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
255 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
256 }
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
257
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
258 return TRUE;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
259 }