ladybird/Userland/Libraries/LibGfx/ImageFormats/JPEG2000Loader.h
Nico Weber 7296b0fa43 LibGfx/JPEG2000: Implement tag trees
A tag tree is a data structure used for deserializing JPEG2000
packet headers.

We don't use them for anything yet, except from tests.

The implementation feels a bit awkward to me, but we can always polish
it later.

The spec thankfully includes two concrete examples. The code is
correct enough to pass those -- I added them as test.
2024-04-16 00:40:16 +02:00

54 lines
1.1 KiB
C++

/*
* Copyright (c) 2024, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/ImageFormats/ImageDecoder.h>
namespace Gfx {
namespace JPEG2000 {
struct TagTreeNode;
class TagTree {
public:
TagTree(TagTree&&);
~TagTree();
static ErrorOr<TagTree> create(u32 x_count, u32 y_count);
ErrorOr<u32> read_value(u32 x, u32 y, Function<ErrorOr<bool>()> const& read_bit, Optional<u32> stop_at = {}) const;
private:
TagTree(NonnullOwnPtr<TagTreeNode>);
NonnullOwnPtr<TagTreeNode> m_root;
};
}
struct JPEG2000LoadingContext;
class JPEG2000ImageDecoderPlugin : public ImageDecoderPlugin {
public:
static bool sniff(ReadonlyBytes);
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
virtual ~JPEG2000ImageDecoderPlugin() override = default;
virtual IntSize size() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
private:
JPEG2000ImageDecoderPlugin();
OwnPtr<JPEG2000LoadingContext> m_context;
};
}