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 )
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 using src_colour_space_t =
typename color_space_type<SrcP>::type;
61 using dst_colour_space_t =
typename color_space_type<DstP>::type;
62 using src_colour_channels =
typename mpl::remove <src_colour_space_t, alpha_t>::type;
64 using has_alpha_t = mpl::bool_<mpl::contains<dst_colour_space_t, alpha_t>::value>;
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 using const_t = premultiply_deref_fn<SrcConstRefP, DstP>;
76 using value_type = DstP;
77 using reference = value_type;
78 using const_reference =
const value_type &;
79 using argument_type = SrcConstRefP;
80 using result_type = reference;
81 static constexpr
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 using src_pix_ref =
typename SrcView::const_t::reference;
96 using deref_t = premultiply_deref_fn<src_pix_ref, DstP>;
97 using add_ref_t =
typename SrcView::template add_deref<deref_t>;
99 using type =
typename add_ref_t::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);
Definition: algorithm.hpp:30
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:485
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:193