IDS peak IPL v1.13.0
Loading...
Searching...
No Matches
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
30namespace peak
31{
32namespace ipl
33{
34
35class Image;
36
41{
66 ColorCorrectionFactors(float facRR, float facGR, float facBR, float facRG, float facGG, float facBG, float facRB,
67 float facGB, float facBB)
68 : factorRR(facRR)
69 , factorGR(facGR)
70 , factorBR(facBR)
71 , factorRG(facRG)
72 , factorGG(facGG)
73 , factorBG(facBG)
74 , factorRB(facRB)
75 , factorGB(facGB)
76 , factorBB(facBB)
77 {}
78
86
94
104
114
124
134
146 {
147 return (isEqual(factorRR, other.factorRR) && isEqual(factorGR, other.factorGR)
148 && isEqual(factorBR, other.factorBR) && isEqual(factorRG, other.factorRG)
149 && isEqual(factorGG, other.factorGG) && isEqual(factorBG, other.factorBG)
150 && isEqual(factorRB, other.factorRB) && isEqual(factorGB, other.factorGB)
151 && isEqual(factorBB, other.factorBB));
152 }
153
154 float factorRR{};
155 float factorGR{};
156 float factorBR{};
157 float factorRG{};
158 float factorGG{};
159 float factorBG{};
160 float factorRB{};
161 float factorGB{};
162 float factorBB{};
163
164private:
165 template <class T>
166 static typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type isEqual(T x, T y)
167 {
168 return std::fabs(x - y) <= std::numeric_limits<T>::epsilon();
169 }
170};
171
175class ColorCorrector final
176{
177public:
185
193
205 ColorCorrector(const ColorCorrector& other);
206
219
228 ColorCorrector(ColorCorrector&& other) noexcept;
229
238 ColorCorrector& operator=(ColorCorrector&& other) noexcept;
239
255
264
273
281 PEAK_IPL_NO_DISCARD float Saturation() const;
282
291
300
308 void SetSaturation(float saturation);
309
320
334 void ProcessInPlace(Image& image) const;
335
349 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
350
351private:
352 PEAK_IPL_COLOR_CORRECTOR_HANDLE m_backendHandle{};
353};
354
359
361{
362 if (m_backendHandle)
363 {
365 }
366}
367
369{
370 if (other.m_backendHandle)
371 {
373 }
374
375 m_backendHandle = other.m_backendHandle;
376}
377
379{
380 if (this != &other)
381 {
382 if (m_backendHandle)
383 {
385 }
386
387 if (other.m_backendHandle)
388 {
390 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ColorCorrector_Acquire(other.m_backendHandle); });
391 }
392 }
393
394 m_backendHandle = other.m_backendHandle;
395
396 return *this;
397}
398
400{
401 *this = std::move(other);
402}
403
405{
406 if (this != &other)
407 {
408 if (m_backendHandle != nullptr)
409 {
411 }
412 m_backendHandle = other.m_backendHandle;
413 other.m_backendHandle = nullptr;
414 }
415
416 return *this;
417}
418
420{
423 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors));
424 });
425}
426
428{
429 size_t colorCorrectorFactorsSize = 0;
430
433 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
434 });
435
436 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
437
440 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
441 });
442
443 return colorCorrectorFactors;
444}
445
447{
448 size_t colorCorrectorFactorsSize = 0;
449
452 m_backendHandle, nullptr, &colorCorrectorFactorsSize);
453 });
454
455 peak::ipl::ColorCorrectionFactors colorCorrectorFactors;
456
459 m_backendHandle, reinterpret_cast<float*>(&colorCorrectorFactors), &colorCorrectorFactorsSize);
460 });
461
462 return colorCorrectorFactors;
463}
464
465inline float ColorCorrector::Saturation() const
466{
467 float saturation;
468
471 m_backendHandle, reinterpret_cast<float*>(&saturation));
472 });
473
474 return saturation;
475}
476
478{
479 float saturationMin;
480
483 m_backendHandle, reinterpret_cast<float*>(&saturationMin));
484 });
485
486 return saturationMin;
487}
488
490{
491 float saturationMax;
492
495 m_backendHandle, reinterpret_cast<float*>(&saturationMax));
496 });
497
498 return saturationMax;
499}
500
501inline void ColorCorrector::SetSaturation(float saturation)
502{
505 m_backendHandle, saturation);
506 });
507}
508
510{
511 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
512
515 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
516 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
517 });
518
519 return isPixelFormatSupported > 0;
520}
521
522inline void ColorCorrector::ProcessInPlace(Image& image) const
523{
526 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
527 });
528}
529
530inline Image ColorCorrector::Process(const Image& inputImage) const
531{
532 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
535 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
536 });
537
538 return ImageBackendAccessor::CreateImage(outputImageHandle);
539}
540
541} /* namespace ipl */
542} /* namespace peak */
Applies a 3x3 color correction matrix to the data.
Definition peak_ipl_color_corrector.hpp:176
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the color corrector supports the given pixel format.
Definition peak_ipl_color_corrector.hpp:509
void SetSaturation(float saturation)
Sets the color saturation value.
Definition peak_ipl_color_corrector.hpp:501
ColorCorrector & operator=(const ColorCorrector &other)
Copy assigment for ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:378
float SaturationMin() const
Returns the minimum color saturation value.
Definition peak_ipl_color_corrector.hpp:477
float SaturationMax() const
Returns the maximum color saturation value.
Definition peak_ipl_color_corrector.hpp:489
void SetColorCorrectionFactors(peak::ipl::ColorCorrectionFactors colorCorrectorFactors)
Sets the values of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:419
~ColorCorrector()
Destructor for the ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:360
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:530
float Saturation() const
Returns the color saturation value.
Definition peak_ipl_color_corrector.hpp:465
ColorCorrector()
Constructor for a new ColorCorrector instance.
Definition peak_ipl_color_corrector.hpp:355
peak::ipl::ColorCorrectionFactors ColorCorrectionFactors()
Returns the factors of the color correction matrix.
Definition peak_ipl_color_corrector.hpp:427
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:522
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:40
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
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:369
struct PEAK_IPL_COLOR_CORRECTOR * PEAK_IPL_COLOR_CORRECTOR_HANDLE
Definition peak_ipl_backend.h:357
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:41
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_backend.h:26
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:188
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_corrector.hpp:41
~ColorCorrectionFactors()=default
Destructor for the ColorCorrectionFactors instance.
float factorBB
Blue-Blue Factor.
Definition peak_ipl_color_corrector.hpp:162
float factorGB
Green-Blue Factor.
Definition peak_ipl_color_corrector.hpp:161
float factorGR
Green-Red Factor.
Definition peak_ipl_color_corrector.hpp:155
ColorCorrectionFactors(ColorCorrectionFactors &&o)=default
Copy Constructor for a new ColorCorrectionFactors instance.
ColorCorrectionFactors & operator=(const ColorCorrectionFactors &o)=default
Copy assigment for ColorCorrectionFactors instance.
ColorCorrectionFactors(float facRR, float facGR, float facBR, float facRG, float facGG, float facBG, float facRB, float facGB, float facBB)
Constructor for a new ColorCorrectionFactors instance.
Definition peak_ipl_color_corrector.hpp:66
float factorRG
Red-Green Factor.
Definition peak_ipl_color_corrector.hpp:157
float factorGG
Green-Green Factor.
Definition peak_ipl_color_corrector.hpp:158
ColorCorrectionFactors()=default
Constructor for a new ColorCorrectionFactors instance.
ColorCorrectionFactors(const ColorCorrectionFactors &o)=default
Move constructor for ColorCorrectionFactors instance.
ColorCorrectionFactors & operator=(ColorCorrectionFactors &&o)=default
Move assignment for ColorCorrectionFactors instance.
float factorBG
Blue-Green Factor.
Definition peak_ipl_color_corrector.hpp:159
bool operator==(const ColorCorrectionFactors &other) const
Compare ColorCorrectionFactors.
Definition peak_ipl_color_corrector.hpp:145
float factorBR
Blue-Red Factor.
Definition peak_ipl_color_corrector.hpp:156
float factorRB
Red-Blue Factor.
Definition peak_ipl_color_corrector.hpp:160
float factorRR
Red-Red Factor.
Definition peak_ipl_color_corrector.hpp:154