diff options
Diffstat (limited to 'apps/plugins/greyscale.c')
-rw-r--r-- | apps/plugins/greyscale.c | 352 |
1 files changed, 352 insertions, 0 deletions
diff --git a/apps/plugins/greyscale.c b/apps/plugins/greyscale.c new file mode 100644 index 0000000000..de90d5737f --- /dev/null +++ b/apps/plugins/greyscale.c | |||
@@ -0,0 +1,352 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Greyscale demo plugin | ||
11 | * | ||
12 | * Copyright (C) 2004-2008 Jens Arnold | ||
13 | * | ||
14 | * All files in this archive are subject to the GNU General Public License. | ||
15 | * See the file COPYING in the source tree root for full license agreement. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "plugin.h" | ||
23 | #include "helper.h" | ||
24 | |||
25 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) | ||
26 | #include "grey.h" | ||
27 | |||
28 | PLUGIN_HEADER | ||
29 | |||
30 | /* variable button definitions */ | ||
31 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
32 | #define GREYSCALE_SHIFT BUTTON_ON | ||
33 | #define GREYSCALE_UP BUTTON_UP | ||
34 | #define GREYSCALE_DOWN BUTTON_DOWN | ||
35 | #define GREYSCALE_LEFT BUTTON_LEFT | ||
36 | #define GREYSCALE_RIGHT BUTTON_RIGHT | ||
37 | #define GREYSCALE_OFF BUTTON_OFF | ||
38 | |||
39 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
40 | #define GREYSCALE_SHIFT BUTTON_MENU | ||
41 | #define GREYSCALE_UP BUTTON_UP | ||
42 | #define GREYSCALE_DOWN BUTTON_DOWN | ||
43 | #define GREYSCALE_LEFT BUTTON_LEFT | ||
44 | #define GREYSCALE_RIGHT BUTTON_RIGHT | ||
45 | #define GREYSCALE_OFF BUTTON_OFF | ||
46 | |||
47 | #elif CONFIG_KEYPAD == IRIVER_H100_PAD | ||
48 | #define GREYSCALE_SHIFT BUTTON_ON | ||
49 | #define GREYSCALE_UP BUTTON_UP | ||
50 | #define GREYSCALE_DOWN BUTTON_DOWN | ||
51 | #define GREYSCALE_LEFT BUTTON_LEFT | ||
52 | #define GREYSCALE_RIGHT BUTTON_RIGHT | ||
53 | #define GREYSCALE_OFF BUTTON_OFF | ||
54 | |||
55 | #define GREYSCALE_RC_OFF BUTTON_RC_STOP | ||
56 | |||
57 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ | ||
58 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) | ||
59 | #define GREYSCALE_SHIFT BUTTON_SELECT | ||
60 | #define GREYSCALE_UP BUTTON_SCROLL_BACK | ||
61 | #define GREYSCALE_DOWN BUTTON_SCROLL_FWD | ||
62 | #define GREYSCALE_LEFT BUTTON_LEFT | ||
63 | #define GREYSCALE_RIGHT BUTTON_RIGHT | ||
64 | #define GREYSCALE_OFF BUTTON_MENU | ||
65 | |||
66 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD | ||
67 | #define GREYSCALE_SHIFT BUTTON_PLAY | ||
68 | #define GREYSCALE_UP BUTTON_UP | ||
69 | #define GREYSCALE_DOWN BUTTON_DOWN | ||
70 | #define GREYSCALE_LEFT BUTTON_LEFT | ||
71 | #define GREYSCALE_RIGHT BUTTON_RIGHT | ||
72 | #define GREYSCALE_OFF BUTTON_EQ | ||
73 | #endif | ||
74 | |||
75 | #define GFX_HEIGHT (LCD_HEIGHT-8) | ||
76 | #if LCD_WIDTH < 160 | ||
77 | #define GFX_GREYTONE_WIDTH 86 | ||
78 | #define GFX_GREYTONE_STEP 3 | ||
79 | #else | ||
80 | #define GFX_GREYTONE_WIDTH 128 | ||
81 | #define GFX_GREYTONE_STEP 2 | ||
82 | #endif | ||
83 | /******************************* Globals ***********************************/ | ||
84 | |||
85 | static struct plugin_api* rb; /* global api struct pointer */ | ||
86 | static char pbuf[32]; /* global printf buffer */ | ||
87 | static unsigned char *gbuf; | ||
88 | static size_t gbuf_size = 0; | ||
89 | |||
90 | /**************************** main function ********************************/ | ||
91 | |||
92 | void cleanup(void *parameter) | ||
93 | { | ||
94 | (void)parameter; | ||
95 | |||
96 | grey_release(); /* switch off overlay and deinitialize */ | ||
97 | /* Turn on backlight timeout (revert to settings) */ | ||
98 | backlight_use_settings(rb); /* backlight control in lib/helper.c */ | ||
99 | } | ||
100 | |||
101 | /* this is only a demo of what the framework can do */ | ||
102 | int main(void) | ||
103 | { | ||
104 | int time; | ||
105 | int x, y, i; | ||
106 | int button, scroll_amount; | ||
107 | bool black_border = false; | ||
108 | |||
109 | static const unsigned char rockbox[] = { | ||
110 | /* ........................................... | ||
111 | * .####...###...###..#...#.####...###..#...#. | ||
112 | * .#...#.#...#.#...#.#..#..#...#.#...#..#.#.. | ||
113 | * .####..#...#.#.....###...####..#...#...#... | ||
114 | * .#..#..#...#.#...#.#..#..#...#.#...#..#.#.. | ||
115 | * .#...#..###...###..#...#.####...###..#...#. | ||
116 | * ........................................... | ||
117 | * 43 x 7 pixel, 1 bpp | ||
118 | */ | ||
119 | 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22, | ||
120 | 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E, | ||
121 | 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14, | ||
122 | 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08, | ||
123 | 0x14, 0x22, 0x00 | ||
124 | }; | ||
125 | |||
126 | static const unsigned char showing[] = { | ||
127 | /* ....................................... | ||
128 | * ..####.#...#..###..#...#.#.#...#..####. | ||
129 | * .#.....#...#.#...#.#...#.#.##..#.#..... | ||
130 | * ..###..#####.#...#.#.#.#.#.#.#.#.#..##. | ||
131 | * .....#.#...#.#...#.#.#.#.#.#..##.#...#. | ||
132 | * .####..#...#..###...#.#..#.#...#..####. | ||
133 | * ....................................... | ||
134 | * 39 x 7 pixel, 1 bpp | ||
135 | */ | ||
136 | 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08, | ||
137 | 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E, | ||
138 | 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08, | ||
139 | 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00 | ||
140 | }; | ||
141 | |||
142 | static const unsigned char grayscale_grey[] = { | ||
143 | /* ....................................................... | ||
144 | * ..####.####...###..#...#..####..###...###..#.....#####. | ||
145 | * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#..... | ||
146 | * .#..##.####..#####..#.#...###..#.....#####.#.....####.. | ||
147 | * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#..... | ||
148 | * ..####.#...#.#...#...#...####...###..#...#.#####.#####. | ||
149 | * ....................................................... | ||
150 | * 55 x 7 pixel, 8 bpp | ||
151 | */ | ||
152 | 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
153 | 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
154 | 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
155 | 110,110,110,110,110,110,110, | ||
156 | 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24, | ||
157 | 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120, | ||
158 | 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120, | ||
159 | 120, 36, 36, 36, 36, 36,120, | ||
160 | 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130, | ||
161 | 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230, | ||
162 | 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130, | ||
163 | 130, 36,130,130,130,130,130, | ||
164 | 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24, | ||
165 | 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230, | ||
166 | 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140, | ||
167 | 140, 36, 36, 36, 36,140,140, | ||
168 | 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130, | ||
169 | 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230, | ||
170 | 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130, | ||
171 | 130, 36,130,130,130,130,130, | ||
172 | 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120, | ||
173 | 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120, | ||
174 | 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234, | ||
175 | 120, 36, 36, 36, 36, 36,120, | ||
176 | 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
177 | 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
178 | 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
179 | 110,110,110,110,110,110,110 | ||
180 | }; | ||
181 | |||
182 | /* Turn off backlight timeout */ | ||
183 | backlight_force_on(rb); /* backlight control in lib/helper.c */ | ||
184 | |||
185 | rb->lcd_setfont(FONT_SYSFIXED); /* select default font */ | ||
186 | |||
187 | /* get the remainder of the plugin buffer */ | ||
188 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | ||
189 | |||
190 | /* initialize the greyscale buffer: | ||
191 | Archos: 112 pixels wide, 7 rows (56 pixels) high. | ||
192 | H1x0: 160 pixels wide, 30 rows (120 pixels) high. */ | ||
193 | if (!grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, GFX_HEIGHT, NULL)) | ||
194 | { | ||
195 | rb->splash(HZ, "Not enough memory."); | ||
196 | return PLUGIN_ERROR; | ||
197 | } | ||
198 | |||
199 | /* place greyscale overlay 1 row down */ | ||
200 | grey_set_position(0, 8); | ||
201 | |||
202 | rb->lcd_puts(0, 0, "Shades: 129"); | ||
203 | rb->lcd_update(); | ||
204 | |||
205 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
206 | rb->cpu_boost(true); | ||
207 | #endif | ||
208 | grey_show(true); /* switch on greyscale overlay */ | ||
209 | |||
210 | time = *rb->current_tick; /* start time measurement */ | ||
211 | |||
212 | grey_set_background(150); | ||
213 | grey_clear_display(); /* fill everything with grey 150 */ | ||
214 | |||
215 | /* draw a dark grey line star background */ | ||
216 | grey_set_foreground(80); | ||
217 | for (y = 0; y < GFX_HEIGHT; y += 8) /* horizontal part */ | ||
218 | { | ||
219 | grey_drawline(0, y, (LCD_WIDTH-1), (GFX_HEIGHT-1) - y); /*grey lines */ | ||
220 | } | ||
221 | for (x = 10; x <= LCD_WIDTH; x += 10) /* vertical part */ | ||
222 | { | ||
223 | grey_drawline(x, 0, (LCD_WIDTH-1) - x, (GFX_HEIGHT-1)); /*grey lines */ | ||
224 | } | ||
225 | |||
226 | grey_set_foreground(0); | ||
227 | grey_drawrect(0, 0, LCD_WIDTH, GFX_HEIGHT); /* black border */ | ||
228 | |||
229 | /* draw grey tones */ | ||
230 | for (i = 0; i < GFX_GREYTONE_WIDTH; i++) | ||
231 | { | ||
232 | x = ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2) + i; | ||
233 | grey_set_foreground(GFX_GREYTONE_STEP * i); | ||
234 | /* vertical lines */ | ||
235 | grey_vline(x, (GFX_HEIGHT/8), (GFX_HEIGHT-GFX_HEIGHT/8-1)); | ||
236 | } | ||
237 | |||
238 | grey_set_drawmode(DRMODE_COMPLEMENT); | ||
239 | /* invert rectangle (lower half) */ | ||
240 | grey_fillrect((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2+1), | ||
241 | GFX_GREYTONE_WIDTH, (GFX_HEIGHT/2-GFX_HEIGHT/8-1)); | ||
242 | /* invert a line */ | ||
243 | grey_hline((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2, | ||
244 | (LCD_WIDTH+GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2-1)); | ||
245 | |||
246 | /* show bitmaps (1 bit and 8 bit) */ | ||
247 | /* opaque */ | ||
248 | grey_set_drawinfo(DRMODE_SOLID, 255, 100); | ||
249 | grey_mono_bitmap(rockbox, | ||
250 | MAX((LCD_WIDTH/2-47), ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2)), | ||
251 | (5*GFX_HEIGHT/16-4), 43, 7); | ||
252 | /* transparent */ | ||
253 | grey_set_drawinfo(DRMODE_FG, 0, 100); | ||
254 | grey_mono_bitmap(showing, (LCD_WIDTH/2+4) , (5*GFX_HEIGHT/16-4), 39, 7); | ||
255 | /* greyscale */ | ||
256 | grey_gray_bitmap(grayscale_grey, ((LCD_WIDTH-55)/2), (11*GFX_HEIGHT/16-4), | ||
257 | 55, 7); | ||
258 | |||
259 | grey_update(); | ||
260 | |||
261 | time = *rb->current_tick - time; /* end time measurement */ | ||
262 | |||
263 | rb->snprintf(pbuf, sizeof(pbuf), "Shades: 129, %d.%02ds", | ||
264 | time / 100, time % 100); | ||
265 | rb->lcd_puts(0, 0, pbuf); | ||
266 | grey_deferred_lcd_update(); /* schedule an lcd_update() */ | ||
267 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
268 | rb->cpu_boost(false); | ||
269 | #endif | ||
270 | |||
271 | /* drawing is now finished, play around with scrolling | ||
272 | * until you press OFF or connect USB | ||
273 | */ | ||
274 | grey_set_background(255); | ||
275 | while (true) | ||
276 | { | ||
277 | scroll_amount = 1; | ||
278 | |||
279 | button = rb->button_get(true); | ||
280 | |||
281 | if (rb->default_event_handler_ex(button, cleanup, NULL) | ||
282 | == SYS_USB_CONNECTED) | ||
283 | return PLUGIN_USB_CONNECTED; | ||
284 | |||
285 | if (button & GREYSCALE_SHIFT) | ||
286 | { | ||
287 | if (!black_border) | ||
288 | { | ||
289 | grey_set_background(0); | ||
290 | black_border = true; | ||
291 | } | ||
292 | } | ||
293 | else | ||
294 | { | ||
295 | if (black_border) | ||
296 | { | ||
297 | grey_set_background(255); | ||
298 | black_border = false; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | if (button & BUTTON_REPEAT) | ||
303 | scroll_amount = 4; | ||
304 | |||
305 | switch (button & ~(GREYSCALE_SHIFT | BUTTON_REPEAT)) | ||
306 | { | ||
307 | case GREYSCALE_LEFT: | ||
308 | |||
309 | grey_scroll_left(scroll_amount); /* scroll left */ | ||
310 | grey_update(); | ||
311 | break; | ||
312 | |||
313 | case GREYSCALE_RIGHT: | ||
314 | |||
315 | grey_scroll_right(scroll_amount); /* scroll right */ | ||
316 | grey_update(); | ||
317 | break; | ||
318 | |||
319 | case GREYSCALE_UP: | ||
320 | |||
321 | grey_scroll_up(scroll_amount); /* scroll up */ | ||
322 | grey_update(); | ||
323 | break; | ||
324 | |||
325 | case GREYSCALE_DOWN: | ||
326 | |||
327 | grey_scroll_down(scroll_amount); /* scroll down */ | ||
328 | grey_update(); | ||
329 | break; | ||
330 | #ifdef GREYSCALE_RC_OFF | ||
331 | case GREYSCALE_RC_OFF: | ||
332 | #endif | ||
333 | case GREYSCALE_OFF: | ||
334 | |||
335 | cleanup(NULL); | ||
336 | return PLUGIN_OK; | ||
337 | } | ||
338 | } | ||
339 | } | ||
340 | |||
341 | /*************************** Plugin entry point ****************************/ | ||
342 | |||
343 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
344 | { | ||
345 | rb = api; /* copy to global api pointer */ | ||
346 | (void)parameter; | ||
347 | |||
348 | return main(); | ||
349 | } | ||
350 | |||
351 | #endif /* #ifdef HAVE_LCD_BITMAP */ | ||
352 | |||