annotate src/histogram.c @ 1718:8fd961808345

preserve histmap on NOTIFY_CHANGE
author nadvornik
date Sun, 13 Sep 2009 12:33:11 +0000
parents 24a12aa0cb54
children
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
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1055
diff changeset
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
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"
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
17 #include "filedata.h"
284
84c4618cd1cb Fix missing header files inclusions.
zas_
parents: 281
diff changeset
18
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
19 #include <math.h>
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 *----------------------------------------------------------------------------
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
23 * image histogram
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
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
27 #define HISTMAP_SIZE 256
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
28
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
29 struct _HistMap {
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
30 gulong r[HISTMAP_SIZE];
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
31 gulong g[HISTMAP_SIZE];
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
32 gulong b[HISTMAP_SIZE];
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
33 gulong max[HISTMAP_SIZE];
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
34
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1498
diff changeset
35 guint idle_id; /* event source id */
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
36 GdkPixbuf *pixbuf;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
37 gint y;
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
38 };
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
39
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
40
609
b690cecbf5b8 Use function(void) instead of function() for declaring functions which
zas_
parents: 475
diff changeset
41 Histogram *histogram_new(void)
273
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 Histogram *histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
44
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
45 histogram = g_new0(Histogram, 1);
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
46 histogram->histogram_channel = HCHAN_RGB;
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
47 histogram->histogram_mode = 0;
1304
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
48
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
49 /* grid */
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
50 histogram->vgrid = 5;
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
51 histogram->hgrid = 3;
1304
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
52 histogram->grid_color.R = 160;
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
53 histogram->grid_color.G = 160;
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
54 histogram->grid_color.B = 160;
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
55 histogram->grid_color.A = 250;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
56
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
57 return histogram;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
58 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
59
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
60 void histogram_free(Histogram *histogram)
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 g_free(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
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 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
67 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
68 if (!histogram) return 0;
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
69 histogram->histogram_channel = chan;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
70 return chan;
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
73 gint histogram_get_channel(Histogram *histogram)
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 if (!histogram) return 0;
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
76 return histogram->histogram_channel;
273
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
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
79 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
80 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
81 if (!histogram) return 0;
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
82 histogram->histogram_mode = mode;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
83 return mode;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
84 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
85
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
86 gint histogram_get_mode(Histogram *histogram)
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 if (!histogram) return 0;
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
89 return histogram->histogram_mode;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
90 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
91
1312
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
92 gint histogram_toggle_channel(Histogram *histogram)
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
93 {
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
94 if (!histogram) return 0;
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
95 return histogram_set_channel(histogram, (histogram_get_channel(histogram)+1)%HCHAN_COUNT);
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
96 }
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
97
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
98 gint histogram_toggle_mode(Histogram *histogram)
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
99 {
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
100 if (!histogram) return 0;
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
101 return histogram_set_mode(histogram, !histogram_get_mode(histogram));
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
102 }
fcf0e7a6143e Introduce helpers histogram_toggle_channel() and histogram_toggle_mode().
zas_
parents: 1310
diff changeset
103
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
104 const gchar *histogram_label(Histogram *histogram)
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 const gchar *t1 = "";
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
107
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
108 if (!histogram) return NULL;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
109
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
110 if (histogram->histogram_mode)
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
111 switch (histogram->histogram_channel)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
112 {
1344
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
113 case HCHAN_R: t1 = _("Log Histogram on Red"); break;
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
114 case HCHAN_G: t1 = _("Log Histogram on Green"); break;
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
115 case HCHAN_B: t1 = _("Log Histogram on Blue"); break;
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
116 case HCHAN_RGB: t1 = _("Log Histogram on RGB"); break;
1349
5f21db044ec4 max value -> value. Shorter.
zas_
parents: 1344
diff changeset
117 case HCHAN_MAX: t1 = _("Log Histogram on value"); break;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
118 }
999
bbed8e9a5d33 Indentation fixes.
zas_
parents: 612
diff changeset
119 else
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
120 switch (histogram->histogram_channel)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
121 {
1344
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
122 case HCHAN_R: t1 = _("Linear Histogram on Red"); break;
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
123 case HCHAN_G: t1 = _("Linear Histogram on Green"); break;
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
124 case HCHAN_B: t1 = _("Linear Histogram on Blue"); break;
3f9be528787c show histogram label in the title
nadvornik
parents: 1329
diff changeset
125 case HCHAN_RGB: t1 = _("Linear Histogram on RGB"); break;
1349
5f21db044ec4 max value -> value. Shorter.
zas_
parents: 1344
diff changeset
126 case HCHAN_MAX: t1 = _("Linear Histogram on value"); break;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
127 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
128 return t1;
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
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
131 static HistMap *histmap_new(void)
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
132 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
133 HistMap *histmap = g_new0(HistMap, 1);
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
134 return histmap;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
135 }
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
136
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
137 void histmap_free(HistMap *histmap)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
138 {
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
139 if (!histmap) return;
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1498
diff changeset
140 if (histmap->idle_id) g_source_remove(histmap->idle_id);
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
141 if (histmap->pixbuf) g_object_unref(histmap->pixbuf);
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
142 g_free(histmap);
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
143 }
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
144
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
145 static gboolean histmap_read(HistMap *histmap, gboolean whole)
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
146 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
147 gint w, h, i, j, srs, has_alpha, step, end_line;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
148 guchar *s_pix;
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
149 GdkPixbuf *imgpixbuf = histmap->pixbuf;
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
150
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
151 w = gdk_pixbuf_get_width(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
152 h = gdk_pixbuf_get_height(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
153 srs = gdk_pixbuf_get_rowstride(imgpixbuf);
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
154 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
155 has_alpha = gdk_pixbuf_get_has_alpha(imgpixbuf);
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
156
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
157 if (whole)
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
158 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
159 end_line = h;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
160 }
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
161 else
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
162 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
163 gint lines = 1 + 16384 / w;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
164 end_line = histmap->y + lines;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
165 if (end_line > h) end_line = h;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
166 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
167
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
168 step = 3 + !!(has_alpha);
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
169 for (i = histmap->y; i < end_line; i++)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
170 {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
171 guchar *sp = s_pix + (i * srs); /* 8bit */
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
172 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
173 {
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
174 guint max = sp[0];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
175 if (sp[1] > max) max = sp[1];
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
176 if (sp[2] > max) max = sp[2];
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
177
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
178 histmap->r[sp[0]]++;
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
179 histmap->g[sp[1]]++;
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
180 histmap->b[sp[2]]++;
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
181 histmap->max[max]++;
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
182
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
183 sp += step;
462
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
184 }
6a2934cd0883 histogram_read(): speed up calculations by 20%.
zas_
parents: 461
diff changeset
185 }
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
186 histmap->y = end_line;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
187 return end_line >= h;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
188 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
189
1298
c37f36b97173 added histogram pane
nadvornik
parents: 1294
diff changeset
190 const HistMap *histmap_get(FileData *fd)
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
191 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1498
diff changeset
192 if (fd->histmap && !fd->histmap->idle_id) return fd->histmap; /* histmap exists and is finished */
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
193
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
194 return NULL;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
195 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
196
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
197 static gboolean histmap_idle_cb(gpointer data)
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
198 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
199 FileData *fd = data;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
200 if (histmap_read(fd->histmap, FALSE))
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
201 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
202 /* finished */
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
203 g_object_unref(fd->histmap->pixbuf); /*pixbuf is no longer needed */
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
204 fd->histmap->pixbuf = NULL;
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1498
diff changeset
205 fd->histmap->idle_id = 0;
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
206 file_data_send_notification(fd, NOTIFY_HISTMAP);
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
207 return FALSE;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
208 }
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
209 return TRUE;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
210 }
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
211
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
212 gboolean histmap_start_idle(FileData *fd)
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
213 {
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
214 if (fd->histmap || !fd->pixbuf) return FALSE;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
215
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
216 fd->histmap = histmap_new();
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
217 fd->histmap->pixbuf = fd->pixbuf;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
218 g_object_ref(fd->histmap->pixbuf);
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
219
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
220 fd->histmap->idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, histmap_idle_cb, fd, NULL);
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
221 return TRUE;
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
222 }
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
223
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
224
1302
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
225 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
226 {
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
227 guint i;
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
228 float add;
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
229
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
230 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
231
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
232 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
233
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
234 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
235 {
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
236 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
237
1304
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
238 pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
239 histogram->grid_color.R,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
240 histogram->grid_color.G,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
241 histogram->grid_color.B,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
242 histogram->grid_color.A);
1302
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
243 }
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
244 }
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
245
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
246 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
247 {
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
248 guint i;
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
249 float add;
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
250
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
251 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
252
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
253 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
254
1303
9669104eb58a Remove histogram_ prefix from struct _Histogram fields names and rename them more properly.
zas_
parents: 1302
diff changeset
255 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
256 {
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
257 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
258
1304
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
259 pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
260 histogram->grid_color.R,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
261 histogram->grid_color.G,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
262 histogram->grid_color.B,
edeb07e1da5d Move grid color setting to histogram_new().
zas_
parents: 1303
diff changeset
263 histogram->grid_color.A);
1302
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
264 }
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
265 }
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
266
1431
7e180091e0b7 More gboolean and tidy up.
zas_
parents: 1349
diff changeset
267 gboolean 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
268 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
269 /* FIXME: use the coordinates correctly */
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
270 gint i;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
271 gulong max = 0;
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 999
diff changeset
272 gdouble logmax;
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
273 gint combine = (HISTMAP_SIZE - 1) / width + 1;
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
274 gint ypos = y + height;
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
275
1431
7e180091e0b7 More gboolean and tidy up.
zas_
parents: 1349
diff changeset
276 if (!histogram || !histmap) return FALSE;
1302
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
277
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
278 /* Draw the grid */
8d1f9739c06a Add grid to bar histogram, simplify the code and draw horizontal lines too.
zas_
parents: 1298
diff changeset
279 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
280 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
281
1477
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
282 /* exclude overexposed and underexposed */
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
283 for (i = 1; i < HISTMAP_SIZE - 1; i++)
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
284 {
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
285 if (histmap->r[i] > max) max = histmap->r[i];
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
286 if (histmap->g[i] > max) max = histmap->g[i];
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
287 if (histmap->b[i] > max) max = histmap->b[i];
1477
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
288 if (histmap->max[i] > max) max = histmap->max[i];
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
289 }
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
290
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
291 if (max > 0)
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
292 logmax = log(max);
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
293 else
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
294 logmax = 1.0;
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
295
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
296 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
297 {
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
298 gint j;
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
299 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
300 gint rplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
301 gint gplus = 0;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
302 gint bplus = 0;
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
303 gint ii = i * HISTMAP_SIZE / width;
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
304 gint xpos = x + i;
1477
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
305 gint num_chan;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
306
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
307 for (j = 0; j < combine; j++)
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
308 {
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
309 guint p = ii + j;
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
310 v[0] += histmap->r[p];
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
311 v[1] += histmap->g[p];
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
312 v[2] += histmap->b[p];
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
313 v[3] += histmap->max[p];
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
314 }
1310
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
315
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
316 for (j = 0; combine > 1 && j < 4; j++)
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
317 v[j] /= combine;
ef05743535e3 Fix and simplify histogram code, drop histogram based on mean value.
zas_
parents: 1308
diff changeset
318
1477
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
319 num_chan = (histogram->histogram_channel == HCHAN_RGB) ? 3 : 1;
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
320 for (j = 0; j < num_chan; j++)
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
321 {
1477
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
322 gint chanmax;
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
323 if (histogram->histogram_channel == HCHAN_RGB)
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
324 {
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
325 chanmax = HCHAN_R;
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
326 if (v[HCHAN_G] > v[HCHAN_R]) chanmax = HCHAN_G;
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
327 if (v[HCHAN_B] > v[chanmax]) chanmax = HCHAN_B;
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
328 }
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
329 else
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
330 {
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
331 chanmax = histogram->histogram_channel;
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
332 }
29aa897ea540 fixed histogram drawing
nadvornik
parents: 1439
diff changeset
333
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
334 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
335 gulong pt;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
336 gint r = rplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
337 gint g = gplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
338 gint b = bplus;
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
339
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
340 switch (chanmax)
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
341 {
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
342 case HCHAN_R: rplus = r = 255; break;
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
343 case HCHAN_G: gplus = g = 255; break;
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
344 case HCHAN_B: bplus = b = 255; break;
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
345 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
346
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
347 switch (histogram->histogram_channel)
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
348 {
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
349 case HCHAN_RGB:
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
350 if (r == 255 && g == 255 && b == 255)
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
351 {
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
352 r = 0; b = 0; g = 0;
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
353 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
354 break;
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
355 case HCHAN_R: b = 0; g = 0; break;
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
356 case HCHAN_G: r = 0; b = 0; break;
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
357 case HCHAN_B: r = 0; g = 0; break;
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
358 case HCHAN_MAX: r = 0; b = 0; g = 0; break;
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
359 }
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
360
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
361 if (v[chanmax] == 0)
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
362 pt = 0;
1329
1fc356f629fe Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
zas_
parents: 1312
diff changeset
363 else if (histogram->histogram_mode)
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
364 pt = ((gdouble)log(v[chanmax])) / logmax * (height - 1);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
365 else
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
366 pt = ((gdouble)v[chanmax]) / max * (height - 1);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
367
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 290
diff changeset
368 pixbuf_draw_line(pixbuf,
290
4bbde8a38ad4 improved histogram drawing
nadvornik
parents: 287
diff changeset
369 x, y, width, height,
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
370 xpos, ypos, xpos, ypos - pt,
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
371 r, g, b, 255);
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
372 }
1308
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
373
2320339ca8be Attempt to simplify and fix histrogram code.
zas_
parents: 1304
diff changeset
374 v[chanmax] = -1;
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
375 }
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
376 }
463
544934a1ff89 histogram_draw(): tidy up.
zas_
parents: 462
diff changeset
377
273
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
378 return TRUE;
e0e2c2b72c5a reworked the histogram patch by Uwe Ohse, most of the code is in
nadvornik
parents:
diff changeset
379 }
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
380
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
381 void histogram_notify_cb(FileData *fd, NotifyType type, gpointer data)
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
382 {
1718
8fd961808345 preserve histmap on NOTIFY_CHANGE
nadvornik
parents: 1523
diff changeset
383 if ((type & NOTIFY_REREAD) && fd->histmap)
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
384 {
1498
5f49f305a6b6 improved debug messages
nadvornik
parents: 1488
diff changeset
385 DEBUG_1("Notify histogram: %s %04x", fd->path, type);
1439
2441a90c4bcf compute histogram in idle time
nadvornik
parents: 1432
diff changeset
386 histmap_free(fd->histmap);
1294
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
387 fd->histmap = NULL;
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
388 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
389 }
7ac9664242b2 histogram caching
nadvornik
parents: 1284
diff changeset
390
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1000
diff changeset
391 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */