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>
|
2021-02-01 09:03:04 +00:00
|
|
|
#include <LibGfx/BMPLoader.h>
|
|
|
|
#include <LibGfx/GIFLoader.h>
|
|
|
|
#include <LibGfx/ICOLoader.h>
|
|
|
|
#include <LibGfx/ImageDecoder.h>
|
2023-02-18 21:09:16 +00:00
|
|
|
#include <LibGfx/JPEGLoader.h>
|
2021-02-01 09:03:04 +00:00
|
|
|
#include <LibGfx/PBMLoader.h>
|
|
|
|
#include <LibGfx/PGMLoader.h>
|
|
|
|
#include <LibGfx/PNGLoader.h>
|
|
|
|
#include <LibGfx/PPMLoader.h>
|
2022-12-31 11:34:05 +00:00
|
|
|
#include <LibGfx/TGALoader.h>
|
2023-02-26 00:27:09 +00:00
|
|
|
#include <LibGfx/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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::BMPImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::GIFImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(!MUST(Gfx::ICOImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::ICOImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_jpg)
|
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-18 21:09:16 +00:00
|
|
|
EXPECT(MUST(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::PBMImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::PGMImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::PNGImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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-01-29 22:21:24 +00:00
|
|
|
EXPECT(MUST(Gfx::PPMImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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)));
|
|
|
|
EXPECT(MUST(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(240, 240));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_simple_lossless)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("simple-vp8l.webp"sv)));
|
|
|
|
EXPECT(MUST(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(386, 395));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_extended_lossy)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossy.webp"sv)));
|
|
|
|
EXPECT(MUST(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(417, 223));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_extended_lossless)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless.webp"sv)));
|
|
|
|
EXPECT(MUST(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(417, 223));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_webp_extended_lossless_animated)
|
|
|
|
{
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless-animated.webp"sv)));
|
|
|
|
EXPECT(MUST(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())));
|
|
|
|
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));
|
|
|
|
}
|