LibGfx/ISOBMFF: Read JPEG2000HeaderBox

This commit is contained in:
Nico Weber 2024-03-22 13:29:39 -04:00 committed by Tim Schumacher
parent 15ba0a7e18
commit a073b2d047
Notes: sideshowbarker 2024-07-17 05:05:51 +09:00
4 changed files with 46 additions and 0 deletions

View file

@ -5,6 +5,7 @@
*/
#include "Boxes.h"
#include "Reader.h"
namespace Gfx::ISOBMFF {
@ -103,4 +104,19 @@ void FileTypeBox::dump(String const& prepend) const
outln("{}{}", prepend, compatible_brands_string.string_view());
}
ErrorOr<void> SuperBox::read_from_stream(BoxStream& stream)
{
auto reader = TRY(Gfx::ISOBMFF::Reader::create(MaybeOwned { stream }));
m_child_boxes = TRY(reader.read_entire_file());
return {};
}
void SuperBox::dump(String const& prepend) const
{
Box::dump(prepend);
auto indented_prepend = add_indent(prepend);
for (auto const& child_box : m_child_boxes)
child_box->dump(indented_prepend);
}
}

View file

@ -93,4 +93,25 @@ struct FileTypeBox final : public Box {
Vector<BrandIdentifier> compatible_brands;
};
// 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)
{
}
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

@ -14,6 +14,11 @@ ErrorOr<Reader> Reader::create(MaybeOwned<SeekableStream> stream)
return Reader(make<BoxStream>(move(stream), size));
}
ErrorOr<Reader> Reader::create(MaybeOwned<BoxStream> stream)
{
return Reader(move(stream));
}
ErrorOr<BoxList> Reader::read_entire_file()
{
BoxList top_level_boxes;
@ -26,6 +31,9 @@ ErrorOr<BoxList> Reader::read_entire_file()
case BoxType::FileTypeBox:
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))));
break;
default:
TRY(top_level_boxes.try_append(TRY(UnknownBox::create_from_stream(box_header.type, box_stream))));
break;

View file

@ -16,6 +16,7 @@ namespace Gfx::ISOBMFF {
class Reader {
public:
static ErrorOr<Reader> create(MaybeOwned<SeekableStream> stream);
static ErrorOr<Reader> create(MaybeOwned<BoxStream> stream);
ErrorOr<BoxList> read_entire_file();