JPEGXLLoader.cpp 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. /*
  2. * Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/BitStream.h>
  7. #include <AK/Endian.h>
  8. #include <AK/FixedArray.h>
  9. #include <AK/String.h>
  10. #include <LibCompress/Brotli.h>
  11. #include <LibGfx/ImageFormats/JPEGXLLoader.h>
  12. namespace Gfx {
  13. /// 4.2 - Functions
  14. static ALWAYS_INLINE i32 unpack_signed(u32 u)
  15. {
  16. if (u % 2 == 0)
  17. return static_cast<i32>(u / 2);
  18. return -static_cast<i32>((u + 1) / 2);
  19. }
  20. ///
  21. /// B.2 - Field types
  22. // This is defined as a macro in order to get lazy-evaluated parameter
  23. // Note that the lambda will capture your context by reference.
  24. #define U32(d0, d1, d2, d3) \
  25. ({ \
  26. u8 const selector = TRY(stream.read_bits(2)); \
  27. auto value = [&, selector]() -> ErrorOr<u32> { \
  28. if (selector == 0) \
  29. return (d0); \
  30. if (selector == 1) \
  31. return (d1); \
  32. if (selector == 2) \
  33. return (d2); \
  34. if (selector == 3) \
  35. return (d3); \
  36. VERIFY_NOT_REACHED(); \
  37. }(); \
  38. TRY(value); \
  39. })
  40. static ALWAYS_INLINE ErrorOr<u64> U64(LittleEndianInputBitStream& stream)
  41. {
  42. u8 const selector = TRY(stream.read_bits(2));
  43. if (selector == 0)
  44. return 0;
  45. if (selector == 1)
  46. return 1 + TRY(stream.read_bits(4));
  47. if (selector == 2)
  48. return 17 + TRY(stream.read_bits(8));
  49. VERIFY(selector == 3);
  50. u64 value = TRY(stream.read_bits(12));
  51. u8 shift = 12;
  52. while (TRY(stream.read_bits(1)) == 1) {
  53. if (shift == 60) {
  54. value += TRY(stream.read_bits(4)) << shift;
  55. break;
  56. }
  57. value += TRY(stream.read_bits(8)) << shift;
  58. shift += 8;
  59. }
  60. return value;
  61. }
  62. ///
  63. /// D.2 - Image dimensions
  64. struct SizeHeader {
  65. u32 height {};
  66. u32 width {};
  67. };
  68. static u32 aspect_ratio(u32 height, u32 ratio)
  69. {
  70. if (ratio == 1)
  71. return height;
  72. if (ratio == 2)
  73. return height * 12 / 10;
  74. if (ratio == 3)
  75. return height * 4 / 3;
  76. if (ratio == 4)
  77. return height * 3 / 2;
  78. if (ratio == 5)
  79. return height * 16 / 9;
  80. if (ratio == 6)
  81. return height * 5 / 4;
  82. if (ratio == 7)
  83. return height * 2 / 1;
  84. VERIFY_NOT_REACHED();
  85. }
  86. static ErrorOr<SizeHeader> read_size_header(LittleEndianInputBitStream& stream)
  87. {
  88. SizeHeader size {};
  89. auto const div8 = TRY(stream.read_bit());
  90. if (div8) {
  91. auto const h_div8 = 1 + TRY(stream.read_bits(5));
  92. size.height = 8 * h_div8;
  93. } else {
  94. size.height = U32(
  95. 1 + TRY(stream.read_bits(9)),
  96. 1 + TRY(stream.read_bits(13)),
  97. 1 + TRY(stream.read_bits(18)),
  98. 1 + TRY(stream.read_bits(30)));
  99. }
  100. auto const ratio = TRY(stream.read_bits(3));
  101. if (ratio == 0) {
  102. if (div8) {
  103. auto const w_div8 = 1 + TRY(stream.read_bits(5));
  104. size.width = 8 * w_div8;
  105. } else {
  106. size.width = U32(
  107. 1 + TRY(stream.read_bits(9)),
  108. 1 + TRY(stream.read_bits(13)),
  109. 1 + TRY(stream.read_bits(18)),
  110. 1 + TRY(stream.read_bits(30)));
  111. }
  112. } else {
  113. size.width = aspect_ratio(size.height, ratio);
  114. }
  115. return size;
  116. }
  117. ///
  118. /// D.3.5 - BitDepth
  119. struct BitDepth {
  120. u32 bits_per_sample { 8 };
  121. u8 exp_bits {};
  122. };
  123. static ErrorOr<BitDepth> read_bit_depth(LittleEndianInputBitStream& stream)
  124. {
  125. BitDepth bit_depth;
  126. bool const float_sample = TRY(stream.read_bit());
  127. if (float_sample) {
  128. bit_depth.bits_per_sample = U32(32, 16, 24, 1 + TRY(stream.read_bits(6)));
  129. bit_depth.exp_bits = 1 + TRY(stream.read_bits(4));
  130. } else {
  131. bit_depth.bits_per_sample = U32(8, 10, 12, 1 + TRY(stream.read_bits(6)));
  132. }
  133. return bit_depth;
  134. }
  135. ///
  136. /// E.2 - ColourEncoding
  137. struct ColourEncoding {
  138. enum class ColourSpace {
  139. kRGB = 0,
  140. kGrey = 1,
  141. kXYB = 2,
  142. kUnknown = 3,
  143. };
  144. enum class WhitePoint {
  145. kD65 = 1,
  146. kCustom = 2,
  147. kE = 10,
  148. kDCI = 11,
  149. };
  150. enum class Primaries {
  151. kSRGB = 1,
  152. kCustom = 2,
  153. k2100 = 3,
  154. kP3 = 11,
  155. };
  156. enum class RenderingIntent {
  157. kPerceptual = 0,
  158. kRelative = 1,
  159. kSaturation = 2,
  160. kAbsolute = 3,
  161. };
  162. struct Customxy {
  163. u32 ux {};
  164. u32 uy {};
  165. };
  166. bool want_icc = false;
  167. ColourSpace colour_space { ColourSpace::kRGB };
  168. WhitePoint white_point { WhitePoint::kD65 };
  169. Primaries primaries { Primaries::kSRGB };
  170. Customxy white {};
  171. Customxy red {};
  172. Customxy green {};
  173. Customxy blue {};
  174. RenderingIntent rendering_intent { RenderingIntent::kRelative };
  175. };
  176. [[maybe_unused]] static ErrorOr<ColourEncoding::Customxy> read_custom_xy(LittleEndianInputBitStream& stream)
  177. {
  178. ColourEncoding::Customxy custom_xy;
  179. auto const read_custom = [&stream]() -> ErrorOr<u32> {
  180. return U32(
  181. TRY(stream.read_bits(19)),
  182. 524288 + TRY(stream.read_bits(19)),
  183. 1048576 + TRY(stream.read_bits(20)),
  184. 2097152 + TRY(stream.read_bits(21)));
  185. };
  186. custom_xy.ux = TRY(read_custom());
  187. custom_xy.uy = TRY(read_custom());
  188. return custom_xy;
  189. }
  190. static ErrorOr<ColourEncoding> read_colour_encoding(LittleEndianInputBitStream& stream)
  191. {
  192. ColourEncoding colour_encoding;
  193. bool const all_default = TRY(stream.read_bit());
  194. if (!all_default) {
  195. TODO();
  196. }
  197. return colour_encoding;
  198. }
  199. ///
  200. /// B.3 - Extensions
  201. struct Extensions {
  202. u64 extensions {};
  203. };
  204. static ErrorOr<Extensions> read_extensions(LittleEndianInputBitStream& stream)
  205. {
  206. Extensions extensions;
  207. extensions.extensions = TRY(U64(stream));
  208. if (extensions.extensions != 0)
  209. TODO();
  210. return extensions;
  211. }
  212. ///
  213. /// K.2 - Non-separable upsampling
  214. Array s_d_up2 {
  215. -0.01716200, -0.03452303, -0.04022174, -0.02921014, -0.00624645,
  216. 0.14111091, 0.28896755, 0.00278718, -0.01610267, 0.56661550,
  217. 0.03777607, -0.01986694, -0.03144731, -0.01185068, -0.00213539
  218. };
  219. Array s_d_up4 = {
  220. -0.02419067, -0.03491987, -0.03693351, -0.03094285, -0.00529785,
  221. -0.01663432, -0.03556863, -0.03888905, -0.03516850, -0.00989469,
  222. 0.23651958, 0.33392945, -0.01073543, -0.01313181, -0.03556694,
  223. 0.13048175, 0.40103025, 0.03951150, -0.02077584, 0.46914198,
  224. -0.00209270, -0.01484589, -0.04064806, 0.18942530, 0.56279892,
  225. 0.06674400, -0.02335494, -0.03551682, -0.00754830, -0.02267919,
  226. -0.02363578, 0.00315804, -0.03399098, -0.01359519, -0.00091653,
  227. -0.00335467, -0.01163294, -0.01610294, -0.00974088, -0.00191622,
  228. -0.01095446, -0.03198464, -0.04455121, -0.02799790, -0.00645912,
  229. 0.06390599, 0.22963888, 0.00630981, -0.01897349, 0.67537268,
  230. 0.08483369, -0.02534994, -0.02205197, -0.01667999, -0.00384443
  231. };
  232. Array s_d_up8 {
  233. -0.02928613, -0.03706353, -0.03783812, -0.03324558, -0.00447632, -0.02519406, -0.03752601, -0.03901508, -0.03663285, -0.00646649,
  234. -0.02066407, -0.03838633, -0.04002101, -0.03900035, -0.00901973, -0.01626393, -0.03954148, -0.04046620, -0.03979621, -0.01224485,
  235. 0.29895328, 0.35757708, -0.02447552, -0.01081748, -0.04314594, 0.23903219, 0.41119301, -0.00573046, -0.01450239, -0.04246845,
  236. 0.17567618, 0.45220643, 0.02287757, -0.01936783, -0.03583255, 0.11572472, 0.47416733, 0.06284440, -0.02685066, 0.42720050,
  237. -0.02248939, -0.01155273, -0.04562755, 0.28689496, 0.49093869, -0.00007891, -0.01545926, -0.04562659, 0.21238920, 0.53980934,
  238. 0.03369474, -0.02070211, -0.03866988, 0.14229550, 0.56593398, 0.08045181, -0.02888298, -0.03680918, -0.00542229, -0.02920477,
  239. -0.02788574, -0.02118180, -0.03942402, -0.00775547, -0.02433614, -0.03193943, -0.02030828, -0.04044014, -0.01074016, -0.01930822,
  240. -0.03620399, -0.01974125, -0.03919545, -0.01456093, -0.00045072, -0.00360110, -0.01020207, -0.01231907, -0.00638988, -0.00071592,
  241. -0.00279122, -0.00957115, -0.01288327, -0.00730937, -0.00107783, -0.00210156, -0.00890705, -0.01317668, -0.00813895, -0.00153491,
  242. -0.02128481, -0.04173044, -0.04831487, -0.03293190, -0.00525260, -0.01720322, -0.04052736, -0.05045706, -0.03607317, -0.00738030,
  243. -0.01341764, -0.03965629, -0.05151616, -0.03814886, -0.01005819, 0.18968273, 0.33063684, -0.01300105, -0.01372950, -0.04017465,
  244. 0.13727832, 0.36402234, 0.01027890, -0.01832107, -0.03365072, 0.08734506, 0.38194295, 0.04338228, -0.02525993, 0.56408126,
  245. 0.00458352, -0.01648227, -0.04887868, 0.24585519, 0.62026135, 0.04314807, -0.02213737, -0.04158014, 0.16637289, 0.65027023,
  246. 0.09621636, -0.03101388, -0.04082742, -0.00904519, -0.02790922, -0.02117818, 0.00798662, -0.03995711, -0.01243427, -0.02231705,
  247. -0.02946266, 0.00992055, -0.03600283, -0.01684920, -0.00111684, -0.00411204, -0.01297130, -0.01723725, -0.01022545, -0.00165306,
  248. -0.00313110, -0.01218016, -0.01763266, -0.01125620, -0.00231663, -0.01374149, -0.03797620, -0.05142937, -0.03117307, -0.00581914,
  249. -0.01064003, -0.03608089, -0.05272168, -0.03375670, -0.00795586, 0.09628104, 0.27129991, -0.00353779, -0.01734151, -0.03153981,
  250. 0.05686230, 0.28500998, 0.02230594, -0.02374955, 0.68214326, 0.05018048, -0.02320852, -0.04383616, 0.18459474, 0.71517975,
  251. 0.10805613, -0.03263677, -0.03637639, -0.01394373, -0.02511203, -0.01728636, 0.05407331, -0.02867568, -0.01893131, -0.00240854,
  252. -0.00446511, -0.01636187, -0.02377053, -0.01522848, -0.00333334, -0.00819975, -0.02964169, -0.04499287, -0.02745350, -0.00612408,
  253. 0.02727416, 0.19446600, 0.00159832, -0.02232473, 0.74982506, 0.11452620, -0.03348048, -0.01605681, -0.02070339, -0.00458223
  254. };
  255. ///
  256. /// D.3 - Image metadata
  257. struct PreviewHeader {
  258. };
  259. struct AnimationHeader {
  260. };
  261. struct ExtraChannelInfo {
  262. };
  263. static ErrorOr<ExtraChannelInfo> read_extra_channel_info(LittleEndianInputBitStream&)
  264. {
  265. TODO();
  266. }
  267. struct ToneMapping {
  268. };
  269. static ErrorOr<ToneMapping> read_tone_mapping(LittleEndianInputBitStream&)
  270. {
  271. TODO();
  272. }
  273. struct OpsinInverseMatrix {
  274. };
  275. static ErrorOr<OpsinInverseMatrix> read_opsin_inverse_matrix(LittleEndianInputBitStream&)
  276. {
  277. TODO();
  278. }
  279. struct ImageMetadata {
  280. u8 orientation { 1 };
  281. Optional<SizeHeader> intrinsic_size;
  282. Optional<PreviewHeader> preview;
  283. Optional<AnimationHeader> animation;
  284. BitDepth bit_depth;
  285. bool modular_16bit_buffers { true };
  286. u16 num_extra_channels {};
  287. Vector<ExtraChannelInfo, 4> ec_info;
  288. bool xyb_encoded { true };
  289. ColourEncoding colour_encoding;
  290. ToneMapping tone_mapping;
  291. Extensions extensions;
  292. bool default_m;
  293. OpsinInverseMatrix opsin_inverse_matrix;
  294. u8 cw_mask { 0 };
  295. Array<double, 15> up2_weight = s_d_up2;
  296. Array<double, 55> up4_weight = s_d_up4;
  297. Array<double, 210> up8_weight = s_d_up8;
  298. };
  299. static ErrorOr<ImageMetadata> read_metadata_header(LittleEndianInputBitStream& stream)
  300. {
  301. ImageMetadata metadata;
  302. bool const all_default = TRY(stream.read_bit());
  303. if (!all_default) {
  304. bool const extra_fields = TRY(stream.read_bit());
  305. if (extra_fields) {
  306. metadata.orientation = 1 + TRY(stream.read_bits(3));
  307. bool const have_intr_size = TRY(stream.read_bit());
  308. if (have_intr_size)
  309. metadata.intrinsic_size = TRY(read_size_header(stream));
  310. bool const have_preview = TRY(stream.read_bit());
  311. if (have_preview)
  312. TODO();
  313. bool const have_animation = TRY(stream.read_bit());
  314. if (have_animation)
  315. TODO();
  316. }
  317. metadata.bit_depth = TRY(read_bit_depth(stream));
  318. metadata.modular_16bit_buffers = TRY(stream.read_bit());
  319. metadata.num_extra_channels = U32(0, 1, 2 + TRY(stream.read_bits(4)), 1 + TRY(stream.read_bits(12)));
  320. for (u16 i {}; i < metadata.num_extra_channels; ++i)
  321. metadata.ec_info.append(TRY(read_extra_channel_info(stream)));
  322. metadata.xyb_encoded = TRY(stream.read_bit());
  323. metadata.colour_encoding = TRY(read_colour_encoding(stream));
  324. if (extra_fields)
  325. metadata.tone_mapping = TRY(read_tone_mapping(stream));
  326. metadata.extensions = TRY(read_extensions(stream));
  327. }
  328. metadata.default_m = TRY(stream.read_bit());
  329. if (!metadata.default_m && metadata.xyb_encoded)
  330. metadata.opsin_inverse_matrix = TRY(read_opsin_inverse_matrix(stream));
  331. if (!metadata.default_m)
  332. metadata.cw_mask = TRY(stream.read_bits(3));
  333. if (metadata.cw_mask != 0)
  334. TODO();
  335. return metadata;
  336. }
  337. ///
  338. /// Table F.7 — BlendingInfo bundle
  339. struct BlendingInfo {
  340. enum class BlendMode {
  341. kReplace = 0,
  342. kAdd = 1,
  343. kBlend = 2,
  344. kMulAdd = 3,
  345. kMul = 4,
  346. };
  347. BlendMode mode {};
  348. u8 alpha_channel {};
  349. u8 clamp {};
  350. u8 source {};
  351. };
  352. static ErrorOr<BlendingInfo> read_blending_info(LittleEndianInputBitStream& stream, ImageMetadata const& metadata, bool full_frame)
  353. {
  354. BlendingInfo blending_info;
  355. blending_info.mode = static_cast<BlendingInfo::BlendMode>(U32(0, 1, 2, 3 + TRY(stream.read_bits(2))));
  356. bool const extra = metadata.num_extra_channels > 0;
  357. if (extra) {
  358. TODO();
  359. }
  360. if (blending_info.mode != BlendingInfo::BlendMode::kReplace
  361. || !full_frame) {
  362. blending_info.source = TRY(stream.read_bits(2));
  363. }
  364. return blending_info;
  365. }
  366. ///
  367. /// J.1 - General
  368. struct RestorationFilter {
  369. bool gab { true };
  370. u8 epf_iters { 2 };
  371. Extensions extensions;
  372. };
  373. static ErrorOr<RestorationFilter> read_restoration_filter(LittleEndianInputBitStream& stream)
  374. {
  375. RestorationFilter restoration_filter;
  376. auto const all_defaults = TRY(stream.read_bit());
  377. if (!all_defaults) {
  378. restoration_filter.gab = TRY(stream.read_bit());
  379. if (restoration_filter.gab) {
  380. TODO();
  381. }
  382. restoration_filter.epf_iters = TRY(stream.read_bits(2));
  383. if (restoration_filter.epf_iters != 0) {
  384. TODO();
  385. }
  386. restoration_filter.extensions = TRY(read_extensions(stream));
  387. }
  388. return restoration_filter;
  389. }
  390. ///
  391. /// Table F.6 — Passes bundle
  392. struct Passes {
  393. u8 num_passes { 1 };
  394. };
  395. static ErrorOr<Passes> read_passes(LittleEndianInputBitStream& stream)
  396. {
  397. Passes passes;
  398. passes.num_passes = U32(1, 2, 3, 4 + TRY(stream.read_bits(3)));
  399. if (passes.num_passes != 1) {
  400. TODO();
  401. }
  402. return passes;
  403. }
  404. ///
  405. /// F.2 - FrameHeader
  406. struct FrameHeader {
  407. enum class FrameType {
  408. kRegularFrame = 0,
  409. kLFFrame = 1,
  410. kReferenceOnly = 2,
  411. kSkipProgressive = 3,
  412. };
  413. enum class Encoding {
  414. kVarDCT = 0,
  415. kModular = 1,
  416. };
  417. enum class Flags {
  418. None = 0,
  419. kNoise = 1,
  420. kPatches = 1 << 1,
  421. kSplines = 1 << 4,
  422. kUseLfFrame = 1 << 5,
  423. kSkipAdaptiveLFSmoothing = 1 << 7,
  424. };
  425. FrameType frame_type { FrameType::kRegularFrame };
  426. Encoding encoding { Encoding::kVarDCT };
  427. Flags flags { Flags::None };
  428. bool do_YCbCr { false };
  429. Array<u8, 3> jpeg_upsampling {};
  430. u8 upsampling {};
  431. Vector<u8> ec_upsampling {};
  432. u8 group_size_shift { 1 };
  433. Passes passes {};
  434. u8 lf_level {};
  435. bool have_crop { false };
  436. BlendingInfo blending_info {};
  437. u32 duration {};
  438. bool is_last { true };
  439. u8 save_as_reference {};
  440. bool save_before_ct {};
  441. String name {};
  442. RestorationFilter restoration_filter {};
  443. Extensions extensions {};
  444. };
  445. static int operator&(FrameHeader::Flags first, FrameHeader::Flags second)
  446. {
  447. return static_cast<int>(first) & static_cast<int>(second);
  448. }
  449. static ErrorOr<FrameHeader> read_frame_header(LittleEndianInputBitStream& stream, ImageMetadata const& metadata)
  450. {
  451. FrameHeader frame_header;
  452. bool const all_default = TRY(stream.read_bit());
  453. if (!all_default) {
  454. frame_header.frame_type = static_cast<FrameHeader::FrameType>(TRY(stream.read_bits(2)));
  455. frame_header.encoding = static_cast<FrameHeader::Encoding>(TRY(stream.read_bits(1)));
  456. frame_header.flags = static_cast<FrameHeader::Flags>(TRY(U64(stream)));
  457. if (!metadata.xyb_encoded)
  458. frame_header.do_YCbCr = TRY(stream.read_bit());
  459. if (!(frame_header.flags & FrameHeader::Flags::kUseLfFrame)) {
  460. if (frame_header.do_YCbCr) {
  461. frame_header.jpeg_upsampling[0] = TRY(stream.read_bits(2));
  462. frame_header.jpeg_upsampling[1] = TRY(stream.read_bits(2));
  463. frame_header.jpeg_upsampling[2] = TRY(stream.read_bits(2));
  464. }
  465. frame_header.upsampling = U32(1, 2, 4, 8);
  466. for (u16 i {}; i < metadata.num_extra_channels; ++i)
  467. TODO();
  468. }
  469. if (frame_header.encoding == FrameHeader::Encoding::kModular)
  470. frame_header.group_size_shift = TRY(stream.read_bits(2));
  471. if (frame_header.encoding == FrameHeader::Encoding::kVarDCT)
  472. TODO();
  473. if (frame_header.frame_type != FrameHeader::FrameType::kReferenceOnly)
  474. frame_header.passes = TRY(read_passes(stream));
  475. if (frame_header.frame_type == FrameHeader::FrameType::kLFFrame)
  476. TODO();
  477. if (frame_header.frame_type != FrameHeader::FrameType::kLFFrame)
  478. frame_header.have_crop = TRY(stream.read_bit());
  479. if (frame_header.have_crop)
  480. TODO();
  481. bool const normal_frame = frame_header.frame_type == FrameHeader::FrameType::kRegularFrame
  482. || frame_header.frame_type == FrameHeader::FrameType::kSkipProgressive;
  483. // FIXME: also consider "cropped" image of the dimension of the frame
  484. VERIFY(!frame_header.have_crop);
  485. bool const full_frame = !frame_header.have_crop;
  486. if (normal_frame) {
  487. frame_header.blending_info = TRY(read_blending_info(stream, metadata, full_frame));
  488. for (u16 i {}; i < metadata.num_extra_channels; ++i)
  489. TODO();
  490. if (metadata.animation.has_value())
  491. TODO();
  492. frame_header.is_last = TRY(stream.read_bit());
  493. }
  494. // FIXME: Ensure that is_last has the correct default value
  495. VERIFY(normal_frame);
  496. auto const resets_canvas = full_frame && frame_header.blending_info.mode == BlendingInfo::BlendMode::kReplace;
  497. auto const can_reference = !frame_header.is_last && (frame_header.duration == 0 || frame_header.save_as_reference != 0) && frame_header.frame_type != FrameHeader::FrameType::kLFFrame;
  498. if (frame_header.frame_type != FrameHeader::FrameType::kLFFrame) {
  499. if (!frame_header.is_last)
  500. TODO();
  501. }
  502. frame_header.save_before_ct = !normal_frame;
  503. if (frame_header.frame_type == FrameHeader::FrameType::kReferenceOnly || (resets_canvas && can_reference))
  504. frame_header.save_before_ct = TRY(stream.read_bit());
  505. auto const name_length = U32(0, TRY(stream.read_bits(4)), 16 + TRY(stream.read_bits(5)), 48 + TRY(stream.read_bits(10)));
  506. auto string_buffer = TRY(FixedArray<u8>::create(name_length));
  507. TRY(stream.read_until_filled(string_buffer.span()));
  508. frame_header.name = TRY(String::from_utf8(StringView { string_buffer.span() }));
  509. frame_header.restoration_filter = TRY(read_restoration_filter(stream));
  510. frame_header.extensions = TRY(read_extensions(stream));
  511. }
  512. return frame_header;
  513. }
  514. ///
  515. /// F.3 TOC
  516. struct TOC {
  517. FixedArray<u32> entries;
  518. FixedArray<u32> group_offsets;
  519. };
  520. static u64 num_toc_entries(FrameHeader const& frame_header, u64 num_groups, u64 num_lf_groups)
  521. {
  522. // F.3.1 - General
  523. if (num_groups == 1 && frame_header.passes.num_passes == 1)
  524. return 1;
  525. return 1 + num_lf_groups + 1 + num_groups * frame_header.passes.num_passes;
  526. }
  527. static ErrorOr<TOC> read_toc(LittleEndianInputBitStream& stream, FrameHeader const& frame_header, u64 num_groups, u64 num_lf_groups)
  528. {
  529. TOC toc;
  530. bool const permuted_toc = TRY(stream.read_bit());
  531. if (permuted_toc) {
  532. // Read permutations
  533. TODO();
  534. }
  535. // F.3.3 - Decoding TOC
  536. stream.align_to_byte_boundary();
  537. auto const toc_entries = num_toc_entries(frame_header, num_groups, num_lf_groups);
  538. toc.entries = TRY(FixedArray<u32>::create(toc_entries));
  539. toc.group_offsets = TRY(FixedArray<u32>::create(toc_entries));
  540. for (u32 i {}; i < toc_entries; ++i) {
  541. auto const new_entry = U32(
  542. TRY(stream.read_bits(10)),
  543. 1024 + TRY(stream.read_bits(14)),
  544. 17408 + TRY(stream.read_bits(22)),
  545. 4211712 + TRY(stream.read_bits(30)));
  546. toc.entries[i] = new_entry;
  547. toc.group_offsets[i] = (i == 0 ? 0 : toc.group_offsets[i - 1]) + new_entry;
  548. }
  549. if (permuted_toc)
  550. TODO();
  551. stream.align_to_byte_boundary();
  552. return toc;
  553. }
  554. ///
  555. /// G.1.2 - LF channel dequantization weights
  556. struct LfChannelDequantization {
  557. float m_x_lf_unscaled { 4096 };
  558. float m_y_lf_unscaled { 512 };
  559. float m_b_lf_unscaled { 256 };
  560. };
  561. static ErrorOr<LfChannelDequantization> read_lf_channel_dequantization(LittleEndianInputBitStream& stream)
  562. {
  563. LfChannelDequantization lf_channel_dequantization;
  564. auto const all_default = TRY(stream.read_bit());
  565. if (!all_default) {
  566. TODO();
  567. }
  568. return lf_channel_dequantization;
  569. }
  570. ///
  571. /// C - Entropy decoding
  572. class EntropyDecoder {
  573. using BrotliCanonicalCode = Compress::Brotli::CanonicalCode;
  574. public:
  575. static ErrorOr<EntropyDecoder> create(LittleEndianInputBitStream& stream, u8 initial_num_distrib)
  576. {
  577. EntropyDecoder entropy_decoder;
  578. // C.2 - Distribution decoding
  579. entropy_decoder.m_lz77_enabled = TRY(stream.read_bit());
  580. if (entropy_decoder.m_lz77_enabled) {
  581. TODO();
  582. }
  583. TRY(entropy_decoder.read_pre_clustered_distributions(stream, initial_num_distrib));
  584. bool const use_prefix_code = TRY(stream.read_bit());
  585. if (!use_prefix_code)
  586. entropy_decoder.m_log_alphabet_size = 5 + TRY(stream.read_bits(2));
  587. for (auto& config : entropy_decoder.m_configs)
  588. config = TRY(entropy_decoder.read_config(stream));
  589. Vector<u16> counts;
  590. TRY(counts.try_resize(entropy_decoder.m_configs.size()));
  591. TRY(entropy_decoder.m_distributions.try_resize(entropy_decoder.m_configs.size()));
  592. if (use_prefix_code) {
  593. for (auto& count : counts) {
  594. if (TRY(stream.read_bit())) {
  595. auto const n = TRY(stream.read_bits(4));
  596. count = 1 + (1 << n) + TRY(stream.read_bits(n));
  597. } else {
  598. count = 1;
  599. }
  600. }
  601. // After reading the counts, the decoder reads each D[i] (implicitly
  602. // described by a prefix code) as specified in C.2.4, with alphabet_size = count[i].
  603. for (u32 i {}; i < entropy_decoder.m_distributions.size(); ++i) {
  604. // The alphabet size mentioned in the [Brotli] RFC is explicitly specified as parameter alphabet_size
  605. // when the histogram is being decoded, except in the special case of alphabet_size == 1, where no
  606. // histogram is read, and all decoded symbols are zero without reading any bits at all.
  607. if (counts[i] != 1) {
  608. entropy_decoder.m_distributions[i] = TRY(BrotliCanonicalCode::read_prefix_code(stream, counts[i]));
  609. } else {
  610. entropy_decoder.m_distributions[i] = BrotliCanonicalCode { { 1 }, { 0 } };
  611. }
  612. }
  613. } else {
  614. TODO();
  615. }
  616. return entropy_decoder;
  617. }
  618. ErrorOr<u32> decode_hybrid_uint(LittleEndianInputBitStream& stream, u16 context)
  619. {
  620. // C.3.3 - Hybrid integer decoding
  621. if (m_lz77_enabled)
  622. TODO();
  623. // Read symbol from entropy coded stream using D[clusters[ctx]]
  624. auto const token = TRY(m_distributions[m_clusters[context]].read_symbol(stream));
  625. auto r = TRY(read_uint(stream, m_configs[m_clusters[context]], token));
  626. return r;
  627. }
  628. private:
  629. struct HybridUint {
  630. u32 split_exponent {};
  631. u32 split {};
  632. u32 msb_in_token {};
  633. u32 lsb_in_token {};
  634. };
  635. static ErrorOr<u32> read_uint(LittleEndianInputBitStream& stream, HybridUint const& config, u32 token)
  636. {
  637. if (token < config.split)
  638. return token;
  639. auto const n = config.split_exponent
  640. - config.msb_in_token
  641. - config.lsb_in_token
  642. + ((token - config.split) >> (config.msb_in_token + config.lsb_in_token));
  643. VERIFY(n < 32);
  644. u32 const low_bits = token & ((1 << config.lsb_in_token) - 1);
  645. token = token >> config.lsb_in_token;
  646. token &= (1 << config.msb_in_token) - 1;
  647. token |= (1 << config.msb_in_token);
  648. auto const result = ((token << n | TRY(stream.read_bits(n))) << config.lsb_in_token) | low_bits;
  649. VERIFY(result < (1ul << 32));
  650. return result;
  651. }
  652. ErrorOr<void> read_pre_clustered_distributions(LittleEndianInputBitStream& stream, u8 num_distrib)
  653. {
  654. // C.2.2 Distribution clustering
  655. if (num_distrib == 1)
  656. TODO();
  657. TRY(m_clusters.try_resize(num_distrib));
  658. bool const is_simple = TRY(stream.read_bit());
  659. u16 num_clusters = 0;
  660. if (is_simple) {
  661. u8 const nbits = TRY(stream.read_bits(2));
  662. for (u8 i {}; i < num_distrib; ++i) {
  663. m_clusters[i] = TRY(stream.read_bits(nbits));
  664. if (m_clusters[i] >= num_clusters)
  665. num_clusters = m_clusters[i] + 1;
  666. }
  667. } else {
  668. TODO();
  669. }
  670. TRY(m_configs.try_resize(num_clusters));
  671. return {};
  672. }
  673. ErrorOr<HybridUint> read_config(LittleEndianInputBitStream& stream) const
  674. {
  675. // C.2.3 - Hybrid integer configuration
  676. HybridUint config {};
  677. config.split_exponent = TRY(stream.read_bits(ceil(log2(m_log_alphabet_size + 1))));
  678. if (config.split_exponent != m_log_alphabet_size) {
  679. auto nbits = ceil(log2(config.split_exponent + 1));
  680. config.msb_in_token = TRY(stream.read_bits(nbits));
  681. nbits = ceil(log2(config.split_exponent - config.msb_in_token + 1));
  682. config.lsb_in_token = TRY(stream.read_bits(nbits));
  683. } else {
  684. config.msb_in_token = 0;
  685. config.lsb_in_token = 0;
  686. }
  687. config.split = 1 << config.split_exponent;
  688. return config;
  689. }
  690. bool m_lz77_enabled {};
  691. Vector<u32> m_clusters;
  692. Vector<HybridUint> m_configs;
  693. u8 m_log_alphabet_size { 15 };
  694. Vector<BrotliCanonicalCode> m_distributions; // D in the spec
  695. };
  696. ///
  697. /// H.4.2 - MA tree decoding
  698. class MATree {
  699. public:
  700. struct LeafNode {
  701. u8 ctx {};
  702. u8 predictor {};
  703. i32 offset {};
  704. u32 multiplier {};
  705. };
  706. static ErrorOr<MATree> decode(LittleEndianInputBitStream& stream, Optional<EntropyDecoder>& decoder)
  707. {
  708. // G.1.3 - GlobalModular
  709. MATree tree;
  710. // 1 / 2 Read the 6 pre-clustered distributions
  711. auto const num_distrib = 6;
  712. if (!decoder.has_value())
  713. decoder = TRY(EntropyDecoder::create(stream, num_distrib));
  714. // 2 / 2 Decode the tree
  715. u64 ctx_id = 0;
  716. u64 nodes_left = 1;
  717. tree.m_tree.clear();
  718. while (nodes_left > 0) {
  719. nodes_left--;
  720. i32 const property = TRY(decoder->decode_hybrid_uint(stream, 1)) - 1;
  721. if (property >= 0) {
  722. DecisionNode decision_node;
  723. decision_node.property = property;
  724. decision_node.value = unpack_signed(TRY(decoder->decode_hybrid_uint(stream, 0)));
  725. decision_node.left_child = tree.m_tree.size() + nodes_left + 1;
  726. decision_node.right_child = tree.m_tree.size() + nodes_left + 2;
  727. tree.m_tree.empend(decision_node);
  728. nodes_left += 2;
  729. } else {
  730. LeafNode leaf_node;
  731. leaf_node.ctx = ctx_id++;
  732. leaf_node.predictor = TRY(decoder->decode_hybrid_uint(stream, 2));
  733. leaf_node.offset = unpack_signed(TRY(decoder->decode_hybrid_uint(stream, 3)));
  734. auto const mul_log = TRY(decoder->decode_hybrid_uint(stream, 4));
  735. auto const mul_bits = TRY(decoder->decode_hybrid_uint(stream, 5));
  736. leaf_node.multiplier = (mul_bits + 1) << mul_log;
  737. tree.m_tree.empend(leaf_node);
  738. }
  739. }
  740. // Finally, the decoder reads (tree.size() + 1) / 2 pre-clustered distributions D as specified in C.1.
  741. auto const num_pre_clustered_distributions = (tree.m_tree.size() + 1) / 2;
  742. decoder = TRY(decoder->create(stream, num_pre_clustered_distributions));
  743. return tree;
  744. }
  745. LeafNode get_leaf(Vector<i32> const& properties) const
  746. {
  747. // To find the MA leaf node, the MA tree is traversed, starting at the root node tree[0]
  748. // and for each decision node d, testing if property[d.property] > d.value, proceeding to
  749. // the node tree[d.left_child] if the test evaluates to true and to the node tree[d.right_child]
  750. // otherwise, until a leaf node is reached.
  751. DecisionNode node { m_tree[0].get<DecisionNode>() };
  752. while (true) {
  753. auto const next_node = [this, &properties, &node]() {
  754. // Note: The behavior when trying to access a non-existing property is taken from jxl-oxide
  755. if (node.property < properties.size() && properties[node.property] > node.value)
  756. return m_tree[node.left_child];
  757. return m_tree[node.right_child];
  758. }();
  759. if (next_node.has<LeafNode>())
  760. return next_node.get<LeafNode>();
  761. node = next_node.get<DecisionNode>();
  762. }
  763. }
  764. private:
  765. struct DecisionNode {
  766. u64 property {};
  767. i64 value {};
  768. u64 left_child {};
  769. u64 right_child {};
  770. };
  771. Vector<Variant<DecisionNode, LeafNode>> m_tree;
  772. };
  773. ///
  774. /// H.5 - Self-correcting predictor
  775. struct WPHeader {
  776. u8 wp_p1 { 16 };
  777. u8 wp_p2 { 10 };
  778. u8 wp_p3a { 7 };
  779. u8 wp_p3b { 7 };
  780. u8 wp_p3c { 7 };
  781. u8 wp_p3d { 0 };
  782. u8 wp_p3e { 0 };
  783. u8 wp_w0 { 13 };
  784. u8 wp_w1 { 12 };
  785. u8 wp_w2 { 12 };
  786. u8 wp_w3 { 12 };
  787. };
  788. static ErrorOr<WPHeader> read_self_correcting_predictor(LittleEndianInputBitStream& stream)
  789. {
  790. WPHeader self_correcting_predictor {};
  791. bool const default_wp = TRY(stream.read_bit());
  792. if (!default_wp) {
  793. TODO();
  794. }
  795. return self_correcting_predictor;
  796. }
  797. ///
  798. ///
  799. struct TransformInfo {
  800. enum class TransformId {
  801. kRCT = 0,
  802. kPalette = 1,
  803. kSqueeze = 2,
  804. };
  805. TransformId tr {};
  806. u32 begin_c {};
  807. u32 rct_type {};
  808. };
  809. static ErrorOr<TransformInfo> read_transform_info(LittleEndianInputBitStream& stream)
  810. {
  811. TransformInfo transform_info;
  812. transform_info.tr = static_cast<TransformInfo::TransformId>(TRY(stream.read_bits(2)));
  813. if (transform_info.tr != TransformInfo::TransformId::kSqueeze) {
  814. transform_info.begin_c = U32(
  815. TRY(stream.read_bits(3)),
  816. 8 + TRY(stream.read_bits(3)),
  817. 72 + TRY(stream.read_bits(10)),
  818. 1096 + TRY(stream.read_bits(13)));
  819. }
  820. if (transform_info.tr == TransformInfo::TransformId::kRCT) {
  821. transform_info.rct_type = U32(
  822. 6,
  823. TRY(stream.read_bits(2)),
  824. 2 + TRY(stream.read_bits(4)),
  825. 10 + TRY(stream.read_bits(6)));
  826. }
  827. if (transform_info.tr != TransformInfo::TransformId::kRCT)
  828. TODO();
  829. return transform_info;
  830. }
  831. ///
  832. /// Local abstractions to store the decoded image
  833. class Channel {
  834. public:
  835. static ErrorOr<Channel> create(u32 width, u32 height)
  836. {
  837. Channel channel;
  838. channel.m_width = width;
  839. channel.m_height = height;
  840. TRY(channel.m_pixels.try_resize(channel.m_width * channel.m_height));
  841. return channel;
  842. }
  843. i32 get(u32 x, u32 y) const
  844. {
  845. return m_pixels[x * m_width + y];
  846. }
  847. void set(u32 x, u32 y, i32 value)
  848. {
  849. m_pixels[x * m_width + y] = value;
  850. }
  851. u32 width() const
  852. {
  853. return m_width;
  854. }
  855. u32 height() const
  856. {
  857. return m_height;
  858. }
  859. u32 hshift() const
  860. {
  861. return m_hshift;
  862. }
  863. u32 vshift() const
  864. {
  865. return m_vshift;
  866. }
  867. bool decoded() const
  868. {
  869. return m_decoded;
  870. }
  871. void set_decoded(bool decoded)
  872. {
  873. m_decoded = decoded;
  874. }
  875. private:
  876. u32 m_width {};
  877. u32 m_height {};
  878. u32 m_hshift {};
  879. u32 m_vshift {};
  880. bool m_decoded { false };
  881. Vector<i32> m_pixels {};
  882. };
  883. class Image {
  884. public:
  885. static ErrorOr<Image> create(IntSize size)
  886. {
  887. Image image {};
  888. // FIXME: Don't assume three channels and a fixed size
  889. TRY(image.m_channels.try_append(TRY(Channel::create(size.width(), size.height()))));
  890. TRY(image.m_channels.try_append(TRY(Channel::create(size.width(), size.height()))));
  891. TRY(image.m_channels.try_append(TRY(Channel::create(size.width(), size.height()))));
  892. return image;
  893. }
  894. ErrorOr<NonnullRefPtr<Bitmap>> to_bitmap(u8 bits_per_sample) const
  895. {
  896. // FIXME: which channel size should we use?
  897. auto const width = m_channels[0].width();
  898. auto const height = m_channels[0].height();
  899. auto bitmap = TRY(Bitmap::create(BitmapFormat::BGRx8888, { width, height }));
  900. // FIXME: This assumes a raw image with RGB channels, other cases are possible
  901. VERIFY(bits_per_sample >= 8);
  902. for (u32 y {}; y < height; ++y) {
  903. for (u32 x {}; x < width; ++x) {
  904. auto const to_u8 = [&, bits_per_sample](i32 sample) -> u8 {
  905. // FIXME: Don't truncate the result to 8 bits
  906. static constexpr auto maximum_supported_bit_depth = 8;
  907. if (bits_per_sample > maximum_supported_bit_depth)
  908. sample >>= (bits_per_sample - maximum_supported_bit_depth);
  909. return clamp(sample + .5, 0, (1 << maximum_supported_bit_depth) - 1);
  910. };
  911. Color const color {
  912. to_u8(m_channels[0].get(x, y)),
  913. to_u8(m_channels[1].get(x, y)),
  914. to_u8(m_channels[2].get(x, y)),
  915. };
  916. bitmap->set_pixel(x, y, color);
  917. }
  918. }
  919. return bitmap;
  920. }
  921. Vector<Channel>& channels()
  922. {
  923. return m_channels;
  924. }
  925. private:
  926. Vector<Channel> m_channels;
  927. };
  928. ///
  929. /// H.2 - Image decoding
  930. struct ModularHeader {
  931. bool use_global_tree {};
  932. WPHeader wp_params {};
  933. Vector<TransformInfo> transform {};
  934. };
  935. static ErrorOr<Vector<i32>> get_properties(Vector<Channel> const& channels, u16 i, u32 x, u32 y)
  936. {
  937. Vector<i32> properties;
  938. // Table H.4 - Property definitions
  939. TRY(properties.try_append(i));
  940. // FIXME: Handle other cases than GlobalModular
  941. TRY(properties.try_append(0));
  942. TRY(properties.try_append(y));
  943. TRY(properties.try_append(x));
  944. i32 const W = x > 0 ? channels[i].get(x - 1, y) : (y > 0 ? channels[i].get(x, y - 1) : 0);
  945. i32 const N = y > 0 ? channels[i].get(x, y - 1) : W;
  946. i32 const NW = x > 0 && y > 0 ? channels[i].get(x - 1, y - 1) : W;
  947. i32 const NE = x + 1 < channels[i].width() && y > 0 ? channels[i].get(x + 1, y - 1) : N;
  948. i32 const NN = y > 1 ? channels[i].get(x, y - 2) : N;
  949. i32 const WW = x > 1 ? channels[i].get(x - 2, y) : W;
  950. TRY(properties.try_append(abs(N)));
  951. TRY(properties.try_append(abs(W)));
  952. TRY(properties.try_append(N));
  953. TRY(properties.try_append(W));
  954. // x > 0 ? W - /* (the value of property 9 at position (x - 1, y)) */ : W
  955. i32 x_1 = x - 1;
  956. i32 const W_x_1 = x_1 > 0 ? channels[i].get(x_1 - 1, y) : (x_1 >= 0 && y > 0 ? channels[i].get(x_1, y - 1) : 0);
  957. i32 const N_x_1 = x_1 >= 0 && y > 0 ? channels[i].get(x_1, y - 1) : W_x_1;
  958. i32 const NW_x_1 = x_1 > 0 && y > 0 ? channels[i].get(x_1 - 1, y - 1) : W_x_1;
  959. TRY(properties.try_append(W_x_1 + N_x_1 - NW_x_1));
  960. TRY(properties.try_append(W + N - NW));
  961. TRY(properties.try_append(W - NW));
  962. TRY(properties.try_append(NW - N));
  963. TRY(properties.try_append(N - NE));
  964. TRY(properties.try_append(N - NN));
  965. TRY(properties.try_append(W - WW));
  966. // FIXME: Correctly compute max_error
  967. TRY(properties.try_append(0));
  968. for (i16 j = i - 1; j >= 0; j--) {
  969. if (channels[j].width() != channels[i].width())
  970. continue;
  971. if (channels[j].height() != channels[i].height())
  972. continue;
  973. if (channels[j].hshift() != channels[i].hshift())
  974. continue;
  975. if (channels[j].vshift() != channels[i].vshift())
  976. continue;
  977. auto rC = channels[j].get(x, y);
  978. auto rW = (x > 0 ? channels[j].get(x - 1, y) : 0);
  979. auto rN = (y > 0 ? channels[j].get(x, y - 1) : rW);
  980. auto rNW = (x > 0 && y > 0 ? channels[j].get(x - 1, y - 1) : rW);
  981. auto rG = clamp(rW + rN - rNW, min(rW, rN), max(rW, rN));
  982. TRY(properties.try_append(abs(rC)));
  983. TRY(properties.try_append(rC));
  984. TRY(properties.try_append(abs(rC - rG)));
  985. TRY(properties.try_append(rC - rG));
  986. }
  987. return properties;
  988. }
  989. static i32 prediction(Channel const& channel, u32 x, u32 y, u32 predictor)
  990. {
  991. i32 const W = x > 0 ? channel.get(x - 1, y) : (y > 0 ? channel.get(x, y - 1) : 0);
  992. i32 const N = y > 0 ? channel.get(x, y - 1) : W;
  993. i32 const NW = x > 0 && y > 0 ? channel.get(x - 1, y - 1) : W;
  994. i32 const NE = x + 1 < channel.width() && y > 0 ? channel.get(x + 1, y - 1) : N;
  995. i32 const NN = y > 1 ? channel.get(x, y - 2) : N;
  996. i32 const NEE = x + 2 < channel.width() and y > 0 ? channel.get(x + 2, y - 1) : NE;
  997. i32 const WW = x > 1 ? channel.get(x - 2, y) : W;
  998. switch (predictor) {
  999. case 0:
  1000. return 0;
  1001. case 1:
  1002. return W;
  1003. case 2:
  1004. return N;
  1005. case 3:
  1006. return (W + N) / 2;
  1007. case 4:
  1008. return abs(N - NW) < abs(W - NW) ? W : N;
  1009. case 5:
  1010. return clamp(W + N - NW, min(W, N), max(W, N));
  1011. case 6:
  1012. TODO();
  1013. return (0 + 3) >> 3;
  1014. case 7:
  1015. return NE;
  1016. case 8:
  1017. return NW;
  1018. case 9:
  1019. return WW;
  1020. case 10:
  1021. return (W + NW) / 2;
  1022. case 11:
  1023. return (N + NW) / 2;
  1024. case 12:
  1025. return (N + NE) / 2;
  1026. case 13:
  1027. return (6 * N - 2 * NN + 7 * W + WW + NEE + 3 * NE + 8) / 16;
  1028. }
  1029. VERIFY_NOT_REACHED();
  1030. }
  1031. static ErrorOr<ModularHeader> read_modular_header(LittleEndianInputBitStream& stream,
  1032. Image& image,
  1033. Optional<EntropyDecoder>& decoder,
  1034. MATree const& global_tree,
  1035. u16 num_channels)
  1036. {
  1037. ModularHeader modular_header;
  1038. modular_header.use_global_tree = TRY(stream.read_bit());
  1039. modular_header.wp_params = TRY(read_self_correcting_predictor(stream));
  1040. auto const nb_transforms = U32(0, 1, 2 + TRY(stream.read_bits(4)), 18 + TRY(stream.read_bits(8)));
  1041. TRY(modular_header.transform.try_resize(nb_transforms));
  1042. for (u32 i {}; i < nb_transforms; ++i)
  1043. modular_header.transform[i] = TRY(read_transform_info(stream));
  1044. Optional<MATree> local_tree;
  1045. if (!modular_header.use_global_tree)
  1046. TODO();
  1047. // The decoder then starts an entropy-coded stream (C.1) and decodes the data for each channel
  1048. // (in ascending order of index) as specified in H.3, skipping any channels having width or height
  1049. // zero. Finally, the inverse transformations are applied (from last to first) as described in H.6.
  1050. auto const& tree = local_tree.has_value() ? *local_tree : global_tree;
  1051. for (u16 i {}; i < num_channels; ++i) {
  1052. for (u32 y {}; y < image.channels()[i].height(); y++) {
  1053. for (u32 x {}; x < image.channels()[i].width(); x++) {
  1054. auto const properties = TRY(get_properties(image.channels(), i, x, y));
  1055. auto const leaf_node = tree.get_leaf(properties);
  1056. auto diff = unpack_signed(TRY(decoder->decode_hybrid_uint(stream, leaf_node.ctx)));
  1057. diff = (diff * leaf_node.multiplier) + leaf_node.offset;
  1058. auto const total = diff + prediction(image.channels()[i], x, y, leaf_node.predictor);
  1059. image.channels()[i].set(x, y, total);
  1060. }
  1061. }
  1062. image.channels()[i].set_decoded(true);
  1063. }
  1064. return modular_header;
  1065. }
  1066. ///
  1067. /// G.1.2 - LF channel dequantization weights
  1068. struct GlobalModular {
  1069. MATree ma_tree;
  1070. ModularHeader modular_header;
  1071. };
  1072. static ErrorOr<GlobalModular> read_global_modular(LittleEndianInputBitStream& stream,
  1073. Image& image,
  1074. FrameHeader const& frame_header,
  1075. ImageMetadata const& metadata,
  1076. Optional<EntropyDecoder>& entropy_decoder)
  1077. {
  1078. GlobalModular global_modular;
  1079. auto const decode_ma_tree = TRY(stream.read_bit());
  1080. if (decode_ma_tree)
  1081. global_modular.ma_tree = TRY(MATree::decode(stream, entropy_decoder));
  1082. // The decoder then decodes a modular sub-bitstream (Annex H), where
  1083. // the number of channels is computed as follows:
  1084. auto num_channels = metadata.num_extra_channels;
  1085. if (frame_header.encoding == FrameHeader::Encoding::kModular) {
  1086. if (!frame_header.do_YCbCr && !metadata.xyb_encoded
  1087. && metadata.colour_encoding.colour_space == ColourEncoding::ColourSpace::kGrey) {
  1088. num_channels += 1;
  1089. } else {
  1090. num_channels += 3;
  1091. }
  1092. }
  1093. // FIXME: Ensure this spec comment:
  1094. // However, the decoder only decodes the first nb_meta_channels channels and any further channels
  1095. // that have a width and height that are both at most group_dim. At that point, it stops decoding.
  1096. // No inverse transforms are applied yet.
  1097. global_modular.modular_header = TRY(read_modular_header(stream, image, entropy_decoder, global_modular.ma_tree, num_channels));
  1098. return global_modular;
  1099. }
  1100. ///
  1101. /// G.1 - LfGlobal
  1102. struct LfGlobal {
  1103. LfChannelDequantization lf_dequant;
  1104. GlobalModular gmodular;
  1105. };
  1106. static ErrorOr<LfGlobal> read_lf_global(LittleEndianInputBitStream& stream,
  1107. Image& image,
  1108. FrameHeader const& frame_header,
  1109. ImageMetadata const& metadata,
  1110. Optional<EntropyDecoder>& entropy_decoder)
  1111. {
  1112. LfGlobal lf_global;
  1113. if (frame_header.flags != FrameHeader::Flags::None)
  1114. TODO();
  1115. lf_global.lf_dequant = TRY(read_lf_channel_dequantization(stream));
  1116. if (frame_header.encoding == FrameHeader::Encoding::kVarDCT)
  1117. TODO();
  1118. lf_global.gmodular = TRY(read_global_modular(stream, image, frame_header, metadata, entropy_decoder));
  1119. return lf_global;
  1120. }
  1121. ///
  1122. /// G.2 - LfGroup
  1123. static ErrorOr<void> read_lf_group(LittleEndianInputBitStream&,
  1124. Image& image,
  1125. FrameHeader const& frame_header)
  1126. {
  1127. // LF coefficients
  1128. if (frame_header.encoding == FrameHeader::Encoding::kVarDCT) {
  1129. TODO();
  1130. }
  1131. // ModularLfGroup
  1132. for (auto const& channel : image.channels()) {
  1133. if (channel.decoded())
  1134. continue;
  1135. if (channel.hshift() < 3 || channel.vshift() < 3)
  1136. continue;
  1137. // This code actually only detect that we need to read a null image
  1138. // so a no-op. It should be fully rewritten when we add proper support
  1139. // for LfGroup.
  1140. TODO();
  1141. }
  1142. // HF metadata
  1143. if (frame_header.encoding == FrameHeader::Encoding::kVarDCT) {
  1144. TODO();
  1145. }
  1146. return {};
  1147. }
  1148. ///
  1149. /// H.6 - Transformations
  1150. static void apply_rct(Image& image, TransformInfo const& transformation)
  1151. {
  1152. auto& channels = image.channels();
  1153. for (u32 y {}; y < channels[transformation.begin_c].height(); y++) {
  1154. for (u32 x {}; x < channels[transformation.begin_c].width(); x++) {
  1155. auto a = channels[transformation.begin_c + 0].get(x, y);
  1156. auto b = channels[transformation.begin_c + 1].get(x, y);
  1157. auto c = channels[transformation.begin_c + 2].get(x, y);
  1158. i32 d {};
  1159. i32 e {};
  1160. i32 f {};
  1161. auto const permutation = transformation.rct_type / 7;
  1162. auto const type = transformation.rct_type % 7;
  1163. if (type == 6) { // YCgCo
  1164. auto const tmp = a - (c >> 1);
  1165. e = c + tmp;
  1166. f = tmp - (b >> 1);
  1167. d = f + b;
  1168. } else {
  1169. if (type & 1)
  1170. c = c + a;
  1171. if ((type >> 1) == 1)
  1172. b = b + a;
  1173. if ((type >> 1) == 2)
  1174. b = b + ((a + c) >> 1);
  1175. d = a;
  1176. e = b;
  1177. f = c;
  1178. }
  1179. Array<i32, 3> v {};
  1180. v[permutation % 3] = d;
  1181. v[(permutation + 1 + (permutation / 3)) % 3] = e;
  1182. v[(permutation + 2 - (permutation / 3)) % 3] = f;
  1183. channels[transformation.begin_c + 0].set(x, y, v[0]);
  1184. channels[transformation.begin_c + 1].set(x, y, v[1]);
  1185. channels[transformation.begin_c + 2].set(x, y, v[2]);
  1186. }
  1187. }
  1188. }
  1189. static void apply_transformation(Image& image, TransformInfo const& transformation)
  1190. {
  1191. switch (transformation.tr) {
  1192. case TransformInfo::TransformId::kRCT:
  1193. apply_rct(image, transformation);
  1194. break;
  1195. case TransformInfo::TransformId::kPalette:
  1196. case TransformInfo::TransformId::kSqueeze:
  1197. TODO();
  1198. default:
  1199. VERIFY_NOT_REACHED();
  1200. }
  1201. }
  1202. ///
  1203. /// G.3.2 - PassGroup
  1204. static ErrorOr<void> read_pass_group(LittleEndianInputBitStream& stream,
  1205. Image& image,
  1206. FrameHeader const& frame_header,
  1207. u32 group_dim)
  1208. {
  1209. if (frame_header.encoding == FrameHeader::Encoding::kVarDCT) {
  1210. (void)stream;
  1211. TODO();
  1212. }
  1213. auto& channels = image.channels();
  1214. for (u16 i {}; i < channels.size(); ++i) {
  1215. // Skip meta-channels
  1216. // FIXME: Also test if the channel has already been decoded
  1217. // See: nb_meta_channels in the spec
  1218. bool const is_meta_channel = channels[i].width() <= group_dim
  1219. || channels[i].height() <= group_dim
  1220. || channels[i].hshift() >= 3
  1221. || channels[i].vshift() >= 3;
  1222. if (!is_meta_channel)
  1223. TODO();
  1224. }
  1225. return {};
  1226. }
  1227. ///
  1228. /// Table F.1 — Frame bundle
  1229. struct Frame {
  1230. FrameHeader frame_header;
  1231. TOC toc;
  1232. LfGlobal lf_global;
  1233. u64 width {};
  1234. u64 height {};
  1235. u64 num_groups {};
  1236. u64 num_lf_groups {};
  1237. };
  1238. static ErrorOr<Frame> read_frame(LittleEndianInputBitStream& stream,
  1239. Image& image,
  1240. SizeHeader const& size_header,
  1241. ImageMetadata const& metadata,
  1242. Optional<EntropyDecoder>& entropy_decoder)
  1243. {
  1244. // F.1 - General
  1245. // Each Frame is byte-aligned by invoking ZeroPadToByte() (B.2.7)
  1246. stream.align_to_byte_boundary();
  1247. Frame frame;
  1248. frame.frame_header = TRY(read_frame_header(stream, metadata));
  1249. if (!frame.frame_header.have_crop) {
  1250. frame.width = size_header.width;
  1251. frame.height = size_header.height;
  1252. } else {
  1253. TODO();
  1254. }
  1255. if (frame.frame_header.upsampling > 1) {
  1256. frame.width = ceil(static_cast<double>(frame.width) / frame.frame_header.upsampling);
  1257. frame.height = ceil(static_cast<double>(frame.height) / frame.frame_header.upsampling);
  1258. }
  1259. if (frame.frame_header.lf_level > 0)
  1260. TODO();
  1261. // F.2 - FrameHeader
  1262. auto const group_dim = 128 << frame.frame_header.group_size_shift;
  1263. auto const frame_width = static_cast<double>(frame.width);
  1264. auto const frame_height = static_cast<double>(frame.height);
  1265. frame.num_groups = ceil(frame_width / group_dim) * ceil(frame_height / group_dim);
  1266. frame.num_lf_groups = ceil(frame_width / (group_dim * 8)) * ceil(frame_height / (group_dim * 8));
  1267. frame.toc = TRY(read_toc(stream, frame.frame_header, frame.num_groups, frame.num_lf_groups));
  1268. image = TRY(Image::create({ frame.width, frame.height }));
  1269. frame.lf_global = TRY(read_lf_global(stream, image, frame.frame_header, metadata, entropy_decoder));
  1270. for (u32 i {}; i < frame.num_lf_groups; ++i)
  1271. TRY(read_lf_group(stream, image, frame.frame_header));
  1272. if (frame.frame_header.encoding == FrameHeader::Encoding::kVarDCT) {
  1273. TODO();
  1274. }
  1275. auto const num_pass_group = frame.num_groups * frame.frame_header.passes.num_passes;
  1276. auto const& transform_infos = frame.lf_global.gmodular.modular_header.transform;
  1277. for (u64 i {}; i < num_pass_group; ++i)
  1278. TRY(read_pass_group(stream, image, frame.frame_header, group_dim));
  1279. // G.4.2 - Modular group data
  1280. // When all modular groups are decoded, the inverse transforms are applied to
  1281. // the at that point fully decoded GlobalModular image, as specified in H.6.
  1282. for (auto const& transformation : transform_infos.in_reverse())
  1283. apply_transformation(image, transformation);
  1284. return frame;
  1285. }
  1286. ///
  1287. /// 5.2 - Mirroring
  1288. static u32 mirror_1d(i32 coord, u32 size)
  1289. {
  1290. if (coord < 0)
  1291. return mirror_1d(-coord - 1, size);
  1292. else if (static_cast<u32>(coord) >= size)
  1293. return mirror_1d(2 * size - 1 - coord, size);
  1294. else
  1295. return coord;
  1296. }
  1297. ///
  1298. /// K - Image features
  1299. static ErrorOr<void> apply_upsampling(Image& image, ImageMetadata const& metadata, Frame const& frame)
  1300. {
  1301. Optional<u32> ec_max;
  1302. for (auto upsampling : frame.frame_header.ec_upsampling) {
  1303. if (!ec_max.has_value() || upsampling > *ec_max)
  1304. ec_max = upsampling;
  1305. }
  1306. if (frame.frame_header.upsampling > 1 || ec_max.value_or(0) > 1) {
  1307. if (ec_max.value_or(0) > 2)
  1308. TODO();
  1309. auto const k = frame.frame_header.upsampling;
  1310. auto weight = [k, &metadata](u8 index) -> double {
  1311. if (k == 2)
  1312. return metadata.up2_weight[index];
  1313. if (k == 4)
  1314. return metadata.up4_weight[index];
  1315. return metadata.up8_weight[index];
  1316. };
  1317. // FIXME: Use ec_upsampling for extra-channels
  1318. for (auto& channel : image.channels()) {
  1319. auto upsampled = TRY(Channel::create(k * channel.width(), k * channel.height()));
  1320. // Loop over the original image
  1321. for (u32 y {}; y < channel.height(); y++) {
  1322. for (u32 x {}; x < channel.width(); x++) {
  1323. // Loop over the upsampling factor
  1324. for (u8 kx {}; kx < k; ++kx) {
  1325. for (u8 ky {}; ky < k; ++ky) {
  1326. double sum {};
  1327. // Loop over the W window
  1328. double W_min = NumericLimits<double>::max();
  1329. double W_max = -NumericLimits<double>::max();
  1330. for (u8 ix {}; ix < 5; ++ix) {
  1331. for (u8 iy {}; iy < 5; ++iy) {
  1332. auto const j = (ky < k / 2) ? (iy + 5 * ky) : ((4 - iy) + 5 * (k - 1 - ky));
  1333. auto const i = (kx < k / 2) ? (ix + 5 * kx) : ((4 - ix) + 5 * (k - 1 - kx));
  1334. auto const minimum = min(i, j);
  1335. auto const maximum = max(i, j);
  1336. auto const index = 5 * k * minimum / 2 - minimum * (minimum - 1) / 2 + maximum - minimum;
  1337. auto const origin_sample_x = mirror_1d(x + ix - 2, channel.width());
  1338. auto const origin_sample_y = mirror_1d(y + iy - 2, channel.height());
  1339. auto const origin_sample = channel.get(origin_sample_x, origin_sample_y);
  1340. W_min = min(W_min, origin_sample);
  1341. W_max = max(W_max, origin_sample);
  1342. sum += origin_sample * weight(index);
  1343. }
  1344. }
  1345. // The resulting sample is clamped to the range [a, b] where a and b are
  1346. // the minimum and maximum of the samples in W.
  1347. sum = clamp(sum, W_min, W_max);
  1348. upsampled.set(x * k + kx, y * k + ky, sum);
  1349. }
  1350. }
  1351. }
  1352. }
  1353. channel = move(upsampled);
  1354. }
  1355. }
  1356. return {};
  1357. }
  1358. static ErrorOr<void> apply_image_features(Image& image, ImageMetadata const& metadata, Frame const& frame)
  1359. {
  1360. TRY(apply_upsampling(image, metadata, frame));
  1361. if (frame.frame_header.flags != FrameHeader::Flags::None)
  1362. TODO();
  1363. return {};
  1364. }
  1365. ///
  1366. class JPEGXLLoadingContext {
  1367. public:
  1368. JPEGXLLoadingContext(NonnullOwnPtr<Stream> stream)
  1369. : m_stream(move(stream))
  1370. {
  1371. }
  1372. ErrorOr<void> decode_image_header()
  1373. {
  1374. constexpr auto JPEGXL_SIGNATURE = 0xFF0A;
  1375. auto const signature = TRY(m_stream.read_value<BigEndian<u16>>());
  1376. if (signature != JPEGXL_SIGNATURE)
  1377. return Error::from_string_literal("Unrecognized signature");
  1378. m_header = TRY(read_size_header(m_stream));
  1379. m_metadata = TRY(read_metadata_header(m_stream));
  1380. m_state = State::HeaderDecoded;
  1381. return {};
  1382. }
  1383. ErrorOr<void> decode_frame()
  1384. {
  1385. Image image {};
  1386. auto const frame = TRY(read_frame(m_stream, image, m_header, m_metadata, m_entropy_decoder));
  1387. if (frame.frame_header.restoration_filter.gab || frame.frame_header.restoration_filter.epf_iters != 0)
  1388. TODO();
  1389. TRY(apply_image_features(image, m_metadata, frame));
  1390. // FIXME: Do a proper color transformation with metadata.colour_encoding
  1391. if (m_metadata.xyb_encoded || frame.frame_header.do_YCbCr)
  1392. TODO();
  1393. m_bitmap = TRY(image.to_bitmap(m_metadata.bit_depth.bits_per_sample));
  1394. return {};
  1395. }
  1396. ErrorOr<void> decode()
  1397. {
  1398. auto result = [this]() -> ErrorOr<void> {
  1399. // A.1 - Codestream structure
  1400. // The header is already decoded in JPEGXLImageDecoderPlugin::create()
  1401. if (m_metadata.colour_encoding.want_icc)
  1402. TODO();
  1403. if (m_metadata.preview.has_value())
  1404. TODO();
  1405. TRY(decode_frame());
  1406. return {};
  1407. }();
  1408. m_state = result.is_error() ? State::Error : State::FrameDecoded;
  1409. return result;
  1410. }
  1411. enum class State {
  1412. NotDecoded = 0,
  1413. Error,
  1414. HeaderDecoded,
  1415. FrameDecoded,
  1416. };
  1417. State state() const
  1418. {
  1419. return m_state;
  1420. }
  1421. IntSize size() const
  1422. {
  1423. return { m_header.width, m_header.height };
  1424. }
  1425. RefPtr<Bitmap> bitmap() const
  1426. {
  1427. return m_bitmap;
  1428. }
  1429. private:
  1430. State m_state { State::NotDecoded };
  1431. LittleEndianInputBitStream m_stream;
  1432. RefPtr<Gfx::Bitmap> m_bitmap;
  1433. Optional<EntropyDecoder> m_entropy_decoder {};
  1434. SizeHeader m_header;
  1435. ImageMetadata m_metadata;
  1436. FrameHeader m_frame_header;
  1437. TOC m_toc;
  1438. };
  1439. JPEGXLImageDecoderPlugin::JPEGXLImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream> stream)
  1440. {
  1441. m_context = make<JPEGXLLoadingContext>(move(stream));
  1442. }
  1443. JPEGXLImageDecoderPlugin::~JPEGXLImageDecoderPlugin() = default;
  1444. IntSize JPEGXLImageDecoderPlugin::size()
  1445. {
  1446. return m_context->size();
  1447. }
  1448. bool JPEGXLImageDecoderPlugin::sniff(ReadonlyBytes data)
  1449. {
  1450. return data.size() > 2
  1451. && data.data()[0] == 0xFF
  1452. && data.data()[1] == 0x0A;
  1453. }
  1454. ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> JPEGXLImageDecoderPlugin::create(ReadonlyBytes data)
  1455. {
  1456. auto stream = TRY(try_make<FixedMemoryStream>(data));
  1457. auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) JPEGXLImageDecoderPlugin(move(stream))));
  1458. TRY(plugin->m_context->decode_image_header());
  1459. return plugin;
  1460. }
  1461. bool JPEGXLImageDecoderPlugin::is_animated()
  1462. {
  1463. return false;
  1464. }
  1465. size_t JPEGXLImageDecoderPlugin::loop_count()
  1466. {
  1467. return 0;
  1468. }
  1469. size_t JPEGXLImageDecoderPlugin::frame_count()
  1470. {
  1471. return 1;
  1472. }
  1473. size_t JPEGXLImageDecoderPlugin::first_animated_frame_index()
  1474. {
  1475. return 0;
  1476. }
  1477. ErrorOr<ImageFrameDescriptor> JPEGXLImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
  1478. {
  1479. if (index > 0)
  1480. return Error::from_string_literal("JPEGXLImageDecoderPlugin: Invalid frame index");
  1481. if (m_context->state() == JPEGXLLoadingContext::State::Error)
  1482. return Error::from_string_literal("JPEGXLImageDecoderPlugin: Decoding failed");
  1483. if (m_context->state() < JPEGXLLoadingContext::State::FrameDecoded)
  1484. TRY(m_context->decode());
  1485. return ImageFrameDescriptor { m_context->bitmap(), 0 };
  1486. }
  1487. ErrorOr<Optional<ReadonlyBytes>> JPEGXLImageDecoderPlugin::icc_data()
  1488. {
  1489. return OptionalNone {};
  1490. }
  1491. }