IDS peak IPL  v1.9.2
peak_ipl_binning.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
18 
22 namespace peak
23 {
24 namespace ipl
25 {
26 
27 class Binning final
28 {
29 public:
35  enum class BinningMode : uint16_t
36  {
38  Average = 0,
39 
41  Sum = 1
42  };
43 
50  Binning();
51 
58  ~Binning();
59 
71  Binning(const Binning& other);
72 
84  Binning& operator=(const Binning& other);
85 
94  Binning(Binning&& other) noexcept;
95 
104  Binning& operator=(Binning&& other) noexcept;
105 
115  void SetBinningX(uint8_t value);
116 
124  PEAK_IPL_NO_DISCARD uint8_t BinningX() const;
125 
135  void SetBinningY(uint8_t value);
136 
144  PEAK_IPL_NO_DISCARD uint8_t BinningY() const;
145 
153  PEAK_IPL_NO_DISCARD uint8_t BinningMin() const;
154 
162  PEAK_IPL_NO_DISCARD uint8_t BinningMax() const;
163 
176  PEAK_IPL_NO_DISCARD Size2D ExpectedOutputSize(Size2D inputSize, PixelFormatName pixelFormat) const;
177 
187  void SetMode(BinningMode mode);
188 
196  PEAK_IPL_NO_DISCARD BinningMode Mode() const;
197 
207  PEAK_IPL_NO_DISCARD bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const;
208 
220  PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
221 
222 private:
223  PEAK_IPL_BINNING_HANDLE m_backendHandle{};
224 };
225 
227 {
229 }
230 
232 {
233  if (m_backendHandle)
234  {
235  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Destruct(m_backendHandle);
236  }
237 }
238 
239 inline Binning::Binning(const Binning& other)
240 {
241  if (other.m_backendHandle)
242  {
243  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Acquire(other.m_backendHandle); });
244  }
245 
246  m_backendHandle = other.m_backendHandle;
247 }
248 
249 inline Binning& Binning::operator=(const Binning& other)
250 {
251  if (this != &other)
252  {
253  if (m_backendHandle)
254  {
255  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Destruct(m_backendHandle);
256  }
257 
258  if (other.m_backendHandle)
259  {
261  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Acquire(other.m_backendHandle); });
262  }
263  }
264 
265  m_backendHandle = other.m_backendHandle;
266 
267  return *this;
268 }
269 
270 inline Binning::Binning(Binning&& other) noexcept
271 {
272  *this = std::move(other);
273 }
274 
275 inline Binning& Binning::operator=(Binning&& other) noexcept
276 {
277  if (this != &other)
278  {
279  if (m_backendHandle != nullptr)
280  {
281  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_Destruct(m_backendHandle);
282  }
283 
284  m_backendHandle = other.m_backendHandle;
285  other.m_backendHandle = nullptr;
286  }
287 
288  return *this;
289 }
290 
291 inline void Binning::SetBinningX(uint8_t value)
292 {
293  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_SetBinningX(m_backendHandle, &value); });
294 }
295 
296 inline void Binning::SetBinningY(uint8_t value)
297 {
298  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_SetBinningY(m_backendHandle, &value); });
299 }
300 
301 inline uint8_t Binning::BinningX() const
302 {
303  uint8_t value;
304 
305  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningX(m_backendHandle, &value); });
306 
307  return value;
308 }
309 
310 inline uint8_t Binning::BinningY() const
311 {
312  uint8_t value;
313 
314  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningY(m_backendHandle, &value); });
315 
316  return value;
317 }
318 
319 inline uint8_t Binning::BinningMin() const
320 {
321  uint8_t value;
322 
324  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningMin(m_backendHandle, &value); });
325 
326  return value;
327 }
328 
329 inline uint8_t Binning::BinningMax() const
330 {
331  uint8_t value;
332 
334  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_GetBinningMax(m_backendHandle, &value); });
335 
336  return value;
337 }
338 
339 inline Size2D Binning::ExpectedOutputSize(Size2D inputSize, PixelFormatName pixelFormat) const
340 {
341  Size2D size{};
343  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Binning_ExpectedOutputSize(m_backendHandle, &size.width, &size.height,
344  inputSize.width, inputSize.height, static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormat));
345  });
346 
347  return size;
348 }
349 
350 inline bool Binning::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
351 {
352  PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
353 
356  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
357  reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
358  });
359 
360  return isPixelFormatSupported > 0;
361 }
362 
363 inline Image Binning::Process(const Image& inputImage) const
364 {
365  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
368  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
369  });
370 
371  return ImageBackendAccessor::CreateImage(outputImageHandle);
372 }
373 
375 {
378  m_backendHandle, reinterpret_cast<PEAK_IPL_BINNINGMODE*>(&mode));
379  });
380 }
381 
382 inline Binning::BinningMode Binning::Mode() const
383 {
384  BinningMode value;
385 
388  m_backendHandle, reinterpret_cast<PEAK_IPL_BINNINGMODE*>(&value));
389  });
390 
391  return value;
392 }
393 
394 
395 } /* namespace ipl */
396 } /* namespace peak */
#define PEAK_IPL_NO_DISCARD
Definition: peak_ipl_backend.h:26
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_Construct(PEAK_IPL_BINNING_HANDLE *binningHandle)
Creates a binning.
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_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_SetBinningMode(PEAK_IPL_BINNING_HANDLE binningHandle, PEAK_IPL_BINNINGMODE *mode)
Sets the value of binning mode.
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
size_t height
Height of size.
Definition: peak_ipl_simple_types.hpp:206
Definition: peak_ipl_binning.hpp:27
Binning & operator=(const Binning &other)
Copy assigment for Binning instance.
Definition: peak_ipl_binning.hpp:249
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.
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
PixelFormatName
Enum holding the possible pixel format names.
Definition: peak_ipl_simple_types.hpp:38
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.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
2D size of an image.
Definition: peak_ipl_simple_types.hpp:203
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:39
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:357
PEAK_IPL_C_API PEAK_IPL_Binning_SetBinningY(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningYValue)
Sets the value of binning in vertical direction.
void SetBinningY(uint8_t value)
Sets the values of the binning in vertical direction.
Definition: peak_ipl_binning.hpp:296
int8_t PEAK_IPL_BOOL8
Definition: peak_ipl_backend.h:41
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningY(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningYValue)
Returns the value of binning in vertical direction.
BinningMode
Mode parameter for the binning algorithm.
Definition: peak_ipl_binning.hpp:35
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_GetBinningMode(PEAK_IPL_BINNING_HANDLE binningHandle, PEAK_IPL_BINNINGMODE *mode)
Returns the value of binning mode.
void SetBinningX(uint8_t value)
Sets the values of the binning in horizontal direction.
Definition: peak_ipl_binning.hpp:291
PEAK_IPL_C_API PEAK_IPL_Binning_GetBinningX(PEAK_IPL_BINNING_HANDLE binningHandle, uint8_t *binningXValue)
Returns the value of binning in horizontal direction.
PEAK_IPL_C_API PEAK_IPL_Binning_Acquire(PEAK_IPL_BINNING_HANDLE binningHandle)
Increase the reference count of a binning object.
~Binning()
Destructor for the Binning instance.
Definition: peak_ipl_binning.hpp:231
size_t width
Width of size.
Definition: peak_ipl_simple_types.hpp:205
Binning()
Constructor for a new Binning instance.
Definition: peak_ipl_binning.hpp:226
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.
struct PEAK_IPL_BINNING * PEAK_IPL_BINNING_HANDLE
Definition: peak_ipl_backend.h:337
void SetMode(BinningMode mode)
Sets the values of the binning mode.
Definition: peak_ipl_binning.hpp:374