// // Copyright 2019-2020 Mateusz Loskot // // Distribtted under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // #ifndef BOOST_GIL_TEST_TEST_UTILITY_HPP #define BOOST_GIL_TEST_TEST_UTILITY_HPP #include // static_for_each #include #include #include #include #include #include #include #include #include // Utilities to make GIL primitives printable for BOOST_TEST_EQ and other macros namespace boost { namespace gil { namespace test { namespace utility { template struct printable_numeric { using type = typename std::conditional < std::is_integral::value, typename ::boost::gil::promote_integral::type, typename std::common_type::type >::type; static_assert(std::is_arithmetic::value, "T must be numeric type"); static_assert(sizeof(T) <= sizeof(type), "bit-size narrowing conversion"); }; template using printable_numeric_t = typename printable_numeric::type; struct print_color_base { std::ostream& os_; std::size_t element_index_{0}; print_color_base(std::ostream& os) : os_(os) {} template void operator()(Element const& c) { printable_numeric_t n{c}; if (element_index_ > 0) os_ << ", "; os_ << "v" << element_index_ << "=" << n; ++element_index_; } template void operator()(gil::packed_channel_reference const& c) { printable_numeric_t n{c.get()}; if (element_index_ > 0) os_ << ", "; os_ << "v" << element_index_ << "=" << n; ++element_index_; } template void operator()(gil::scoped_channel_value const& c) { printable_numeric_t n{c}; if (element_index_ > 0) os_ << ", "; os_ << "v" << element_index_ << "=" << n; ++element_index_; } }; }} // namespace test::utility template std::ostream& operator<<(std::ostream& os, point const& p) { os << "point<" << boost::core::demangled_name(typeid(T)) << ">"; os << "(" << p.x << ", " << p.y << ")" << std::endl; return os; } template std::ostream& operator<<(std::ostream& os, pixel const& p) { os << "pixel<" << "\n\tChannel=" << boost::core::demangled_name(typeid(ChannelValue)) << ",\n\tLayout=" << boost::core::demangled_name(typeid(Layout)) << "\n>("; static_for_each(p, test::utility::print_color_base{os}); os << ")" << std::endl; return os; } template std::ostream& operator<<(std::ostream& os, packed_pixel const& p) { os << "packed_pixel<" << "\n\tBitField=" << boost::core::demangled_name(typeid(BitField)) << ",\n\tChannelRefs=" << boost::core::demangled_name(typeid(ChannelRefs)) << ",\n\tLayout=" << boost::core::demangled_name(typeid(Layout)) << ">("; static_for_each(p, test::utility::print_color_base{os}); os << ")" << std::endl; return os; } template std::ostream& operator<<(std::ostream& os, planar_pixel_reference const& p) { os << "planar_pixel_reference<" << "\nChannelReference=" << boost::core::demangled_name(typeid(ChannelReference)) << ",\nColorSpace=" << boost::core::demangled_name(typeid(ColorSpace)) << ">("; static_for_each(p, test::utility::print_color_base{os}); os << ")" << std::endl; return os; } }} // namespace boost::gil #endif