Mercurial > audlegacy-plugins
annotate src/paranormal/cmaps.c @ 3184:b009fad90e92
alsa-ng: buffer timing cleanups
author | Joris van Rantwijk <joris2822@xs4all.nl> |
---|---|
date | Sun, 14 Jun 2009 23:10:04 -0500 |
parents | f1b6f1b2cdb3 |
children |
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 |
2835 | 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1892
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 | 27 #include "libcalc/calc.h" |
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 | 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 | 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 | 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 | 115 |
116 /* **************** cmap_dynamic **************** */ | |
117 static struct pn_actuator_option_desc cmap_dynamic_opts[] = | |
118 { | |
119 STD_CMAP_OPTS, | |
120 { "script", "The script to run on each step.", | |
121 OPT_TYPE_STRING, { sval: "red = red + 0.01; blue = blue + 0.01; green = green + 0.01;" } }, | |
122 { NULL } | |
123 }; | |
124 | |
125 typedef struct { | |
126 expression_t *expr; | |
127 symbol_dict_t *dict; | |
128 } PnDynamicColourmapData; | |
129 | |
130 static void | |
131 cmap_dynamic_init(gpointer *data) | |
132 { | |
133 *data = g_new0(PnDynamicColourmapData, 1); | |
134 } | |
135 | |
136 static void | |
137 cmap_dynamic_cleanup(gpointer data) | |
138 { | |
139 PnDynamicColourmapData *d = (PnDynamicColourmapData *) data; | |
140 | |
141 if (d->expr) | |
142 expr_free(d->expr); | |
143 if (d->dict) | |
144 dict_free(d->dict); | |
145 | |
146 g_free(d); | |
147 } | |
148 | |
149 static void | |
150 cmap_dynamic_exec(const struct pn_actuator_option *opts, | |
151 gpointer data) | |
152 { | |
153 PnDynamicColourmapData *d = (PnDynamicColourmapData *) data; | |
2186 | 154 gint i; |
338 | 155 gdouble *rf, *bf, *gf, *inf; |
156 gint rn, bn, gn; | |
157 | |
158 if (!d->dict && !d->expr) | |
159 { | |
160 d->dict = dict_new(); | |
161 if (!d->dict) | |
162 return; | |
163 | |
164 d->expr = expr_compile_string(opts[2].val.sval, d->dict); | |
165 if (!d->expr) | |
166 { | |
167 dict_free(d->dict); | |
168 d->dict = NULL; | |
169 return; | |
170 } | |
171 } | |
172 | |
173 rf = dict_variable(d->dict, "red"); | |
174 gf = dict_variable(d->dict, "green"); | |
175 bf = dict_variable(d->dict, "blue"); | |
176 inf = dict_variable(d->dict, "index"); | |
177 | |
178 for (i = opts[0].val.ival; i < 255 && i <= opts[1].val.ival; i++) | |
179 { | |
180 *inf = ((gdouble)i / 255.0); | |
181 | |
182 expr_execute(d->expr, d->dict); | |
183 | |
184 /* Convert rf/bf/gf to realworld values. */ | |
185 rn = (gdouble)(*rf * 255); | |
186 gn = (gdouble)(*gf * 255); | |
187 bn = (gdouble)(*bf * 255); | |
188 | |
189 pn_image_data->cmap[i].r = rn; | |
190 pn_image_data->cmap[i].g = gn; | |
191 pn_image_data->cmap[i].b = bn; | |
192 } | |
193 } | |
194 | |
195 struct pn_actuator_desc builtin_cmap_dynamic = | |
196 { | |
197 "cmap_dynamic", | |
198 "Dynamic Colourmap", | |
199 "Scriptable colourmap modifier.", | |
200 0, cmap_dynamic_opts, | |
201 cmap_dynamic_init, cmap_dynamic_cleanup, cmap_dynamic_exec | |
202 }; |