Skip to content

Commit

Permalink
Add tests for ext/blaze
Browse files Browse the repository at this point in the history
Add tests for image<->matrix conversion
and pixel<->vector conversion
  • Loading branch information
simmplecoder committed May 15, 2020
1 parent ae8429b commit f8dad7c
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/extension/blaze/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
61 changes: 61 additions & 0 deletions test/extension/blaze/pixel_to_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <boost/core/lightweight_test.hpp>

#include <boost/gil/extension/blaze/blaze.hpp>

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();
}
69 changes: 69 additions & 0 deletions test/extension/blaze/to_image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <boost/core/lightweight_test.hpp>

#include <boost/gil/algorithm.hpp>
#include <boost/gil/extension/blaze/blaze.hpp>

namespace gil = boost::gil;

void matrix_to_gray8_uniform()
{
gil::gray8_image_t expected(16, 16, gil::gray8_pixel_t(13));
blaze::DynamicMatrix<blaze::StaticVector<std::uint8_t, 1>> input(16, 16, {13});
auto result = gil::to_image<gil::gray8_image_t>(input);

BOOST_TEST(gil::equal_pixels(gil::view(result), gil::view(expected)));
}

void matrix_to_gray8_distinct()
{
blaze::DynamicMatrix<blaze::StaticVector<std::uint8_t, 1>> 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<gil::gray8_image_t>(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<std::uint8_t, 3> default_vector({1, 2, 3});
blaze::DynamicMatrix<blaze::StaticVector<std::uint8_t, 3>> input(16, 16, default_vector);

auto result = gil::to_image<gil::rgb8_image_t>(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<std::uint8_t, 3> default_vector({1, 2, 3});
blaze::DynamicMatrix<blaze::StaticVector<std::uint8_t, 3>> input(16, 16, default_vector);
input(0, 0) = {10, 20, 30};
input(0, 1) = {50, 50, 50};

auto result = gil::to_image<gil::rgb8_image_t>(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();
}
1 change: 0 additions & 1 deletion test/extension/blaze/to_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,5 @@ int main()
rgb8_to_matrix_uniform();
rgb8_to_matrix_distinct();


return boost::report_errors();
}
67 changes: 67 additions & 0 deletions test/extension/blaze/vector_to_pixel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <boost/core/lightweight_test.hpp>

#include <boost/gil/extension/blaze/blaze.hpp>

namespace gil = boost::gil;

void vector1d_zero_to_gray8()
{
blaze::StaticVector<std::uint8_t, 1> v({0});
auto p = gil::vector_to_pixel<gil::gray8_pixel_t>(v);

BOOST_TEST_EQ(p[0], 0);
}

void vector1d_to_gray8()
{
blaze::StaticVector<std::uint8_t, 1> v({23});
auto p = gil::vector_to_pixel<gil::gray8_pixel_t>(v);

BOOST_TEST_EQ(p[0], 23);
}

void vector3d_zero_to_rgb8()
{
blaze::StaticVector<std::uint8_t, 3> v({0, 0, 0});
auto p = gil::vector_to_pixel<gil::gray8_pixel_t>(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<std::uint8_t, 3> v({value, value, value});

auto p = gil::vector_to_pixel<gil::rgb8_pixel_t>(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<std::uint8_t, 3> v({value0, value1, value2});
auto p = gil::vector_to_pixel<gil::rgb8_pixel_t>(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();
}

0 comments on commit f8dad7c

Please sign in to comment.