IDS peak IPL v1.18.0
Loading...
Searching...
No Matches
peak_ipl_color_corrector.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
15
16#include <type_traits>
17#include <algorithm>
18#include <cmath>
19#include <cstddef>
20#include <limits>
21#include <utility>
22#include <vector>
23
28
29namespace peak
30{
31namespace ipl
32{
33
34class Image;
35
40class ColorCorrector final
41{
42public:
50
58
70 ColorCorrector(const ColorCorrector& other);
71
84
94 ColorCorrector(ColorCorrector&& other) noexcept;
95
105 ColorCorrector& operator=(ColorCorrector&& other) noexcept;
106
121 void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors);
122
131
140
148 PEAK_IPL_NO_DISCARD float Saturation() const;
149
158
167
175 void SetSaturation(float saturation);
176
190 void ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature);
191
202
216 void ProcessInPlace(Image& image) const;
217
231 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
232
233private:
234 PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
235};
236
241
243{
244 if (m_backendHandle)
245 {
247 }
248}
249
251{
252 if (other.m_backendHandle)
253 {
255 }
256
257 m_backendHandle = other.m_backendHandle;
258}
259
261{
262 if (this != &other)
263 {
264 if (m_backendHandle)
265 {
267 }
268
269 if (other.m_backendHandle)
270 {
272 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ColorCorrector_Acquire(other.m_backendHandle); });
273 }
274 }
275
276 m_backendHandle = other.m_backendHandle;
277
278 return *this;
279}
280
282{
283 *this = std::move(other);
284}
285
287{
288 if (this != &other)
289 {
290 if (m_backendHandle != nullptr)
291 {
293 }
294 m_backendHandle = other.m_backendHandle;
295 other.m_backendHandle = nullptr;
296 }
297
298 return *this;
299}
300
302{
305 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
306 });
307}
308
310{
311 size_t colorCorrectorFactorsSize = 0;
312
315 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
316 });
317
318 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
319
322 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
323 });
324
325 return colorCorrectorFactors;
326}
327
329{
330 size_t colorCorrectorFactorsSize = 0;
331
334 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
335 });
336
337 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
338
341 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
342 });
343
344 return colorCorrectorFactors;
345}
346
347inline float ColorCorrector::Saturation() const
348{
349 float saturation;
350
353 m_backendHandle, reinterpret_cast<float*>(&saturation));
354 });
355
356 return saturation;
357}
358
360{
361 float saturationMin;
362
365 m_backendHandle, reinterpret_cast<float*>(&saturationMin));
366 });
367
368 return saturationMin;
369}
370
372{
373 float saturationMax;
374
377 m_backendHandle, reinterpret_cast<float*>(&saturationMax));
378 });
379
380 return saturationMax;
381}
382
383inline void ColorCorrector::SetSaturation(float saturation)
384{
387 m_backendHandle, saturation);
388 });
389}
390
392{
393 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
394
397 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
398 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
399 });
400
401 return isPixelFormatSupported > 0;
402}
403
404inline void ColorCorrector::ProcessInPlace(Image& image) const
405{
408 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
409 });
410}
411
412inline Image ColorCorrector::Process(const Image& inputImage) const
413{
414 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
417 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
418 });
419
420 return ImageBackendAccessor::CreateImage(outputImageHandle);
421}
422
423inline void ColorCorrector::ApplyChromaticAdaption(const ChromaticAdapter& chromaticAdapter, uint32_t colorTemperature)
424{
425 const auto value = ColorCorrectionFactors();
426 const auto calculatedMatrix = chromaticAdapter.CalculateColorCorrectionMatrix(colorTemperature, value);
427 SetColorCorrectionFactors(calculatedMatrix);
428}
429
430} /* namespace ipl */
431} /* namespace peak */
Adjust to changes in lighting conditions to maintain consistent color perception despite variations i...
Definition peak_ipl_chromatic_adaption.hpp:37
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:319
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition peak_ipl_color_corrector.hpp:391
void SetSaturation(float saturation)
Sets the color saturation value.
Definition peak_ipl_color_corrector.hpp:383
ColorCorrector & operator=(const ColorCorrector &other)
Copy assigment for ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:260
float SaturationMin() const
Returns the minimum color saturation value.
Definition peak_ipl_color_corrector.hpp:359
float SaturationMax() const
Returns the maximum color saturation value.
Definition peak_ipl_color_corrector.hpp:371
~ColorCorrector()
Destructor for the ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:242
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:412
void ApplyChromaticAdaption(const ChromaticAdapter &chromaticAdapter, uint32_t colorTemperature)
Applies the chromatic adaption matrix to the color corrector matrix.
Definition peak_ipl_color_corrector.hpp:423
float Saturation() const
Returns the color saturation value.
Definition peak_ipl_color_corrector.hpp:347
ColorCorrector()
Constructor for a new ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:237
peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:309
void SetColorCorrectionFactors(ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:301
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:404
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:42
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:38
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:284
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:20
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:402
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition peak_ipl_backend.h:390
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:23
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:170
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:11
The Factors of the Color Correction Matrix.
Definition peak_ipl_color_correction_factors.hpp:30