Skip to content

Commit

Permalink
Thumbnail fixes (libretro#16062)
Browse files Browse the repository at this point in the history
* Minor thumbnail improvements

- set standard name if only one entry is in the playlist
- use first database name for thumbnails if core has multiple

* Fix playlist thumbnail downloader

Playlist thumbnail downloader function was missed from the flexible
thumbnail name update, now it is added.
  • Loading branch information
zoltanvb authored and Sunderland93 committed Dec 26, 2024
1 parent f2c54aa commit 4331b38
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
17 changes: 13 additions & 4 deletions gfx/gfx_thumbnail_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,19 @@ bool gfx_thumbnail_set_content_playlist(
{
char *db_name_no_ext = NULL;
char tmp_buf[PATH_MAX_LENGTH];
/* Remove .lpl extension
* > path_remove_extension() requires a char * (not const)
* so have to use a temporary buffer... */
strlcpy(tmp_buf, db_name, sizeof(tmp_buf));
const char* pos = strchr(db_name, '|');

if (pos && (size_t) (pos - db_name)+1 < sizeof(tmp_buf)) {
/* If db_name comes from core info, and there are multiple
* databases mentioned separated by |, use only first one */
strlcpy(tmp_buf, db_name, (size_t) (pos - db_name)+1);
}
else {
/* Remove .lpl extension
* > path_remove_extension() requires a char * (not const)
* so have to use a temporary buffer... */
strlcpy(tmp_buf, db_name, sizeof(tmp_buf));
}
db_name_no_ext = path_remove_extension(tmp_buf);

if (!string_is_empty(db_name_no_ext))
Expand Down
5 changes: 5 additions & 0 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,11 @@ enum playlist_thumbnail_name_flags playlist_get_next_thumbnail_name_flag(playlis
return PLAYLIST_THUMBNAIL_FLAG_SHORT_NAME;
if (entry->thumbnail_flags & PLAYLIST_THUMBNAIL_FLAG_FULL_NAME)
return PLAYLIST_THUMBNAIL_FLAG_STD_NAME;
/* Special case: only one entry in playlist, only one query is possible
* as flag swapping relies on going back and forth among entries
* so just use the most likely version here */
if (idx == 0 && RBUF_LEN(playlist->entries) == 1)
return PLAYLIST_THUMBNAIL_FLAG_STD_NAME;
return PLAYLIST_THUMBNAIL_FLAG_FULL_NAME;
}

Expand Down
28 changes: 20 additions & 8 deletions tasks/task_pl_thumbnail_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ static void free_pl_thumb_handle(pl_thumb_handle_t *pl_thumb)
static void task_pl_thumbnail_download_handler(retro_task_t *task)
{
pl_thumb_handle_t *pl_thumb = NULL;

enum playlist_thumbnail_name_flags next_flag = PLAYLIST_THUMBNAIL_FLAG_INVALID;

if (!task)
goto task_finished;

Expand Down Expand Up @@ -421,6 +422,8 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task)
/* Start iterating over thumbnail type */
pl_thumb->type_idx = 1;
pl_thumb->status = PL_THUMB_ITERATE_TYPE;
playlist_update_thumbnail_name_flag(pl_thumb->playlist, pl_thumb->list_index, PLAYLIST_THUMBNAIL_FLAG_FULL_NAME);
pl_thumb->name_flags = PLAYLIST_THUMBNAIL_FLAG_FULL_NAME;
}
else
{
Expand Down Expand Up @@ -450,13 +453,22 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task)
/* Check whether all thumbnail types have been processed */
if (pl_thumb->type_idx > 3)
{
/* Time to move on to the next entry */
pl_thumb->list_index++;
if (pl_thumb->list_index < pl_thumb->list_size)
pl_thumb->status = PL_THUMB_ITERATE_ENTRY;
else
pl_thumb->status = PL_THUMB_END;
break;
next_flag = playlist_get_next_thumbnail_name_flag(pl_thumb->playlist,pl_thumb->list_index);
if (next_flag == PLAYLIST_THUMBNAIL_FLAG_NONE) {
if (pl_thumb->playlist )
/* Time to move on to the next entry */
pl_thumb->list_index++;
if (pl_thumb->list_index < pl_thumb->list_size)
pl_thumb->status = PL_THUMB_ITERATE_ENTRY;
else
pl_thumb->status = PL_THUMB_END;
break;
} else {
/* Increment the name flag to cover the 3 supported naming conventions. */
pl_thumb->type_idx = 1;
playlist_update_thumbnail_name_flag(pl_thumb->playlist, pl_thumb->list_index, next_flag);
pl_thumb->name_flags = next_flag;
}
}

/* Download current thumbnail */
Expand Down

0 comments on commit 4331b38

Please sign in to comment.