diff --git a/include/boost/gil/extension/dynamic_image/image_view_factory.hpp b/include/boost/gil/extension/dynamic_image/image_view_factory.hpp index 6667a828fa..a41dc32c54 100644 --- a/include/boost/gil/extension/dynamic_image/image_view_factory.hpp +++ b/include/boost/gil/extension/dynamic_image/image_view_factory.hpp @@ -314,20 +314,12 @@ auto nth_channel_view(any_image_view const& src, int n) namespace detail { -template -struct get_ccv_type : color_converted_view_type {}; - template struct views_get_ccv_type { private: - // FIXME: Remove class name injection with detail:: qualification - // Required as workaround for MP11 issue that treats unqualified metafunction - // in the class definition of the same name as the specialization (Peter Dimov): - // invalid template argument for template parameter 'F', expected a class template - template - using ccvt = detail::get_ccv_type; - + template + using ccvt = typename color_converted_view_type::type; public: using type = mp11::mp_transform; }; @@ -340,7 +332,7 @@ template struct color_converted_view_type,DstP,CC> { //using type = any_image_view::type>; - using type = detail::views_get_ccv_type, DstP, CC>; + using type = typename detail::views_get_ccv_type, DstP, CC>::type; }; /// \ingroup ImageViewTransformationsColorConvert @@ -348,11 +340,11 @@ struct color_converted_view_type,DstP,CC> /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept template inline -auto color_converted_view(any_image_view const& src, CC) +auto color_converted_view(any_image_view const& src, CC cc) -> typename color_converted_view_type, DstP, CC>::type { using cc_view_t = typename color_converted_view_type, DstP, CC>::type; - return variant2::visit(detail::color_converted_view_fn(), src); + return variant2::visit(detail::color_converted_view_fn(cc), src); } /// \ingroup ImageViewTransformationsColorConvert @@ -360,7 +352,7 @@ auto color_converted_view(any_image_view const& src, CC) template struct color_converted_view_type,DstP> { - using type = detail::views_get_ccv_type, DstP, default_color_converter>; + using type = typename detail::views_get_ccv_type, DstP, default_color_converter>::type; }; /// \ingroup ImageViewTransformationsColorConvert diff --git a/test/extension/dynamic_image/image_view_factory.cpp b/test/extension/dynamic_image/image_view_factory.cpp index ce0ad9ee28..3837f740e5 100644 --- a/test/extension/dynamic_image/image_view_factory.cpp +++ b/test/extension/dynamic_image/image_view_factory.cpp @@ -83,10 +83,77 @@ struct test_flipped_up_down_view } }; +template +bool equal_pixels_values(V1&& v1, + V2&& v2, + float threshold = 1e-6f) +{ +// convert both images to rgba32f and compare with threshold + return boost::variant2::visit([=](auto const& v1, auto const& v2) -> bool { + auto it1 = v1.begin(); + auto it2 = v2.begin(); + while(it1 != v1.end() && it2 != v2.end()) { + using pixel_t = gil::rgba32f_pixel_t; + static constexpr std::size_t num_channels = gil::num_channels::value; + pixel_t p1{}; + gil::color_convert(*it1++, p1); + pixel_t p2{}; + gil::color_convert(*it2++, p2); + for(size_t i = 0; i < num_channels; ++i) { + if(std::abs(p1[i] - p2[i]) > threshold){ + return false; + } + } + } + return true; + }, + std::forward(v1), + std::forward(v2)); +} + +struct test_color_converted_view +{ + static void run() + { + using dynamic_image_t = gil::any_image; + using src_image_t = gil::gray8_image_t; + using dst_image_t = gil::gray16_image_t; + using dst_pixel_t = typename dst_image_t::value_type; + static constexpr std::size_t num_channels = 1; + auto color_converter = [](auto const& src, auto& dst) { dst = 2 * src; }; + std::array pixel_data = + { + 0, 1, 2, + 3, 4, 5, + 6, 7, 8 + }; + std::array expected_pixel_data; + std::transform(std::begin(pixel_data), + std::end(pixel_data), + std::begin(expected_pixel_data), + [](auto v) { return 2 * v; }); + + dynamic_image_t source_image = + fixture::generate_image( + 3, 3, generator{pixel_data.data()}); + + dynamic_image_t expected_image = + fixture::generate_image( + 3, 3, generator{expected_pixel_data.data()}); + + auto result_view = gil::color_converted_view(gil::const_view(source_image), color_converter); + + BOOST_TEST(equal_pixels_values(result_view, + gil::const_view(expected_image), + 1e-6f)); + } +}; int main() { test_flipped_up_down_view::run(); + test_color_converted_view::run(); + return ::boost::report_errors(); }