* removed some more unused stuff in the simulator makefile
[kugel-rb.git] / apps / plugins / grayscale.c
blobf2374f7a4b3d9af51c57b9e524df3fe8415ecfbc
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Grayscale demo plugin
12 * Copyright (C) 2004 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 #ifndef SIMULATOR /* not for simulator by now */
23 #include "plugin.h"
25 #ifdef HAVE_LCD_BITMAP /* and also not for the Player */
26 #include "gray.h"
28 /******************************* Globals ***********************************/
30 static struct plugin_api* rb; /* global api struct pointer */
31 static char pbuf[32]; /* global printf buffer */
32 static unsigned char *gbuf;
33 static unsigned int gbuf_size = 0;
35 /**************************** main function ********************************/
37 /* this is only a demo of what the framework can do */
38 int main(void)
40 int shades, time;
41 int x, y, i;
42 int button, scroll_amount;
43 bool black_border;
45 static unsigned char rockbox[] = {
46 /* ...........................................
47 * .####...###...###..#...#.####...###..#...#.
48 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
49 * .####..#...#.#.....###...####..#...#...#...
50 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
51 * .#...#..###...###..#...#.####...###..#...#.
52 * ...........................................
53 * 43 x 7 pixel, 1 bpp
55 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
56 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
57 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
58 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
59 0x14, 0x22, 0x00
62 static unsigned char showing[] = {
63 /* .......................................
64 * ..####.#...#..###..#...#.#.#...#..####.
65 * .#.....#...#.#...#.#...#.#.##..#.#.....
66 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
67 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
68 * .####..#...#..###...#.#..#.#...#..####.
69 * .......................................
70 * 39 x 7 pixel, 1 bpp
72 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
73 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
74 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
75 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
78 static unsigned char grayscale_gray[] = {
79 /* .......................................................
80 * ..####.####...###..#...#..####..###...###..#.....#####.
81 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
82 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
83 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
84 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
85 * .......................................................
86 * 55 x 7 pixel, 8 bpp
88 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
89 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
90 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
91 110,110,110,110,110,110,110,
92 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
93 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
94 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
95 120, 36, 36, 36, 36, 36,120,
96 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
97 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
98 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
99 130, 36,130,130,130,130,130,
100 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
101 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
102 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
103 140, 36, 36, 36, 36,140,140,
104 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
105 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
106 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
107 130, 36,130,130,130,130,130,
108 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
109 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
110 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
111 120, 36, 36, 36, 36, 36,120,
112 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
113 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
114 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
115 110,110,110,110,110,110,110
118 if (rb->global_settings->backlight_timeout > 0)
119 rb->backlight_set_timeout(1); /* keep the light on */
121 rb->lcd_setfont(FONT_SYSFIXED); /* select default font */
123 /* get the remainder of the plugin buffer */
124 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
126 /* initialize the grayscale buffer:
127 * 112 pixels wide, 7 rows (56 pixels) high, (try to) reserve
128 * 32 bitplanes for 33 shades of gray. (uses 25268 bytes)*/
129 shades = gray_init_buffer(gbuf, gbuf_size, 112, 7, 32, NULL) + 1;
131 /* place grayscale overlay 1 row down */
132 gray_position_display(0, 1);
134 rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d", shades);
135 rb->lcd_puts(0, 0, pbuf);
136 rb->lcd_update();
138 gray_show_display(true); /* switch on grayscale overlay */
140 time = *rb->current_tick; /* start time measurement */
142 gray_fillrect(0, 0, 111, 55, 150); /* fill everything with gray 150 */
144 /* draw a dark gray line star background */
145 for (y = 0; y < 56; y += 8) /* horizontal part */
147 gray_drawline(0, y, 111, 55 - y, 80); /* gray lines */
149 for (x = 10; x < 112; x += 10) /* vertical part */
151 gray_drawline(x, 0, 111 - x, 55, 80); /* gray lines */
154 gray_drawrect(0, 0, 111, 55, 0); /* black border */
156 /* draw gray tones */
157 for (i = 0; i < 86; i++)
159 x = 13 + i;
160 gray_fillrect(x, 6, x, 49, 3 * i); /* gray rectangles */
163 gray_invertrect(13, 29, 98, 49); /* invert rectangle (lower half) */
164 gray_invertline(13, 27, 98, 27); /* invert a line */
166 /* show bitmaps (1 bit and 8 bit) */
167 gray_drawbitmap(rockbox, 14, 13, 43, 7, 43, true, 255, 100); /* opaque */
168 gray_drawbitmap(showing, 58, 13, 39, 7, 39, false, 0, 0); /* transparent */
169 gray_drawgraymap(grayscale_gray, 28, 35, 55, 7, 55);
171 time = *rb->current_tick - time; /* end time measurement */
173 rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d, %d.%02ds", shades,
174 time / 100, time % 100);
175 rb->lcd_puts(0, 0, pbuf);
176 gray_deferred_update(); /* schedule an lcd_update() */
178 /* drawing is now finished, play around with scrolling
179 * until you press OFF or connect USB
181 while (true)
183 scroll_amount = 1;
184 black_border = false;
186 button = rb->button_get(true);
188 if (button == SYS_USB_CONNECTED)
190 gray_release_buffer(); /* switch off overlay and deinitialize */
191 /* restore normal backlight setting */
192 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
193 return PLUGIN_USB_CONNECTED;
196 if (button & BUTTON_ON)
197 black_border = true;
199 if (button & BUTTON_REPEAT)
200 scroll_amount = 4;
202 switch(button & ~(BUTTON_ON | BUTTON_REPEAT))
204 case BUTTON_LEFT:
206 gray_scroll_left(scroll_amount, black_border); /* scroll left */
207 break;
209 case BUTTON_RIGHT:
211 gray_scroll_right(scroll_amount, black_border); /* scroll right */
212 break;
214 case BUTTON_UP:
216 gray_scroll_up(scroll_amount, black_border); /* scroll up */
217 break;
219 case BUTTON_DOWN:
221 gray_scroll_down(scroll_amount, black_border); /* scroll down */
222 break;
224 case BUTTON_OFF:
226 gray_release_buffer(); /* switch off overlay and deinitialize */
227 /* restore normal backlight setting */
228 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
229 return PLUGIN_OK;
234 /*************************** Plugin entry point ****************************/
236 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
238 int ret;
239 /* this macro should be called as the first thing you do in the plugin.
240 it test that the api version and model the plugin was compiled for
241 matches the machine it is running on */
242 TEST_PLUGIN_API(api);
244 rb = api; // copy to global api pointer
245 (void)parameter;
247 /* This plugin uses the grayscale framework, so initialize */
248 gray_init(api);
250 ret = main();
252 if (ret == PLUGIN_USB_CONNECTED)
253 rb->usb_screen();
254 return ret;
257 #endif // #ifdef HAVE_LCD_BITMAP
258 #endif // #ifndef SIMULATOR