LibGfx/ISOBMFF: Add JPEG2000URLBox

This commit is contained in:
Nico Weber 2024-03-22 15:49:25 -04:00 committed by Tim Schumacher
parent c58996f4fc
commit f080836127
Notes: sideshowbarker 2024-07-16 23:52:10 +09:00
2 changed files with 46 additions and 0 deletions

View File

@ -161,6 +161,8 @@ ErrorOr<void> JPEG2000UUIDInfoBox::read_from_stream(BoxStream& stream)
switch (type) {
case BoxType::JPEG2000UUIDListBox:
return TRY(JPEG2000UUIDListBox::create_from_stream(stream));
case BoxType::JPEG2000URLBox:
return TRY(JPEG2000URLBox::create_from_stream(stream));
default:
return OptionalNone {};
}
@ -198,4 +200,37 @@ void JPEG2000UUIDListBox::dump(String const& prepend) const
}
}
ErrorOr<String> JPEG2000URLBox::url_as_string() const
{
// Zero-terminated UTF-8 per spec.
if (url_bytes.is_empty() || url_bytes.bytes().last() != '\0')
return Error::from_string_literal("URL not zero-terminated");
return String::from_utf8(StringView { url_bytes.bytes().trim(url_bytes.size() - 1) });
}
ErrorOr<void> JPEG2000URLBox::read_from_stream(BoxStream& stream)
{
version_number = TRY(stream.read_value<u8>());
flag = TRY(stream.read_value<u8>()) << 16;
flag |= TRY(stream.read_value<BigEndian<u16>>());
url_bytes = TRY(ByteBuffer::create_uninitialized(stream.remaining()));
TRY(stream.read_until_filled(url_bytes));
return {};
}
void JPEG2000URLBox::dump(String const& prepend) const
{
Box::dump(prepend);
outln("{}- version_number = {}", prepend, version_number);
outln("{}- flag = {:#06x}", prepend, flag);
auto url_or_err = url_as_string();
if (url_or_err.is_error())
outln("{}- url = <invalid {}; {} bytes>", prepend, url_or_err.release_error(), url_bytes.size());
else
outln("{}- url = {}", prepend, url_or_err.release_value());
}
}

View File

@ -80,4 +80,15 @@ struct JPEG2000UUIDListBox final : public Box {
Vector<Array<u8, 16>> uuids;
};
// I.7.3.2 Data Entry URL box
struct JPEG2000URLBox final : public Box {
BOX_SUBTYPE(JPEG2000URLBox);
ErrorOr<String> url_as_string() const;
u8 version_number;
u32 flag;
ByteBuffer url_bytes;
};
}