JPEG2000Loader.cpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. /*
  2. * Copyright (c) 2024, Nico Weber <thakis@chromium.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Debug.h>
  7. #include <AK/Enumerate.h>
  8. #include <AK/MemoryStream.h>
  9. #include <LibGfx/ImageFormats/ISOBMFF/JPEG2000Boxes.h>
  10. #include <LibGfx/ImageFormats/ISOBMFF/Reader.h>
  11. #include <LibGfx/ImageFormats/JPEG2000Loader.h>
  12. #include <LibTextCodec/Decoder.h>
  13. // Core coding system spec (.jp2 format): T-REC-T.800-201511-S!!PDF-E.pdf available here:
  14. // https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.800-201511-S!!PDF-E&type=items
  15. // Extensions (.jpx format): T-REC-T.801-202106-S!!PDF-E.pdf available here:
  16. // https://handle.itu.int/11.1002/1000/14666-en?locatt=format:pdf&auth
  17. // rfc3745 lists the MIME type. It only mentions the jp2_id_string as magic number.
  18. namespace Gfx {
  19. // A JPEG2000 image can be stored in a codestream with markers, similar to a JPEG image,
  20. // or in a JP2 file, which is a container format based on boxes similar to ISOBMFF.
  21. // This is the marker for the codestream version. We don't support this yet.
  22. // If we add support, add a second `"image/jp2"` line to MimeData.cpp for this magic number.
  23. // T.800 Annex A, Codestream syntax, A.2 Information in the marker segments and A.3 Construction of the codestream
  24. [[maybe_unused]] static constexpr u8 marker_id_string[] = { 0xFF, 0x4F, 0xFF, 0x51 };
  25. // This is the marker for the box version.
  26. // T.800 Annex I, JP2 file format syntax, I.5.1 JPEG 2000 Signature box
  27. static constexpr u8 jp2_id_string[] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A };
  28. // Table A.2 – List of markers and marker segments
  29. // "Delimiting markers and marker segments"
  30. #define J2K_SOC 0xFF4F // "Start of codestream"
  31. #define J2K_SOT 0xFF90 // "Start of tile-part"
  32. #define J2K_SOD 0xFF93 // "Start of data"
  33. #define J2K_EOC 0xFFD9 // "End of codestream"
  34. // "Fixed information marker segments"
  35. #define J2K_SIZ 0xFF51 // "Image and tile size"
  36. // "Functional marker segments"
  37. #define J2K_COD 0xFF52 // "Coding style default"
  38. #define J2K_COC 0xFF53 // "Coding style component"
  39. #define J2K_RGN 0xFF5E // "Region-of-interest"
  40. #define J2K_QCD 0xFF5C // "Quantization default"
  41. #define J2K_QCC 0xFF5D // "Quantization component"
  42. #define J2K_POC 0xFF5F // "Progression order change"
  43. // "Pointer marker segments"
  44. #define J2K_TLM 0xFF55 // "Tile-part lengths"
  45. #define J2K_PLM 0xFF57 // "Packet length, main header"
  46. #define J2K_PLT 0xFF58 // "Packet length, tile-part header"
  47. #define J2K_PPM 0xFF60 // "Packed packet headers, main header"
  48. #define J2K_PPT 0xFF61 // "Packed packet headers, tile-part header"
  49. // "In-bit-stream markers and marker segments"
  50. #define J2K_SOP 0xFF91 // "Start of packet"
  51. #define J2K_EPH 0xFF92 // "End of packet header"
  52. // "Informational marker segments"
  53. #define J2K_CRG 0xFF63 // "Component registration"
  54. #define J2K_COM 0xFF64 // "Comment"
  55. // A.4.2 Start of tile-part (SOT)
  56. struct StartOfTilePart {
  57. // "Tile index. This number refers to the tiles in raster order starting at the number 0."
  58. u16 tile_index { 0 }; // "Isot" in spec.
  59. // "Length, in bytes, from the beginning of the first byte of this SOT marker segment of the tile-part to
  60. // the end of the data of that tile-part. Figure A.16 shows this alignment. Only the last tile-part in the
  61. // codestream may contain a 0 for Psot. If the Psot is 0, this tile-part is assumed to contain all data until
  62. // the EOC marker."
  63. u32 tile_part_length { 0 }; // "Psot" in spec.
  64. // "Tile-part index. There is a specific order required for decoding tile-parts; this index denotes the order
  65. // from 0. If there is only one tile-part for a tile, then this value is zero. The tile-parts of this tile shall
  66. // appear in the codestream in this order, although not necessarily consecutively."
  67. u8 tile_part_index { 0 }; // "TPsot" in spec.
  68. // "Number of tile-parts of a tile in the codestream. Two values are allowed: the correct number of tile-
  69. // parts for that tile and zero. A zero value indicates that the number of tile-parts of this tile is not
  70. // specified in this tile-part.
  71. u8 number_of_tile_parts { 0 }; // "TNsot" in spec.
  72. };
  73. static ErrorOr<StartOfTilePart> read_start_of_tile_part(ReadonlyBytes data)
  74. {
  75. if (data.size() < 8)
  76. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for SOT marker segment");
  77. StartOfTilePart sot;
  78. sot.tile_index = *reinterpret_cast<AK::BigEndian<u16> const*>(data.data());
  79. sot.tile_part_length = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 2);
  80. sot.tile_part_index = data[6];
  81. sot.number_of_tile_parts = data[7];
  82. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: SOT marker segment: tile_index={}, tile_part_length={}, tile_part_index={}, number_of_tile_parts={}", sot.tile_index, sot.tile_part_length, sot.tile_part_index, sot.number_of_tile_parts);
  83. return sot;
  84. }
  85. // A.5.1 Image and tile size (SIZ)
  86. struct ImageAndTileSize {
  87. // "Denotes capabilities that a decoder needs to properly decode the codestream."
  88. u16 needed_decoder_capabilities { 0 }; // "Rsiz" in spec.
  89. // "Width of the reference grid."
  90. u32 width { 0 }; // "Xsiz" in spec.
  91. // "Height of the reference grid."
  92. u32 height { 0 }; // "Ysiz" in spec.
  93. // "Horizontal offset from the origin of the reference grid to the left side of the image area."
  94. u32 x_offset { 0 }; // "XOsiz" in spec.
  95. // "Vertical offset from the origin of the reference grid to the top side of the image area."
  96. u32 y_offset { 0 }; // "YOsiz" in spec.
  97. // "Width of one reference tile with respect to the reference grid."
  98. u32 tile_width { 0 }; // "XTsiz" in spec.
  99. // "Height of one reference tile with respect to the reference grid."
  100. u32 tile_height { 0 }; // "YTsiz" in spec.
  101. // "Horizontal offset from the origin of the reference grid to the left side of the first tile."
  102. u32 tile_x_offset { 0 }; // "XTOsiz" in spec.
  103. // "Vertical offset from the origin of the reference grid to the top side of the first tile."
  104. u32 tile_y_offset { 0 }; // "YTOsiz" in spec.
  105. // "Csiz" isn't stored in this struct. It corresponds to `components.size()`.
  106. struct ComponentInformation {
  107. // "Precision (depth) in bits and sign of the ith component samples."
  108. u8 depth_and_sign { 0 }; // "Ssiz" in spec.
  109. // Table A.11 – Component Ssiz parameter
  110. u8 bit_depth() const { return (depth_and_sign & 0x7F) + 1; }
  111. bool is_signed() const { return depth_and_sign & 0x80; }
  112. // "Horizontal separation of a sample of the ith component with respect to the reference grid."
  113. u8 horizontal_separation { 0 }; // "XRsiz" in spec.
  114. // "Vertical separation of a sample of the ith component with respect to the reference grid."
  115. u8 vertical_separation { 0 }; // "YRsiz" in spec.
  116. };
  117. Vector<ComponentInformation> components;
  118. };
  119. static ErrorOr<ImageAndTileSize> read_image_and_tile_size(ReadonlyBytes data)
  120. {
  121. if (data.size() < 36)
  122. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for SIZ marker segment");
  123. ImageAndTileSize siz;
  124. siz.needed_decoder_capabilities = *reinterpret_cast<AK::BigEndian<u16> const*>(data.data());
  125. siz.width = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 2);
  126. siz.height = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 6);
  127. siz.x_offset = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 10);
  128. siz.y_offset = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 14);
  129. siz.tile_width = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 18);
  130. siz.tile_height = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 22);
  131. siz.tile_x_offset = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 26);
  132. siz.tile_y_offset = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 30);
  133. u16 component_count = *reinterpret_cast<AK::BigEndian<u16> const*>(data.data() + 34); // "Csiz" in spec.
  134. if (data.size() < 36u + component_count * 3u)
  135. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for SIZ marker segment component information");
  136. for (size_t i = 0; i < component_count; ++i) {
  137. ImageAndTileSize::ComponentInformation component;
  138. component.depth_and_sign = data[36 + i * 3];
  139. if (component.bit_depth() > 38)
  140. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid component depth");
  141. component.horizontal_separation = data[37 + i * 3];
  142. component.vertical_separation = data[38 + i * 3];
  143. siz.components.append(component);
  144. }
  145. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: SIZ marker segment: needed_decoder_capabilities={}, width={}, height={}, x_offset={}, y_offset={}, tile_width={}, tile_height={}, tile_x_offset={}, tile_y_offset={}", siz.needed_decoder_capabilities, siz.width, siz.height, siz.x_offset, siz.y_offset, siz.tile_width, siz.tile_height, siz.tile_x_offset, siz.tile_y_offset);
  146. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: SIZ marker segment: {} components:", component_count);
  147. for (auto [i, component] : enumerate(siz.components))
  148. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: SIZ marker segment: component[{}]: is_signed={}, bit_depth={}, horizontal_separation={}, vertical_separation={}", i, component.is_signed(), component.bit_depth(), component.horizontal_separation, component.vertical_separation);
  149. return siz;
  150. }
  151. // A.6.1 Coding style default (COD)
  152. struct CodingStyleDefault {
  153. // Table A.13 – Coding style parameter values for the Scod parameter
  154. bool has_explicit_precinct_size { false };
  155. bool may_use_SOP_marker { false };
  156. bool may_use_EPH_marker { false };
  157. // Table A.16 – Progression order for the SGcod, SPcoc, and Ppoc parameters
  158. enum ProgressionOrder {
  159. LayerResolutionComponentPosition = 0,
  160. ResolutionLayerComponentPosition = 1,
  161. ResolutionPositionComponentLayer = 2,
  162. PositionComponentResolutionLayer = 3,
  163. ComponentPositionResolutionLayer = 4,
  164. };
  165. // Table A.17 – Multiple component transformation for the SGcod parameters
  166. enum MultipleComponentTransformationType {
  167. None = 0,
  168. MultipleComponentTransformationUsed = 1, // See Annex G
  169. };
  170. // Table A.14 – Coding style parameter values of the SGcod parameter
  171. ProgressionOrder progression_order { LayerResolutionComponentPosition };
  172. u16 number_of_layers { 0 };
  173. MultipleComponentTransformationType multiple_component_transformation_type { None };
  174. // Table A.20 – Transformation for the SPcod and SPcoc parameters
  175. enum Transformation {
  176. Irreversible_9_7_Filter = 0,
  177. Reversible_5_3_Filter = 1,
  178. };
  179. // Table A.15 – Coding style parameter values of the SPcod and SPcoc parameters
  180. // "Number of decomposition levels, NL, Zero implies no transformation."
  181. u8 number_of_decomposition_levels { 0 };
  182. u8 code_block_width_exponent { 0 }; // "xcb" in spec; 2 already added.
  183. u8 code_block_height_exponent { 0 }; // "ycb" in spec; 2 already added.
  184. u8 code_block_style { 0 };
  185. Transformation transformation { Irreversible_9_7_Filter };
  186. // Table A.19 – Code-block style for the SPcod and SPcoc parameters
  187. bool uses_selective_arithmetic_coding_bypass() const { return code_block_style & 1; }
  188. bool reset_context_probabilities() const { return code_block_style & 2; }
  189. bool uses_termination_on_each_coding_pass() const { return code_block_style & 4; }
  190. bool uses_vertically_causal_context() const { return code_block_style & 8; }
  191. bool uses_predictable_termination() const { return code_block_style & 0x10; }
  192. bool uses_segmentation_symbols() const { return code_block_style & 0x20; }
  193. // If has_explicit_precinct_size is false, this contains the default { 15, 15 } number_of_decomposition_levels + 1 times.
  194. // If has_explicit_precinct_size is true, this contains number_of_decomposition_levels + 1 explicit values stored in the COD marker segment.
  195. struct PrecinctSize {
  196. u8 PPx { 0 };
  197. u8 PPy { 0 };
  198. };
  199. Vector<PrecinctSize> precinct_sizes;
  200. };
  201. static ErrorOr<CodingStyleDefault> read_coding_style_default(ReadonlyBytes data)
  202. {
  203. if (data.size() < 10)
  204. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for COD marker segment");
  205. CodingStyleDefault cod;
  206. u8 Scod = data[0];
  207. cod.has_explicit_precinct_size = Scod & 1;
  208. cod.may_use_SOP_marker = Scod & 2;
  209. cod.may_use_EPH_marker = Scod & 4;
  210. u32 SGcod = *reinterpret_cast<AK::BigEndian<u32> const*>(data.data() + 1);
  211. u8 progression_order = SGcod >> 24;
  212. if (progression_order > 4)
  213. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid progression order");
  214. cod.progression_order = static_cast<CodingStyleDefault::ProgressionOrder>(progression_order);
  215. cod.number_of_layers = (SGcod >> 8) & 0xFFFF;
  216. if (cod.number_of_layers == 0)
  217. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid number of layers");
  218. u8 multiple_component_transformation_type = SGcod & 0xFF;
  219. if (multiple_component_transformation_type > 1)
  220. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid multiple component transformation type");
  221. cod.multiple_component_transformation_type = static_cast<CodingStyleDefault::MultipleComponentTransformationType>(multiple_component_transformation_type);
  222. cod.number_of_decomposition_levels = data[5];
  223. if (cod.number_of_decomposition_levels > 32)
  224. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid number of decomposition levels");
  225. // Table A.18 – Width or height exponent of the code-blocks for the SPcod and SPcoc parameters
  226. u8 xcb = (data[6] & 0xF) + 2;
  227. u8 ycb = (data[7] & 0xF) + 2;
  228. if (xcb > 10 || ycb > 10 || xcb + ycb > 12)
  229. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid code block size");
  230. cod.code_block_width_exponent = xcb;
  231. cod.code_block_height_exponent = ycb;
  232. cod.code_block_style = data[8];
  233. u8 transformation = data[9];
  234. if (transformation > 1)
  235. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid transformation");
  236. cod.transformation = static_cast<CodingStyleDefault::Transformation>(transformation);
  237. if (cod.has_explicit_precinct_size) {
  238. if (data.size() < 10u + cod.number_of_decomposition_levels + 1u)
  239. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for COD marker segment precinct sizes");
  240. for (size_t i = 0; i < cod.number_of_decomposition_levels + 1u; ++i) {
  241. u8 b = data[10 + i];
  242. // Table A.21 – Precinct width and height for the SPcod and SPcoc parameters
  243. CodingStyleDefault::PrecinctSize precinct_size;
  244. precinct_size.PPx = b & 0xF;
  245. precinct_size.PPy = b >> 4;
  246. if ((precinct_size.PPx == 0 || precinct_size.PPy == 0) && i > 0)
  247. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid precinct size");
  248. cod.precinct_sizes.append(precinct_size);
  249. }
  250. } else {
  251. for (size_t i = 0; i < cod.number_of_decomposition_levels + 1u; ++i)
  252. cod.precinct_sizes.append({ 15, 15 });
  253. }
  254. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COD marker segment: has_explicit_precinct_size={}, may_use_SOP_marker={}, may_use_EPH_marker={}, progression_order={}, number_of_layers={}", cod.has_explicit_precinct_size, cod.may_use_SOP_marker, cod.may_use_EPH_marker, (int)cod.progression_order, cod.number_of_layers);
  255. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COD marker segment: multiple_component_transformation_type={}, number_of_decomposition_levels={}, code_block_width_exponent={}, code_block_height_exponent={}", (int)cod.multiple_component_transformation_type, cod.number_of_decomposition_levels, cod.code_block_width_exponent, cod.code_block_height_exponent);
  256. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COD marker segment: code_block_style={}, transformation={}", cod.code_block_style, (int)cod.transformation);
  257. if (cod.has_explicit_precinct_size) {
  258. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COD marker segment: {} explicit precinct sizes:", cod.precinct_sizes.size());
  259. for (auto [i, precinct_size] : enumerate(cod.precinct_sizes))
  260. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COD marker segment: precinct_size[{}]: PPx={}, PPy={}", i, precinct_size.PPx, precinct_size.PPy);
  261. }
  262. return cod;
  263. }
  264. // A.6.4 Quantization default (QCD)
  265. struct QuantizationDefault {
  266. enum QuantizationStyle {
  267. NoQuantization = 0,
  268. ScalarDerived = 1,
  269. ScalarExpounded = 2,
  270. };
  271. QuantizationStyle quantization_style { NoQuantization };
  272. u8 number_of_guard_bits { 0 };
  273. struct ReversibleStepSize {
  274. u8 exponent { 0 };
  275. };
  276. struct IrreversibleStepSize {
  277. u16 mantissa { 0 };
  278. u8 exponent { 0 };
  279. };
  280. // Stores a Vector<ReversibleStepSize> if quantization_style is NoQuantization, and a Vector<IrreversibleStepSize> otherwise.
  281. // The size of the vector is >= 3*number_of_decomposition_levels + 1 if quantization_style is not ScalarDerived, and 1 otherwise.
  282. using StepSizeType = Variant<Empty, Vector<ReversibleStepSize>, Vector<IrreversibleStepSize>>;
  283. StepSizeType step_sizes;
  284. };
  285. static ErrorOr<QuantizationDefault> read_quantization_default(ReadonlyBytes data, StringView marker_name = "QCD"sv)
  286. {
  287. if (data.size() < 1)
  288. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for COD marker segment");
  289. QuantizationDefault qcd;
  290. u8 sqcd = data[0];
  291. u8 quantization_style = sqcd & 0x1F;
  292. if (quantization_style > 2)
  293. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid quantization style");
  294. qcd.quantization_style = static_cast<QuantizationDefault::QuantizationStyle>(quantization_style);
  295. qcd.number_of_guard_bits = sqcd >> 5;
  296. qcd.step_sizes = TRY([&]() -> ErrorOr<QuantizationDefault::StepSizeType> {
  297. if (quantization_style == QuantizationDefault::NoQuantization) {
  298. // Table A.29 – Reversible step size values for the SPqcd and SPqcc parameters (reversible transform only)
  299. if (data.size() < 2)
  300. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for QCD marker segment");
  301. u8 number_of_decomposition_levels = (data.size() - 2) / 3;
  302. Vector<QuantizationDefault::ReversibleStepSize> reversible_step_sizes;
  303. for (size_t i = 0; i < 1u + 3u * number_of_decomposition_levels; ++i)
  304. reversible_step_sizes.append({ static_cast<u8>(data[1 + i] >> 3) });
  305. return reversible_step_sizes;
  306. }
  307. // Table A.30 – Quantization values for the SPqcd and SPqcc parameters (irreversible transformation only)
  308. if (data.size() < 3)
  309. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for QCD marker segment");
  310. u8 number_of_decomposition_levels = 0;
  311. if (quantization_style == QuantizationDefault::ScalarExpounded)
  312. number_of_decomposition_levels = (data.size() - 3) / 6;
  313. Vector<QuantizationDefault::IrreversibleStepSize> irreversible_step_sizes;
  314. for (size_t i = 0; i < 1u + 3u * number_of_decomposition_levels; ++i) {
  315. u16 value = *reinterpret_cast<AK::BigEndian<u16> const*>(data.data() + 1 + i * 2);
  316. QuantizationDefault::IrreversibleStepSize step_size;
  317. step_size.mantissa = value & 0x7FF;
  318. step_size.exponent = value >> 11;
  319. irreversible_step_sizes.append(step_size);
  320. }
  321. return irreversible_step_sizes;
  322. }());
  323. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: {} marker segment: quantization_style={}, number_of_guard_bits={}", marker_name, (int)qcd.quantization_style, qcd.number_of_guard_bits);
  324. qcd.step_sizes.visit(
  325. [](Empty) { VERIFY_NOT_REACHED(); },
  326. [&](Vector<QuantizationDefault::ReversibleStepSize> const& step_sizes) {
  327. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: {} marker segment: {} step sizes:", marker_name, step_sizes.size());
  328. for (auto [i, step_size] : enumerate(step_sizes)) {
  329. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: {} marker segment: step_size[{}]: exponent={}", marker_name, i, step_size.exponent);
  330. }
  331. },
  332. [&](Vector<QuantizationDefault::IrreversibleStepSize> const& step_sizes) {
  333. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: {} marker segment: {} step sizes:", marker_name, step_sizes.size());
  334. for (auto [i, step_size] : enumerate(step_sizes)) {
  335. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: {} marker segment: step_size[{}]: mantissa={}, exponent={}", marker_name, i, step_size.mantissa, step_size.exponent);
  336. }
  337. });
  338. return qcd;
  339. }
  340. // A.6.5 Quantization component (QCC)
  341. struct QuantizationComponent {
  342. u16 component_index { 0 }; // "Cqcc" in spec.
  343. QuantizationDefault qcd;
  344. };
  345. static ErrorOr<QuantizationComponent> read_quantization_component(ReadonlyBytes data, size_t number_of_components)
  346. {
  347. size_t cqcc_size = number_of_components < 257 ? 1 : 2;
  348. if (data.size() < cqcc_size)
  349. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for QCC marker segment");
  350. QuantizationComponent qcc;
  351. if (number_of_components < 257)
  352. qcc.component_index = data[0];
  353. else
  354. qcc.component_index = *reinterpret_cast<AK::BigEndian<u16> const*>(data.data());
  355. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: QCC marker segment: component_index={}", qcc.component_index);
  356. qcc.qcd = TRY(read_quantization_default(data.slice(cqcc_size), "QCC"sv));
  357. return qcc;
  358. }
  359. // A.9.2 Comment (COM)
  360. struct Comment {
  361. enum CommentType {
  362. Binary = 0,
  363. ISO_IEC_8859_15 = 1,
  364. };
  365. CommentType type { Binary }; // "Rcom" in spec.
  366. ReadonlyBytes data;
  367. };
  368. static ErrorOr<Comment> read_comment(ReadonlyBytes data)
  369. {
  370. if (data.size() < 2)
  371. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for COM marker segment");
  372. Comment com;
  373. u16 comment_type = *reinterpret_cast<AK::BigEndian<u16> const*>(data.data());
  374. if (comment_type > 1)
  375. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid comment type");
  376. com.type = static_cast<Comment::CommentType>(comment_type);
  377. com.data = data.slice(1);
  378. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COM marker segment: comment_type={}, size()={}", (int)com.type, com.data.size());
  379. if (com.type == Comment::ISO_IEC_8859_15)
  380. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: COM marker segment, ISO/IEC 8859-15 text: '{}'", TRY(TextCodec::decoder_for("ISO-8859-1"sv)->to_utf8(StringView { com.data })));
  381. return com;
  382. }
  383. struct TilePartData {
  384. StartOfTilePart sot;
  385. Vector<Comment> coms;
  386. ReadonlyBytes data;
  387. };
  388. struct TileData {
  389. Optional<QuantizationDefault> qcd;
  390. Vector<QuantizationComponent> qccs;
  391. Vector<TilePartData> tile_parts;
  392. };
  393. struct JPEG2000LoadingContext {
  394. enum class State {
  395. NotDecoded = 0,
  396. DecodedTileHeaders,
  397. Error,
  398. };
  399. State state { State::NotDecoded };
  400. ReadonlyBytes codestream_data;
  401. size_t codestream_cursor { 0 };
  402. Optional<ReadonlyBytes> icc_data;
  403. IntSize size;
  404. ISOBMFF::BoxList boxes;
  405. // Data from marker segments:
  406. ImageAndTileSize siz;
  407. CodingStyleDefault cod;
  408. QuantizationDefault qcd;
  409. Vector<QuantizationComponent> qccs;
  410. Vector<Comment> coms;
  411. Vector<TileData> tiles;
  412. };
  413. struct MarkerSegment {
  414. u16 marker;
  415. // OptionalNone for markers that don't have data.
  416. // For markers that do have data, this does not include the marker length data. (`data.size() + 2` is the value of the marker length field.)
  417. Optional<ReadonlyBytes> data;
  418. };
  419. static ErrorOr<u16> peek_marker(JPEG2000LoadingContext& context)
  420. {
  421. if (context.codestream_cursor + 2 > context.codestream_data.size())
  422. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for marker");
  423. return *reinterpret_cast<AK::BigEndian<u16> const*>(context.codestream_data.data() + context.codestream_cursor);
  424. }
  425. static ErrorOr<MarkerSegment> read_marker_at_cursor(JPEG2000LoadingContext& context)
  426. {
  427. u16 marker = TRY(peek_marker(context));
  428. // "All markers with the marker code between 0xFF30 and 0xFF3F have no marker segment parameters. They shall be skipped by the decoder."
  429. // "The SOC, SOD and EOC are delimiting markers not marker segments, and have no explicit length information or other parameters."
  430. bool is_marker_segment = !(marker >= 0xFF30 && marker <= 0xFF3F) && marker != J2K_SOC && marker != J2K_SOD && marker != J2K_EOC;
  431. MarkerSegment marker_segment;
  432. marker_segment.marker = marker;
  433. if (is_marker_segment) {
  434. if (context.codestream_cursor + 4 > context.codestream_data.size())
  435. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for marker segment length");
  436. u16 marker_length = *reinterpret_cast<AK::BigEndian<u16> const*>(context.codestream_data.data() + context.codestream_cursor + 2);
  437. if (marker_length < 2)
  438. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Marker segment length too small");
  439. if (context.codestream_cursor + 2 + marker_length > context.codestream_data.size())
  440. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for marker segment data");
  441. marker_segment.data = ReadonlyBytes { context.codestream_data.data() + context.codestream_cursor + 4, marker_length - 2u };
  442. }
  443. context.codestream_cursor += 2;
  444. if (is_marker_segment)
  445. context.codestream_cursor += 2 + marker_segment.data->size();
  446. return marker_segment;
  447. }
  448. static ErrorOr<void> parse_codestream_main_header(JPEG2000LoadingContext& context)
  449. {
  450. // Figure A.3 – Construction of the main header
  451. // "Required as the first marker"
  452. auto marker = TRY(read_marker_at_cursor(context));
  453. if (marker.marker != J2K_SOC)
  454. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected SOC marker");
  455. // "Required as the second marker segment"
  456. marker = TRY(read_marker_at_cursor(context));
  457. if (marker.marker != J2K_SIZ)
  458. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected SIZ marker");
  459. context.siz = TRY(read_image_and_tile_size(marker.data.value()));
  460. bool saw_COD_marker = false;
  461. bool saw_QCD_marker = false;
  462. while (true) {
  463. u16 marker = TRY(peek_marker(context));
  464. switch (marker) {
  465. case J2K_COD:
  466. case J2K_COC:
  467. case J2K_QCD:
  468. case J2K_QCC:
  469. case J2K_RGN:
  470. case J2K_POC:
  471. case J2K_PPM:
  472. case J2K_TLM:
  473. case J2K_PLM:
  474. case J2K_CRG:
  475. case J2K_COM: {
  476. auto marker = TRY(read_marker_at_cursor(context));
  477. if (marker.marker == J2K_COD) {
  478. if (saw_COD_marker)
  479. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Multiple COD markers in main header");
  480. context.cod = TRY(read_coding_style_default(marker.data.value()));
  481. saw_COD_marker = true;
  482. } else if (marker.marker == J2K_QCD) {
  483. if (saw_QCD_marker)
  484. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Multiple QCD markers in main header");
  485. context.qcd = TRY(read_quantization_default(marker.data.value()));
  486. saw_QCD_marker = true;
  487. } else if (marker.marker == J2K_QCC) {
  488. context.qccs.append(TRY(read_quantization_component(marker.data.value(), context.siz.components.size())));
  489. } else if (marker.marker == J2K_COM) {
  490. context.coms.append(TRY(read_comment(marker.data.value())));
  491. } else {
  492. // FIXME: These are valid main header markers. Parse contents.
  493. dbgln("JPEG2000ImageDecoderPlugin: marker {:#04x} not yet implemented", marker.marker);
  494. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: marker not yet implemented");
  495. }
  496. break;
  497. }
  498. case J2K_SOT: {
  499. // SOT terminates the main header.
  500. // A.4.2: "There shall be at least one SOT in a codestream."
  501. if (!saw_COD_marker)
  502. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Required COD marker not present in main header");
  503. if (!saw_QCD_marker)
  504. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Required QCD marker not present in main header");
  505. // A.6.4: "there is not necessarily a correspondence with the number of sub-bands present because the sub-bands
  506. // can be truncated with no requirement to correct [the QCD] marker segment."
  507. size_t step_sizes_count = context.qcd.step_sizes.visit(
  508. [](Empty) -> size_t { VERIFY_NOT_REACHED(); },
  509. [](Vector<QuantizationDefault::ReversibleStepSize> const& step_sizes) { return step_sizes.size(); },
  510. [](Vector<QuantizationDefault::IrreversibleStepSize> const& step_sizes) { return step_sizes.size(); });
  511. if (context.qcd.quantization_style != QuantizationDefault::ScalarDerived && step_sizes_count < context.cod.number_of_decomposition_levels * 3u + 1u)
  512. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough step sizes for number of decomposition levels");
  513. return {};
  514. }
  515. default:
  516. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Unexpected marker in main header");
  517. }
  518. }
  519. }
  520. static ErrorOr<void> parse_codestream_tile_header(JPEG2000LoadingContext& context)
  521. {
  522. // Figure A.4 – Construction of the first tile-part header of a given tile
  523. // Figure A.5 – Construction of a non-first tile-part header
  524. // "Required as the first marker segment of every tile-part header"
  525. auto tile_start = context.codestream_cursor;
  526. auto marker = TRY(read_marker_at_cursor(context));
  527. if (marker.marker != J2K_SOT)
  528. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected SOT marker");
  529. auto start_of_tile = TRY(read_start_of_tile_part(marker.data.value()));
  530. // FIXME: Store start_of_tile on context somewhere.
  531. context.tiles.resize(max(context.tiles.size(), (size_t)start_of_tile.tile_index + 1));
  532. auto& tile = context.tiles[start_of_tile.tile_index];
  533. if (tile.tile_parts.size() != start_of_tile.tile_part_index)
  534. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Tile part index out of order");
  535. tile.tile_parts.append({});
  536. auto& tile_part = tile.tile_parts.last();
  537. tile_part.sot = start_of_tile;
  538. bool found_start_of_data = false;
  539. while (!found_start_of_data) {
  540. u16 marker = TRY(peek_marker(context));
  541. switch (marker) {
  542. case J2K_SOD:
  543. // "Required as the last marker segment of every tile-part header"
  544. context.codestream_cursor += 2;
  545. found_start_of_data = true;
  546. break;
  547. case J2K_COD:
  548. case J2K_COC:
  549. case J2K_QCD:
  550. case J2K_QCC:
  551. case J2K_RGN:
  552. if (start_of_tile.tile_part_index != 0)
  553. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: COD, COC, QCD, QCC, RGN markers are only valid in the first tile-part header");
  554. [[fallthrough]];
  555. case J2K_POC:
  556. case J2K_PPT:
  557. case J2K_PLT:
  558. case J2K_COM: {
  559. auto marker = TRY(read_marker_at_cursor(context));
  560. if (marker.marker == J2K_QCD) {
  561. if (tile.qcd.has_value())
  562. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Multiple QCD markers in tile header");
  563. tile.qcd = TRY(read_quantization_default(marker.data.value()));
  564. } else if (marker.marker == J2K_QCC) {
  565. tile.qccs.append(TRY(read_quantization_component(marker.data.value(), context.siz.components.size())));
  566. } else if (marker.marker == J2K_COM) {
  567. tile_part.coms.append(TRY(read_comment(marker.data.value())));
  568. } else {
  569. // FIXME: These are valid main header markers. Parse contents.
  570. dbgln("JPEG2000ImageDecoderPlugin: marker {:#04x} not yet implemented in tile header", marker.marker);
  571. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: marker not yet implemented in tile header");
  572. }
  573. break;
  574. }
  575. default:
  576. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Unexpected marker in tile header");
  577. }
  578. }
  579. u32 tile_bitstream_length;
  580. if (start_of_tile.tile_part_length == 0) {
  581. // Leave room for EOC marker.
  582. if (context.codestream_data.size() - context.codestream_cursor < 2)
  583. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for EOC marker");
  584. tile_bitstream_length = context.codestream_data.size() - context.codestream_cursor - 2;
  585. } else {
  586. u32 tile_header_length = context.codestream_cursor - tile_start;
  587. if (start_of_tile.tile_part_length < tile_header_length)
  588. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid tile part length");
  589. tile_bitstream_length = start_of_tile.tile_part_length - tile_header_length;
  590. }
  591. if (context.codestream_cursor + tile_bitstream_length > context.codestream_data.size())
  592. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Not enough data for tile bitstream");
  593. tile_part.data = context.codestream_data.slice(context.codestream_cursor, tile_bitstream_length);
  594. context.codestream_cursor += tile_bitstream_length;
  595. dbgln_if(JPEG2000_DEBUG, "JPEG2000ImageDecoderPlugin: Tile bitstream length: {}", tile_bitstream_length);
  596. return {};
  597. }
  598. static ErrorOr<void> parse_codestream_tile_headers(JPEG2000LoadingContext& context)
  599. {
  600. while (true) {
  601. auto marker = TRY(peek_marker(context));
  602. if (marker == J2K_EOC) {
  603. context.codestream_cursor += 2;
  604. break;
  605. }
  606. TRY(parse_codestream_tile_header(context));
  607. }
  608. if (context.codestream_cursor < context.codestream_data.size())
  609. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Unexpected data after EOC marker");
  610. return {};
  611. }
  612. static ErrorOr<void> decode_jpeg2000_header(JPEG2000LoadingContext& context, ReadonlyBytes data)
  613. {
  614. if (!JPEG2000ImageDecoderPlugin::sniff(data))
  615. return Error::from_string_literal("JPEG2000LoadingContext: Invalid JPEG2000 header");
  616. auto reader = TRY(Gfx::ISOBMFF::Reader::create(TRY(try_make<FixedMemoryStream>(data))));
  617. context.boxes = TRY(reader.read_entire_file());
  618. // I.2.2 File organization
  619. // "A particular order of those boxes in the file is not generally implied. However, the JPEG 2000 Signature box
  620. // shall be the first box in a JP2 file, the File Type box shall immediately follow the JPEG 2000 Signature box
  621. // and the JP2 Header box shall fall before the Contiguous Codestream box."
  622. if (context.boxes.size() < 4)
  623. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected at least four boxes");
  624. // Required toplevel boxes: signature box, file type box, jp2 header box, contiguous codestream box.
  625. if (context.boxes[0]->box_type() != ISOBMFF::BoxType::JPEG2000SignatureBox)
  626. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected JPEG2000SignatureBox as first box");
  627. if (context.boxes[1]->box_type() != ISOBMFF::BoxType::FileTypeBox)
  628. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected FileTypeBox as second box");
  629. Optional<size_t> jp2_header_box_index;
  630. Optional<size_t> contiguous_codestream_box_index;
  631. for (size_t i = 2; i < context.boxes.size(); ++i) {
  632. if (context.boxes[i]->box_type() == ISOBMFF::BoxType::JPEG2000HeaderBox) {
  633. // "Within a JP2 file, there shall be one and only one JP2 Header box."
  634. if (jp2_header_box_index.has_value())
  635. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Multiple JP2 Header boxes");
  636. jp2_header_box_index = i;
  637. }
  638. if (context.boxes[i]->box_type() == ISOBMFF::BoxType::JPEG2000ContiguousCodestreamBox && !contiguous_codestream_box_index.has_value()) {
  639. // "a conforming reader shall ignore all codestreams after the first codestream found in the file.
  640. // Contiguous Codestream boxes may be found anywhere in the file except before the JP2 Header box."
  641. contiguous_codestream_box_index = i;
  642. if (!jp2_header_box_index.has_value() || contiguous_codestream_box_index.value() < jp2_header_box_index.value())
  643. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: JP2 Header box must come before Contiguous Codestream box");
  644. }
  645. }
  646. if (!jp2_header_box_index.has_value())
  647. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected JP2 Header box");
  648. if (!contiguous_codestream_box_index.has_value())
  649. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected Contiguous Codestream box");
  650. // FIXME: JPEG2000ContiguousCodestreamBox makes a copy of the codestream data. That's too heavy for header scanning.
  651. // Add a mode to ISOBMFF::Reader where it only stores offsets for the codestream data and the ICC profile.
  652. auto const& codestream_box = static_cast<ISOBMFF::JPEG2000ContiguousCodestreamBox const&>(*context.boxes[contiguous_codestream_box_index.value()]);
  653. context.codestream_data = codestream_box.codestream.bytes();
  654. // Required child boxes of the jp2 header box: image header box, color box.
  655. Optional<size_t> image_header_box_index;
  656. Optional<size_t> color_header_box_index;
  657. auto const& header_box = static_cast<ISOBMFF::JPEG2000HeaderBox const&>(*context.boxes[jp2_header_box_index.value()]);
  658. for (size_t i = 0; i < header_box.child_boxes().size(); ++i) {
  659. auto const& subbox = header_box.child_boxes()[i];
  660. if (subbox->box_type() == ISOBMFF::BoxType::JPEG2000ImageHeaderBox) {
  661. if (image_header_box_index.has_value())
  662. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Multiple Image Header boxes");
  663. image_header_box_index = i;
  664. }
  665. if (subbox->box_type() == ISOBMFF::BoxType::JPEG2000ColorSpecificationBox) {
  666. // T.800 says there should be just one 'colr' box, but T.801 allows several and says to pick the one with highest precedence.
  667. bool use_this_color_box;
  668. if (!color_header_box_index.has_value()) {
  669. use_this_color_box = true;
  670. } else {
  671. auto const& new_header_box = static_cast<ISOBMFF::JPEG2000ColorSpecificationBox const&>(*header_box.child_boxes()[i]);
  672. auto const& current_color_box = static_cast<ISOBMFF::JPEG2000ColorSpecificationBox const&>(*header_box.child_boxes()[color_header_box_index.value()]);
  673. use_this_color_box = new_header_box.precedence > current_color_box.precedence;
  674. }
  675. if (use_this_color_box)
  676. color_header_box_index = i;
  677. }
  678. }
  679. if (!image_header_box_index.has_value())
  680. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected Image Header box");
  681. if (!color_header_box_index.has_value())
  682. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Expected Color Specification box");
  683. auto const& image_header_box = static_cast<ISOBMFF::JPEG2000ImageHeaderBox const&>(*header_box.child_boxes()[image_header_box_index.value()]);
  684. context.size = { image_header_box.width, image_header_box.height };
  685. auto const& color_header_box = static_cast<ISOBMFF::JPEG2000ColorSpecificationBox const&>(*header_box.child_boxes()[color_header_box_index.value()]);
  686. if (color_header_box.method == 2 || color_header_box.method == 3)
  687. context.icc_data = color_header_box.icc_data.bytes();
  688. TRY(parse_codestream_main_header(context));
  689. return {};
  690. }
  691. bool JPEG2000ImageDecoderPlugin::sniff(ReadonlyBytes data)
  692. {
  693. return data.starts_with(jp2_id_string);
  694. }
  695. JPEG2000ImageDecoderPlugin::JPEG2000ImageDecoderPlugin()
  696. {
  697. m_context = make<JPEG2000LoadingContext>();
  698. }
  699. IntSize JPEG2000ImageDecoderPlugin::size()
  700. {
  701. return m_context->size;
  702. }
  703. ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> JPEG2000ImageDecoderPlugin::create(ReadonlyBytes data)
  704. {
  705. auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) JPEG2000ImageDecoderPlugin()));
  706. TRY(decode_jpeg2000_header(*plugin->m_context, data));
  707. return plugin;
  708. }
  709. ErrorOr<ImageFrameDescriptor> JPEG2000ImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
  710. {
  711. if (index != 0)
  712. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Invalid frame index");
  713. if (m_context->state == JPEG2000LoadingContext::State::Error)
  714. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Decoding failed");
  715. if (m_context->state < JPEG2000LoadingContext::State::DecodedTileHeaders) {
  716. TRY(parse_codestream_tile_headers(*m_context));
  717. m_context->state = JPEG2000LoadingContext::State::DecodedTileHeaders;
  718. }
  719. return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Draw the rest of the owl");
  720. }
  721. ErrorOr<Optional<ReadonlyBytes>> JPEG2000ImageDecoderPlugin::icc_data()
  722. {
  723. return m_context->icc_data;
  724. }
  725. }