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>
|
|
|
|
#include <LibGfx/JPGLoader.h>
|
|
|
|
#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>
|
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>
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_bmp)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/bmpsuite_files/rgba32-1.bmp"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::BMPImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::BMPImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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
|
|
|
auto frame = plugin_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/graphics/download-animation.gif"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::GIFImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::GIFImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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
|
|
|
auto frame = plugin_decoder->frame(1).release_value_but_fixme_should_propagate_errors();
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/graphics/buggie.png"sv).release_value();
|
2023-01-20 16:40:28 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::ICOImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), false);
|
2023-01-20 08:13:14 +00:00
|
|
|
auto plugin_decoder_or_error = Gfx::ICOImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
2023-01-20 16:40:28 +00:00
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), false);
|
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)
|
|
|
|
{
|
|
|
|
auto file = Core::MappedFile::map("/res/icons/16x16/serenity.ico"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::ICOImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::ICOImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/bmpsuite_files/rgb24.jpg"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::JPGImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::JPGImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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());
|
|
|
|
|
|
|
|
auto frame = plugin_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/pbmsuite_files/buggie-raw.pbm"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::PBMImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::PBMImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
auto frame = plugin_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/pgmsuite_files/buggie-raw.pgm"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::PGMImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::PGMImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
auto frame = plugin_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/graphics/buggie.png"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::PNGImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::PNGImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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());
|
|
|
|
|
|
|
|
auto frame = plugin_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
|
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
|
|
|
{
|
2022-07-11 17:32:29 +00:00
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/ppmsuite_files/buggie-raw.ppm"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::PPMImageDecoderPlugin::sniff({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::PPMImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
auto frame = plugin_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
|
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)
|
|
|
|
{
|
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/targasuite_files/buggie-bottom-left-uncompressed.tga"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::TGAImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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-01-20 08:13:14 +00:00
|
|
|
EXPECT(!plugin_decoder->frame(0).is_error());
|
|
|
|
|
|
|
|
auto frame_or_error = plugin_decoder->frame(0);
|
2022-12-31 11:34:05 +00:00
|
|
|
EXPECT(!frame_or_error.is_error());
|
|
|
|
auto frame = frame_or_error.release_value();
|
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_targa_top_left)
|
|
|
|
{
|
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/targasuite_files/buggie-top-left-uncompressed.tga"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::TGAImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
|
|
|
|
|
|
|
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-01-20 08:13:14 +00:00
|
|
|
EXPECT(!plugin_decoder->frame(0).is_error());
|
2022-12-31 11:34:05 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
auto frame_or_error = plugin_decoder->frame(0);
|
2022-12-31 11:34:05 +00:00
|
|
|
EXPECT(!frame_or_error.is_error());
|
|
|
|
auto frame = frame_or_error.release_value();
|
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
2023-01-07 15:02:00 +00:00
|
|
|
|
|
|
|
TEST_CASE(test_targa_bottom_left_compressed)
|
|
|
|
{
|
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/targasuite_files/buggie-bottom-left-compressed.tga"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::TGAImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
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-01-20 08:13:14 +00:00
|
|
|
EXPECT(!plugin_decoder->frame(0).is_error());
|
|
|
|
|
|
|
|
auto frame_or_error = plugin_decoder->frame(0);
|
2023-01-07 15:02:00 +00:00
|
|
|
EXPECT(!frame_or_error.is_error());
|
|
|
|
auto frame = frame_or_error.release_value();
|
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(test_targa_top_left_compressed)
|
|
|
|
{
|
|
|
|
auto file = Core::MappedFile::map("/res/html/misc/targasuite_files/buggie-top-left-compressed.tga"sv).release_value();
|
2023-01-20 08:13:14 +00:00
|
|
|
EXPECT_EQ(MUST(Gfx::TGAImageDecoderPlugin::validate_before_create({ (u8 const*)file->data(), file->size() })), true);
|
|
|
|
auto plugin_decoder_or_error = Gfx::TGAImageDecoderPlugin::create({ (u8 const*)file->data(), file->size() });
|
|
|
|
EXPECT(!plugin_decoder_or_error.is_error());
|
|
|
|
auto plugin_decoder = plugin_decoder_or_error.release_value();
|
|
|
|
EXPECT_EQ(plugin_decoder->initialize(), true);
|
|
|
|
|
|
|
|
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-01-20 08:13:14 +00:00
|
|
|
EXPECT(!plugin_decoder->frame(0).is_error());
|
2023-01-07 15:02:00 +00:00
|
|
|
|
2023-01-20 08:13:14 +00:00
|
|
|
auto frame_or_error = plugin_decoder->frame(0);
|
2023-01-07 15:02:00 +00:00
|
|
|
EXPECT(!frame_or_error.is_error());
|
|
|
|
auto frame = frame_or_error.release_value();
|
|
|
|
EXPECT(frame.duration == 0);
|
|
|
|
}
|