IDS peak IPL v1.18.0
Loading...
Searching...
No Matches
peak_ipl_binning.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
13
18
19namespace peak
20{
21namespace ipl
22{
23
38class Binning final
39{
40public:
54
61 Binning();
62
69 ~Binning();
70
82 Binning(const Binning& other);
83
95 Binning& operator=(const Binning& other);
96
105 Binning(Binning&& other) noexcept;
106
115 Binning& operator=(Binning&& other) noexcept;
116
126 void SetBinningX(uint8_t value);
127
135 PEAK_IPL_NO_DISCARD uint8_t BinningX() const;
136
146 void SetBinningY(uint8_t value);
147
155 PEAK_IPL_NO_DISCARD uint8_t BinningY() const;
156
164 PEAK_IPL_NO_DISCARD uint8_t BinningMin() const;
165
173 PEAK_IPL_NO_DISCARD uint8_t BinningMax() const;
174
188
198 void SetMode(BinningMode mode);
199
208
219
233 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
234
235private:
236 PEAK_IPL_BINNING_HANDLE m_backendHandle{};
237};
238
240{
242}
243
245{
246 if (m_backendHandle)
247 {
249 }
250}
251
252inline Binning::Binning(const Binning& other)
253{
254 if (other.m_backendHandle)
255 {
256 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Acquire(other.m_backendHandle); });
257 }
258
259 m_backendHandle = other.m_backendHandle;
260}
261
262inline Binning& Binning::operator=(const Binning& other)
263{
264 if (this != &other)
265 {
266 if (m_backendHandle)
267 {
269 }
270
271 if (other.m_backendHandle)
272 {
274 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Acquire(other.m_backendHandle); });
275 }
276 }
277
278 m_backendHandle = other.m_backendHandle;
279
280 return *this;
281}
282
283inline Binning::Binning(Binning&& other) noexcept
284{
285 *this = std::move(other);
286}
287
288inline Binning& Binning::operator=(Binning&& other) noexcept
289{
290 if (this != &other)
291 {
292 if (m_backendHandle != nullptr)
293 {
295 }
296
297 m_backendHandle = other.m_backendHandle;
298 other.m_backendHandle = nullptr;
299 }
300
301 return *this;
302}
303
304inline void Binning::SetBinningX(uint8_t value)
305{
306 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_SetBinningX(m_backendHandle, &value); });
307}
308
309inline void Binning::SetBinningY(uint8_t value)
310{
311 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_SetBinningY(m_backendHandle, &value); });
312}
313
314inline uint8_t Binning::BinningX() const
315{
316 uint8_t value;
317
318 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningX(m_backendHandle, &value); });
319
320 return value;
321}
322
323inline uint8_t Binning::BinningY() const
324{
325 uint8_t value;
326
327 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningY(m_backendHandle, &value); });
328
329 return value;
330}
331
332inline uint8_t Binning::BinningMin() const
333{
334 uint8_t value;
335
337 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningMin(m_backendHandle, &value); });
338
339 return value;
340}
341
342inline uint8_t Binning::BinningMax() const
343{
344 uint8_t value;
345
347 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningMax(m_backendHandle, &value); });
348
349 return value;
350}
351
352inline Size2D Binning::ExpectedOutputSize(Size2D inputSize, PixelFormatName pixelFormat) const
353{
354 Size2D size{};
356 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_ExpectedOutputSize(m_backendHandle, &size.width, &size.height,
357 inputSize.width, inputSize.height, static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormat));
358 });
359
360 return size;
361}
362
363inline bool Binning::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
364{
365 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
366
369 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
370 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
371 });
372
373 return isPixelFormatSupported > 0;
374}
375
376inline Image Binning::Process(const Image& inputImage) const
377{
378 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
381 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
382 });
383
384 return ImageBackendAccessor::CreateImage(outputImageHandle);
385}
386
388{
391 m_backendHandle, reinterpret_cast<PEAK_IPL_BINNINGMODE*>(&mode));
392 });
393}
394
396{
397 BinningMode value;
398
401 m_backendHandle, reinterpret_cast<PEAK_IPL_BINNINGMODE*>(&value));
402 });
403
404 return value;
405}
406
407
408} /* namespace ipl */
409} /* namespace peak */
Performs spatial binning on 2D images.
Definition peak_ipl_binning.hpp:39
~Binning()
Destructor for the Binning instance.
Definition peak_ipl_binning.hpp:244
Size2D ExpectedOutputSize(Size2D inputSize, PixelFormatName pixelFormat) const
Returns the size of a binned image given the input size and pixelformat.
Definition peak_ipl_binning.hpp:352
uint8_t BinningMax() const
Returns the maximum value for the binning.
Definition peak_ipl_binning.hpp:342
Image Process(const Image &inputImage) const
Applies the binning on the given image.
Definition peak_ipl_binning.hpp:376
uint8_t BinningY() const
Returns the value of the binning in vertical direction.
Definition peak_ipl_binning.hpp:323
Binning()
Constructor for a new Binning instance.
Definition peak_ipl_binning.hpp:239
BinningMode Mode() const
Returns the value of the binning mode.
Definition peak_ipl_binning.hpp:395
void SetBinningX(uint8_t value)
Sets the values of the binning in horizontal direction.
Definition peak_ipl_binning.hpp:304
void SetMode(BinningMode mode)
Sets the values of the binning mode.
Definition peak_ipl_binning.hpp:387
void SetBinningY(uint8_t value)
Sets the values of the binning in vertical direction.
Definition peak_ipl_binning.hpp:309
Binning & operator=(const Binning &other)
Copy assigment for Binning instance.
Definition peak_ipl_binning.hpp:262
uint8_t BinningX() const
Returns the value of the binning in horizontal direction.
Definition peak_ipl_binning.hpp:314
uint8_t BinningMin() const
Returns the minimum value for the binning.
Definition peak_ipl_binning.hpp:332
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the binning supports the given pixel format.
Definition peak_ipl_binning.hpp:363
BinningMode
Mode parameter for the binning algorithm.
Definition peak_ipl_binning.hpp:47
@ Sum
Sum of pixels.
Definition peak_ipl_binning.hpp:52
@ Average
Average (mean) of pixels.
Definition peak_ipl_binning.hpp:49
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:42
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:38
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:284
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:20
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningY(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningYValue)
Returns the value of binning in vertical direction.
PEAK_IPL_C_API PEAK_IPL_Binning_SetBinningMode(PEAK_IPL_BINNING_HANDLE binningHandle, PEAK_IPL_BINNINGMODE *mode)
Sets the value of binning mode.
PEAK_IPL_C_API PEAK_IPL_Binning_IsPixelformatSupported(PEAK_IPL_BINNING_HANDLE binningHandle, PEAK_IPL_PIXEL_FORMAT pixelFormat, PEAK_IPL_BOOL8 *isPixelFormatSupported)
Asks the given binning whether it supports the given pixel format.
PEAK_IPL_C_API PEAK_IPL_Binning_ExpectedOutputSize(PEAK_IPL_BINNING_HANDLE binningHandle, size_t *outputWidth, size_t *outputHeight, size_t inputWidth, size_t inputHeight, PEAK_IPL_PIXEL_FORMAT pixelFormat)
Returns the size of a binned image given the input size and pixelformat.
PEAK_IPL_C_API PEAK_IPL_Binning_Acquire(PEAK_IPL_BINNING_HANDLE binningHandle)
Increase the reference count of a binning object.
PEAK_IPL_C_API PEAK_IPL_Binning_SetBinningY(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningYValue)
Sets the value of binning in vertical direction.
PEAK_IPL_C_API PEAK_IPL_Binning_Process(PEAK_IPL_BINNING_HANDLE binningHandle, PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Apply the binning on the given image.
@ PEAK_IPL_BINNINGMODE_SUM
Definition peak_ipl_backend.h:225
@ PEAK_IPL_BINNINGMODE_AVERAGE
Definition peak_ipl_backend.h:224
uint16_t PEAK_IPL_BINNINGMODE
Definition peak_ipl_backend.h:227
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningMax(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningMax)
Returns the maximum binning value which can be set.
PEAK_IPL_C_API PEAK_IPL_Binning_SetBinningX(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningXValue)
Sets the value of binning in horizontal direction.
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningMode(PEAK_IPL_BINNING_HANDLE binningHandle, PEAK_IPL_BINNINGMODE *mode)
Returns the value of binning mode.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition peak_ipl_backend.h:402
PEAK_IPL_C_API PEAK_IPL_Binning_Destruct(PEAK_IPL_BINNING_HANDLE binningHandle)
Destroys the binning associated with the given handle.
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningMin(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningMin)
Returns the minimum binning value which can be set.
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningX(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningXValue)
Returns the value of binning in horizontal direction.
int8_t PEAK_IPL_BOOL8
Definition peak_ipl_backend.h:23
PEAK_IPL_C_API PEAK_IPL_Binning_Construct(PEAK_IPL_BINNING_HANDLE *binningHandle)
Creates a binning.
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:170
struct PEAK_IPL_BINNING * PEAK_IPL_BINNING_HANDLE
Definition peak_ipl_backend.h:382
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:11
2D size of an image.
Definition peak_ipl_simple_types.hpp:220
size_t height
Height of size.
Definition peak_ipl_simple_types.hpp:222
size_t width
Width of size.
Definition peak_ipl_simple_types.hpp:221