New makefile solution: A single invocation of 'make' to build the entire tree. Fully...
[kugel-rb.git] / apps / plugins / greyscale.c
blobcd8db5bf8b5b2be8f7ca533b85d7977d687d4540
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Greyscale demo plugin
12 * Copyright (C) 2004-2008 Jens Arnold
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 ****************************************************************************/
24 #include "plugin.h"
25 #include "lib/helper.h"
27 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
28 #include "lib/grey.h"
30 PLUGIN_HEADER
32 /* variable button definitions */
33 #if CONFIG_KEYPAD == RECORDER_PAD
34 #define GREYSCALE_SHIFT BUTTON_ON
35 #define GREYSCALE_UP BUTTON_UP
36 #define GREYSCALE_DOWN BUTTON_DOWN
37 #define GREYSCALE_LEFT BUTTON_LEFT
38 #define GREYSCALE_RIGHT BUTTON_RIGHT
39 #define GREYSCALE_OFF BUTTON_OFF
41 #elif CONFIG_KEYPAD == ONDIO_PAD
42 #define GREYSCALE_SHIFT BUTTON_MENU
43 #define GREYSCALE_UP BUTTON_UP
44 #define GREYSCALE_DOWN BUTTON_DOWN
45 #define GREYSCALE_LEFT BUTTON_LEFT
46 #define GREYSCALE_RIGHT BUTTON_RIGHT
47 #define GREYSCALE_OFF BUTTON_OFF
49 #elif CONFIG_KEYPAD == IRIVER_H100_PAD
50 #define GREYSCALE_SHIFT BUTTON_ON
51 #define GREYSCALE_UP BUTTON_UP
52 #define GREYSCALE_DOWN BUTTON_DOWN
53 #define GREYSCALE_LEFT BUTTON_LEFT
54 #define GREYSCALE_RIGHT BUTTON_RIGHT
55 #define GREYSCALE_OFF BUTTON_OFF
57 #define GREYSCALE_RC_OFF BUTTON_RC_STOP
59 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) || (CONFIG_KEYPAD == MROBE100_PAD)
60 #define GREYSCALE_SHIFT BUTTON_PLAY /* won't work, but define it anyway */
61 #define GREYSCALE_UP BUTTON_UP
62 #define GREYSCALE_DOWN BUTTON_DOWN
63 #define GREYSCALE_LEFT BUTTON_LEFT
64 #define GREYSCALE_RIGHT BUTTON_RIGHT
65 #define GREYSCALE_OFF BUTTON_POWER
67 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
68 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
69 #define GREYSCALE_SHIFT BUTTON_SELECT
70 #define GREYSCALE_UP BUTTON_SCROLL_BACK
71 #define GREYSCALE_DOWN BUTTON_SCROLL_FWD
72 #define GREYSCALE_LEFT BUTTON_LEFT
73 #define GREYSCALE_RIGHT BUTTON_RIGHT
74 #define GREYSCALE_OFF BUTTON_MENU
76 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
77 #define GREYSCALE_SHIFT BUTTON_PLAY
78 #define GREYSCALE_UP BUTTON_UP
79 #define GREYSCALE_DOWN BUTTON_DOWN
80 #define GREYSCALE_LEFT BUTTON_LEFT
81 #define GREYSCALE_RIGHT BUTTON_RIGHT
82 #define GREYSCALE_OFF BUTTON_EQ
84 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
85 #define GREYSCALE_SHIFT BUTTON_RC_PLAY /* somewhat dangerous... */
86 #define GREYSCALE_UP BUTTON_RC_VOL_UP
87 #define GREYSCALE_DOWN BUTTON_RC_VOL_DOWN
88 #define GREYSCALE_LEFT BUTTON_RC_REW
89 #define GREYSCALE_RIGHT BUTTON_RC_FF
90 #define GREYSCALE_OFF BUTTON_RC_REC
92 #define GREYSCALE_RC_OFF BUTTON_REC
94 #endif
96 #define GFX_HEIGHT (LCD_HEIGHT-8)
97 #if LCD_WIDTH < 160
98 #define GFX_GREYTONE_WIDTH 86
99 #define GFX_GREYTONE_STEP 3
100 #else
101 #define GFX_GREYTONE_WIDTH 128
102 #define GFX_GREYTONE_STEP 2
103 #endif
104 /******************************* Globals ***********************************/
106 GREY_INFO_STRUCT
107 static const struct plugin_api* rb; /* global api struct pointer */
108 static char pbuf[32]; /* global printf buffer */
109 static unsigned char *gbuf;
110 static size_t gbuf_size = 0;
112 /**************************** main function ********************************/
114 void cleanup(void *parameter)
116 (void)parameter;
118 grey_release(); /* switch off overlay and deinitialize */
119 /* Turn on backlight timeout (revert to settings) */
120 backlight_use_settings(rb); /* backlight control in lib/helper.c */
123 /* this is only a demo of what the framework can do */
124 int main(void)
126 int time;
127 int x, y, i;
128 int button, scroll_amount;
129 bool black_border = false;
131 static const unsigned char rockbox[] = {
132 /* ...........................................
133 * .####...###...###..#...#.####...###..#...#.
134 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
135 * .####..#...#.#.....###...####..#...#...#...
136 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
137 * .#...#..###...###..#...#.####...###..#...#.
138 * ...........................................
139 * 43 x 7 pixel, 1 bpp
141 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
142 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
143 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
144 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
145 0x14, 0x22, 0x00
148 static const unsigned char showing[] = {
149 /* .......................................
150 * ..####.#...#..###..#...#.#.#...#..####.
151 * .#.....#...#.#...#.#...#.#.##..#.#.....
152 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
153 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
154 * .####..#...#..###...#.#..#.#...#..####.
155 * .......................................
156 * 39 x 7 pixel, 1 bpp
158 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
159 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
160 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
161 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
164 static const unsigned char grayscale_grey[] = {
165 /* .......................................................
166 * ..####.####...###..#...#..####..###...###..#.....#####.
167 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
168 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
169 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
170 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
171 * .......................................................
172 * 55 x 7 pixel, 8 bpp
174 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
175 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
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,
178 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
179 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
180 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
181 120, 36, 36, 36, 36, 36,120,
182 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
183 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
184 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
185 130, 36,130,130,130,130,130,
186 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
187 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
188 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
189 140, 36, 36, 36, 36,140,140,
190 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
191 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
192 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
193 130, 36,130,130,130,130,130,
194 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
195 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
196 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
197 120, 36, 36, 36, 36, 36,120,
198 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
199 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
200 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
201 110,110,110,110,110,110,110
204 /* Turn off backlight timeout */
205 backlight_force_on(rb); /* backlight control in lib/helper.c */
207 rb->lcd_setfont(FONT_SYSFIXED); /* select default font */
209 /* get the remainder of the plugin buffer */
210 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
212 /* initialize the greyscale buffer:
213 Archos: 112 pixels wide, 7 rows (56 pixels) high.
214 H1x0: 160 pixels wide, 30 rows (120 pixels) high. */
215 if (!grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP,
216 LCD_WIDTH, GFX_HEIGHT, NULL))
218 rb->splash(HZ, "Not enough memory.");
219 return PLUGIN_ERROR;
222 /* place greyscale overlay 1 row down */
223 grey_set_position(0, 8);
225 rb->lcd_puts(0, 0, "Shades: 129");
226 rb->lcd_update();
228 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
229 rb->cpu_boost(true);
230 #endif
231 grey_show(true); /* switch on greyscale overlay */
233 time = *rb->current_tick; /* start time measurement */
235 grey_set_background(150);
236 grey_clear_display(); /* fill everything with grey 150 */
238 /* draw a dark grey line star background */
239 grey_set_foreground(80);
240 for (y = 0; y < GFX_HEIGHT; y += 8) /* horizontal part */
242 grey_drawline(0, y, (LCD_WIDTH-1), (GFX_HEIGHT-1) - y); /*grey lines */
244 for (x = 10; x <= LCD_WIDTH; x += 10) /* vertical part */
246 grey_drawline(x, 0, (LCD_WIDTH-1) - x, (GFX_HEIGHT-1)); /*grey lines */
249 grey_set_foreground(0);
250 grey_drawrect(0, 0, LCD_WIDTH, GFX_HEIGHT); /* black border */
252 /* draw grey tones */
253 for (i = 0; i < GFX_GREYTONE_WIDTH; i++)
255 x = ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2) + i;
256 grey_set_foreground(GFX_GREYTONE_STEP * i);
257 /* vertical lines */
258 grey_vline(x, (GFX_HEIGHT/8), (GFX_HEIGHT-GFX_HEIGHT/8-1));
261 grey_set_drawmode(DRMODE_COMPLEMENT);
262 /* invert rectangle (lower half) */
263 grey_fillrect((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2+1),
264 GFX_GREYTONE_WIDTH, (GFX_HEIGHT/2-GFX_HEIGHT/8-1));
265 /* invert a line */
266 grey_hline((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2,
267 (LCD_WIDTH+GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2-1));
269 /* show bitmaps (1 bit and 8 bit) */
270 /* opaque */
271 grey_set_drawinfo(DRMODE_SOLID, 255, 100);
272 grey_mono_bitmap(rockbox,
273 MAX((LCD_WIDTH/2-47), ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2)),
274 (5*GFX_HEIGHT/16-4), 43, 7);
275 /* transparent */
276 grey_set_drawinfo(DRMODE_FG, 0, 100);
277 grey_mono_bitmap(showing, (LCD_WIDTH/2+4) , (5*GFX_HEIGHT/16-4), 39, 7);
278 /* greyscale */
279 grey_gray_bitmap(grayscale_grey, ((LCD_WIDTH-55)/2), (11*GFX_HEIGHT/16-4),
280 55, 7);
282 grey_update();
284 time = *rb->current_tick - time; /* end time measurement */
286 rb->snprintf(pbuf, sizeof(pbuf), "Shades: 129, %d.%02ds",
287 time / 100, time % 100);
288 rb->lcd_puts(0, 0, pbuf);
289 grey_deferred_lcd_update(); /* schedule an lcd_update() */
290 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
291 rb->cpu_boost(false);
292 #endif
294 /* drawing is now finished, play around with scrolling
295 * until you press OFF or connect USB
297 grey_set_background(255);
298 while (true)
300 scroll_amount = 1;
302 button = rb->button_get(true);
304 if (rb->default_event_handler_ex(button, cleanup, NULL)
305 == SYS_USB_CONNECTED)
306 return PLUGIN_USB_CONNECTED;
308 if (button & GREYSCALE_SHIFT)
310 if (!black_border)
312 grey_set_background(0);
313 black_border = true;
316 else
318 if (black_border)
320 grey_set_background(255);
321 black_border = false;
325 if (button & BUTTON_REPEAT)
326 scroll_amount = 4;
328 switch (button & ~(GREYSCALE_SHIFT | BUTTON_REPEAT))
330 case GREYSCALE_LEFT:
332 grey_scroll_left(scroll_amount); /* scroll left */
333 grey_update();
334 break;
336 case GREYSCALE_RIGHT:
338 grey_scroll_right(scroll_amount); /* scroll right */
339 grey_update();
340 break;
342 case GREYSCALE_UP:
344 grey_scroll_up(scroll_amount); /* scroll up */
345 grey_update();
346 break;
348 case GREYSCALE_DOWN:
350 grey_scroll_down(scroll_amount); /* scroll down */
351 grey_update();
352 break;
353 #ifdef GREYSCALE_RC_OFF
354 case GREYSCALE_RC_OFF:
355 #endif
356 case GREYSCALE_OFF:
358 cleanup(NULL);
359 return PLUGIN_OK;
364 /*************************** Plugin entry point ****************************/
366 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
368 rb = api; /* copy to global api pointer */
369 (void)parameter;
371 return main();
374 #endif /* #ifdef HAVE_LCD_BITMAP */