From f8dad7c79eb799abdd4db5ec0bfed5801923a6b9 Mon Sep 17 00:00:00 2001 From: Olzhas Zhumabek Date: Sat, 16 May 2020 02:01:52 +0600 Subject: [PATCH] Add tests for ext/blaze Add tests for image<->matrix conversion and pixel<->vector conversion --- test/extension/blaze/CMakeLists.txt | 4 +- test/extension/blaze/pixel_to_vector.cpp | 61 +++++++++++++++++++++ test/extension/blaze/to_image.cpp | 69 ++++++++++++++++++++++++ test/extension/blaze/to_matrix.cpp | 1 - test/extension/blaze/vector_to_pixel.cpp | 67 +++++++++++++++++++++++ 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 test/extension/blaze/pixel_to_vector.cpp create mode 100644 test/extension/blaze/to_image.cpp create mode 100644 test/extension/blaze/vector_to_pixel.cpp diff --git a/test/extension/blaze/CMakeLists.txt b/test/extension/blaze/CMakeLists.txt index 1c23a218da..dfecf329e4 100644 --- a/test/extension/blaze/CMakeLists.txt +++ b/test/extension/blaze/CMakeLists.txt @@ -8,7 +8,9 @@ message(STATUS "Boost.GIL: Configuring tests in test/extension/blaze") foreach(_name to_matrix - ) + pixel_to_vector + vector_to_pixel + to_image) set(_test t_ext_blaze_${_name}) set(_target test_ext_blaze_${_name}) diff --git a/test/extension/blaze/pixel_to_vector.cpp b/test/extension/blaze/pixel_to_vector.cpp new file mode 100644 index 0000000000..398468ee4c --- /dev/null +++ b/test/extension/blaze/pixel_to_vector.cpp @@ -0,0 +1,61 @@ +#include + +#include + +namespace gil = boost::gil; + +void gray8_zero_to_vector() +{ + gil::gray8_pixel_t p(0); + auto v = gil::pixel_to_vector(p); + BOOST_TEST_EQ(v[0], 0); +} + +void gray8_to_vector() +{ + gil::gray8_pixel_t p(23); + auto v = gil::pixel_to_vector(p); + BOOST_TEST_EQ(v[0], 23); +} + +void rgb8_zero_to_vector() +{ + gil::rgb8_pixel_t p(0, 0, 0); + auto vector = gil::pixel_to_vector(p); + BOOST_TEST_EQ(vector[0], 0); + BOOST_TEST_EQ(vector[1], 0); + BOOST_TEST_EQ(vector[2], 0); +} + +void rgb8_uniform_to_vector() +{ + auto value = std::uint8_t(23); + gil::rgb8_pixel_t p(value, value, value); + auto vector = gil::pixel_to_vector(p); + BOOST_TEST_EQ(vector[0], value); + BOOST_TEST_EQ(vector[1], value); + BOOST_TEST_EQ(vector[2], value); +} + +void rgb8_distinct_to_vector() +{ + auto value0 = std::uint8_t(23); + auto value1 = std::uint8_t(11); + auto value2 = std::uint8_t(1); + gil::rgb8_pixel_t p(value0, value1, value2); + auto vector = gil::pixel_to_vector(p); + BOOST_TEST_EQ(vector[0], value0); + BOOST_TEST_EQ(vector[1], value1); + BOOST_TEST_EQ(vector[2], value2); +} + +int main() +{ + gray8_zero_to_vector(); + gray8_to_vector(); + rgb8_zero_to_vector(); + rgb8_uniform_to_vector(); + rgb8_distinct_to_vector(); + + return boost::report_errors(); +} diff --git a/test/extension/blaze/to_image.cpp b/test/extension/blaze/to_image.cpp new file mode 100644 index 0000000000..b1ea801966 --- /dev/null +++ b/test/extension/blaze/to_image.cpp @@ -0,0 +1,69 @@ +#include + +#include +#include + +namespace gil = boost::gil; + +void matrix_to_gray8_uniform() +{ + gil::gray8_image_t expected(16, 16, gil::gray8_pixel_t(13)); + blaze::DynamicMatrix> input(16, 16, {13}); + auto result = gil::to_image(input); + + BOOST_TEST(gil::equal_pixels(gil::view(result), gil::view(expected))); +} + +void matrix_to_gray8_distinct() +{ + blaze::DynamicMatrix> input(16, 16, {13}); + gil::gray8_image_t expected(16, 16, gil::gray8_pixel_t(13)); + auto view = gil::view(expected); + input(0, 0)[0] = 0; + input(1, 0)[0] = 1; // rows and cols are different for GIL vs Blaze + + auto result = gil::to_image(input); + view(0, 0)[0] = 0; + view(0, 1)[0] = 1; + + BOOST_TEST(gil::equal_pixels(gil::view(result), gil::view(expected))); +} + +void matrix_to_rgb8_uniform() +{ + gil::rgb8_pixel_t default_pixel(1, 2, 3); + gil::rgb8_image_t expected(16, 16, default_pixel); + + blaze::StaticVector default_vector({1, 2, 3}); + blaze::DynamicMatrix> input(16, 16, default_vector); + + auto result = gil::to_image(input); + BOOST_TEST(gil::equal_pixels(gil::view(result), gil::view(expected))); +} + +void matrix_to_rgb8_distinct() +{ + gil::rgb8_pixel_t default_pixel(1, 2, 3); + gil::rgb8_image_t expected(16, 16, default_pixel); + auto view = gil::view(expected); + view(0, 0) = gil::rgb8_pixel_t(10, 20, 30); + view(1, 0) = gil::rgb8_pixel_t(50, 50, 50); + + blaze::StaticVector default_vector({1, 2, 3}); + blaze::DynamicMatrix> input(16, 16, default_vector); + input(0, 0) = {10, 20, 30}; + input(0, 1) = {50, 50, 50}; + + auto result = gil::to_image(input); + BOOST_TEST(gil::equal_pixels(gil::view(result), gil::view(expected))); +} + +int main() +{ + matrix_to_gray8_uniform(); + matrix_to_gray8_distinct(); + matrix_to_rgb8_uniform(); + matrix_to_rgb8_distinct(); + + return boost::report_errors(); +} diff --git a/test/extension/blaze/to_matrix.cpp b/test/extension/blaze/to_matrix.cpp index ce559b9aa7..61b2cae79e 100644 --- a/test/extension/blaze/to_matrix.cpp +++ b/test/extension/blaze/to_matrix.cpp @@ -64,6 +64,5 @@ int main() rgb8_to_matrix_uniform(); rgb8_to_matrix_distinct(); - return boost::report_errors(); } diff --git a/test/extension/blaze/vector_to_pixel.cpp b/test/extension/blaze/vector_to_pixel.cpp new file mode 100644 index 0000000000..9fa8ccb3e8 --- /dev/null +++ b/test/extension/blaze/vector_to_pixel.cpp @@ -0,0 +1,67 @@ +#include + +#include + +namespace gil = boost::gil; + +void vector1d_zero_to_gray8() +{ + blaze::StaticVector v({0}); + auto p = gil::vector_to_pixel(v); + + BOOST_TEST_EQ(p[0], 0); +} + +void vector1d_to_gray8() +{ + blaze::StaticVector v({23}); + auto p = gil::vector_to_pixel(v); + + BOOST_TEST_EQ(p[0], 23); +} + +void vector3d_zero_to_rgb8() +{ + blaze::StaticVector v({0, 0, 0}); + auto p = gil::vector_to_pixel(v); + + BOOST_TEST_EQ(p[0], 0); + BOOST_TEST_EQ(p[1], 0); + BOOST_TEST_EQ(p[2], 0); +} + +void vector3d_uniform_to_rgb8() +{ + std::uint8_t value = 23; + blaze::StaticVector v({value, value, value}); + + auto p = gil::vector_to_pixel(v); + + BOOST_TEST_EQ(p[0], value); + BOOST_TEST_EQ(p[1], value); + BOOST_TEST_EQ(p[2], value); +} + +void vector3d_distinct_to_rgb8() +{ + std::uint8_t value0 = 23; + std::uint8_t value1 = 11; + std::uint8_t value2 = 1; + blaze::StaticVector v({value0, value1, value2}); + auto p = gil::vector_to_pixel(v); + + BOOST_TEST_EQ(p[0], value0); + BOOST_TEST_EQ(p[1], value1); + BOOST_TEST_EQ(p[2], value2); +} + +int main() +{ + vector1d_zero_to_gray8(); + vector1d_to_gray8(); + vector3d_zero_to_rgb8(); + vector3d_uniform_to_rgb8(); + vector3d_distinct_to_rgb8(); + + return boost::report_errors(); +}