diff options
-rw-r--r-- | apps/plugins/imageviewer/imageviewer.c | 255 | ||||
-rw-r--r-- | apps/plugins/imageviewer/imageviewer.h | 5 | ||||
-rw-r--r-- | apps/plugins/imageviewer/jpeg/jpeg.c | 10 | ||||
-rw-r--r-- | apps/plugins/imageviewer/png/png.c | 35 |
4 files changed, 143 insertions, 162 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 */ #ifdef DISK_SPINDOWN bool immediate_ata_off = false; /* power down disk after loading */ #endif -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF /* are we using the plugin buffer or the audio buffer? */ bool plug_buf = true; #endif @@ -86,10 +86,6 @@ static struct configdata config[] = { .int_p = &settings.ss_timeout }, "Slideshow Time", NULL }, }; -#if LCD_DEPTH > 1 -static fb_data* old_backdrop; -#endif - /**************** begin Application ********************/ @@ -109,11 +105,9 @@ static ssize_t buf_size; static int ds, ds_min, ds_max; /* downscaling and limits */ static struct image_info image_info; -static struct tree_context *tree; - /* the current full file name */ static char np_file[MAX_PATH]; -static int curfile = 0, direction = DIR_NONE, entries = 0; +static int curfile = 0, direction = DIR_NEXT, entries = 0; /* list of the supported image files */ static char **file_pt; @@ -123,11 +117,10 @@ static char **file_pt; /* Read directory contents for scrolling. */ static void get_pic_list(void) { + struct tree_context *tree = rb->tree_get_context(); + struct entry *dircache = tree->dircache; int i; - struct entry *dircache; char *pname; - tree = rb->tree_get_context(); - dircache = tree->dircache; file_pt = (char **) buf; @@ -181,15 +174,7 @@ static int change_filename(int direct) return PLUGIN_ERROR; } - if (rb->strlen(tree->currdir) > 1) - { - rb->strcpy(np_file, tree->currdir); - rb->strcat(np_file, "/"); - } - else - rb->strcpy(np_file, tree->currdir); - - rb->strcat(np_file, file_pt[curfile]); + rb->strcpy(rb->strrchr(np_file, '/')+1, file_pt[curfile]); return PLUGIN_OTHER; } @@ -203,12 +188,6 @@ static void cleanup(void *parameter) #endif } -#define VSCROLL (LCD_HEIGHT/8) -#define HSCROLL (LCD_WIDTH/10) - -#define ZOOM_IN 100 /* return codes for below function */ -#define ZOOM_OUT 101 - #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) static bool set_option_grayscale(void) { @@ -246,16 +225,6 @@ static void display_options(void) static int show_menu(void) /* return 1 to quit */ { -#if LCD_DEPTH > 1 - rb->lcd_set_backdrop(old_backdrop); -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(rb->global_settings->fg_color); - rb->lcd_set_background(rb->global_settings->bg_color); -#else - rb->lcd_set_foreground(LCD_BLACK); - rb->lcd_set_background(LCD_WHITE); -#endif -#endif int result; enum menu_id @@ -263,7 +232,7 @@ static int show_menu(void) /* return 1 to quit */ MIID_RETURN = 0, MIID_TOGGLE_SS_MODE, MIID_CHANGE_SS_MODE, -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF MIID_SHOW_PLAYBACK_MENU, #endif #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) @@ -275,7 +244,7 @@ static int show_menu(void) /* return 1 to quit */ MENUITEM_STRINGLIST(menu, MENU_TITLE, NULL, "Return", "Toggle Slideshow Mode", "Change Slideshow Time", -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF "Show Playback Menu", #endif #if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) @@ -304,7 +273,7 @@ static int show_menu(void) /* return 1 to quit */ SS_MIN_TIMEOUT, SS_MAX_TIMEOUT, NULL); break; -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF case MIID_SHOW_PLAYBACK_MENU: if (plug_buf) { @@ -354,6 +323,88 @@ static int show_menu(void) /* return 1 to quit */ return 0; } +#ifdef USE_PLUG_BUF +static int ask_and_get_audio_buffer(const char *filename) +{ + rb->lcd_setfont(FONT_SYSFIXED); + rb->lcd_clear_display(); + rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); + rb->lcd_puts(0, 1, "Not enough plugin memory!"); + rb->lcd_puts(0, 2, "Zoom In: Stop playback."); + if(entries > 1) + rb->lcd_puts(0, 3, "Left/Right: Skip File."); + rb->lcd_puts(0, 4, "Show Menu: Quit."); + rb->lcd_update(); + rb->lcd_setfont(FONT_UI); + + rb->button_clear_queue(); + + while (1) + { + int button = rb->button_get(true); + switch(button) + { + case IMGVIEW_ZOOM_IN: + plug_buf = false; + buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); + /*try again this file, now using the audio buffer */ + return PLUGIN_OTHER; +#ifdef IMGVIEW_RC_MENU + case IMGVIEW_RC_MENU: +#endif + case IMGVIEW_MENU: + return PLUGIN_OK; + + case IMGVIEW_LEFT: + if(entries>1) + { + rb->lcd_clear_display(); + return change_filename(DIR_PREV); + } + break; + + case IMGVIEW_RIGHT: + if(entries>1) + { + rb->lcd_clear_display(); + return change_filename(DIR_NEXT); + } + break; + default: + if(rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + + } + } +} +#endif /* USE_PLUG_BUF */ + +/* callback updating a progress meter while image decoding */ +void cb_progress(int current, int total) +{ + rb->yield(); /* be nice to the other threads */ +#ifndef USEGSLIB + /* in slideshow mode, keep gui interference to a minimum */ + const int size = (!running_slideshow ? 8 : 4); +#else + const int size = 8; + if(!running_slideshow) +#endif + { + rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], + 0, LCD_HEIGHT-size, LCD_WIDTH, size, + total, 0, current, HORIZONTAL); + rb->lcd_update_rect(0, LCD_HEIGHT-size, LCD_WIDTH, size); + } +} + +#define VSCROLL (LCD_HEIGHT/8) +#define HSCROLL (LCD_WIDTH/10) + +#define ZOOM_IN 100 /* return codes for below function */ +#define ZOOM_OUT 101 + /* Pan the viewing window right - move image to the left and fill in the right-hand side */ static void pan_view_right(struct image_info *info) @@ -454,7 +505,7 @@ static void pan_view_down(struct image_info *info) static int scroll_bmp(struct image_info *info) { int button; - int lastbutton = 0; + int lastbutton = BUTTON_NONE; while (true) { @@ -494,17 +545,16 @@ static int scroll_bmp(struct image_info *info) break; case BUTTON_NONE: - if (!slideshow_enabled) - break; - running_slideshow = true; - if (entries > 1) + if (slideshow_enabled && entries > 1) + { + running_slideshow = true; return change_filename(DIR_NEXT); + } break; #ifdef IMGVIEW_SLIDE_SHOW case IMGVIEW_SLIDE_SHOW: slideshow_enabled = !slideshow_enabled; - running_slideshow = slideshow_enabled; break; #endif @@ -539,6 +589,7 @@ static int scroll_bmp(struct image_info *info) #endif return ZOOM_OUT; break; + #ifdef IMGVIEW_RC_MENU case IMGVIEW_RC_MENU: #endif @@ -557,6 +608,7 @@ static int scroll_bmp(struct image_info *info) MYLCD_UPDATE(); #endif break; + default: if (rb->default_event_handler_ex(button, cleanup, NULL) == SYS_USB_CONNECTED) @@ -572,29 +624,6 @@ static int scroll_bmp(struct image_info *info) /********************* main function *************************/ -/* callback updating a progress meter while image decoding */ -void cb_progress(int current, int total) -{ - rb->yield(); /* be nice to the other threads */ - if(!running_slideshow) - { - rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], - 0, LCD_HEIGHT-8, LCD_WIDTH, 8, - total, 0, current, HORIZONTAL); - rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); - } -#ifndef USEGSLIB - else - { - /* in slideshow mode, keep gui interference to a minimum */ - rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], - 0, LCD_HEIGHT-4, LCD_WIDTH, 4, - total, 0, current, HORIZONTAL); - rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4); - } -#endif -} - /* how far can we zoom in without running out of memory */ static int min_downscale(int bufsize) { @@ -658,11 +687,6 @@ static int load_and_show(char* filename, struct image_info *info) int cx, cy; ssize_t remaining; -#if LCD_DEPTH > 1 - rb->lcd_set_foreground(LCD_WHITE); - rb->lcd_set_background(LCD_BLACK); - rb->lcd_set_backdrop(NULL); -#endif rb->lcd_clear_display(); rb->memset(info, 0, sizeof(*info)); @@ -675,61 +699,10 @@ static int load_and_show(char* filename, struct image_info *info) if (status == PLUGIN_OUTOFMEM) { -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF if(plug_buf) { - rb->lcd_setfont(FONT_SYSFIXED); - rb->lcd_clear_display(); - rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1); - rb->lcd_puts(0,0,print); - rb->lcd_puts(0,1,"Not enough plugin memory!"); - rb->lcd_puts(0,2,"Zoom In: Stop playback."); - if(entries>1) - rb->lcd_puts(0,3,"Left/Right: Skip File."); - rb->lcd_puts(0,4,"Show Menu: Quit."); - rb->lcd_update(); - rb->lcd_setfont(FONT_UI); - - rb->button_clear_queue(); - - while (1) - { - int button = rb->button_get(true); - switch(button) - { - case IMGVIEW_ZOOM_IN: - plug_buf = false; - buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); - /*try again this file, now using the audio buffer */ - return PLUGIN_OTHER; -#ifdef IMGVIEW_RC_MENU - case IMGVIEW_RC_MENU: -#endif - case IMGVIEW_MENU: - return PLUGIN_OK; - - case IMGVIEW_LEFT: - if(entries>1) - { - rb->lcd_clear_display(); - return change_filename(DIR_PREV); - } - break; - - case IMGVIEW_RIGHT: - if(entries>1) - { - rb->lcd_clear_display(); - return change_filename(DIR_NEXT); - } - break; - default: - if(rb->default_event_handler_ex(button, cleanup, NULL) - == SYS_USB_CONNECTED) - return PLUGIN_USB_CONNECTED; - - } - } + return ask_and_get_audio_buffer(filename); } else #endif @@ -758,9 +731,18 @@ static int load_and_show(char* filename, struct image_info *info) ds_min = ds_max = 1; #else /* not enough memory to decode image. */ - rb->splash(HZ, "too large"); - file_pt[curfile] = NULL; - return change_filename(direction); +#ifdef USE_PLUG_BUF + if(plug_buf) + { + return ask_and_get_audio_buffer(filename); + } + else +#endif + { + rb->splash(HZ, "too large"); + file_pt[curfile] = NULL; + return change_filename(direction); + } #endif } else if (ds_max < ds_min) @@ -784,7 +766,7 @@ static int load_and_show(char* filename, struct image_info *info) if(!running_slideshow) { rb->snprintf(print, sizeof(print), "showing %dx%d", - info->width, info->height); + info->width, info->height); rb->lcd_puts(0, 3, print); rb->lcd_update(); } @@ -869,13 +851,10 @@ enum plugin_status plugin_start(const void* parameter) #ifdef USEGSLIB long greysize; /* helper */ #endif -#if LCD_DEPTH > 1 - old_backdrop = rb->lcd_get_backdrop(); -#endif if(!parameter) return PLUGIN_ERROR; -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF buf = rb->plugin_get_buffer((size_t *)&buf_size); #else buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); @@ -886,7 +865,7 @@ enum plugin_status plugin_start(const void* parameter) if(!entries) return PLUGIN_ERROR; -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF if(!rb->audio_status()) { plug_buf = false; @@ -914,6 +893,12 @@ enum plugin_status plugin_start(const void* parameter) /* Turn off backlight timeout */ backlight_force_on(); /* backlight control in lib/helper.c */ +#if LCD_DEPTH > 1 + rb->lcd_set_backdrop(NULL); + rb->lcd_set_foreground(LCD_WHITE); + rb->lcd_set_background(LCD_BLACK); +#endif + do { condition = load_and_show(np_file, &image_info); diff --git a/apps/plugins/imageviewer/imageviewer.h b/apps/plugins/imageviewer/imageviewer.h index 4ced196e59..e1009ec32f 100644 --- a/apps/plugins/imageviewer/imageviewer.h +++ b/apps/plugins/imageviewer/imageviewer.h @@ -361,6 +361,9 @@ #if !defined(SIMULATOR) && defined(HAVE_DISK_STORAGE) #define DISK_SPINDOWN #endif +#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#define USE_PLUG_BUF +#endif /* Settings. jpeg needs these */ struct imgview_settings @@ -390,7 +393,7 @@ extern bool running_slideshow; #ifdef DISK_SPINDOWN extern bool immediate_ata_off; #endif -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF extern bool plug_buf; #endif diff --git a/apps/plugins/imageviewer/jpeg/jpeg.c b/apps/plugins/imageviewer/jpeg/jpeg.c index b4ac6c0fce..91e0c1021f 100644 --- a/apps/plugins/imageviewer/jpeg/jpeg.c +++ b/apps/plugins/imageviewer/jpeg/jpeg.c @@ -156,8 +156,7 @@ int load_image(char *filename, struct image_info *info, if(!running_slideshow) { - rb->snprintf(print, sizeof(print), "%s:", rb->strrchr(filename,'/')+1); - rb->lcd_puts(0, 0, print); + rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); rb->lcd_update(); rb->snprintf(print, sizeof(print), "loading %d bytes", filesize); @@ -170,8 +169,7 @@ int load_image(char *filename, struct image_info *info, if(!running_slideshow) { - rb->snprintf(print, sizeof(print), "decoding markers"); - rb->lcd_puts(0, 2, print); + rb->lcd_puts(0, 2, "decoding markers"); rb->lcd_update(); } #ifdef DISK_SPINDOWN @@ -198,7 +196,7 @@ int load_image(char *filename, struct image_info *info, if(!running_slideshow) { rb->snprintf(print, sizeof(print), "image %dx%d", - p_jpg->x_size, p_jpg->y_size); + p_jpg->x_size, p_jpg->y_size); rb->lcd_puts(0, 2, print); rb->lcd_update(); } @@ -272,7 +270,7 @@ int get_image(struct image_info *info, int ds) if(!running_slideshow) { rb->snprintf(print, sizeof(print), "decoding %d*%d", - p_jpg->x_size/ds, p_jpg->y_size/ds); + info->width, info->height); rb->lcd_puts(0, 3, print); rb->lcd_update(); } diff --git a/apps/plugins/imageviewer/png/png.c b/apps/plugins/imageviewer/png/png.c index d04b0850f4..958793b37d 100644 --- a/apps/plugins/imageviewer/png/png.c +++ b/apps/plugins/imageviewer/png/png.c @@ -144,7 +144,7 @@ static fb_data *disp[9]; static fb_data *disp_buf; /* my memory pool (from the mp3 buffer) */ -static char print[128]; /* use a common snprintf() buffer */ +static char print[32]; /* use a common snprintf() buffer */ unsigned char *memory, *memory_max; /* inffast.c needs memory_max */ static size_t memory_size; @@ -204,7 +204,6 @@ static unsigned LodePNG_decompress(unsigned char* out, size_t* outsize, const un if (stream.msg != Z_NULL) rb->strcpy(error_msg, stream.msg); return err; - } /* ////////////////////////////////////////////////////////////////////////// */ @@ -469,8 +468,7 @@ unsigned LodePNG_convert(fb_data* out, const unsigned char* in, LodePNG_InfoColo if (!running_slideshow) { - rb->snprintf(print, sizeof(print), "color conversion in progress"); - rb->lcd_puts(0, 3, print); + rb->lcd_puts(0, 3, "color conversion in progress"); rb->lcd_update(); } @@ -1201,8 +1199,7 @@ static void decodeGeneric(LodePNG_Decoder* decoder, unsigned char* in, size_t si memset(decoded_image, 0, decoded_image_size * sizeof(unsigned char)); if (!running_slideshow) { - rb->snprintf(print, sizeof(print), "unfiltering scanlines"); - rb->lcd_puts(0, 3, print); + rb->lcd_puts(0, 3, "unfiltering scanlines"); rb->lcd_update(); } decoder->error = postProcessScanlines(decoded_image, scanlines, decoder); @@ -1217,7 +1214,7 @@ void LodePNG_decode(LodePNG_Decoder* decoder, unsigned char* in, size_t insize, /*TODO: check if this works according to the statement in the documentation: "The converter can convert from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/ if (!(decoder->infoRaw.color.colorType == 2 || decoder->infoRaw.color.colorType == 6) && !(decoder->infoRaw.color.bitDepth == 8)) { decoder->error = 56; return; } - converted_image = (fb_data *)((intptr_t)(memory + 3) & ~3); + converted_image = (fb_data *)memory; converted_image_size = decoder->infoPng.width*decoder->infoPng.height; if ((unsigned char *)(converted_image + converted_image_size) >= decoded_image) { decoder->error = OUT_OF_MEMORY; } if (!decoder->error) decoder->error = LodePNG_convert(converted_image, decoded_image, &decoder->infoRaw.color, &decoder->infoPng.color, decoder->infoPng.width, decoder->infoPng.height); @@ -1333,9 +1330,10 @@ int load_image(char *filename, struct image_info *info, memset(&disp, 0, sizeof(disp)); LodePNG_Decoder_init(decoder); - memory = buf; - memory_size = *buf_size; - memory_max = memory + memory_size; + /* align buffer */ + memory = (unsigned char *)((intptr_t)(buf + 3) & ~3); + memory_max = (unsigned char *)((intptr_t)(memory + *buf_size) & ~3); + memory_size = memory_max - memory; fd = rb->open(filename, O_RDONLY); if (fd < 0) @@ -1348,8 +1346,7 @@ int load_image(char *filename, struct image_info *info, DEBUGF("reading file '%s'\n", filename); if (!running_slideshow) { - rb->snprintf(print, sizeof(print), "%s:", rb->strrchr(filename,'/')+1); - rb->lcd_puts(0, 0, print); + rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); rb->lcd_update(); } @@ -1369,8 +1366,7 @@ int load_image(char *filename, struct image_info *info, rb->close(fd); if (!running_slideshow) { - rb->snprintf(print, sizeof(print), "decoding image"); - rb->lcd_puts(0, 2, print); + rb->lcd_puts(0, 2, "decoding image"); rb->lcd_update(); } #ifdef DISK_SPINDOWN @@ -1409,11 +1405,10 @@ int load_image(char *filename, struct image_info *info, #else LodePNG_decode(decoder, image, image_size, cb_progress); #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ + time = *rb->current_tick - time; } } - time = *rb->current_tick - time; - if (!running_slideshow && !decoder->error) { rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ); @@ -1423,7 +1418,7 @@ int load_image(char *filename, struct image_info *info, } if (decoder->error) { -#if PLUGIN_BUFFER_SIZE >= MIN_MEM +#ifdef USE_PLUG_BUF if (plug_buf && (decoder->error == FILE_TOO_LARGE || decoder->error == OUT_OF_MEMORY || decoder->error == Z_MEM_ERROR)) return PLUGIN_OUTOFMEM; @@ -1457,7 +1452,7 @@ int load_image(char *filename, struct image_info *info, return PLUGIN_ERROR; } - disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3); + disp_buf = converted_image + converted_image_size; info->x_size = decoder->infoPng.width; info->y_size = decoder->infoPng.height; *buf_size = memory_max - (unsigned char*)disp_buf; @@ -1498,11 +1493,11 @@ int get_image(struct image_info *info, int ds) for (i=1; i<=8; i++) disp[i] = NULL; /* invalidate all bitmaps */ /* start again from the beginning of the buffer */ - disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3); + disp_buf = converted_image + converted_image_size; } *p_disp = disp_buf; - disp_buf = (fb_data *)((intptr_t)(disp_buf + size + 3) & ~3); + disp_buf += size; bmp_src.width = decoder->infoPng.width; bmp_src.height = decoder->infoPng.height; |