diff options
author | Jens Arnold <amiconn@rockbox.org> | 2004-05-19 08:21:30 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2004-05-19 08:21:30 +0000 |
commit | e4c1667979b9c320b1e24acb6c5db84711b3862e (patch) | |
tree | 11f90400047c65f44254462ea36e0b32510ba2f8 | |
parent | a05c41377469f52fc8c76494c1e9d8d5a2094f9a (diff) | |
download | rockbox-e4c1667979b9c320b1e24acb6c5db84711b3862e.tar.gz rockbox-e4c1667979b9c320b1e24acb6c5db84711b3862e.zip |
Grayscale demo plugin, now using the grayscale library
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4642 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/grayscale.c | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/apps/plugins/grayscale.c b/apps/plugins/grayscale.c new file mode 100644 index 0000000000..0231541761 --- /dev/null +++ b/apps/plugins/grayscale.c | |||
@@ -0,0 +1,259 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Grayscale demo plugin | ||
11 | * | ||
12 | * Copyright (C) 2004 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 | #ifndef SIMULATOR /* not for simulator by now */ | ||
23 | #include "plugin.h" | ||
24 | |||
25 | #ifdef HAVE_LCD_BITMAP /* and also not for the Player */ | ||
26 | #include "gray.h" | ||
27 | |||
28 | /******************************* Globals ***********************************/ | ||
29 | |||
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; | ||
34 | |||
35 | /**************************** main function ********************************/ | ||
36 | |||
37 | /* this is only a demo of what the framework can do */ | ||
38 | int main(void) | ||
39 | { | ||
40 | int shades, time; | ||
41 | int x, y, i; | ||
42 | int button, scroll_amount; | ||
43 | bool black_border; | ||
44 | |||
45 | static unsigned char rockbox[] = { | ||
46 | /* ........................................... | ||
47 | * .####...###...###..#...#.####...###..#...#. | ||
48 | * .#...#.#...#.#...#.#..#..#...#.#...#..#.#.. | ||
49 | * .####..#...#.#.....###...####..#...#...#... | ||
50 | * .#..#..#...#.#...#.#..#..#...#.#...#..#.#.. | ||
51 | * .#...#..###...###..#...#.####...###..#...#. | ||
52 | * ........................................... | ||
53 | * 43 x 7 pixel, 1 bpp | ||
54 | */ | ||
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 | ||
60 | }; | ||
61 | |||
62 | static unsigned char showing[] = { | ||
63 | /* ....................................... | ||
64 | * ..####.#...#..###..#...#.#.#...#..####. | ||
65 | * .#.....#...#.#...#.#...#.#.##..#.#..... | ||
66 | * ..###..#####.#...#.#.#.#.#.#.#.#.#..##. | ||
67 | * .....#.#...#.#...#.#.#.#.#.#..##.#...#. | ||
68 | * .####..#...#..###...#.#..#.#...#..####. | ||
69 | * ....................................... | ||
70 | * 39 x 7 pixel, 1 bpp | ||
71 | */ | ||
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 | ||
76 | }; | ||
77 | |||
78 | static unsigned char grayscale_gray[] = { | ||
79 | /* ....................................................... | ||
80 | * ..####.####...###..#...#..####..###...###..#.....#####. | ||
81 | * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#..... | ||
82 | * .#..##.####..#####..#.#...###..#.....#####.#.....####.. | ||
83 | * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#..... | ||
84 | * ..####.#...#.#...#...#...####...###..#...#.#####.#####. | ||
85 | * ....................................................... | ||
86 | * 55 x 7 pixel, 8 bpp | ||
87 | */ | ||
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 | ||
116 | }; | ||
117 | |||
118 | if (rb->global_settings->backlight_timeout > 0) | ||
119 | rb->backlight_set_timeout(1); /* keep the light on */ | ||
120 | |||
121 | rb->lcd_setfont(FONT_SYSFIXED); /* select default font */ | ||
122 | |||
123 | /* get the remainder of the plugin buffer */ | ||
124 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | ||
125 | |||
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) + 1; | ||
130 | |||
131 | /* place grayscale overlay 1 row down */ | ||
132 | gray_position_display(0, 1); | ||
133 | |||
134 | rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d", shades); | ||
135 | rb->lcd_puts(0, 0, pbuf); | ||
136 | rb->lcd_update(); | ||
137 | |||
138 | gray_show_display(true); /* switch on grayscale overlay */ | ||
139 | |||
140 | time = *rb->current_tick; /* start time measurement */ | ||
141 | |||
142 | gray_fillrect(0, 0, 111, 55, 150); /* fill everything with gray 150 */ | ||
143 | |||
144 | /* draw a dark gray line star background */ | ||
145 | for (y = 0; y < 56; y += 8) /* horizontal part */ | ||
146 | { | ||
147 | gray_drawline(0, y, 111, 55 - y, 80); /* gray lines */ | ||
148 | } | ||
149 | for (x = 10; x < 112; x += 10) /* vertical part */ | ||
150 | { | ||
151 | gray_drawline(x, 0, 111 - x, 55, 80); /* gray lines */ | ||
152 | } | ||
153 | |||
154 | gray_drawrect(0, 0, 111, 55, 0); /* black border */ | ||
155 | |||
156 | /* draw gray tones */ | ||
157 | for (i = 0; i < 86; i++) | ||
158 | { | ||
159 | x = 13 + i; | ||
160 | gray_fillrect(x, 6, x, 49, 3 * i); /* gray rectangles */ | ||
161 | } | ||
162 | |||
163 | gray_invertrect(13, 29, 98, 49); /* invert rectangle (lower half) */ | ||
164 | gray_invertline(13, 27, 98, 27); /* invert a line */ | ||
165 | |||
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); | ||
170 | |||
171 | time = *rb->current_tick - time; /* end time measurement */ | ||
172 | |||
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() */ | ||
177 | |||
178 | /* drawing is now finished, play around with scrolling | ||
179 | * until you press OFF or connect USB | ||
180 | */ | ||
181 | while (true) | ||
182 | { | ||
183 | scroll_amount = 1; | ||
184 | black_border = false; | ||
185 | |||
186 | button = rb->button_get(true); | ||
187 | |||
188 | if (button == SYS_USB_CONNECTED) | ||
189 | { | ||
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; | ||
194 | } | ||
195 | |||
196 | if (button & BUTTON_ON) | ||
197 | black_border = true; | ||
198 | |||
199 | if (button & BUTTON_REPEAT) | ||
200 | scroll_amount = 4; | ||
201 | |||
202 | switch(button & ~(BUTTON_ON | BUTTON_REPEAT)) | ||
203 | { | ||
204 | case BUTTON_LEFT: | ||
205 | |||
206 | gray_scroll_left(scroll_amount, black_border); /* scroll left */ | ||
207 | break; | ||
208 | |||
209 | case BUTTON_RIGHT: | ||
210 | |||
211 | gray_scroll_right(scroll_amount, black_border); /* scroll right */ | ||
212 | break; | ||
213 | |||
214 | case BUTTON_UP: | ||
215 | |||
216 | gray_scroll_up(scroll_amount, black_border); /* scroll up */ | ||
217 | break; | ||
218 | |||
219 | case BUTTON_DOWN: | ||
220 | |||
221 | gray_scroll_down(scroll_amount, black_border); /* scroll down */ | ||
222 | break; | ||
223 | |||
224 | case BUTTON_OFF: | ||
225 | |||
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; | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | |||
234 | /*************************** Plugin entry point ****************************/ | ||
235 | |||
236 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
237 | { | ||
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); | ||
243 | |||
244 | rb = api; // copy to global api pointer | ||
245 | (void)parameter; | ||
246 | |||
247 | /* This plugin uses the grayscale framework, so initialize */ | ||
248 | gray_init(api); | ||
249 | |||
250 | ret = main(); | ||
251 | |||
252 | if (ret == PLUGIN_USB_CONNECTED) | ||
253 | rb->usb_screen(); | ||
254 | return ret; | ||
255 | } | ||
256 | |||
257 | #endif // #ifdef HAVE_LCD_BITMAP | ||
258 | #endif // #ifndef SIMULATOR | ||
259 | |||