17#include <peak_icv_c/algorithms/preprocessing/peak_icv_gain.h>
99 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
139 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
169 PEAK_COMMON_NO_DISCARD
float GetMaster()
const override;
183 void SetRed(
float value)
override;
192 PEAK_COMMON_NO_DISCARD
float GetRed()
const override;
206 void SetGreen(
float value)
override;
215 PEAK_COMMON_NO_DISCARD
float GetGreen()
const override;
229 void SetBlue(
float value)
override;
238 PEAK_COMMON_NO_DISCARD
float GetBlue()
const override;
296 void Apply(peak_icv_gain_type type,
float value)
const;
298 PEAK_COMMON_NO_DISCARD
float Fetch(peak_icv_gain_type type)
const;
300 static constexpr int moduleVersion = 1;
301 static constexpr auto masterGainKey =
"MasterGain";
302 static constexpr auto redGainKey =
"RedGain";
303 static constexpr auto greenGainKey =
"GreenGain";
304 static constexpr auto blueGainKey =
"BlueGain";
306 peak_icv_gain_handle m_handle{};
307 bool m_enabled{
true };
313 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Create(&m_handle);
319 if (m_handle !=
nullptr)
321 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
327 m_handle = std::exchange(other.m_handle,
nullptr);
328 m_enabled = other.m_enabled;
335 if (m_handle !=
nullptr)
338 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
342 m_handle = std::exchange(other.m_handle,
nullptr);
343 m_enabled = other.m_enabled;
361 archive.
SetInt(
"Version", moduleVersion);
364 archive.
SetDouble(masterGainKey, Fetch(PEAK_ICV_GAIN_TYPE_MASTER));
365 archive.
SetDouble(redGainKey, Fetch(PEAK_ICV_GAIN_TYPE_RED));
366 archive.
SetDouble(greenGainKey, Fetch(PEAK_ICV_GAIN_TYPE_GREEN));
367 archive.
SetDouble(blueGainKey, Fetch(PEAK_ICV_GAIN_TYPE_BLUE));
372 const auto version = archive.
GetInt(
"Version");
377 Apply(PEAK_ICV_GAIN_TYPE_MASTER,
static_cast<float>(archive.
GetDouble(masterGainKey)));
379 Apply(PEAK_ICV_GAIN_TYPE_RED,
static_cast<float>(archive.
GetDouble(redGainKey)));
380 Apply(PEAK_ICV_GAIN_TYPE_GREEN,
static_cast<float>(archive.
GetDouble(greenGainKey)));
381 Apply(PEAK_ICV_GAIN_TYPE_BLUE,
static_cast<float>(archive.
GetDouble(blueGainKey)));
391 Apply(PEAK_ICV_GAIN_TYPE_MASTER, 1.0F);
393 Apply(PEAK_ICV_GAIN_TYPE_RED, 1.0F);
394 Apply(PEAK_ICV_GAIN_TYPE_GREEN, 1.0F);
395 Apply(PEAK_ICV_GAIN_TYPE_BLUE, 1.0F);
400 Apply(PEAK_ICV_GAIN_TYPE_MASTER, value);
405 return Fetch(PEAK_ICV_GAIN_TYPE_MASTER);
410 Apply(PEAK_ICV_GAIN_TYPE_RED, value);
415 return Fetch(PEAK_ICV_GAIN_TYPE_RED);
420 Apply(PEAK_ICV_GAIN_TYPE_GREEN, value);
425 return Fetch(PEAK_ICV_GAIN_TYPE_GREEN);
430 Apply(PEAK_ICV_GAIN_TYPE_BLUE, value);
435 return Fetch(PEAK_ICV_GAIN_TYPE_BLUE);
440 peak_common_interval_f cRange{};
442 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetRange(m_handle, &cRange);
445 return { cRange.minimum, cRange.maximum };
455 auto needsProcessing = [&] {
458 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_NeedsProcessing(m_handle, &value);
469 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
472 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_ProcessInplace(m_handle, inputImageHandle);
478inline void GainModule::Apply(peak_icv_gain_type type,
const float value)
const
481 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_SetValue(m_handle, type, value);
485inline float GainModule::Fetch(peak_icv_gain_type type)
const
489 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetValue(m_handle, type, &value);
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Represents a continuous numeric interval with inclusive lower and upper bounds.
Interface for a hierarchical key-value archive system.
virtual void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
virtual double GetDouble(const std::string &key) const =0
Retrieves a double-precision number by key.
virtual void SetInt(const std::string &key, int64_t value)=0
Stores a 64-bit signed integer.
virtual int64_t GetInt(const std::string &key) const =0
Retrieves a 64-bit signed integer by key.
virtual bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
virtual void SetDouble(const std::string &key, double value)=0
Stores a double-precision floating point number.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
Image pipeline module for applying gain to the image.
float GetGreen() const override
Returns the current green gain.
const char * GetType() const override
Returns the type of the module for serialization purposes.
peak::common::IntervalF GetRange() const
Returns the valid range for the master or color gains.
void SetBlue(float value) override
Sets the blue gain value.
float GetMaster() const override
Returns the current master gain.
void SetGreen(float value) override
Sets the green gain value.
GainModule()
Creates an instance of class GainModule with default values.
GainModule(const GainModule &other)=delete
Copy constructor for class GainModule is deleted.
void SetRed(float value) override
Sets the red gain value.
float GetBlue() const override
Returns the current blue gain.
float GetRed() const override
Returns the current red gain.
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the object's internal state into the provided archive.
peak::icv::Image Process(const peak::icv::Image &input) const
Applies the gains to the input image in place and returns a reference to the modified image.
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
void SetMaster(float value) override
Sets the master gain value.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
GainModule & operator=(const GainModule &other)=delete
Copy assignment for class GainModule is deleted.
void ResetToDefault() override
Resets the gain values to their defaults.
bool IsEnabled() const override
Checks if the module is currently enabled.
Interface for modules that provide gain control functionality.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)