Mercurial > audlegacy-plugins
diff src/paranormal/cmaps.c @ 338:d517fc608e89 trunk
[svn] - some more presets
- add dynamic colourmap, a scripted colourmap basically.
author | nenolod |
---|---|
date | Wed, 06 Dec 2006 05:09:57 -0800 |
parents | 0d826917c56f |
children | 3b034150d31e |
line wrap: on
line diff
--- a/src/paranormal/cmaps.c Tue Dec 05 22:29:56 2006 -0800 +++ b/src/paranormal/cmaps.c Wed Dec 06 05:09:57 2006 -0800 @@ -7,6 +7,8 @@ #include "paranormal.h" #include "actuators.h" +#include "libcalc/calc.h" + #define STD_CMAP_OPTS { "low_index", "The lowest index of the \ color map that should be altered", OPT_TYPE_COLOR_INDEX, { ival: 0 } },\ { "high_index", "The highest index of the color map that should be \ @@ -89,7 +91,95 @@ "cmap_bwgradient", "Value-based colourmap", "Sets the colormap to a gradient going from black to " - "while, via an intermediate color", + "white, via an intermediate color", 0, cmap_bwgradient_opts, NULL, NULL, cmap_bwgradient_exec }; + +/* **************** cmap_dynamic **************** */ +static struct pn_actuator_option_desc cmap_dynamic_opts[] = +{ + STD_CMAP_OPTS, + { "script", "The script to run on each step.", + OPT_TYPE_STRING, { sval: "red = red + 0.01; blue = blue + 0.01; green = green + 0.01;" } }, + { NULL } +}; + +typedef struct { + expression_t *expr; + symbol_dict_t *dict; +} PnDynamicColourmapData; + +static void +cmap_dynamic_init(gpointer *data) +{ + *data = g_new0(PnDynamicColourmapData, 1); +} + +static void +cmap_dynamic_cleanup(gpointer data) +{ + PnDynamicColourmapData *d = (PnDynamicColourmapData *) data; + + if (d->expr) + expr_free(d->expr); + if (d->dict) + dict_free(d->dict); + + g_free(d); +} + +static void +cmap_dynamic_exec(const struct pn_actuator_option *opts, + gpointer data) +{ + PnDynamicColourmapData *d = (PnDynamicColourmapData *) data; + gint i, j; + gdouble *rf, *bf, *gf, *inf; + gint rn, bn, gn; + + if (!d->dict && !d->expr) + { + d->dict = dict_new(); + if (!d->dict) + return; + + d->expr = expr_compile_string(opts[2].val.sval, d->dict); + if (!d->expr) + { + dict_free(d->dict); + d->dict = NULL; + return; + } + } + + rf = dict_variable(d->dict, "red"); + gf = dict_variable(d->dict, "green"); + bf = dict_variable(d->dict, "blue"); + inf = dict_variable(d->dict, "index"); + + for (i = opts[0].val.ival; i < 255 && i <= opts[1].val.ival; i++) + { + *inf = ((gdouble)i / 255.0); + + expr_execute(d->expr, d->dict); + + /* Convert rf/bf/gf to realworld values. */ + rn = (gdouble)(*rf * 255); + gn = (gdouble)(*gf * 255); + bn = (gdouble)(*bf * 255); + + pn_image_data->cmap[i].r = rn; + pn_image_data->cmap[i].g = gn; + pn_image_data->cmap[i].b = bn; + } +} + +struct pn_actuator_desc builtin_cmap_dynamic = +{ + "cmap_dynamic", + "Dynamic Colourmap", + "Scriptable colourmap modifier.", + 0, cmap_dynamic_opts, + cmap_dynamic_init, cmap_dynamic_cleanup, cmap_dynamic_exec +};