LibGfx/ISOBMFF: Add JPEG2000ColorSpecificationBox

This commit is contained in:
Nico Weber 2024-03-22 14:46:54 -04:00 committed by Tim Schumacher
parent 59bd378db8
commit 214ff799ce
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
2 changed files with 40 additions and 0 deletions

View File

@ -13,6 +13,8 @@ ErrorOr<void> JPEG2000HeaderBox::read_from_stream(BoxStream& stream)
{
auto make_subbox = [](BoxType type, BoxStream& stream) -> ErrorOr<Optional<NonnullOwnPtr<Box>>> {
switch (type) {
case BoxType::JPEG2000ColorSpecificationBox:
return TRY(JPEG2000ColorSpecificationBox::create_from_stream(stream));
case BoxType::JPEG2000ImageHeaderBox:
return TRY(JPEG2000ImageHeaderBox::create_from_stream(stream));
default:
@ -58,6 +60,33 @@ void JPEG2000ImageHeaderBox::dump(String const& prepend) const
outln("{}- contains_intellectual_property_rights = {}", prepend, contains_intellectual_property_rights);
}
ErrorOr<void> JPEG2000ColorSpecificationBox::read_from_stream(BoxStream& stream)
{
method = TRY(stream.read_value<u8>());
precedence = TRY(stream.read_value<i8>());
approximation = TRY(stream.read_value<u8>());
if (method == 1)
enumerated_color_space = TRY(stream.read_value<BigEndian<u32>>());
if (method == 2) {
ByteBuffer local_icc_data = TRY(ByteBuffer::create_uninitialized(stream.remaining()));
TRY(stream.read_until_filled(local_icc_data));
icc_data = move(local_icc_data);
}
return {};
}
void JPEG2000ColorSpecificationBox::dump(String const& prepend) const
{
Box::dump(prepend);
outln("{}- method = {}", prepend, method);
outln("{}- precedence = {}", prepend, precedence);
outln("{}- approximation = {}", prepend, approximation);
if (method == 1)
outln("{}- enumerated_color_space = {}", prepend, enumerated_color_space);
if (method == 2)
outln("{}- icc_data = {} bytes", prepend, icc_data.size());
}
ErrorOr<void> JPEG2000SignatureBox::read_from_stream(BoxStream& stream)
{
signature = TRY(stream.read_value<BigEndian<u32>>());

View File

@ -27,6 +27,17 @@ struct JPEG2000ImageHeaderBox final : public Box {
u8 contains_intellectual_property_rights { 0 };
};
// I.5.3.3 Colour Specification box
struct JPEG2000ColorSpecificationBox final : public Box {
BOX_SUBTYPE(JPEG2000ColorSpecificationBox);
u8 method { 0 };
i8 precedence { 0 };
u8 approximation { 0 };
u32 enumerated_color_space { 0 }; // Only set if method == 1
ByteBuffer icc_data; // Only set if method == 2
};
struct JPEG2000SignatureBox final : public Box {
BOX_SUBTYPE(JPEG2000SignatureBox);