summaryrefslogtreecommitdiffhomepage
path: root/test/bitmask.cpp
blob: a1bbd0de18b225026aff7cb570028262af5e77ac (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
#include "app.hpp"
#include "compat/assert.hpp"
#include "src/anim-atlas.hpp"
#include "loader/loader.hpp"
#include <Corrade/Containers/ArrayView.h>
#include <mg/Functions.h>
#include <mg/ImageData.h>

namespace floormat {

namespace {

const unsigned char src[] = {
#include "bitmask.embed.inc"
};

constexpr auto data_nbytes = arraySize(src);
constexpr auto size = Vector2i{21, 52};
//static_assert(size_t{size.product()+7}/8 <= data_nbytes);

void bitmask_test()
{
    auto img = loader.texture("images/", "bitmask-test1"_s);
    auto bitmask = anim_atlas::make_bitmask(img);
    fm_assert(bitmask.size() >= size_t{size.product()});
    fm_assert(img.pixelSize() == 4);
//#define DO_GENERATE
#ifdef DO_GENERATE
    fputc('\n', stdout);
    for (auto i = 0u; i < (bitmask.size()+7)/8; i++)
    {
        printf("0x%02hhx,", bitmask.data()[i]);
        if (i % 15 == 14)
            printf("\n");
    }
    printf("\n");
    fflush(stdout);
#endif
    const auto len = Math::min(data_nbytes, (size_t)bitmask.size()+7 >> 3);
    fm_assert(arraySize(src) >= len);
    for (auto i = 0uz; i < len; i++)
    {
        auto a = (unsigned char)bitmask.data()[i];
        if (a != src[i])
            fm_abort("wrong value 0x%02hhx at byte %zu, should be' 0x%02hhx'", a, i, src[i]);
    }
}

} // namespace

void test_app::test_bitmask()
{
    bitmask_test();
    //bitmask_benchmark();
}

} // namespace floormat