Mercurial > audlegacy-plugins
annotate src/rovascope/cmaps.c @ 525:c91f3d7cd641 trunk
[svn] - mpg123: fix warnings in compilation, added function prototype to common.h
author | giacomo |
---|---|
date | Mon, 22 Jan 2007 14:52:22 -0800 |
parents | 290588854a9d |
children | f305ebcc8136 |
rev | line source |
---|---|
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
1 #ifdef HAVE_CONFIG_H |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
2 # include <config.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
3 #endif |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
4 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
5 #include <glib.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
6 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
7 #include "paranormal.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
8 #include "actuators.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
9 |
338 | 10 #include "libcalc/calc.h" |
11 | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
12 #define STD_CMAP_OPTS { "low_index", "The lowest index of the \ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
13 color map that should be altered", OPT_TYPE_COLOR_INDEX, { ival: 0 } },\ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
14 { "high_index", "The highest index of the color map that should be \ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
15 altered", OPT_TYPE_COLOR_INDEX, { ival: 255 } } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
16 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
17 static struct pn_color black = {0, 0, 0}; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
18 static struct pn_color white = {255, 255, 255}; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
19 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
20 /* **************** cmap generation funcs **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
21 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
22 cmap_gen_gradient (int step, const struct pn_color *a, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
23 const struct pn_color *b, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
24 struct pn_color *c) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
25 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
30 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
31 /* **************** cmap_gradient **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
32 static struct pn_actuator_option_desc cmap_gradient_opts[] = |
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 STD_CMAP_OPTS, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
35 { "lcolor", "The low color used in the gradient generation", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
36 OPT_TYPE_COLOR, { cval: {0, 0, 0} } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
37 { "hcolor", "The high color used in the gradient generation", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
38 OPT_TYPE_COLOR, { cval: {0, 0, 0} } }, |
188 | 39 { NULL } |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
40 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
41 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
42 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
43 cmap_gradient_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
44 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
45 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
46 int i; |
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 for (i=opts[0].val.ival; i<=opts[1].val.ival; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
49 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
|
50 - opts[0].val.ival), |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
51 &opts[2].val.cval, &opts[3].val.cval, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
52 &pn_image_data->cmap[i]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
53 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
54 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
55 struct pn_actuator_desc builtin_cmap_gradient = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
56 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
57 "cmap_gradient", |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
58 "Normal colourmap", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
59 "Sets the colormap to a gradient going from <lcolor> to " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
60 "<hcolor>", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
61 0, cmap_gradient_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
62 NULL, NULL, cmap_gradient_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
63 }; |
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 /* **************** cmap_bwgradient **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
66 static struct pn_actuator_option_desc cmap_bwgradient_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
67 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
68 STD_CMAP_OPTS, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
69 { "color", "The intermediate color to use in the gradient", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
70 OPT_TYPE_COLOR, { cval: {191, 191, 191} } }, |
188 | 71 { NULL } |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
72 }; |
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 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
75 cmap_bwgradient_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
76 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
77 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
78 int i; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
79 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
80 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
|
81 cmap_gen_gradient (i<<1, &black, &opts[2].val.cval, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
82 &pn_image_data->cmap[i]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
83 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
84 for (i=128; i<256 && i<=opts[1].val.ival; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
85 cmap_gen_gradient ((i-128)<<1, &opts[2].val.cval, &white, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
86 &pn_image_data->cmap[i]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
87 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
88 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
89 struct pn_actuator_desc builtin_cmap_bwgradient = |
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 "cmap_bwgradient", |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
92 "Value-based colourmap", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
93 "Sets the colormap to a gradient going from black to " |
338 | 94 "white, via an intermediate color", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
95 0, cmap_bwgradient_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
96 NULL, NULL, cmap_bwgradient_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
97 }; |
338 | 98 |
99 /* **************** cmap_dynamic **************** */ | |
100 static struct pn_actuator_option_desc cmap_dynamic_opts[] = | |
101 { | |
102 STD_CMAP_OPTS, | |
103 { "script", "The script to run on each step.", | |
104 OPT_TYPE_STRING, { sval: "red = red + 0.01; blue = blue + 0.01; green = green + 0.01;" } }, | |
105 { NULL } | |
106 }; | |
107 | |
108 typedef struct { | |
109 expression_t *expr; | |
110 symbol_dict_t *dict; | |
111 } PnDynamicColourmapData; | |
112 | |
113 static void | |
114 cmap_dynamic_init(gpointer *data) | |
115 { | |
116 *data = g_new0(PnDynamicColourmapData, 1); | |
117 } | |
118 | |
119 static void | |
120 cmap_dynamic_cleanup(gpointer data) | |
121 { | |
122 PnDynamicColourmapData *d = (PnDynamicColourmapData *) data; | |
123 | |
124 if (d->expr) | |
125 expr_free(d->expr); | |
126 if (d->dict) | |
127 dict_free(d->dict); | |
128 | |
129 g_free(d); | |
130 } | |
131 | |
132 static void | |
133 cmap_dynamic_exec(const struct pn_actuator_option *opts, | |
134 gpointer data) | |
135 { | |
136 PnDynamicColourmapData *d = (PnDynamicColourmapData *) data; | |
137 gint i, j; | |
138 gdouble *rf, *bf, *gf, *inf; | |
139 gint rn, bn, gn; | |
140 | |
141 if (!d->dict && !d->expr) | |
142 { | |
143 d->dict = dict_new(); | |
144 if (!d->dict) | |
145 return; | |
146 | |
147 d->expr = expr_compile_string(opts[2].val.sval, d->dict); | |
148 if (!d->expr) | |
149 { | |
150 dict_free(d->dict); | |
151 d->dict = NULL; | |
152 return; | |
153 } | |
154 } | |
155 | |
156 rf = dict_variable(d->dict, "red"); | |
157 gf = dict_variable(d->dict, "green"); | |
158 bf = dict_variable(d->dict, "blue"); | |
159 inf = dict_variable(d->dict, "index"); | |
160 | |
161 for (i = opts[0].val.ival; i < 255 && i <= opts[1].val.ival; i++) | |
162 { | |
163 *inf = ((gdouble)i / 255.0); | |
164 | |
165 expr_execute(d->expr, d->dict); | |
166 | |
167 /* Convert rf/bf/gf to realworld values. */ | |
168 rn = (gdouble)(*rf * 255); | |
169 gn = (gdouble)(*gf * 255); | |
170 bn = (gdouble)(*bf * 255); | |
171 | |
172 pn_image_data->cmap[i].r = rn; | |
173 pn_image_data->cmap[i].g = gn; | |
174 pn_image_data->cmap[i].b = bn; | |
175 } | |
176 } | |
177 | |
178 struct pn_actuator_desc builtin_cmap_dynamic = | |
179 { | |
180 "cmap_dynamic", | |
181 "Dynamic Colourmap", | |
182 "Scriptable colourmap modifier.", | |
183 0, cmap_dynamic_opts, | |
184 cmap_dynamic_init, cmap_dynamic_cleanup, cmap_dynamic_exec | |
185 }; |