diff --git a/include/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp b/include/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp index 202168234..7c35ba1d9 100644 --- a/include/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp +++ b/include/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp @@ -12,7 +12,7 @@ #include // FIXME: Include what you use! -#include +#include #include #include @@ -55,6 +55,21 @@ typedef boost::gil::layout ycbcr_709__layout_t; GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, ycbcr_601_) GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, ycbcr_709_) +namespace detail { + +// Source:boost/algorithm/clamp.hpp +template +constexpr T const& clamp(T const& val, + typename boost::mpl::identity::type const & lo, + typename boost::mpl::identity::type const & hi) +{ + // assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal + auto const p = std::less(); + return p(val, lo) ? lo : p(hi, val) ? hi : val; +} + +} // namespace detail + /* * 601 Source: http://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion * 709 Source: http://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion @@ -91,7 +106,6 @@ private: , mpl::true_ // is 8 bit channel ) const { - using namespace boost::algorithm; using namespace ycbcr_601_color_space; typedef typename channel_type< Src_Pixel >::type src_channel_t; @@ -105,9 +119,9 @@ private: std::int_fast16_t c = y - 16; std::int_fast16_t d = cb - 128; std::int_fast16_t e = cr - 128; - std::int_fast16_t red = clamp((( 298 * c + 409 * e + 128) >> 8), 0, 255); - std::int_fast16_t green = clamp((( 298 * c - 100 * d - 208 * e + 128) >> 8), 0, 255); - std::int_fast16_t blue = clamp((( 298 * c + 516 * d + 128) >> 8), 0, 255); + std::int_fast16_t red = detail::clamp((( 298 * c + 409 * e + 128) >> 8), 0, 255); + std::int_fast16_t green = detail::clamp((( 298 * c - 100 * d - 208 * e + 128) >> 8), 0, 255); + std::int_fast16_t blue = detail::clamp((( 298 * c + 516 * d + 128) >> 8), 0, 255); get_color( dst, red_t() ) = (dst_channel_t) red; get_color( dst, green_t() ) = (dst_channel_t) green; @@ -123,7 +137,6 @@ private: , mpl::false_ // is 8 bit channel ) const { - using namespace boost::algorithm; using namespace ycbcr_601_color_space; typedef typename channel_type< Dst_Pixel >::type dst_channel_t; @@ -132,20 +145,14 @@ private: double cb = get_color( src, cb_t() ); double cr = get_color( src, cr_t() ); - get_color(dst, red_t()) = (dst_channel_t) clamp( 1.6438 * ( y - 16.0 ) + 1.5960 * ( cr -128.0 ) - , 0.0 - , 255.0 - ); + get_color(dst, red_t()) = static_cast( + detail::clamp(1.6438 * (y - 16.0) + 1.5960 * (cr -128.0), 0.0, 255.0)); - get_color(dst, green_t()) = (dst_channel_t) clamp( 1.6438 * ( y - 16.0 ) - 0.3917 * ( cb - 128.0 ) + 0.8129 * ( cr -128.0 ) - , 0.0 - , 255.0 - ); + get_color(dst, green_t()) = static_cast( + detail::clamp(1.6438 * (y - 16.0) - 0.3917 * (cb - 128.0) + 0.8129 * (cr -128.0), 0.0, 255.0)); - get_color(dst, blue_t()) = (dst_channel_t) clamp( 1.6438 * ( y - 16.0 ) - 2.0172 * ( cb -128.0 ) - , 0.0 - , 255.0 - ); + get_color(dst, blue_t()) = static_cast( + detail::clamp(1.6438 * ( y - 16.0 ) - 2.0172 * ( cb -128.0 ), 0.0, 255.0)); } }; diff --git a/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp b/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp index 1d961f791..be2a7baa8 100644 --- a/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp +++ b/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp @@ -59,7 +59,7 @@ struct subchroma_image_deref_fn {} /// operator() - typename result_type operator()( const point_t& p ) const + result_type operator()( const point_t& p ) const { typedef Scaling_Factors< mpl::at_c< Factors, 0 >::type::value , mpl::at_c< Factors, 1 >::type::value