Generic Image Library: pixel_numeric_operations.hpp Source File

###  | #  |

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
16namespace 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
36template <typename PixelRef1, typename PixelRef2, typename PixelResult>
37 struct pixel_plus_t
38{
39 auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
40 {
41 PixelResult result;
42 static_transform(p1, p2, result,
43 channel_plus_t
44 <
45 typename channel_type<PixelRef1>::type,
46 typename channel_type<PixelRef2>::type,
47 typename channel_type<PixelResult>::type
48 >());
49 return result;
50 }
51};
52
58template <typename PixelRef1, typename PixelRef2, typename PixelResult>
59 struct pixel_minus_t
60{
61 auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
62 {
63 PixelResult result;
64 static_transform(p1, p2, result,
65 channel_minus_t
66 <
67 typename channel_type<PixelRef1>::type,
68 typename channel_type<PixelRef2>::type,
69 typename channel_type<PixelResult>::type
70 >());
71 return result;
72 }
73};
74
80template <typename PixelRef, typename Scalar, typename PixelResult>
81 struct pixel_multiplies_scalar_t
82{
83 auto operator()(PixelRef const& p, Scalar const& s) const -> PixelResult
84 {
85 PixelResult result;
86 static_transform(p, result,
87 std::bind(
88 channel_multiplies_scalar_t<typename channel_type<PixelRef>::type,
89 Scalar,
90 typename channel_type<PixelResult>::type>(),
91 std::placeholders::_1, s));
92 return result;
93 }
94};
95
101template <typename PixelRef1, typename PixelRef2, typename PixelResult>
102 struct pixel_multiplies_t
103{
104 auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
105 {
106 PixelResult result;
107 static_transform(p1, p2, result,
108 channel_multiplies_t
109 <
110 typename channel_type<PixelRef1>::type,
111 typename channel_type<PixelRef2>::type,
112 typename channel_type<PixelResult>::type
113 >());
114 return result;
115 }
116};
117
118template <typename PixelRef1, typename PixelRef2, typename PixelResult>
119using pixel_multiply_t [[deprecated]] = pixel_multiplies_t<PixelRef1, PixelRef2, PixelResult>;
120
126template <typename PixelRef, typename Scalar, typename PixelResult>
127 struct pixel_divides_scalar_t
128{
129 auto operator()(PixelRef const& p, Scalar const& s) const -> PixelResult
130 {
131 PixelResult result;
132 static_transform(p, result,
133 std::bind(channel_divides_scalar_t<typename channel_type<PixelRef>::type,
134 Scalar,
135 typename channel_type<PixelResult>::type>(),
136 std::placeholders::_1, s));
137 return result;
138 }
139};
140
146template <typename PixelRef1, typename PixelRef2, typename PixelResult>
147 struct pixel_divides_t
148{
149 auto operator()(PixelRef1 const& p1, PixelRef2 const& p2) const -> PixelResult
150 {
151 PixelResult result;
152 static_transform(p1, p2, result,
153 channel_divides_t
154 <
155 typename channel_type<PixelRef1>::type,
156 typename channel_type<PixelRef2>::type,
157 typename channel_type<PixelResult>::type
158 >());
159 return result;
160 }
161};
162
163template <typename PixelRef1, typename PixelRef2, typename PixelResult>
164using pixel_divide_t [[deprecated]] = pixel_divides_t<PixelRef1, PixelRef2, PixelResult>;
165
169template <typename PixelRef>
170 struct pixel_halves_t
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
182template <typename PixelRef>
183 struct pixel_zeros_t
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
194template <typename Pixel>
195void zero_channels(Pixel& p)
196{
197 static_for_each(p, channel_zeros_t<typename channel_type<Pixel>::type>());
198}
199
208template <typename PixelRef, typename PixelResult>
209 struct pixel_assigns_t
210{
211 auto operator()(PixelRef const& src, PixelResult& dst) const -> PixelResult
212 {
213 static_for_each(src, dst,
214 channel_assigns_t
215 <
216 typename channel_type<PixelRef>::type,
217 typename channel_type<PixelResult>::type
218 >());
219 return dst;
220 }
221};
222
223}} // namespace boost::gil
224
225#endif
boost
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
boost::gil::channel_assigns_t
Definition channel_numeric_operations.hpp:236
boost::gil::channel_divides_scalar_t
Arithmetic operation of dividing channel value by scalar.
Definition channel_numeric_operations.hpp:182
boost::gil::channel_divides_t
Arithmetic operation of division of two channel values.
Definition channel_numeric_operations.hpp:99
boost::gil::channel_halves_t
Arithmetic operation of dividing channel value by 2.
Definition channel_numeric_operations.hpp:203
boost::gil::channel_minus_t
Arithmetic operation of subtraction of two channel values.
Definition channel_numeric_operations.hpp:57
boost::gil::channel_multiplies_scalar_t
Arithmetic operation of channel value by a scalar.
Definition channel_numeric_operations.hpp:161
boost::gil::channel_multiplies_t
Arithmetic operation of multiplication of two channel values.
Definition channel_numeric_operations.hpp:78
boost::gil::channel_plus_t
Arithmetic operation of addition of two channel values.
Definition channel_numeric_operations.hpp:36
boost::gil::channel_type
Definition fwd.hpp:25
boost::gil::channel_zeros_t
Operation of setting channel value to zero.
Definition channel_numeric_operations.hpp:221
boost::gil::pixel_assigns_t
Casts and assigns a pixel to another.
Definition pixel_numeric_operations.hpp:210
boost::gil::pixel_divides_scalar_t
Performs channel-wise division of pixel elements by scalar.
Definition pixel_numeric_operations.hpp:128
boost::gil::pixel_divides_t
Performs channel-wise division of two pixels.
Definition pixel_numeric_operations.hpp:148
boost::gil::pixel_halves_t
Performs channel-wise division by 2.
Definition pixel_numeric_operations.hpp:171
boost::gil::pixel_minus_t
Performs channel-wise subtraction of two pixels.
Definition pixel_numeric_operations.hpp:60
boost::gil::pixel_multiplies_scalar_t
Performs channel-wise multiplication of pixel elements by scalar.
Definition pixel_numeric_operations.hpp:82
boost::gil::pixel_multiplies_t
Performs channel-wise multiplication of two pixels.
Definition pixel_numeric_operations.hpp:103
boost::gil::pixel_plus_t
Performs channel-wise addition of two pixels.
Definition pixel_numeric_operations.hpp:38
boost::gil::pixel_zeros_t
Sets pixel elements to zero (for whatever zero means)
Definition pixel_numeric_operations.hpp:184