LibGfx/ISOBMFF: Add JPEG2000BitsPerComponentBox

I haven't seen this in the wild yet, but it's the only missing
box type in I.5.3 and it's similar to to a subset of palette box
in I.5.3.4, so maybe the implementation is not completely wrong.
This commit is contained in:
Nico Weber 2025-01-18 21:02:17 -05:00
parent 68bf57bd8a
commit ed8f0a6263
2 changed files with 35 additions and 0 deletions

View file

@ -17,6 +17,8 @@ ErrorOr<void> JPEG2000HeaderBox::read_from_stream(BoxStream& stream)
// I.5.3 JP2 Header box (superbox)
auto make_subbox = [](BoxType type, BoxStream& stream) -> ErrorOr<Optional<NonnullOwnPtr<Box>>> {
switch (type) {
case BoxType::JPEG2000BitsPerComponentBox:
return TRY(JPEG2000BitsPerComponentBox::create_from_stream(stream));
case BoxType::JPEG2000ChannelDefinitionBox:
return TRY(JPEG2000ChannelDefinitionBox::create_from_stream(stream));
case BoxType::JPEG2000ColorSpecificationBox:
@ -73,6 +75,28 @@ void JPEG2000ImageHeaderBox::dump(String const& prepend) const
outln("{}- contains_intellectual_property_rights = {}", prepend, contains_intellectual_property_rights);
}
ErrorOr<void> JPEG2000BitsPerComponentBox::read_from_stream(BoxStream& stream)
{
// I.5.3.2 Bits Per Component box
while (!stream.is_eof()) {
BitsPerComponent bits_per_component;
u8 depth = TRY(stream.read_value<u8>());
bits_per_component.depth = (depth & 0x7f) + 1;
bits_per_component.is_signed = (depth & 0x80) != 0;
bits_per_components.append(bits_per_component);
}
return {};
}
void JPEG2000BitsPerComponentBox::dump(String const& prepend) const
{
Box::dump(prepend);
for (auto const& bits_per_component : bits_per_components) {
outln("{}- depth = {}", prepend, bits_per_component.depth);
outln("{}- is_signed = {}", prepend, bits_per_component.is_signed);
}
}
ErrorOr<void> JPEG2000ColorSpecificationBox::read_from_stream(BoxStream& stream)
{
// I.5.3.3 Colour Specification box

View file

@ -27,6 +27,17 @@ struct JPEG2000ImageHeaderBox final : public Box {
u8 contains_intellectual_property_rights { 0 };
};
// I.5.3.2 Bits Per Component box
struct JPEG2000BitsPerComponentBox final : public Box {
BOX_SUBTYPE(JPEG2000BitsPerComponentBox);
struct BitsPerComponent {
u8 depth;
bool is_signed;
};
Vector<BitsPerComponent> bits_per_components;
};
// I.5.3.3 Colour Specification box
struct JPEG2000ColorSpecificationBox final : public Box {
BOX_SUBTYPE(JPEG2000ColorSpecificationBox);