From a41fbf75aff54f4d3bd88793cdf2bf281ea9ee01 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 14 Apr 2022 12:54:06 +0800 Subject: Add pixel and bitmap color depth conversion. --- test_bitmap.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test_bitmap.cpp (limited to 'test_bitmap.cpp') diff --git a/test_bitmap.cpp b/test_bitmap.cpp new file mode 100644 index 0000000..4f20d3f --- /dev/null +++ b/test_bitmap.cpp @@ -0,0 +1,33 @@ +// +// Created by Keuin on 2022/4/14. +// + +#include + +#include "bitmap.h" + +TEST(Pixel, PixelDepthConvert) { + const auto white8 = pixel8b::white(); + const auto white32 = pixel::white(); + ASSERT_EQ(white8, pixel8b::from(white32)); + + const auto black8 = pixel8b::black(); + const auto black32 = pixel::black(); + ASSERT_EQ(black8, pixel8b::from(black32)); + + const auto gray8 = pixel8b{127, 127, 127}; + const auto gray32 = pixel{ + ((1ULL << 32U) - 1U) >> 1U, + ((1ULL << 32U) - 1U) >> 1U, + ((1ULL << 32U) - 1U) >> 1U + }; + ASSERT_EQ(gray8, pixel8b::from(gray32)); + + const auto mix8 = pixel8b{0, 127, 255}; + const auto mix32 = pixel{ + 0, + ((1ULL << 32U) - 1U) >> 1U, + ((1ULL << 32U) - 1U) + }; + ASSERT_EQ(mix8, pixel8b::from(mix32)); +} \ No newline at end of file -- cgit v1.2.3