annotate src/paranormal/cmaps.c @ 2155:69c9f138611b

- Fix files being left open after playing
author Ralf Ertzinger <ralf@skytale.net>
date Tue, 06 Nov 2007 19:03:29 +0100
parents 56bb18dd3fdd
children a509498d76b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1892
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
1 /*
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
2 * paranormal: iterated pipeline-driven visualization plugin
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
5 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
7 * it under the terms of the GNU General Public License as published by
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
8 * the Free Software Foundation; under version 2 of the License.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
9 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
10 * This program is distributed in the hope that it will be useful,
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
13 * GNU General Public License for more details.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
14 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
15 * You should have received a copy of the GNU General Public License
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
16 * along with this program; if not, write to the Free Software
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
18 */
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 338
diff changeset
19
1943
56bb18dd3fdd paranormal: CONFIG_H removal
William Pitcock <nenolod@atheme.org>
parents: 1892
diff changeset
20 #include <config.h>
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
21
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
22 #include <glib.h>
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
23
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
24 #include "paranormal.h"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
25 #include "actuators.h"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
26
338
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
27 #include "libcalc/calc.h"
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
28
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
29 #define STD_CMAP_OPTS { "low_index", "The lowest index of the \
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
30 color map that should be altered", OPT_TYPE_COLOR_INDEX, { ival: 0 } },\
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
31 { "high_index", "The highest index of the color map that should be \
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
32 altered", OPT_TYPE_COLOR_INDEX, { ival: 255 } }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
33
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
34 static struct pn_color black = {0, 0, 0};
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
35 static struct pn_color white = {255, 255, 255};
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
36
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
37 /* **************** cmap generation funcs **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
38 static void
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
39 cmap_gen_gradient (int step, const struct pn_color *a,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
40 const struct pn_color *b,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
41 struct pn_color *c)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
42 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
43 c->r = a->r + step * ((((float)b->r) - ((float)a->r)) / 256.0);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
44 c->g = a->g + step * ((((float)b->g) - ((float)a->g)) / 256.0);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
45 c->b = a->b + step * ((((float)b->b) - ((float)a->b)) / 256.0);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
46 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
47
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
48 /* **************** cmap_gradient **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
49 static struct pn_actuator_option_desc cmap_gradient_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
50 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
51 STD_CMAP_OPTS,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
52 { "lcolor", "The low color used in the gradient generation",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
53 OPT_TYPE_COLOR, { cval: {0, 0, 0} } },
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
54 { "hcolor", "The high color used in the gradient generation",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
55 OPT_TYPE_COLOR, { cval: {0, 0, 0} } },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 155
diff changeset
56 { NULL }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
57 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
58
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
59 static void
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
60 cmap_gradient_exec (const struct pn_actuator_option *opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
61 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
62 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
63 int i;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
64
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
65 for (i=opts[0].val.ival; i<=opts[1].val.ival; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
66 cmap_gen_gradient (((i-opts[0].val.ival)<<8)/(opts[1].val.ival
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
67 - opts[0].val.ival),
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
68 &opts[2].val.cval, &opts[3].val.cval,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
69 &pn_image_data->cmap[i]);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
70 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
71
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
72 struct pn_actuator_desc builtin_cmap_gradient =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
73 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
74 "cmap_gradient",
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
75 "Normal colourmap",
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
76 "Sets the colormap to a gradient going from <lcolor> to "
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
77 "<hcolor>",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
78 0, cmap_gradient_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
79 NULL, NULL, cmap_gradient_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
80 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
81
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
82 /* **************** cmap_bwgradient **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
83 static struct pn_actuator_option_desc cmap_bwgradient_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
84 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
85 STD_CMAP_OPTS,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
86 { "color", "The intermediate color to use in the gradient",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
87 OPT_TYPE_COLOR, { cval: {191, 191, 191} } },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 155
diff changeset
88 { NULL }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
89 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
90
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
91 static void
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
92 cmap_bwgradient_exec (const struct pn_actuator_option *opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
93 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
94 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
95 int i;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
96
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
97 for (i=opts[0].val.ival; i<128 && i<=opts[1].val.ival; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
98 cmap_gen_gradient (i<<1, &black, &opts[2].val.cval,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
99 &pn_image_data->cmap[i]);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
100
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
101 for (i=128; i<256 && i<=opts[1].val.ival; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
102 cmap_gen_gradient ((i-128)<<1, &opts[2].val.cval, &white,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
103 &pn_image_data->cmap[i]);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
104 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
105
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
106 struct pn_actuator_desc builtin_cmap_bwgradient =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
107 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
108 "cmap_bwgradient",
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
109 "Value-based colourmap",
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
110 "Sets the colormap to a gradient going from black to "
338
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
111 "white, via an intermediate color",
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
112 0, cmap_bwgradient_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
113 NULL, NULL, cmap_bwgradient_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
114 };
338
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
115
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
116 /* **************** cmap_dynamic **************** */
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
117 static struct pn_actuator_option_desc cmap_dynamic_opts[] =
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
118 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
119 STD_CMAP_OPTS,
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
120 { "script", "The script to run on each step.",
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
121 OPT_TYPE_STRING, { sval: "red = red + 0.01; blue = blue + 0.01; green = green + 0.01;" } },
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
122 { NULL }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
123 };
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
124
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
125 typedef struct {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
126 expression_t *expr;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
127 symbol_dict_t *dict;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
128 } PnDynamicColourmapData;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
129
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
130 static void
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
131 cmap_dynamic_init(gpointer *data)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
132 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
133 *data = g_new0(PnDynamicColourmapData, 1);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
134 }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
135
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
136 static void
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
137 cmap_dynamic_cleanup(gpointer data)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
138 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
139 PnDynamicColourmapData *d = (PnDynamicColourmapData *) data;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
140
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
141 if (d->expr)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
142 expr_free(d->expr);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
143 if (d->dict)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
144 dict_free(d->dict);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
145
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
146 g_free(d);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
147 }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
148
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
149 static void
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
150 cmap_dynamic_exec(const struct pn_actuator_option *opts,
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
151 gpointer data)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
152 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
153 PnDynamicColourmapData *d = (PnDynamicColourmapData *) data;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
154 gint i, j;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
155 gdouble *rf, *bf, *gf, *inf;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
156 gint rn, bn, gn;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
157
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
158 if (!d->dict && !d->expr)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
159 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
160 d->dict = dict_new();
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
161 if (!d->dict)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
162 return;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
163
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
164 d->expr = expr_compile_string(opts[2].val.sval, d->dict);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
165 if (!d->expr)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
166 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
167 dict_free(d->dict);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
168 d->dict = NULL;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
169 return;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
170 }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
171 }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
172
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
173 rf = dict_variable(d->dict, "red");
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
174 gf = dict_variable(d->dict, "green");
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
175 bf = dict_variable(d->dict, "blue");
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
176 inf = dict_variable(d->dict, "index");
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
177
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
178 for (i = opts[0].val.ival; i < 255 && i <= opts[1].val.ival; i++)
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
179 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
180 *inf = ((gdouble)i / 255.0);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
181
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
182 expr_execute(d->expr, d->dict);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
183
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
184 /* Convert rf/bf/gf to realworld values. */
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
185 rn = (gdouble)(*rf * 255);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
186 gn = (gdouble)(*gf * 255);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
187 bn = (gdouble)(*bf * 255);
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
188
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
189 pn_image_data->cmap[i].r = rn;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
190 pn_image_data->cmap[i].g = gn;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
191 pn_image_data->cmap[i].b = bn;
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
192 }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
193 }
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
194
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
195 struct pn_actuator_desc builtin_cmap_dynamic =
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
196 {
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
197 "cmap_dynamic",
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
198 "Dynamic Colourmap",
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
199 "Scriptable colourmap modifier.",
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
200 0, cmap_dynamic_opts,
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
201 cmap_dynamic_init, cmap_dynamic_cleanup, cmap_dynamic_exec
d517fc608e89 [svn] - some more presets
nenolod
parents: 188
diff changeset
202 };