8 #ifndef BOOST_GIL_PREMULTIPLY_HPP 9 #define BOOST_GIL_PREMULTIPLY_HPP 11 #include <boost/gil/rgba.hpp> 12 #include <boost/gil/detail/mp11.hpp> 14 #include <boost/core/ignore_unused.hpp> 16 #include <type_traits> 18 namespace boost {
namespace gil {
20 template <
typename SrcP,
typename DstP>
21 struct channel_premultiply
23 channel_premultiply(SrcP
const & src, DstP & dst)
24 : src_(src), dst_(dst)
27 template <
typename Channel>
28 void operator()(Channel )
const 41 template <
typename SrcP,
typename DstP>
42 void assign_alpha_if(std::true_type, SrcP
const &src, DstP &dst)
44 get_color(dst,alpha_t()) = alpha_or_max(src);
47 template <
typename SrcP,
typename DstP>
48 void assign_alpha_if(std::false_type, SrcP
const& src, DstP& dst)
51 boost::ignore_unused(src);
52 boost::ignore_unused(dst);
58 template <
typename SrcP,
typename DstP>
59 void operator()(
const SrcP& src, DstP& dst)
const 61 using src_colour_space_t =
typename color_space_type<SrcP>::type;
62 using dst_colour_space_t =
typename color_space_type<DstP>::type;
63 using src_colour_channels = mp11::mp_remove<src_colour_space_t, alpha_t>;
65 using has_alpha_t = std::integral_constant<bool, mp11::mp_contains<dst_colour_space_t, alpha_t>::value>;
66 mp11::mp_for_each<src_colour_channels>(channel_premultiply<SrcP, DstP>(src, dst));
67 detail::assign_alpha_if(has_alpha_t(), src, dst);
71 template <
typename SrcConstRefP,
73 class premultiply_deref_fn
76 using const_t = premultiply_deref_fn<SrcConstRefP, DstP>;
77 using value_type = DstP;
78 using reference = value_type;
79 using const_reference =
const value_type &;
80 using argument_type = SrcConstRefP;
81 using result_type = reference;
82 static constexpr
bool is_mutable =
false;
84 result_type operator()(argument_type srcP)
const 87 premultiply()(srcP,dstP);
92 template <
typename SrcView,
typename DstP>
93 struct premultiplied_view_type
96 using src_pix_ref =
typename SrcView::const_t::reference;
97 using deref_t = premultiply_deref_fn<src_pix_ref, DstP>;
98 using add_ref_t =
typename SrcView::template add_deref<deref_t>;
100 using type =
typename add_ref_t::type;
101 static type make(
const SrcView& sv) {
return add_ref_t::make(sv, deref_t()); }
104 template <
typename DstP,
typename View>
inline 105 typename premultiplied_view_type<View,DstP>::type premultiply_view(
const View& src)
107 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:539
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:190