Просмотр исходного кода

LibGfx/ISOBMFF: Add JPEG2000ContiguousCodestreamBox

Nico Weber 1 год назад
Родитель
Сommit
c58996f4fc

+ 16 - 0
Userland/Libraries/LibGfx/ImageFormats/ISOBMFF/JPEG2000Boxes.cpp

@@ -127,6 +127,22 @@ void JPEG2000CaptureResolutionBox::dump(String const& prepend) const
     outln("{}- horizontal_capture_grid_resolution = {}/{} * 10^{}", prepend, horizontal_capture_grid_resolution_numerator, horizontal_capture_grid_resolution_denominator, horizontal_capture_grid_resolution_exponent);
 }
 
+ErrorOr<void> JPEG2000ContiguousCodestreamBox::read_from_stream(BoxStream& stream)
+{
+    // FIXME: It's wasteful to make a copy of all the image data here. Having just a ReadonlyBytes
+    // or streaming it into the jpeg2000 decoder would be nicer.
+    ByteBuffer local_codestream = TRY(ByteBuffer::create_uninitialized(stream.remaining()));
+    TRY(stream.read_until_filled(local_codestream));
+    codestream = move(local_codestream);
+    return {};
+}
+
+void JPEG2000ContiguousCodestreamBox::dump(String const& prepend) const
+{
+    Box::dump(prepend);
+    outln("{}- codestream = {} bytes", prepend, codestream.size());
+}
+
 ErrorOr<void> JPEG2000SignatureBox::read_from_stream(BoxStream& stream)
 {
     signature = TRY(stream.read_value<BigEndian<u32>>());

+ 7 - 0
Userland/Libraries/LibGfx/ImageFormats/ISOBMFF/JPEG2000Boxes.h

@@ -55,6 +55,13 @@ struct JPEG2000CaptureResolutionBox final : public Box {
     i8 horizontal_capture_grid_resolution_exponent { 0 };
 };
 
+// I.5.4 Contiguous Codestream box
+struct JPEG2000ContiguousCodestreamBox final : public Box {
+    BOX_SUBTYPE(JPEG2000ContiguousCodestreamBox);
+
+    ByteBuffer codestream;
+};
+
 struct JPEG2000SignatureBox final : public Box {
     BOX_SUBTYPE(JPEG2000SignatureBox);
 

+ 2 - 0
Userland/Libraries/LibGfx/ImageFormats/ISOBMFF/Reader.cpp

@@ -27,6 +27,8 @@ ErrorOr<BoxList> Reader::read_entire_file()
         switch (type) {
         case BoxType::FileTypeBox:
             return TRY(FileTypeBox::create_from_stream(stream));
+        case BoxType::JPEG2000ContiguousCodestreamBox:
+            return TRY(JPEG2000ContiguousCodestreamBox::create_from_stream(stream));
         case BoxType::JPEG2000HeaderBox:
             return TRY(JPEG2000HeaderBox::create_from_stream(stream));
         case BoxType::JPEG2000SignatureBox: