From eb31b6d25af2b707f04fe71fb70341c889645101 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 27 Feb 2023 11:47:52 +0100 Subject: test: add sprite bitmap test --- src/anim-atlas.hpp | 3 ++- test/app.hpp | 1 + test/bitmask.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/main.cpp | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/bitmask.cpp diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp index d8105813..eaddef21 100644 --- a/src/anim-atlas.hpp +++ b/src/anim-atlas.hpp @@ -48,6 +48,8 @@ struct anim_atlas final fm_DECLARE_DELETED_COPY_ASSIGNMENT(anim_atlas); + static BitArray make_bitmask(const ImageView2D& tex); + private: GL::Texture2D _tex; String _name; @@ -59,7 +61,6 @@ private: static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept; static std::uint8_t rotation_to_index(StringView name) noexcept; - static BitArray make_bitmask(const ImageView2D& tex); }; } // namespace floormat diff --git a/test/app.hpp b/test/app.hpp index b3787826..894401c8 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -29,5 +29,6 @@ struct test_app final : private FM_APPLICATION static void test_serializer(); static void test_entity(); static void test_loader(); + static void test_bitmask(); }; } // namespace floormat diff --git a/test/bitmask.cpp b/test/bitmask.cpp new file mode 100644 index 00000000..f7d12dc2 --- /dev/null +++ b/test/bitmask.cpp @@ -0,0 +1,56 @@ +#include "app.hpp" +#include "compat/assert.hpp" +#include "src/anim-atlas.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace floormat { + +namespace { + +constexpr Vector4ub + red(0xff, 0x00, 0x00, 0x20), green(0x00, 0x00, 0xff, 0x20), blue(0xff, 0x00, 0x00, 0x20), + red0(0xff, 0x00, 0x00, 0x1f), green0(0x00, 0x00, 0xff, 0x1f), blue0(0xff, 0x00, 0x00, 0x1f), + none0(0xff, 0xff, 0xff, 0x1f), white(0xff, 0xff, 0xff, 0xff); + +constexpr Vector4ub img_data[] = { + red, green0, blue0, white, + red0, green, blue, none0, + none0, green, blue0, blue, + red0, green0, blue, green, + red, green, blue, none0, + red, green0, blue0, red, +}; + +constexpr bool result[] = { + // inverse row order, use tac(1) + true, false, false, true, + true, true, true, false, + false, false, true, true, + false, true, false, true, + false, true, true, false, + true, false, false, true, + +}; + +} // namespace + +void test_app::test_bitmask() +{ + constexpr auto size = std::size(img_data), width = 4_uz, height = size/4; + static_assert(size % 4 == 0); + static_assert(size == std::size(result)); + ImageView2D img{PixelFormat::RGBA8Unorm, {width, height}, img_data}; + auto bitmask = anim_atlas::make_bitmask(img); + fm_assert(img.size().product() == std::size(result)); + for (auto i = 0_uz; i < size; i++) + if (bitmask[i] != result[i]) + fm_abort("wrong value at bit %zu, should be %s", i, result[i] ? "true" : "false"); +} + +} // namespace floormat diff --git a/test/main.cpp b/test/main.cpp index c01f09f0..2187ba21 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -25,6 +25,7 @@ int test_app::exec() test_serializer(); test_entity(); test_loader(); + test_bitmask(); return 0; } -- cgit v1.2.3