fixing red:
[Rockbox.git] / apps / plugins / greyscale.c
blob42ba08f22ef58e1f4198785b137eb5e40f8bea1e
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 * 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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "plugin.h"
23 #include "helper.h"
25 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
26 #include "grey.h"
28 PLUGIN_HEADER
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
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
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
55 #define GREYSCALE_RC_OFF BUTTON_RC_STOP
57 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
58 #define GREYSCALE_SHIFT BUTTON_PLAY /* won't work, but define it anyway */
59 #define GREYSCALE_UP BUTTON_UP
60 #define GREYSCALE_DOWN BUTTON_DOWN
61 #define GREYSCALE_LEFT BUTTON_LEFT
62 #define GREYSCALE_RIGHT BUTTON_RIGHT
63 #define GREYSCALE_OFF BUTTON_POWER
65 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
66 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
67 #define GREYSCALE_SHIFT BUTTON_SELECT
68 #define GREYSCALE_UP BUTTON_SCROLL_BACK
69 #define GREYSCALE_DOWN BUTTON_SCROLL_FWD
70 #define GREYSCALE_LEFT BUTTON_LEFT
71 #define GREYSCALE_RIGHT BUTTON_RIGHT
72 #define GREYSCALE_OFF BUTTON_MENU
74 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
75 #define GREYSCALE_SHIFT BUTTON_PLAY
76 #define GREYSCALE_UP BUTTON_UP
77 #define GREYSCALE_DOWN BUTTON_DOWN
78 #define GREYSCALE_LEFT BUTTON_LEFT
79 #define GREYSCALE_RIGHT BUTTON_RIGHT
80 #define GREYSCALE_OFF BUTTON_EQ
82 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
83 #define GREYSCALE_SHIFT BUTTON_RC_PLAY /* somewhat dangerous... */
84 #define GREYSCALE_UP BUTTON_RC_VOL_UP
85 #define GREYSCALE_DOWN BUTTON_RC_VOL_DOWN
86 #define GREYSCALE_LEFT BUTTON_RC_REW
87 #define GREYSCALE_RIGHT BUTTON_RC_FF
88 #define GREYSCALE_OFF BUTTON_RC_REC
90 #define GREYSCALE_RC_OFF BUTTON_REC
92 #endif
94 #define GFX_HEIGHT (LCD_HEIGHT-8)
95 #if LCD_WIDTH < 160
96 #define GFX_GREYTONE_WIDTH 86
97 #define GFX_GREYTONE_STEP 3
98 #else
99 #define GFX_GREYTONE_WIDTH 128
100 #define GFX_GREYTONE_STEP 2
101 #endif
102 /******************************* Globals ***********************************/
104 GREY_INFO_STRUCT
105 static struct plugin_api* rb; /* global api struct pointer */
106 static char pbuf[32]; /* global printf buffer */
107 static unsigned char *gbuf;
108 static size_t gbuf_size = 0;
110 /**************************** main function ********************************/
112 void cleanup(void *parameter)
114 (void)parameter;
116 grey_release(); /* switch off overlay and deinitialize */
117 /* Turn on backlight timeout (revert to settings) */
118 backlight_use_settings(rb); /* backlight control in lib/helper.c */
121 /* this is only a demo of what the framework can do */
122 int main(void)
124 int time;
125 int x, y, i;
126 int button, scroll_amount;
127 bool black_border = false;
129 static const unsigned char rockbox[] = {
130 /* ...........................................
131 * .####...###...###..#...#.####...###..#...#.
132 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
133 * .####..#...#.#.....###...####..#...#...#...
134 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
135 * .#...#..###...###..#...#.####...###..#...#.
136 * ...........................................
137 * 43 x 7 pixel, 1 bpp
139 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
140 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
141 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
142 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
143 0x14, 0x22, 0x00
146 static const unsigned char showing[] = {
147 /* .......................................
148 * ..####.#...#..###..#...#.#.#...#..####.
149 * .#.....#...#.#...#.#...#.#.##..#.#.....
150 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
151 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
152 * .####..#...#..###...#.#..#.#...#..####.
153 * .......................................
154 * 39 x 7 pixel, 1 bpp
156 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
157 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
158 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
159 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
162 static const unsigned char grayscale_grey[] = {
163 /* .......................................................
164 * ..####.####...###..#...#..####..###...###..#.....#####.
165 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
166 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
167 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
168 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
169 * .......................................................
170 * 55 x 7 pixel, 8 bpp
172 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
173 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
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,
176 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
177 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
178 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
179 120, 36, 36, 36, 36, 36,120,
180 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
181 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
182 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
183 130, 36,130,130,130,130,130,
184 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
185 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
186 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
187 140, 36, 36, 36, 36,140,140,
188 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
189 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
190 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
191 130, 36,130,130,130,130,130,
192 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
193 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
194 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
195 120, 36, 36, 36, 36, 36,120,
196 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
197 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
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
202 /* Turn off backlight timeout */
203 backlight_force_on(rb); /* backlight control in lib/helper.c */
205 rb->lcd_setfont(FONT_SYSFIXED); /* select default font */
207 /* get the remainder of the plugin buffer */
208 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
210 /* initialize the greyscale buffer:
211 Archos: 112 pixels wide, 7 rows (56 pixels) high.
212 H1x0: 160 pixels wide, 30 rows (120 pixels) high. */
213 if (!grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED,
214 LCD_WIDTH, GFX_HEIGHT, NULL))
216 rb->splash(HZ, "Not enough memory.");
217 return PLUGIN_ERROR;
220 /* place greyscale overlay 1 row down */
221 grey_set_position(0, 8);
223 rb->lcd_puts(0, 0, "Shades: 129");
224 rb->lcd_update();
226 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
227 rb->cpu_boost(true);
228 #endif
229 grey_show(true); /* switch on greyscale overlay */
231 time = *rb->current_tick; /* start time measurement */
233 grey_set_background(150);
234 grey_clear_display(); /* fill everything with grey 150 */
236 /* draw a dark grey line star background */
237 grey_set_foreground(80);
238 for (y = 0; y < GFX_HEIGHT; y += 8) /* horizontal part */
240 grey_drawline(0, y, (LCD_WIDTH-1), (GFX_HEIGHT-1) - y); /*grey lines */
242 for (x = 10; x <= LCD_WIDTH; x += 10) /* vertical part */
244 grey_drawline(x, 0, (LCD_WIDTH-1) - x, (GFX_HEIGHT-1)); /*grey lines */
247 grey_set_foreground(0);
248 grey_drawrect(0, 0, LCD_WIDTH, GFX_HEIGHT); /* black border */
250 /* draw grey tones */
251 for (i = 0; i < GFX_GREYTONE_WIDTH; i++)
253 x = ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2) + i;
254 grey_set_foreground(GFX_GREYTONE_STEP * i);
255 /* vertical lines */
256 grey_vline(x, (GFX_HEIGHT/8), (GFX_HEIGHT-GFX_HEIGHT/8-1));
259 grey_set_drawmode(DRMODE_COMPLEMENT);
260 /* invert rectangle (lower half) */
261 grey_fillrect((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2+1),
262 GFX_GREYTONE_WIDTH, (GFX_HEIGHT/2-GFX_HEIGHT/8-1));
263 /* invert a line */
264 grey_hline((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2,
265 (LCD_WIDTH+GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2-1));
267 /* show bitmaps (1 bit and 8 bit) */
268 /* opaque */
269 grey_set_drawinfo(DRMODE_SOLID, 255, 100);
270 grey_mono_bitmap(rockbox,
271 MAX((LCD_WIDTH/2-47), ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2)),
272 (5*GFX_HEIGHT/16-4), 43, 7);
273 /* transparent */
274 grey_set_drawinfo(DRMODE_FG, 0, 100);
275 grey_mono_bitmap(showing, (LCD_WIDTH/2+4) , (5*GFX_HEIGHT/16-4), 39, 7);
276 /* greyscale */
277 grey_gray_bitmap(grayscale_grey, ((LCD_WIDTH-55)/2), (11*GFX_HEIGHT/16-4),
278 55, 7);
280 grey_update();
282 time = *rb->current_tick - time; /* end time measurement */
284 rb->snprintf(pbuf, sizeof(pbuf), "Shades: 129, %d.%02ds",
285 time / 100, time % 100);
286 rb->lcd_puts(0, 0, pbuf);
287 grey_deferred_lcd_update(); /* schedule an lcd_update() */
288 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
289 rb->cpu_boost(false);
290 #endif
292 /* drawing is now finished, play around with scrolling
293 * until you press OFF or connect USB
295 grey_set_background(255);
296 while (true)
298 scroll_amount = 1;
300 button = rb->button_get(true);
302 if (rb->default_event_handler_ex(button, cleanup, NULL)
303 == SYS_USB_CONNECTED)
304 return PLUGIN_USB_CONNECTED;
306 if (button & GREYSCALE_SHIFT)
308 if (!black_border)
310 grey_set_background(0);
311 black_border = true;
314 else
316 if (black_border)
318 grey_set_background(255);
319 black_border = false;
323 if (button & BUTTON_REPEAT)
324 scroll_amount = 4;
326 switch (button & ~(GREYSCALE_SHIFT | BUTTON_REPEAT))
328 case GREYSCALE_LEFT:
330 grey_scroll_left(scroll_amount); /* scroll left */
331 grey_update();
332 break;
334 case GREYSCALE_RIGHT:
336 grey_scroll_right(scroll_amount); /* scroll right */
337 grey_update();
338 break;
340 case GREYSCALE_UP:
342 grey_scroll_up(scroll_amount); /* scroll up */
343 grey_update();
344 break;
346 case GREYSCALE_DOWN:
348 grey_scroll_down(scroll_amount); /* scroll down */
349 grey_update();
350 break;
351 #ifdef GREYSCALE_RC_OFF
352 case GREYSCALE_RC_OFF:
353 #endif
354 case GREYSCALE_OFF:
356 cleanup(NULL);
357 return PLUGIN_OK;
362 /*************************** Plugin entry point ****************************/
364 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
366 rb = api; /* copy to global api pointer */
367 (void)parameter;
369 return main();
372 #endif /* #ifdef HAVE_LCD_BITMAP */