summaryrefslogtreecommitdiffhomepage
path: root/test/bitmask.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-02 11:33:45 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-02 12:02:04 +0100
commitf8a5e5ba5e4abb50750dbe914349664e958be2ae (patch)
tree68d2204fb46fe8cc92eeb997fd7546acd72c97b4 /test/bitmask.cpp
parentd8df3fb6e7e824c358cd20edfe83c4eff5cfd9da (diff)
test: improve bitmask test
It wasn't testing the `width0` code path.
Diffstat (limited to 'test/bitmask.cpp')
-rw-r--r--test/bitmask.cpp58
1 files changed, 25 insertions, 33 deletions
diff --git a/test/bitmask.cpp b/test/bitmask.cpp
index 2160928c..5398bce7 100644
--- a/test/bitmask.cpp
+++ b/test/bitmask.cpp
@@ -4,45 +4,27 @@
#include "loader/loader.hpp"
#include <iterator>
#include <Corrade/Containers/ArrayView.h>
-#include <Magnum/Magnum.h>
-#include <Magnum/Math/Vector4.h>
+#include <Corrade/Containers/StridedArrayView.h>
#include <Magnum/Trade/ImageData.h>
#include <Magnum/ImageView.h>
#include <Magnum/PixelFormat.h>
#include <chrono>
+//#define DO_GENERATE
+
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,
-
+constexpr std::size_t data_nbytes = 128;
+const unsigned char data_door_close[] = {
+#include "bitmask.embed.inc"
};
[[maybe_unused]] void bitmask_benchmark()
{
std::chrono::high_resolution_clock clock;
+
auto img = loader.texture(loader.SCENERY_PATH, "door-close"_s);
auto bitmask = anim_atlas::make_bitmask(img);
constexpr int runs = 10, warmup = 500, cycles = 1000;
@@ -61,15 +43,25 @@ constexpr bool result[] = {
void bitmask_test()
{
- 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 img = loader.texture(loader.SCENERY_PATH, "door-close"_s);
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");
+ fm_assert(img.pixelSize() == 4 && (std::size_t)img.size().product() >= data_nbytes);
+#ifdef DO_GENERATE
+ for (auto i = 0_uz; i < data_nbytes; i++)
+ {
+ if (i && i % 16 == 0)
+ printf("\n");
+ printf("0x%02hhx,", bitmask.data()[i]);
+ if ((i+1) % 16 != 0)
+ printf(" ");
+ }
+ printf("\n");
+ fflush(stdout);
+#endif
+ const auto len = std::min(data_nbytes, (std::size_t)bitmask.size()+7 >> 3);
+ for (auto i = 0_uz; i < len; i++)
+ if ((unsigned char)bitmask.data()[i] != data_door_close[i])
+ fm_abort("wrong value at bit %zu, should be' 0x%02hhx'", i, data_door_close[i]);
}
} // namespace