IDS peak IPL v1.17.2
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
45class ColorCorrector final
46{
47public:
55
63
75 ColorCorrector(const ColorCorrector& other);
76
89
99 ColorCorrector(ColorCorrector&& other) noexcept;
100
110 ColorCorrector& operator=(ColorCorrector&& other) noexcept;
111
126 void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors);
127
136
145
153 PEAK_IPL_NO_DISCARD float Saturation() const;
154
163
172
180 void SetSaturation(float saturation);
181
195 void ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature);
196
207
221 void ProcessInPlace(Image& image) const;
222
236 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
237
238private:
239 PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
240};
241
246
248{
249 if (m_backendHandle)
250 {
252 }
253}
254
256{
257 if (other.m_backendHandle)
258 {
260 }
261
262 m_backendHandle = other.m_backendHandle;
263}
264
266{
267 if (this != &other)
268 {
269 if (m_backendHandle)
270 {
272 }
273
274 if (other.m_backendHandle)
275 {
277 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ColorCorrector_Acquire(other.m_backendHandle); });
278 }
279 }
280
281 m_backendHandle = other.m_backendHandle;
282
283 return *this;
284}
285
287{
288 *this = std::move(other);
289}
290
292{
293 if (this != &other)
294 {
295 if (m_backendHandle != nullptr)
296 {
298 }
299 m_backendHandle = other.m_backendHandle;
300 other.m_backendHandle = nullptr;
301 }
302
303 return *this;
304}
305
307{
310 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
311 });
312}
313
315{
316 size_t colorCorrectorFactorsSize = 0;
317
320 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
321 });
322
323 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
324
327 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
328 });
329
330 return colorCorrectorFactors;
331}
332
334{
335 size_t colorCorrectorFactorsSize = 0;
336
339 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
340 });
341
342 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
343
346 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
347 });
348
349 return colorCorrectorFactors;
350}
351
352inline float ColorCorrector::Saturation() const
353{
354 float saturation;
355
358 m_backendHandle, reinterpret_cast<float*>(&saturation));
359 });
360
361 return saturation;
362}
363
365{
366 float saturationMin;
367
370 m_backendHandle, reinterpret_cast<float*>(&saturationMin));
371 });
372
373 return saturationMin;
374}
375
377{
378 float saturationMax;
379
382 m_backendHandle, reinterpret_cast<float*>(&saturationMax));
383 });
384
385 return saturationMax;
386}
387
388inline void ColorCorrector::SetSaturation(float saturation)
389{
392 m_backendHandle, saturation);
393 });
394}
395
397{
398 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
399
402 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
403 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
404 });
405
406 return isPixelFormatSupported > 0;
407}
408
409inline void ColorCorrector::ProcessInPlace(Image& image) const
410{
413 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
414 });
415}
416
417inline Image ColorCorrector::Process(const Image& inputImage) const
418{
419 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
422 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
423 });
424
425 return ImageBackendAccessor::CreateImage(outputImageHandle);
426}
427
428inline void ColorCorrector::ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature)
429{
430 const auto value = ColorCorrectionFactors();
431 const auto calculatedMatrix = chromaticAdapter.CalculateColorCorrectionMatrix(colorTemperature, value);
432 SetColorCorrectionFactors(calculatedMatrix);
433}
434
435} /* namespace ipl */
436} /* namespace peak */
Adjust to changes in lighting conditions to maintain consistent color perception despite variations i...
Definition peak_ipl_chromatic_adaption.hpp:42
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:324
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition peak_ipl_color_corrector.hpp:396
void SetSaturation(float saturation)
Sets the color saturation value.
Definition peak_ipl_color_corrector.hpp:388
ColorCorrector & operator=(const ColorCorrector &other)
Copy assigment for ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:265
float SaturationMin() const
Returns the minimum color saturation value.
Definition peak_ipl_color_corrector.hpp:364
float SaturationMax() const
Returns the maximum color saturation value.
Definition peak_ipl_color_corrector.hpp:376
~ColorCorrector()
Destructor for the ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:247
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:417
void ApplyChromaticAdaption(const ChromaticAdapter &chromaticAdapter, uint32_t colorTemperature)
Applies the chromatic adaption matrix to the color corrector matrix.
Definition peak_ipl_color_corrector.hpp:428
float Saturation() const
Returns the color saturation value.
Definition peak_ipl_color_corrector.hpp:352
ColorCorrector()
Constructor for a new ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:242
peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:314
void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:306
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:409
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:47
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:43
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:289
#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:35