1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Kevin Ferrare
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
25 #include "lib/helper.h"
26 #ifdef HAVE_LCD_BITMAP
28 #include "lib/pluginlib_actions.h"
29 #include "lib/fixedpoint.h"
31 #ifndef HAVE_LCD_COLOR
35 #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
36 /* Archos has not enough plugin RAM for full-width fire :( */
37 #define FIRE_WIDTH 106
40 #define FIRE_WIDTH LCD_WIDTH
46 #ifndef HAVE_LCD_COLOR
48 static unsigned char draw_buffer
[FIRE_WIDTH
];
53 const struct button_mapping
* plugin_contexts
[]= {
54 generic_increase_decrease
,
56 #if defined(HAVE_REMOTE_LCD)
61 #define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
63 #define FIRE_QUIT PLA_QUIT
64 #define FIRE_SWITCH_FLAMES_TYPE PLA_LEFT
65 #define FIRE_SWITCH_FLAMES_MOVING PLA_RIGHT
66 #define FIRE_INCREASE_MULT PLA_INC
67 #define FIRE_DECREASE_MULT PLA_DEC
69 #define MIN_FLAME_VALUE 0
70 #define COOL_MAX (440/LCD_HEIGHT+2)
72 #ifndef HAVE_LCD_COLOR
73 static unsigned char palette
[256];
75 void color_palette_init(unsigned char* palette
)
78 for(i
=0;i
<=160;i
++)//palette[i]=(3/2)*i
81 /* 'regular' fire doesn't exceed this value */
82 for(;i
<=255;i
++)//palette[i]=(3/20)*i+216
83 palette
[i
]=(i
*3+20*217)/20;
87 static fb_data palette
[256];
90 * Color palette generation algorithm taken from
91 * the "The Demo Effects Collection" GPL project
92 * Copyright (C) 2002 W.P. van Paassen
94 void color_palette_init(fb_data
* palette
)
97 for (i
= 0; i
< 32; i
++){
98 /* black to blue, 32 values*/
99 palette
[i
]=LCD_RGBPACK(0, 0, 2*i
);
101 /* blue to red, 32 values*/
102 palette
[i
+ 32]=LCD_RGBPACK(8*i
, 0, 64 - 2*i
);
104 /* red to yellow, 32 values*/
105 palette
[i
+ 64]=LCD_RGBPACK(255, 8*i
, 0);
107 /* yellow to white, 162 values */
108 palette
[i
+ 96]=LCD_RGBPACK(255, 255, 0 + 4*i
);
109 palette
[i
+ 128]=LCD_RGBPACK(255, 255, 64 + 4*i
);
110 palette
[i
+ 160]=LCD_RGBPACK(255, 255, 128 + 4*i
);
111 palette
[i
+ 192]=LCD_RGBPACK(255, 255, 192 + i
);
112 palette
[i
+ 224]=LCD_RGBPACK(255, 255, 224 + i
);
118 static void tab_init_rand(unsigned char *tab
, unsigned int tab_size
,
121 unsigned char *end
= tab
+ tab_size
;
124 *tab
++ = (unsigned char)rb
->rand() % rand_max
;
128 unsigned char fire
[LCD_HEIGHT
+3][FIRE_WIDTH
];
129 unsigned char cooling_map
[LCD_HEIGHT
][FIRE_WIDTH
];
134 /* makes the instance a global variable since it's too big to fit on the target's stack */
135 static struct fire fire
;
137 static inline void fire_convolve(struct fire
* fire
)
139 unsigned int pixel_value
;
140 unsigned int cooling_value
;
141 unsigned char *ptr
, *end
, *cool
;
142 unsigned int mult
=fire
->mult
;
145 /* Convolve the pixels and handle cooling (to add nice shapes effects later) */
146 cool
= &fire
->cooling_map
[0][0];
147 ptr
= &fire
->fire
[0][0];
148 end
= ptr
+ LCD_HEIGHT
*FIRE_WIDTH
;
150 switch (fire
->flames_type
){
153 pixel_value
= ptr
[FIRE_WIDTH
-1] /* fire[y+1][x-1] */
154 + ptr
[2*FIRE_WIDTH
] /* fire[y+2][x] */
155 + ptr
[FIRE_WIDTH
+1] /* fire[y+1][x+1] */
156 + ptr
[3*FIRE_WIDTH
]; /* fire[y+3][x] */
157 pixel_value
= FMULU(pixel_value
, mult
) >> 10;
159 cooling_value
= *cool
++;
160 if (cooling_value
<= pixel_value
)
161 pixel_value
-= cooling_value
;
162 /* else it's too cold, don't frost the pixels !!! */
164 if (pixel_value
> 255)
167 *ptr
++ = pixel_value
;
174 pixel_value
= ptr
[FIRE_WIDTH
-1] /* fire[y+1][x-1] */
175 + ptr
[FIRE_WIDTH
] /* fire[y+1][x] */
176 + ptr
[FIRE_WIDTH
+1] /* fire[y+1][x+1] */
177 + ptr
[2*FIRE_WIDTH
]; /* fire[y+2][x] */
178 pixel_value
= FMULU(pixel_value
, mult
) >> 10;
180 cooling_value
= *cool
++;
181 if (cooling_value
<= pixel_value
)
182 pixel_value
-= cooling_value
;
183 /* else it's too cold, don't frost the pixels !!! */
185 if (pixel_value
> 255)
188 *ptr
++ = pixel_value
;
192 default: /* We should never reach this */
198 static void fire_generate_bottom_seed(struct fire
* fire
)
200 unsigned char *ptr
, *end
;
201 ptr
= &fire
->fire
[LCD_HEIGHT
][0];
202 end
= ptr
+ FIRE_WIDTH
;
204 *ptr
++ = (MIN_FLAME_VALUE
+ rb
->rand() % (256-MIN_FLAME_VALUE
));
208 static inline void fire_step(struct fire
* fire
)
211 /* Randomize the bottom line */
212 fire_generate_bottom_seed(fire
);
213 /* Add here further effects like fire letters, ball ... */
218 static void fire_init(struct fire
* fire
)
223 rb
->memset(&fire
->fire
[0][0], 0, sizeof(fire
->fire
));
224 tab_init_rand(&fire
->cooling_map
[0][0], LCD_HEIGHT
*FIRE_WIDTH
, COOL_MAX
);
225 fire_generate_bottom_seed(fire
);
228 static inline void fire_draw(struct fire
* fire
)
231 unsigned char *src
= &fire
->fire
[0][0];
232 #ifndef HAVE_LCD_COLOR
233 unsigned char *dest
, *end
;
238 for (y
= 0; y
< LCD_HEIGHT
; y
++){
239 #ifndef HAVE_LCD_COLOR
242 dest
= rb
->lcd_framebuffer
+ LCD_WIDTH
* y
+ FIRE_XPOS
;
244 end
= dest
+ FIRE_WIDTH
;
247 *dest
++ = palette
[*src
++];
249 #ifndef HAVE_LCD_COLOR
250 grey_ub_gray_bitmap(draw_buffer
, 0, y
, FIRE_WIDTH
, 1);
253 #ifdef HAVE_LCD_COLOR
258 void cleanup(void *parameter
)
261 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
262 rb
->cpu_boost(false);
264 #ifndef HAVE_LCD_COLOR
267 /* Turn on backlight timeout (revert to settings) */
268 backlight_use_settings(); /* backlight control in lib/helper.c */
272 #ifndef HAVE_LCD_COLOR
276 size_t gbuf_size
= 0;
278 /* get the remainder of the plugin buffer */
279 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
281 if (!grey_init(gbuf
, gbuf_size
, GREY_ON_COP
,
282 FIRE_WIDTH
, LCD_HEIGHT
, NULL
)){
283 rb
->splash(HZ
, "not enough memory");
286 /* switch on greyscale overlay */
287 grey_set_position(FIRE_XPOS
, 0);
297 #ifndef HAVE_LCD_COLOR
298 if(init_grey()!=PLUGIN_OK
)
299 return(PLUGIN_ERROR
);
301 color_palette_init(palette
);
303 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
313 action
= pluginlib_getaction(0, plugin_contexts
, PLA_ARRAY_COUNT
);
320 case FIRE_INCREASE_MULT
:
324 case FIRE_DECREASE_MULT
:
329 case FIRE_SWITCH_FLAMES_TYPE
:
330 fire
.flames_type
= (fire
.flames_type
+ 1) % 2;
333 case FIRE_SWITCH_FLAMES_MOVING
:
334 fire
.moving
= !fire
.moving
;
338 if (rb
->default_event_handler_ex(action
, cleanup
, NULL
)
339 == SYS_USB_CONNECTED
)
340 return PLUGIN_USB_CONNECTED
;
345 /*************************** Plugin entry point ****************************/
347 enum plugin_status
plugin_start(const void* parameter
)
353 rb
->lcd_set_backdrop(NULL
);
355 /* Turn off backlight timeout */
356 backlight_force_on(); /* backlight control in lib/helper.c */
363 #endif /* #ifdef HAVE_LCD_BITMAP */