2021-02-01 09:03:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2021-04-29 01:38:16 +00:00
|
|
|
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
2021-02-01 09:03:04 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-01 09:03:04 +00:00
|
|
|
*/
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2021-11-23 10:32:25 +00:00
|
|
|
#include <LibCore/MappedFile.h>
|
2023-03-21 18:58:06 +00:00
|
|
|
#include <LibGfx/ImageFormats/BMPLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/GIFLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/ICOLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/ImageDecoder.h>
|
|
|
|
#include <LibGfx/ImageFormats/JPEGLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/PBMLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/PGMLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/PNGLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/PPMLoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/TGALoader.h>
|
|
|
|
#include <LibGfx/ImageFormats/WebPLoader.h>
|
2021-04-29 01:38:16 +00:00
|
|
|
#include <LibTest/TestCase.h>
|
2021-02-01 09:03:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2023-01-31 19:00:33 +00:00
|
|
|
#ifdef AK_OS_SERENITY
|
|
|
|
# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x)
|
|
|
|
#else
|
|
|
|
# define TEST_INPUT(x) ("test-inputs/" x)
|
|
|
|
#endif
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_bmp)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("rgba32-1.bmp"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_gif)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("download-animation.gif"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::GIFImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::GIFImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame_count());
|
2023-01-20 16:41:21 +00:00
|
|
|
EXPECT(plugin_decoder->is_animated());
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(1));
|
2021-11-11 10:20:58 +00:00
|
|
|
EXPECT(frame.duration == 400);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 18:13:19 +00:00
|
|
|
TEST_CASE(test_not_ico)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie.png"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(!Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(!plugin_decoder->initialize());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame(0).is_error());
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 18:13:19 +00:00
|
|
|
TEST_CASE(test_bmp_embedded_in_ico)
|
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("serenity.ico"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2022-12-18 18:13:19 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2022-12-18 18:13:19 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(!plugin_decoder->frame(0).is_error());
|
2022-12-18 18:13:19 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 22:02:07 +00:00
|
|
|
TEST_CASE(test_jpeg_sof0_one_scan)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("rgb24.jpg"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
|
2023-02-18 21:09:16 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
EXPECT(plugin_decoder->initialize());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 22:07:14 +00:00
|
|
|
TEST_CASE(test_jpeg_sof0_several_scans)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("several_scans.jpg"sv)));
|
|
|
|
EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
|
|
|
|
auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2023-03-04 02:44:22 +00:00
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(592, 800));
|
2023-02-26 22:07:14 +00:00
|
|
|
}
|
|
|
|
|
2023-03-05 03:05:02 +00:00
|
|
|
TEST_CASE(test_jpeg_rgb_components)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("rgb_components.jpg"sv)));
|
|
|
|
EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
|
|
|
|
auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(592, 800));
|
|
|
|
}
|
|
|
|
|
2023-02-27 19:32:41 +00:00
|
|
|
TEST_CASE(test_jpeg_sof2_spectral_selection)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("spectral_selection.jpg"sv)));
|
|
|
|
EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
|
|
|
|
auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(592, 800));
|
|
|
|
}
|
|
|
|
|
2023-03-04 04:45:47 +00:00
|
|
|
TEST_CASE(test_jpeg_sof0_several_scans_odd_number_mcu)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("several_scans_odd_number_mcu.jpg"sv)));
|
|
|
|
EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
|
|
|
|
auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(600, 600));
|
|
|
|
}
|
|
|
|
|
2023-03-18 03:39:30 +00:00
|
|
|
TEST_CASE(test_jpeg_sof2_successive_aproximation)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("successive_approximation.jpg"sv)));
|
|
|
|
EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()));
|
|
|
|
auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(600, 800));
|
|
|
|
}
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_pbm)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-raw.pbm"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::PBMImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::PBMImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2023-01-20 08:13:14 +00:00
|
|
|
|
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_pgm)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-raw.pgm"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::PGMImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::PGMImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2023-01-20 08:13:14 +00:00
|
|
|
|
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_png)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie.png"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::PNGImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::PNGImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_ppm)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-raw.ppm"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::PPMImageDecoderPlugin::sniff(file->bytes()));
|
2023-01-29 22:21:24 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::PPMImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2023-01-20 08:13:14 +00:00
|
|
|
|
|
|
|
EXPECT(plugin_decoder->frame_count());
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|
2022-12-31 11:34:05 +00:00
|
|
|
|
|
|
|
TEST_CASE(test_targa_bottom_left)
|
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-bottom-left-uncompressed.tga"sv)));
|
2023-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
|
|
|
|
auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2022-12-31 11:34:05 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2022-12-31 11:34:05 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2022-12-31 11:34:05 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_targa_top_left)
|
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-top-left-uncompressed.tga"sv)));
|
2023-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
|
|
|
|
auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2023-01-20 08:13:14 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2022-12-31 11:34:05 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2022-12-31 11:34:05 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
2023-01-07 15:02:00 +00:00
|
|
|
|
|
|
|
TEST_CASE(test_targa_bottom_left_compressed)
|
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-bottom-left-compressed.tga"sv)));
|
2023-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
|
|
|
|
auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2023-01-07 15:02:00 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2023-01-07 15:02:00 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2023-01-07 15:02:00 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_targa_top_left_compressed)
|
|
|
|
{
|
2023-01-31 19:00:33 +00:00
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-top-left-compressed.tga"sv)));
|
2023-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())));
|
|
|
|
auto plugin_decoder = MUST(Gfx::TGAImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
2023-01-20 08:13:14 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
2023-01-07 15:02:00 +00:00
|
|
|
|
2023-02-25 23:58:19 +00:00
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
2023-01-07 15:02:00 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
2023-02-26 00:27:09 +00:00
|
|
|
|
|
|
|
TEST_CASE(test_webp_simple_lossy)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("simple-vp8.webp"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
|
2023-02-26 00:27:09 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(240, 240));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_simple_lossless)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("simple-vp8l.webp"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
|
2023-02-26 00:27:09 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(386, 395));
|
2023-04-06 17:33:43 +00:00
|
|
|
|
|
|
|
// Ironically, simple-vp8l.webp is a much more complex file than extended-lossless.webp tested below.
|
|
|
|
// extended-lossless.webp tests the decoding basics.
|
|
|
|
// This here tests the predictor, color, and subtract green transforms,
|
|
|
|
// 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 = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(386, 395));
|
|
|
|
|
|
|
|
// This pixel tests all predictor modes except 5, 7, 8, 9, and 13.
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(289, 332), Gfx::Color(0xf2, 0xee, 0xd3, 255));
|
2023-02-26 00:27:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_extended_lossy)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossy.webp"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
|
2023-02-26 00:27:09 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(417, 223));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_extended_lossless)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless.webp"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
|
2023-02-26 00:27:09 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(417, 223));
|
2023-04-03 18:54:05 +00:00
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(417, 223));
|
|
|
|
|
|
|
|
// Check some basic pixels.
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(43, 75), Gfx::Color(255, 0, 0, 255));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(141, 75), Gfx::Color(0, 255, 0, 255));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(235, 75), Gfx::Color(0, 0, 255, 255));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(341, 75), Gfx::Color(0, 0, 0, 128));
|
|
|
|
|
|
|
|
// Check pixels using the color cache.
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(94, 73), Gfx::Color(255, 0, 0, 255));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(176, 115), Gfx::Color(0, 255, 0, 255));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(290, 89), Gfx::Color(0, 0, 255, 255));
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(359, 73), Gfx::Color(0, 0, 0, 128));
|
2023-02-26 00:27:09 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 19:21:57 +00:00
|
|
|
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("Qpalette.webp"sv)));
|
|
|
|
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
|
|
|
|
auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT(!plugin_decoder->is_animated());
|
|
|
|
EXPECT(!plugin_decoder->loop_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(256, 256));
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(256, 256));
|
|
|
|
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(100, 100), Gfx::Color(0x73, 0x37, 0x23, 0xff));
|
|
|
|
}
|
|
|
|
|
2023-04-07 22:40:28 +00:00
|
|
|
TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling)
|
|
|
|
{
|
|
|
|
struct TestCase {
|
|
|
|
StringView file_name;
|
|
|
|
Gfx::Color line_color;
|
|
|
|
Gfx::Color background_color;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The number after the dash is the number of colors in each file's color index bitmap.
|
|
|
|
// catdog-alert-2 tests the 1-bit-per-pixel case,
|
|
|
|
// catdog-alert-3 tests the 2-bit-per-pixel case,
|
|
|
|
// catdog-alert-8 and catdog-alert-13 both test the 4-bits-per-pixel case.
|
|
|
|
TestCase test_cases[] = {
|
|
|
|
{ "catdog-alert-2.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0xf3, 0xe6, 0xd8, 0xff) },
|
|
|
|
{ "catdog-alert-3.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0, 0, 0, 0) },
|
|
|
|
{ "catdog-alert-8.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
|
|
|
|
{ "catdog-alert-13.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
|
|
|
|
};
|
|
|
|
|
|
|
|
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()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(32, 32));
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(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);
|
|
|
|
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(9, 5), test_case.background_color);
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(10, 5), test_case.line_color);
|
|
|
|
EXPECT_EQ(frame.image->get_pixel(11, 5), test_case.background_color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-08 21:50:54 +00:00
|
|
|
TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling_odd_width)
|
|
|
|
{
|
|
|
|
StringView file_names[] = {
|
|
|
|
"width11-height11-colors2.webp"sv,
|
|
|
|
"width11-height11-colors3.webp"sv,
|
|
|
|
"width11-height11-colors15.webp"sv,
|
|
|
|
};
|
|
|
|
|
|
|
|
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(plugin_decoder->initialize());
|
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(11, 11));
|
|
|
|
|
|
|
|
auto frame = MUST(plugin_decoder->frame(0));
|
|
|
|
EXPECT_EQ(frame.image->size(), Gfx::IntSize(11, 11));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-26 00:27:09 +00:00
|
|
|
TEST_CASE(test_webp_extended_lossless_animated)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless-animated.webp"sv)));
|
2023-02-26 18:02:50 +00:00
|
|
|
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
|
2023-02-26 00:27:09 +00:00
|
|
|
auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
|
|
|
|
EXPECT(plugin_decoder->initialize());
|
|
|
|
|
2023-02-26 03:15:34 +00:00
|
|
|
EXPECT_EQ(plugin_decoder->frame_count(), 8u);
|
|
|
|
EXPECT(plugin_decoder->is_animated());
|
2023-02-26 14:13:27 +00:00
|
|
|
EXPECT_EQ(plugin_decoder->loop_count(), 42u);
|
2023-02-26 00:27:09 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(990, 1050));
|
|
|
|
}
|