8 #ifndef BOOST_GIL_PREMULTIPLY_HPP
9 #define BOOST_GIL_PREMULTIPLY_HPP
11 #include <boost/gil/rgba.hpp>
13 #include <boost/core/ignore_unused.hpp>
14 #include <boost/mpl/for_each.hpp>
15 #include <boost/mpl/remove.hpp>
17 namespace boost {
namespace gil {
19 template <
typename SrcP,
typename DstP>
20 struct channel_premultiply
22 channel_premultiply(SrcP
const & src, DstP & dst)
23 : src_(src), dst_(dst)
26 template <
typename Channel>
27 void operator()(Channel c)
const
40 template <
typename SrcP,
typename DstP>
41 void assign_alpha_if(mpl::true_, SrcP
const &src, DstP &dst)
43 get_color(dst,alpha_t()) = alpha_or_max(src);
46 template <
typename SrcP,
typename DstP>
47 void assign_alpha_if(mpl::false_, SrcP
const& src, DstP& dst)
50 boost::ignore_unused(src);
51 boost::ignore_unused(dst);
57 template <
typename SrcP,
typename DstP>
58 void operator()(
const SrcP& src, DstP& dst)
const
60 typedef typename color_space_type<SrcP>::type src_colour_space_t;
61 typedef typename color_space_type<DstP>::type dst_colour_space_t;
62 typedef typename mpl::remove <src_colour_space_t, alpha_t>::type src_colour_channels;
64 typedef mpl::bool_<mpl::contains<dst_colour_space_t, alpha_t>::value> has_alpha_t;
65 mpl::for_each<src_colour_channels>(channel_premultiply<SrcP, DstP>(src, dst));
66 detail::assign_alpha_if(has_alpha_t(), src, dst);
70 template <
typename SrcConstRefP,
72 class premultiply_deref_fn
75 typedef premultiply_deref_fn const_t;
76 typedef DstP value_type;
77 typedef value_type reference;
78 typedef const value_type& const_reference;
79 typedef SrcConstRefP argument_type;
80 typedef reference result_type;
81 BOOST_STATIC_CONSTANT(
bool, is_mutable=
false);
83 result_type operator()(argument_type srcP)
const
86 premultiply()(srcP,dstP);
91 template <
typename SrcView,
typename DstP>
92 struct premultiplied_view_type
95 typedef typename SrcView::const_t::reference src_pix_ref;
96 typedef premultiply_deref_fn<src_pix_ref, DstP> deref_t;
97 typedef typename SrcView::template add_deref<deref_t> add_ref_t;
99 typedef typename add_ref_t::type type;
100 static type make(
const SrcView& sv) {
return add_ref_t::make(sv, deref_t()); }
103 template <
typename DstP,
typename View>
inline
104 typename premultiplied_view_type<View,DstP>::type premultiply_view(
const View& src)
106 return premultiplied_view_type<View,DstP>::make(src);
channel_traits< Channel >::value_type channel_multiply(Channel a, Channel b)
A function multiplying two channels. result = a * b / max_value.
Definition: channel_algorithm.hpp:488
color_element_reference_type< ColorBase, Color >::type get_color(ColorBase &cb, Color=Color())
Mutable accessor to the element associated with a given color name.
Definition: color_base_algorithm.hpp:169