IDS peak IPL v1.17.0
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
33
34namespace peak
35{
36namespace ipl
37{
38
39class Image;
40
44class ColorCorrector final
45{
46public:
54
62
74 ColorCorrector(const ColorCorrector& other);
75
88
98 ColorCorrector(ColorCorrector&& other) noexcept;
99
109 ColorCorrector& operator=(ColorCorrector&& other) noexcept;
110
125 void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors);
126
135
144
152 PEAK_IPL_NO_DISCARD float Saturation() const;
153
162
171
179 void SetSaturation(float saturation);
180
194 void ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature);
195
206
220 void ProcessInPlace(Image& image) const;
221
235 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
236
237private:
238 PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
239};
240
245
247{
248 if (m_backendHandle)
249 {
251 }
252}
253
255{
256 if (other.m_backendHandle)
257 {
259 }
260
261 m_backendHandle = other.m_backendHandle;
262}
263
265{
266 if (this != &other)
267 {
268 if (m_backendHandle)
269 {
271 }
272
273 if (other.m_backendHandle)
274 {
276 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ColorCorrector_Acquire(other.m_backendHandle); });
277 }
278 }
279
280 m_backendHandle = other.m_backendHandle;
281
282 return *this;
283}
284
286{
287 *this = std::move(other);
288}
289
291{
292 if (this != &other)
293 {
294 if (m_backendHandle != nullptr)
295 {
297 }
298 m_backendHandle = other.m_backendHandle;
299 other.m_backendHandle = nullptr;
300 }
301
302 return *this;
303}
304
306{
309 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
310 });
311}
312
314{
315 size_t colorCorrectorFactorsSize = 0;
316
319 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
320 });
321
322 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
323
326 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
327 });
328
329 return colorCorrectorFactors;
330}
331
333{
334 size_t colorCorrectorFactorsSize = 0;
335
338 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
339 });
340
341 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
342
345 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
346 });
347
348 return colorCorrectorFactors;
349}
350
351inline float ColorCorrector::Saturation() const
352{
353 float saturation;
354
357 m_backendHandle, reinterpret_cast<float*>(&saturation));
358 });
359
360 return saturation;
361}
362
364{
365 float saturationMin;
366
369 m_backendHandle, reinterpret_cast<float*>(&saturationMin));
370 });
371
372 return saturationMin;
373}
374
376{
377 float saturationMax;
378
381 m_backendHandle, reinterpret_cast<float*>(&saturationMax));
382 });
383
384 return saturationMax;
385}
386
387inline void ColorCorrector::SetSaturation(float saturation)
388{
391 m_backendHandle, saturation);
392 });
393}
394
396{
397 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
398
401 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
402 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
403 });
404
405 return isPixelFormatSupported > 0;
406}
407
408inline void ColorCorrector::ProcessInPlace(Image& image) const
409{
412 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
413 });
414}
415
416inline Image ColorCorrector::Process(const Image& inputImage) const
417{
418 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
421 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
422 });
423
424 return ImageBackendAccessor::CreateImage(outputImageHandle);
425}
426
427inline void ColorCorrector::ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature)
428{
429 const auto value = ColorCorrectionFactors();
430 const auto calculatedMatrix = chromaticAdapter.CalculateColorCorrectionMatrix(colorTemperature, value);
431 SetColorCorrectionFactors(calculatedMatrix);
432}
433
434} /* namespace ipl */
435} /* namespace peak */
Adjust to changes in lighting conditions to maintain consistent color perception despite variations i...
Definition peak_ipl_chromatic_adaption.hpp:41
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:323
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition peak_ipl_color_corrector.hpp:395
void SetSaturation(float saturation)
Sets the color saturation value.
Definition peak_ipl_color_corrector.hpp:387
ColorCorrector & operator=(const ColorCorrector &other)
Copy assigment for ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:264
float SaturationMin() const
Returns the minimum color saturation value.
Definition peak_ipl_color_corrector.hpp:363
float SaturationMax() const
Returns the maximum color saturation value.
Definition peak_ipl_color_corrector.hpp:375
~ColorCorrector()
Destructor for the ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:246
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:416
void ApplyChromaticAdaption(const ChromaticAdapter &chromaticAdapter, uint32_t colorTemperature)
Applies the chromatic adaption matrix to the color corrector matrix.
Definition peak_ipl_color_corrector.hpp:427
float Saturation() const
Returns the color saturation value.
Definition peak_ipl_color_corrector.hpp:351
ColorCorrector()
Constructor for a new ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:241
peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:313
void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:305
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:408
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:46
The "peak::ipl" namespace contains the whole image processing library.
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:41
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:271
#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:34