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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/String.h>
|
|
|
|
#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>
|
2021-04-29 01:38:16 +00:00
|
|
|
#include <LibTest/TestCase.h>
|
2021-02-01 09:03:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
TEST_CASE(test_bmp)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
|
|
|
auto image = Gfx::load_bmp("/res/html/misc/bmpsuite_files/rgba32-1.bmp");
|
|
|
|
auto bmp = Gfx::BMPImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(bmp.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!bmp.sniff());
|
|
|
|
EXPECT(!bmp.is_animated());
|
|
|
|
EXPECT(!bmp.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = bmp.frame(1);
|
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
|
|
|
{
|
|
|
|
auto image = Gfx::load_gif("/res/graphics/download-animation.gif");
|
|
|
|
auto gif = Gfx::GIFImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(gif.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!gif.sniff());
|
2021-02-01 09:03:04 +00:00
|
|
|
// FIXME: is_animated() should return true
|
|
|
|
// LibGfx::load_gif() returns a bitmap and lies about is_animated()
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!gif.is_animated());
|
|
|
|
EXPECT(!gif.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = gif.frame(1);
|
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_ico)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
|
|
|
// FIXME: Use an ico file
|
|
|
|
auto image = Gfx::load_ico("/res/graphics/buggie.png");
|
|
|
|
auto ico = Gfx::ICOImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(ico.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!ico.sniff());
|
|
|
|
EXPECT(!ico.is_animated());
|
|
|
|
EXPECT(!ico.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = ico.frame(1);
|
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_jpg)
|
2021-02-01 09:03:04 +00:00
|
|
|
{
|
|
|
|
auto image = Gfx::load_jpg("/res/html/misc/bmpsuite_files/rgb24.jpg");
|
|
|
|
auto jpg = Gfx::JPGImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(jpg.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!jpg.sniff());
|
|
|
|
EXPECT(!jpg.is_animated());
|
|
|
|
EXPECT(!jpg.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = jpg.frame(1);
|
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
|
|
|
{
|
|
|
|
auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
|
|
|
|
auto pbm = Gfx::PBMImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(pbm.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!pbm.sniff());
|
|
|
|
EXPECT(!pbm.is_animated());
|
|
|
|
EXPECT(!pbm.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = pbm.frame(1);
|
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
|
|
|
{
|
|
|
|
auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
|
|
|
|
auto pgm = Gfx::PGMImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(pgm.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!pgm.sniff());
|
|
|
|
EXPECT(!pgm.is_animated());
|
|
|
|
EXPECT(!pgm.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = pgm.frame(1);
|
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
|
|
|
{
|
|
|
|
auto image = Gfx::load_png("/res/graphics/buggie.png");
|
|
|
|
auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(png.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!png.sniff());
|
|
|
|
EXPECT(!png.is_animated());
|
|
|
|
EXPECT(!png.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = png.frame(1);
|
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
|
|
|
{
|
|
|
|
auto image = Gfx::load_ppm("/res/html/misc/ppmsuite_files/buggie-raw.ppm");
|
|
|
|
auto ppm = Gfx::PPMImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(ppm.frame_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(!ppm.sniff());
|
|
|
|
EXPECT(!ppm.is_animated());
|
|
|
|
EXPECT(!ppm.loop_count());
|
2021-02-01 09:03:04 +00:00
|
|
|
|
|
|
|
auto frame = ppm.frame(1);
|
2021-04-29 01:38:16 +00:00
|
|
|
EXPECT(frame.duration == 0);
|
2021-02-01 09:03:04 +00:00
|
|
|
}
|