gst/goom/: Add license headers in all source files. Remove filter.c from
[platform/upstream/gst-plugins-good.git] / gst / goom / plugin_info.c
1 /* Goom Project
2  * Copyright (C) <2003> iOS-Software
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <gst/gst.h>
24
25 #include "goom_config.h"
26
27 #include "goom_plugin_info.h"
28 #include "goom_fx.h"
29 #include "drawmethods.h"
30 #include <math.h>
31 #include <stdio.h>
32
33
34 #if defined (HAVE_CPU_PPC64) || defined (HAVE_CPU_PPC)
35 #include <sys/types.h>
36 #include <sys/sysctl.h>
37 #include "ppc_zoom_ultimate.h"
38 #include "ppc_drawings.h"
39 #endif /* HAVE_CPU_PPC64 || HAVE_CPU_PPC */
40
41
42 #ifdef HAVE_MMX
43 #include "mmx.h"
44 #endif /* HAVE_MMX */
45
46 #include <liboil/liboil.h>
47 #include <liboil/liboilfunction.h>
48 #include <liboil/liboilcpu.h>
49
50 GST_DEBUG_CATEGORY_EXTERN (goom_debug);
51 #define GST_CAT_DEFAULT goom_debug
52
53 static void
54 setOptimizedMethods (PluginInfo * p)
55 {
56
57   unsigned int cpuFlavour = oil_cpu_get_flags ();
58
59   /* set default methods */
60   p->methods.draw_line = draw_line;
61   p->methods.zoom_filter = zoom_filter_c;
62 /*    p->methods.create_output_with_brightness = create_output_with_brightness;*/
63
64   GST_INFO ("liboil cpu flags: 0x%08x", cpuFlavour);
65
66 /* FIXME: what about HAVE_CPU_X86_64 ? */
67 #ifdef HAVE_CPU_I386
68 #ifdef HAVE_MMX
69   GST_INFO ("have an x86");
70   if (cpuFlavour & OIL_IMPL_FLAG_MMXEXT) {
71     GST_INFO ("Extended MMX detected. Using the fastest methods!");
72     p->methods.draw_line = draw_line_xmmx;
73     p->methods.zoom_filter = zoom_filter_xmmx;
74   } else if (cpuFlavour & OIL_IMPL_FLAG_MMX) {
75     GST_INFO ("MMX detected. Using fast methods!");
76     p->methods.draw_line = draw_line_mmx;
77     p->methods.zoom_filter = zoom_filter_mmx;
78   } else {
79     GST_INFO ("Too bad ! No SIMD optimization available for your CPU.");
80   }
81 #endif
82 #endif /* HAVE_CPU_I386 */
83
84 /* disable all PPC stuff until someone finds out what to use here instead of
85  * CPU_OPTION_64_BITS, and until someone fixes the assembly build for ppc */
86 #if 0
87 #ifdef HAVE_CPU_PPC64
88   if ((cpuFlavour & CPU_OPTION_64_BITS) != 0) {
89 /*            p->methods.create_output_with_brightness = ppc_brightness_G5;        */
90     p->methods.zoom_filter = ppc_zoom_generic;
91   }
92 #endif /* HAVE_CPU_PPC64 */
93
94 #ifdef HAVE_CPU_PPC
95   if ((cpuFlavour & OIL_IMPL_FLAG_ALTIVEC) != 0) {
96 /*            p->methods.create_output_with_brightness = ppc_brightness_G4;        */
97     p->methods.zoom_filter = ppc_zoom_G4;
98   } else {
99 /*            p->methods.create_output_with_brightness = ppc_brightness_generic;*/
100     p->methods.zoom_filter = ppc_zoom_generic;
101   }
102 #endif /* HAVE_CPU_PPC */
103 #endif
104
105   cpuFlavour = 0;               /* trick compiler into thinking variable is used */
106 }
107
108 void
109 plugin_info_init (PluginInfo * pp, int nbVisuals)
110 {
111
112   PluginInfo p;
113   int i;
114
115   p.sound.speedvar = p.sound.accelvar = p.sound.totalgoom = 0;
116   p.sound.prov_max = 0;
117   p.sound.goom_limit = 1;
118   p.sound.allTimesMax = 1;
119   p.sound.timeSinceLastGoom = 1;
120   p.sound.timeSinceLastBigGoom = 1;
121   p.sound.cycle = 0;
122
123   p.sound.volume_p = secure_f_feedback ("Sound Volume");
124   p.sound.accel_p = secure_f_feedback ("Sound Acceleration");
125   p.sound.speed_p = secure_f_feedback ("Sound Speed");
126   p.sound.goom_limit_p = secure_f_feedback ("Goom Limit");
127   p.sound.last_goom_p = secure_f_feedback ("Goom Detection");
128   p.sound.last_biggoom_p = secure_f_feedback ("Big Goom Detection");
129   p.sound.goom_power_p = secure_f_feedback ("Goom Power");
130
131   p.sound.biggoom_speed_limit_p = secure_i_param ("Big Goom Speed Limit");
132   IVAL (p.sound.biggoom_speed_limit_p) = 10;
133   IMIN (p.sound.biggoom_speed_limit_p) = 0;
134   IMAX (p.sound.biggoom_speed_limit_p) = 100;
135   ISTEP (p.sound.biggoom_speed_limit_p) = 1;
136
137   p.sound.biggoom_factor_p = secure_i_param ("Big Goom Factor");
138   IVAL (p.sound.biggoom_factor_p) = 10;
139   IMIN (p.sound.biggoom_factor_p) = 0;
140   IMAX (p.sound.biggoom_factor_p) = 100;
141   ISTEP (p.sound.biggoom_factor_p) = 1;
142
143   p.sound.params = plugin_parameters ("Sound", 11);
144
145   p.nbParams = 0;
146   p.params = NULL;
147   p.nbVisuals = nbVisuals;
148   p.visuals = (VisualFX **) malloc (sizeof (VisualFX *) * nbVisuals);
149
150   *pp = p;
151   pp->sound.params.params[0] = &pp->sound.biggoom_speed_limit_p;
152   pp->sound.params.params[1] = &pp->sound.biggoom_factor_p;
153   pp->sound.params.params[2] = 0;
154   pp->sound.params.params[3] = &pp->sound.volume_p;
155   pp->sound.params.params[4] = &pp->sound.accel_p;
156   pp->sound.params.params[5] = &pp->sound.speed_p;
157   pp->sound.params.params[6] = 0;
158   pp->sound.params.params[7] = &pp->sound.goom_limit_p;
159   pp->sound.params.params[8] = &pp->sound.goom_power_p;
160   pp->sound.params.params[9] = &pp->sound.last_goom_p;
161   pp->sound.params.params[10] = &pp->sound.last_biggoom_p;
162
163   pp->statesNumber = 8;
164   pp->statesRangeMax = 510;
165   {
166     GoomState states[8] = {
167       {1, 0, 0, 1, 4, 0, 100}
168       ,
169       {1, 0, 0, 0, 1, 101, 140}
170       ,
171       {1, 0, 0, 1, 2, 141, 200}
172       ,
173       {0, 1, 0, 1, 2, 201, 260}
174       ,
175       {0, 1, 0, 1, 0, 261, 330}
176       ,
177       {0, 1, 1, 1, 4, 331, 400}
178       ,
179       {0, 0, 1, 0, 5, 401, 450}
180       ,
181       {0, 0, 1, 1, 1, 451, 510}
182     };
183     for (i = 0; i < 8; ++i)
184       pp->states[i] = states[i];
185   }
186   pp->curGState = &(pp->states[6]);
187
188   /* datas for the update loop */
189   pp->update.lockvar = 0;
190   pp->update.goomvar = 0;
191   pp->update.loopvar = 0;
192   pp->update.stop_lines = 0;
193   pp->update.ifs_incr = 1;      /* dessiner l'ifs (0 = non: > = increment) */
194   pp->update.decay_ifs = 0;     /* disparition de l'ifs */
195   pp->update.recay_ifs = 0;     /* dedisparition de l'ifs */
196   pp->update.cyclesSinceLastChange = 0;
197   pp->update.drawLinesDuration = 80;
198   pp->update.lineMode = pp->update.drawLinesDuration;
199
200   pp->update.switchMultAmount = (29.0f / 30.0f);
201   pp->update.switchIncrAmount = 0x7f;
202   pp->update.switchMult = 1.0f;
203   pp->update.switchIncr = pp->update.switchIncrAmount;
204
205   pp->update.stateSelectionRnd = 0;
206   pp->update.stateSelectionBlocker = 0;
207   pp->update.previousZoomSpeed = 128;
208
209   {
210     ZoomFilterData zfd = {
211       127, 8, 16,
212       1, 1, 0, NORMAL_MODE,
213       0, 0, 0, 0, 0
214     };
215     pp->update.zoomFilterData = zfd;
216   }
217
218   setOptimizedMethods (pp);
219
220   for (i = 0; i < 0xffff; i++) {
221     pp->sintable[i] =
222         (int) (1024 * sin ((double) i * 360 / (sizeof (pp->sintable) /
223                 sizeof (pp->sintable[0]) - 1) * 3.141592 / 180) + .5);
224     /* sintable [us] = (int)(1024.0f * sin (us*2*3.31415f/0xffff)) ; */
225   }
226 }
227
228 void
229 plugin_info_add_visual (PluginInfo * p, int i, VisualFX * visual)
230 {
231   p->visuals[i] = visual;
232   if (i == p->nbVisuals - 1) {
233     ++i;
234     p->nbParams = 1;
235     while (i--) {
236       if (p->visuals[i]->params)
237         p->nbParams++;
238     }
239     p->params =
240         (PluginParameters *) malloc (sizeof (PluginParameters) * p->nbParams);
241     i = p->nbVisuals;
242     p->nbParams = 1;
243     p->params[0] = p->sound.params;
244     while (i--) {
245       if (p->visuals[i]->params)
246         p->params[p->nbParams++] = *(p->visuals[i]->params);
247     }
248   }
249 }
250
251 void
252 plugin_info_free (PluginInfo * p)
253 {
254   goom_plugin_parameters_free (&p->sound.params);
255
256   if (p->params)
257     free (p->params);
258   free (p->visuals);
259 }