TestImageDecoder.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/DeprecatedString.h>
  8. #include <LibCore/MappedFile.h>
  9. #include <LibGfx/ImageFormats/BMPLoader.h>
  10. #include <LibGfx/ImageFormats/DDSLoader.h>
  11. #include <LibGfx/ImageFormats/GIFLoader.h>
  12. #include <LibGfx/ImageFormats/ICOLoader.h>
  13. #include <LibGfx/ImageFormats/ILBMLoader.h>
  14. #include <LibGfx/ImageFormats/ImageDecoder.h>
  15. #include <LibGfx/ImageFormats/JPEGLoader.h>
  16. #include <LibGfx/ImageFormats/JPEGXLLoader.h>
  17. #include <LibGfx/ImageFormats/PBMLoader.h>
  18. #include <LibGfx/ImageFormats/PGMLoader.h>
  19. #include <LibGfx/ImageFormats/PNGLoader.h>
  20. #include <LibGfx/ImageFormats/PPMLoader.h>
  21. #include <LibGfx/ImageFormats/TGALoader.h>
  22. #include <LibGfx/ImageFormats/TIFFLoader.h>
  23. #include <LibGfx/ImageFormats/TinyVGLoader.h>
  24. #include <LibGfx/ImageFormats/WebPLoader.h>
  25. #include <LibTest/TestCase.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #ifdef AK_OS_SERENITY
  29. # define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x)
  30. #else
  31. # define TEST_INPUT(x) ("test-inputs/" x)
  32. #endif
  33. static ErrorOr<Gfx::ImageFrameDescriptor> expect_single_frame(Gfx::ImageDecoderPlugin& plugin_decoder)
  34. {
  35. EXPECT_EQ(plugin_decoder.frame_count(), 1u);
  36. EXPECT(!plugin_decoder.is_animated());
  37. EXPECT(!plugin_decoder.loop_count());
  38. auto frame = TRY(plugin_decoder.frame(0));
  39. EXPECT_EQ(frame.duration, 0);
  40. return frame;
  41. }
  42. static ErrorOr<Gfx::ImageFrameDescriptor> expect_single_frame_of_size(Gfx::ImageDecoderPlugin& plugin_decoder, Gfx::IntSize size)
  43. {
  44. EXPECT_EQ(plugin_decoder.size(), size);
  45. auto frame = TRY(expect_single_frame(plugin_decoder));
  46. EXPECT_EQ(frame.image->size(), size);
  47. return frame;
  48. }
  49. TEST_CASE(test_bmp)
  50. {
  51. auto file = MUST(Core::MappedFile::map(TEST_INPUT("bmp/rgba32-1.bmp"sv)));
  52. EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
  53. auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
  54. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  55. }
  56. TEST_CASE(test_bmp_top_down)
  57. {
  58. auto file = MUST(Core::MappedFile::map(TEST_INPUT("bmp/top-down.bmp"sv)));
  59. EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
  60. auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
  61. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  62. }
  63. TEST_CASE(test_ico_malformed_frame)
  64. {
  65. Array test_inputs = {
  66. TEST_INPUT("ico/oss-fuzz-testcase-62541.ico"sv),
  67. TEST_INPUT("ico/oss-fuzz-testcase-63177.ico"sv),
  68. TEST_INPUT("ico/oss-fuzz-testcase-63357.ico"sv)
  69. };
  70. for (auto test_input : test_inputs) {
  71. auto file = MUST(Core::MappedFile::map(test_input));
  72. auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
  73. auto frame_or_error = plugin_decoder->frame(0);
  74. EXPECT(frame_or_error.is_error());
  75. }
  76. }
  77. TEST_CASE(test_gif)
  78. {
  79. auto file = MUST(Core::MappedFile::map(TEST_INPUT("download-animation.gif"sv)));
  80. EXPECT(Gfx::GIFImageDecoderPlugin::sniff(file->bytes()));
  81. auto plugin_decoder = TRY_OR_FAIL(Gfx::GIFImageDecoderPlugin::create(file->bytes()));
  82. EXPECT(plugin_decoder->frame_count());
  83. EXPECT(plugin_decoder->is_animated());
  84. EXPECT(!plugin_decoder->loop_count());
  85. auto frame = MUST(plugin_decoder->frame(1));
  86. EXPECT(frame.duration == 400);
  87. }
  88. TEST_CASE(test_not_ico)
  89. {
  90. auto file = MUST(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv)));
  91. EXPECT(!Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
  92. EXPECT(Gfx::ICOImageDecoderPlugin::create(file->bytes()).is_error());
  93. }
  94. TEST_CASE(test_bmp_embedded_in_ico)
  95. {
  96. auto file = MUST(Core::MappedFile::map(TEST_INPUT("serenity.ico"sv)));
  97. EXPECT(Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
  98. auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
  99. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  100. }
  101. TEST_CASE(test_ilbm)
  102. {
  103. auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/gradient.iff"sv)));
  104. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  105. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  106. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 }));
  107. EXPECT_EQ(frame.image->get_pixel(8, 0), Gfx::Color(0xee, 0xbb, 0, 255));
  108. }
  109. TEST_CASE(test_ilbm_uncompressed)
  110. {
  111. auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/gradient-uncompressed.iff"sv)));
  112. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  113. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  114. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 }));
  115. EXPECT_EQ(frame.image->get_pixel(8, 0), Gfx::Color(0xee, 0xbb, 0, 255));
  116. }
  117. TEST_CASE(test_ilbm_ham6)
  118. {
  119. auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/ham6.iff"sv)));
  120. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  121. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  122. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 256, 256 }));
  123. EXPECT_EQ(frame.image->get_pixel(77, 107), Gfx::Color(0xf0, 0x40, 0x40, 0xff));
  124. }
  125. TEST_CASE(test_ilbm_malformed_header)
  126. {
  127. Array test_inputs = {
  128. TEST_INPUT("ilbm/truncated-bmhd-chunk.iff"sv)
  129. };
  130. for (auto test_input : test_inputs) {
  131. auto file = MUST(Core::MappedFile::map(test_input));
  132. auto plugin_decoder_or_error = Gfx::ILBMImageDecoderPlugin::create(file->bytes());
  133. EXPECT(plugin_decoder_or_error.is_error());
  134. }
  135. }
  136. TEST_CASE(test_ilbm_malformed_frame)
  137. {
  138. Array test_inputs = {
  139. TEST_INPUT("ilbm/incorrect-cmap-size.iff"sv),
  140. TEST_INPUT("ilbm/incorrect-uncompressed-size.iff"sv),
  141. TEST_INPUT("ilbm/missing-body-chunk.iff"sv)
  142. };
  143. for (auto test_input : test_inputs) {
  144. auto file = MUST(Core::MappedFile::map(test_input));
  145. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  146. auto frame_or_error = plugin_decoder->frame(0);
  147. EXPECT(frame_or_error.is_error());
  148. }
  149. }
  150. TEST_CASE(test_jpeg_sof0_one_scan)
  151. {
  152. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/rgb24.jpg"sv)));
  153. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  154. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  155. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  156. }
  157. TEST_CASE(test_jpeg_sof0_several_scans)
  158. {
  159. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/several_scans.jpg"sv)));
  160. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  161. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  162. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  163. }
  164. TEST_CASE(test_jpeg_rgb_components)
  165. {
  166. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/rgb_components.jpg"sv)));
  167. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  168. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  169. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  170. }
  171. TEST_CASE(test_jpeg_sof2_spectral_selection)
  172. {
  173. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/spectral_selection.jpg"sv)));
  174. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  175. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  176. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  177. }
  178. TEST_CASE(test_jpeg_sof0_several_scans_odd_number_mcu)
  179. {
  180. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/several_scans_odd_number_mcu.jpg"sv)));
  181. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  182. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  183. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 600, 600 }));
  184. }
  185. TEST_CASE(test_jpeg_sof2_successive_aproximation)
  186. {
  187. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/successive_approximation.jpg"sv)));
  188. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  189. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  190. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 600, 800 }));
  191. }
  192. TEST_CASE(test_jpeg_sof1_12bits)
  193. {
  194. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/12-bit.jpg"sv)));
  195. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  196. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  197. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 }));
  198. }
  199. TEST_CASE(test_jpeg_sof2_12bits)
  200. {
  201. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/12-bit-progressive.jpg"sv)));
  202. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  203. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  204. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 }));
  205. }
  206. TEST_CASE(test_jpeg_empty_icc)
  207. {
  208. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/gradient_empty_icc.jpg"sv)));
  209. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  210. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  211. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 }));
  212. }
  213. TEST_CASE(test_jpeg_grayscale_with_app14)
  214. {
  215. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/grayscale_app14.jpg"sv)));
  216. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  217. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  218. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 }));
  219. }
  220. TEST_CASE(test_jpeg_malformed_header)
  221. {
  222. Array test_inputs = {
  223. TEST_INPUT("jpg/oss-fuzz-testcase-59785.jpg"sv)
  224. };
  225. for (auto test_input : test_inputs) {
  226. auto file = MUST(Core::MappedFile::map(test_input));
  227. auto plugin_decoder_or_error = Gfx::JPEGImageDecoderPlugin::create(file->bytes());
  228. EXPECT(plugin_decoder_or_error.is_error());
  229. }
  230. }
  231. TEST_CASE(test_jpeg_malformed_frame)
  232. {
  233. Array test_inputs = {
  234. TEST_INPUT("jpg/oss-fuzz-testcase-62584.jpg"sv),
  235. TEST_INPUT("jpg/oss-fuzz-testcase-63815.jpg"sv)
  236. };
  237. for (auto test_input : test_inputs) {
  238. auto file = MUST(Core::MappedFile::map(test_input));
  239. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  240. auto frame_or_error = plugin_decoder->frame(0);
  241. EXPECT(frame_or_error.is_error());
  242. }
  243. }
  244. TEST_CASE(test_pbm)
  245. {
  246. auto file = MUST(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.pbm"sv)));
  247. EXPECT(Gfx::PBMImageDecoderPlugin::sniff(file->bytes()));
  248. auto plugin_decoder = TRY_OR_FAIL(Gfx::PBMImageDecoderPlugin::create(file->bytes()));
  249. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  250. }
  251. TEST_CASE(test_pgm)
  252. {
  253. auto file = MUST(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.pgm"sv)));
  254. EXPECT(Gfx::PGMImageDecoderPlugin::sniff(file->bytes()));
  255. auto plugin_decoder = TRY_OR_FAIL(Gfx::PGMImageDecoderPlugin::create(file->bytes()));
  256. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  257. }
  258. TEST_CASE(test_png)
  259. {
  260. auto file = MUST(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv)));
  261. EXPECT(Gfx::PNGImageDecoderPlugin::sniff(file->bytes()));
  262. auto plugin_decoder = TRY_OR_FAIL(Gfx::PNGImageDecoderPlugin::create(file->bytes()));
  263. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  264. }
  265. TEST_CASE(test_png_malformed_frame)
  266. {
  267. Array test_inputs = {
  268. TEST_INPUT("png/oss-fuzz-testcase-62371.png"sv),
  269. TEST_INPUT("png/oss-fuzz-testcase-63052.png"sv)
  270. };
  271. for (auto test_input : test_inputs) {
  272. auto file = MUST(Core::MappedFile::map(test_input));
  273. auto plugin_decoder = TRY_OR_FAIL(Gfx::PNGImageDecoderPlugin::create(file->bytes()));
  274. auto frame_or_error = plugin_decoder->frame(0);
  275. EXPECT(frame_or_error.is_error());
  276. }
  277. }
  278. TEST_CASE(test_ppm)
  279. {
  280. auto file = MUST(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.ppm"sv)));
  281. EXPECT(Gfx::PPMImageDecoderPlugin::sniff(file->bytes()));
  282. auto plugin_decoder = TRY_OR_FAIL(Gfx::PPMImageDecoderPlugin::create(file->bytes()));
  283. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  284. }
  285. TEST_CASE(test_targa_bottom_left)
  286. {
  287. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-uncompressed.tga"sv)));
  288. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  289. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  290. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  291. }
  292. TEST_CASE(test_targa_top_left)
  293. {
  294. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-uncompressed.tga"sv)));
  295. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  296. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  297. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  298. }
  299. TEST_CASE(test_targa_bottom_left_compressed)
  300. {
  301. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-compressed.tga"sv)));
  302. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  303. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  304. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  305. }
  306. TEST_CASE(test_targa_top_left_compressed)
  307. {
  308. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-compressed.tga"sv)));
  309. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  310. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  311. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  312. }
  313. TEST_CASE(test_tiff_uncompressed)
  314. {
  315. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/uncompressed.tiff"sv)));
  316. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  317. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  318. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  319. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  320. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  321. }
  322. TEST_CASE(test_tiff_lzw)
  323. {
  324. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/lzw.tiff"sv)));
  325. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  326. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  327. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  328. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  329. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  330. }
  331. TEST_CASE(test_tiff_packed_bits)
  332. {
  333. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/packed_bits.tiff"sv)));
  334. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  335. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  336. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  337. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  338. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  339. }
  340. TEST_CASE(test_tiff_grayscale)
  341. {
  342. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/grayscale.tiff"sv)));
  343. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  344. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  345. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  346. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  347. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color(130, 130, 130));
  348. }
  349. TEST_CASE(test_tiff_16_bits)
  350. {
  351. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/16_bits.tiff"sv)));
  352. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  353. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  354. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  355. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  356. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  357. }
  358. TEST_CASE(test_webp_simple_lossy)
  359. {
  360. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8.webp"sv)));
  361. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  362. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  363. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 240, 240 }));
  364. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  365. // So pixels changing by 1 or so below is fine if you change code.
  366. EXPECT_EQ(frame.image->get_pixel(120, 232), Gfx::Color(0xf2, 0xef, 0xf0, 255));
  367. EXPECT_EQ(frame.image->get_pixel(198, 202), Gfx::Color(0x7b, 0xaa, 0xd5, 255));
  368. }
  369. TEST_CASE(test_webp_simple_lossless)
  370. {
  371. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8l.webp"sv)));
  372. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  373. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  374. // Ironically, simple-vp8l.webp is a much more complex file than extended-lossless.webp tested below.
  375. // extended-lossless.webp tests the decoding basics.
  376. // This here tests the predictor, color, and subtract green transforms,
  377. // as well as meta prefix images, one-element canonical code handling,
  378. // and handling of canonical codes with more than 288 elements.
  379. // This image uses all 13 predictor modes of the predictor transform.
  380. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 386, 395 }));
  381. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0));
  382. // This pixel tests all predictor modes except 5, 7, 8, 9, and 13.
  383. EXPECT_EQ(frame.image->get_pixel(289, 332), Gfx::Color(0xf2, 0xee, 0xd3, 255));
  384. }
  385. TEST_CASE(test_webp_simple_lossless_alpha_used_false)
  386. {
  387. // This file is identical to simple-vp8l.webp, but the `is_alpha_used` used bit is false.
  388. // The file still contains alpha data. This tests that the decoder replaces the stored alpha data with 0xff if `is_alpha_used` is false.
  389. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8l-alpha-used-false.webp"sv)));
  390. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  391. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  392. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 386, 395 }));
  393. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0xff));
  394. }
  395. TEST_CASE(test_webp_extended_lossy)
  396. {
  397. // This extended lossy image has an ALPH chunk for (losslessly compressed) alpha data.
  398. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossy.webp"sv)));
  399. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  400. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  401. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 }));
  402. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  403. // So pixels changing by 1 or so below is fine if you change code.
  404. EXPECT_EQ(frame.image->get_pixel(89, 72), Gfx::Color(255, 1, 0, 255));
  405. EXPECT_EQ(frame.image->get_pixel(174, 69), Gfx::Color(0, 255, 0, 255));
  406. EXPECT_EQ(frame.image->get_pixel(245, 84), Gfx::Color(0, 0, 255, 255));
  407. EXPECT_EQ(frame.image->get_pixel(352, 125), Gfx::Color(0, 0, 0, 128));
  408. EXPECT_EQ(frame.image->get_pixel(355, 106), Gfx::Color(0, 0, 0, 0));
  409. // Check same basic pixels as in test_webp_extended_lossless too.
  410. // (The top-left pixel in the lossy version is fully transparent white, compared to fully transparent black in the lossless version).
  411. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(255, 255, 255, 0));
  412. EXPECT_EQ(frame.image->get_pixel(43, 75), Gfx::Color(255, 0, 2, 255));
  413. EXPECT_EQ(frame.image->get_pixel(141, 75), Gfx::Color(0, 255, 3, 255));
  414. EXPECT_EQ(frame.image->get_pixel(235, 75), Gfx::Color(0, 0, 255, 255));
  415. EXPECT_EQ(frame.image->get_pixel(341, 75), Gfx::Color(0, 0, 0, 128));
  416. }
  417. TEST_CASE(test_webp_extended_lossy_alpha_horizontal_filter)
  418. {
  419. // Also lossy rgb + lossless alpha, but with a horizontal alpha filtering method.
  420. // The image should look like smolkling.webp, but with a horizontal alpha gradient.
  421. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling-horizontal-alpha.webp"sv)));
  422. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  423. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  424. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  425. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  426. // So pixels changing by 1 or so below is fine if you change code.
  427. // The important component in this test is alpha, and that shouldn't change even by 1 as it's losslessly compressed and doesn't use YUV.
  428. EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x8f, 0x51, 0x2f, 0x4b));
  429. }
  430. TEST_CASE(test_webp_extended_lossy_alpha_vertical_filter)
  431. {
  432. // Also lossy rgb + lossless alpha, but with a vertical alpha filtering method.
  433. // The image should look like smolkling.webp, but with a vertical alpha gradient, and with a fully transparent first column.
  434. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling-vertical-alpha.webp"sv)));
  435. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  436. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  437. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  438. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  439. // So pixels changing by 1 or so below is fine if you change code.
  440. // The important component in this test is alpha, and that shouldn't change even by 1 as it's losslessly compressed and doesn't use YUV.
  441. EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x94, 0x50, 0x32, 0x4c));
  442. }
  443. TEST_CASE(test_webp_extended_lossy_alpha_gradient_filter)
  444. {
  445. // Also lossy rgb + lossless alpha, but with a gradient alpha filtering method.
  446. // The image should look like smolkling.webp, but with a few transparent pixels in the shape of a C on it. Most of the image should not be transparent.
  447. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling-gradient-alpha.webp"sv)));
  448. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  449. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  450. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  451. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  452. // So pixels changing by 1 or so below is fine if you change code.
  453. // The important component in this test is alpha, and that shouldn't change even by 1 as it's losslessly compressed and doesn't use YUV.
  454. // In particular, the center of the image should be fully opaque, not fully transparent.
  455. EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x8c, 0x47, 0x2e, 255));
  456. }
  457. TEST_CASE(test_webp_extended_lossy_uncompressed_alpha)
  458. {
  459. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossy-uncompressed-alpha.webp"sv)));
  460. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  461. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  462. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 }));
  463. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  464. // So pixels changing by 1 or so below is fine if you change code.
  465. EXPECT_EQ(frame.image->get_pixel(89, 72), Gfx::Color(255, 0, 4, 255));
  466. EXPECT_EQ(frame.image->get_pixel(174, 69), Gfx::Color(4, 255, 0, 255));
  467. EXPECT_EQ(frame.image->get_pixel(245, 84), Gfx::Color(0, 0, 255, 255));
  468. EXPECT_EQ(frame.image->get_pixel(352, 125), Gfx::Color(0, 0, 0, 128));
  469. EXPECT_EQ(frame.image->get_pixel(355, 106), Gfx::Color(0, 0, 0, 0));
  470. }
  471. TEST_CASE(test_webp_extended_lossy_negative_quantization_offset)
  472. {
  473. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling.webp"sv)));
  474. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  475. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  476. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  477. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  478. // So pixels changing by 1 or so below is fine if you change code.
  479. EXPECT_EQ(frame.image->get_pixel(16, 16), Gfx::Color(0x3c, 0x24, 0x1a, 255));
  480. }
  481. TEST_CASE(test_webp_lossy_4)
  482. {
  483. // This is https://commons.wikimedia.org/wiki/File:Fr%C3%BChling_bl%C3%BChender_Kirschenbaum.jpg,
  484. // under the Creative Commons Attribution-Share Alike 3.0 Unported license. The image was re-encoded
  485. // as webp at https://developers.google.com/speed/webp/gallery1 and the webp version is from there.
  486. // No other changes have been made.
  487. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/4.webp"sv)));
  488. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  489. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  490. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 772 }));
  491. // This image tests macroblocks that have `skip_coefficients` set to true, and it test a boolean entropy decoder edge case.
  492. EXPECT_EQ(frame.image->get_pixel(780, 570), Gfx::Color(0x72, 0xc8, 0xf6, 255));
  493. }
  494. TEST_CASE(test_webp_lossy_4_with_partitions)
  495. {
  496. // Same input file as in the previous test, but re-encoded to use 8 secondary partitions.
  497. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/4-with-8-partitions.webp"sv)));
  498. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  499. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  500. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 772 }));
  501. EXPECT_EQ(frame.image->get_pixel(780, 570), Gfx::Color(0x73, 0xc9, 0xf9, 255));
  502. }
  503. TEST_CASE(test_webp_extended_lossless)
  504. {
  505. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossless.webp"sv)));
  506. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  507. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  508. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 }));
  509. // Check some basic pixels.
  510. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0));
  511. EXPECT_EQ(frame.image->get_pixel(43, 75), Gfx::Color(255, 0, 0, 255));
  512. EXPECT_EQ(frame.image->get_pixel(141, 75), Gfx::Color(0, 255, 0, 255));
  513. EXPECT_EQ(frame.image->get_pixel(235, 75), Gfx::Color(0, 0, 255, 255));
  514. EXPECT_EQ(frame.image->get_pixel(341, 75), Gfx::Color(0, 0, 0, 128));
  515. // Check pixels using the color cache.
  516. EXPECT_EQ(frame.image->get_pixel(94, 73), Gfx::Color(255, 0, 0, 255));
  517. EXPECT_EQ(frame.image->get_pixel(176, 115), Gfx::Color(0, 255, 0, 255));
  518. EXPECT_EQ(frame.image->get_pixel(290, 89), Gfx::Color(0, 0, 255, 255));
  519. EXPECT_EQ(frame.image->get_pixel(359, 73), Gfx::Color(0, 0, 0, 128));
  520. }
  521. TEST_CASE(test_webp_simple_lossless_color_index_transform)
  522. {
  523. // In addition to testing the index transform, this file also tests handling of explicity setting max_symbol.
  524. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/Qpalette.webp"sv)));
  525. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  526. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  527. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 256, 256 }));
  528. EXPECT_EQ(frame.image->get_pixel(100, 100), Gfx::Color(0x73, 0x37, 0x23, 0xff));
  529. }
  530. TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling)
  531. {
  532. struct TestCase {
  533. StringView file_name;
  534. Gfx::Color line_color;
  535. Gfx::Color background_color;
  536. };
  537. // The number after the dash is the number of colors in each file's color index bitmap.
  538. // catdog-alert-2 tests the 1-bit-per-pixel case,
  539. // catdog-alert-3 tests the 2-bit-per-pixel case,
  540. // catdog-alert-8 and catdog-alert-13 both test the 4-bits-per-pixel case.
  541. // catdog-alert-13-alpha-used-false is like catdog-alert-13, but with is_alpha_used set to false in the header
  542. // (which has the effect of ignoring the alpha information in the palette and instead always setting alpha to 0xff).
  543. TestCase test_cases[] = {
  544. { "webp/catdog-alert-2.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0xf3, 0xe6, 0xd8, 0xff) },
  545. { "webp/catdog-alert-3.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0, 0, 0, 0) },
  546. { "webp/catdog-alert-8.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
  547. { "webp/catdog-alert-13.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
  548. { "webp/catdog-alert-13-alpha-used-false.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 255) },
  549. };
  550. for (auto test_case : test_cases) {
  551. auto file = MUST(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), test_case.file_name))));
  552. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  553. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  554. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 }));
  555. EXPECT_EQ(frame.image->get_pixel(4, 0), test_case.background_color);
  556. EXPECT_EQ(frame.image->get_pixel(5, 0), test_case.line_color);
  557. EXPECT_EQ(frame.image->get_pixel(9, 5), test_case.background_color);
  558. EXPECT_EQ(frame.image->get_pixel(10, 5), test_case.line_color);
  559. EXPECT_EQ(frame.image->get_pixel(11, 5), test_case.background_color);
  560. }
  561. }
  562. TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling_odd_width)
  563. {
  564. StringView file_names[] = {
  565. "webp/width11-height11-colors2.webp"sv,
  566. "webp/width11-height11-colors3.webp"sv,
  567. "webp/width11-height11-colors15.webp"sv,
  568. };
  569. for (auto file_name : file_names) {
  570. auto file = MUST(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), file_name))));
  571. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  572. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 11, 11 }));
  573. }
  574. }
  575. TEST_CASE(test_webp_extended_lossless_animated)
  576. {
  577. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossless-animated.webp"sv)));
  578. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  579. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  580. EXPECT_EQ(plugin_decoder->frame_count(), 8u);
  581. EXPECT(plugin_decoder->is_animated());
  582. EXPECT_EQ(plugin_decoder->loop_count(), 42u);
  583. EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(990, 1050));
  584. for (size_t frame_index = 0; frame_index < plugin_decoder->frame_count(); ++frame_index) {
  585. auto frame = MUST(plugin_decoder->frame(frame_index));
  586. EXPECT_EQ(frame.image->size(), Gfx::IntSize(990, 1050));
  587. // This pixel happens to be the same color in all frames.
  588. EXPECT_EQ(frame.image->get_pixel(500, 700), Gfx::Color::Yellow);
  589. // This one isn't the same in all frames.
  590. EXPECT_EQ(frame.image->get_pixel(500, 0), (frame_index == 2 || frame_index == 6) ? Gfx::Color::Black : Gfx::Color(255, 255, 255, 0));
  591. }
  592. }
  593. TEST_CASE(test_tvg)
  594. {
  595. auto file = MUST(Core::MappedFile::map(TEST_INPUT("tvg/yak.tvg"sv)));
  596. EXPECT(Gfx::TinyVGImageDecoderPlugin::sniff(file->bytes()));
  597. auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes()));
  598. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 1024 }));
  599. }
  600. TEST_CASE(test_everything_tvg)
  601. {
  602. Array file_names {
  603. TEST_INPUT("tvg/everything.tvg"sv),
  604. TEST_INPUT("tvg/everything-32.tvg"sv)
  605. };
  606. for (auto file_name : file_names) {
  607. auto file = MUST(Core::MappedFile::map(file_name));
  608. EXPECT(Gfx::TinyVGImageDecoderPlugin::sniff(file->bytes()));
  609. auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes()));
  610. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 768 }));
  611. }
  612. }
  613. TEST_CASE(test_tvg_malformed)
  614. {
  615. Array test_inputs = {
  616. TEST_INPUT("tvg/bogus-color-table-size.tvg"sv)
  617. };
  618. for (auto test_input : test_inputs) {
  619. auto file = MUST(Core::MappedFile::map(test_input));
  620. auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes()));
  621. auto frame_or_error = plugin_decoder->frame(0);
  622. EXPECT(frame_or_error.is_error());
  623. }
  624. }
  625. TEST_CASE(test_jxl_modular_simple_tree_upsample2_10bits)
  626. {
  627. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jxl/modular_simple_tree_upsample2_10bits_rct.jxl"sv)));
  628. EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes()));
  629. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes()));
  630. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 128, 128 }));
  631. auto frame = MUST(plugin_decoder->frame(0));
  632. EXPECT_EQ(frame.image->get_pixel(42, 57), Gfx::Color::from_string("#4c0072"sv));
  633. }
  634. TEST_CASE(test_jxl_modular_property_8)
  635. {
  636. auto file = MUST(Core::MappedFile::map(TEST_INPUT("jxl/modular_property_8.jxl"sv)));
  637. EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes()));
  638. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes()));
  639. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 }));
  640. auto frame = MUST(plugin_decoder->frame(0));
  641. for (u8 i = 0; i < 32; ++i) {
  642. for (u8 j = 0; j < 32; ++j) {
  643. auto const color = frame.image->get_pixel(i, j);
  644. if ((i + j) % 2 == 0)
  645. EXPECT_EQ(color, Gfx::Color::Black);
  646. else
  647. EXPECT_EQ(color, Gfx::Color::Yellow);
  648. }
  649. }
  650. }
  651. TEST_CASE(test_dds)
  652. {
  653. Array file_names = {
  654. TEST_INPUT("dds/catdog-alert-29x29.dds"sv),
  655. TEST_INPUT("dds/catdog-alert-32x32.dds"sv)
  656. };
  657. for (auto file_name : file_names) {
  658. auto file = MUST(Core::MappedFile::map(file_name));
  659. EXPECT(Gfx::DDSImageDecoderPlugin::sniff(file->bytes()));
  660. auto plugin_decoder = TRY_OR_FAIL(Gfx::DDSImageDecoderPlugin::create(file->bytes()));
  661. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  662. }
  663. }