IDS peak IPL  v1.6.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;
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 {
221 }
222 
224 {
225  *this = std::move(other);
226 }
227 
229 {
230  if (this != &other)
231  {
233  m_backendHandle = other.m_backendHandle;
234  other.m_backendHandle = nullptr;
235  }
236 
237  return *this;
238 }
239 
241 {
244  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
245  });
246 }
247 
249 {
250  size_t colorCorrectorFactorsSize = 0;
251 
254  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
255  });
256 
257  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
258 
261  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
262  });
263 
264  return colorCorrectorFactors;
265 }
266 
268 {
269  size_t colorCorrectorFactorsSize = 0;
270 
273  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
274  });
275 
276  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
277 
280  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
281  });
282 
283  return colorCorrectorFactors;
284 }
285 
286 inline float ColorCorrector::Saturation() const
287 {
288  float saturation;
289 
292  m_backendHandle, reinterpret_cast<float*>(&saturation));
293  });
294 
295  return saturation;
296 }
297 
298 inline float ColorCorrector::SaturationMin() const
299 {
300  float saturationMin;
301 
304  m_backendHandle, reinterpret_cast<float*>(&saturationMin));
305  });
306 
307  return saturationMin;
308 }
309 
310 inline float ColorCorrector::SaturationMax() const
311 {
312  float saturationMax;
313 
316  m_backendHandle, reinterpret_cast<float*>(&saturationMax));
317  });
318 
319  return saturationMax;
320 }
321 
322 inline void ColorCorrector::SetSaturation(float saturation)
323 {
326  m_backendHandle, saturation);
327  });
328 }
329 
330 inline bool ColorCorrector::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
331 {
332  PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
333 
336  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
337  reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
338  });
339 
340  return isPixelFormatSupported > 0;
341 }
342 
343 inline void ColorCorrector::ProcessInPlace(Image& image) const
344 {
347  m_backendHandle, ImageBackendAccessor::BackendHandle(image));
348  });
349 }
350 
351 inline Image ColorCorrector::Process(const Image& inputImage) const
352 {
353  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
356  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
357  });
358 
359  return ImageBackendAccessor::CreateImage(outputImageHandle);
360 }
361 
362 } /* namespace ipl */
363 } /* namespace peak */
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition: peak_ipl_backend.h:295
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:330
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:16
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:351
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:37
peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:248
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:307
void SetSaturation(float saturation)
Sets the color saturation value.
Definition: peak_ipl_color_corrector.hpp:322
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:298
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:310
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:343
void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:240
float Saturation() const
Returns the color saturation value.
Definition: peak_ipl_color_corrector.hpp:286
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