10 #ifndef BOOST_GIL_PREMULTIPLY_HPP
11 #define BOOST_GIL_PREMULTIPLY_HPP
16 #include <boost/mpl/remove.hpp>
18 namespace boost {
namespace gil {
20 template <
typename SrcP,
typename DstP>
21 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 {
38 template <
typename SrcP,
typename DstP>
39 void assign_alpha_if(mpl::true_, SrcP
const &src, DstP &dst)
41 get_color (dst,alpha_t()) = alpha_or_max (src);
44 template <
typename SrcP,
typename DstP>
45 void assign_alpha_if(mpl::false_, SrcP
const &src, DstP &dst)
52 template <
typename SrcP,
typename DstP>
53 void operator()(
const SrcP& src, DstP& dst)
const {
54 typedef typename color_space_type<SrcP>::type src_colour_space_t;
55 typedef typename color_space_type<DstP>::type dst_colour_space_t;
56 typedef typename mpl:: remove <src_colour_space_t, alpha_t>:: type src_colour_channels;
58 typedef mpl::bool_<mpl::contains<dst_colour_space_t, alpha_t>::value> has_alpha_t;
59 mpl:: for_each <src_colour_channels> ( channel_premultiply <SrcP, DstP> (src, dst) );
60 detail::assign_alpha_if(has_alpha_t(), src, dst);
64 template <
typename SrcConstRefP,
66 class premultiply_deref_fn {
68 typedef premultiply_deref_fn const_t;
69 typedef DstP value_type;
70 typedef value_type reference;
71 typedef const value_type& const_reference;
72 typedef SrcConstRefP argument_type;
73 typedef reference result_type;
74 BOOST_STATIC_CONSTANT(
bool, is_mutable=
false);
76 result_type operator()(argument_type srcP)
const {
78 premultiply () (srcP,dstP);
83 template <
typename SrcView,
typename DstP>
84 struct premultiplied_view_type {
86 typedef typename SrcView::const_t::reference src_pix_ref;
87 typedef premultiply_deref_fn<src_pix_ref, DstP> deref_t;
88 typedef typename SrcView::template add_deref<deref_t> add_ref_t;
90 typedef typename add_ref_t::type type;
91 static type make(
const SrcView& sv) {
return add_ref_t::make(sv, deref_t()); }
94 template <
typename DstP,
typename View>
inline
95 typename premultiplied_view_type<View,DstP>::type premultiply_view(
const View& src) {
96 return premultiplied_view_type<View,DstP>::make(src);
102 #endif // BOOST_GIL_PREMULTIPLY_HPP
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:510
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:185
Support for RGBA color space and variants.