Mercurial > audlegacy-plugins
annotate src/rovascope/xform.c @ 1263:458d46e65a86
wav-sndfile: in is_our_file, ensure that filename is not NULL before passing it to sf_open
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Fri, 13 Jul 2007 20:55:42 +0200 |
parents | f305ebcc8136 |
children |
rev | line source |
---|---|
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
1 /* FIXME: allow for only using an xform on part of the img? */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
2 /* FIXME: perhaps combine these into a single vector field |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
3 so that only 1 apply_xform needs to be done for as many |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
4 of these as someone wants to use */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
5 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
6 #ifdef HAVE_CONFIG_H |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
7 # include <config.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
8 #endif |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
9 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
10 #include <math.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
11 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
12 #include <glib.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
13 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
14 #include "paranormal.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
15 #include "actuators.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
16 #include "pn_utils.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
17 |
333 | 18 #include "libcalc/calc.h" |
19 | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
20 struct xform_vector |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
21 { |
189
772ad5bc7050
[svn] - now working on amd64/little-endian. no idea how it was working in bigendian mode, though.
nenolod
parents:
188
diff
changeset
|
22 gint32 offset; /* the offset of the top left pixel */ |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
23 guint16 w; /* 4:4:4:4 NE, NW, SE, SW pixel weights |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
24 The total should be 16 */ |
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 /* if offset < 0 then w is the color index to |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
27 which the pixel will be set */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
28 }; |
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 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
31 xfvec (float x, float y, struct xform_vector *v) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
32 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
33 float xd, yd; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
34 int weight[4]; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
35 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
36 if (x >= pn_image_data->width-1 || y >= pn_image_data->height-1 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
37 || x < 0 || y < 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
38 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
39 v->offset = -1; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
40 v->w = 0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
41 return; |
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
44 v->offset = PN_IMG_INDEX (floor(x), floor(y)); |
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 xd = x - floor (x); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
47 yd = y - floor (y); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
48 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
49 weight[3] = xd * yd * 16; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
50 weight[2] = (1-xd) * yd * 16; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
51 weight[1] = xd * (1-yd) * 16; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
52 weight[0] = 16 - weight[3] - weight[2] - weight[1]; /* just in case */ |
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 v->w = (weight[0]<<12) | (weight[1]<<8) | (weight[2]<<4) | weight[3]; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
55 } |
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 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
58 apply_xform (struct xform_vector *vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
59 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
60 int i; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
61 struct xform_vector *v; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
62 register guchar *srcptr; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
63 register guchar *destptr; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
64 register int color; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
65 |
334
a9f1bd76a3e6
[svn] - apply_xform(): check for NULL vfield (broken scripts)
nenolod
parents:
333
diff
changeset
|
66 if (vfield == NULL) |
a9f1bd76a3e6
[svn] - apply_xform(): check for NULL vfield (broken scripts)
nenolod
parents:
333
diff
changeset
|
67 return; |
a9f1bd76a3e6
[svn] - apply_xform(): check for NULL vfield (broken scripts)
nenolod
parents:
333
diff
changeset
|
68 |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
69 for (i=0, v=vfield, destptr=pn_image_data->surface[1]; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
70 i<pn_image_data->width*pn_image_data->height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
71 i++, v++, destptr++) |
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 /* off the screen */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
74 if (v->offset < 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
75 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
76 *destptr = (guchar)v->w; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
77 continue; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
78 } |
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 srcptr = pn_image_data->surface[0] + v->offset; |
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 /* exactly on the pixel */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
83 if (v->w == 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
84 *destptr = *srcptr; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
85 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
86 /* gotta blend the points */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
87 else |
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 color = *srcptr * (v->w>>12); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
90 color += *++srcptr * ((v->w>>8) & 0x0f); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
91 color += *(srcptr+=pn_image_data->width) * (v->w & 0x0f); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
92 color += *(--srcptr) * ((v->w>>4) & 0x0f); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
93 color >>= 4; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
94 *destptr = (guchar)color; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
95 } |
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 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
98 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
99 /* **************** xform_spin **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
100 /* FIXME: Describe these better, how they are backwards */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
101 /* FIXME: better name? */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
102 struct pn_actuator_option_desc xform_spin_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
103 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
104 { "angle", "The angle of rotation", OPT_TYPE_FLOAT, { fval: -8.0 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
105 { "r_add", "The number of pixels by which the r coordinate will be " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
106 "increased (before scaling)", OPT_TYPE_FLOAT, { fval: 0.0 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
107 { "r_scale", "The amount by which the r coordinate of each pixel will " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
108 "be scaled", OPT_TYPE_FLOAT, { fval: 1.0 } }, |
188 | 109 { NULL } |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
110 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
111 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
112 struct xform_spin_data |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
113 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
114 int width, height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
115 struct xform_vector *vfield; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
116 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
117 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
118 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
119 xform_spin_init (gpointer *data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
120 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
121 *data = g_new0 (struct xform_spin_data, 1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
122 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
123 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
124 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
125 xform_spin_cleanup (gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
126 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
127 struct xform_spin_data *d = (struct xform_spin_data *) data; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
128 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
129 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
130 if (d) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
131 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
132 if (d->vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
133 g_free (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
134 g_free (d); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
135 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
136 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
137 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
138 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
139 xform_spin_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
140 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
141 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
142 struct xform_spin_data *d = (struct xform_spin_data*)data; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
143 float i, j; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
144 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
145 if (d->width != pn_image_data->width |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
146 || d->height != pn_image_data->height) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
147 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
148 d->width = pn_image_data->width; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
149 d->height = pn_image_data->height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
150 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
151 if (d->vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
152 g_free (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
153 |
188 | 154 d->vfield = g_malloc0 (sizeof(struct xform_vector) |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
155 * d->width * d->height); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
156 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
157 for (j=-(pn_image_data->height>>1)+1; j<=pn_image_data->height>>1; j++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
158 for (i=-(pn_image_data->width>>1); i<pn_image_data->width>>1; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
159 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
160 float r, t = 0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
161 float x, y; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
162 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
163 r = sqrt (i*i + j*j); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
164 if (r) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
165 t = asin (j/r); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
166 if (i < 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
167 t = M_PI - t; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
168 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
169 t += opts[0].val.fval * M_PI/180.0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
170 r += opts[1].val.fval; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
171 r *= opts[2].val.fval; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
172 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
173 x = (r * cos (t)) + (pn_image_data->width>>1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
174 y = (pn_image_data->height>>1) - (r * sin (t)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
175 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
176 xfvec (x, y, &d->vfield |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
177 [PN_IMG_INDEX ((pn_image_data->width>>1)+(int)rint(i), |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
178 ((pn_image_data->height>>1)-(int)rint(j)))]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
179 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
180 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
181 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
182 apply_xform (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
183 pn_swap_surfaces (); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
184 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
185 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
186 struct pn_actuator_desc builtin_xform_spin = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
187 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
188 "xform_spin", "Spin Transform", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
189 "Rotates and radially scales the image", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
190 0, xform_spin_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
191 xform_spin_init, xform_spin_cleanup, xform_spin_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
192 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
193 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
194 /* **************** xform_ripple **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
195 struct pn_actuator_option_desc xform_ripple_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
196 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
197 { "angle", "The angle of rotation", OPT_TYPE_FLOAT, { fval: 0 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
198 { "ripples", "The number of ripples that fit on the screen " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
199 "(horizontally)", OPT_TYPE_FLOAT, { fval: 8 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
200 { "base_speed", "The minimum number of pixels to move each pixel", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
201 OPT_TYPE_FLOAT, { fval: 1 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
202 { "mod_speed", "The maximum number of pixels by which base_speed" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
203 " will be modified", OPT_TYPE_FLOAT, { fval: 1 } }, |
188 | 204 { NULL } |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
205 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
206 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
207 struct xform_ripple_data |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
208 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
209 int width, height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
210 struct xform_vector *vfield; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
211 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
212 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
213 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
214 xform_ripple_init (gpointer *data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
215 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
216 *data = g_new0 (struct xform_ripple_data, 1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
217 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
218 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
219 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
220 xform_ripple_cleanup (gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
221 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
222 struct xform_ripple_data *d = (struct xform_ripple_data*) data; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
223 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
224 if (d) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
225 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
226 if (d->vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
227 g_free (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
228 g_free (d); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
229 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
230 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
231 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
232 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
233 xform_ripple_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
234 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
235 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
236 struct xform_ripple_data *d = (struct xform_ripple_data*)data; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
237 float i, j; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
238 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
239 if (d->width != pn_image_data->width |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
240 || d->height != pn_image_data->height) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
241 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
242 d->width = pn_image_data->width; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
243 d->height = pn_image_data->height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
244 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
245 if (d->vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
246 g_free (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
247 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
248 d->vfield = g_malloc (sizeof(struct xform_vector) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
249 * d->width * d->height); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
250 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
251 for (j=-(pn_image_data->height>>1)+1; j<=pn_image_data->height>>1; j++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
252 for (i=-(pn_image_data->width>>1); i<pn_image_data->width>>1; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
253 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
254 float r, t = 0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
255 float x, y; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
256 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
257 r = sqrt (i*i + j*j); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
258 if (r) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
259 t = asin (j/r); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
260 if (i < 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
261 t = M_PI - t; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
262 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
263 t += opts[0].val.fval * M_PI/180.0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
264 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
265 if (r > 4)//(pn_image_data->width/(2*opts[1].val.fval))) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
266 r -= opts[2].val.fval + (opts[3].val.fval/2) * |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
267 (1 + sin ((r/(pn_image_data->width/(2*opts[1].val.fval)))*M_PI)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
268 /* else if (r > 4) */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
269 /* r *= r/(pn_image_data->width/opts[1].val.fval); */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
270 else /* don't let it explode */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
271 r = 1000000; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
272 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
273 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
274 x = (r * cos (t)) + (pn_image_data->width>>1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
275 y = (pn_image_data->height>>1) - (r * sin (t)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
276 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
277 xfvec (x, y, &d->vfield |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
278 [PN_IMG_INDEX ((pn_image_data->width>>1)+(int)rint(i), |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
279 ((pn_image_data->height>>1)-(int)rint(j)))]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
280 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
281 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
282 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
283 apply_xform (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
284 pn_swap_surfaces (); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
285 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
286 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
287 struct pn_actuator_desc builtin_xform_ripple = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
288 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
289 "xform_ripple", "Ripple Transform", "Creates an ripple effect", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
290 0, xform_ripple_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
291 xform_ripple_init, xform_ripple_cleanup, xform_ripple_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
292 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
293 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
294 /* **************** xform_bump_spin **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
295 struct pn_actuator_option_desc xform_bump_spin_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
296 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
297 { "angle", "The angle of rotation", OPT_TYPE_FLOAT, { fval: 0 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
298 { "bumps", "The number of bumps that on the image", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
299 OPT_TYPE_FLOAT, { fval: 8 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
300 { "base_scale", "The base radial scale", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
301 OPT_TYPE_FLOAT, { fval: 0.95 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
302 { "mod_scale", "The maximum amount that should be " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
303 "added to the base_scale to create the 'bump' effect", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
304 OPT_TYPE_FLOAT, { fval: .1 } }, |
188 | 305 { NULL } |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
306 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
307 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
308 struct xform_bump_spin_data |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
309 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
310 int width, height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
311 struct xform_vector *vfield; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
312 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
313 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
314 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
315 xform_bump_spin_init (gpointer *data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
316 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
317 *data = g_new0 (struct xform_bump_spin_data, 1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
318 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
319 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
320 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
321 xform_bump_spin_cleanup (gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
322 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
323 struct xform_bump_spin_data *d = (struct xform_bump_spin_data*) data; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
324 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
325 if (d) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
326 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
327 if (d->vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
328 g_free (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
329 g_free (d); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
330 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
331 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
332 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
333 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
334 xform_bump_spin_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
335 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
336 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
337 struct xform_bump_spin_data *d = (struct xform_bump_spin_data*)data; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
338 float i, j; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
339 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
340 if (d->width != pn_image_data->width |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
341 || d->height != pn_image_data->height) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
342 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
343 d->width = pn_image_data->width; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
344 d->height = pn_image_data->height; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
345 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
346 if (d->vfield) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
347 g_free (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
348 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
349 d->vfield = g_malloc (sizeof(struct xform_vector) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
350 * d->width * d->height); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
351 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
352 for (j=-(pn_image_data->height>>1)+1; j<=pn_image_data->height>>1; j++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
353 for (i=-(pn_image_data->width>>1); i<pn_image_data->width>>1; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
354 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
355 float r, t = 0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
356 float x, y; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
357 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
358 r = sqrt (i*i + j*j); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
359 if (r) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
360 t = asin (j/r); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
361 if (i < 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
362 t = M_PI - t; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
363 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
364 t += opts[0].val.fval * M_PI/180.0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
365 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
366 r *= opts[2].val.fval + opts[3].val.fval |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
367 * (1 + sin (t*opts[1].val.fval)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
368 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
369 x = (r * cos (t)) + (pn_image_data->width>>1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
370 y = (pn_image_data->height>>1) - (r * sin (t)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
371 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
372 xfvec (x, y, &d->vfield |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
373 [PN_IMG_INDEX ((pn_image_data->width>>1)+(int)rint(i), |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
374 ((pn_image_data->height>>1)-(int)rint(j)))]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
375 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
376 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
377 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
378 apply_xform (d->vfield); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
379 pn_swap_surfaces (); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
380 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
381 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
382 struct pn_actuator_desc builtin_xform_bump_spin = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
383 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
384 "xform_bump_spin", "Bump Transform", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
385 "Rotate the image at a varying speed to create " |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
386 "the illusion of bumps", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
387 0, xform_bump_spin_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
388 xform_bump_spin_init, xform_bump_spin_cleanup, xform_bump_spin_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
389 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
390 |
273
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
391 /* **************** xform_halfrender **************** */ |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
392 struct pn_actuator_option_desc xform_halfrender_opts[] = |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
393 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
394 { "direction", "Negative is horizontal, positive is vertical.", |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
395 OPT_TYPE_INT, { ival: 1 } }, |
275
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
396 { "render_twice", "Render the second image.", |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
397 OPT_TYPE_BOOLEAN, { bval: TRUE } }, |
273
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
398 { NULL } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
399 }; |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
400 |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
401 static void |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
402 xform_halfrender_exec (const struct pn_actuator_option *opts, |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
403 gpointer data) |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
404 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
405 gint x, y; |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
406 |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
407 if (opts[0].val.ival < 0) |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
408 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
409 for (y = 0; y < pn_image_data->height; y += 2) |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
410 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
411 for (x = 0; x < pn_image_data->width; x++) |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
412 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
413 pn_image_data->surface[1][PN_IMG_INDEX(x, y / 2)] = |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
414 pn_image_data->surface[0][PN_IMG_INDEX(x, y)]; |
275
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
415 if (opts[1].val.bval) |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
416 { |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
417 pn_image_data->surface[1][PN_IMG_INDEX(x, (y / 2) + (pn_image_data->height / 2))] = |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
418 pn_image_data->surface[0][PN_IMG_INDEX(x, y)]; |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
419 } |
273
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
420 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
421 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
422 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
423 else |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
424 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
425 for (y = 0; y < pn_image_data->height; y++) |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
426 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
427 for (x = 0; x < pn_image_data->width; x += 2) |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
428 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
429 pn_image_data->surface[1][PN_IMG_INDEX(x / 2, y)] = |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
430 pn_image_data->surface[0][PN_IMG_INDEX(x, y)]; |
275
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
431 if (opts[1].val.bval) |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
432 { |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
433 pn_image_data->surface[1][PN_IMG_INDEX((x / 2) + (pn_image_data->width / 2), y)] = |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
434 pn_image_data->surface[0][PN_IMG_INDEX(x, y)]; |
a1517b09cb3a
[svn] - add an option to make it only render the downscaled image.
nenolod
parents:
273
diff
changeset
|
435 } |
273
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
436 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
437 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
438 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
439 |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
440 pn_swap_surfaces (); |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
441 } |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
442 |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
443 struct pn_actuator_desc builtin_xform_halfrender = |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
444 { |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
445 "xform_halfrender", "Halfrender Transform", |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
446 "Divides the surface in half and renders it twice.", |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
447 0, xform_halfrender_opts, |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
448 NULL, NULL, xform_halfrender_exec |
fac0b72ee0de
[svn] - add halfrender transform, and a new preset which demonstrates what it can do.
nenolod
parents:
189
diff
changeset
|
449 }; |
333 | 450 |
451 /* **************** xform_movement **************** */ | |
452 struct pn_actuator_option_desc xform_movement_opts[] = | |
453 { | |
454 { "formula", "The formula to evaluate.", | |
365 | 455 OPT_TYPE_STRING, { sval: "r = r * cos(r); d = sin(d);" } }, |
456 { "polar", "Whether the coordinates are polar or not.", | |
457 OPT_TYPE_BOOLEAN, { bval: TRUE } }, | |
333 | 458 { NULL } |
459 }; | |
460 | |
461 typedef struct { | |
462 int width, height; /* Previous width and height. */ | |
463 struct xform_vector *vfield; | |
464 } PnMovementData; | |
465 | |
466 static void | |
467 xform_movement_init (gpointer *data) | |
468 { | |
469 *data = g_new0(PnMovementData, 1); | |
470 } | |
471 | |
472 static void | |
473 xform_movement_cleanup (gpointer data) | |
474 { | |
475 PnMovementData *d = (PnMovementData *) data; | |
476 | |
477 if (d) | |
478 { | |
479 if (d->vfield) | |
480 g_free (d->vfield); | |
481 g_free (d); | |
482 } | |
483 } | |
484 | |
365 | 485 inline void |
486 xform_trans_polar (struct xform_vector *vfield, gint x, gint y, | |
487 expression_t *expr, symbol_dict_t *dict) | |
488 { | |
489 gdouble *rf, *df; | |
490 gdouble xf, yf; | |
491 gint xn, yn; | |
492 | |
493 rf = dict_variable(dict, "r"); | |
494 df = dict_variable(dict, "d"); | |
495 | |
496 /* Points (xf, yf) must be in a (-1..1) square. */ | |
497 xf = 2.0 * x / (pn_image_data->width - 1) - 1.0; | |
498 yf = 2.0 * y / (pn_image_data->height - 1) - 1.0; | |
499 | |
500 /* Now, convert to polar coordinates r and d. */ | |
501 *rf = hypot(xf, yf); | |
502 *df = atan2(yf, xf); | |
503 | |
504 /* Run the script. */ | |
505 expr_execute(expr, dict); | |
506 | |
507 /* Back to (-1..1) square. */ | |
508 xf = (*rf) * cos ((*df)); | |
509 yf = (*rf) * sin ((*df)); | |
510 | |
511 /* Convert back to physical coordinates. */ | |
512 xn = (int)(((xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); | |
513 yn = (int)(((yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); | |
514 | |
515 if (xn < 0 || xn >= pn_image_data->width || yn < 0 || yn >= pn_image_data->height) | |
516 { | |
517 xn = x; yn = y; | |
518 } | |
519 | |
520 xfvec (xn, yn, &vfield[PN_IMG_INDEX (x, y)]); | |
521 } | |
522 | |
523 inline void | |
524 xform_trans_literal (struct xform_vector *vfield, gint x, gint y, | |
525 expression_t *expr, symbol_dict_t *dict) | |
526 { | |
527 gdouble *xf, *yf; | |
528 gint xn, yn; | |
529 | |
530 xf = dict_variable(dict, "x"); | |
531 yf = dict_variable(dict, "y"); | |
532 | |
533 /* Points (xf, yf) must be in a (-1..1) square. */ | |
534 *xf = 2.0 * x / (pn_image_data->width - 1) - 1.0; | |
535 *yf = 2.0 * y / (pn_image_data->height - 1) - 1.0; | |
536 | |
537 /* Run the script. */ | |
538 expr_execute(expr, dict); | |
539 | |
540 /* Convert back to physical coordinates. */ | |
541 xn = (int)(((*xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); | |
542 yn = (int)(((*yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); | |
543 | |
544 if (xn < 0 || xn >= pn_image_data->width || yn < 0 || yn >= pn_image_data->height) | |
545 { | |
546 xn = x; yn = y; | |
547 } | |
548 | |
549 xfvec (xn, yn, &vfield[PN_IMG_INDEX (x, y)]); | |
550 } | |
551 | |
333 | 552 static void |
553 xform_movement_exec (const struct pn_actuator_option *opts, | |
554 gpointer odata) | |
555 { | |
556 PnMovementData *d = (PnMovementData *) odata; | |
365 | 557 void (*transform_func)(struct xform_vector *, gint, gint, expression_t *, symbol_dict_t *) = |
558 opts[1].val.bval == TRUE ? xform_trans_polar : xform_trans_literal; | |
333 | 559 |
560 if (d->width != pn_image_data->width | |
561 || d->height != pn_image_data->height) | |
562 { | |
563 gint i, j; | |
564 gdouble *rf, *df; | |
565 expression_t *expr; | |
566 symbol_dict_t *dict; | |
567 | |
568 d->width = pn_image_data->width; | |
569 d->height = pn_image_data->height; | |
570 | |
571 if (d->vfield) | |
572 { | |
573 g_free (d->vfield); | |
574 d->vfield = NULL; | |
575 } | |
576 | |
577 if (opts[0].val.sval == NULL) | |
578 return; | |
579 | |
580 dict = dict_new(); | |
581 expr = expr_compile_string(opts[0].val.sval, dict); | |
582 if (!expr) | |
583 { | |
584 dict_free(dict); | |
585 return; | |
586 } | |
587 | |
588 rf = dict_variable(dict, "r"); | |
589 df = dict_variable(dict, "d"); | |
590 | |
591 d->vfield = g_malloc (sizeof(struct xform_vector) | |
592 * d->width * d->height); | |
593 | |
594 for (j = 0; j < pn_image_data->height; j++) | |
595 for (i = 0; i < pn_image_data->width; i++) | |
596 { | |
365 | 597 transform_func(d->vfield, i, j, expr, dict); |
333 | 598 } |
599 } | |
600 | |
601 apply_xform (d->vfield); | |
602 pn_swap_surfaces (); | |
603 } | |
604 | |
605 struct pn_actuator_desc builtin_xform_movement = | |
606 { | |
607 "xform_movement", "Movement Transform", | |
608 "A customizable blitter.", | |
609 0, xform_movement_opts, | |
610 xform_movement_init, xform_movement_cleanup, xform_movement_exec | |
611 }; | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
612 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
613 /* **************** xform_dynmovement **************** */ |
337 | 614 /* FIXME: really slow */ |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
615 struct pn_actuator_option_desc xform_dynmovement_opts[] = |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
616 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
617 { "init_script", "The formula to evaluate on init.", |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
618 OPT_TYPE_STRING, { sval: "" } }, |
366 | 619 { "beat_script", "The formula to evaluate on each beat.", |
620 OPT_TYPE_STRING, { sval: "" } }, | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
621 { "frame_script", "The formula to evaluate on each frame.", |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
622 OPT_TYPE_STRING, { sval: "" } }, |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
623 { "point_script", "The formula to evaluate.", |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
624 OPT_TYPE_STRING, { sval: "d = 0.15;" } }, |
365 | 625 { "polar", "Whether or not the coordinates to use are polar.", |
626 OPT_TYPE_BOOLEAN, { bval: TRUE } }, | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
627 { NULL } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
628 }; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
629 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
630 typedef struct { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
631 int width, height; /* Previous width and height. */ |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
632 expression_t *expr_init; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
633 expression_t *expr_frame; |
366 | 634 expression_t *expr_beat; |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
635 expression_t *expr_point; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
636 symbol_dict_t *dict; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
637 struct xform_vector *vfield; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
638 } PnDynMovementData; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
639 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
640 static void |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
641 xform_dynmovement_init (gpointer *data) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
642 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
643 *data = g_new0(PnDynMovementData, 1); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
644 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
645 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
646 static void |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
647 xform_dynmovement_cleanup (gpointer data) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
648 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
649 PnDynMovementData *d = (PnDynMovementData *) data; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
650 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
651 if (d) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
652 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
653 if (d->expr_init) |
337 | 654 expr_free (d->expr_init); |
367 | 655 if (d->expr_beat) |
656 expr_free (d->expr_beat); | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
657 if (d->expr_frame) |
337 | 658 expr_free (d->expr_frame); |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
659 if (d->expr_point) |
337 | 660 expr_free (d->expr_point); |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
661 if (d->dict) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
662 dict_free (d->dict); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
663 if (d->vfield) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
664 g_free (d->vfield); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
665 g_free (d); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
666 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
667 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
668 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
669 static void |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
670 xform_dynmovement_exec (const struct pn_actuator_option *opts, |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
671 gpointer odata) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
672 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
673 PnDynMovementData *d = (PnDynMovementData *) odata; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
674 gint i, j; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
675 gdouble *rf, *df; |
365 | 676 void (*transform_func)(struct xform_vector *, gint, gint, expression_t *, symbol_dict_t *) = |
367 | 677 opts[4].val.bval == TRUE ? xform_trans_polar : xform_trans_literal; |
678 gboolean make_table = FALSE; | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
679 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
680 if (d->width != pn_image_data->width |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
681 || d->height != pn_image_data->height) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
682 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
683 d->width = pn_image_data->width; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
684 d->height = pn_image_data->height; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
685 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
686 if (d->vfield) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
687 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
688 g_free (d->vfield); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
689 d->vfield = NULL; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
690 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
691 |
367 | 692 if (opts[3].val.sval == NULL) |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
693 return; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
694 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
695 if (!d->dict) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
696 d->dict = dict_new(); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
697 else |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
698 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
699 dict_free(d->dict); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
700 d->dict = dict_new(); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
701 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
702 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
703 if (d->expr_init) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
704 { |
337 | 705 expr_free(d->expr_init); |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
706 d->expr_init = NULL; |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
707 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
708 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
709 /* initialize */ |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
710 d->expr_init = expr_compile_string(opts[0].val.sval, d->dict); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
711 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
712 if (d->expr_init != NULL) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
713 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
714 expr_execute(d->expr_init, d->dict); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
715 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
716 |
367 | 717 d->expr_beat = expr_compile_string(opts[1].val.sval, d->dict); |
718 d->expr_frame = expr_compile_string(opts[2].val.sval, d->dict); | |
719 d->expr_point = expr_compile_string(opts[3].val.sval, d->dict); | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
720 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
721 d->vfield = g_malloc (sizeof(struct xform_vector) |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
722 * d->width * d->height); |
367 | 723 |
724 make_table = TRUE; | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
725 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
726 |
337 | 727 rf = dict_variable(d->dict, "r"); |
728 df = dict_variable(d->dict, "d"); | |
729 | |
367 | 730 if (*opts[2].val.sval != '\0' || pn_new_beat) |
731 make_table = TRUE; | |
732 | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
733 /* run the on-frame script. */ |
367 | 734 if (make_table == TRUE) |
366 | 735 { |
367 | 736 if (d->expr_beat != NULL) |
366 | 737 expr_execute(d->expr_beat, d->dict); |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
738 |
366 | 739 if (d->expr_frame != NULL) |
740 expr_execute(d->expr_frame, d->dict); | |
741 | |
742 for (j = 0; j < pn_image_data->height; j++) | |
743 for (i = 0; i < pn_image_data->width; i++) | |
744 { | |
745 transform_func(d->vfield, i, j, d->expr_point, d->dict); | |
746 } | |
747 } | |
336
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
748 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
749 apply_xform (d->vfield); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
750 pn_swap_surfaces (); |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
751 } |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
752 |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
753 struct pn_actuator_desc builtin_xform_dynmovement = |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
754 { |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
755 "xform_dynmovement", "Dynamic Movement Transform", |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
756 "A customizable blitter.", |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
757 0, xform_dynmovement_opts, |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
758 xform_dynmovement_init, xform_dynmovement_cleanup, xform_dynmovement_exec |
8554beb862c0
[svn] - implement AVS-like Trans / Dynamic Movement
nenolod
parents:
334
diff
changeset
|
759 }; |