/* * Copyright (c) 2022, Dex♪ * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include "ImageCodecPluginLadybird.h" #include #include namespace Ladybird { ImageCodecPluginLadybird::~ImageCodecPluginLadybird() = default; Optional ImageCodecPluginLadybird::decode_image(ReadonlyBytes data) { auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(data); if (!decoder || !decoder->frame_count()) { return {}; } Vector frames; for (size_t i = 0; i < decoder->frame_count(); ++i) { auto frame_or_error = decoder->frame(i); if (frame_or_error.is_error()) return {}; auto frame = frame_or_error.release_value(); frames.append({ move(frame.image), static_cast(frame.duration) }); } return Web::Platform::DecodedImage { decoder->is_animated(), static_cast(decoder->loop_count()), move(frames), }; } }