IDSpeakIPL  v1.8.0
peak_ipl_color_corrector.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
18 
19 #include <type_traits>
20 #include <algorithm>
21 #include <cmath>
22 #include <cstddef>
23 #include <limits>
24 #include <utility>
25 #include <vector>
26 
30 namespace peak
31 {
32 namespace ipl
33 {
34 
35 class Image;
36 
41 {
66  ColorCorrectionFactors(float facRR, float facGR, float facBR, float facRG, float facGG, float facBG, float facRB,
67  float facGB, float facBB)
68  : factorRR(facRR)
69  , factorGR(facGR)
70  , factorBR(facBR)
71  , factorRG(facRG)
72  , factorGG(facGG)
73  , factorBG(facBG)
74  , factorRB(facRB)
75  , factorGB(facGB)
76  , factorBB(facBB)
77  {}
78 
85  ColorCorrectionFactors() = default;
86 
93  ~ColorCorrectionFactors() = default;
94 
104 
114 
124 
134 
146  {
147  return (isEqual(factorRR, other.factorRR) && isEqual(factorGR, other.factorGR)
148  && isEqual(factorBR, other.factorBR) && isEqual(factorRG, other.factorRG)
149  && isEqual(factorGG, other.factorGG) && isEqual(factorBG, other.factorBG)
150  && isEqual(factorRB, other.factorRB) && isEqual(factorGB, other.factorGB)
151  && isEqual(factorBB, other.factorBB));
152  }
153 
154  float factorRR{};
155  float factorGR{};
156  float factorBR{};
157  float factorRG{};
158  float factorGG{};
159  float factorBG{};
160  float factorRB{};
161  float factorGB{};
162  float factorBB{};
163 
164 private:
165  template <class T>
166  static typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type isEqual(T x, T y)
167  {
168  return std::fabs(x - y) <= std::numeric_limits<T>::epsilon();
169  }
170 };
171 
175 class ColorCorrector final
176 {
177 public:
184  ColorCorrector();
185 
192  ~ColorCorrector();
193 
205  ColorCorrector(const ColorCorrector& other);
206 
218  ColorCorrector& operator=(const ColorCorrector& other);
219 
228  ColorCorrector(ColorCorrector&& other) noexcept;
229 
238  ColorCorrector& operator=(ColorCorrector&& other) noexcept;
239 
254  void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors);
255 
264 
273 
281  PEAK_IPL_NO_DISCARD float Saturation() const;
282 
290  PEAK_IPL_NO_DISCARD float SaturationMin() const;
291 
299  PEAK_IPL_NO_DISCARD float SaturationMax() const;
300 
308  void SetSaturation(float saturation);
309 
319  PEAK_IPL_NO_DISCARD bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const;
320 
332  void ProcessInPlace(Image& image) const;
333 
345  PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
346 
347 private:
348  PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
349 };
350 
352 {
354 }
355 
357 {
358  if (m_backendHandle)
359  {
361  }
362 }
363 
365 {
366  if (other.m_backendHandle)
367  {
369  }
370 
371  m_backendHandle = other.m_backendHandle;
372 }
373 
375 {
376  if (this != &other)
377  {
378  if (m_backendHandle)
379  {
381  }
382 
383  if (other.m_backendHandle)
384  {
386  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ColorCorrector_Acquire(other.m_backendHandle); });
387  }
388  }
389 
390  m_backendHandle = other.m_backendHandle;
391 
392  return *this;
393 }
394 
396 {
397  *this = std::move(other);
398 }
399 
401 {
402  if (this != &other)
403  {
405  m_backendHandle = other.m_backendHandle;
406  other.m_backendHandle = nullptr;
407  }
408 
409  return *this;
410 }
411 
413 {
416  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
417  });
418 }
419 
421 {
422  size_t colorCorrectorFactorsSize = 0;
423 
426  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
427  });
428 
429  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
430 
433  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
434  });
435 
436  return colorCorrectorFactors;
437 }
438 
440 {
441  size_t colorCorrectorFactorsSize = 0;
442 
445  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
446  });
447 
448  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
449 
452  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
453  });
454 
455  return colorCorrectorFactors;
456 }
457 
458 inline float ColorCorrector::Saturation() const
459 {
460  float saturation;
461 
464  m_backendHandle, reinterpret_cast<float*>(&saturation));
465  });
466 
467  return saturation;
468 }
469 
470 inline float ColorCorrector::SaturationMin() const
471 {
472  float saturationMin;
473 
476  m_backendHandle, reinterpret_cast<float*>(&saturationMin));
477  });
478 
479  return saturationMin;
480 }
481 
482 inline float ColorCorrector::SaturationMax() const
483 {
484  float saturationMax;
485 
488  m_backendHandle, reinterpret_cast<float*>(&saturationMax));
489  });
490 
491  return saturationMax;
492 }
493 
494 inline void ColorCorrector::SetSaturation(float saturation)
495 {
498  m_backendHandle, saturation);
499  });
500 }
501 
502 inline bool ColorCorrector::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
503 {
504  PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
505 
508  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
509  reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
510  });
511 
512  return isPixelFormatSupported > 0;
513 }
514 
515 inline void ColorCorrector::ProcessInPlace(Image& image) const
516 {
519  m_backendHandle, ImageBackendAccessor::BackendHandle(image));
520  });
521 }
522 
523 inline Image ColorCorrector::Process(const Image& inputImage) const
524 {
525  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
528  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
529  });
530 
531  return ImageBackendAccessor::CreateImage(outputImageHandle);
532 }
533 
534 } /* namespace ipl */
535 } /* namespace peak */
#define PEAK_IPL_NO_DISCARD
Definition: peak_ipl_backend.h:26
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition: peak_ipl_backend.h:342
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_SetColorCorrectionFactors(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *colorCorrectorFactors)
Sets the factors of the color correction matrix.
Applies a 3x3 color correction matrix to the data.
Definition: peak_ipl_color_corrector.hpp:175
float factorGB
Green-Blue Factor.
Definition: peak_ipl_color_corrector.hpp:161
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Acquire(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle)
Increase the reference count of a color corrector.
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
The Factors of the Color Correction Matrix.
Definition: peak_ipl_color_corrector.hpp:40
PixelFormatName
Enum holding the possible pixel format names.
Definition: peak_ipl_simple_types.hpp:38
PEAK_IPL_NO_DISCARD bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition: peak_ipl_color_corrector.hpp:502
float factorGG
Green-Green Factor.
Definition: peak_ipl_color_corrector.hpp:158
float factorBR
Blue-Red Factor.
Definition: peak_ipl_color_corrector.hpp:156
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetColorCorrectionFactors(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *colorCorrectorFactors, size_t *colorCorrectorFactorsSize)
Returns the color corrector 3x3 matrix factors and its size.
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
PEAK_IPL_NO_DISCARD Image Process(const Image &inputImage) const
Corrects the colors of the given image by applying a 3x3 color correction matrix to the data...
Definition: peak_ipl_color_corrector.hpp:523
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetSaturation(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *saturation)
Returns the color saturation value.
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Construct(PEAK_IPL_COLOR_CORRECTOR_HANDLE *colorCorrectorHandle)
Creates a color corrector.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
PEAK_IPL_NO_DISCARD bool operator==(const ColorCorrectionFactors &other) const
Compare ColorCorrectionFactors.
Definition: peak_ipl_color_corrector.hpp:145
float factorRG
Red-Green Factor.
Definition: peak_ipl_color_corrector.hpp:157
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:39
PEAK_IPL_NO_DISCARD peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:420
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_ProcessInPlace(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, PEAK_IPL_IMAGE_HANDLE imageHandle)
Corrects the colors of the given image.
float factorGR
Green-Red Factor.
Definition: peak_ipl_color_corrector.hpp:155
~ColorCorrector()
Destructor for the ColorCorrector instance.
Definition: peak_ipl_color_corrector.hpp:356
float factorRB
Red-Blue Factor.
Definition: peak_ipl_color_corrector.hpp:160
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:354
ColorCorrector & operator=(const ColorCorrector &other)
Copy assigment for ColorCorrector instance.
Definition: peak_ipl_color_corrector.hpp:374
void SetSaturation(float saturation)
Sets the color saturation value.
Definition: peak_ipl_color_corrector.hpp:494
ColorCorrectionFactors()=default
Constructor for a new ColorCorrectionFactors instance.
ColorCorrectionFactors(float facRR, float facGR, float facBR, float facRG, float facGG, float facBG, float facRB, float facGB, float facBB)
Constructor for a new ColorCorrectionFactors instance.
Definition: peak_ipl_color_corrector.hpp:66
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Process(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Corrects the colors of the given image.
PEAK_IPL_NO_DISCARD float SaturationMin() const
Returns the minimum color saturation value.
Definition: peak_ipl_color_corrector.hpp:470
~ColorCorrectionFactors()=default
Destructor for the ColorCorrectionFactors instance.
int8_t PEAK_IPL_BOOL8
Definition: peak_ipl_backend.h:41
float factorBG
Blue-Green Factor.
Definition: peak_ipl_color_corrector.hpp:159
float factorBB
Blue-Blue Factor.
Definition: peak_ipl_color_corrector.hpp:162
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Destruct(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle)
Destroys the color corrector associated with the given handle.
PEAK_IPL_NO_DISCARD float SaturationMax() const
Returns the maximum color saturation value.
Definition: peak_ipl_color_corrector.hpp:482
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetSaturationMax(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *saturationMax)
Returns the maximum color saturation value.
ColorCorrectionFactors & operator=(const ColorCorrectionFactors &o)=default
Copy assigment for ColorCorrectionFactors instance.
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetSaturationMin(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *saturationMin)
Returns the minimum color saturation value.
void ProcessInPlace(Image &image) const
Corrects the colors of the given image by applying a 3x3 color correction matrix to the data in place...
Definition: peak_ipl_color_corrector.hpp:515
void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:412
PEAK_IPL_NO_DISCARD float Saturation() const
Returns the color saturation value.
Definition: peak_ipl_color_corrector.hpp:458
ColorCorrector()
Constructor for a new ColorCorrector instance.
Definition: peak_ipl_color_corrector.hpp:351
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_SetSaturation(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float saturation)
Sets the color saturation value.
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetIsPixelFormatSupported(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, PEAK_IPL_PIXEL_FORMAT pixelFormat, PEAK_IPL_BOOL8 *isPixelFormatSupported)
Asks the given color corrector whether it supports the given pixel format.
float factorRR
Red-Red Factor.
Definition: peak_ipl_color_corrector.hpp:154