Debian Codegraph @

src/filter/vertigo/vertigo.c

raw symbols SCIP
1 /*
2 * VertigoTV - Alpha blending with zoomed and rotated images.
3 * Copyright (C) 2001 FUKUCHI Kentarou
4 * parametrization by jaromil
5 * ported to frei0r by joepadmiraal
6 *
7 * This source code is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This source code is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
15 * to the GNU Public License for more details.
16 *
17 * You should have received a copy of the GNU Public License along
18 * with this source code; if not, write to: Free Software Foundation,
19 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23
24 #include "frei0r.h"
25 #include <stdlib.h>
26 #include <assert.h>
27 #include <math.h>
28 #include <string.h>
29
30
31 typedef struct vertigo_instance
32 {
33 unsigned int width;
34 unsigned int height;
35 int x,y,xc,yc;
36 double phase_increment;
37 double zoomrate;
38 double tfactor;
39 uint32_t *current_buffer, *alt_buffer;
40
41 uint32_t *buffer;
42 uint8_t is_buffer_init;
43 int dx, dy;
44 int sx, sy;
45
46 int pixels;
47 double phase;
48 } vertigo_instance_t;
49
50
51
52 int f0r_init()
53 {
54 return 1;
55 }
56
57 void f0r_deinit()
58 {
59 /* no deinitialization required */
60 }
61
62 void f0r_get_plugin_info(f0r_plugin_info_t* vertigoInfo)
63 {
64 vertigoInfo->name = "Vertigo";
65 vertigoInfo->author = "Fukuchi Kentarou";
66 vertigoInfo->plugin_type = F0R_PLUGIN_TYPE_FILTER;
67 vertigoInfo->color_model = F0R_COLOR_MODEL_RGBA8888;
68 vertigoInfo->frei0r_version = FREI0R_MAJOR_VERSION;
69 vertigoInfo->major_version = 1;
70 vertigoInfo->minor_version = 2;
71 vertigoInfo->num_params = 2;
72 vertigoInfo->explanation = "alpha blending with zoomed and rotated images";
73 }
74
75 void f0r_get_param_info(f0r_param_info_t* info, int param_index)
76 {
77 switch(param_index)
78 {
79 case 0:
80 info->name = "PhaseIncrement";
81 info->type = F0R_PARAM_DOUBLE;
82 info->explanation = "Phase increment";
83 break;
84 case 1:
85 info->name = "Zoomrate";
86 info->type = F0R_PARAM_DOUBLE;
87 info->explanation = "Zoomrate";
88 break;
89 }
90 }
91
92 f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
93 {
94 vertigo_instance_t* inst =
95 (vertigo_instance_t*)calloc(1, sizeof(*inst));
96 inst->width = width; inst->height = height;
97
98 inst->pixels = width*height;
99
100 inst->buffer = (uint32_t*)calloc(inst->pixels*2, sizeof(uint32_t));
101 if(inst->buffer == NULL) {
102 free(inst);
103 return 0;
104 }
105
106 inst->current_buffer = inst->buffer;
107 inst->alt_buffer = inst->buffer + inst->pixels;
108
109 inst->phase = 0.0;
110 inst->phase_increment = 0.02;
111 inst->zoomrate = 1.01;
112
113 inst->x = width>>1;
114 inst->y = height>>1;
115 inst->xc = inst->x*inst->x;
116 inst->yc = inst->y*inst->y;
117 inst->tfactor = (inst->xc+inst->yc) * inst->zoomrate;
118
119 return (f0r_instance_t)inst;
120 }
121
122 void f0r_destruct(f0r_instance_t instance)
123 {
124 vertigo_instance_t* inst = (vertigo_instance_t*)instance;
125 free(inst->buffer);
126 free(instance);
127 }
128
129 void f0r_set_param_value(f0r_instance_t instance,
130 f0r_param_t param, int param_index)
131 {
132 assert(instance);
133 vertigo_instance_t* inst = (vertigo_instance_t*)instance;
134
135 switch(param_index)
136 {
137 case 0:
138 /* phase_increment */
139 inst->phase_increment = *((double*)param);
140 break;
141 case 1:
142 /* zoomrate */
143 inst->zoomrate = *((double*)param) * 5;
144 inst->tfactor = (inst->xc+inst->yc) * inst->zoomrate;
145 break;
146 }
147 }
148
149 void f0r_get_param_value(f0r_instance_t instance,
150 f0r_param_t param, int param_index)
151 {
152 assert(instance);
153 vertigo_instance_t* inst = (vertigo_instance_t*)instance;
154
155 switch(param_index)
156 {
157 case 0:
158 /* phase_increment */
159 *((double*)param) = (double) (inst->phase_increment);
160 break;
161 case 1:
162 /* zoomrate */
163 *((double*)param) = (double) (inst->zoomrate) / 5.;
164 break;
165 }
166 }
167
168 void f0r_update(f0r_instance_t instance, double time,
169 const uint32_t* inframe, uint32_t* outframe)
170 {
171 vertigo_instance_t* inst = (vertigo_instance_t*)instance;
172 unsigned int w = inst->width;
173 unsigned int h = inst->height;
174 int x = inst->x;
175 int y = inst->y;
176 int xc = inst->xc;
177 int yc = inst->yc;
178 double tfactor = inst->tfactor;
179
180 uint32_t* dst = outframe;
181 const uint32_t* src = inframe;
182 uint32_t *p;
183 uint32_t v;
184 uint32_t alpha;
185 int ox, oy;
186 int i;
187
188 double vx, vy;
189 double dizz;
190
191 dizz = sin(inst->phase) * 10 + sin(inst->phase*1.9+5) * 5;
192
193 if (!inst->is_buffer_init)
194 {
195 memcpy(inst->buffer, inframe, inst->pixels * sizeof(uint32_t));
196 memcpy(&inst->buffer[inst->pixels], inframe, inst->pixels * sizeof(uint32_t));
197 inst->is_buffer_init = 1;
198 }
199
200 if(w > h)
201 {
202 if(dizz >= 0)
203 {
204 if(dizz > x) dizz = x;
205 vx = (x*(x-dizz) + yc) / tfactor;
206 } else
207 {
208 if(dizz < -x) dizz = -x;
209 vx = (x*(x+dizz) + yc) / tfactor;
210 }
211 vy = (dizz*y) / tfactor;
212
213 } else
214 {
215 if(dizz >= 0)
216 {
217 if(dizz > y) dizz = y;
218 vx = (xc + y*(y-dizz)) / tfactor;
219 } else
220 {
221 if(dizz < -y) dizz = -y;
222 vx = (xc + y*(y+dizz)) / tfactor;
223 }
224 vy = (dizz*x) / tfactor;
225 }
226
227 inst->dx = vx * 65536;
228 inst->dy = vy * 65536;
229 inst->sx = (-vx * x + vy * y + x + cos(inst->phase*5) * 2) * 65536;
230 inst->sy = (-vx * y - vy * x + y + sin(inst->phase*6) * 2) * 65536;
231
232 inst->phase += inst->phase_increment;
233 if(inst->phase > 5700000) inst->phase = 0;
234
235
236 p = inst->alt_buffer;
237
238 for(y=h; y>0; y--)
239 {
240 ox = inst->sx;
241 oy = inst->sy;
242 for(x=w; x>0; x--)
243 {
244 i = (oy>>16)*w + (ox>>16);
245 if(i<0) i = 0;
246 if(i>=inst->pixels) i = inst->pixels - 1;
247 v = inst->current_buffer[i] & 0xfcfcff;
248 alpha = *src & 0xff000000;
249 v = (v * 3) + ((*src++) & 0xfcfcff);
250 *dst++ = (v>>2) | alpha;
251 *p++ = (v>>2);
252 ox += inst->dx;
253 oy += inst->dy;
254 }
255 inst->sx -= inst->dy;
256 inst->sy += inst->dx;
257 }
258
259 p = inst->current_buffer;
260 inst->current_buffer = inst->alt_buffer;
261 inst->alt_buffer = p;
262
263 }