diff options
-rw-r--r-- | apps/plugins/plasma.c | 116 |
1 files changed, 62 insertions, 54 deletions
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c index f9fc80e81c..668cff0cd7 100644 --- a/apps/plugins/plasma.c +++ b/apps/plugins/plasma.c | |||
@@ -22,13 +22,11 @@ | |||
22 | * | 22 | * |
23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
24 | 24 | ||
25 | #ifndef SIMULATOR /* not for simulator by now */ | ||
26 | #include "plugin.h" | 25 | #include "plugin.h" |
27 | 26 | ||
28 | #ifdef HAVE_LCD_BITMAP /* and also not for the Player */ | 27 | #if defined(HAVE_LCD_BITMAP) && (defined(HAVE_LCD_COLOR) || !defined(SIMULATOR)) |
29 | #ifdef HAVE_LCD_COLOR | 28 | |
30 | #include "xlcd.h" | 29 | #ifndef HAVE_LCD_COLOR |
31 | #else | ||
32 | #include "gray.h" | 30 | #include "gray.h" |
33 | #endif | 31 | #endif |
34 | 32 | ||
@@ -38,10 +36,13 @@ PLUGIN_HEADER | |||
38 | 36 | ||
39 | static struct plugin_api* rb; /* global api struct pointer */ | 37 | static struct plugin_api* rb; /* global api struct pointer */ |
40 | static unsigned char wave_array[256]; /* Pre calculated wave array */ | 38 | static unsigned char wave_array[256]; /* Pre calculated wave array */ |
41 | static unsigned char colours[256]; /* Smooth transition of shades */ | ||
42 | #ifdef HAVE_LCD_COLOR | 39 | #ifdef HAVE_LCD_COLOR |
43 | static unsigned char colorbuffer[3*LCD_HEIGHT*LCD_WIDTH]; /* off screen buffer */ | 40 | static fb_data colours[256]; /* Smooth transition of shades */ |
41 | static int redfactor = 1, greenfactor = 2, bluefactor = 3; | ||
42 | static int redphase = 0, greenphase = 50, bluephase = 100; | ||
43 | /* lower chance of gray at regular intervals */ | ||
44 | #else | 44 | #else |
45 | static unsigned char colours[256]; /* Smooth transition of shades */ | ||
45 | static unsigned char graybuffer[LCD_HEIGHT*LCD_WIDTH]; /* off screen buffer */ | 46 | static unsigned char graybuffer[LCD_HEIGHT*LCD_WIDTH]; /* off screen buffer */ |
46 | static unsigned char *gbuf; | 47 | static unsigned char *gbuf; |
47 | static unsigned int gbuf_size = 0; | 48 | static unsigned int gbuf_size = 0; |
@@ -142,29 +143,50 @@ static void wave_table_generate(void) | |||
142 | } | 143 | } |
143 | } | 144 | } |
144 | 145 | ||
145 | /* | 146 | #ifdef HAVE_LCD_COLOR |
146 | * This function is to make a smooth shade from white into | 147 | /* Make a smooth colour cycle. */ |
147 | * black and back into white again. I thought this would be quicker | 148 | void shades_generate(int time) |
148 | * than calculating on the fly - am I wrong? | 149 | { |
149 | */ | 150 | int i; |
151 | unsigned red, green, blue; | ||
152 | unsigned r = time * redfactor + redphase; | ||
153 | unsigned g = time * greenfactor + greenphase; | ||
154 | unsigned b = time * bluefactor + bluephase; | ||
155 | |||
156 | for(i=0; i < 256; ++i) | ||
157 | { | ||
158 | r &= 0xFF; g &= 0xFF; b &= 0xFF; | ||
159 | |||
160 | red = 2 * r; | ||
161 | if (red > 255) | ||
162 | red = 510 - red; | ||
163 | green = 2 * g; | ||
164 | if (green > 255) | ||
165 | green = 510 - green; | ||
166 | blue = 2 * b; | ||
167 | if (blue > 255) | ||
168 | blue= 510 - blue; | ||
150 | 169 | ||
170 | colours[i] = LCD_RGBPACK(red, green, blue); | ||
171 | |||
172 | r++; g++; b++; | ||
173 | } | ||
174 | } | ||
175 | #else | ||
176 | /* Make a smooth shade from black into white and back into black again. */ | ||
151 | static void shades_generate(void) | 177 | static void shades_generate(void) |
152 | { | 178 | { |
153 | int i=1; | 179 | int i, y; |
154 | int j=0; | ||
155 | int nAdd=2; | ||
156 | 180 | ||
157 | for(i=0; i < 256; ++i) | 181 | for(i=0; i < 256; ++i) |
158 | { | 182 | { |
159 | colours[i] = j; | 183 | y = 2 * i; |
160 | j += nAdd; | 184 | if (y > 255) |
161 | 185 | y = 510 - y; | |
162 | if(j > 240 || j < 2) | 186 | colours[i] = y; |
163 | { | ||
164 | nAdd = -nAdd; | ||
165 | } | ||
166 | } | 187 | } |
167 | } | 188 | } |
189 | #endif | ||
168 | 190 | ||
169 | void cleanup(void *parameter) | 191 | void cleanup(void *parameter) |
170 | { | 192 | { |
@@ -184,32 +206,25 @@ void cleanup(void *parameter) | |||
184 | int main(void) | 206 | int main(void) |
185 | { | 207 | { |
186 | plasma_frequency = 1; | 208 | plasma_frequency = 1; |
187 | int shades, button, x, y; | 209 | int button, x, y; |
188 | unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z; | 210 | unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z; |
189 | int n=0; | ||
190 | #ifdef HAVE_LCD_COLOR | 211 | #ifdef HAVE_LCD_COLOR |
212 | fb_data *ptr; | ||
191 | int time=0; | 213 | int time=0; |
192 | int redfactor=1, greenfactor=2, bluefactor=3; | 214 | #else |
193 | int redphase=0, greenphase=50, bluephase=100; /* lower chance of gray at * | 215 | unsigned char *ptr; |
194 | * regular intervals */ | ||
195 | #endif | 216 | #endif |
217 | |||
196 | /*Generate the neccesary pre calced stuff*/ | 218 | /*Generate the neccesary pre calced stuff*/ |
197 | wave_table_generate(); | 219 | wave_table_generate(); |
198 | shades_generate(); | ||
199 | 220 | ||
200 | #ifdef HAVE_LCD_COLOR | 221 | #ifndef HAVE_LCD_COLOR |
201 | shades = 256; | 222 | shades_generate(); /* statically */ |
202 | #else | 223 | |
203 | /* get the remainder of the plugin buffer */ | 224 | /* get the remainder of the plugin buffer */ |
204 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 225 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
205 | 226 | ||
206 | shades = gray_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT/8, | 227 | gray_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT/8, 32, NULL); |
207 | 32, NULL) + 1; | ||
208 | #endif | ||
209 | |||
210 | #ifdef HAVE_LCD_COLOR | ||
211 | xlcd_init(rb); | ||
212 | #else | ||
213 | /* switch on grayscale overlay */ | 228 | /* switch on grayscale overlay */ |
214 | gray_show(true); | 229 | gray_show(true); |
215 | #endif | 230 | #endif |
@@ -220,9 +235,14 @@ int main(void) | |||
220 | p1=p2=p3=p4=0; | 235 | p1=p2=p3=p4=0; |
221 | while (true) | 236 | while (true) |
222 | { | 237 | { |
238 | #ifdef HAVE_LCD_COLOR | ||
239 | shades_generate(time++); /* dynamically */ | ||
240 | ptr = rb->lcd_framebuffer; | ||
241 | #else | ||
242 | ptr = graybuffer; | ||
243 | #endif | ||
223 | t1=p1; | 244 | t1=p1; |
224 | t2=p2; | 245 | t2=p2; |
225 | n=0; | ||
226 | for(y = 0; y < LCD_HEIGHT; ++y) | 246 | for(y = 0; y < LCD_HEIGHT; ++y) |
227 | { | 247 | { |
228 | t3=p3; | 248 | t3=p3; |
@@ -230,19 +250,10 @@ int main(void) | |||
230 | for(x = 0; x < LCD_WIDTH; ++x) | 250 | for(x = 0; x < LCD_WIDTH; ++x) |
231 | { | 251 | { |
232 | z = wave_array[t1] + wave_array[t2] + wave_array[t3] | 252 | z = wave_array[t1] + wave_array[t2] + wave_array[t3] |
233 | + wave_array[t4]; | 253 | + wave_array[t4]; |
234 | #ifdef HAVE_LCD_COLOR | 254 | *ptr++ = colours[z]; |
235 | colorbuffer[n] = colours[(z+time*redfactor+redphase)%256]; | ||
236 | ++n; | ||
237 | colorbuffer[n] = colours[(z+time*greenfactor+greenphase)%256]; | ||
238 | ++n; | ||
239 | colorbuffer[n] = colours[(z+time*bluefactor+bluephase)%256]; | ||
240 | #else | ||
241 | graybuffer[n] = colours[z]; | ||
242 | #endif | ||
243 | t3+=1; | 255 | t3+=1; |
244 | t4+=2; | 256 | t4+=2; |
245 | ++n; | ||
246 | } | 257 | } |
247 | t1+=2; | 258 | t1+=2; |
248 | t2+=1; | 259 | t2+=1; |
@@ -253,8 +264,6 @@ int main(void) | |||
253 | p3+=sp3; | 264 | p3+=sp3; |
254 | p4-=sp4; | 265 | p4-=sp4; |
255 | #ifdef HAVE_LCD_COLOR | 266 | #ifdef HAVE_LCD_COLOR |
256 | time++; | ||
257 | xlcd_color_bitmap(colorbuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT); | ||
258 | rb->lcd_update(); | 267 | rb->lcd_update(); |
259 | #else | 268 | #else |
260 | gray_ub_gray_bitmap(graybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT); | 269 | gray_ub_gray_bitmap(graybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT); |
@@ -317,5 +326,4 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
317 | return ret; | 326 | return ret; |
318 | } | 327 | } |
319 | 328 | ||
320 | #endif // #ifdef HAVE_LCD_BITMAP | 329 | #endif // HAVE_LCD_BITMAP && (HAVE_LCD_COLOR || !SIMULATOR) |
321 | #endif // #ifndef SIMULATOR | ||