LibGfx/ISOBMFF: Add JPEG2000ImageHeaderBox
This commit is contained in:
parent
78deac3dca
commit
59bd378db8
Notes:
sideshowbarker
2024-07-17 04:03:27 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/59bd378db8 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 ✅
2 changed files with 49 additions and 2 deletions
|
@ -11,8 +11,13 @@ namespace Gfx::ISOBMFF {
|
|||
|
||||
ErrorOr<void> JPEG2000HeaderBox::read_from_stream(BoxStream& stream)
|
||||
{
|
||||
auto make_subbox = [](BoxType, BoxStream&) -> ErrorOr<Optional<NonnullOwnPtr<Box>>> {
|
||||
return OptionalNone {};
|
||||
auto make_subbox = [](BoxType type, BoxStream& stream) -> ErrorOr<Optional<NonnullOwnPtr<Box>>> {
|
||||
switch (type) {
|
||||
case BoxType::JPEG2000ImageHeaderBox:
|
||||
return TRY(JPEG2000ImageHeaderBox::create_from_stream(stream));
|
||||
default:
|
||||
return OptionalNone {};
|
||||
}
|
||||
};
|
||||
|
||||
TRY(SuperBox::read_from_stream(stream, move(make_subbox)));
|
||||
|
@ -24,6 +29,35 @@ void JPEG2000HeaderBox::dump(String const& prepend) const
|
|||
SuperBox::dump(prepend);
|
||||
}
|
||||
|
||||
ErrorOr<void> JPEG2000ImageHeaderBox::read_from_stream(BoxStream& stream)
|
||||
{
|
||||
height = TRY(stream.read_value<BigEndian<u32>>());
|
||||
width = TRY(stream.read_value<BigEndian<u32>>());
|
||||
num_components = TRY(stream.read_value<BigEndian<u16>>());
|
||||
bits_per_component = TRY(stream.read_value<u8>());
|
||||
compression_type = TRY(stream.read_value<u8>());
|
||||
is_colorspace_unknown = TRY(stream.read_value<u8>());
|
||||
contains_intellectual_property_rights = TRY(stream.read_value<u8>());
|
||||
return {};
|
||||
}
|
||||
|
||||
void JPEG2000ImageHeaderBox::dump(String const& prepend) const
|
||||
{
|
||||
Box::dump(prepend);
|
||||
outln("{}- height = {}", prepend, height);
|
||||
outln("{}- width = {}", prepend, width);
|
||||
outln("{}- num_components = {}", prepend, num_components);
|
||||
if (bits_per_component == 0xFF) {
|
||||
outln("{}- components vary in bit depth", prepend);
|
||||
} else {
|
||||
outln("{}- are_components_signed = {}", prepend, (bits_per_component & 0x80) != 0);
|
||||
outln("{}- bits_per_component = {}", prepend, (bits_per_component & 0x7f) + 1);
|
||||
}
|
||||
outln("{}- compression_type = {}", prepend, compression_type);
|
||||
outln("{}- is_colorspace_unknown = {}", prepend, is_colorspace_unknown);
|
||||
outln("{}- contains_intellectual_property_rights = {}", prepend, contains_intellectual_property_rights);
|
||||
}
|
||||
|
||||
ErrorOr<void> JPEG2000SignatureBox::read_from_stream(BoxStream& stream)
|
||||
{
|
||||
signature = TRY(stream.read_value<BigEndian<u32>>());
|
||||
|
|
|
@ -14,6 +14,19 @@ struct JPEG2000HeaderBox final : public SuperBox {
|
|||
BOX_SUBTYPE(JPEG2000HeaderBox);
|
||||
};
|
||||
|
||||
// I.5.3.1 Image Header box
|
||||
struct JPEG2000ImageHeaderBox final : public Box {
|
||||
BOX_SUBTYPE(JPEG2000ImageHeaderBox);
|
||||
|
||||
u32 height { 0 };
|
||||
u32 width { 0 };
|
||||
u16 num_components { 0 };
|
||||
u8 bits_per_component { 0 };
|
||||
u8 compression_type { 0 };
|
||||
u8 is_colorspace_unknown { 0 };
|
||||
u8 contains_intellectual_property_rights { 0 };
|
||||
};
|
||||
|
||||
struct JPEG2000SignatureBox final : public Box {
|
||||
BOX_SUBTYPE(JPEG2000SignatureBox);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue