aboutsummaryrefslogtreecommitdiff
path: root/test/src/TestBitmap.c
blob: cfeee7f61f1d85435fe35bd8e37deb7260e030ae (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
#include <BH/Bitmap.h>
#include <BH/Color.h>
#include <BH/IO.h>
#include <BH/Unit.h>


BH_UNIT_TEST(RoundTrip)
{
    size_t i, format;

    uint16_t data[][4] =
    {
        {0,     0,     0,     65535},
        {0,     0,     65535, 65535},
        {0,     65535, 0,     65535},
        {65535, 0,     0,     65535},
        {0,     65535, 65535, 65535},
        {65535, 0,     65535, 65535},
        {65535, 65535, 0,     65535},
        {65535, 65535, 65535, 65535},
        {0,     0,     0,     0},
        {0,     0,     65535, 0},
        {0,     65535, 0,     0},
        {65535, 0,     0,     0},
        {0,     65535, 65535, 0},
        {65535, 0,     65535, 0},
        {65535, 65535, 0,     0},
        {65535, 65535, 65535, 0},
    };

    uint16_t formats[] =
    {
        BH_BITMAP_RGBA32,
        BH_BITMAP_RGBA64,
        BH_BITMAP_RGB888,
        BH_BITMAP_RGBA8888,
        BH_BITMAP_RGB161616,
        BH_BITMAP_RGBA16161616,
        BH_BITMAP_RGB565,
        BH_BITMAP_RGBA1010102,
        BH_BITMAP_RGBA8888 | BH_BITMAP_NOALPHA,
        BH_BITMAP_RGBA16161616 | BH_BITMAP_NOALPHA,
        BH_BITMAP_RGBA1010102 | BH_BITMAP_NOALPHA,
    };

    for (format = 0; format < sizeof(formats) / sizeof(uint16_t); ++format)
    {
        for (i = 0; i < 16; ++i)
        {
            BH_Color source, destination;
            uint64_t temp;

            temp = 0;
            BH_ColorSetRGBA16(&source, data[i][0], data[i][1], data[i][2],
                                        data[i][3]);
            BH_BitmapConvertRow(&source.data, BH_BITMAP_RGBA16161616, NULL,
                                &temp, formats[format], NULL, 1);
            BH_BitmapConvertRow(&temp, formats[format], NULL, &destination.data,
                                BH_BITMAP_RGBA16161616, NULL, 1);

            BH_VERIFY(source.data.rgba.r == destination.data.rgba.r);
            BH_VERIFY(source.data.rgba.g == destination.data.rgba.g);
            BH_VERIFY(source.data.rgba.b == destination.data.rgba.b);

            if (formats[format] == BH_BITMAP_RGB888 ||
                formats[format] == BH_BITMAP_RGB161616 ||
                formats[format] == BH_BITMAP_RGB565 ||
                formats[format] & BH_BITMAP_NOALPHA)
                BH_VERIFY(destination.data.rgba.a == 65535);
            else
                BH_VERIFY(source.data.rgba.a == destination.data.rgba.a);
        }
    }

    return 0;
}


int main(int argc, char **argv)
{
    BH_UNUSED(argc);
    BH_UNUSED(argv);

    BH_UNIT_ADD(RoundTrip);

    return BH_UnitRun();
}