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_invert()21void test_channel_invert() 22 { 23 fixture::channel<ChannelFixtureBase> f; 24 BOOST_TEST_EQ(gil::channel_invert(f.min_v_), f.max_v_); 25 BOOST_TEST_EQ(gil::channel_invert(f.max_v_), f.min_v_); 26 } 27 28 struct test_channel_value 29 { 30 template <typename Channel> operator ()test_channel_value31 void operator()(Channel const &) 32 { 33 using channel_t = Channel; 34 using fixture_t = fixture::channel_value<channel_t>; 35 test_channel_invert<fixture_t>(); 36 } runtest_channel_value37 static void run() 38 { 39 boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value{}); 40 } 41 }; 42 43 struct test_channel_reference 44 { 45 template <typename Channel> operator ()test_channel_reference46 void operator()(Channel const &) 47 { 48 using channel_t = Channel; 49 using fixture_t = fixture::channel_reference<channel_t&>; 50 test_channel_invert<fixture_t>(); 51 } runtest_channel_reference52 static void run() 53 { 54 boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_reference{}); 55 } 56 }; 57 58 struct test_channel_reference_const 59 { 60 template <typename Channel> operator ()test_channel_reference_const61 void operator()(Channel const &) 62 { 63 using channel_t = Channel; 64 using fixture_t = fixture::channel_reference<channel_t const&>; 65 test_channel_invert<fixture_t>(); 66 } runtest_channel_reference_const67 static void run() 68 { 69 boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_reference_const{}); 70 } 71 }; 72 73 struct test_packed_channel_reference 74 { 75 template <typename BitField> operator ()test_packed_channel_reference76 void operator()(BitField const &) 77 { 78 using bitfield_t = BitField; 79 using channels565_t = fixture::packed_channels565<bitfield_t>; 80 test_channel_invert<typename channels565_t::fixture_0_5_t>(); 81 test_channel_invert<typename channels565_t::fixture_5_6_t>(); 82 test_channel_invert<typename channels565_t::fixture_11_5_t>(); 83 } runtest_packed_channel_reference84 static void run() 85 { 86 boost::mp11::mp_for_each<fixture::channel_bitfield_types>(test_packed_channel_reference{}); 87 } 88 }; 89 90 struct test_packed_dynamic_channel_reference 91 { 92 template <typename BitField> operator ()test_packed_dynamic_channel_reference93 void operator()(BitField const &) 94 { 95 using bitfield_t = BitField; 96 using channels565_t = fixture::packed_dynamic_channels565<bitfield_t>; 97 test_channel_invert<typename channels565_t::fixture_5_t>(); 98 test_channel_invert<typename channels565_t::fixture_6_t>(); 99 } runtest_packed_dynamic_channel_reference100 static void run() 101 { 102 boost::mp11::mp_for_each<fixture::channel_bitfield_types>(test_packed_dynamic_channel_reference{}); 103 } 104 }; 105 main()106int main() 107 { 108 test_channel_value::run(); 109 test_channel_reference::run(); 110 test_channel_reference_const::run(); 111 test_packed_channel_reference::run(); 112 test_packed_dynamic_channel_reference::run(); 113 114 // TODO: packed_channel_reference_const ? 115 // TODO: packed_dynamic_channel_reference_const ? 116 117 return ::boost::report_errors(); 118 } 119