Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / gil / test / channel / scoped_channel_value.cpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 // Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
4 //
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
8 //
9 #include <boost/gil/channel.hpp>
10 #include <boost/gil/channel_algorithm.hpp>
11 #include <boost/gil/typedefs.hpp>
12 #include <cstdint>
13 #include <limits>
14
15 #define BOOST_TEST_MODULE test_scoped_channel_value
16 #include "unit_test.hpp"
17
18 namespace gil = boost::gil;
19
20 BOOST_AUTO_TEST_CASE(scoped_channel_float32_t)
21 {
22     auto const tolerance = btt::tolerance(std::numeric_limits<float>::epsilon());
23     // min
24     BOOST_TEST(gil::float_point_zero<float>::apply() == 0.0, tolerance);
25     BOOST_TEST(gil::channel_traits<gil::float32_t>::min_value() == 0.0);
26     // max
27     BOOST_TEST(gil::float_point_one<float>::apply() == 1.0, tolerance);
28     BOOST_TEST(gil::channel_traits<gil::float32_t>::max_value() == 1.0);
29 }
30
31 BOOST_AUTO_TEST_CASE(scoped_channel_float64_t)
32 {
33     auto const tolerance = btt::tolerance(std::numeric_limits<double>::epsilon());
34     // min
35     BOOST_TEST(gil::float_point_zero<double>::apply() == 0.0, tolerance);
36     BOOST_TEST(gil::channel_traits<gil::float64_t>::min_value() == 0.0, tolerance);
37     // max
38     BOOST_TEST(gil::float_point_one<double>::apply() == 1.0, tolerance);
39     BOOST_TEST(gil::channel_traits<gil::float64_t>::max_value() == 1.0, tolerance);
40 }
41
42 BOOST_AUTO_TEST_CASE(scoped_channel_halfs)
43 {
44     // Create a double channel with range [-0.5 .. 0.5]
45     struct minus_half { static double apply() { return -0.5; } };
46     struct plus_half { static double apply() { return 0.5; } };
47     using halfs = gil::scoped_channel_value<double, minus_half, plus_half>;
48
49     auto const tolerance = btt::tolerance(std::numeric_limits<double>::epsilon());
50     BOOST_TEST(gil::channel_traits<halfs>::min_value() == minus_half::apply(), tolerance);
51     BOOST_TEST(gil::channel_traits<halfs>::max_value() == plus_half::apply(), tolerance);
52     // scoped channel maximum should map to the maximum
53     BOOST_TEST(gil::channel_convert<std::uint16_t>(
54         gil::channel_traits<halfs>::max_value()) == 65535, tolerance);
55 }