diff options
Diffstat (limited to 'apps/plugins/imageviewer/imageviewer.c')
-rw-r--r-- | apps/plugins/imageviewer/imageviewer.c | 255 |
1 files changed, 120 insertions, 135 deletions
diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c index c35c1f26be..5c6bcc918f 100644 --- a/apps/plugins/imageviewer/imageviewer.c +++ b/apps/plugins/imageviewer/imageviewer.c | |||
@@ -43,7 +43,7 @@ bool running_slideshow = false; /* loading image because of slideshow */ | |||
43 | #ifdef DISK_SPINDOWN | 43 | #ifdef DISK_SPINDOWN |
44 | bool immediate_ata_off = false; /* power down disk after loading */ | 44 | bool immediate_ata_off = false; /* power down disk after loading */ |
45 | #endif | 45 | #endif |
46 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 46 | #ifdef USE_PLUG_BUF |
47 | /* are we using the plugin buffer or the audio buffer? */ | 47 | /* are we using the plugin buffer or the audio buffer? */ |
48 | bool plug_buf = true; | 48 | bool plug_buf = true; |
49 | #endif | 49 | #endif |
@@ -86,10 +86,6 @@ static struct configdata config[] = | |||
86 | { .int_p = &settings.ss_timeout }, "Slideshow Time", NULL }, | 86 | { .int_p = &settings.ss_timeout }, "Slideshow Time", NULL }, |
87 | }; | 87 | }; |
88 | 88 | ||
89 | #if LCD_DEPTH > 1 | ||
90 | static fb_data* old_backdrop; | ||
91 | #endif | ||
92 | |||
93 | /**************** begin Application ********************/ | 89 | /**************** begin Application ********************/ |
94 | 90 | ||
95 | 91 | ||
@@ -109,11 +105,9 @@ static ssize_t buf_size; | |||
109 | static int ds, ds_min, ds_max; /* downscaling and limits */ | 105 | static int ds, ds_min, ds_max; /* downscaling and limits */ |
110 | static struct image_info image_info; | 106 | static struct image_info image_info; |
111 | 107 | ||
112 | static struct tree_context *tree; | ||
113 | |||
114 | /* the current full file name */ | 108 | /* the current full file name */ |
115 | static char np_file[MAX_PATH]; | 109 | static char np_file[MAX_PATH]; |
116 | static int curfile = 0, direction = DIR_NONE, entries = 0; | 110 | static int curfile = 0, direction = DIR_NEXT, entries = 0; |
117 | 111 | ||
118 | /* list of the supported image files */ | 112 | /* list of the supported image files */ |
119 | static char **file_pt; | 113 | static char **file_pt; |
@@ -123,11 +117,10 @@ static char **file_pt; | |||
123 | /* Read directory contents for scrolling. */ | 117 | /* Read directory contents for scrolling. */ |
124 | static void get_pic_list(void) | 118 | static void get_pic_list(void) |
125 | { | 119 | { |
120 | struct tree_context *tree = rb->tree_get_context(); | ||
121 | struct entry *dircache = tree->dircache; | ||
126 | int i; | 122 | int i; |
127 | struct entry *dircache; | ||
128 | char *pname; | 123 | char *pname; |
129 | tree = rb->tree_get_context(); | ||
130 | dircache = tree->dircache; | ||
131 | 124 | ||
132 | file_pt = (char **) buf; | 125 | file_pt = (char **) buf; |
133 | 126 | ||
@@ -181,15 +174,7 @@ static int change_filename(int direct) | |||
181 | return PLUGIN_ERROR; | 174 | return PLUGIN_ERROR; |
182 | } | 175 | } |
183 | 176 | ||
184 | if (rb->strlen(tree->currdir) > 1) | 177 | rb->strcpy(rb->strrchr(np_file, '/')+1, file_pt[curfile]); |
185 | { | ||
186 | rb->strcpy(np_file, tree->currdir); | ||
187 | rb->strcat(np_file, "/"); | ||
188 | } | ||
189 | else | ||
190 | rb->strcpy(np_file, tree->currdir); | ||
191 | |||
192 | rb->strcat(np_file, file_pt[curfile]); | ||
193 | 178 | ||
194 | return PLUGIN_OTHER; | 179 | return PLUGIN_OTHER; |
195 | } | 180 | } |
@@ -203,12 +188,6 @@ static void cleanup(void *parameter) | |||
203 | #endif | 188 | #endif |
204 | } | 189 | } |
205 | 190 | ||
206 | #define VSCROLL (LCD_HEIGHT/8) | ||
207 | #define HSCROLL (LCD_WIDTH/10) | ||
208 | |||
209 | #define ZOOM_IN 100 /* return codes for below function */ | ||
210 | #define ZOOM_OUT 101 | ||
211 | |||
212 | #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) | 191 | #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) |
213 | static bool set_option_grayscale(void) | 192 | static bool set_option_grayscale(void) |
214 | { | 193 | { |
@@ -246,16 +225,6 @@ static void display_options(void) | |||
246 | 225 | ||
247 | static int show_menu(void) /* return 1 to quit */ | 226 | static int show_menu(void) /* return 1 to quit */ |
248 | { | 227 | { |
249 | #if LCD_DEPTH > 1 | ||
250 | rb->lcd_set_backdrop(old_backdrop); | ||
251 | #ifdef HAVE_LCD_COLOR | ||
252 | rb->lcd_set_foreground(rb->global_settings->fg_color); | ||
253 | rb->lcd_set_background(rb->global_settings->bg_color); | ||
254 | #else | ||
255 | rb->lcd_set_foreground(LCD_BLACK); | ||
256 | rb->lcd_set_background(LCD_WHITE); | ||
257 | #endif | ||
258 | #endif | ||
259 | int result; | 228 | int result; |
260 | 229 | ||
261 | enum menu_id | 230 | enum menu_id |
@@ -263,7 +232,7 @@ static int show_menu(void) /* return 1 to quit */ | |||
263 | MIID_RETURN = 0, | 232 | MIID_RETURN = 0, |
264 | MIID_TOGGLE_SS_MODE, | 233 | MIID_TOGGLE_SS_MODE, |
265 | MIID_CHANGE_SS_MODE, | 234 | MIID_CHANGE_SS_MODE, |
266 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 235 | #ifdef USE_PLUG_BUF |
267 | MIID_SHOW_PLAYBACK_MENU, | 236 | MIID_SHOW_PLAYBACK_MENU, |
268 | #endif | 237 | #endif |
269 | #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) | 238 | #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) |
@@ -275,7 +244,7 @@ static int show_menu(void) /* return 1 to quit */ | |||
275 | MENUITEM_STRINGLIST(menu, MENU_TITLE, NULL, | 244 | MENUITEM_STRINGLIST(menu, MENU_TITLE, NULL, |
276 | "Return", "Toggle Slideshow Mode", | 245 | "Return", "Toggle Slideshow Mode", |
277 | "Change Slideshow Time", | 246 | "Change Slideshow Time", |
278 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 247 | #ifdef USE_PLUG_BUF |
279 | "Show Playback Menu", | 248 | "Show Playback Menu", |
280 | #endif | 249 | #endif |
281 | #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) | 250 | #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) |
@@ -304,7 +273,7 @@ static int show_menu(void) /* return 1 to quit */ | |||
304 | SS_MIN_TIMEOUT, SS_MAX_TIMEOUT, NULL); | 273 | SS_MIN_TIMEOUT, SS_MAX_TIMEOUT, NULL); |
305 | break; | 274 | break; |
306 | 275 | ||
307 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 276 | #ifdef USE_PLUG_BUF |
308 | case MIID_SHOW_PLAYBACK_MENU: | 277 | case MIID_SHOW_PLAYBACK_MENU: |
309 | if (plug_buf) | 278 | if (plug_buf) |
310 | { | 279 | { |
@@ -354,6 +323,88 @@ static int show_menu(void) /* return 1 to quit */ | |||
354 | return 0; | 323 | return 0; |
355 | } | 324 | } |
356 | 325 | ||
326 | #ifdef USE_PLUG_BUF | ||
327 | static int ask_and_get_audio_buffer(const char *filename) | ||
328 | { | ||
329 | rb->lcd_setfont(FONT_SYSFIXED); | ||
330 | rb->lcd_clear_display(); | ||
331 | rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); | ||
332 | rb->lcd_puts(0, 1, "Not enough plugin memory!"); | ||
333 | rb->lcd_puts(0, 2, "Zoom In: Stop playback."); | ||
334 | if(entries > 1) | ||
335 | rb->lcd_puts(0, 3, "Left/Right: Skip File."); | ||
336 | rb->lcd_puts(0, 4, "Show Menu: Quit."); | ||
337 | rb->lcd_update(); | ||
338 | rb->lcd_setfont(FONT_UI); | ||
339 | |||
340 | rb->button_clear_queue(); | ||
341 | |||
342 | while (1) | ||
343 | { | ||
344 | int button = rb->button_get(true); | ||
345 | switch(button) | ||
346 | { | ||
347 | case IMGVIEW_ZOOM_IN: | ||
348 | plug_buf = false; | ||
349 | buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); | ||
350 | /*try again this file, now using the audio buffer */ | ||
351 | return PLUGIN_OTHER; | ||
352 | #ifdef IMGVIEW_RC_MENU | ||
353 | case IMGVIEW_RC_MENU: | ||
354 | #endif | ||
355 | case IMGVIEW_MENU: | ||
356 | return PLUGIN_OK; | ||
357 | |||
358 | case IMGVIEW_LEFT: | ||
359 | if(entries>1) | ||
360 | { | ||
361 | rb->lcd_clear_display(); | ||
362 | return change_filename(DIR_PREV); | ||
363 | } | ||
364 | break; | ||
365 | |||
366 | case IMGVIEW_RIGHT: | ||
367 | if(entries>1) | ||
368 | { | ||
369 | rb->lcd_clear_display(); | ||
370 | return change_filename(DIR_NEXT); | ||
371 | } | ||
372 | break; | ||
373 | default: | ||
374 | if(rb->default_event_handler_ex(button, cleanup, NULL) | ||
375 | == SYS_USB_CONNECTED) | ||
376 | return PLUGIN_USB_CONNECTED; | ||
377 | |||
378 | } | ||
379 | } | ||
380 | } | ||
381 | #endif /* USE_PLUG_BUF */ | ||
382 | |||
383 | /* callback updating a progress meter while image decoding */ | ||
384 | void cb_progress(int current, int total) | ||
385 | { | ||
386 | rb->yield(); /* be nice to the other threads */ | ||
387 | #ifndef USEGSLIB | ||
388 | /* in slideshow mode, keep gui interference to a minimum */ | ||
389 | const int size = (!running_slideshow ? 8 : 4); | ||
390 | #else | ||
391 | const int size = 8; | ||
392 | if(!running_slideshow) | ||
393 | #endif | ||
394 | { | ||
395 | rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], | ||
396 | 0, LCD_HEIGHT-size, LCD_WIDTH, size, | ||
397 | total, 0, current, HORIZONTAL); | ||
398 | rb->lcd_update_rect(0, LCD_HEIGHT-size, LCD_WIDTH, size); | ||
399 | } | ||
400 | } | ||
401 | |||
402 | #define VSCROLL (LCD_HEIGHT/8) | ||
403 | #define HSCROLL (LCD_WIDTH/10) | ||
404 | |||
405 | #define ZOOM_IN 100 /* return codes for below function */ | ||
406 | #define ZOOM_OUT 101 | ||
407 | |||
357 | /* Pan the viewing window right - move image to the left and fill in | 408 | /* Pan the viewing window right - move image to the left and fill in |
358 | the right-hand side */ | 409 | the right-hand side */ |
359 | static void pan_view_right(struct image_info *info) | 410 | static void pan_view_right(struct image_info *info) |
@@ -454,7 +505,7 @@ static void pan_view_down(struct image_info *info) | |||
454 | static int scroll_bmp(struct image_info *info) | 505 | static int scroll_bmp(struct image_info *info) |
455 | { | 506 | { |
456 | int button; | 507 | int button; |
457 | int lastbutton = 0; | 508 | int lastbutton = BUTTON_NONE; |
458 | 509 | ||
459 | while (true) | 510 | while (true) |
460 | { | 511 | { |
@@ -494,17 +545,16 @@ static int scroll_bmp(struct image_info *info) | |||
494 | break; | 545 | break; |
495 | 546 | ||
496 | case BUTTON_NONE: | 547 | case BUTTON_NONE: |
497 | if (!slideshow_enabled) | 548 | if (slideshow_enabled && entries > 1) |
498 | break; | 549 | { |
499 | running_slideshow = true; | 550 | running_slideshow = true; |
500 | if (entries > 1) | ||
501 | return change_filename(DIR_NEXT); | 551 | return change_filename(DIR_NEXT); |
552 | } | ||
502 | break; | 553 | break; |
503 | 554 | ||
504 | #ifdef IMGVIEW_SLIDE_SHOW | 555 | #ifdef IMGVIEW_SLIDE_SHOW |
505 | case IMGVIEW_SLIDE_SHOW: | 556 | case IMGVIEW_SLIDE_SHOW: |
506 | slideshow_enabled = !slideshow_enabled; | 557 | slideshow_enabled = !slideshow_enabled; |
507 | running_slideshow = slideshow_enabled; | ||
508 | break; | 558 | break; |
509 | #endif | 559 | #endif |
510 | 560 | ||
@@ -539,6 +589,7 @@ static int scroll_bmp(struct image_info *info) | |||
539 | #endif | 589 | #endif |
540 | return ZOOM_OUT; | 590 | return ZOOM_OUT; |
541 | break; | 591 | break; |
592 | |||
542 | #ifdef IMGVIEW_RC_MENU | 593 | #ifdef IMGVIEW_RC_MENU |
543 | case IMGVIEW_RC_MENU: | 594 | case IMGVIEW_RC_MENU: |
544 | #endif | 595 | #endif |
@@ -557,6 +608,7 @@ static int scroll_bmp(struct image_info *info) | |||
557 | MYLCD_UPDATE(); | 608 | MYLCD_UPDATE(); |
558 | #endif | 609 | #endif |
559 | break; | 610 | break; |
611 | |||
560 | default: | 612 | default: |
561 | if (rb->default_event_handler_ex(button, cleanup, NULL) | 613 | if (rb->default_event_handler_ex(button, cleanup, NULL) |
562 | == SYS_USB_CONNECTED) | 614 | == SYS_USB_CONNECTED) |
@@ -572,29 +624,6 @@ static int scroll_bmp(struct image_info *info) | |||
572 | 624 | ||
573 | /********************* main function *************************/ | 625 | /********************* main function *************************/ |
574 | 626 | ||
575 | /* callback updating a progress meter while image decoding */ | ||
576 | void cb_progress(int current, int total) | ||
577 | { | ||
578 | rb->yield(); /* be nice to the other threads */ | ||
579 | if(!running_slideshow) | ||
580 | { | ||
581 | rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], | ||
582 | 0, LCD_HEIGHT-8, LCD_WIDTH, 8, | ||
583 | total, 0, current, HORIZONTAL); | ||
584 | rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); | ||
585 | } | ||
586 | #ifndef USEGSLIB | ||
587 | else | ||
588 | { | ||
589 | /* in slideshow mode, keep gui interference to a minimum */ | ||
590 | rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], | ||
591 | 0, LCD_HEIGHT-4, LCD_WIDTH, 4, | ||
592 | total, 0, current, HORIZONTAL); | ||
593 | rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4); | ||
594 | } | ||
595 | #endif | ||
596 | } | ||
597 | |||
598 | /* how far can we zoom in without running out of memory */ | 627 | /* how far can we zoom in without running out of memory */ |
599 | static int min_downscale(int bufsize) | 628 | static int min_downscale(int bufsize) |
600 | { | 629 | { |
@@ -658,11 +687,6 @@ static int load_and_show(char* filename, struct image_info *info) | |||
658 | int cx, cy; | 687 | int cx, cy; |
659 | ssize_t remaining; | 688 | ssize_t remaining; |
660 | 689 | ||
661 | #if LCD_DEPTH > 1 | ||
662 | rb->lcd_set_foreground(LCD_WHITE); | ||
663 | rb->lcd_set_background(LCD_BLACK); | ||
664 | rb->lcd_set_backdrop(NULL); | ||
665 | #endif | ||
666 | rb->lcd_clear_display(); | 690 | rb->lcd_clear_display(); |
667 | 691 | ||
668 | rb->memset(info, 0, sizeof(*info)); | 692 | rb->memset(info, 0, sizeof(*info)); |
@@ -675,61 +699,10 @@ static int load_and_show(char* filename, struct image_info *info) | |||
675 | 699 | ||
676 | if (status == PLUGIN_OUTOFMEM) | 700 | if (status == PLUGIN_OUTOFMEM) |
677 | { | 701 | { |
678 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 702 | #ifdef USE_PLUG_BUF |
679 | if(plug_buf) | 703 | if(plug_buf) |
680 | { | 704 | { |
681 | rb->lcd_setfont(FONT_SYSFIXED); | 705 | return ask_and_get_audio_buffer(filename); |
682 | rb->lcd_clear_display(); | ||
683 | rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1); | ||
684 | rb->lcd_puts(0,0,print); | ||
685 | rb->lcd_puts(0,1,"Not enough plugin memory!"); | ||
686 | rb->lcd_puts(0,2,"Zoom In: Stop playback."); | ||
687 | if(entries>1) | ||
688 | rb->lcd_puts(0,3,"Left/Right: Skip File."); | ||
689 | rb->lcd_puts(0,4,"Show Menu: Quit."); | ||
690 | rb->lcd_update(); | ||
691 | rb->lcd_setfont(FONT_UI); | ||
692 | |||
693 | rb->button_clear_queue(); | ||
694 | |||
695 | while (1) | ||
696 | { | ||
697 | int button = rb->button_get(true); | ||
698 | switch(button) | ||
699 | { | ||
700 | case IMGVIEW_ZOOM_IN: | ||
701 | plug_buf = false; | ||
702 | buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); | ||
703 | /*try again this file, now using the audio buffer */ | ||
704 | return PLUGIN_OTHER; | ||
705 | #ifdef IMGVIEW_RC_MENU | ||
706 | case IMGVIEW_RC_MENU: | ||
707 | #endif | ||
708 | case IMGVIEW_MENU: | ||
709 | return PLUGIN_OK; | ||
710 | |||
711 | case IMGVIEW_LEFT: | ||
712 | if(entries>1) | ||
713 | { | ||
714 | rb->lcd_clear_display(); | ||
715 | return change_filename(DIR_PREV); | ||
716 | } | ||
717 | break; | ||
718 | |||
719 | case IMGVIEW_RIGHT: | ||
720 | if(entries>1) | ||
721 | { | ||
722 | rb->lcd_clear_display(); | ||
723 | return change_filename(DIR_NEXT); | ||
724 | } | ||
725 | break; | ||
726 | default: | ||
727 | if(rb->default_event_handler_ex(button, cleanup, NULL) | ||
728 | == SYS_USB_CONNECTED) | ||
729 | return PLUGIN_USB_CONNECTED; | ||
730 | |||
731 | } | ||
732 | } | ||
733 | } | 706 | } |
734 | else | 707 | else |
735 | #endif | 708 | #endif |
@@ -758,9 +731,18 @@ static int load_and_show(char* filename, struct image_info *info) | |||
758 | ds_min = ds_max = 1; | 731 | ds_min = ds_max = 1; |
759 | #else | 732 | #else |
760 | /* not enough memory to decode image. */ | 733 | /* not enough memory to decode image. */ |
761 | rb->splash(HZ, "too large"); | 734 | #ifdef USE_PLUG_BUF |
762 | file_pt[curfile] = NULL; | 735 | if(plug_buf) |
763 | return change_filename(direction); | 736 | { |
737 | return ask_and_get_audio_buffer(filename); | ||
738 | } | ||
739 | else | ||
740 | #endif | ||
741 | { | ||
742 | rb->splash(HZ, "too large"); | ||
743 | file_pt[curfile] = NULL; | ||
744 | return change_filename(direction); | ||
745 | } | ||
764 | #endif | 746 | #endif |
765 | } | 747 | } |
766 | else if (ds_max < ds_min) | 748 | else if (ds_max < ds_min) |
@@ -784,7 +766,7 @@ static int load_and_show(char* filename, struct image_info *info) | |||
784 | if(!running_slideshow) | 766 | if(!running_slideshow) |
785 | { | 767 | { |
786 | rb->snprintf(print, sizeof(print), "showing %dx%d", | 768 | rb->snprintf(print, sizeof(print), "showing %dx%d", |
787 | info->width, info->height); | 769 | info->width, info->height); |
788 | rb->lcd_puts(0, 3, print); | 770 | rb->lcd_puts(0, 3, print); |
789 | rb->lcd_update(); | 771 | rb->lcd_update(); |
790 | } | 772 | } |
@@ -869,13 +851,10 @@ enum plugin_status plugin_start(const void* parameter) | |||
869 | #ifdef USEGSLIB | 851 | #ifdef USEGSLIB |
870 | long greysize; /* helper */ | 852 | long greysize; /* helper */ |
871 | #endif | 853 | #endif |
872 | #if LCD_DEPTH > 1 | ||
873 | old_backdrop = rb->lcd_get_backdrop(); | ||
874 | #endif | ||
875 | 854 | ||
876 | if(!parameter) return PLUGIN_ERROR; | 855 | if(!parameter) return PLUGIN_ERROR; |
877 | 856 | ||
878 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 857 | #ifdef USE_PLUG_BUF |
879 | buf = rb->plugin_get_buffer((size_t *)&buf_size); | 858 | buf = rb->plugin_get_buffer((size_t *)&buf_size); |
880 | #else | 859 | #else |
881 | buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); | 860 | buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); |
@@ -886,7 +865,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
886 | 865 | ||
887 | if(!entries) return PLUGIN_ERROR; | 866 | if(!entries) return PLUGIN_ERROR; |
888 | 867 | ||
889 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 868 | #ifdef USE_PLUG_BUF |
890 | if(!rb->audio_status()) | 869 | if(!rb->audio_status()) |
891 | { | 870 | { |
892 | plug_buf = false; | 871 | plug_buf = false; |
@@ -914,6 +893,12 @@ enum plugin_status plugin_start(const void* parameter) | |||
914 | /* Turn off backlight timeout */ | 893 | /* Turn off backlight timeout */ |
915 | backlight_force_on(); /* backlight control in lib/helper.c */ | 894 | backlight_force_on(); /* backlight control in lib/helper.c */ |
916 | 895 | ||
896 | #if LCD_DEPTH > 1 | ||
897 | rb->lcd_set_backdrop(NULL); | ||
898 | rb->lcd_set_foreground(LCD_WHITE); | ||
899 | rb->lcd_set_background(LCD_BLACK); | ||
900 | #endif | ||
901 | |||
917 | do | 902 | do |
918 | { | 903 | { |
919 | condition = load_and_show(np_file, &image_info); | 904 | condition = load_and_show(np_file, &image_info); |