Mercurial > audlegacy-plugins
changeset 365:b6916d136a12 trunk
[svn] - add support for polar coordinates.
author | nenolod |
---|---|
date | Mon, 11 Dec 2006 22:16:54 -0800 |
parents | 50347c06ec68 |
children | 7d8a357fdff4 |
files | ChangeLog src/paranormal/xform.c |
diffstat | 2 files changed, 90 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Dec 11 06:07:12 2006 -0800 +++ b/ChangeLog Mon Dec 11 22:16:54 2006 -0800 @@ -1,3 +1,14 @@ +2006-12-11 14:07:12 +0000 William Pitcock <nenolod@nenolod.net> + revision [796] + - make scrobbler behave better + - put xspf check back in configure.ac (oops) + + trunk/configure.ac | 4 ++++ + trunk/src/scrobbler/configure.c | 2 ++ + trunk/src/scrobbler/plugin.c | 18 ++++++++++++------ + 3 files changed, 18 insertions(+), 6 deletions(-) + + 2006-12-11 13:19:44 +0000 William Pitcock <nenolod@nenolod.net> revision [794] - fix other plugins dependant on the playlist framework
--- a/src/paranormal/xform.c Mon Dec 11 06:07:12 2006 -0800 +++ b/src/paranormal/xform.c Mon Dec 11 22:16:54 2006 -0800 @@ -452,7 +452,9 @@ struct pn_actuator_option_desc xform_movement_opts[] = { { "formula", "The formula to evaluate.", - OPT_TYPE_STRING, { sval: "d = 0.15;" } }, + OPT_TYPE_STRING, { sval: "r = r * cos(r); d = sin(d);" } }, + { "polar", "Whether the coordinates are polar or not.", + OPT_TYPE_BOOLEAN, { bval: TRUE } }, { NULL } }; @@ -480,11 +482,81 @@ } } +inline void +xform_trans_polar (struct xform_vector *vfield, gint x, gint y, + expression_t *expr, symbol_dict_t *dict) +{ + gdouble *rf, *df; + gdouble xf, yf; + gint xn, yn; + + rf = dict_variable(dict, "r"); + df = dict_variable(dict, "d"); + + /* Points (xf, yf) must be in a (-1..1) square. */ + xf = 2.0 * x / (pn_image_data->width - 1) - 1.0; + yf = 2.0 * y / (pn_image_data->height - 1) - 1.0; + + /* Now, convert to polar coordinates r and d. */ + *rf = hypot(xf, yf); + *df = atan2(yf, xf); + + /* Run the script. */ + expr_execute(expr, dict); + + /* Back to (-1..1) square. */ + xf = (*rf) * cos ((*df)); + yf = (*rf) * sin ((*df)); + + /* Convert back to physical coordinates. */ + xn = (int)(((xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); + yn = (int)(((yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); + + if (xn < 0 || xn >= pn_image_data->width || yn < 0 || yn >= pn_image_data->height) + { + xn = x; yn = y; + } + + xfvec (xn, yn, &vfield[PN_IMG_INDEX (x, y)]); +} + +inline void +xform_trans_literal (struct xform_vector *vfield, gint x, gint y, + expression_t *expr, symbol_dict_t *dict) +{ + gdouble rf, df; + gdouble *xf, *yf; + gint xn, yn; + + xf = dict_variable(dict, "x"); + yf = dict_variable(dict, "y"); + + /* Points (xf, yf) must be in a (-1..1) square. */ + *xf = 2.0 * x / (pn_image_data->width - 1) - 1.0; + *yf = 2.0 * y / (pn_image_data->height - 1) - 1.0; + + /* Run the script. */ + expr_execute(expr, dict); + + /* Convert back to physical coordinates. */ + xn = (int)(((*xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); + yn = (int)(((*yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); + + if (xn < 0 || xn >= pn_image_data->width || yn < 0 || yn >= pn_image_data->height) + { + xn = x; yn = y; + } + + xfvec (xn, yn, &vfield[PN_IMG_INDEX (x, y)]); +} + static void xform_movement_exec (const struct pn_actuator_option *opts, gpointer odata) { PnMovementData *d = (PnMovementData *) odata; + void (*transform_func)(struct xform_vector *, gint, gint, expression_t *, symbol_dict_t *) = + opts[1].val.bval == TRUE ? xform_trans_polar : xform_trans_literal; if (d->width != pn_image_data->width || d->height != pn_image_data->height) @@ -525,31 +597,7 @@ for (j = 0; j < pn_image_data->height; j++) for (i = 0; i < pn_image_data->width; i++) { - /* Points (xf, yf) must be in a (-1..1) square. */ - xf = 2.0 * i / (pn_image_data->width - 1) - 1.0; - yf = 2.0 * j / (pn_image_data->height - 1) - 1.0; - - /* Now, convert to polar coordinates r and d. */ - *rf = hypot(xf, yf); - *df = atan2(yf, xf); - - /* Run the script. */ - expr_execute(expr, dict); - - /* Back to (-1..1) square. */ - xf = (*rf) * cos ((*df)); - yf = (*rf) * sin ((*df)); - - /* Convert back to physical coordinates. */ - xn = (int)(((xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); - yn = (int)(((yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); - - if (xn < 0 || xn >= pn_image_data->width || yn < 0 || yn >= pn_image_data->height) - { - xn = i; yn = j; - } - - xfvec (xn, yn, &d->vfield[PN_IMG_INDEX (i, j)]); + transform_func(d->vfield, i, j, expr, dict); } } @@ -575,6 +623,8 @@ OPT_TYPE_STRING, { sval: "" } }, { "point_script", "The formula to evaluate.", OPT_TYPE_STRING, { sval: "d = 0.15;" } }, + { "polar", "Whether or not the coordinates to use are polar.", + OPT_TYPE_BOOLEAN, { bval: TRUE } }, { NULL } }; @@ -623,6 +673,8 @@ gdouble *rf, *df; gdouble xf, yf; gint xn, yn; + void (*transform_func)(struct xform_vector *, gint, gint, expression_t *, symbol_dict_t *) = + opts[3].val.bval == TRUE ? xform_trans_polar : xform_trans_literal; if (d->width != pn_image_data->width || d->height != pn_image_data->height) @@ -678,32 +730,7 @@ for (j = 0; j < pn_image_data->height; j++) for (i = 0; i < pn_image_data->width; i++) { - /* Points (xf, yf) must be in a (-1..1) square. */ - xf = 2.0 * i / (pn_image_data->width - 1) - 1.0; - yf = 2.0 * j / (pn_image_data->height - 1) - 1.0; - - /* Now, convert to polar coordinates r and d. */ - *rf = hypot(xf, yf); - *df = atan2(yf, xf); - - /* Run the script. */ - if (d->expr_point != NULL) - expr_execute(d->expr_point, d->dict); - - /* Back to (-1..1) square. */ - xf = (*rf) * cos ((*df)); - yf = (*rf) * sin ((*df)); - - /* Convert back to physical coordinates. */ - xn = (int)(((xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); - yn = (int)(((yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); - - if (xn < 0 || xn >= pn_image_data->width || yn < 0 || yn >= pn_image_data->height) - { - xn = i; yn = j; - } - - xfvec (xn, yn, &d->vfield[PN_IMG_INDEX (i, j)]); + transform_func(d->vfield, i, j, d->expr_point, d->dict); } apply_xform (d->vfield);