// // Copyright 2005-2007 Adobe Systems Incorporated // // 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_EXTENSION_NUMERIC_PIXEL_NUMERIC_OPERATIONS_HPP #define BOOST_GIL_EXTENSION_NUMERIC_PIXEL_NUMERIC_OPERATIONS_HPP #include #include #include namespace boost { namespace gil { // Structures for pixel-wise numeric operations // Currently defined structures: // pixel_plus_t (+), pixel_minus_t (-) // pixel_multiplies_scalar_t (*), pixel_divides_scalar_t (/) // pixel_halves_t (/=2), pixel_zeros_t (=0) // pixel_assigns_t (=) /// \ingroup PixelNumericOperations /// \brief construct for adding two pixels template // models pixel value concept struct pixel_plus_t { PixelR operator() (const PixelRef1& p1, const PixelRef2& p2) const { PixelR result; static_transform(p1,p2,result, channel_plus_t::type, typename channel_type::type, typename channel_type::type>()); return result; } }; /// \ingroup PixelNumericOperations /// \brief construct for subtracting two pixels template // models pixel value concept struct pixel_minus_t { PixelR operator() (const PixelRef1& p1, const PixelRef2& p2) const { PixelR result; static_transform(p1,p2,result, channel_minus_t::type, typename channel_type::type, typename channel_type::type>()); return result; } }; /// \ingroup PixelNumericOperations /// \brief construct for multiplying scalar to a pixel template // models pixel value concept struct pixel_multiplies_scalar_t { PixelR operator () (const PixelRef& p, const Scalar& s) const { PixelR result; static_transform(p,result, std::bind(channel_multiplies_scalar_t::type, Scalar, typename channel_type::type>(), std::placeholders::_1, s)); return result; } }; /// \ingroup PixelNumericOperations /// \brief construct for dividing two pixels template // models pixel value concept struct pixel_multiply_t { PixelR operator() (const PixelRef1& p1, const PixelRef2& p2) const { PixelR result; static_transform(p1,p2,result, channel_multiplies_t::type, typename channel_type::type, typename channel_type::type>()); return result; } }; /// \ingroup PixelNumericOperations /// \brief construct for dividing a pixel by a scalar template // models pixel value concept struct pixel_divides_scalar_t { PixelR operator () (const PixelRef& p, const Scalar& s) const { PixelR result; static_transform(p,result, std::bind(channel_divides_scalar_t::type, Scalar, typename channel_type::type>(), std::placeholders::_1, s)); return result; } }; /// \ingroup PixelNumericOperations /// \brief construct for dividing two pixels template // models pixel value concept struct pixel_divide_t { PixelR operator() (const PixelRef1& p1, const PixelRef2& p2) const { PixelR result; static_transform(p1,p2,result, channel_divides_t::type, typename channel_type::type, typename channel_type::type>()); return result; } }; /// \ingroup PixelNumericOperations /// \brief construct for dividing a pixel by 2 template // models pixel concept struct pixel_halves_t { PixelRef& operator () (PixelRef& p) const { static_for_each(p,channel_halves_t::type>()); return p; } }; /// \ingroup PixelNumericOperations /// \brief construct for setting a pixel to zero (for whatever zero means) template // models pixel concept struct pixel_zeros_t { PixelRef& operator () (PixelRef& p) const { static_for_each(p,channel_zeros_t::type>()); return p; } }; // Hailin: This is how you can do it: template void zero_channels(Pixel& p) { static_for_each(p,channel_zeros_t::type>()); } /// \ingroup PixelNumericOperations ///definition and a generic implementation for casting and assigning a pixel to another ///user should specialize it for better performance template // models pixel concept struct pixel_assigns_t { PixelRefR operator () (const PixelRef& src, PixelRefR& dst) const { static_for_each(src,dst,channel_assigns_t::type, typename channel_type::type>()); return dst; } }; }} // namespace boost::gil #endif