From 09b44d9681eaf66670f77cbd440300cdc22f3df3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2024 09:48:37 +0200 Subject: Manga: convert webp images to png to make them viewable --- depends/mglpp | 2 +- include/AsyncImageLoader.hpp | 1 + src/AsyncImageLoader.cpp | 4 ++-- src/QuickMedia.cpp | 9 +++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/depends/mglpp b/depends/mglpp index fd15a69..8cb04e1 160000 --- a/depends/mglpp +++ b/depends/mglpp @@ -1 +1 @@ -Subproject commit fd15a6947741c997072df8b1ddf93cefc416c838 +Subproject commit 8cb04e1859588bb1fed003c369a9adb96c6c932a diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp index 672e0e6..7eed39e 100644 --- a/include/AsyncImageLoader.hpp +++ b/include/AsyncImageLoader.hpp @@ -38,6 +38,7 @@ namespace QuickMedia { mgl::vec2i resize_target_size; }; + bool ffmpeg_convert_image_format(const Path &thumbnail_path, const Path &destination_path); // If |symlink_if_no_resize| is false then a copy is made from |thumbnail_path| to |thumbnail_path_resized| instead of a symlink if |thumbnail_path| is not larger than |resize_target_size|. // One example of why you might not want a symlink is if |thumbnail_path| is a temporary file. bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, mgl::vec2i resize_target_size, ContentType content_type); diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index 1118ee6..14cfe6a 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -26,7 +26,7 @@ #pragma GCC diagnostic pop namespace QuickMedia { - static bool ffmpeg_image_to_png(const Path &thumbnail_path, const Path &destination_path) { + bool ffmpeg_convert_image_format(const Path &thumbnail_path, const Path &destination_path) { const char *args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", thumbnail_path.data.c_str(), "--", destination_path.data.c_str(), nullptr}; return exec_program(args, nullptr, nullptr) == 0; } @@ -37,7 +37,7 @@ namespace QuickMedia { if(content_type == ContentType::IMAGE_WEBP || content_type == ContentType::IMAGE_AVIF) { Path result_path_tmp = thumbnail_path_resized; result_path_tmp.append(".tmp.png"); - if(!ffmpeg_image_to_png(thumbnail_path, result_path_tmp)) + if(!ffmpeg_convert_image_format(thumbnail_path, result_path_tmp)) return false; input_path = std::move(result_path_tmp); } diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 648f231..332308b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -4230,6 +4230,15 @@ namespace QuickMedia { } } + { + FileAnalyzer file_analyzer; + if(file_analyzer.load_file(image_filepath_tmp.data.c_str(), false) && file_analyzer.get_content_type() == ContentType::IMAGE_WEBP) { + Path new_filepath = image_filepath_tmp.data + ".png"; + if(ffmpeg_convert_image_format(image_filepath_tmp, new_filepath)) + image_filepath_tmp = std::move(new_filepath); + } + } + bool rename_immediately = true; if(upscale_image_action == UpscaleImageAction::LOW_RESOLUTION) { int screen_width, screen_height; -- cgit v1.2.3