Debian Codegraph @

src/generator/dem0scene/plasma.cpp

raw symbols SCIP
1 /*
2 Plasma 8bit demos-scene effect
3
4 Copyright (C) 2002 W.P. van Paassen - [email protected]
5 (C) 2009 Denis Roio - [email protected]
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General 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 program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22
23
24 #include <stdlib.h>
25 #include <assert.h>
26 #include <math.h>
27 #include <string.h>
28 #include <inttypes.h>
29
30 #include <frei0r.hpp>cxx . . $ `<file>/include/frei0r.hpp`/
31
32
33 typedef structcxx . . $ $anonymous_type_230be950dd5337fa_0# {
34 int16_t xcxx . . $ $anonymous_type_230be950dd5337fa_0#x.; ///< x axis position coordinate
35 int16_t ycxx . . $ $anonymous_type_230be950dd5337fa_0#y.; ///< y axis position coordinate
36 uint16_tcxx . . $ uint16_t# wcxx . . $ $anonymous_type_230be950dd5337fa_0#w.; ///< width of frame in pixels
37 uint16_tcxx . . $ uint16_t# hcxx . . $ $anonymous_type_230be950dd5337fa_0#h.; ///< height of frame in pixels
38 uint8_tcxx . . $ uint8_t# bppcxx . . $ $anonymous_type_230be950dd5337fa_0#bpp.; ///< bits per pixel
39 uint16_tcxx . . $ uint16_t# pitchcxx . . $ $anonymous_type_230be950dd5337fa_0#pitch.; ///< width of frame in bytes
40 uint32_tcxx . . $ uint32_t# sizecxx . . $ $anonymous_type_230be950dd5337fa_0#size.; ///< size of the whole frame in bytes
41 } ScreenGeometrycxx . . $ ScreenGeometry#;
42
43 typedef structcxx . . $ $anonymous_type_230be950dd5337fa_1# {
44 uint8_tcxx . . $ uint8_t# rcxx . . $ $anonymous_type_230be950dd5337fa_1#r.;
45 uint8_tcxx . . $ uint8_t# gcxx . . $ $anonymous_type_230be950dd5337fa_1#g.;
46 uint8_tcxx . . $ uint8_t# bcxx . . $ $anonymous_type_230be950dd5337fa_1#b.;
47 } Palettecxx . . $ Palette#;
48
49 class Plasmacxx . . $ Plasma#: public frei0rcxx . . $ frei0r/::sourcecxx . . $ frei0r/source# {
50
51 public:
52 Plasmacxx . . $ Plasma#Plasma(3e454b8ccf442868).(int wdt, int hgt);
53 ~cxx . . $ Plasma#`~Plasma`(49f6e7a06ebc5aa8).Plasmacxx . . $ Plasma#();
54
55 virtual void updatecxx . . $ Plasma#update(c707e0475ee5518c).(double time, uint32_tcxx . . $ uint32_t#* out);
56
57 private:
58
59 ScreenGeometrycxx . . $ ScreenGeometry# geocxx . . $ Plasma#geo.;
60
61 void _initcxx . . $ Plasma#_init(3e454b8ccf442868).(int wdt, int hgt);
62
63
64 uint16_tcxx . . $ uint16_t# pos1cxx . . $ Plasma#pos1., pos2cxx . . $ Plasma#pos2., pos3cxx . . $ Plasma#pos3., pos4cxx . . $ Plasma#pos4.;
65 uint16_tcxx . . $ uint16_t# tpos1cxx . . $ Plasma#tpos1., tpos2cxx . . $ Plasma#tpos2., tpos3cxx . . $ Plasma#tpos3., tpos4cxx . . $ Plasma#tpos4.;
66
67 int aSincxx . . $ Plasma#aSin.[512];
68
69 Palettecxx . . $ Palette# colorscxx . . $ Plasma#colors.[256];
70
71 uint32_tcxx . . $ uint32_t# palette2rgbcxx . . $ Plasma#palette2rgb(ded9d4c05c7b1550).(uint8_tcxx . . $ uint8_t# idx);
72
73 // vectors (exposed parameters from 0 to 1)
74 double speed1cxx . . $ Plasma#speed1.; // 5
75 double speed2cxx . . $ Plasma#speed2.; // 3
76 double speed3cxx . . $ Plasma#speed3.; // 3
77 double speed4cxx . . $ Plasma#speed4.; // 1
78 double move1cxx . . $ Plasma#move1.; // 9
79 double move2cxx . . $ Plasma#move2.; // 8
80
81 // scalars
82 double _speed1cxx . . $ Plasma#_speed1.; // 5
83 double _speed2cxx . . $ Plasma#_speed2.; // 3
84 double _speed3cxx . . $ Plasma#_speed3.; // 3
85 double _speed4cxx . . $ Plasma#_speed4.; // 1
86 double _move1cxx . . $ Plasma#_move1.; // 9
87 double _move2cxx . . $ Plasma#_move2.; // 8
88
89 };
90
91 void Plasmacxx . . $ Plasma#::_initcxx . . $ Plasma#_init(3e454b8ccf442868).(int wdt, int hgt) {
92 geocxx . . $ Plasma#geo..wcxx . . $ $anonymous_type_230be950dd5337fa_0#w. = wdt;
93 geocxx . . $ Plasma#geo..hcxx . . $ $anonymous_type_230be950dd5337fa_0#h. = hgt;
94 geocxx . . $ Plasma#geo..bppcxx . . $ $anonymous_type_230be950dd5337fa_0#bpp. = 32;
95 geocxx . . $ Plasma#geo..sizecxx . . $ $anonymous_type_230be950dd5337fa_0#size. = geocxx . . $ Plasma#geo..wcxx . . $ $anonymous_type_230be950dd5337fa_0#w.*geocxx . . $ Plasma#geo..hcxx . . $ $anonymous_type_230be950dd5337fa_0#h.*(geocxx . . $ Plasma#geo..bppcxx . . $ $anonymous_type_230be950dd5337fa_0#bpp./8);
96 geocxx . . $ Plasma#geo..pitchcxx . . $ $anonymous_type_230be950dd5337fa_0#pitch. = geocxx . . $ Plasma#geo..wcxx . . $ $anonymous_type_230be950dd5337fa_0#w.*(geocxx . . $ Plasma#geo..bppcxx . . $ $anonymous_type_230be950dd5337fa_0#bpp./8);
97 }
98
99 Plasmacxx . . $ Plasma#::Plasmacxx . . $ Plasma#Plasma(3e454b8ccf442868).(int wdt, int hgt) {
100
101 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(speed1cxx . . $ Plasma#speed1., "1_speed"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
102 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(speed2cxx . . $ Plasma#speed2., "2_speed"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
103 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(speed3cxx . . $ Plasma#speed3., "3_speed"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
104 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(speed4cxx . . $ Plasma#speed4., "4_speed"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
105
106 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(move1cxx . . $ Plasma#move1., "1_move"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
107 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(move2cxx . . $ Plasma#move2., "2_move"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
108
109
110 int i;
111 float rad;
112
113 _initcxx . . $ Plasma#_init(3e454b8ccf442868).(wdt, hgt);
114
115
116 /*create sin lookup table */
117 for (i = 0; i < 512; i++)
118 {
119 /* 360 / 512 * degree to rad,
120 360 degrees spread over 512 values
121 to be able to use AND 512-1 instead
122 of using modulo 360*/
123 rad = ((float)i * 0.703125) * 0.0174532;
124
125 /*using fixed point math with 1024 as base*/
126 aSincxx . . $ Plasma#aSin.[i] = sincxx . . $ sin(fbcf3211dfe1bfd1).(rad) * 1024;
127
128 }
129
130 /* create palette */
131 for (i = 0; i < 64; ++i)
132 {
133 colorscxx . . $ Plasma#colors.[i].rcxx . . $ $anonymous_type_230be950dd5337fa_1#r. = i << 2;
134 colorscxx . . $ Plasma#colors.[i].gcxx . . $ $anonymous_type_230be950dd5337fa_1#g. = 255 - ((i << 2) + 1);
135 colorscxx . . $ Plasma#colors.[i+64].rcxx . . $ $anonymous_type_230be950dd5337fa_1#r. = 255;
136 colorscxx . . $ Plasma#colors.[i+64].gcxx . . $ $anonymous_type_230be950dd5337fa_1#g. = (i << 2) + 1;
137 colorscxx . . $ Plasma#colors.[i+128].rcxx . . $ $anonymous_type_230be950dd5337fa_1#r. = 255 - ((i << 2) + 1);
138 colorscxx . . $ Plasma#colors.[i+128].gcxx . . $ $anonymous_type_230be950dd5337fa_1#g. = 255 - ((i << 2) + 1);
139 colorscxx . . $ Plasma#colors.[i+192].gcxx . . $ $anonymous_type_230be950dd5337fa_1#g. = (i << 2) + 1;
140 }
141
142 speed1cxx . . $ Plasma#speed1. = 1.;
143 speed2cxx . . $ Plasma#speed2. = 1.;
144 speed3cxx . . $ Plasma#speed3. = 1.;
145 speed4cxx . . $ Plasma#speed4. = 1.;
146 move1cxx . . $ Plasma#move1. = 1.;
147 move2cxx . . $ Plasma#move2. = 1.;
148
149 _speed1cxx . . $ Plasma#_speed1. = 5;
150 _speed2cxx . . $ Plasma#_speed2. = 3;
151 _speed3cxx . . $ Plasma#_speed3. = 3;
152 _speed4cxx . . $ Plasma#_speed4. = 1;
153 _move1cxx . . $ Plasma#_move1. = 9;
154 _move2cxx . . $ Plasma#_move2. = 8;
155
156 }
157
158 Plasmacxx . . $ Plasma#::~cxx . . $ Plasma#`~Plasma`(49f6e7a06ebc5aa8).Plasmacxx . . $ Plasma#() {
159
160 }
161
162 void Plasmacxx . . $ Plasma#::updatecxx . . $ Plasma#update(c707e0475ee5518c).(double time, uint32_tcxx . . $ uint32_t#* out) {
163 uint16_tcxx . . $ uint16_t# i, j;
164 uint8_tcxx . . $ uint8_t# index;
165 int x;
166
167 uint32_tcxx . . $ uint32_t# *image = (uint32_tcxx . . $ uint32_t#*)out;
168
169 // number parameters are not good in frei0r
170 // we need types defining multipliers and min/max values
171 // so for now we leave this generator like this
172 // but TODO ASAP new parameter types: fader and minmax
173 // then fix also parameters of the partik0l which is suffering
174 // of the same problem - jaromil
175
176 // update parameters
177 _speed1cxx . . $ Plasma#_speed1. = _speed1cxx . . $ Plasma#_speed1. * speed1cxx . . $ Plasma#speed1.;
178 _speed2cxx . . $ Plasma#_speed2. = _speed2cxx . . $ Plasma#_speed2. * speed2cxx . . $ Plasma#speed2.;
179 _speed3cxx . . $ Plasma#_speed3. = _speed3cxx . . $ Plasma#_speed3. * speed3cxx . . $ Plasma#speed3.;
180 _speed4cxx . . $ Plasma#_speed4. = _speed4cxx . . $ Plasma#_speed4. * speed4cxx . . $ Plasma#speed4.;
181
182 _move1cxx . . $ Plasma#_move1. = _move1cxx . . $ Plasma#_move1. * move1cxx . . $ Plasma#move1.;
183 _move2cxx . . $ Plasma#_move2. = _move2cxx . . $ Plasma#_move2. * move2cxx . . $ Plasma#move2.;
184
185 tpos4cxx . . $ Plasma#tpos4. = pos4cxx . . $ Plasma#pos4.;
186 tpos3cxx . . $ Plasma#tpos3. = pos3cxx . . $ Plasma#pos3.;
187
188 for (i = 0; i < geocxx . . $ Plasma#geo..hcxx . . $ $anonymous_type_230be950dd5337fa_0#h.; ++i) {
189 tpos1cxx . . $ Plasma#tpos1. = pos1cxx . . $ Plasma#pos1. + (int)_speed1cxx . . $ Plasma#_speed1.;
190 tpos2cxx . . $ Plasma#tpos2. = pos2cxx . . $ Plasma#pos2. + (int)_speed2cxx . . $ Plasma#_speed2.;
191
192 tpos3cxx . . $ Plasma#tpos3. &= 511;
193 tpos4cxx . . $ Plasma#tpos4. &= 511;
194
195 for (j = 0; j < geocxx . . $ Plasma#geo..wcxx . . $ $anonymous_type_230be950dd5337fa_0#w.; ++j) {
196 tpos1cxx . . $ Plasma#tpos1. &= 511;
197 tpos2cxx . . $ Plasma#tpos2. &= 511;
198
199 x = aSincxx . . $ Plasma#aSin.[tpos1cxx . . $ Plasma#tpos1.] + aSincxx . . $ Plasma#aSin.[tpos2cxx . . $ Plasma#tpos2.] + aSincxx . . $ Plasma#aSin.[tpos3cxx . . $ Plasma#tpos3.] + aSincxx . . $ Plasma#aSin.[tpos4cxx . . $ Plasma#tpos4.];
200 /*actual plasma calculation*/
201
202 index = 128 + (x >> 4);
203 /* fixed point multiplication but optimized so basically
204 it says (x * (64 * 1024) / (1024 * 1024)), x is
205 already multiplied by 1024*/
206
207 *image++ = palette2rgbcxx . . $ Plasma#palette2rgb(ded9d4c05c7b1550).(index);
208
209 tpos1cxx . . $ Plasma#tpos1. += (int)_speed1cxx . . $ Plasma#_speed1.;
210 tpos2cxx . . $ Plasma#tpos2. += (int)_speed2cxx . . $ Plasma#_speed2.;
211 }
212
213 tpos4cxx . . $ Plasma#tpos4. += (int)_speed3cxx . . $ Plasma#_speed3.;
214 tpos3cxx . . $ Plasma#tpos3. += (int)_speed4cxx . . $ Plasma#_speed4.;
215 }
216
217 /* move plasma */
218
219 pos1cxx . . $ Plasma#pos1. += (int)_move1cxx . . $ Plasma#_move1.;
220 pos3cxx . . $ Plasma#pos3. += (int)_move2cxx . . $ Plasma#_move2.;
221 }
222
223 uint32_tcxx . . $ uint32_t# Plasmacxx . . $ Plasma#::palette2rgbcxx . . $ Plasma#palette2rgb(ded9d4c05c7b1550).(uint8_tcxx . . $ uint8_t# idx) {
224 uint32_tcxx . . $ uint32_t# rgba;
225 // just for little endian
226 // TODO: big endian
227 rgba = (colorscxx . . $ Plasma#colors.[idx].rcxx . . $ $anonymous_type_230be950dd5337fa_1#r. << 16)
228 | (colorscxx . . $ Plasma#colors.[idx].gcxx . . $ $anonymous_type_230be950dd5337fa_1#g. << 8)
229 | (colorscxx . . $ Plasma#colors.[idx].bcxx . . $ $anonymous_type_230be950dd5337fa_1#b. )
230 | (0xff << 24);
231
232 return rgba;
233 }
234
235 frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<Plasmacxx . . $ Plasma#> plugincxx . . $ plugin.("Plasma"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
236 "Demo scene 8bit plasma"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
237 "Jaromil"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
238 0,3);