• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 // Copyright 2018-2020 Mateusz Loskot <mateusz at loskot dot net>
4 //
5 // Distributed 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_algorithm.hpp>
10 
11 #include <boost/core/lightweight_test.hpp>
12 
13 #include <cstdint>
14 
15 #include "test_fixture.hpp"
16 
17 namespace gil = boost::gil;
18 namespace fixture = boost::gil::test::fixture;
19 
20 template <typename ChannelFixtureBase>
test_channel_multiply()21 void test_channel_multiply()
22 {
23     fixture::channel<ChannelFixtureBase> f;
24     BOOST_TEST_EQ(gil::channel_multiply(f.min_v_, f.min_v_), f.min_v_);
25     BOOST_TEST_EQ(gil::channel_multiply(f.max_v_, f.max_v_), f.max_v_);
26     BOOST_TEST_EQ(gil::channel_multiply(f.max_v_, f.min_v_), f.min_v_);
27 }
28 
29 struct test_channel_value
30 {
31     template <typename Channel>
operator ()test_channel_value32     void operator()(Channel const &)
33     {
34         using channel_t = Channel;
35         using fixture_t = fixture::channel_value<channel_t>;
36         test_channel_multiply<fixture_t>();
37     }
runtest_channel_value38     static void run()
39     {
40         boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value{});
41     }
42 };
43 
44 struct test_channel_reference
45 {
46     template <typename Channel>
operator ()test_channel_reference47     void operator()(Channel const &)
48     {
49         using channel_t = Channel;
50         using fixture_t = fixture::channel_reference<channel_t&>;
51         test_channel_multiply<fixture_t>();
52     }
runtest_channel_reference53     static void run()
54     {
55         boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_reference{});
56     }
57 };
58 
59 struct test_channel_reference_const
60 {
61     template <typename Channel>
operator ()test_channel_reference_const62     void operator()(Channel const &)
63     {
64         using channel_t = Channel;
65         using fixture_t = fixture::channel_reference<channel_t const&>;
66         test_channel_multiply<fixture_t>();
67     }
runtest_channel_reference_const68     static void run()
69     {
70         boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_reference_const{});
71     }
72 };
73 
74 struct test_packed_channel_reference
75 {
76     template <typename BitField>
operator ()test_packed_channel_reference77     void operator()(BitField const &)
78     {
79         using bitfield_t = BitField;
80         using channels565_t = fixture::packed_channels565<bitfield_t>;
81         test_channel_multiply<typename channels565_t::fixture_0_5_t>();
82         test_channel_multiply<typename channels565_t::fixture_5_6_t>();
83         test_channel_multiply<typename channels565_t::fixture_11_5_t>();
84     }
runtest_packed_channel_reference85     static void run()
86     {
87         boost::mp11::mp_for_each<fixture::channel_bitfield_types>(test_packed_channel_reference{});
88     }
89 };
90 
91 struct test_packed_dynamic_channel_reference
92 {
93     template <typename BitField>
operator ()test_packed_dynamic_channel_reference94     void operator()(BitField const &)
95     {
96         using bitfield_t = BitField;
97         using channels565_t = fixture::packed_dynamic_channels565<bitfield_t>;
98         test_channel_multiply<typename channels565_t::fixture_5_t>();
99         test_channel_multiply<typename channels565_t::fixture_6_t>();
100     }
runtest_packed_dynamic_channel_reference101     static void run()
102     {
103         boost::mp11::mp_for_each<fixture::channel_bitfield_types>(test_packed_dynamic_channel_reference{});
104     }
105 };
106 
main()107 int main()
108 {
109     test_channel_value::run();
110     test_channel_reference::run();
111     test_channel_reference_const::run();
112     test_packed_channel_reference::run();
113     test_packed_dynamic_channel_reference::run();
114 
115     // TODO: packed_channel_reference_const ?
116     // TODO: packed_dynamic_channel_reference_const ?
117 
118     return ::boost::report_errors();
119 }
120