TestImageDecoder.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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/ByteString.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/PAMLoader.h>
  18. #include <LibGfx/ImageFormats/PBMLoader.h>
  19. #include <LibGfx/ImageFormats/PGMLoader.h>
  20. #include <LibGfx/ImageFormats/PNGLoader.h>
  21. #include <LibGfx/ImageFormats/PPMLoader.h>
  22. #include <LibGfx/ImageFormats/TGALoader.h>
  23. #include <LibGfx/ImageFormats/TIFFLoader.h>
  24. #include <LibGfx/ImageFormats/TinyVGLoader.h>
  25. #include <LibGfx/ImageFormats/WebPLoader.h>
  26. #include <LibTest/TestCase.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #ifdef AK_OS_SERENITY
  30. # define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x)
  31. #else
  32. # define TEST_INPUT(x) ("test-inputs/" x)
  33. #endif
  34. static ErrorOr<Gfx::ImageFrameDescriptor> expect_single_frame(Gfx::ImageDecoderPlugin& plugin_decoder)
  35. {
  36. EXPECT_EQ(plugin_decoder.frame_count(), 1u);
  37. EXPECT(!plugin_decoder.is_animated());
  38. EXPECT(!plugin_decoder.loop_count());
  39. auto frame = TRY(plugin_decoder.frame(0));
  40. EXPECT_EQ(frame.duration, 0);
  41. return frame;
  42. }
  43. static ErrorOr<Gfx::ImageFrameDescriptor> expect_single_frame_of_size(Gfx::ImageDecoderPlugin& plugin_decoder, Gfx::IntSize size)
  44. {
  45. EXPECT_EQ(plugin_decoder.size(), size);
  46. auto frame = TRY(expect_single_frame(plugin_decoder));
  47. EXPECT_EQ(frame.image->size(), size);
  48. return frame;
  49. }
  50. TEST_CASE(test_bmp)
  51. {
  52. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("bmp/rgba32-1.bmp"sv)));
  53. EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
  54. auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
  55. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  56. }
  57. TEST_CASE(test_bmp_top_down)
  58. {
  59. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("bmp/top-down.bmp"sv)));
  60. EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
  61. auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
  62. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  63. }
  64. TEST_CASE(test_ico_malformed_frame)
  65. {
  66. Array test_inputs = {
  67. TEST_INPUT("ico/oss-fuzz-testcase-62541.ico"sv),
  68. TEST_INPUT("ico/oss-fuzz-testcase-63177.ico"sv),
  69. TEST_INPUT("ico/oss-fuzz-testcase-63357.ico"sv)
  70. };
  71. for (auto test_input : test_inputs) {
  72. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  73. auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
  74. auto frame_or_error = plugin_decoder->frame(0);
  75. EXPECT(frame_or_error.is_error());
  76. }
  77. }
  78. TEST_CASE(test_gif)
  79. {
  80. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("download-animation.gif"sv)));
  81. EXPECT(Gfx::GIFImageDecoderPlugin::sniff(file->bytes()));
  82. auto plugin_decoder = TRY_OR_FAIL(Gfx::GIFImageDecoderPlugin::create(file->bytes()));
  83. EXPECT(plugin_decoder->frame_count());
  84. EXPECT(plugin_decoder->is_animated());
  85. EXPECT(!plugin_decoder->loop_count());
  86. auto frame = TRY_OR_FAIL(plugin_decoder->frame(1));
  87. EXPECT(frame.duration == 400);
  88. }
  89. TEST_CASE(test_gif_without_global_color_table)
  90. {
  91. Array<u8, 35> gif_data {
  92. // Header (6 bytes): "GIF89a"
  93. 0x47,
  94. 0x49,
  95. 0x46,
  96. 0x38,
  97. 0x39,
  98. 0x61,
  99. // Logical Screen Descriptor (7 bytes)
  100. 0x01,
  101. 0x00, // Width (1)
  102. 0x01,
  103. 0x00, // Height (1)
  104. 0x00, // Packed fields (NOTE: the MSB here is the Global Color Table flag!)
  105. 0x00, // Background Color Index
  106. 0x00, // Pixel Aspect Ratio
  107. // Image Descriptor (10 bytes)
  108. 0x2C,
  109. 0x00,
  110. 0x00,
  111. 0x00,
  112. 0x00,
  113. 0x01,
  114. 0x00,
  115. 0x01,
  116. 0x00,
  117. 0x80,
  118. // Local Color Table (6 bytes: 2 colors, 3 bytes per color)
  119. 0x00,
  120. 0x00,
  121. 0x00, // Color 1: Black (RGB: 0, 0, 0)
  122. 0xff,
  123. 0x00,
  124. 0x00, // Color 2: Red (RGB: 255, 0, 0)
  125. // Image Data (8 bytes)
  126. 0x02, // LZW Minimum Code Size
  127. 0x02, // Data Sub-block size (2 bytes)
  128. 0x4C,
  129. 0x01, // Image Data
  130. 0x00, // Data Sub-block Terminator
  131. // Trailer (1 byte)
  132. 0x3B,
  133. };
  134. auto plugin_decoder = TRY_OR_FAIL(Gfx::GIFImageDecoderPlugin::create(gif_data));
  135. EXPECT_EQ(plugin_decoder->frame_count(), 1u);
  136. auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
  137. EXPECT(frame.image);
  138. EXPECT_EQ(frame.image->size(), Gfx::IntSize(1, 1));
  139. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Red);
  140. }
  141. TEST_CASE(test_not_ico)
  142. {
  143. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv)));
  144. EXPECT(!Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
  145. EXPECT(Gfx::ICOImageDecoderPlugin::create(file->bytes()).is_error());
  146. }
  147. TEST_CASE(test_bmp_embedded_in_ico)
  148. {
  149. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ico/serenity.ico"sv)));
  150. EXPECT(Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
  151. auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
  152. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 16, 16 }));
  153. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Transparent);
  154. EXPECT_EQ(frame.image->get_pixel(7, 4), Gfx::Color(161, 0, 0));
  155. }
  156. TEST_CASE(test_malformed_maskless_ico)
  157. {
  158. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ico/malformed_maskless.ico"sv)));
  159. EXPECT(Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
  160. auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
  161. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 16, 16 }));
  162. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Transparent);
  163. EXPECT_EQ(frame.image->get_pixel(7, 4), Gfx::Color(161, 0, 0));
  164. }
  165. TEST_CASE(test_ilbm)
  166. {
  167. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/gradient.iff"sv)));
  168. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  169. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  170. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 }));
  171. EXPECT_EQ(frame.image->get_pixel(8, 0), Gfx::Color(0xee, 0xbb, 0, 255));
  172. }
  173. TEST_CASE(test_ilbm_uncompressed)
  174. {
  175. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/gradient-uncompressed.iff"sv)));
  176. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  177. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  178. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 }));
  179. EXPECT_EQ(frame.image->get_pixel(8, 0), Gfx::Color(0xee, 0xbb, 0, 255));
  180. }
  181. TEST_CASE(test_ilbm_ham6)
  182. {
  183. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/ham6.iff"sv)));
  184. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  185. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  186. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 256, 256 }));
  187. EXPECT_EQ(frame.image->get_pixel(77, 107), Gfx::Color(0xf0, 0x40, 0x40, 0xff));
  188. }
  189. TEST_CASE(test_ilbm_dos)
  190. {
  191. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/serenity.lbm"sv)));
  192. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  193. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  194. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 640, 480 }));
  195. EXPECT_EQ(frame.image->get_pixel(315, 134), Gfx::Color::NamedColor::Red);
  196. }
  197. TEST_CASE(test_24bit)
  198. {
  199. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/serenity-24bit.iff"sv)));
  200. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  201. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  202. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 640, 640 }));
  203. EXPECT_EQ(frame.image->get_pixel(158, 270), Gfx::Color(0xee, 0x3d, 0x3c, 255));
  204. }
  205. TEST_CASE(test_brush_transparent_color)
  206. {
  207. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/brush-transparent-color.iff"sv)));
  208. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  209. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  210. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 266, 309 }));
  211. EXPECT_EQ(frame.image->get_pixel(114, 103), Gfx::Color::NamedColor::Black);
  212. }
  213. TEST_CASE(test_small_24bit)
  214. {
  215. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/small-24bit.iff"sv)));
  216. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  217. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  218. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 10, 10 }));
  219. EXPECT_EQ(frame.image->get_pixel(0, 4), Gfx::Color(1, 0, 1, 255));
  220. }
  221. TEST_CASE(test_stencil_mask)
  222. {
  223. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("ilbm/test-stencil.iff"sv)));
  224. EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes()));
  225. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  226. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 }));
  227. EXPECT_EQ(frame.image->get_pixel(0, 4), Gfx::Color(0, 0, 0, 255));
  228. }
  229. TEST_CASE(test_ilbm_malformed_header)
  230. {
  231. Array test_inputs = {
  232. TEST_INPUT("ilbm/truncated-bmhd-chunk.iff"sv)
  233. };
  234. for (auto test_input : test_inputs) {
  235. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  236. auto plugin_decoder_or_error = Gfx::ILBMImageDecoderPlugin::create(file->bytes());
  237. EXPECT(plugin_decoder_or_error.is_error());
  238. }
  239. }
  240. TEST_CASE(test_ilbm_malformed_frame)
  241. {
  242. Array test_inputs = {
  243. TEST_INPUT("ilbm/incorrect-cmap-size.iff"sv),
  244. TEST_INPUT("ilbm/incorrect-uncompressed-size.iff"sv),
  245. TEST_INPUT("ilbm/missing-body-chunk.iff"sv)
  246. };
  247. for (auto test_input : test_inputs) {
  248. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  249. auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes()));
  250. auto frame_or_error = plugin_decoder->frame(0);
  251. EXPECT(frame_or_error.is_error());
  252. }
  253. }
  254. TEST_CASE(test_jpeg_sof0_one_scan)
  255. {
  256. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/rgb24.jpg"sv)));
  257. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  258. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  259. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  260. }
  261. TEST_CASE(test_jpeg_sof0_several_scans)
  262. {
  263. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/several_scans.jpg"sv)));
  264. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  265. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  266. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  267. }
  268. TEST_CASE(test_odd_mcu_restart_interval)
  269. {
  270. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/odd-restart.jpg"sv)));
  271. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  272. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  273. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 102, 77 }));
  274. }
  275. TEST_CASE(test_jpeg_rgb_components)
  276. {
  277. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/rgb_components.jpg"sv)));
  278. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  279. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  280. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  281. }
  282. TEST_CASE(test_jpeg_ycck)
  283. {
  284. Array test_inputs = {
  285. TEST_INPUT("jpg/ycck-1111.jpg"sv),
  286. TEST_INPUT("jpg/ycck-2111.jpg"sv),
  287. TEST_INPUT("jpg/ycck-2112.jpg"sv),
  288. };
  289. for (auto test_input : test_inputs) {
  290. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  291. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  292. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  293. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  294. // Compare difference between pixels so we don't depend on exact CMYK->RGB conversion behavior.
  295. // These two pixels are currently off by one in R.
  296. // FIXME: For 2111, they're off by way more.
  297. EXPECT(frame.image->get_pixel(6, 319).distance_squared_to(frame.image->get_pixel(6, 320)) < 1.0f / 255.0f);
  298. }
  299. }
  300. TEST_CASE(test_jpeg_sof2_spectral_selection)
  301. {
  302. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/spectral_selection.jpg"sv)));
  303. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  304. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  305. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 }));
  306. }
  307. TEST_CASE(test_jpeg_sof0_several_scans_odd_number_mcu)
  308. {
  309. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/several_scans_odd_number_mcu.jpg"sv)));
  310. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  311. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  312. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 600, 600 }));
  313. }
  314. TEST_CASE(test_jpeg_sof2_successive_aproximation)
  315. {
  316. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/successive_approximation.jpg"sv)));
  317. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  318. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  319. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 600, 800 }));
  320. }
  321. TEST_CASE(test_jpeg_sof1_12bits)
  322. {
  323. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/12-bit.jpg"sv)));
  324. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  325. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  326. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 }));
  327. }
  328. TEST_CASE(test_jpeg_sof2_12bits)
  329. {
  330. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/12-bit-progressive.jpg"sv)));
  331. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  332. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  333. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 }));
  334. }
  335. TEST_CASE(test_jpeg_empty_icc)
  336. {
  337. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/gradient_empty_icc.jpg"sv)));
  338. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  339. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  340. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 }));
  341. }
  342. TEST_CASE(test_jpeg_grayscale_with_app14)
  343. {
  344. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/grayscale_app14.jpg"sv)));
  345. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  346. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  347. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 }));
  348. }
  349. TEST_CASE(test_jpeg_grayscale_with_weird_mcu_and_reset_marker)
  350. {
  351. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/grayscale_mcu.jpg"sv)));
  352. EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
  353. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  354. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 }));
  355. }
  356. TEST_CASE(test_jpeg_malformed_header)
  357. {
  358. Array test_inputs = {
  359. TEST_INPUT("jpg/oss-fuzz-testcase-59785.jpg"sv)
  360. };
  361. for (auto test_input : test_inputs) {
  362. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  363. auto plugin_decoder_or_error = Gfx::JPEGImageDecoderPlugin::create(file->bytes());
  364. EXPECT(plugin_decoder_or_error.is_error());
  365. }
  366. }
  367. TEST_CASE(test_jpeg_malformed_frame)
  368. {
  369. Array test_inputs = {
  370. TEST_INPUT("jpg/oss-fuzz-testcase-62584.jpg"sv),
  371. TEST_INPUT("jpg/oss-fuzz-testcase-63815.jpg"sv)
  372. };
  373. for (auto test_input : test_inputs) {
  374. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  375. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
  376. auto frame_or_error = plugin_decoder->frame(0);
  377. EXPECT(frame_or_error.is_error());
  378. }
  379. }
  380. TEST_CASE(test_pam_rgb)
  381. {
  382. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("pnm/2x1.pam"sv)));
  383. EXPECT(Gfx::PAMImageDecoderPlugin::sniff(file->bytes()));
  384. auto plugin_decoder = TRY_OR_FAIL(Gfx::PAMImageDecoderPlugin::create(file->bytes()));
  385. auto frame = TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  386. EXPECT_EQ(frame.image->size(), Gfx::IntSize(2, 1));
  387. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color('0', 'z', '0'));
  388. EXPECT_EQ(frame.image->get_pixel(1, 0), Gfx::Color('0', '0', 'z'));
  389. }
  390. TEST_CASE(test_pam_cmyk)
  391. {
  392. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("pnm/2x1-cmyk.pam"sv)));
  393. EXPECT(Gfx::PAMImageDecoderPlugin::sniff(file->bytes()));
  394. auto plugin_decoder = TRY_OR_FAIL(Gfx::PAMImageDecoderPlugin::create(file->bytes()));
  395. EXPECT_EQ(plugin_decoder->natural_frame_format(), Gfx::NaturalFrameFormat::CMYK);
  396. auto cmyk_frame = TRY_OR_FAIL(plugin_decoder->cmyk_frame());
  397. EXPECT_EQ(cmyk_frame->size(), Gfx::IntSize(2, 1));
  398. EXPECT_EQ(cmyk_frame->begin()[0], (Gfx::CMYK { '0', 'z', '0', 'y' }));
  399. EXPECT_EQ(cmyk_frame->begin()[1], (Gfx::CMYK { '0', '0', 'z', 'y' }));
  400. auto frame = TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  401. EXPECT_EQ(frame.image->size(), Gfx::IntSize(2, 1));
  402. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color('l', 'E', 'l'));
  403. EXPECT_EQ(frame.image->get_pixel(1, 0), Gfx::Color('l', 'l', 'E'));
  404. }
  405. TEST_CASE(test_pbm)
  406. {
  407. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.pbm"sv)));
  408. EXPECT(Gfx::PBMImageDecoderPlugin::sniff(file->bytes()));
  409. auto plugin_decoder = TRY_OR_FAIL(Gfx::PBMImageDecoderPlugin::create(file->bytes()));
  410. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  411. }
  412. TEST_CASE(test_pgm)
  413. {
  414. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.pgm"sv)));
  415. EXPECT(Gfx::PGMImageDecoderPlugin::sniff(file->bytes()));
  416. auto plugin_decoder = TRY_OR_FAIL(Gfx::PGMImageDecoderPlugin::create(file->bytes()));
  417. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  418. }
  419. TEST_CASE(test_png)
  420. {
  421. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv)));
  422. EXPECT(Gfx::PNGImageDecoderPlugin::sniff(file->bytes()));
  423. auto plugin_decoder = TRY_OR_FAIL(Gfx::PNGImageDecoderPlugin::create(file->bytes()));
  424. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  425. }
  426. TEST_CASE(test_png_malformed_frame)
  427. {
  428. Array test_inputs = {
  429. TEST_INPUT("png/oss-fuzz-testcase-62371.png"sv),
  430. TEST_INPUT("png/oss-fuzz-testcase-63052.png"sv)
  431. };
  432. for (auto test_input : test_inputs) {
  433. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  434. auto plugin_decoder = TRY_OR_FAIL(Gfx::PNGImageDecoderPlugin::create(file->bytes()));
  435. auto frame_or_error = plugin_decoder->frame(0);
  436. EXPECT(frame_or_error.is_error());
  437. }
  438. }
  439. TEST_CASE(test_ppm)
  440. {
  441. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.ppm"sv)));
  442. EXPECT(Gfx::PPMImageDecoderPlugin::sniff(file->bytes()));
  443. auto plugin_decoder = TRY_OR_FAIL(Gfx::PPMImageDecoderPlugin::create(file->bytes()));
  444. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  445. }
  446. TEST_CASE(test_targa_bottom_left)
  447. {
  448. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-uncompressed.tga"sv)));
  449. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  450. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  451. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  452. }
  453. TEST_CASE(test_targa_top_left)
  454. {
  455. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-uncompressed.tga"sv)));
  456. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  457. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  458. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  459. }
  460. TEST_CASE(test_targa_bottom_left_compressed)
  461. {
  462. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-compressed.tga"sv)));
  463. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  464. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  465. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  466. }
  467. TEST_CASE(test_targa_top_left_compressed)
  468. {
  469. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-compressed.tga"sv)));
  470. EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
  471. auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
  472. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  473. }
  474. TEST_CASE(test_tiff_uncompressed)
  475. {
  476. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/uncompressed.tiff"sv)));
  477. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  478. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  479. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  480. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  481. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  482. }
  483. TEST_CASE(test_tiff_ccitt_rle)
  484. {
  485. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/ccitt_rle.tiff"sv)));
  486. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  487. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  488. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  489. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  490. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Black);
  491. }
  492. TEST_CASE(test_tiff_ccitt3)
  493. {
  494. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/ccitt3.tiff"sv)));
  495. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  496. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  497. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  498. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  499. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Black);
  500. }
  501. TEST_CASE(test_tiff_ccitt3_fill)
  502. {
  503. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/ccitt3_1d_fill.tiff"sv)));
  504. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  505. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  506. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 6, 4 }));
  507. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  508. EXPECT_EQ(frame.image->get_pixel(3, 0), Gfx::Color::NamedColor::Black);
  509. EXPECT_EQ(frame.image->get_pixel(2, 2), Gfx::Color::NamedColor::White);
  510. EXPECT_EQ(frame.image->get_pixel(5, 3), Gfx::Color::NamedColor::White);
  511. }
  512. TEST_CASE(test_tiff_lzw)
  513. {
  514. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/lzw.tiff"sv)));
  515. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  516. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  517. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  518. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  519. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  520. }
  521. TEST_CASE(test_tiff_deflate)
  522. {
  523. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/deflate.tiff"sv)));
  524. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  525. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  526. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  527. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  528. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  529. }
  530. TEST_CASE(test_tiff_krita)
  531. {
  532. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/krita.tif"sv)));
  533. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  534. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  535. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  536. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  537. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  538. }
  539. TEST_CASE(test_tiff_orientation)
  540. {
  541. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/orientation.tiff"sv)));
  542. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  543. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  544. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 300, 400 }));
  545. // Orientation is Rotate90Clockwise
  546. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  547. EXPECT_EQ(frame.image->get_pixel(300 - 75, 60), Gfx::Color::NamedColor::Red);
  548. }
  549. TEST_CASE(test_tiff_packed_bits)
  550. {
  551. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/packed_bits.tiff"sv)));
  552. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  553. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  554. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  555. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  556. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  557. }
  558. TEST_CASE(test_tiff_grayscale)
  559. {
  560. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/grayscale.tiff"sv)));
  561. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  562. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  563. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  564. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  565. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color(130, 130, 130));
  566. }
  567. TEST_CASE(test_tiff_grayscale_alpha)
  568. {
  569. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/grayscale_alpha.tiff"sv)));
  570. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  571. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  572. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  573. EXPECT_EQ(frame.image->get_pixel(0, 0).alpha(), 0);
  574. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color(130, 130, 130));
  575. }
  576. TEST_CASE(test_tiff_rgb_alpha)
  577. {
  578. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/rgb_alpha.tiff"sv)));
  579. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  580. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  581. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  582. EXPECT_EQ(frame.image->get_pixel(0, 0).alpha(), 0);
  583. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  584. }
  585. TEST_CASE(test_tiff_palette_alpha)
  586. {
  587. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/rgb_palette_alpha.tiff"sv)));
  588. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  589. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  590. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  591. EXPECT_EQ(frame.image->get_pixel(0, 0).alpha(), 0);
  592. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  593. }
  594. TEST_CASE(test_tiff_alpha_predictor)
  595. {
  596. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/alpha_predictor.tiff"sv)));
  597. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  598. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  599. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  600. EXPECT_EQ(frame.image->get_pixel(0, 0).alpha(), 255);
  601. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  602. }
  603. TEST_CASE(test_tiff_16_bits)
  604. {
  605. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/16_bits.tiff"sv)));
  606. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  607. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  608. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  609. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  610. EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
  611. }
  612. TEST_CASE(test_tiff_cmyk)
  613. {
  614. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/cmyk.tiff"sv)));
  615. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  616. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  617. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 }));
  618. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
  619. // I stripped the ICC profile from the image, so we can't test for equality with Red here.
  620. EXPECT_NE(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::White);
  621. }
  622. TEST_CASE(test_tiff_invalid_tag)
  623. {
  624. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/invalid_tag.tiff"sv)));
  625. EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
  626. auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
  627. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 10, 10 }));
  628. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Black);
  629. EXPECT_EQ(frame.image->get_pixel(0, 9), Gfx::Color::NamedColor::White);
  630. }
  631. TEST_CASE(test_webp_simple_lossy)
  632. {
  633. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8.webp"sv)));
  634. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  635. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  636. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 240, 240 }));
  637. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  638. // So pixels changing by 1 or so below is fine if you change code.
  639. EXPECT_EQ(frame.image->get_pixel(120, 232), Gfx::Color(0xf2, 0xef, 0xf0, 255));
  640. EXPECT_EQ(frame.image->get_pixel(198, 202), Gfx::Color(0x7b, 0xaa, 0xd5, 255));
  641. }
  642. TEST_CASE(test_webp_simple_lossless)
  643. {
  644. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8l.webp"sv)));
  645. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  646. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  647. // Ironically, simple-vp8l.webp is a much more complex file than extended-lossless.webp tested below.
  648. // extended-lossless.webp tests the decoding basics.
  649. // This here tests the predictor, color, and subtract green transforms,
  650. // as well as meta prefix images, one-element canonical code handling,
  651. // and handling of canonical codes with more than 288 elements.
  652. // This image uses all 13 predictor modes of the predictor transform.
  653. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 386, 395 }));
  654. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0));
  655. // This pixel tests all predictor modes except 5, 7, 8, 9, and 13.
  656. EXPECT_EQ(frame.image->get_pixel(289, 332), Gfx::Color(0xf2, 0xee, 0xd3, 255));
  657. }
  658. TEST_CASE(test_webp_simple_lossless_alpha_used_false)
  659. {
  660. // This file is identical to simple-vp8l.webp, but the `is_alpha_used` used bit is false.
  661. // The file still contains alpha data. This tests that the decoder replaces the stored alpha data with 0xff if `is_alpha_used` is false.
  662. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8l-alpha-used-false.webp"sv)));
  663. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  664. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  665. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 386, 395 }));
  666. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0xff));
  667. }
  668. TEST_CASE(test_webp_extended_lossy)
  669. {
  670. // This extended lossy image has an ALPH chunk for (losslessly compressed) alpha data.
  671. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/extended-lossy.webp"sv)));
  672. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  673. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  674. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 }));
  675. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  676. // So pixels changing by 1 or so below is fine if you change code.
  677. EXPECT_EQ(frame.image->get_pixel(89, 72), Gfx::Color(255, 1, 0, 255));
  678. EXPECT_EQ(frame.image->get_pixel(174, 69), Gfx::Color(0, 255, 0, 255));
  679. EXPECT_EQ(frame.image->get_pixel(245, 84), Gfx::Color(0, 0, 255, 255));
  680. EXPECT_EQ(frame.image->get_pixel(352, 125), Gfx::Color(0, 0, 0, 128));
  681. EXPECT_EQ(frame.image->get_pixel(355, 106), Gfx::Color(0, 0, 0, 0));
  682. // Check same basic pixels as in test_webp_extended_lossless too.
  683. // (The top-left pixel in the lossy version is fully transparent white, compared to fully transparent black in the lossless version).
  684. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(255, 255, 255, 0));
  685. EXPECT_EQ(frame.image->get_pixel(43, 75), Gfx::Color(255, 0, 2, 255));
  686. EXPECT_EQ(frame.image->get_pixel(141, 75), Gfx::Color(0, 255, 3, 255));
  687. EXPECT_EQ(frame.image->get_pixel(235, 75), Gfx::Color(0, 0, 255, 255));
  688. EXPECT_EQ(frame.image->get_pixel(341, 75), Gfx::Color(0, 0, 0, 128));
  689. }
  690. TEST_CASE(test_webp_extended_lossy_alpha_horizontal_filter)
  691. {
  692. // Also lossy rgb + lossless alpha, but with a horizontal alpha filtering method.
  693. // The image should look like smolkling.webp, but with a horizontal alpha gradient.
  694. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/smolkling-horizontal-alpha.webp"sv)));
  695. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  696. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  697. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  698. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  699. // So pixels changing by 1 or so below is fine if you change code.
  700. // 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.
  701. EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x8f, 0x51, 0x2f, 0x4b));
  702. }
  703. TEST_CASE(test_webp_extended_lossy_alpha_vertical_filter)
  704. {
  705. // Also lossy rgb + lossless alpha, but with a vertical alpha filtering method.
  706. // The image should look like smolkling.webp, but with a vertical alpha gradient, and with a fully transparent first column.
  707. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/smolkling-vertical-alpha.webp"sv)));
  708. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  709. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  710. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  711. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  712. // So pixels changing by 1 or so below is fine if you change code.
  713. // 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.
  714. EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x94, 0x50, 0x32, 0x4c));
  715. }
  716. TEST_CASE(test_webp_extended_lossy_alpha_gradient_filter)
  717. {
  718. // Also lossy rgb + lossless alpha, but with a gradient alpha filtering method.
  719. // 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.
  720. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/smolkling-gradient-alpha.webp"sv)));
  721. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  722. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  723. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  724. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  725. // So pixels changing by 1 or so below is fine if you change code.
  726. // 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.
  727. // In particular, the center of the image should be fully opaque, not fully transparent.
  728. EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x8c, 0x47, 0x2e, 255));
  729. }
  730. TEST_CASE(test_webp_extended_lossy_uncompressed_alpha)
  731. {
  732. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/extended-lossy-uncompressed-alpha.webp"sv)));
  733. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  734. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  735. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 }));
  736. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  737. // So pixels changing by 1 or so below is fine if you change code.
  738. EXPECT_EQ(frame.image->get_pixel(89, 72), Gfx::Color(255, 0, 4, 255));
  739. EXPECT_EQ(frame.image->get_pixel(174, 69), Gfx::Color(4, 255, 0, 255));
  740. EXPECT_EQ(frame.image->get_pixel(245, 84), Gfx::Color(0, 0, 255, 255));
  741. EXPECT_EQ(frame.image->get_pixel(352, 125), Gfx::Color(0, 0, 0, 128));
  742. EXPECT_EQ(frame.image->get_pixel(355, 106), Gfx::Color(0, 0, 0, 0));
  743. }
  744. TEST_CASE(test_webp_extended_lossy_negative_quantization_offset)
  745. {
  746. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/smolkling.webp"sv)));
  747. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  748. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  749. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 }));
  750. // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
  751. // So pixels changing by 1 or so below is fine if you change code.
  752. EXPECT_EQ(frame.image->get_pixel(16, 16), Gfx::Color(0x3c, 0x24, 0x1a, 255));
  753. }
  754. TEST_CASE(test_webp_lossy_4)
  755. {
  756. // This is https://commons.wikimedia.org/wiki/File:Fr%C3%BChling_bl%C3%BChender_Kirschenbaum.jpg,
  757. // under the Creative Commons Attribution-Share Alike 3.0 Unported license. The image was re-encoded
  758. // as webp at https://developers.google.com/speed/webp/gallery1 and the webp version is from there.
  759. // No other changes have been made.
  760. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/4.webp"sv)));
  761. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  762. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  763. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 772 }));
  764. // This image tests macroblocks that have `skip_coefficients` set to true, and it test a boolean entropy decoder edge case.
  765. EXPECT_EQ(frame.image->get_pixel(780, 570), Gfx::Color(0x72, 0xc8, 0xf6, 255));
  766. }
  767. TEST_CASE(test_webp_lossy_4_with_partitions)
  768. {
  769. // Same input file as in the previous test, but re-encoded to use 8 secondary partitions.
  770. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/4-with-8-partitions.webp"sv)));
  771. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  772. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  773. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 772 }));
  774. EXPECT_EQ(frame.image->get_pixel(780, 570), Gfx::Color(0x73, 0xc9, 0xf9, 255));
  775. }
  776. TEST_CASE(test_webp_extended_lossless)
  777. {
  778. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/extended-lossless.webp"sv)));
  779. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  780. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  781. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 }));
  782. // Check some basic pixels.
  783. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0));
  784. EXPECT_EQ(frame.image->get_pixel(43, 75), Gfx::Color(255, 0, 0, 255));
  785. EXPECT_EQ(frame.image->get_pixel(141, 75), Gfx::Color(0, 255, 0, 255));
  786. EXPECT_EQ(frame.image->get_pixel(235, 75), Gfx::Color(0, 0, 255, 255));
  787. EXPECT_EQ(frame.image->get_pixel(341, 75), Gfx::Color(0, 0, 0, 128));
  788. // Check pixels using the color cache.
  789. EXPECT_EQ(frame.image->get_pixel(94, 73), Gfx::Color(255, 0, 0, 255));
  790. EXPECT_EQ(frame.image->get_pixel(176, 115), Gfx::Color(0, 255, 0, 255));
  791. EXPECT_EQ(frame.image->get_pixel(290, 89), Gfx::Color(0, 0, 255, 255));
  792. EXPECT_EQ(frame.image->get_pixel(359, 73), Gfx::Color(0, 0, 0, 128));
  793. }
  794. TEST_CASE(test_webp_simple_lossless_color_index_transform)
  795. {
  796. // In addition to testing the index transform, this file also tests handling of explicity setting max_symbol.
  797. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/Qpalette.webp"sv)));
  798. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  799. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  800. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 256, 256 }));
  801. EXPECT_EQ(frame.image->get_pixel(100, 100), Gfx::Color(0x73, 0x37, 0x23, 0xff));
  802. }
  803. TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling)
  804. {
  805. struct TestCase {
  806. StringView file_name;
  807. Gfx::Color line_color;
  808. Gfx::Color background_color;
  809. };
  810. // The number after the dash is the number of colors in each file's color index bitmap.
  811. // catdog-alert-2 tests the 1-bit-per-pixel case,
  812. // catdog-alert-3 tests the 2-bit-per-pixel case,
  813. // catdog-alert-8 and catdog-alert-13 both test the 4-bits-per-pixel case.
  814. // catdog-alert-13-alpha-used-false is like catdog-alert-13, but with is_alpha_used set to false in the header
  815. // (which has the effect of ignoring the alpha information in the palette and instead always setting alpha to 0xff).
  816. TestCase test_cases[] = {
  817. { "webp/catdog-alert-2.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0xf3, 0xe6, 0xd8, 0xff) },
  818. { "webp/catdog-alert-3.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0, 0, 0, 0) },
  819. { "webp/catdog-alert-8.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
  820. { "webp/catdog-alert-13.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
  821. { "webp/catdog-alert-13-alpha-used-false.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 255) },
  822. };
  823. for (auto test_case : test_cases) {
  824. auto file = TRY_OR_FAIL(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), test_case.file_name))));
  825. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  826. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  827. auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 }));
  828. EXPECT_EQ(frame.image->get_pixel(4, 0), test_case.background_color);
  829. EXPECT_EQ(frame.image->get_pixel(5, 0), test_case.line_color);
  830. EXPECT_EQ(frame.image->get_pixel(9, 5), test_case.background_color);
  831. EXPECT_EQ(frame.image->get_pixel(10, 5), test_case.line_color);
  832. EXPECT_EQ(frame.image->get_pixel(11, 5), test_case.background_color);
  833. }
  834. }
  835. TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling_odd_width)
  836. {
  837. StringView file_names[] = {
  838. "webp/width11-height11-colors2.webp"sv,
  839. "webp/width11-height11-colors3.webp"sv,
  840. "webp/width11-height11-colors15.webp"sv,
  841. };
  842. for (auto file_name : file_names) {
  843. auto file = TRY_OR_FAIL(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), file_name))));
  844. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  845. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 11, 11 }));
  846. }
  847. }
  848. TEST_CASE(test_webp_extended_lossless_animated)
  849. {
  850. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/extended-lossless-animated.webp"sv)));
  851. EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
  852. auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
  853. EXPECT_EQ(plugin_decoder->frame_count(), 8u);
  854. EXPECT(plugin_decoder->is_animated());
  855. EXPECT_EQ(plugin_decoder->loop_count(), 42u);
  856. EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(990, 1050));
  857. for (size_t frame_index = 0; frame_index < plugin_decoder->frame_count(); ++frame_index) {
  858. auto frame = TRY_OR_FAIL(plugin_decoder->frame(frame_index));
  859. EXPECT_EQ(frame.image->size(), Gfx::IntSize(990, 1050));
  860. // This pixel happens to be the same color in all frames.
  861. EXPECT_EQ(frame.image->get_pixel(500, 700), Gfx::Color::Yellow);
  862. // This one isn't the same in all frames.
  863. EXPECT_EQ(frame.image->get_pixel(500, 0), (frame_index == 2 || frame_index == 6) ? Gfx::Color::Black : Gfx::Color(255, 255, 255, 0));
  864. }
  865. }
  866. TEST_CASE(test_tvg)
  867. {
  868. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tvg/yak.tvg"sv)));
  869. EXPECT(Gfx::TinyVGImageDecoderPlugin::sniff(file->bytes()));
  870. auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes()));
  871. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 1024 }));
  872. }
  873. TEST_CASE(test_everything_tvg)
  874. {
  875. Array file_names {
  876. TEST_INPUT("tvg/everything.tvg"sv),
  877. TEST_INPUT("tvg/everything-32.tvg"sv)
  878. };
  879. for (auto file_name : file_names) {
  880. auto file = TRY_OR_FAIL(Core::MappedFile::map(file_name));
  881. EXPECT(Gfx::TinyVGImageDecoderPlugin::sniff(file->bytes()));
  882. auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes()));
  883. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 768 }));
  884. }
  885. }
  886. TEST_CASE(test_tvg_malformed)
  887. {
  888. Array test_inputs = {
  889. TEST_INPUT("tvg/bogus-color-table-size.tvg"sv)
  890. };
  891. for (auto test_input : test_inputs) {
  892. auto file = TRY_OR_FAIL(Core::MappedFile::map(test_input));
  893. auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes()));
  894. auto frame_or_error = plugin_decoder->frame(0);
  895. EXPECT(frame_or_error.is_error());
  896. }
  897. }
  898. TEST_CASE(test_jxl_modular_simple_tree_upsample2_10bits)
  899. {
  900. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jxl/modular_simple_tree_upsample2_10bits_rct.jxl"sv)));
  901. EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes()));
  902. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes()));
  903. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 128, 128 }));
  904. auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
  905. EXPECT_EQ(frame.image->get_pixel(42, 57), Gfx::Color::from_string("#4c0072"sv));
  906. }
  907. TEST_CASE(test_jxl_modular_property_8)
  908. {
  909. auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jxl/modular_property_8.jxl"sv)));
  910. EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes()));
  911. auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes()));
  912. TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 }));
  913. auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
  914. for (u8 i = 0; i < 32; ++i) {
  915. for (u8 j = 0; j < 32; ++j) {
  916. auto const color = frame.image->get_pixel(i, j);
  917. if ((i + j) % 2 == 0)
  918. EXPECT_EQ(color, Gfx::Color::Black);
  919. else
  920. EXPECT_EQ(color, Gfx::Color::Yellow);
  921. }
  922. }
  923. }
  924. TEST_CASE(test_dds)
  925. {
  926. Array file_names = {
  927. TEST_INPUT("dds/catdog-alert-29x29.dds"sv),
  928. TEST_INPUT("dds/catdog-alert-32x32.dds"sv)
  929. };
  930. for (auto file_name : file_names) {
  931. auto file = TRY_OR_FAIL(Core::MappedFile::map(file_name));
  932. EXPECT(Gfx::DDSImageDecoderPlugin::sniff(file->bytes()));
  933. auto plugin_decoder = TRY_OR_FAIL(Gfx::DDSImageDecoderPlugin::create(file->bytes()));
  934. TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
  935. }
  936. }