From 55a5bfe7409677a26437651798abbc6d87b56089 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Mon, 14 Oct 2024 21:33:40 +0300 Subject: View Album Art from WPS context menu Add ability to imageviewer to view current track embedded/folder album art Add "View Album Art" WPS context menu item Change-Id: I49caebd38e5e3e2910d418bbeaa5e51da0e6bd93 --- apps/lang/english.lang | 14 +++++ apps/onplay.c | 14 +++++ apps/plugins/imageviewer/bmp/bmp.c | 9 +++- apps/plugins/imageviewer/gif/gif.c | 5 +- apps/plugins/imageviewer/imageviewer.c | 98 ++++++++++++++++++++++++++++------ apps/plugins/imageviewer/imageviewer.h | 2 +- apps/plugins/imageviewer/jpeg/jpeg.c | 14 +++-- apps/plugins/imageviewer/jpegp/jpegp.c | 8 ++- apps/plugins/imageviewer/png/png.c | 17 ++++-- apps/plugins/imageviewer/ppm/ppm.c | 16 ++++-- 10 files changed, 166 insertions(+), 31 deletions(-) diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 1beb730411..f88864efcc 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -16567,3 +16567,17 @@ *: "Remaining" + + id: LANG_VIEW_ALBUMART + desc: WPS context menu + user: core + + *: "View Album Art" + + + *: "View Album Art" + + + *: "View Album Art" + + diff --git a/apps/onplay.c b/apps/onplay.c index ab507f08ac..a259e88c58 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -211,6 +211,13 @@ static void playing_time(void) plugin_load(PLUGIN_APPS_DIR"/playing_time.rock", NULL); } +#ifdef HAVE_ALBUMART +static void view_album_art(void) +{ + plugin_load(VIEWERS_DIR"/imageviewer.rock", NULL); +} +#endif + MENUITEM_FUNCTION(wps_view_cur_playlist_item, 0, ID2P(LANG_VIEW_DYNAMIC_PLAYLIST), wps_view_cur_playlist, NULL, Icon_NOICON); MENUITEM_FUNCTION(search_playlist_item, 0, ID2P(LANG_SEARCH_IN_PLAYLIST), @@ -705,6 +712,10 @@ MENUITEM_FUNCTION(browse_id3_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_MENU_SHOW_I MENUITEM_FUNCTION(pitch_screen_item, 0, ID2P(LANG_PITCH), gui_syncpitchscreen_run, NULL, Icon_Audio); #endif +#ifdef HAVE_ALBUMART +MENUITEM_FUNCTION(view_album_art_item, 0, ID2P(LANG_VIEW_ALBUMART), + view_album_art, NULL, Icon_NOICON); +#endif static int clipboard_delete_selected_fileobject(void) { @@ -1027,6 +1038,9 @@ MAKE_ONPLAYMENU( wps_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE), &delete_file_item, &view_cue_item, #ifdef HAVE_PITCHCONTROL &pitch_screen_item, +#endif +#ifdef HAVE_ALBUMART + &view_album_art_item, #endif ); diff --git a/apps/plugins/imageviewer/bmp/bmp.c b/apps/plugins/imageviewer/bmp/bmp.c index f7e55dbe62..019c4982d3 100644 --- a/apps/plugins/imageviewer/bmp/bmp.c +++ b/apps/plugins/imageviewer/bmp/bmp.c @@ -100,8 +100,10 @@ static int img_mem(int ds) } static int load_image(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size) + unsigned char *buf, ssize_t *buf_size, + int offset, int filesize) { + (void)filesize; int w, h; /* used to center output */ long time; /* measured ticks */ int fd; @@ -127,6 +129,11 @@ static int load_image(char *filename, struct image_info *info, rb->splashf(HZ, "err opening %s: %d", filename, fd); return PLUGIN_ERROR; } + if (offset) + { + rb->lseek(fd, offset, SEEK_SET); + } + int ds = 1; /* check size of image needed to load image. */ size = scaled_read_bmp_fd(fd, &bmp, 0, format | FORMAT_RETURN_SIZE, cformat); diff --git a/apps/plugins/imageviewer/gif/gif.c b/apps/plugins/imageviewer/gif/gif.c index 0521c29e3a..61ff1a6146 100644 --- a/apps/plugins/imageviewer/gif/gif.c +++ b/apps/plugins/imageviewer/gif/gif.c @@ -76,8 +76,11 @@ static int img_mem(int ds) } static int load_image(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size) + unsigned char *buf, ssize_t *buf_size, + int offset, int filesize) { + (void)offset;(void)filesize; + int w, h; long time = 0; /* measured ticks */ struct gif_decoder *p_decoder = &decoder; diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c index ba5f8fec16..77286bd37d 100644 --- a/apps/plugins/imageviewer/imageviewer.c +++ b/apps/plugins/imageviewer/imageviewer.c @@ -838,16 +838,12 @@ static void get_view(struct image_info *info, int *p_cx, int *p_cy) } /* load, decode, display the image */ -static int load_and_show(char* filename, struct image_info *info) +static int load_and_show(char *filename, struct image_info *info, + int offset, int filesize, int status) { - int status; int cx, cy; ssize_t remaining; - rb->lcd_clear_display(); - - /* suppress warning while running slideshow */ - status = get_image_type(filename, iv_api.running_slideshow); if (status == IMAGE_UNKNOWN) { /* file isn't supported image file, skip this. */ file_pt[curfile] = NULL; @@ -855,6 +851,8 @@ static int load_and_show(char* filename, struct image_info *info) } reload_decoder: + rb->lcd_clear_display(); + if (image_type != status) /* type of image is changed, load decoder. */ { struct loader_info loader_info = { @@ -881,11 +879,10 @@ reload_decoder: if (rb->button_get(false) == IMGVIEW_MENU) status = PLUGIN_ABORT; else - status = imgdec->load_image(filename, info, buf, &remaining); + status = imgdec->load_image(filename, info, buf, &remaining, offset, filesize); if (status == PLUGIN_JPEG_PROGRESSIVE) { - rb->lcd_clear_display(); status = IMAGE_JPEG_PROGRESSIVE; goto reload_decoder; } @@ -1035,6 +1032,47 @@ reload_decoder: return status; } +static bool find_album_art(int *offset, int *filesize, int *status) +{ +#ifndef HAVE_ALBUMART + (void)offset;(void)filesize;(void)status; + return false; +#else + struct mp3entry *current_track = rb->audio_current_track(); + + if (current_track == NULL) + { + return false; + } + + switch (current_track->albumart.type) + { + case AA_TYPE_BMP: + (*status) = IMAGE_BMP; + break; + case AA_TYPE_PNG: + (*status) = IMAGE_PNG; + break; + case AA_TYPE_JPG: + (*status) = IMAGE_JPEG; + break; + default: + if (rb->search_albumart_files(current_track, "", np_file, MAX_PATH)) + { + (*status) = get_image_type(np_file, false); + return true; + } else + { + return false; + } + } + rb->strcpy(np_file, current_track->path); + (*offset) = current_track->albumart.pos; + (*filesize) = current_track->albumart.size; + return true; +#endif +} + /******************** Plugin entry point *********************/ enum plugin_status plugin_start(const void* parameter) @@ -1044,13 +1082,28 @@ enum plugin_status plugin_start(const void* parameter) long greysize; /* helper */ #endif - if(!parameter) {rb->splash(HZ*2, "No file"); return PLUGIN_ERROR; } + int offset = 0, filesize = 0, status; - rb->strcpy(np_file, parameter); - if (get_image_type(np_file, false) == IMAGE_UNKNOWN) + bool is_album_art = false; + if (!parameter) { - rb->splash(HZ*2, "Unsupported file"); - return PLUGIN_ERROR; + if (!find_album_art(&offset, &filesize, &status)) + { + rb->splash(HZ * 2, "No file"); + return PLUGIN_ERROR; + } + + entries = 1; + is_album_art = true; + } + else + { + rb->strcpy(np_file, parameter); + if ((status = get_image_type(np_file, false)) == IMAGE_UNKNOWN) + { + rb->splash(HZ * 2, "Unsupported file"); + return PLUGIN_ERROR; + } } #ifdef USE_PLUG_BUF @@ -1060,7 +1113,10 @@ enum plugin_status plugin_start(const void* parameter) buf = rb->plugin_get_audio_buffer(&buf_size); #endif - get_pic_list(); + if(!is_album_art) + { + get_pic_list(); + } #ifdef USEGSLIB if (!grey_init(buf, buf_size, GREY_ON_COP, @@ -1100,8 +1156,18 @@ enum plugin_status plugin_start(const void* parameter) do { - condition = load_and_show(np_file, &image_info); - } while (condition >= PLUGIN_OTHER); + condition = load_and_show(np_file, &image_info, offset, filesize, status); + if (condition >= PLUGIN_OTHER) + { + if(!is_album_art) + { + /* suppress warning while running slideshow */ + status = get_image_type(np_file, iv_api.running_slideshow); + } + continue; + } + break; + } while (true); release_decoder(); if (rb->memcmp(&settings, &old_settings, sizeof (settings))) diff --git a/apps/plugins/imageviewer/imageviewer.h b/apps/plugins/imageviewer/imageviewer.h index 44e56c0696..79691f747e 100644 --- a/apps/plugins/imageviewer/imageviewer.h +++ b/apps/plugins/imageviewer/imageviewer.h @@ -126,7 +126,7 @@ struct image_decoder { * size of buf after load image. it is used to calculate min downscale. * return PLUGIN_ERROR for error. ui will skip to next image. */ int (*load_image)(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size); + unsigned char *buf, ssize_t *buf_size, int offset, int filesize); /* downscale loaded image by ds. use the buffer passed to load_image to * reszie image and/or store resized image. * return PLUGIN_ERROR for error. ui will skip to next image. */ diff --git a/apps/plugins/imageviewer/jpeg/jpeg.c b/apps/plugins/imageviewer/jpeg/jpeg.c index c231209beb..c7969c10c9 100644 --- a/apps/plugins/imageviewer/jpeg/jpeg.c +++ b/apps/plugins/imageviewer/jpeg/jpeg.c @@ -110,10 +110,10 @@ static int img_mem(int ds) } static int load_image(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size) + unsigned char *buf, ssize_t *buf_size, + int offset, int filesize) { int fd; - int filesize; unsigned char* buf_jpeg; /* compressed JPEG image */ int status; struct jpeg *p_jpg = &jpg; @@ -127,7 +127,15 @@ static int load_image(char *filename, struct image_info *info, rb->splashf(HZ, "err opening %s: %d", filename, fd); return PLUGIN_ERROR; } - filesize = rb->filesize(fd); + + if (offset) + { + rb->lseek(fd, offset, SEEK_SET); + } + else + { + filesize = rb->filesize(fd); + } /* allocate JPEG buffer */ buf_jpeg = buf; diff --git a/apps/plugins/imageviewer/jpegp/jpegp.c b/apps/plugins/imageviewer/jpegp/jpegp.c index bb7be314f1..88edc7e8f3 100644 --- a/apps/plugins/imageviewer/jpegp/jpegp.c +++ b/apps/plugins/imageviewer/jpegp/jpegp.c @@ -96,8 +96,10 @@ static void scaled_dequantization_and_idct(void) } static int load_image(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size) + unsigned char *buf, ssize_t *buf_size, + int offset, int filesize) { + (void)filesize; int status; struct JPEGD *p_jpg = &jpg; @@ -110,6 +112,10 @@ static int load_image(char *filename, struct image_info *info, { return PLUGIN_ERROR; } + if (offset) + { + POS(offset); + } if (!iv->running_slideshow) { diff --git a/apps/plugins/imageviewer/png/png.c b/apps/plugins/imageviewer/png/png.c index 29b6713585..34a8a1fd34 100644 --- a/apps/plugins/imageviewer/png/png.c +++ b/apps/plugins/imageviewer/png/png.c @@ -89,7 +89,8 @@ static int img_mem(int ds) } static int load_image(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size) + unsigned char *buf, ssize_t *buf_size, + int offset, int file_size) { int fd; long time = 0; /* measured ticks */ @@ -97,7 +98,7 @@ static int load_image(char *filename, struct image_info *info, LodePNG_Decoder *p_decoder = &decoder; unsigned char *memory, *memory_max, *image; - size_t memory_size, file_size; + size_t memory_size; /* cleanup */ memset(&disp, 0, sizeof(disp)); @@ -113,7 +114,15 @@ static int load_image(char *filename, struct image_info *info, rb->splashf(HZ, "err opening %s: %d", filename, fd); return PLUGIN_ERROR; } - file_size = rb->filesize(fd); + + if (offset) + { + rb->lseek(fd, offset, SEEK_SET); + } + else + { + file_size = rb->filesize(fd); + } DEBUGF("reading file '%s'\n", filename); @@ -122,7 +131,7 @@ static int load_image(char *filename, struct image_info *info, rb->lcd_update(); } - if (file_size > memory_size) { + if ((size_t)file_size > memory_size) { p_decoder->error = FILE_TOO_LARGE; rb->close(fd); diff --git a/apps/plugins/imageviewer/ppm/ppm.c b/apps/plugins/imageviewer/ppm/ppm.c index 5e03f8c335..6f59b1f6b0 100644 --- a/apps/plugins/imageviewer/ppm/ppm.c +++ b/apps/plugins/imageviewer/ppm/ppm.c @@ -75,7 +75,8 @@ static int img_mem(int ds) } static int load_image(char *filename, struct image_info *info, - unsigned char *buf, ssize_t *buf_size) + unsigned char *buf, ssize_t *buf_size, + int offset, int filesize) { int fd; int rc = PLUGIN_OK; @@ -83,7 +84,7 @@ static int load_image(char *filename, struct image_info *info, int w, h; /* used to center output */ unsigned char *memory, *memory_max; - size_t memory_size, file_size; + size_t memory_size; /* cleanup */ memset(&disp, 0, sizeof(disp)); @@ -100,13 +101,20 @@ static int load_image(char *filename, struct image_info *info, return PLUGIN_ERROR; } - file_size = rb->filesize(fd); + if (offset) + { + rb->lseek(fd, offset, SEEK_SET); + } + else + { + filesize = rb->filesize(fd); + } DEBUGF("reading file '%s'\n", filename); if (!iv->running_slideshow) { rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); - rb->lcd_putsf(0, 1, "loading %zu bytes", file_size); + rb->lcd_putsf(0, 1, "loading %zu bytes", filesize); rb->lcd_update(); } -- cgit v1.2.3