IDS peak IPL  v1.7.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 {
42  ColorCorrectionFactors(float facRR, float facGR, float facBR, float facRG, float facGG, float facBG, float facRB,
43  float facGB, float facBB)
44  : factorRR(facRR)
45  , factorGR(facGR)
46  , factorBR(facBR)
47  , factorRG(facRG)
48  , factorGG(facGG)
49  , factorBG(facBG)
50  , factorRB(facRB)
51  , factorGB(facGB)
52  , factorBB(facBB)
53  {}
54 
55  ColorCorrectionFactors() = default;
56  ~ColorCorrectionFactors() = default;
61 
62  bool operator==(const ColorCorrectionFactors& other) const
63  {
64  return (isEqual(factorRR, other.factorRR) && isEqual(factorGR, other.factorGR)
65  && isEqual(factorBR, other.factorBR) && isEqual(factorRG, other.factorRG)
66  && isEqual(factorGG, other.factorGG) && isEqual(factorBG, other.factorBG)
67  && isEqual(factorRB, other.factorRB) && isEqual(factorGB, other.factorGB)
68  && isEqual(factorBB, other.factorBB));
69  }
70 
71  float factorRR;
72  float factorGR;
73  float factorBR;
74  float factorRG;
75  float factorGG;
76  float factorBG;
77  float factorRB;
78  float factorGB;
79  float factorBB;
80 
81 private:
82  template <class T>
83  static typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type isEqual(T x, T y)
84  {
85  return std::fabs(x - y) <= std::numeric_limits<T>::epsilon();
86  }
87 };
88 
92 class ColorCorrector final
93 {
94 public:
96  ~ColorCorrector();
97  ColorCorrector(const ColorCorrector& other) = delete;
98  ColorCorrector& operator=(const ColorCorrector& other) = delete;
99  ColorCorrector(ColorCorrector&& other) noexcept;
100  ColorCorrector& operator=(ColorCorrector&& other) noexcept;
101 
116  void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors);
117 
126 
135 
143  float Saturation() const;
144 
152  float SaturationMin() const;
153 
161  float SaturationMax() const;
162 
170  void SetSaturation(float saturation);
171 
181  bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const;
182 
194  void ProcessInPlace(Image& image) const;
195 
207  Image Process(const Image& inputImage) const;
208 
209 private:
210  PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
211 };
212 
214 {
216 }
217 
219 {
220  if (m_backendHandle)
221  {
223  }
224 }
225 
227 {
228  *this = std::move(other);
229 }
230 
232 {
233  if (this != &other)
234  {
236  m_backendHandle = other.m_backendHandle;
237  other.m_backendHandle = nullptr;
238  }
239 
240  return *this;
241 }
242 
244 {
247  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
248  });
249 }
250 
252 {
253  size_t colorCorrectorFactorsSize = 0;
254 
257  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
258  });
259 
260  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
261 
264  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
265  });
266 
267  return colorCorrectorFactors;
268 }
269 
271 {
272  size_t colorCorrectorFactorsSize = 0;
273 
276  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
277  });
278 
279  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
280 
283  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
284  });
285 
286  return colorCorrectorFactors;
287 }
288 
289 inline float ColorCorrector::Saturation() const
290 {
291  float saturation;
292 
295  m_backendHandle, reinterpret_cast<float*>(&saturation));
296  });
297 
298  return saturation;
299 }
300 
301 inline float ColorCorrector::SaturationMin() const
302 {
303  float saturationMin;
304 
307  m_backendHandle, reinterpret_cast<float*>(&saturationMin));
308  });
309 
310  return saturationMin;
311 }
312 
313 inline float ColorCorrector::SaturationMax() const
314 {
315  float saturationMax;
316 
319  m_backendHandle, reinterpret_cast<float*>(&saturationMax));
320  });
321 
322  return saturationMax;
323 }
324 
325 inline void ColorCorrector::SetSaturation(float saturation)
326 {
329  m_backendHandle, saturation);
330  });
331 }
332 
333 inline bool ColorCorrector::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
334 {
335  PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
336 
339  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
340  reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
341  });
342 
343  return isPixelFormatSupported > 0;
344 }
345 
346 inline void ColorCorrector::ProcessInPlace(Image& image) const
347 {
350  m_backendHandle, ImageBackendAccessor::BackendHandle(image));
351  });
352 }
353 
354 inline Image ColorCorrector::Process(const Image& inputImage) const
355 {
356  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
359  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
360  });
361 
362  return ImageBackendAccessor::CreateImage(outputImageHandle);
363 }
364 
365 } /* namespace ipl */
366 } /* namespace peak */
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition: peak_ipl_backend.h:314
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:92
float factorGB
Definition: peak_ipl_color_corrector.hpp:78
#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
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition: peak_ipl_color_corrector.hpp:333
float factorGG
Definition: peak_ipl_color_corrector.hpp:75
float factorBR
Definition: peak_ipl_color_corrector.hpp:73
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
ColorCorrectionFactors & operator=(ColorCorrectionFactors &&o)=default
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:354
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
float factorRG
Definition: peak_ipl_color_corrector.hpp:74
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::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:251
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
Definition: peak_ipl_color_corrector.hpp:72
~ColorCorrector()
Definition: peak_ipl_color_corrector.hpp:218
float factorRB
Definition: peak_ipl_color_corrector.hpp:77
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:326
void SetSaturation(float saturation)
Sets the color saturation value.
Definition: peak_ipl_color_corrector.hpp:325
ColorCorrectionFactors(float facRR, float facGR, float facBR, float facRG, float facGG, float facBG, float facRB, float facGB, float facBB)
Definition: peak_ipl_color_corrector.hpp:42
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.
float SaturationMin() const
Returns the minimum color saturation value.
Definition: peak_ipl_color_corrector.hpp:301
int8_t PEAK_IPL_BOOL8
Definition: peak_ipl_backend.h:25
float factorBG
Definition: peak_ipl_color_corrector.hpp:76
float factorBB
Definition: peak_ipl_color_corrector.hpp:79
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Destruct(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle)
Destroys the color corrector associated with the given handle.
float SaturationMax() const
Returns the maximum color saturation value.
Definition: peak_ipl_color_corrector.hpp:313
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetSaturationMax(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *saturationMax)
Returns the maximum color saturation value.
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:346
void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:243
float Saturation() const
Returns the color saturation value.
Definition: peak_ipl_color_corrector.hpp:289
ColorCorrector & operator=(const ColorCorrector &other)=delete
ColorCorrector()
Definition: peak_ipl_color_corrector.hpp:213
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
Definition: peak_ipl_color_corrector.hpp:71
bool operator==(const ColorCorrectionFactors &other) const
Definition: peak_ipl_color_corrector.hpp:62