CVB++ 15.0
bitwise.hpp
1#pragma once
2
3#if defined _WIN32
4
5# include "../_cexports/c_foundation.h"
6
7# include "../global.hpp"
8# include "../image.hpp"
9# include "../exception.hpp"
10
11# include <vector>
12# include <memory>
13
14namespace Cvb
15{
16 CVB_BEGIN_INLINE_NS
17
18 namespace Foundation
19 {
20
22
26 namespace Bitwise
27 {
28
30
40 inline std::unique_ptr<Image> And(const Image &image1, const Image &image2)
41 {
42 return Internal::DoResCallObjectOut<Image>(
43 [&](void *&resimg) { return CVB_CALL_CAPI(AndImages(image1.Handle(), image2.Handle(), resimg)); });
44 }
45
47
54 template <class RANGE>
55 inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type And(const Image &image, const RANGE &values)
56 {
57 if (std::distance(std::begin(values), std::end(values)) < image.PlanesCount())
58 {
59 throw std::logic_error("insufficient number of bitwise operation values");
60 }
61
62 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
63 /* Note: To ensure platform independence, the input range must be converted to expected underlying type. */
64 std::vector<CExports::cvbval_t> values_conv(std::begin(values), std::end(values));
65 return CVB_CALL_CAPI(AndConstant(image.Handle(), values_conv.data(), resimg));
66 });
67 }
68
70
77 inline std::unique_ptr<Image> And(const Image &image, int value)
78 {
79 return And(image, std::vector<int>(image.PlanesCount(), value));
80 }
81
83
93 inline std::unique_ptr<Image> Or(const Image &image1, const Image &image2)
94 {
95 return Internal::DoResCallObjectOut<Image>(
96 [&](void *&resimg) { return CVB_CALL_CAPI(OrImages(image1.Handle(), image2.Handle(), resimg)); });
97 }
98
100
107 template <class RANGE>
108 inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type Or(const Image &image, const RANGE &values)
109 {
110 if (std::distance(std::begin(values), std::end(values)) < image.PlanesCount())
111 {
112 throw std::logic_error("insufficient number of bitwise operation values");
113 }
114
115 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
116 /* Note: To ensure platform independence, the input vector must be converted to expected underlying type. */
117 std::vector<CExports::cvbval_t> values_conv(std::begin(values), std::end(values));
118 return CVB_CALL_CAPI(OrConstant(image.Handle(), values_conv.data(), resimg));
119 });
120 }
121
123
130 inline std::unique_ptr<Image> Or(const Image &image, int value)
131 {
132 return Or(image, std::vector<int>(image.PlanesCount(), value));
133 }
134
136
146 inline std::unique_ptr<Image> Xor(const Image &image1, const Image &image2)
147 {
148 return Internal::DoResCallObjectOut<Image>(
149 [&](void *&resimg) { return CVB_CALL_CAPI(XorImages(image1.Handle(), image2.Handle(), resimg)); });
150 }
151
153
160 template <class RANGE>
161 inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type Xor(const Image &image, const RANGE &values)
162 {
163 if (std::distance(std::begin(values), std::end(values)) < image.PlanesCount())
164 {
165 throw std::logic_error("insufficient number of bitwise operation values");
166 }
167
168 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
169 /* Note: To ensure platform independence, the input vector must be converted to expected underlying type. */
170 std::vector<CExports::cvbval_t> values_conv(std::begin(values), std::end(values));
171 return CVB_CALL_CAPI(XorConstant(image.Handle(), values_conv.data(), resimg));
172 });
173 }
174
176
183 inline std::unique_ptr<Image> Xor(const Image &image, int value)
184 {
185 return Xor(image, std::vector<int>(image.PlanesCount(), value));
186 }
187
189
196 {
197 return Internal::DoResCallObjectOut<Image>(
198 [&](void *&resimg) { return CVB_CALL_CAPI(NegateImage(image.Handle(), resimg)); });
199 }
200
202
209 template <class RANGE>
210 inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type UpShift(const Image &image,
211 const RANGE &values)
212 {
213 if (std::distance(std::begin(values), std::end(values)) < image.PlanesCount())
214 {
215 throw std::logic_error("insufficient number of bitwise operation values");
216 }
217
218 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
219 /* Note: To ensure platform independence, the input vector must be converted to expected underlying type. */
220 std::vector<CExports::cvbval_t> values_conv(std::begin(values), std::end(values));
221 return CVB_CALL_CAPI(UpShift(image.Handle(), values_conv.data(), resimg));
222 });
223 }
224
226
233 inline std::unique_ptr<Image> UpShift(const Image &image, int value)
234 {
235 return UpShift(image, std::vector<int>(image.PlanesCount(), value));
236 }
237
239
246 template <class RANGE>
247 inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type DownShift(const Image &image,
248 const RANGE &values)
249 {
250 if (std::distance(std::begin(values), std::end(values)) < image.PlanesCount())
251 {
252 throw std::logic_error("insufficient number of bitwise operation values");
253 }
254
255 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
256 /* Note: To ensure platform independence, the input vector must be converted to expected underlying type. */
257 std::vector<CExports::cvbval_t> values_conv(std::begin(values), std::end(values));
258 return CVB_CALL_CAPI(DownShift(image.Handle(), values_conv.data(), resimg));
259 });
260 }
261
263
270 inline std::unique_ptr<Image> DownShift(const Image &image, int value)
271 {
272 return DownShift(image, std::vector<int>(image.PlanesCount(), value));
273 }
274
275 } /* namespace Bitwise */
276
277 using Bitwise::And;
278 using Bitwise::DownShift;
279 using Bitwise::Negate;
280 using Bitwise::Or;
281 using Bitwise::UpShift;
282 using Bitwise::Xor;
283
284 } /* namespace Foundation */
285 CVB_END_INLINE_NS
286} /* namespace Cvb */
287
288#endif
T begin(T... args)
The Common Vision Blox image.
Definition decl_image.hpp:50
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition decl_image.hpp:247
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
T distance(T... args)
T end(T... args)
cvbres_t AndImages(IMG ImgIn1, IMG ImgIn2, IMG &ImgOut)
cvbres_t XorConstant(IMG ImgIn, long Values[], IMG &ImgOut)
cvbres_t OrImages(IMG ImgIn1, IMG ImgIn2, IMG &ImgOut)
cvbres_t OrConstant(IMG ImgIn, long Values[], IMG &ImgOut)
cvbres_t XorImages(IMG ImgIn1, IMG ImgIn2, IMG &ImgOut)
cvbres_t NegateImage(IMG ImgIn, IMG &ImgOut)
cvbres_t AndConstant(IMG ImgIn, long Values[], IMG &ImgOut)
Namespace for collection of bitwise image functions from the Foundation package.
Definition bitwise.hpp:27
TypedRange< std::unique_ptr< Image >, int, RANGE >::type UpShift(const Image &image, const RANGE &values)
Bit-wise shift the input image with constant values.
Definition bitwise.hpp:210
std::unique_ptr< Image > Or(const Image &image1, const Image &image2)
Performs a bit-wise OR operation between the pixels of the two input images.
Definition bitwise.hpp:93
std::unique_ptr< Image > Xor(const Image &image1, const Image &image2)
Performs a bit-wise XOR operation between the pixels of the two input images.
Definition bitwise.hpp:146
TypedRange< std::unique_ptr< Image >, int, RANGE >::type DownShift(const Image &image, const RANGE &values)
Bit-wise shift the input image with constant values.
Definition bitwise.hpp:247
std::unique_ptr< Image > Negate(const Image &image)
Performs a bit-wise NOT operation on the pixels of the input image to create the output image.
Definition bitwise.hpp:195
std::unique_ptr< Image > And(const Image &image1, const Image &image2)
Performs a bit-wise AND operation between the pixels of the two input images.
Definition bitwise.hpp:40
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17