mirror of
https://github.com/boostorg/gil.git
synced 2026-02-18 14:12:10 +00:00
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]
This commit is contained in:
committed by
Stefan Seefeld
parent
6631602f89
commit
5cc317cdab
@@ -27,6 +27,7 @@
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include "gil_config.hpp"
|
||||
#include "utilities.hpp"
|
||||
|
||||
@@ -669,4 +670,30 @@ struct is_integral<gil::scoped_channel_value<BaseChannelValue,MinVal,MaxVal> > :
|
||||
|
||||
}
|
||||
|
||||
// \brief Determines the fundamental type which may be used, e.g., to cast from larger to smaller channel types.
|
||||
namespace boost { namespace gil {
|
||||
template <typename T>
|
||||
struct base_channel_type_impl { typedef T type; };
|
||||
|
||||
template <int N>
|
||||
struct base_channel_type_impl<packed_channel_value<N> >
|
||||
{ typedef typename packed_channel_value<N>::integer_t type; };
|
||||
|
||||
template <typename B, int F, int N, bool M>
|
||||
struct base_channel_type_impl<packed_channel_reference<B, F, N, M> >
|
||||
{ typedef typename packed_channel_reference<B,F,N,M>::integer_t type; };
|
||||
|
||||
template <typename B, int N, bool M>
|
||||
struct base_channel_type_impl<packed_dynamic_channel_reference<B, N, M> >
|
||||
{ typedef typename packed_dynamic_channel_reference<B,N,M>::integer_t type; };
|
||||
|
||||
template <typename ChannelValue, typename MinV, typename MaxV>
|
||||
struct base_channel_type_impl<scoped_channel_value<ChannelValue, MinV, MaxV> >
|
||||
{ typedef ChannelValue type; };
|
||||
|
||||
template <typename T>
|
||||
struct base_channel_type : base_channel_type_impl<typename remove_cv<T>::type > {};
|
||||
|
||||
} } //namespace boost::gil
|
||||
|
||||
#endif
|
||||
|
||||
@@ -226,8 +226,8 @@ struct channel_converter_unsigned_integral_impl<SrcChannelV,DstChannelV,SrcLessT
|
||||
template <typename SrcChannelV, typename DstChannelV>
|
||||
struct channel_converter_unsigned_integral_nondivisible<SrcChannelV,DstChannelV,true,false> {
|
||||
DstChannelV operator()(SrcChannelV src) const {
|
||||
typedef typename detail::min_fast_uint<unsigned_integral_num_bits<SrcChannelV>::value+unsigned_integral_num_bits<DstChannelV>::value>::type integer_t;
|
||||
return DstChannelV(integer_t(src * unsigned_integral_max_value<DstChannelV>::value) / unsigned_integral_max_value<SrcChannelV>::value);
|
||||
typedef typename base_channel_type<DstChannelV>::type dest_t;
|
||||
return DstChannelV(static_cast<dest_t>( src * unsigned_integral_max_value<DstChannelV>::value) / unsigned_integral_max_value<SrcChannelV>::value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -410,7 +410,7 @@ assert(mul == 64); // 64 = 128 * 128 / 255
|
||||
template <typename ChannelValue>
|
||||
struct channel_multiplier_unsigned : public std::binary_function<ChannelValue,ChannelValue,ChannelValue> {
|
||||
ChannelValue operator()(ChannelValue a, ChannelValue b) const {
|
||||
return ChannelValue(a / double(channel_traits<ChannelValue>::max_value()) * b);
|
||||
return ChannelValue(static_cast<typename base_channel_type<ChannelValue>::type>(a / double(channel_traits<ChannelValue>::max_value()) * b));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user