mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00: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
1 changed files with 25 additions and 2 deletions
|
@ -223,9 +223,32 @@ public:
|
||||||
|
|
||||||
virtual ~HeadlessImageDecoderClient() override = default;
|
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:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue