Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:42:34

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 // Copyright 2021 Pranam Lashkari <plashkari628@gmail.com>
0004 //
0005 // Distributed under the Boost Software License, Version 1.0
0006 // See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt
0008 //
0009 #ifndef BOOST_GIL_PIXEL_NUMERIC_OPERATIONS_HPP
0010 #define BOOST_GIL_PIXEL_NUMERIC_OPERATIONS_HPP
0011 
0012 #include <boost/gil/color_base_algorithm.hpp>
0013 #include <boost/gil/pixel.hpp>
0014 #include <boost/gil/channel_numeric_operations.hpp>
0015 
0016 namespace boost { namespace gil {
0017 
0018 // Function objects and utilities for pixel-wise numeric operations.
0019 //
0020 // List of currently defined functors:
0021 //   pixel_plus_t (+)
0022 //   pixel_minus_t (-)
0023 //   pixel_multiplies_scalar_t (*s)
0024 //   pixel_multiplies_t (*)
0025 //   pixel_divides_scalar_t (/s)
0026 //   pixel_divides_t (/)
0027 //   pixel_halves_t (/=2),
0028 //   pixel_zeros_t (=0)
0029 //   pixel_assigns_t (=)
0030 
0031 /// \ingroup PixelNumericOperations
0032 /// \brief Performs channel-wise addition of two pixels.
0033 /// \tparam PixelRef1 - models PixelConcept
0034 /// \tparam PixelRef2 - models PixelConcept
0035 /// \tparam PixelResult - models PixelValueConcept
0036 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
0037 struct pixel_plus_t
0038 {
0039     auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
0040     {
0041         PixelResult result;
0042         static_transform(p1, p2, result,
0043             channel_plus_t
0044             <
0045                 typename channel_type<PixelRef1>::type,
0046                 typename channel_type<PixelRef2>::type,
0047                 typename channel_type<PixelResult>::type
0048             >());
0049         return result;
0050     }
0051 };
0052 
0053 /// \ingroup PixelNumericOperations
0054 /// \brief Performs channel-wise subtraction of two pixels.
0055 /// \tparam PixelRef1 - models PixelConcept
0056 /// \tparam PixelRef2 - models PixelConcept
0057 /// \tparam PixelResult - models PixelValueConcept
0058 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
0059 struct pixel_minus_t
0060 {
0061     auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
0062     {
0063         PixelResult result;
0064         static_transform(p1, p2, result,
0065             channel_minus_t
0066             <
0067                 typename channel_type<PixelRef1>::type,
0068                 typename channel_type<PixelRef2>::type,
0069                 typename channel_type<PixelResult>::type
0070             >());
0071         return result;
0072     }
0073 };
0074 
0075 /// \ingroup PixelNumericOperations
0076 /// \brief Performs channel-wise multiplication of pixel elements by scalar.
0077 /// \tparam PixelRef - models PixelConcept
0078 /// \tparam Scalar - models a scalar type
0079 /// \tparam PixelResult - models PixelValueConcept
0080 template <typename PixelRef, typename Scalar, typename PixelResult>
0081 struct pixel_multiplies_scalar_t
0082 {
0083     auto operator()(PixelRef const& p, Scalar const& s) const -> PixelResult
0084     {
0085         PixelResult result;
0086         static_transform(p, result,
0087             std::bind(
0088                 channel_multiplies_scalar_t<typename channel_type<PixelRef>::type,
0089                 Scalar,
0090                 typename channel_type<PixelResult>::type>(),
0091                 std::placeholders::_1, s));
0092         return result;
0093     }
0094 };
0095 
0096 /// \ingroup PixelNumericOperations
0097 /// \brief Performs channel-wise multiplication of two pixels.
0098 /// \tparam PixelRef1 - models PixelConcept
0099 /// \tparam PixelRef1 - models PixelConcept
0100 /// \tparam PixelResult - models PixelValueConcept
0101 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
0102 struct pixel_multiplies_t
0103 {
0104     auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
0105     {
0106         PixelResult result;
0107         static_transform(p1, p2, result,
0108             channel_multiplies_t
0109             <
0110                 typename channel_type<PixelRef1>::type,
0111                 typename channel_type<PixelRef2>::type,
0112                 typename channel_type<PixelResult>::type
0113             >());
0114         return result;
0115     }
0116 };
0117 
0118 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
0119 using pixel_multiply_t [[deprecated]] = pixel_multiplies_t<PixelRef1, PixelRef2, PixelResult>;
0120 
0121 /// \ingroup PixelNumericOperations
0122 /// \brief Performs channel-wise division of pixel elements by scalar.
0123 /// \tparam PixelRef - models PixelConcept
0124 /// \tparam Scalar - models a scalar type
0125 /// \tparam PixelResult - models PixelValueConcept
0126 template <typename PixelRef, typename Scalar, typename PixelResult>
0127 struct pixel_divides_scalar_t
0128 {
0129     auto operator()(PixelRef const& p, Scalar const& s) const -> PixelResult
0130     {
0131         PixelResult result;
0132         static_transform(p, result,
0133             std::bind(channel_divides_scalar_t<typename channel_type<PixelRef>::type,
0134                 Scalar,
0135                 typename channel_type<PixelResult>::type>(),
0136                 std::placeholders::_1, s));
0137         return result;
0138     }
0139 };
0140 
0141 /// \ingroup PixelNumericOperations
0142 /// \brief Performs channel-wise division of two pixels.
0143 /// \tparam PixelRef1 - models PixelConcept
0144 /// \tparam PixelRef2 - models PixelConcept
0145 /// \tparam PixelResult - models PixelValueConcept
0146 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
0147 struct pixel_divides_t
0148 {
0149     auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
0150     {
0151         PixelResult result;
0152         static_transform(p1, p2, result,
0153             channel_divides_t
0154             <
0155                 typename channel_type<PixelRef1>::type,
0156                 typename channel_type<PixelRef2>::type,
0157                 typename channel_type<PixelResult>::type
0158             >());
0159         return result;
0160     }
0161 };
0162 
0163 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
0164 using pixel_divide_t [[deprecated]] = pixel_divides_t<PixelRef1, PixelRef2, PixelResult>;
0165 
0166 /// \ingroup PixelNumericOperations
0167 /// \brief Performs channel-wise division by 2
0168 /// \tparam PixelRef - models PixelConcept
0169 template <typename PixelRef>
0170 struct pixel_halves_t
0171 {
0172     auto operator()(PixelRef& p) const -> PixelRef&
0173     {
0174         static_for_each(p, channel_halves_t<typename channel_type<PixelRef>::type>());
0175         return p;
0176     }
0177 };
0178 
0179 /// \ingroup PixelNumericOperations
0180 /// \brief Sets pixel elements to zero (for whatever zero means)
0181 /// \tparam PixelRef - models PixelConcept
0182 template <typename PixelRef>
0183 struct pixel_zeros_t
0184 {
0185     auto operator()(PixelRef& p) const -> PixelRef&
0186     {
0187         static_for_each(p, channel_zeros_t<typename channel_type<PixelRef>::type>());
0188         return p;
0189     }
0190 };
0191 
0192 /// \brief Sets pixel elements to zero (for whatever zero means)
0193 /// \tparam Pixel - models PixelConcept
0194 template <typename Pixel>
0195 void zero_channels(Pixel& p)
0196 {
0197     static_for_each(p, channel_zeros_t<typename channel_type<Pixel>::type>());
0198 }
0199 
0200 /// \ingroup PixelNumericOperations
0201 /// \brief Casts and assigns a pixel to another
0202 ///
0203 /// A generic implementation for casting and assigning a pixel to another.
0204 /// User should specialize it for better performance.
0205 ///
0206 /// \tparam PixelRef - models PixelConcept
0207 /// \tparam PixelResult - models PixelValueConcept
0208 template <typename PixelRef, typename PixelResult>
0209 struct pixel_assigns_t
0210 {
0211     auto operator()(PixelRef const& src, PixelResult& dst) const -> PixelResult
0212     {
0213         static_for_each(src, dst,
0214             channel_assigns_t
0215             <
0216                 typename channel_type<PixelRef>::type,
0217                 typename channel_type<PixelResult>::type
0218             >());
0219         return dst;
0220     }
0221 };
0222 
0223 }} // namespace boost::gil
0224 
0225 #endif