1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Roman Artiukhin 2024-10-14 21:33:40 +03:00 committed by Christian Soffke
parent c1bcebd998
commit 55a5bfe740
10 changed files with 166 additions and 31 deletions

View file

@ -16567,3 +16567,17 @@
*: "Remaining" *: "Remaining"
</voice> </voice>
</phrase> </phrase>
<phrase>
id: LANG_VIEW_ALBUMART
desc: WPS context menu
user: core
<source>
*: "View Album Art"
</source>
<dest>
*: "View Album Art"
</dest>
<voice>
*: "View Album Art"
</voice>
</phrase>

View file

@ -211,6 +211,13 @@ static void playing_time(void)
plugin_load(PLUGIN_APPS_DIR"/playing_time.rock", NULL); 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), MENUITEM_FUNCTION(wps_view_cur_playlist_item, 0, ID2P(LANG_VIEW_DYNAMIC_PLAYLIST),
wps_view_cur_playlist, NULL, Icon_NOICON); wps_view_cur_playlist, NULL, Icon_NOICON);
MENUITEM_FUNCTION(search_playlist_item, 0, ID2P(LANG_SEARCH_IN_PLAYLIST), 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), MENUITEM_FUNCTION(pitch_screen_item, 0, ID2P(LANG_PITCH),
gui_syncpitchscreen_run, NULL, Icon_Audio); gui_syncpitchscreen_run, NULL, Icon_Audio);
#endif #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) 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, &delete_file_item, &view_cue_item,
#ifdef HAVE_PITCHCONTROL #ifdef HAVE_PITCHCONTROL
&pitch_screen_item, &pitch_screen_item,
#endif
#ifdef HAVE_ALBUMART
&view_album_art_item,
#endif #endif
); );

View file

@ -100,8 +100,10 @@ static int img_mem(int ds)
} }
static int load_image(char *filename, struct image_info *info, 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 */ int w, h; /* used to center output */
long time; /* measured ticks */ long time; /* measured ticks */
int fd; 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); rb->splashf(HZ, "err opening %s: %d", filename, fd);
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
if (offset)
{
rb->lseek(fd, offset, SEEK_SET);
}
int ds = 1; int ds = 1;
/* check size of image needed to load image. */ /* check size of image needed to load image. */
size = scaled_read_bmp_fd(fd, &bmp, 0, format | FORMAT_RETURN_SIZE, cformat); size = scaled_read_bmp_fd(fd, &bmp, 0, format | FORMAT_RETURN_SIZE, cformat);

View file

@ -76,8 +76,11 @@ static int img_mem(int ds)
} }
static int load_image(char *filename, struct image_info *info, 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; int w, h;
long time = 0; /* measured ticks */ long time = 0; /* measured ticks */
struct gif_decoder *p_decoder = &decoder; struct gif_decoder *p_decoder = &decoder;

View file

@ -838,16 +838,12 @@ static void get_view(struct image_info *info, int *p_cx, int *p_cy)
} }
/* load, decode, display the image */ /* 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; int cx, cy;
ssize_t remaining; 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) { if (status == IMAGE_UNKNOWN) {
/* file isn't supported image file, skip this. */ /* file isn't supported image file, skip this. */
file_pt[curfile] = NULL; file_pt[curfile] = NULL;
@ -855,6 +851,8 @@ static int load_and_show(char* filename, struct image_info *info)
} }
reload_decoder: reload_decoder:
rb->lcd_clear_display();
if (image_type != status) /* type of image is changed, load decoder. */ if (image_type != status) /* type of image is changed, load decoder. */
{ {
struct loader_info loader_info = { struct loader_info loader_info = {
@ -881,11 +879,10 @@ reload_decoder:
if (rb->button_get(false) == IMGVIEW_MENU) if (rb->button_get(false) == IMGVIEW_MENU)
status = PLUGIN_ABORT; status = PLUGIN_ABORT;
else else
status = imgdec->load_image(filename, info, buf, &remaining); status = imgdec->load_image(filename, info, buf, &remaining, offset, filesize);
if (status == PLUGIN_JPEG_PROGRESSIVE) if (status == PLUGIN_JPEG_PROGRESSIVE)
{ {
rb->lcd_clear_display();
status = IMAGE_JPEG_PROGRESSIVE; status = IMAGE_JPEG_PROGRESSIVE;
goto reload_decoder; goto reload_decoder;
} }
@ -1035,6 +1032,47 @@ reload_decoder:
return status; 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 *********************/ /******************** Plugin entry point *********************/
enum plugin_status plugin_start(const void* parameter) enum plugin_status plugin_start(const void* parameter)
@ -1044,13 +1082,28 @@ enum plugin_status plugin_start(const void* parameter)
long greysize; /* helper */ long greysize; /* helper */
#endif #endif
if(!parameter) {rb->splash(HZ*2, "No file"); return PLUGIN_ERROR; } int offset = 0, filesize = 0, status;
rb->strcpy(np_file, parameter); bool is_album_art = false;
if (get_image_type(np_file, false) == IMAGE_UNKNOWN) if (!parameter)
{ {
rb->splash(HZ*2, "Unsupported file"); if (!find_album_art(&offset, &filesize, &status))
return PLUGIN_ERROR; {
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 #ifdef USE_PLUG_BUF
@ -1060,7 +1113,10 @@ enum plugin_status plugin_start(const void* parameter)
buf = rb->plugin_get_audio_buffer(&buf_size); buf = rb->plugin_get_audio_buffer(&buf_size);
#endif #endif
get_pic_list(); if(!is_album_art)
{
get_pic_list();
}
#ifdef USEGSLIB #ifdef USEGSLIB
if (!grey_init(buf, buf_size, GREY_ON_COP, if (!grey_init(buf, buf_size, GREY_ON_COP,
@ -1100,8 +1156,18 @@ enum plugin_status plugin_start(const void* parameter)
do do
{ {
condition = load_and_show(np_file, &image_info); condition = load_and_show(np_file, &image_info, offset, filesize, status);
} while (condition >= PLUGIN_OTHER); 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(); release_decoder();
if (rb->memcmp(&settings, &old_settings, sizeof (settings))) if (rb->memcmp(&settings, &old_settings, sizeof (settings)))

View file

@ -126,7 +126,7 @@ struct image_decoder {
* size of buf after load image. it is used to calculate min downscale. * size of buf after load image. it is used to calculate min downscale.
* return PLUGIN_ERROR for error. ui will skip to next image. */ * return PLUGIN_ERROR for error. ui will skip to next image. */
int (*load_image)(char *filename, struct image_info *info, 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 /* downscale loaded image by ds. use the buffer passed to load_image to
* reszie image and/or store resized image. * reszie image and/or store resized image.
* return PLUGIN_ERROR for error. ui will skip to next image. */ * return PLUGIN_ERROR for error. ui will skip to next image. */

View file

@ -110,10 +110,10 @@ static int img_mem(int ds)
} }
static int load_image(char *filename, struct image_info *info, 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 fd;
int filesize;
unsigned char* buf_jpeg; /* compressed JPEG image */ unsigned char* buf_jpeg; /* compressed JPEG image */
int status; int status;
struct jpeg *p_jpg = &jpg; 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); rb->splashf(HZ, "err opening %s: %d", filename, fd);
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
filesize = rb->filesize(fd);
if (offset)
{
rb->lseek(fd, offset, SEEK_SET);
}
else
{
filesize = rb->filesize(fd);
}
/* allocate JPEG buffer */ /* allocate JPEG buffer */
buf_jpeg = buf; buf_jpeg = buf;

View file

@ -96,8 +96,10 @@ static void scaled_dequantization_and_idct(void)
} }
static int load_image(char *filename, struct image_info *info, 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; int status;
struct JPEGD *p_jpg = &jpg; struct JPEGD *p_jpg = &jpg;
@ -110,6 +112,10 @@ static int load_image(char *filename, struct image_info *info,
{ {
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
if (offset)
{
POS(offset);
}
if (!iv->running_slideshow) if (!iv->running_slideshow)
{ {

View file

@ -89,7 +89,8 @@ static int img_mem(int ds)
} }
static int load_image(char *filename, struct image_info *info, 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; int fd;
long time = 0; /* measured ticks */ long time = 0; /* measured ticks */
@ -97,7 +98,7 @@ static int load_image(char *filename, struct image_info *info,
LodePNG_Decoder *p_decoder = &decoder; LodePNG_Decoder *p_decoder = &decoder;
unsigned char *memory, *memory_max, *image; unsigned char *memory, *memory_max, *image;
size_t memory_size, file_size; size_t memory_size;
/* cleanup */ /* cleanup */
memset(&disp, 0, sizeof(disp)); 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); rb->splashf(HZ, "err opening %s: %d", filename, fd);
return PLUGIN_ERROR; 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); DEBUGF("reading file '%s'\n", filename);
@ -122,7 +131,7 @@ static int load_image(char *filename, struct image_info *info,
rb->lcd_update(); rb->lcd_update();
} }
if (file_size > memory_size) { if ((size_t)file_size > memory_size) {
p_decoder->error = FILE_TOO_LARGE; p_decoder->error = FILE_TOO_LARGE;
rb->close(fd); rb->close(fd);

View file

@ -75,7 +75,8 @@ static int img_mem(int ds)
} }
static int load_image(char *filename, struct image_info *info, 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 fd;
int rc = PLUGIN_OK; 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 */ int w, h; /* used to center output */
unsigned char *memory, *memory_max; unsigned char *memory, *memory_max;
size_t memory_size, file_size; size_t memory_size;
/* cleanup */ /* cleanup */
memset(&disp, 0, sizeof(disp)); memset(&disp, 0, sizeof(disp));
@ -100,13 +101,20 @@ static int load_image(char *filename, struct image_info *info,
return PLUGIN_ERROR; 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); DEBUGF("reading file '%s'\n", filename);
if (!iv->running_slideshow) if (!iv->running_slideshow)
{ {
rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); 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(); rb->lcd_update();
} }