diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-12-04 16:20:14 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-12-04 16:20:14 +0100 |
commit | 15f5c9a1433bccf8a85a12713079c0aad0650dfa (patch) | |
tree | 4ff36c95e66951c55031e69e37de632a4e03ecf1 /src | |
parent | c71b04dad549ceaa9e06d524bc2ca11034dd1dbf (diff) |
Support bmp and avif
Diffstat (limited to 'src')
-rw-r--r-- | src/AsyncImageLoader.cpp | 8 | ||||
-rw-r--r-- | src/FileAnalyzer.cpp | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index 0ddc10c..8b8c5f6 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -26,7 +26,7 @@ #pragma GCC diagnostic pop namespace QuickMedia { - static bool webp_to_png(const Path &thumbnail_path, const Path &destination_path) { + static bool ffmpeg_image_to_png(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; } @@ -34,10 +34,10 @@ namespace QuickMedia { bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, mgl::vec2i resize_target_size, ContentType content_type) { Path input_path = thumbnail_path; - if(content_type == ContentType::IMAGE_WEBP) { + 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(!webp_to_png(thumbnail_path, result_path_tmp)) + if(!ffmpeg_image_to_png(thumbnail_path, result_path_tmp)) return false; input_path = std::move(result_path_tmp); } @@ -69,7 +69,7 @@ namespace QuickMedia { result_path_tmp.append(".tmp.png"); if(image.get_size().x <= resize_target_size.x && image.get_size().y <= resize_target_size.y) { - if(content_type == ContentType::IMAGE_WEBP) { + if(content_type == ContentType::IMAGE_WEBP || content_type == ContentType::IMAGE_AVIF) { if(rename_atomic(input_path.data.c_str(), thumbnail_path_resized.data.c_str()) == 0) _exit(0); else diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp index 61eff7b..9efdc52 100644 --- a/src/FileAnalyzer.cpp +++ b/src/FileAnalyzer.cpp @@ -21,7 +21,7 @@ namespace QuickMedia { // https://mimesniff.spec.whatwg.org/ // TODO: Test all of these - static const std::array<MagicNumber, 33> magic_numbers = { + static const std::array<MagicNumber, 34> magic_numbers = { MagicNumber{ {'R', 'I', 'F', 'F', -1, -1, -1, -1, 'A', 'V', 'I', ' '}, 12, ContentType::VIDEO_AVI }, MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'p', 'i', 's', 'o', 'm'}, 12, ContentType::VIDEO_MP4 }, MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'p', 'i', 's', 'o', '5'}, 12, ContentType::VIDEO_MP4 }, @@ -32,6 +32,7 @@ namespace QuickMedia { MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'm', 'p', '4', '2'}, 11, ContentType::VIDEO_MP4 }, MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', '3', 'g', 'p', '5'}, 11, ContentType::VIDEO_MP4 }, MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'p', 'q', 't'}, 10, ContentType::VIDEO_MP4 }, + MagicNumber{ {0x00, 0x00, 0x00, -1, 'f', 't', 'y', 'p', 'a', 'v', 'i', 'f'}, 12, ContentType::IMAGE_AVIF }, MagicNumber{ {0x00, 0x00, 0x01, 0xBA}, 4, ContentType::VIDEO_MPEG }, MagicNumber{ {0x00, 0x00, 0x01, 0xB3}, 4, ContentType::VIDEO_MPEG }, MagicNumber{ {0x1A, 0x45, 0xDF, 0xA3}, 4, ContentType::VIDEO_WEBM }, @@ -91,6 +92,7 @@ namespace QuickMedia { case ContentType::IMAGE_PNG: return "image/png"; case ContentType::IMAGE_GIF: return "image/gif"; case ContentType::IMAGE_BMP: return "image/bmp"; + case ContentType::IMAGE_AVIF: return "image/avif"; case ContentType::IMAGE_WEBP: return "image/webp"; } return "application/octet-stream"; @@ -101,7 +103,9 @@ namespace QuickMedia { || strcase_equals(ext, ".jpeg") || strcase_equals(ext, ".png") || strcase_equals(ext, ".gif") - || strcase_equals(ext, ".webp"); + || strcase_equals(ext, ".webp") + || strcase_equals(ext, ".bmp") + || strcase_equals(ext, ".avif"); } bool is_video_ext(const char *ext) { |