summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/fire.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c
index fb08e5a5f1..2d7a66ea16 100644
--- a/apps/plugins/fire.c
+++ b/apps/plugins/fire.c
@@ -24,7 +24,16 @@
24 24
25#ifdef HAVE_LCD_BITMAP /* and also not for the Player */ 25#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
26#ifndef HAVE_LCD_COLOR 26#ifndef HAVE_LCD_COLOR
27#include "gray.h" 27#include "grey.h"
28#endif
29
30#if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
31/* Archos has not enough plugin RAM for full-width fire :( */
32#define FIRE_WIDTH 108
33#define FIRE_XPOS 2
34#else
35#define FIRE_WIDTH LCD_WIDTH
36#define FIRE_XPOS 0
28#endif 37#endif
29 38
30PLUGIN_HEADER 39PLUGIN_HEADER
@@ -33,13 +42,13 @@ PLUGIN_HEADER
33 42
34static struct plugin_api* rb; /* global api struct pointer */ 43static struct plugin_api* rb; /* global api struct pointer */
35 44
36static unsigned char fire[LCD_HEIGHT+3][LCD_WIDTH]; 45static unsigned char fire[LCD_HEIGHT+3][FIRE_WIDTH];
37static unsigned char cooling_map[LCD_HEIGHT][LCD_WIDTH]; 46static unsigned char cooling_map[LCD_HEIGHT][FIRE_WIDTH];
38 47
39#ifndef HAVE_LCD_COLOR 48#ifndef HAVE_LCD_COLOR
40static unsigned char *gbuf; 49static unsigned char *gbuf;
41static size_t gbuf_size = 0; 50static size_t gbuf_size = 0;
42static unsigned char draw_buffer[8*LCD_WIDTH]; 51static unsigned char draw_buffer[FIRE_WIDTH];
43#endif 52#endif
44 53
45/* Key assignement */ 54/* Key assignement */
@@ -230,7 +239,7 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
230 if(moving) 239 if(moving)
231 {/* moving must be true the first time the function is called */ 240 {/* moving must be true the first time the function is called */
232 ptr = &fire[LCD_HEIGHT][0]; 241 ptr = &fire[LCD_HEIGHT][0];
233 end = ptr + LCD_WIDTH; 242 end = ptr + FIRE_WIDTH;
234 243
235 do 244 do
236 { 245 {
@@ -243,17 +252,17 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
243 /* Convolve the pixels and handle cooling (to add nice shapes effects later) */ 252 /* Convolve the pixels and handle cooling (to add nice shapes effects later) */
244 cool = &cooling_map[0][0]; 253 cool = &cooling_map[0][0];
245 ptr = &fire[0][0]; 254 ptr = &fire[0][0];
246 end = ptr + LCD_HEIGHT*LCD_WIDTH; 255 end = ptr + LCD_HEIGHT*FIRE_WIDTH;
247 256
248 switch (flames_type) 257 switch (flames_type)
249 { 258 {
250 case 0: 259 case 0:
251 do 260 do
252 { 261 {
253 pixel_value = ptr[LCD_WIDTH-1] /* fire[y+1][x-1] */ 262 pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */
254 + ptr[2*LCD_WIDTH] /* fire[y+2][x] */ 263 + ptr[2*FIRE_WIDTH] /* fire[y+2][x] */
255 + ptr[LCD_WIDTH+1] /* fire[y+1][x+1] */ 264 + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */
256 + ptr[3*LCD_WIDTH]; /* fire[y+3][x] */ 265 + ptr[3*FIRE_WIDTH]; /* fire[y+3][x] */
257 pixel_value = FMULU(pixel_value, mult) >> 10; 266 pixel_value = FMULU(pixel_value, mult) >> 10;
258 267
259 cooling_value = *cool++; 268 cooling_value = *cool++;
@@ -273,10 +282,10 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
273 mult -= 2; 282 mult -= 2;
274 do 283 do
275 { 284 {
276 pixel_value = ptr[LCD_WIDTH-1] /* fire[y+1][x-1] */ 285 pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */
277 + ptr[LCD_WIDTH] /* fire[y+1][x] */ 286 + ptr[FIRE_WIDTH] /* fire[y+1][x] */
278 + ptr[LCD_WIDTH+1] /* fire[y+1][x+1] */ 287 + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */
279 + ptr[2*LCD_WIDTH]; /* fire[y+2][x] */ 288 + ptr[2*FIRE_WIDTH]; /* fire[y+2][x] */
280 pixel_value = FMULU(pixel_value, mult) >> 10; 289 pixel_value = FMULU(pixel_value, mult) >> 10;
281 290
282 cooling_value = *cool++; 291 cooling_value = *cool++;
@@ -300,31 +309,34 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
300 309
301static inline void fire_draw(void) 310static inline void fire_draw(void)
302{ 311{
312 int y;
313 unsigned char *src = &fire[0][0];
303#ifndef HAVE_LCD_COLOR 314#ifndef HAVE_LCD_COLOR
304 int block;
305 unsigned char *dest, *end; 315 unsigned char *dest, *end;
306 unsigned char *src = &fire[0][0];
307 316
308 for (block = 0; block < LCD_HEIGHT; block += 8) 317 for (y = 0; y < LCD_HEIGHT; y++)
309 { 318 {
310 dest = draw_buffer; 319 dest = draw_buffer;
311 end = dest + 8*LCD_WIDTH; 320 end = dest + FIRE_WIDTH;
312 321
313 do 322 do
314 *dest++ = palette[*src++]; 323 *dest++ = palette[*src++];
315 while(dest < end); 324 while (dest < end);
316 325
317 gray_ub_gray_bitmap(draw_buffer, 0, block, LCD_WIDTH, 8); 326 grey_ub_gray_bitmap(draw_buffer, 0, y, FIRE_WIDTH, 1);
318 } 327 }
319#else 328#else
320 fb_data* dest = rb->lcd_framebuffer; 329 fb_data *dest, *end;
321 fb_data* end = rb->lcd_framebuffer+(LCD_WIDTH*LCD_HEIGHT);
322 unsigned char* src = &fire[0][0];
323 330
324 do 331 for (y = 0; y < LCD_HEIGHT; y++)
325 *dest++ = colorpalette[*src++]; 332 {
326 while (dest < end); 333 dest = rb->lcd_framebuffer + LCD_WIDTH * y + FIRE_XPOS;
334 end = dest + FIRE_WIDTH;
327 335
336 do
337 *dest++ = colorpalette[*src++];
338 while (dest < end);
339 }
328 rb->lcd_update(); 340 rb->lcd_update();
329#endif 341#endif
330} 342}
@@ -337,7 +349,7 @@ void cleanup(void *parameter)
337 rb->cpu_boost(false); 349 rb->cpu_boost(false);
338#endif 350#endif
339#ifndef HAVE_LCD_COLOR 351#ifndef HAVE_LCD_COLOR
340 gray_release(); 352 grey_release();
341#endif 353#endif
342 /* Turn on backlight timeout (revert to settings) */ 354 /* Turn on backlight timeout (revert to settings) */
343 backlight_use_settings(rb); /* backlight control in lib/helper.c */ 355 backlight_use_settings(rb); /* backlight control in lib/helper.c */
@@ -354,27 +366,26 @@ int main(void)
354 int mult = 261; 366 int mult = 261;
355 int flames_type=0; 367 int flames_type=0;
356 bool moving=true; 368 bool moving=true;
357#ifndef HAVE_LCD_COLOR
358 int shades;
359 369
370#ifndef HAVE_LCD_COLOR
360 /* get the remainder of the plugin buffer */ 371 /* get the remainder of the plugin buffer */
361 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); 372 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
362 shades = gray_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, 373
363 32, 1<<8, NULL) + 1; 374 if (!grey_init(rb, gbuf, gbuf_size, false, FIRE_WIDTH, LCD_HEIGHT, NULL))
364 if(shades <= 1)
365 { 375 {
366 rb->splash(HZ, "not enough memory"); 376 rb->splash(HZ, "not enough memory");
367 return PLUGIN_ERROR; 377 return PLUGIN_ERROR;
368 } 378 }
369 /* switch on grayscale overlay */ 379 /* switch on greyscale overlay */
370 gray_show(true); 380 grey_set_position(FIRE_XPOS, 0);
381 grey_show(true);
371#endif 382#endif
372 383
373#ifdef HAVE_ADJUSTABLE_CPU_FREQ 384#ifdef HAVE_ADJUSTABLE_CPU_FREQ
374 rb->cpu_boost(true); 385 rb->cpu_boost(true);
375#endif 386#endif
376 rb->memset(&fire[0][0], 0, sizeof(fire)); 387 rb->memset(&fire[0][0], 0, sizeof(fire));
377 tab_init_rand(&cooling_map[0][0], LCD_HEIGHT*LCD_WIDTH, COOL_MAX); 388 tab_init_rand(&cooling_map[0][0], LCD_HEIGHT*FIRE_WIDTH, COOL_MAX);
378 while (true) 389 while (true)
379 { 390 {
380 fire_generate(mult, flames_type, moving); 391 fire_generate(mult, flames_type, moving);