mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
b5e593d0e7
We should only rely on LibGfx to decode images for us, if LibGfx can't decode an image that should be motivation to improve LibGfx, not hidden by Qt picking up the slack :^)
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2022, Dex♪ <dexes.ttp@gmail.com>
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "ImageCodecPluginLadybird.h"
|
|
#include <LibGfx/Bitmap.h>
|
|
#include <LibGfx/ImageFormats/ImageDecoder.h>
|
|
|
|
namespace Ladybird {
|
|
|
|
ImageCodecPluginLadybird::~ImageCodecPluginLadybird() = default;
|
|
|
|
Optional<Web::Platform::DecodedImage> ImageCodecPluginLadybird::decode_image(ReadonlyBytes data)
|
|
{
|
|
auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(data);
|
|
|
|
if (!decoder || !decoder->frame_count()) {
|
|
return {};
|
|
}
|
|
|
|
bool had_errors = false;
|
|
Vector<Web::Platform::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 });
|
|
had_errors = true;
|
|
} else {
|
|
auto frame = frame_or_error.release_value();
|
|
frames.append({ move(frame.image), static_cast<size_t>(frame.duration) });
|
|
}
|
|
}
|
|
|
|
if (had_errors)
|
|
return {};
|
|
|
|
return Web::Platform::DecodedImage {
|
|
decoder->is_animated(),
|
|
static_cast<u32>(decoder->loop_count()),
|
|
move(frames),
|
|
};
|
|
}
|
|
|
|
}
|