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"
</voice>
</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);
}
#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
);

View file

@ -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);

View file

@ -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;

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 */
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,14 +1082,29 @@ 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;
bool is_album_art = false;
if (!parameter)
{
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 (get_image_type(np_file, false) == IMAGE_UNKNOWN)
if ((status = get_image_type(np_file, false)) == IMAGE_UNKNOWN)
{
rb->splash(HZ * 2, "Unsupported file");
return PLUGIN_ERROR;
}
}
#ifdef USE_PLUG_BUF
buf = rb->plugin_get_buffer(&buf_size);
@ -1060,7 +1113,10 @@ enum plugin_status plugin_start(const void* parameter)
buf = rb->plugin_get_audio_buffer(&buf_size);
#endif
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)))

View file

@ -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. */

View file

@ -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;
}
if (offset)
{
rb->lseek(fd, offset, SEEK_SET);
}
else
{
filesize = rb->filesize(fd);
}
/* allocate JPEG buffer */
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,
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)
{

View file

@ -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;
}
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);

View file

@ -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();
}