From 5cc317cdab432d670c823f3399ef0efed9c38867 Mon Sep 17 00:00:00 2001 From: Christian Henning Date: Sat, 6 Nov 2010 18:17:10 +0000 Subject: [PATCH] Introducing base_channel_type metafunction which helps to avoid useless casting between integral data types. For older compilers it also reduces warnings about those castings operations. [SVN r66416] --- include/boost/gil/channel.hpp | 27 +++++++++++++++++++++++++ include/boost/gil/channel_algorithm.hpp | 6 +++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/boost/gil/channel.hpp b/include/boost/gil/channel.hpp index 823691b35..d8cf78c79 100644 --- a/include/boost/gil/channel.hpp +++ b/include/boost/gil/channel.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "gil_config.hpp" #include "utilities.hpp" @@ -669,4 +670,30 @@ struct is_integral > : } +// \brief Determines the fundamental type which may be used, e.g., to cast from larger to smaller channel types. +namespace boost { namespace gil { +template +struct base_channel_type_impl { typedef T type; }; + +template +struct base_channel_type_impl > +{ typedef typename packed_channel_value::integer_t type; }; + +template +struct base_channel_type_impl > +{ typedef typename packed_channel_reference::integer_t type; }; + +template +struct base_channel_type_impl > +{ typedef typename packed_dynamic_channel_reference::integer_t type; }; + +template +struct base_channel_type_impl > +{ typedef ChannelValue type; }; + +template +struct base_channel_type : base_channel_type_impl::type > {}; + +} } //namespace boost::gil + #endif diff --git a/include/boost/gil/channel_algorithm.hpp b/include/boost/gil/channel_algorithm.hpp index 1361219a3..8d39fafdf 100644 --- a/include/boost/gil/channel_algorithm.hpp +++ b/include/boost/gil/channel_algorithm.hpp @@ -226,8 +226,8 @@ struct channel_converter_unsigned_integral_impl struct channel_converter_unsigned_integral_nondivisible { DstChannelV operator()(SrcChannelV src) const { - typedef typename detail::min_fast_uint::value+unsigned_integral_num_bits::value>::type integer_t; - return DstChannelV(integer_t(src * unsigned_integral_max_value::value) / unsigned_integral_max_value::value); + typedef typename base_channel_type::type dest_t; + return DstChannelV(static_cast( src * unsigned_integral_max_value::value) / unsigned_integral_max_value::value); } }; @@ -410,7 +410,7 @@ assert(mul == 64); // 64 = 128 * 128 / 255 template struct channel_multiplier_unsigned : public std::binary_function { ChannelValue operator()(ChannelValue a, ChannelValue b) const { - return ChannelValue(a / double(channel_traits::max_value()) * b); + return ChannelValue(static_cast::type>(a / double(channel_traits::max_value()) * b)); } };