diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 7135720d63..50f723bf67 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -33,21 +33,21 @@ # define TEST_INPUT(x) ("test-inputs/" x) #endif -static Gfx::ImageFrameDescriptor expect_single_frame(Gfx::ImageDecoderPlugin& plugin_decoder) +static ErrorOr expect_single_frame(Gfx::ImageDecoderPlugin& plugin_decoder) { EXPECT_EQ(plugin_decoder.frame_count(), 1u); EXPECT(!plugin_decoder.is_animated()); EXPECT(!plugin_decoder.loop_count()); - auto frame = MUST(plugin_decoder.frame(0)); + auto frame = TRY(plugin_decoder.frame(0)); EXPECT_EQ(frame.duration, 0); return frame; } -static Gfx::ImageFrameDescriptor expect_single_frame_of_size(Gfx::ImageDecoderPlugin& plugin_decoder, Gfx::IntSize size) +static ErrorOr expect_single_frame_of_size(Gfx::ImageDecoderPlugin& plugin_decoder, Gfx::IntSize size) { EXPECT_EQ(plugin_decoder.size(), size); - auto frame = expect_single_frame(plugin_decoder); + auto frame = TRY(expect_single_frame(plugin_decoder)); EXPECT_EQ(frame.image->size(), size); return frame; } @@ -56,18 +56,18 @@ TEST_CASE(test_bmp) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("bmp/rgba32-1.bmp"sv))); EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::BMPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_bmp_top_down) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("bmp/top-down.bmp"sv))); EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::BMPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_ico_malformed_frame) @@ -90,7 +90,7 @@ TEST_CASE(test_gif) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("download-animation.gif"sv))); EXPECT(Gfx::GIFImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::GIFImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::GIFImageDecoderPlugin::create(file->bytes())); EXPECT(plugin_decoder->frame_count()); EXPECT(plugin_decoder->is_animated()); @@ -111,18 +111,18 @@ TEST_CASE(test_bmp_embedded_in_ico) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("serenity.ico"sv))); EXPECT(Gfx::ICOImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::ICOImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::ICOImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_ilbm) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/gradient.iff"sv))); EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 320, 200 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 })); EXPECT_EQ(frame.image->get_pixel(8, 0), Gfx::Color(0xee, 0xbb, 0, 255)); } @@ -131,9 +131,9 @@ TEST_CASE(test_ilbm_uncompressed) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/gradient-uncompressed.iff"sv))); EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 320, 200 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 200 })); EXPECT_EQ(frame.image->get_pixel(8, 0), Gfx::Color(0xee, 0xbb, 0, 255)); } @@ -142,9 +142,9 @@ TEST_CASE(test_ilbm_ham6) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/ham6.iff"sv))); EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 256, 256 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 256, 256 })); EXPECT_EQ(frame.image->get_pixel(77, 107), Gfx::Color(0xf0, 0x40, 0x40, 0xff)); } @@ -182,90 +182,90 @@ TEST_CASE(test_jpeg_sof0_one_scan) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/rgb24.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_jpeg_sof0_several_scans) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/several_scans.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 592, 800 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 })); } TEST_CASE(test_jpeg_rgb_components) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/rgb_components.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 592, 800 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 })); } TEST_CASE(test_jpeg_sof2_spectral_selection) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/spectral_selection.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 592, 800 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 592, 800 })); } TEST_CASE(test_jpeg_sof0_several_scans_odd_number_mcu) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/several_scans_odd_number_mcu.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 600, 600 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 600, 600 })); } TEST_CASE(test_jpeg_sof2_successive_aproximation) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/successive_approximation.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 600, 800 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 600, 800 })); } TEST_CASE(test_jpeg_sof1_12bits) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/12-bit.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 320, 240 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 })); } TEST_CASE(test_jpeg_sof2_12bits) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/12-bit-progressive.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 320, 240 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 })); } TEST_CASE(test_jpeg_empty_icc) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/gradient_empty_icc.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 80, 80 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 })); } TEST_CASE(test_jpeg_grayscale_with_app14) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jpg/grayscale_app14.jpg"sv))); EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 80, 80 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 })); } TEST_CASE(test_jpeg_malformed_header) @@ -300,27 +300,27 @@ TEST_CASE(test_pbm) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.pbm"sv))); EXPECT(Gfx::PBMImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::PBMImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::PBMImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_pgm) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.pgm"sv))); EXPECT(Gfx::PGMImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::PGMImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::PGMImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_png) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv))); EXPECT(Gfx::PNGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::PNGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::PNGImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_png_malformed_frame) @@ -342,54 +342,54 @@ TEST_CASE(test_ppm) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("pnm/buggie-raw.ppm"sv))); EXPECT(Gfx::PPMImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::PPMImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::PPMImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_targa_bottom_left) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-uncompressed.tga"sv))); - EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); - auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes())); + EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_targa_top_left) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-uncompressed.tga"sv))); - EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); - auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes())); + EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_targa_bottom_left_compressed) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-compressed.tga"sv))); - EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); - auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes())); + EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_targa_top_left_compressed) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-compressed.tga"sv))); - EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); - auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes())); + EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } TEST_CASE(test_tiff_uncompressed) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/uncompressed.tiff"sv))); EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 400, 300 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 })); EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White); EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red); @@ -399,9 +399,9 @@ TEST_CASE(test_tiff_lzw) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/lzw.tiff"sv))); EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 400, 300 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 })); EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White); EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red); @@ -411,9 +411,9 @@ TEST_CASE(test_tiff_packed_bits) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/packed_bits.tiff"sv))); EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 400, 300 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 })); EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White); EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red); @@ -423,9 +423,9 @@ TEST_CASE(test_tiff_grayscale) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/grayscale.tiff"sv))); EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 400, 300 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 })); EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White); EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color(130, 130, 130)); @@ -435,9 +435,9 @@ TEST_CASE(test_webp_simple_lossy) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 240, 240 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 240, 240 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -449,7 +449,7 @@ TEST_CASE(test_webp_simple_lossless) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8l.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); // Ironically, simple-vp8l.webp is a much more complex file than extended-lossless.webp tested below. // extended-lossless.webp tests the decoding basics. @@ -457,7 +457,7 @@ TEST_CASE(test_webp_simple_lossless) // as well as meta prefix images, one-element canonical code handling, // and handling of canonical codes with more than 288 elements. // This image uses all 13 predictor modes of the predictor transform. - auto frame = expect_single_frame_of_size(*plugin_decoder, { 386, 395 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 386, 395 })); EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0)); // This pixel tests all predictor modes except 5, 7, 8, 9, and 13. @@ -470,9 +470,9 @@ TEST_CASE(test_webp_simple_lossless_alpha_used_false) // The file still contains alpha data. This tests that the decoder replaces the stored alpha data with 0xff if `is_alpha_used` is false. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/simple-vp8l-alpha-used-false.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 386, 395 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 386, 395 })); EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0xff)); } @@ -481,9 +481,9 @@ TEST_CASE(test_webp_extended_lossy) // This extended lossy image has an ALPH chunk for (losslessly compressed) alpha data. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossy.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 417, 223 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -508,9 +508,9 @@ TEST_CASE(test_webp_extended_lossy_alpha_horizontal_filter) // The image should look like smolkling.webp, but with a horizontal alpha gradient. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling-horizontal-alpha.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 264, 264 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -524,9 +524,9 @@ TEST_CASE(test_webp_extended_lossy_alpha_vertical_filter) // The image should look like smolkling.webp, but with a vertical alpha gradient, and with a fully transparent first column. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling-vertical-alpha.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 264, 264 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -540,9 +540,9 @@ TEST_CASE(test_webp_extended_lossy_alpha_gradient_filter) // 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. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling-gradient-alpha.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 264, 264 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -555,9 +555,9 @@ TEST_CASE(test_webp_extended_lossy_uncompressed_alpha) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossy-uncompressed-alpha.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 417, 223 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -572,9 +572,9 @@ TEST_CASE(test_webp_extended_lossy_negative_quantization_offset) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/smolkling.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 264, 264 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 264, 264 })); // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. // So pixels changing by 1 or so below is fine if you change code. @@ -589,9 +589,9 @@ TEST_CASE(test_webp_lossy_4) // No other changes have been made. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/4.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 1024, 772 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 772 })); // This image tests macroblocks that have `skip_coefficients` set to true, and it test a boolean entropy decoder edge case. EXPECT_EQ(frame.image->get_pixel(780, 570), Gfx::Color(0x72, 0xc8, 0xf6, 255)); @@ -602,9 +602,9 @@ TEST_CASE(test_webp_lossy_4_with_partitions) // Same input file as in the previous test, but re-encoded to use 8 secondary partitions. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/4-with-8-partitions.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 1024, 772 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 772 })); EXPECT_EQ(frame.image->get_pixel(780, 570), Gfx::Color(0x73, 0xc9, 0xf9, 255)); } @@ -612,9 +612,9 @@ TEST_CASE(test_webp_extended_lossless) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossless.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 417, 223 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 417, 223 })); // Check some basic pixels. EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0)); @@ -635,9 +635,9 @@ TEST_CASE(test_webp_simple_lossless_color_index_transform) // In addition to testing the index transform, this file also tests handling of explicity setting max_symbol. auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/Qpalette.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 256, 256 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 256, 256 })); EXPECT_EQ(frame.image->get_pixel(100, 100), Gfx::Color(0x73, 0x37, 0x23, 0xff)); } @@ -667,9 +667,9 @@ TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling) for (auto test_case : test_cases) { auto file = MUST(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), test_case.file_name)))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - auto frame = expect_single_frame_of_size(*plugin_decoder, { 32, 32 }); + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 })); EXPECT_EQ(frame.image->get_pixel(4, 0), test_case.background_color); EXPECT_EQ(frame.image->get_pixel(5, 0), test_case.line_color); @@ -690,8 +690,8 @@ TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling_odd_wid for (auto file_name : file_names) { auto file = MUST(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), file_name)))); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 11, 11 }); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 11, 11 })); } } @@ -699,7 +699,7 @@ TEST_CASE(test_webp_extended_lossless_animated) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("webp/extended-lossless-animated.webp"sv))); EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); EXPECT_EQ(plugin_decoder->frame_count(), 8u); EXPECT(plugin_decoder->is_animated()); @@ -723,9 +723,9 @@ TEST_CASE(test_tvg) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tvg/yak.tvg"sv))); EXPECT(Gfx::TinyVGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::TinyVGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 1024, 1024 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1024, 1024 })); } TEST_CASE(test_everything_tvg) @@ -738,9 +738,9 @@ TEST_CASE(test_everything_tvg) for (auto file_name : file_names) { auto file = MUST(Core::MappedFile::map(file_name)); EXPECT(Gfx::TinyVGImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::TinyVGImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TinyVGImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 400, 768 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 768 })); } } @@ -762,9 +762,9 @@ TEST_CASE(test_jxl_modular_simple_tree_upsample2_10bits) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jxl/modular_simple_tree_upsample2_10bits_rct.jxl"sv))); EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 128, 128 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 128, 128 })); auto frame = MUST(plugin_decoder->frame(0)); EXPECT_EQ(frame.image->get_pixel(42, 57), Gfx::Color::from_string("#4c0072"sv)); @@ -774,9 +774,9 @@ TEST_CASE(test_jxl_modular_property_8) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("jxl/modular_property_8.jxl"sv))); EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes())); - expect_single_frame_of_size(*plugin_decoder, { 32, 32 }); + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 })); auto frame = MUST(plugin_decoder->frame(0)); for (u8 i = 0; i < 32; ++i) { @@ -800,7 +800,7 @@ TEST_CASE(test_dds) for (auto file_name : file_names) { auto file = MUST(Core::MappedFile::map(file_name)); EXPECT(Gfx::DDSImageDecoderPlugin::sniff(file->bytes())); - auto plugin_decoder = MUST(Gfx::DDSImageDecoderPlugin::create(file->bytes())); - expect_single_frame(*plugin_decoder); + auto plugin_decoder = TRY_OR_FAIL(Gfx::DDSImageDecoderPlugin::create(file->bytes())); + TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); } }