-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for image<->matrix conversion and pixel<->vector conversion
- Loading branch information
1 parent
ae8429b
commit f8dad7c
Showing
5 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,5 @@ int main() | |
rgb8_to_matrix_uniform(); | ||
rgb8_to_matrix_distinct(); | ||
|
||
|
||
return boost::report_errors(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |