Restore translated strings removed by accident in the previous revision.
[kugel-rb.git] / apps / plugins / greyscale.c
blob00699715f71e2f93c2a9af2346e0d24bebf0b122
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"
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 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
95 #define GREYSCALE_SHIFT BUTTON_SELECT
96 #define GREYSCALE_UP BUTTON_UP
97 #define GREYSCALE_DOWN BUTTON_DOWN
98 #define GREYSCALE_LEFT BUTTON_LEFT
99 #define GREYSCALE_RIGHT BUTTON_RIGHT
100 #define GREYSCALE_OFF BUTTON_POWER
102 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
103 #define GREYSCALE_SHIFT BUTTON_FFWD
104 #define GREYSCALE_UP BUTTON_UP
105 #define GREYSCALE_DOWN BUTTON_DOWN
106 #define GREYSCALE_LEFT BUTTON_LEFT
107 #define GREYSCALE_RIGHT BUTTON_RIGHT
108 #define GREYSCALE_OFF BUTTON_PLAY
110 #endif
112 #define GFX_HEIGHT (LCD_HEIGHT-8)
113 #if LCD_WIDTH < 160
114 #define GFX_GREYTONE_WIDTH 86
115 #define GFX_GREYTONE_STEP 3
116 #else
117 #define GFX_GREYTONE_WIDTH 128
118 #define GFX_GREYTONE_STEP 2
119 #endif
120 /******************************* Globals ***********************************/
122 GREY_INFO_STRUCT
123 static unsigned char *gbuf;
124 static size_t gbuf_size = 0;
126 /**************************** main function ********************************/
128 void cleanup(void *parameter)
130 (void)parameter;
132 grey_release(); /* switch off overlay and deinitialize */
133 /* Turn on backlight timeout (revert to settings) */
134 backlight_use_settings(); /* backlight control in lib/helper.c */
137 /* this is only a demo of what the framework can do */
138 int main(void)
140 int time;
141 int x, y, i;
142 int button, scroll_amount;
143 bool black_border = false;
145 static const unsigned char rockbox[] = {
146 /* ...........................................
147 * .####...###...###..#...#.####...###..#...#.
148 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
149 * .####..#...#.#.....###...####..#...#...#...
150 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
151 * .#...#..###...###..#...#.####...###..#...#.
152 * ...........................................
153 * 43 x 7 pixel, 1 bpp
155 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
156 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
157 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
158 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
159 0x14, 0x22, 0x00
162 static const unsigned char showing[] = {
163 /* .......................................
164 * ..####.#...#..###..#...#.#.#...#..####.
165 * .#.....#...#.#...#.#...#.#.##..#.#.....
166 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
167 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
168 * .####..#...#..###...#.#..#.#...#..####.
169 * .......................................
170 * 39 x 7 pixel, 1 bpp
172 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
173 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
174 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
175 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
178 static const unsigned char grayscale_grey[] = {
179 /* .......................................................
180 * ..####.####...###..#...#..####..###...###..#.....#####.
181 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
182 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
183 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
184 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
185 * .......................................................
186 * 55 x 7 pixel, 8 bpp
188 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
189 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
190 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
191 110,110,110,110,110,110,110,
192 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
193 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
194 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
195 120, 36, 36, 36, 36, 36,120,
196 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
197 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
198 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
199 130, 36,130,130,130,130,130,
200 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
201 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
202 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
203 140, 36, 36, 36, 36,140,140,
204 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
205 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
206 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
207 130, 36,130,130,130,130,130,
208 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
209 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
210 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
211 120, 36, 36, 36, 36, 36,120,
212 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
213 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
214 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
215 110,110,110,110,110,110,110
218 /* Turn off backlight timeout */
219 backlight_force_on(); /* backlight control in lib/helper.c */
221 rb->lcd_setfont(FONT_SYSFIXED); /* select default font */
223 /* get the remainder of the plugin buffer */
224 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
226 /* initialize the greyscale buffer:
227 Archos: 112 pixels wide, 7 rows (56 pixels) high.
228 H1x0: 160 pixels wide, 30 rows (120 pixels) high. */
229 if (!grey_init(gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP,
230 LCD_WIDTH, GFX_HEIGHT, NULL))
232 rb->splash(HZ, "Not enough memory.");
233 return PLUGIN_ERROR;
236 /* place greyscale overlay 1 row down */
237 grey_set_position(0, 8);
239 rb->lcd_puts(0, 0, "Shades: 129");
240 rb->lcd_update();
242 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
243 rb->cpu_boost(true);
244 #endif
245 grey_show(true); /* switch on greyscale overlay */
247 time = *rb->current_tick; /* start time measurement */
249 grey_set_background(150);
250 grey_clear_display(); /* fill everything with grey 150 */
252 /* draw a dark grey line star background */
253 grey_set_foreground(80);
254 for (y = 0; y < GFX_HEIGHT; y += 8) /* horizontal part */
256 grey_drawline(0, y, (LCD_WIDTH-1), (GFX_HEIGHT-1) - y); /*grey lines */
258 for (x = 10; x <= LCD_WIDTH; x += 10) /* vertical part */
260 grey_drawline(x, 0, (LCD_WIDTH-1) - x, (GFX_HEIGHT-1)); /*grey lines */
263 grey_set_foreground(0);
264 grey_drawrect(0, 0, LCD_WIDTH, GFX_HEIGHT); /* black border */
266 /* draw grey tones */
267 for (i = 0; i < GFX_GREYTONE_WIDTH; i++)
269 x = ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2) + i;
270 grey_set_foreground(GFX_GREYTONE_STEP * i);
271 /* vertical lines */
272 grey_vline(x, (GFX_HEIGHT/8), (GFX_HEIGHT-GFX_HEIGHT/8-1));
275 grey_set_drawmode(DRMODE_COMPLEMENT);
276 /* invert rectangle (lower half) */
277 grey_fillrect((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2+1),
278 GFX_GREYTONE_WIDTH, (GFX_HEIGHT/2-GFX_HEIGHT/8-1));
279 /* invert a line */
280 grey_hline((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2,
281 (LCD_WIDTH+GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2-1));
283 /* show bitmaps (1 bit and 8 bit) */
284 /* opaque */
285 grey_set_drawinfo(DRMODE_SOLID, 255, 100);
286 grey_mono_bitmap(rockbox,
287 MAX((LCD_WIDTH/2-47), ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2)),
288 (5*GFX_HEIGHT/16-4), 43, 7);
289 /* transparent */
290 grey_set_drawinfo(DRMODE_FG, 0, 100);
291 grey_mono_bitmap(showing, (LCD_WIDTH/2+4) , (5*GFX_HEIGHT/16-4), 39, 7);
292 /* greyscale */
293 grey_gray_bitmap(grayscale_grey, ((LCD_WIDTH-55)/2), (11*GFX_HEIGHT/16-4),
294 55, 7);
296 grey_update();
298 time = *rb->current_tick - time; /* end time measurement */
300 rb->lcd_putsf(0, 0, "Shades: 129, %d.%02ds", time / 100, time % 100);
301 grey_deferred_lcd_update(); /* schedule an lcd_update() */
302 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
303 rb->cpu_boost(false);
304 #endif
306 /* drawing is now finished, play around with scrolling
307 * until you press OFF or connect USB
309 grey_set_background(255);
310 while (true)
312 scroll_amount = 1;
314 button = rb->button_get(true);
316 exit_on_usb(button);
318 if (button & GREYSCALE_SHIFT)
320 if (!black_border)
322 grey_set_background(0);
323 black_border = true;
326 else
328 if (black_border)
330 grey_set_background(255);
331 black_border = false;
335 if (button & BUTTON_REPEAT)
336 scroll_amount = 4;
338 switch (button & ~(GREYSCALE_SHIFT | BUTTON_REPEAT))
340 case GREYSCALE_LEFT:
342 grey_scroll_left(scroll_amount); /* scroll left */
343 grey_update();
344 break;
346 case GREYSCALE_RIGHT:
348 grey_scroll_right(scroll_amount); /* scroll right */
349 grey_update();
350 break;
352 case GREYSCALE_UP:
354 grey_scroll_up(scroll_amount); /* scroll up */
355 grey_update();
356 break;
358 case GREYSCALE_DOWN:
360 grey_scroll_down(scroll_amount); /* scroll down */
361 grey_update();
362 break;
363 #ifdef GREYSCALE_RC_OFF
364 case GREYSCALE_RC_OFF:
365 #endif
366 case GREYSCALE_OFF:
367 return PLUGIN_OK;
372 /*************************** Plugin entry point ****************************/
374 enum plugin_status plugin_start(const void* parameter)
376 (void)parameter;
378 atexit(cleanup);
379 return main();
382 #endif /* #ifdef HAVE_LCD_BITMAP */