From b090f856207c7b3d68c8dafc1b74d1e59b604bfc Mon Sep 17 00:00:00 2001 From: zoltanvb <101990835+zoltanvb@users.noreply.github.com> Date: Thu, 25 Jul 2024 03:31:41 +0200 Subject: [PATCH] Support for non-PNG local thumbnails (#16806) Allow thumbnails (boxart, title, screenshot) to be loaded in any other supported format as well, currently jpg, bmp, tga. Support is for local thumbnails only, downloads are not changed. PNG format is always preferred. Menu option added for control, since trying for multiple thumbnail files may impact performance on slow storage media. --- config.def.h | 2 ++ configuration.c | 1 + configuration.h | 1 + gfx/gfx_thumbnail_path.c | 39 ++++++++++++++++++++++++++++++++++-- intl/msg_hash_us.h | 10 ++++++++- menu/cbs/menu_cbs_sublabel.c | 4 ++++ menu/menu_displaylist.c | 1 + menu/menu_setting.c | 16 +++++++++++++++ msg_hash.h | 1 + 9 files changed, 72 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index df67372ef1..0ee0c31948 100644 --- a/config.def.h +++ b/config.def.h @@ -1511,6 +1511,8 @@ #define DEFAULT_PLAYLIST_USE_FILENAME false +#define DEFAULT_PLAYLIST_ALLOW_NON_PNG false + /* Show Menu start-up screen on boot. */ #define DEFAULT_MENU_SHOW_START_SCREEN true diff --git a/configuration.c b/configuration.c index 1784d7d2f6..8141d0af3f 100644 --- a/configuration.c +++ b/configuration.c @@ -2155,6 +2155,7 @@ static struct config_bool_setting *populate_settings_bool( SETTING_BOOL("playlist_fuzzy_archive_match", &settings->bools.playlist_fuzzy_archive_match, true, DEFAULT_PLAYLIST_FUZZY_ARCHIVE_MATCH, false); SETTING_BOOL("playlist_portable_paths", &settings->bools.playlist_portable_paths, true, DEFAULT_PLAYLIST_PORTABLE_PATHS, false); SETTING_BOOL("playlist_use_filename", &settings->bools.playlist_use_filename, true, DEFAULT_PLAYLIST_USE_FILENAME, false); + SETTING_BOOL("playlist_allow_non_png", &settings->bools.playlist_allow_non_png, true, DEFAULT_PLAYLIST_ALLOW_NON_PNG, false); SETTING_BOOL("frame_time_counter_reset_after_fastforwarding", &settings->bools.frame_time_counter_reset_after_fastforwarding, true, false, false); SETTING_BOOL("frame_time_counter_reset_after_load_state", &settings->bools.frame_time_counter_reset_after_load_state, true, false, false); diff --git a/configuration.h b/configuration.h index 9cdad7e245..91ed43a4d2 100644 --- a/configuration.h +++ b/configuration.h @@ -1053,6 +1053,7 @@ typedef struct settings bool playlist_fuzzy_archive_match; bool playlist_portable_paths; bool playlist_use_filename; + bool playlist_allow_non_png; bool quit_press_twice; bool vibrate_on_keypress; diff --git a/gfx/gfx_thumbnail_path.c b/gfx/gfx_thumbnail_path.c index 3fd0431135..ec55766673 100644 --- a/gfx/gfx_thumbnail_path.c +++ b/gfx/gfx_thumbnail_path.c @@ -573,6 +573,9 @@ bool gfx_thumbnail_update_path( const char *system_name = NULL; char *thumbnail_path = NULL; const char *dir_thumbnails = NULL; + /* Thumbnail extension order. The default (i.e. png) is always the first. */ + #define MAX_SUPPORTED_THUMBNAIL_EXTENSIONS 5 + const char* const SUPPORTED_THUMBNAIL_EXTENSIONS[] = { ".png", ".jpg", ".jpeg", ".bmp", ".tga", 0 }; if (!path_data) return false; @@ -648,6 +651,8 @@ bool gfx_thumbnail_update_path( char tmp_buf[PATH_MAX_LENGTH]; const char *type = gfx_thumbnail_get_type(settings, path_data, thumbnail_id); + int i; + bool thumbnail_found = false; /* > Normal content: assemble path */ /* >> Base + system name */ @@ -663,19 +668,49 @@ bool gfx_thumbnail_update_path( fill_pathname_join_special(thumbnail_path, tmp_buf, path_data->content_img_full, PATH_MAX_LENGTH * sizeof(char)); } + thumbnail_found = path_is_valid(thumbnail_path); + + /* Try alternative file extensions in turn, if wanted */ + for( i=1 ; + settings->bools.playlist_allow_non_png && + !thumbnail_found && + thumbnail_path[0]!='\0' && + i> Add content image - second try with label (database name) */ - if(!path_is_valid(thumbnail_path) && path_data->content_img[0] != '\0') + if(!thumbnail_found && path_data->content_img[0] != '\0') { thumbnail_path[0] = '\0'; fill_pathname_join_special(thumbnail_path, tmp_buf, path_data->content_img, PATH_MAX_LENGTH * sizeof(char)); + thumbnail_found = path_is_valid(thumbnail_path); + } + for( i=1 ; + settings->bools.playlist_allow_non_png && + !thumbnail_found && + i> Add content image - third try with shortened name (title only) */ - if(!path_is_valid(thumbnail_path) && path_data->content_img_short[0] != '\0') + if(!thumbnail_found && path_data->content_img_short[0] != '\0') { thumbnail_path[0] = '\0'; fill_pathname_join_special(thumbnail_path, tmp_buf, path_data->content_img_short, PATH_MAX_LENGTH * sizeof(char)); + thumbnail_found = path_is_valid(thumbnail_path); + } + for( i=1 ; + settings->bools.playlist_allow_non_png && + !thumbnail_found && + ibools.playlist_allow_non_png, + MENU_ENUM_LABEL_PLAYLIST_ALLOW_NON_PNG, + MENU_ENUM_LABEL_VALUE_PLAYLIST_ALLOW_NON_PNG, + DEFAULT_PLAYLIST_ALLOW_NON_PNG, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE + ); + #if defined(HAVE_OZONE) || defined(HAVE_XMB) if (string_is_equal(settings->arrays.menu_driver, "ozone") || string_is_equal(settings->arrays.menu_driver, "xmb")) diff --git a/msg_hash.h b/msg_hash.h index d6486beda2..a4e4472054 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -4134,6 +4134,7 @@ enum msg_hash_enums MENU_LABEL(PLAYLIST_SUBLABEL_LAST_PLAYED_STYLE), MENU_LABEL(PLAYLIST_PORTABLE_PATHS), MENU_LABEL(PLAYLIST_USE_FILENAME), + MENU_LABEL(PLAYLIST_ALLOW_NON_PNG), MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_HIST_FAV, MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_ALWAYS,