IDS peak IPL v1.16.1
Loading...
Searching...
No Matches
peak_ipl_color_corrector.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
20
21#include <type_traits>
22#include <algorithm>
23#include <cmath>
24#include <cstddef>
25#include <limits>
26#include <utility>
27#include <vector>
28
32namespace peak
33{
34namespace ipl
35{
36
37class Image;
38
42class ColorCorrector final
43{
44public:
52
60
72 ColorCorrector(const ColorCorrector& other);
73
86
96 ColorCorrector(ColorCorrector&& other) noexcept;
97
107 ColorCorrector& operator=(ColorCorrector&& other) noexcept;
108
123 void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors);
124
133
142
150 PEAK_IPL_NO_DISCARD float Saturation() const;
151
160
169
177 void SetSaturation(float saturation);
178
192 void ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature);
193
204
218 void ProcessInPlace(Image& image) const;
219
233 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
234
235private:
236 PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
237};
238
243
245{
246 if (m_backendHandle)
247 {
249 }
250}
251
253{
254 if (other.m_backendHandle)
255 {
257 }
258
259 m_backendHandle = other.m_backendHandle;
260}
261
263{
264 if (this != &other)
265 {
266 if (m_backendHandle)
267 {
269 }
270
271 if (other.m_backendHandle)
272 {
274 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ColorCorrector_Acquire(other.m_backendHandle); });
275 }
276 }
277
278 m_backendHandle = other.m_backendHandle;
279
280 return *this;
281}
282
284{
285 *this = std::move(other);
286}
287
289{
290 if (this != &other)
291 {
292 if (m_backendHandle != nullptr)
293 {
295 }
296 m_backendHandle = other.m_backendHandle;
297 other.m_backendHandle = nullptr;
298 }
299
300 return *this;
301}
302
304{
307 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
308 });
309}
310
312{
313 size_t colorCorrectorFactorsSize = 0;
314
317 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
318 });
319
320 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
321
324 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
325 });
326
327 return colorCorrectorFactors;
328}
329
331{
332 size_t colorCorrectorFactorsSize = 0;
333
336 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
337 });
338
339 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
340
343 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
344 });
345
346 return colorCorrectorFactors;
347}
348
349inline float ColorCorrector::Saturation() const
350{
351 float saturation;
352
355 m_backendHandle, reinterpret_cast<float*>(&saturation));
356 });
357
358 return saturation;
359}
360
362{
363 float saturationMin;
364
367 m_backendHandle, reinterpret_cast<float*>(&saturationMin));
368 });
369
370 return saturationMin;
371}
372
374{
375 float saturationMax;
376
379 m_backendHandle, reinterpret_cast<float*>(&saturationMax));
380 });
381
382 return saturationMax;
383}
384
385inline void ColorCorrector::SetSaturation(float saturation)
386{
389 m_backendHandle, saturation);
390 });
391}
392
394{
395 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
396
399 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
400 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
401 });
402
403 return isPixelFormatSupported > 0;
404}
405
406inline void ColorCorrector::ProcessInPlace(Image& image) const
407{
410 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
411 });
412}
413
414inline Image ColorCorrector::Process(const Image& inputImage) const
415{
416 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
419 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
420 });
421
422 return ImageBackendAccessor::CreateImage(outputImageHandle);
423}
424
425inline void ColorCorrector::ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature)
426{
427 const auto value = ColorCorrectionFactors();
428 const auto calculatedMatrix = chromaticAdapter.CalculateColorCorrectionMatrix(colorTemperature, value);
429 SetColorCorrectionFactors(calculatedMatrix);
430}
431
432} /* namespace ipl */
433} /* namespace peak */
Adjust to changes in lighting conditions to maintain consistent color perception despite variations i...
Definition peak_ipl_chromatic_adaption.hpp:39
ColorCorrectionFactors CalculateColorCorrectionMatrix(uint32_t colorTemperature, const ColorCorrectionFactors &correctionFactors=ColorCorrectionFactors::Identity()) const
Calculate the color correction factors for colorTemperature using the current algorithm and color spa...
Definition peak_ipl_chromatic_adaption.hpp:321
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition peak_ipl_color_corrector.hpp:393
void SetSaturation(float saturation)
Sets the color saturation value.
Definition peak_ipl_color_corrector.hpp:385
ColorCorrector & operator=(const ColorCorrector &other)
Copy assigment for ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:262
float SaturationMin() const
Returns the minimum color saturation value.
Definition peak_ipl_color_corrector.hpp:361
float SaturationMax() const
Returns the maximum color saturation value.
Definition peak_ipl_color_corrector.hpp:373
~ColorCorrector()
Destructor for the ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:244
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:414
void ApplyChromaticAdaption(const ChromaticAdapter &chromaticAdapter, uint32_t colorTemperature)
Applies the chromatic adaption matrix to the color corrector matrix.
Definition peak_ipl_color_corrector.hpp:425
float Saturation() const
Returns the color saturation value.
Definition peak_ipl_color_corrector.hpp:349
ColorCorrector()
Constructor for a new ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:239
peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:311
void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:303
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:406
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:41
Definition peak_ipl_binning.hpp:25
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:39
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:182
The "peak::ipl" namespace contains the whole image processing library.
Definition peak_ipl_binning.hpp:23
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:25
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.
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.
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_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_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_SetColorCorrectionFactors(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *colorCorrectorFactors)
Sets the factors of the color correction matrix.
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_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.
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetSaturation(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *saturation)
Returns the color saturation value.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition peak_ipl_backend.h:405
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition peak_ipl_backend.h:393
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Acquire(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle)
Increase the reference count of a color corrector.
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_GetSaturationMin(PEAK_IPL_COLOR_CORRECTOR_HANDLE colorCorrectorHandle, float *saturationMin)
Returns the minimum color saturation value.
int8_t PEAK_IPL_BOOL8
Definition peak_ipl_backend.h:26
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:173
PEAK_IPL_C_API PEAK_IPL_ColorCorrector_Construct(PEAK_IPL_COLOR_CORRECTOR_HANDLE *colorCorrectorHandle)
Creates 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_correction_factors.hpp:32