From 57c2646afca729ced6ae61ecf3918746507c2642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Wed, 9 Oct 2024 16:19:37 -0300 Subject: [PATCH] Add possibility to set a webp decoding function Now a drag&drop operation in Windows can use this custom webp decoding function to decode the first frame of an element dropped as webp data. --- os/dnd.cpp | 11 +++++++++++ os/dnd.h | 2 ++ os/win/dnd.cpp | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/os/dnd.cpp b/os/dnd.cpp index 1b8155f43..db40729cc 100644 --- a/os/dnd.cpp +++ b/os/dnd.cpp @@ -19,6 +19,7 @@ static DecoderFunc g_decode_png = default_decode_png; static DecoderFunc g_decode_jpg = default_decode_jpg; static DecoderFunc g_decode_bmp = default_decode_bmp; static DecoderFunc g_decode_gif = default_decode_gif; +static DecoderFunc g_decode_webp = nullptr; void set_decode_png(DecoderFunc func) { @@ -40,6 +41,11 @@ void set_decode_gif(DecoderFunc func) g_decode_gif = func; } +void set_decode_webp(DecoderFunc func) +{ + g_decode_webp = func; +} + SurfaceRef decode_png(const uint8_t* buf, const uint32_t len) { return g_decode_png(buf, len); @@ -60,6 +66,11 @@ SurfaceRef decode_gif(const uint8_t* buf, const uint32_t len) return g_decode_gif(buf, len); } +SurfaceRef decode_webp(const uint8_t* buf, const uint32_t len) +{ + return g_decode_webp ? g_decode_webp(buf, len) : nullptr; +} + } // namespace os #endif \ No newline at end of file diff --git a/os/dnd.h b/os/dnd.h index 557c2fbad..62f0e8e32 100644 --- a/os/dnd.h +++ b/os/dnd.h @@ -36,11 +36,13 @@ namespace os { void set_decode_jpg(DecoderFunc func); void set_decode_bmp(DecoderFunc func); void set_decode_gif(DecoderFunc func); + void set_decode_webp(DecoderFunc func); SurfaceRef decode_png(const uint8_t* buf, uint32_t len); SurfaceRef decode_jpg(const uint8_t* buf, uint32_t len); SurfaceRef decode_bmp(const uint8_t* buf, uint32_t len); SurfaceRef decode_gif(const uint8_t* buf, uint32_t len); + SurfaceRef decode_webp(const uint8_t* buf, uint32_t len); #endif // Operations that can be supported by source and target windows in a drag // and drop operation. diff --git a/os/win/dnd.cpp b/os/win/dnd.cpp index 5af81407e..c17cfbb89 100644 --- a/os/win/dnd.cpp +++ b/os/win/dnd.cpp @@ -240,6 +240,9 @@ SurfaceRef DragDataProviderWin::getImage() if (ext == "BMP") return os::decode_bmp(content, content.size()); + + if (ext == "WEBP") + return os::decode_webp(content, content.size()); } } } @@ -303,7 +306,8 @@ bool DragDataProviderWin::contains(DragDataItemType type) std::string ext = base::get_file_extension(filename); std::transform(ext.begin(), ext.end(), ext.begin(), ::toupper); if (ext == "PNG" || ext == "JPG" || ext == "JPEG" || - ext == "JPE" || ext == "GIF" || ext == "BMP") + ext == "JPE" || ext == "GIF" || ext == "BMP" || + ext == "WEBP") return true; } }