LibGfx/ISOBMFF: Give JPEG2000HeaderBox its own type

...and make SuperBox a pure superclass that's not usable by itself.
This commit is contained in:
Nico Weber 2024-03-22 14:08:15 -04:00 committed by Tim Schumacher
parent 65bd090815
commit c84487ed2d
4 changed files with 17 additions and 13 deletions

View file

@ -95,22 +95,11 @@ struct FileTypeBox final : public Box {
// A box that contains other boxes.
struct SuperBox : public Box {
static ErrorOr<NonnullOwnPtr<SuperBox>> create_from_stream(BoxType type, BoxStream& stream)
{
auto box = TRY(try_make<SuperBox>(type));
TRY(box->read_from_stream(stream));
return box;
}
SuperBox(BoxType type)
: m_box_type(type)
{
}
SuperBox() = default;
virtual ErrorOr<void> read_from_stream(BoxStream&) override;
virtual BoxType box_type() const override { return m_box_type; }
virtual void dump(String const& prepend = {}) const override;
private:
BoxType m_box_type { BoxType::None };
BoxList m_child_boxes;
};

View file

@ -8,6 +8,17 @@
namespace Gfx::ISOBMFF {
ErrorOr<void> JPEG2000HeaderBox::read_from_stream(BoxStream& stream)
{
TRY(SuperBox::read_from_stream(stream));
return {};
}
void JPEG2000HeaderBox::dump(String const& prepend) const
{
SuperBox::dump(prepend);
}
ErrorOr<void> JPEG2000SignatureBox::read_from_stream(BoxStream& stream)
{
signature = TRY(stream.read_value<BigEndian<u32>>());

View file

@ -10,6 +10,10 @@
namespace Gfx::ISOBMFF {
struct JPEG2000HeaderBox final : public SuperBox {
BOX_SUBTYPE(JPEG2000HeaderBox);
};
struct JPEG2000SignatureBox final : public Box {
BOX_SUBTYPE(JPEG2000SignatureBox);

View file

@ -34,7 +34,7 @@ ErrorOr<BoxList> Reader::read_entire_file()
TRY(top_level_boxes.try_append(TRY(FileTypeBox::create_from_stream(box_stream))));
break;
case BoxType::JPEG2000HeaderBox:
TRY(top_level_boxes.try_append(TRY(SuperBox::create_from_stream(box_header.type, box_stream))));
TRY(top_level_boxes.try_append(TRY(JPEG2000HeaderBox::create_from_stream(box_stream))));
break;
case BoxType::JPEG2000SignatureBox:
TRY(top_level_boxes.try_append(TRY(JPEG2000SignatureBox::create_from_stream(box_stream))));