diff options
Diffstat (limited to 'apps/plugins/grayscale.c')
-rw-r--r-- | apps/plugins/grayscale.c | 86 |
1 files changed, 51 insertions, 35 deletions
diff --git a/apps/plugins/grayscale.c b/apps/plugins/grayscale.c index 196545c0e7..e543f15427 100644 --- a/apps/plugins/grayscale.c +++ b/apps/plugins/grayscale.c | |||
@@ -44,7 +44,7 @@ void cleanup(void *parameter) | |||
44 | { | 44 | { |
45 | (void)parameter; | 45 | (void)parameter; |
46 | 46 | ||
47 | gray_release_buffer(); /* switch off overlay and deinitialize */ | 47 | gray_release(); /* switch off overlay and deinitialize */ |
48 | /* restore normal backlight setting */ | 48 | /* restore normal backlight setting */ |
49 | rb->backlight_set_timeout(rb->global_settings->backlight_timeout); | 49 | rb->backlight_set_timeout(rb->global_settings->backlight_timeout); |
50 | } | 50 | } |
@@ -55,7 +55,7 @@ int main(void) | |||
55 | int shades, time; | 55 | int shades, time; |
56 | int x, y, i; | 56 | int x, y, i; |
57 | int button, scroll_amount; | 57 | int button, scroll_amount; |
58 | bool black_border; | 58 | bool black_border = false; |
59 | 59 | ||
60 | static const unsigned char rockbox[] = { | 60 | static const unsigned char rockbox[] = { |
61 | /* ........................................... | 61 | /* ........................................... |
@@ -138,73 +138,74 @@ int main(void) | |||
138 | /* get the remainder of the plugin buffer */ | 138 | /* get the remainder of the plugin buffer */ |
139 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 139 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
140 | 140 | ||
141 | /* initialize the grayscale buffer: | 141 | /* initialize the greyscale buffer: |
142 | * 112 pixels wide, 7 rows (56 pixels) high, (try to) reserve | 142 | * 112 pixels wide, 7 rows (56 pixels) high, (try to) reserve |
143 | * 32 bitplanes for 33 shades of gray. (uses 25268 bytes)*/ | 143 | * 32 bitplanes for 33 shades of grey. */ |
144 | shades = gray_init_buffer(gbuf, gbuf_size, 112, 7, 32, NULL) + 1; | 144 | shades = gray_init(rb, gbuf, gbuf_size, true, 112, 7, 32, NULL) + 1; |
145 | 145 | ||
146 | /* place grayscale overlay 1 row down */ | 146 | /* place greyscale overlay 1 row down */ |
147 | gray_position_display(0, 1); | 147 | gray_set_position(0, 1); |
148 | 148 | ||
149 | rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d", shades); | 149 | rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d", shades); |
150 | rb->lcd_puts(0, 0, pbuf); | 150 | rb->lcd_puts(0, 0, pbuf); |
151 | rb->lcd_update(); | 151 | rb->lcd_update(); |
152 | 152 | ||
153 | gray_show_display(true); /* switch on grayscale overlay */ | 153 | gray_show(true); /* switch on greyscale overlay */ |
154 | 154 | ||
155 | time = *rb->current_tick; /* start time measurement */ | 155 | time = *rb->current_tick; /* start time measurement */ |
156 | 156 | ||
157 | gray_set_foreground(150); | 157 | gray_set_background(150); |
158 | gray_fillrect(0, 0, 112, 56); /* fill everything with gray 150 */ | 158 | gray_clear_display(); /* fill everything with grey 150 */ |
159 | 159 | ||
160 | /* draw a dark gray line star background */ | 160 | /* draw a dark grey line star background */ |
161 | gray_set_foreground(80); | 161 | gray_set_foreground(80); |
162 | for (y = 0; y < 56; y += 8) /* horizontal part */ | 162 | for (y = 0; y < 56; y += 8) /* horizontal part */ |
163 | { | 163 | { |
164 | gray_drawline(0, y, 111, 55 - y); /* gray lines */ | 164 | gray_drawline(0, y, 111, 55 - y); /* grey lines */ |
165 | } | 165 | } |
166 | for (x = 10; x < 112; x += 10) /* vertical part */ | 166 | for (x = 10; x < 112; x += 10) /* vertical part */ |
167 | { | 167 | { |
168 | gray_drawline(x, 0, 111 - x, 55); /* gray lines */ | 168 | gray_drawline(x, 0, 111 - x, 55); /* grey lines */ |
169 | } | 169 | } |
170 | 170 | ||
171 | gray_set_foreground(0); | 171 | gray_set_foreground(0); |
172 | gray_drawrect(0, 0, 112, 56); /* black border */ | 172 | gray_drawrect(0, 0, 112, 56); /* black border */ |
173 | 173 | ||
174 | /* draw gray tones */ | 174 | /* draw grey tones */ |
175 | for (i = 0; i < 86; i++) | 175 | for (i = 0; i < 86; i++) |
176 | { | 176 | { |
177 | x = 13 + i; | 177 | x = 13 + i; |
178 | gray_set_foreground(3 * i); | 178 | gray_set_foreground(3 * i); |
179 | gray_verline(x, 6, 49); /* vertical lines */ | 179 | gray_vline(x, 6, 49); /* vertical lines */ |
180 | } | 180 | } |
181 | 181 | ||
182 | gray_set_drawmode(GRAY_DRAW_INVERSE); | 182 | gray_set_drawmode(DRMODE_COMPLEMENT); |
183 | gray_fillrect(13, 29, 86, 21); /* invert rectangle (lower half) */ | 183 | gray_fillrect(13, 29, 86, 21); /* invert rectangle (lower half) */ |
184 | gray_drawline(13, 27, 98, 27); /* invert a line */ | 184 | gray_drawline(13, 27, 98, 27); /* invert a line */ |
185 | 185 | ||
186 | /* show bitmaps (1 bit and 8 bit) */ | 186 | /* show bitmaps (1 bit and 8 bit) */ |
187 | gray_set_drawinfo(GRAY_DRAW_SOLID, 255, 100); | 187 | gray_set_drawinfo(DRMODE_SOLID, 255, 100); |
188 | gray_drawbitmap(rockbox, 14, 13, 43, 7, 43); /* opaque */ | 188 | gray_mono_bitmap(rockbox, 14, 13, 43, 7); /* opaque */ |
189 | gray_set_drawinfo(GRAY_DRAW_FG, 0, -1); | 189 | gray_set_drawinfo(DRMODE_FG, 0, 100); |
190 | gray_drawbitmap(showing, 58, 13, 39, 7, 39); /* transparent */ | 190 | gray_mono_bitmap(showing, 58, 13, 39, 7); /* transparent */ |
191 | gray_gray_bitmap(grayscale_gray, 28, 35, 55, 7); | ||
191 | 192 | ||
192 | gray_drawgraymap(grayscale_gray, 28, 35, 55, 7, 55); | 193 | gray_update(); |
193 | 194 | ||
194 | time = *rb->current_tick - time; /* end time measurement */ | 195 | time = *rb->current_tick - time; /* end time measurement */ |
195 | 196 | ||
196 | rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d, %d.%02ds", shades, | 197 | rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d, %d.%02ds", shades, |
197 | time / 100, time % 100); | 198 | time / 100, time % 100); |
198 | rb->lcd_puts(0, 0, pbuf); | 199 | rb->lcd_puts(0, 0, pbuf); |
199 | gray_deferred_update(); /* schedule an lcd_update() */ | 200 | gray_deferred_lcd_update(); /* schedule an lcd_update() */ |
200 | 201 | ||
201 | /* drawing is now finished, play around with scrolling | 202 | /* drawing is now finished, play around with scrolling |
202 | * until you press OFF or connect USB | 203 | * until you press OFF or connect USB |
203 | */ | 204 | */ |
205 | gray_set_background(255); | ||
204 | while (true) | 206 | while (true) |
205 | { | 207 | { |
206 | scroll_amount = 1; | 208 | scroll_amount = 1; |
207 | black_border = false; | ||
208 | 209 | ||
209 | button = rb->button_get(true); | 210 | button = rb->button_get(true); |
210 | 211 | ||
@@ -213,31 +214,49 @@ int main(void) | |||
213 | return PLUGIN_USB_CONNECTED; | 214 | return PLUGIN_USB_CONNECTED; |
214 | 215 | ||
215 | if (button & GRAYSCALE_SHIFT) | 216 | if (button & GRAYSCALE_SHIFT) |
216 | black_border = true; | 217 | { |
217 | 218 | if (!black_border) | |
219 | { | ||
220 | gray_set_background(0); | ||
221 | black_border = true; | ||
222 | } | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | if (black_border) | ||
227 | { | ||
228 | gray_set_background(255); | ||
229 | black_border = false; | ||
230 | } | ||
231 | } | ||
232 | |||
218 | if (button & BUTTON_REPEAT) | 233 | if (button & BUTTON_REPEAT) |
219 | scroll_amount = 4; | 234 | scroll_amount = 4; |
220 | 235 | ||
221 | switch(button & ~(GRAYSCALE_SHIFT | BUTTON_REPEAT)) | 236 | switch (button & ~(GRAYSCALE_SHIFT | BUTTON_REPEAT)) |
222 | { | 237 | { |
223 | case BUTTON_LEFT: | 238 | case BUTTON_LEFT: |
224 | 239 | ||
225 | gray_scroll_left(scroll_amount, black_border); /* scroll left */ | 240 | gray_scroll_left(scroll_amount); /* scroll left */ |
241 | gray_update(); | ||
226 | break; | 242 | break; |
227 | 243 | ||
228 | case BUTTON_RIGHT: | 244 | case BUTTON_RIGHT: |
229 | 245 | ||
230 | gray_scroll_right(scroll_amount, black_border); /* scroll right */ | 246 | gray_scroll_right(scroll_amount); /* scroll right */ |
247 | gray_update(); | ||
231 | break; | 248 | break; |
232 | 249 | ||
233 | case BUTTON_UP: | 250 | case BUTTON_UP: |
234 | 251 | ||
235 | gray_scroll_up(scroll_amount, black_border); /* scroll up */ | 252 | gray_scroll_up(scroll_amount); /* scroll up */ |
253 | gray_update(); | ||
236 | break; | 254 | break; |
237 | 255 | ||
238 | case BUTTON_DOWN: | 256 | case BUTTON_DOWN: |
239 | 257 | ||
240 | gray_scroll_down(scroll_amount, black_border); /* scroll down */ | 258 | gray_scroll_down(scroll_amount); /* scroll down */ |
259 | gray_update(); | ||
241 | break; | 260 | break; |
242 | 261 | ||
243 | case BUTTON_OFF: | 262 | case BUTTON_OFF: |
@@ -260,9 +279,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
260 | rb = api; // copy to global api pointer | 279 | rb = api; // copy to global api pointer |
261 | (void)parameter; | 280 | (void)parameter; |
262 | 281 | ||
263 | /* This plugin uses the grayscale framework, so initialize */ | ||
264 | gray_init(api); | ||
265 | |||
266 | return main(); | 282 | return main(); |
267 | } | 283 | } |
268 | 284 | ||