IDS peak IPL  v1.3.2
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 
145  bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const;
146 
158  void ProcessInPlace(Image& image) const;
159 
171  Image Process(const Image& inputImage) const;
172 
173 private:
174  PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
175 };
176 
178 {
180 }
181 
183 {
185 }
186 
188 {
189  *this = std::move(other);
190 }
191 
193 {
194  if (this != &other)
195  {
197  m_backendHandle = other.m_backendHandle;
198  other.m_backendHandle = nullptr;
199  }
200 
201  return *this;
202 }
203 
205 {
208  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
209  });
210 }
211 
213 {
214  size_t colorCorrectorFactorsSize = 0;
215 
218  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
219  });
220 
221  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
222 
225  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
226  });
227 
228  return colorCorrectorFactors;
229 }
230 
232 {
233  size_t colorCorrectorFactorsSize = 0;
234 
237  m_backendHandle, nullptr, &colorCorrectorFactorsSize);
238  });
239 
240  peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
241 
244  m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
245  });
246 
247  return colorCorrectorFactors;
248 }
249 
250 inline bool ColorCorrector::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
251 {
252  PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
253 
256  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
257  reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
258  });
259 
260  return isPixelFormatSupported > 0;
261 }
262 
263 inline void ColorCorrector::ProcessInPlace(Image& image) const
264 {
267  m_backendHandle, ImageBackendAccessor::BackendHandle(image));
268  });
269 }
270 
271 inline Image ColorCorrector::Process(const Image& inputImage) const
272 {
273  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
276  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
277  });
278 
279  return ImageBackendAccessor::CreateImage(outputImageHandle);
280 }
281 
282 } /* namespace ipl */
283 } /* namespace peak */
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition: peak_ipl_backend.h:215
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:250
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_color_corrector.hpp:30
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:271
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:128
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:212
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:182
float factorRB
Definition: peak_ipl_color_corrector.hpp:77
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:227
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.
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.
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:263
void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition: peak_ipl_color_corrector.hpp:204
ColorCorrector & operator=(const ColorCorrector &other)=delete
ColorCorrector()
Definition: peak_ipl_color_corrector.hpp:177
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