2 // Copyright 2005-2007 Adobe Systems Incorporated
3 // Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
5 // Distribtted under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
9 #include <boost/gil/channel.hpp>
10 #include <boost/gil/channel_algorithm.hpp>
11 #include <boost/gil/typedefs.hpp>
15 #define BOOST_TEST_MODULE test_scoped_channel_value
16 #include "unit_test.hpp"
18 namespace gil
= boost::gil
;
20 struct int_minus_value
{ static std::int8_t apply() { return -64; } };
21 struct int_plus_value
{ static std::int8_t apply() { return 64; } };
22 using fixture
= gil::scoped_channel_value
24 std::uint8_t, int_minus_value
, int_plus_value
27 BOOST_AUTO_TEST_CASE(scoped_channel_value_default_constructor
)
31 BOOST_TEST(v
== std::uint8_t{0});
34 BOOST_AUTO_TEST_CASE(scoped_channel_value_user_defined_constructors
)
38 BOOST_TEST(v
== std::uint8_t{1});
41 BOOST_AUTO_TEST_CASE(scoped_channel_value_copy_constructors
)
46 BOOST_TEST(std::uint8_t{f1
} == std::uint8_t{128});
47 BOOST_TEST(std::uint8_t{f1
} == std::uint8_t{f2
});
50 BOOST_AUTO_TEST_CASE(scoped_channel_value_assignment
)
55 BOOST_TEST(v
== std::uint8_t{64});
58 BOOST_AUTO_TEST_CASE(scoped_channel_value_float32_t
)
60 auto const tolerance
= btt::tolerance(std::numeric_limits
<float>::epsilon());
62 BOOST_TEST(gil::float_point_zero
<float>::apply() == 0.0, tolerance
);
63 BOOST_TEST(gil::channel_traits
<gil::float32_t
>::min_value() == 0.0);
65 BOOST_TEST(gil::float_point_one
<float>::apply() == 1.0, tolerance
);
66 BOOST_TEST(gil::channel_traits
<gil::float32_t
>::max_value() == 1.0);
69 BOOST_AUTO_TEST_CASE(scoped_channel_value_float64_t
)
71 auto const tolerance
= btt::tolerance(std::numeric_limits
<double>::epsilon());
73 BOOST_TEST(gil::float_point_zero
<double>::apply() == 0.0, tolerance
);
74 BOOST_TEST(gil::channel_traits
<gil::float64_t
>::min_value() == 0.0, tolerance
);
76 BOOST_TEST(gil::float_point_one
<double>::apply() == 1.0, tolerance
);
77 BOOST_TEST(gil::channel_traits
<gil::float64_t
>::max_value() == 1.0, tolerance
);
80 BOOST_AUTO_TEST_CASE(scoped_channel_value_halfs
)
82 // Create a double channel with range [-0.5 .. 0.5]
83 struct minus_half
{ static double apply() { return -0.5; } };
84 struct plus_half
{ static double apply() { return 0.5; } };
85 using halfs
= gil::scoped_channel_value
<double, minus_half
, plus_half
>;
87 auto const tolerance
= btt::tolerance(std::numeric_limits
<double>::epsilon());
88 BOOST_TEST(gil::channel_traits
<halfs
>::min_value() == minus_half::apply(), tolerance
);
89 BOOST_TEST(gil::channel_traits
<halfs
>::max_value() == plus_half::apply(), tolerance
);
90 // scoped channel maximum should map to the maximum
91 BOOST_TEST(gil::channel_convert
<std::uint16_t>(
92 gil::channel_traits
<halfs
>::max_value()) == 65535, tolerance
);