Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to set a webp decoding function #109

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading