mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 20:32:56 +03:00
Utilities: Add image decoding to headless-browser
With this, the headless browser can now decode images on its own!
This commit is contained in:
parent
355e74cf65
commit
f9d4c0ecbc
Notes:
sideshowbarker
2024-07-17 10:35:07 +09:00
Author: https://github.com/Dexesttp Commit: https://github.com/SerenityOS/serenity/commit/f9d4c0ecbc Pull-request: https://github.com/SerenityOS/serenity/pull/13473 Issue: https://github.com/SerenityOS/serenity/issues/10968 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/kleinesfilmroellchen Reviewed-by: https://github.com/krkk Reviewed-by: https://github.com/linusg ✅
@ -223,9 +223,32 @@ public:
|
||||
|
||||
virtual ~HeadlessImageDecoderClient() override = default;
|
||||
|
||||
virtual Optional<Web::ImageDecoding::DecodedImage> decode_image(ReadonlyBytes) override
|
||||
virtual Optional<Web::ImageDecoding::DecodedImage> decode_image(ReadonlyBytes data) override
|
||||
{
|
||||
return {};
|
||||
auto decoder = Gfx::ImageDecoder::try_create(data);
|
||||
|
||||
if (!decoder)
|
||||
return Web::ImageDecoding::DecodedImage { false, 0, Vector<Web::ImageDecoding::Frame> {} };
|
||||
|
||||
if (!decoder->frame_count())
|
||||
return Web::ImageDecoding::DecodedImage { false, 0, Vector<Web::ImageDecoding::Frame> {} };
|
||||
|
||||
Vector<Web::ImageDecoding::Frame> frames;
|
||||
for (size_t i = 0; i < decoder->frame_count(); ++i) {
|
||||
auto frame_or_error = decoder->frame(i);
|
||||
if (frame_or_error.is_error()) {
|
||||
frames.append({ {}, 0 });
|
||||
} else {
|
||||
auto frame = frame_or_error.release_value();
|
||||
frames.append({ move(frame.image), static_cast<size_t>(frame.duration) });
|
||||
}
|
||||
}
|
||||
|
||||
return Web::ImageDecoding::DecodedImage {
|
||||
decoder->is_animated(),
|
||||
static_cast<u32>(decoder->loop_count()),
|
||||
frames,
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user