summaryrefslogtreecommitdiff
path: root/boost/gil/premultiply.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/gil/premultiply.hpp')
-rw-r--r--boost/gil/premultiply.hpp117
1 files changed, 63 insertions, 54 deletions
diff --git a/boost/gil/premultiply.hpp b/boost/gil/premultiply.hpp
index eb865d3af1..e7fb315c65 100644
--- a/boost/gil/premultiply.hpp
+++ b/boost/gil/premultiply.hpp
@@ -1,69 +1,76 @@
-/*
- Copyright 2014
- Use, modification and distribution are subject to the Boost Software License,
- Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt).
-*/
-
-/*************************************************************************************************/
-
+//
+// Copyright 2014 Bill Gallafent
+//
+// Distributed under the Boost Software License, Version 1.0
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
#ifndef BOOST_GIL_PREMULTIPLY_HPP
#define BOOST_GIL_PREMULTIPLY_HPP
-#include <iostream>
-
#include <boost/gil/rgba.hpp>
+
+#include <boost/core/ignore_unused.hpp>
+#include <boost/mpl/for_each.hpp>
#include <boost/mpl/remove.hpp>
namespace boost { namespace gil {
template <typename SrcP, typename DstP>
-struct channel_premultiply {
- channel_premultiply (SrcP const & src, DstP & dst)
- : src_ (src), dst_ (dst)
- {}
-
- template <typename Channel>
- void operator () (Channel c) const {
- // @todo: need to do a “channel_convert” too, in case the channel types aren't the same?
- get_color (dst_, Channel()) = channel_multiply(get_color(src_,Channel()), alpha_or_max(src_));
- }
- SrcP const & src_;
- DstP & dst_;
-};
+struct channel_premultiply
+{
+ channel_premultiply(SrcP const & src, DstP & dst)
+ : src_(src), dst_(dst)
+ {}
+
+ template <typename Channel>
+ void operator()(Channel c) const
+ {
+ // FIXME: Is c input paramater not used intentionally? Add comment on relation between src_ vs c.
+ // @todo: need to do a “channel_convert” too, in case the channel types aren't the same?
+ get_color(dst_, Channel()) = channel_multiply(get_color(src_,Channel()), alpha_or_max(src_));
+ }
+ SrcP const & src_;
+ DstP & dst_;
+};
namespace detail
{
- template <typename SrcP, typename DstP>
- void assign_alpha_if(mpl::true_, SrcP const &src, DstP &dst)
- {
- get_color (dst,alpha_t()) = alpha_or_max (src);
- };
-
- template <typename SrcP, typename DstP>
- void assign_alpha_if(mpl::false_, SrcP const &src, DstP &dst)
- {
- // nothing to do
- };
+ template <typename SrcP, typename DstP>
+ void assign_alpha_if(mpl::true_, SrcP const &src, DstP &dst)
+ {
+ get_color(dst,alpha_t()) = alpha_or_max(src);
+ }
+
+ template <typename SrcP, typename DstP>
+ void assign_alpha_if(mpl::false_, SrcP const& src, DstP& dst)
+ {
+ // nothing to do
+ boost::ignore_unused(src);
+ boost::ignore_unused(dst);
+ }
}
-struct premultiply {
- template <typename SrcP, typename DstP>
- void operator()(const SrcP& src, DstP& dst) const {
- typedef typename color_space_type<SrcP>::type src_colour_space_t;
- typedef typename color_space_type<DstP>::type dst_colour_space_t;
- typedef typename mpl:: remove <src_colour_space_t, alpha_t>:: type src_colour_channels;
-
- typedef mpl::bool_<mpl::contains<dst_colour_space_t, alpha_t>::value> has_alpha_t;
- mpl:: for_each <src_colour_channels> ( channel_premultiply <SrcP, DstP> (src, dst) );
- detail::assign_alpha_if(has_alpha_t(), src, dst);
- }
+struct premultiply
+{
+ template <typename SrcP, typename DstP>
+ void operator()(const SrcP& src, DstP& dst) const
+ {
+ typedef typename color_space_type<SrcP>::type src_colour_space_t;
+ typedef typename color_space_type<DstP>::type dst_colour_space_t;
+ typedef typename mpl::remove <src_colour_space_t, alpha_t>::type src_colour_channels;
+
+ typedef mpl::bool_<mpl::contains<dst_colour_space_t, alpha_t>::value> has_alpha_t;
+ mpl::for_each<src_colour_channels>(channel_premultiply<SrcP, DstP>(src, dst));
+ detail::assign_alpha_if(has_alpha_t(), src, dst);
+ }
};
template <typename SrcConstRefP, // const reference to the source pixel
typename DstP> // Destination pixel value (models PixelValueConcept)
-class premultiply_deref_fn {
+class premultiply_deref_fn
+{
public:
typedef premultiply_deref_fn const_t;
typedef DstP value_type;
@@ -73,15 +80,17 @@ public:
typedef reference result_type;
BOOST_STATIC_CONSTANT(bool, is_mutable=false);
- result_type operator()(argument_type srcP) const {
+ result_type operator()(argument_type srcP) const
+ {
result_type dstP;
- premultiply () (srcP,dstP);
+ premultiply()(srcP,dstP);
return dstP;
}
};
template <typename SrcView, typename DstP>
-struct premultiplied_view_type {
+struct premultiplied_view_type
+{
private:
typedef typename SrcView::const_t::reference src_pix_ref; // const reference to pixel in SrcView
typedef premultiply_deref_fn<src_pix_ref, DstP> deref_t; // the dereference adaptor that performs color conversion
@@ -92,11 +101,11 @@ public:
};
template <typename DstP, typename View> inline
-typename premultiplied_view_type<View,DstP>::type premultiply_view(const View& src) {
+typename premultiplied_view_type<View,DstP>::type premultiply_view(const View& src)
+{
return premultiplied_view_type<View,DstP>::make(src);
}
- }
-}
+}} // namespace boost::gil
-#endif // BOOST_GIL_PREMULTIPLY_HPP
+#endif