Skip to content

Commit

Permalink
Add possibility to set a webp decoding function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martincapello committed Oct 9, 2024
1 parent acb17f4 commit 57c2646
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions os/dnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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
2 changes: 2 additions & 0 deletions os/dnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion os/win/dnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 57c2646

Please sign in to comment.