summaryrefslogtreecommitdiff
path: root/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/gil/extension/toolbox/color_spaces/ycbcr.hpp')
-rw-r--r--boost/gil/extension/toolbox/color_spaces/ycbcr.hpp74
1 files changed, 36 insertions, 38 deletions
diff --git a/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp b/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp
index e8e282f6a5..7c35ba1d9b 100644
--- a/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp
+++ b/boost/gil/extension/toolbox/color_spaces/ycbcr.hpp
@@ -1,31 +1,22 @@
-/*
- Copyright 2013 Juan V. Puertos G-Cluster, Christian Henning
- Use, modification and distribution are subject to 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).
-*/
-
-/*************************************************************************************************/
-
+//
+// Copyright 2013 Juan V. Puertos G-Cluster, Christian Henning
+//
+// Distributed 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_EXTENSION_TOOLBOX_COLOR_SPACES_YCBCR_HPP
#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_YCBCR_HPP
-////////////////////////////////////////////////////////////////////////////////////////
-/// \file ycbcr.hpp
-/// \brief Support for ycbcr ITU.BT-601 color space
-/// \author Juan V. Puertos G-Cluster 2013 \n
-///
-/// \date 2013 \n
-///
-////////////////////////////////////////////////////////////////////////////////////////
+#include <boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp>
-#include <cstdint>
-#include <boost/algorithm/clamp.hpp>
+#include <boost/gil.hpp> // FIXME: Include what you use!
+
+#include <boost/mpl/identity.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/vector_c.hpp>
-#include <boost/gil/gil_all.hpp>
-#include <boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp>
+#include <cstdint>
namespace boost{ namespace gil {
@@ -64,6 +55,21 @@ typedef boost::gil::layout<ycbcr_709__t> 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<typename T>
+constexpr T const& clamp(T const& val,
+ typename boost::mpl::identity<T>::type const & lo,
+ typename boost::mpl::identity<T>::type const & hi)
+{
+ // assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal
+ auto const p = std::less<T>();
+ 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
@@ -100,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;
@@ -114,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;
@@ -132,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;
@@ -141,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<dst_channel_t>(
+ 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<dst_channel_t>(
+ 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<dst_channel_t>(
+ detail::clamp(1.6438 * ( y - 16.0 ) - 2.0172 * ( cb -128.0 ), 0.0, 255.0));
}
};