summaryrefslogtreecommitdiff
path: root/Tests/LibGfx/TestImageDecoder.cpp
blob: dd5f74feb9b5618e201cfe8a90c80b38eaa5a87e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2021, the SerenityOS developers.
 * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#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>
#include <LibTest/TestCase.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

TEST_CASE(test_bmp)
{
    auto image = Gfx::load_bmp("/res/html/misc/bmpsuite_files/rgba32-1.bmp");
    auto bmp = Gfx::BMPImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(bmp.frame_count());

    EXPECT(!bmp.sniff());
    EXPECT(!bmp.is_animated());
    EXPECT(!bmp.loop_count());

    auto frame = bmp.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_gif)
{
    auto image = Gfx::load_gif("/res/graphics/download-animation.gif");
    auto gif = Gfx::GIFImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(gif.frame_count());

    EXPECT(!gif.sniff());
    // FIXME: is_animated() should return true
    // LibGfx::load_gif() returns a bitmap and lies about is_animated()
    EXPECT(!gif.is_animated());
    EXPECT(!gif.loop_count());

    auto frame = gif.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_ico)
{
    // FIXME: Use an ico file
    auto image = Gfx::load_ico("/res/graphics/buggie.png");
    auto ico = Gfx::ICOImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(ico.frame_count());

    EXPECT(!ico.sniff());
    EXPECT(!ico.is_animated());
    EXPECT(!ico.loop_count());

    auto frame = ico.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_jpg)
{
    auto image = Gfx::load_jpg("/res/html/misc/bmpsuite_files/rgb24.jpg");
    auto jpg = Gfx::JPGImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(jpg.frame_count());

    EXPECT(!jpg.sniff());
    EXPECT(!jpg.is_animated());
    EXPECT(!jpg.loop_count());

    auto frame = jpg.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_pbm)
{
    auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
    auto pbm = Gfx::PBMImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(pbm.frame_count());

    EXPECT(!pbm.sniff());
    EXPECT(!pbm.is_animated());
    EXPECT(!pbm.loop_count());

    auto frame = pbm.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_pgm)
{
    auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
    auto pgm = Gfx::PGMImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(pgm.frame_count());

    EXPECT(!pgm.sniff());
    EXPECT(!pgm.is_animated());
    EXPECT(!pgm.loop_count());

    auto frame = pgm.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_png)
{
    auto image = Gfx::load_png("/res/graphics/buggie.png");
    auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(png.frame_count());

    EXPECT(!png.sniff());
    EXPECT(!png.is_animated());
    EXPECT(!png.loop_count());

    auto frame = png.frame(1);
    EXPECT(frame.duration == 0);
}

TEST_CASE(test_ppm)
{
    auto image = Gfx::load_ppm("/res/html/misc/ppmsuite_files/buggie-raw.ppm");
    auto ppm = Gfx::PPMImageDecoderPlugin((const u8*)&image, sizeof(*image));
    EXPECT(ppm.frame_count());

    EXPECT(!ppm.sniff());
    EXPECT(!ppm.is_animated());
    EXPECT(!ppm.loop_count());

    auto frame = ppm.frame(1);
    EXPECT(frame.duration == 0);
}