Boost GIL


pixel_numeric_operations.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 // Copyright 2021 Pranam Lashkari <plashkari628@gmail.com>
4 //
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8 //
9 #ifndef BOOST_GIL_PIXEL_NUMERIC_OPERATIONS_HPP
10 #define BOOST_GIL_PIXEL_NUMERIC_OPERATIONS_HPP
11 
12 #include <boost/gil/color_base_algorithm.hpp>
13 #include <boost/gil/pixel.hpp>
14 #include <boost/gil/channel_numeric_operations.hpp>
15 
16 namespace boost { namespace gil {
17 
18 // Function objects and utilities for pixel-wise numeric operations.
19 //
20 // List of currently defined functors:
21 // pixel_plus_t (+)
22 // pixel_minus_t (-)
23 // pixel_multiplies_scalar_t (*s)
24 // pixel_multiplies_t (*)
25 // pixel_divides_scalar_t (/s)
26 // pixel_divides_t (/)
27 // pixel_halves_t (/=2),
28 // pixel_zeros_t (=0)
29 // pixel_assigns_t (=)
30 
36 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
38 {
39  auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
40  {
41  PixelResult result;
42  static_transform(p1, p2, result,
44  <
48  >());
49  return result;
50  }
51 };
52 
58 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
60 {
61  auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
62  {
63  PixelResult result;
64  static_transform(p1, p2, result,
66  <
70  >());
71  return result;
72  }
73 };
74 
80 template <typename PixelRef, typename Scalar, typename PixelResult>
82 {
83  auto operator()(PixelRef const& p, Scalar const& s) const -> PixelResult
84  {
85  PixelResult result;
86  static_transform(p, result,
87  std::bind(
89  Scalar,
91  std::placeholders::_1, s));
92  return result;
93  }
94 };
95 
101 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
103 {
104  auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
105  {
106  PixelResult result;
107  static_transform(p1, p2, result,
109  <
113  >());
114  return result;
115  }
116 };
117 
118 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
120 
126 template <typename PixelRef, typename Scalar, typename PixelResult>
128 {
129  auto operator()(PixelRef const& p, Scalar const& s) const -> PixelResult
130  {
131  PixelResult result;
132  static_transform(p, result,
134  Scalar,
136  std::placeholders::_1, s));
137  return result;
138  }
139 };
140 
146 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
148 {
149  auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
150  {
151  PixelResult result;
152  static_transform(p1, p2, result,
154  <
158  >());
159  return result;
160  }
161 };
162 
163 template <typename PixelRef1, typename PixelRef2, typename PixelResult>
165 
169 template <typename PixelRef>
171 {
172  auto operator()(PixelRef& p) const -> PixelRef&
173  {
174  static_for_each(p, channel_halves_t<typename channel_type<PixelRef>::type>());
175  return p;
176  }
177 };
178 
182 template <typename PixelRef>
184 {
185  auto operator()(PixelRef& p) const -> PixelRef&
186  {
187  static_for_each(p, channel_zeros_t<typename channel_type<PixelRef>::type>());
188  return p;
189  }
190 };
191 
194 template <typename Pixel>
195 void zero_channels(Pixel& p)
196 {
197  static_for_each(p, channel_zeros_t<typename channel_type<Pixel>::type>());
198 }
199 
208 template <typename PixelRef, typename PixelResult>
210 {
211  auto operator()(PixelRef const& src, PixelResult& dst) const -> PixelResult
212  {
213  static_for_each(src, dst,
215  <
218  >());
219  return dst;
220  }
221 };
222 
223 }} // namespace boost::gil
224 
225 #endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Definition: channel_numeric_operations.hpp:236
Arithmetic operation of dividing channel value by scalar.
Definition: channel_numeric_operations.hpp:182
Arithmetic operation of division of two channel values.
Definition: channel_numeric_operations.hpp:99
Arithmetic operation of dividing channel value by 2.
Definition: channel_numeric_operations.hpp:203
Arithmetic operation of subtraction of two channel values.
Definition: channel_numeric_operations.hpp:57
Arithmetic operation of channel value by a scalar.
Definition: channel_numeric_operations.hpp:161
Arithmetic operation of multiplication of two channel values.
Definition: channel_numeric_operations.hpp:78
Arithmetic operation of addition of two channel values.
Definition: channel_numeric_operations.hpp:36
Definition: color_convert.hpp:31
Operation of setting channel value to zero.
Definition: channel_numeric_operations.hpp:221
Casts and assigns a pixel to another.
Definition: pixel_numeric_operations.hpp:210
Performs channel-wise division of pixel elements by scalar.
Definition: pixel_numeric_operations.hpp:128
Performs channel-wise division of two pixels.
Definition: pixel_numeric_operations.hpp:148
Performs channel-wise division by 2.
Definition: pixel_numeric_operations.hpp:171
Performs channel-wise subtraction of two pixels.
Definition: pixel_numeric_operations.hpp:60
Performs channel-wise multiplication of pixel elements by scalar.
Definition: pixel_numeric_operations.hpp:82
Performs channel-wise multiplication of two pixels.
Definition: pixel_numeric_operations.hpp:103
Performs channel-wise addition of two pixels.
Definition: pixel_numeric_operations.hpp:38
Sets pixel elements to zero (for whatever zero means)
Definition: pixel_numeric_operations.hpp:184