aboutsummaryrefslogtreecommitdiff
path: root/src/AsyncImageLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/AsyncImageLoader.cpp')
-rw-r--r--src/AsyncImageLoader.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index 34df062..6504992 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -1,5 +1,4 @@
#include "../include/AsyncImageLoader.hpp"
-#include "../include/FileAnalyzer.hpp"
#include "../include/DownloadUtils.hpp"
#include "../include/Program.hpp"
#include "../include/ImageUtils.hpp"
@@ -11,18 +10,34 @@
#include <assert.h>
namespace QuickMedia {
- bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, sf::Vector2i resize_target_size) {
+ bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, sf::Vector2i resize_target_size, ContentType content_type) {
+ Path input_path = thumbnail_path;
+
+ // TODO: Remove this when imagemagick supports webp
+ // Convert webp to png
+ if(content_type == ContentType::IMAGE_WEBP) {
+ Path result_path_tmp = input_path;
+ result_path_tmp.append(".tmp.png");
+
+ const char *args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", input_path.data.c_str(), "--", result_path_tmp.data.c_str(), nullptr};
+ int res = exec_program(args, nullptr, nullptr);
+ if(res != 0)
+ return false;
+
+ input_path = std::move(result_path_tmp);
+ }
+
// > is to only shrink image if smaller than the target size
std::string new_size = std::to_string(resize_target_size.x) + "x" + std::to_string(resize_target_size.y) + ">";
// We only want the first frame if its a gif
- Path thumbnail_path_first_frame = thumbnail_path;
+ Path thumbnail_path_first_frame = std::move(input_path);
thumbnail_path_first_frame.append("[0]");
Path result_path_tmp = thumbnail_path_resized;
result_path_tmp.append(".tmp");
- const char *args[] = { "convert", thumbnail_path_first_frame.data.c_str(), "-thumbnail", new_size.c_str(), result_path_tmp.data.c_str(), nullptr};
+ const char *args[] = { "convert", thumbnail_path_first_frame.data.c_str(), "-thumbnail", new_size.c_str(), result_path_tmp.data.c_str(), nullptr};
int convert_res = exec_program(args, nullptr, nullptr);
if(convert_res == 0 && rename_atomic(result_path_tmp.data.c_str(), thumbnail_path_resized.data.c_str()) == 0)
return true;
@@ -46,7 +61,7 @@ namespace QuickMedia {
return;
}
- if(create_thumbnail(thumbnail_path, thumbnail_path_resized, resize_target_size)) {
+ if(create_thumbnail(thumbnail_path, thumbnail_path_resized, resize_target_size, file_analyzer.get_content_type())) {
load_image_from_file(*thumbnail_data->image, thumbnail_path_resized.data);
} else {
load_image_from_file(*thumbnail_data->image, thumbnail_path.data);