2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-07-26 20:12:53 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-10-15 16:48:08 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-06-01 16:32:54 -03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2019-10-15 16:48:08 -03:00
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <AK/RefCounted.h>
|
2020-05-03 13:12:54 -03:00
|
|
|
#include <AK/RefPtr.h>
|
2021-01-21 16:55:37 -03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-06 08:04:00 -03:00
|
|
|
#include <LibGfx/Size.h>
|
2019-10-15 16:48:08 -03:00
|
|
|
|
2020-02-06 07:56:38 -03:00
|
|
|
namespace Gfx {
|
|
|
|
|
|
|
|
|
|
class Bitmap;
|
2019-10-15 16:48:08 -03:00
|
|
|
|
2020-12-24 20:19:06 -03:00
|
|
|
static constexpr size_t maximum_width_for_decoded_images = 16384;
|
|
|
|
|
static constexpr size_t maximum_height_for_decoded_images = 16384;
|
|
|
|
|
|
2020-05-03 13:12:54 -03:00
|
|
|
struct ImageFrameDescriptor {
|
|
|
|
|
RefPtr<Bitmap> image;
|
|
|
|
|
int duration { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-19 14:56:49 -03:00
|
|
|
class ImageDecoderPlugin {
|
2019-10-15 16:48:08 -03:00
|
|
|
public:
|
2022-03-14 16:26:37 -03:00
|
|
|
virtual ~ImageDecoderPlugin() = default;
|
2019-10-15 16:48:08 -03:00
|
|
|
|
2020-06-10 05:57:59 -03:00
|
|
|
virtual IntSize size() = 0;
|
2019-10-15 16:48:08 -03:00
|
|
|
|
2019-12-18 16:50:58 -03:00
|
|
|
virtual void set_volatile() = 0;
|
2021-07-24 17:49:48 -03:00
|
|
|
[[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) = 0;
|
2019-12-18 16:50:58 -03:00
|
|
|
|
2020-04-25 09:51:00 -03:00
|
|
|
virtual bool sniff() = 0;
|
|
|
|
|
|
2020-05-03 13:12:54 -03:00
|
|
|
virtual bool is_animated() = 0;
|
|
|
|
|
virtual size_t loop_count() = 0;
|
|
|
|
|
virtual size_t frame_count() = 0;
|
2021-11-20 10:29:33 -03:00
|
|
|
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) = 0;
|
2020-05-03 13:12:54 -03:00
|
|
|
|
2019-10-15 16:48:08 -03:00
|
|
|
protected:
|
2022-03-14 16:26:37 -03:00
|
|
|
ImageDecoderPlugin() = default;
|
2019-10-15 16:48:08 -03:00
|
|
|
};
|
|
|
|
|
|
2019-10-19 14:56:49 -03:00
|
|
|
class ImageDecoder : public RefCounted<ImageDecoder> {
|
2019-10-15 16:48:08 -03:00
|
|
|
public:
|
2021-07-26 20:12:53 -03:00
|
|
|
static RefPtr<ImageDecoder> try_create(ReadonlyBytes);
|
2022-03-14 16:26:37 -03:00
|
|
|
~ImageDecoder() = default;
|
2019-10-15 16:48:08 -03:00
|
|
|
|
2021-07-26 20:12:53 -03:00
|
|
|
IntSize size() const { return m_plugin->size(); }
|
2019-10-15 16:48:08 -03:00
|
|
|
int width() const { return size().width(); }
|
|
|
|
|
int height() const { return size().height(); }
|
2021-07-26 20:12:53 -03:00
|
|
|
void set_volatile() { m_plugin->set_volatile(); }
|
|
|
|
|
[[nodiscard]] bool set_nonvolatile(bool& was_purged) { return m_plugin->set_nonvolatile(was_purged); }
|
|
|
|
|
bool sniff() const { return m_plugin->sniff(); }
|
|
|
|
|
bool is_animated() const { return m_plugin->is_animated(); }
|
|
|
|
|
size_t loop_count() const { return m_plugin->loop_count(); }
|
|
|
|
|
size_t frame_count() const { return m_plugin->frame_count(); }
|
2021-11-20 10:29:33 -03:00
|
|
|
ErrorOr<ImageFrameDescriptor> frame(size_t index) const { return m_plugin->frame(index); }
|
2019-10-15 16:48:08 -03:00
|
|
|
|
|
|
|
|
private:
|
2021-07-26 20:12:53 -03:00
|
|
|
explicit ImageDecoder(NonnullOwnPtr<ImageDecoderPlugin>);
|
2019-10-15 16:48:08 -03:00
|
|
|
|
2021-07-26 20:12:53 -03:00
|
|
|
NonnullOwnPtr<ImageDecoderPlugin> mutable m_plugin;
|
2019-10-15 16:48:08 -03:00
|
|
|
};
|
2020-02-06 07:56:38 -03:00
|
|
|
|
|
|
|
|
}
|