mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibGfx/ISOBMFF: Read JPEG2000HeaderBox
This commit is contained in:
parent
15ba0a7e18
commit
a073b2d047
Notes:
sideshowbarker
2024-07-17 05:05:51 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/a073b2d047 Pull-request: https://github.com/SerenityOS/serenity/pull/23682 Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/Zaggy1024 Reviewed-by: https://github.com/timschumi ✅
4 changed files with 46 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue