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;
171 PEAK_COMMON_NO_DISCARD
float GetMaster()
const override;
185 void SetRed(
float value)
override;
194 PEAK_COMMON_NO_DISCARD
float GetRed()
const override;
208 void SetGreen(
float value)
override;
217 PEAK_COMMON_NO_DISCARD
float GetGreen()
const override;
231 void SetBlue(
float value)
override;
240 PEAK_COMMON_NO_DISCARD
float GetBlue()
const override;
298 void Apply(peak_icv_gain_type type,
float value)
const;
300 PEAK_COMMON_NO_DISCARD
float Fetch(peak_icv_gain_type type)
const;
302 static constexpr int moduleVersion = 1;
303 static constexpr auto masterGainKey =
"MasterGain";
304 static constexpr auto redGainKey =
"RedGain";
305 static constexpr auto greenGainKey =
"GreenGain";
306 static constexpr auto blueGainKey =
"BlueGain";
308 peak_icv_gain_handle m_handle{};
309 bool m_enabled{
true };
315 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Create(&m_handle);
321 if (m_handle !=
nullptr)
323 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
329 m_handle = std::exchange(other.m_handle,
nullptr);
330 m_enabled = other.m_enabled;
337 if (m_handle !=
nullptr)
340 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
344 m_handle = std::exchange(other.m_handle,
nullptr);
345 m_enabled = other.m_enabled;
363 archive.
SetInt(
"Version", moduleVersion);
366 archive.
SetDouble(masterGainKey, Fetch(PEAK_ICV_GAIN_TYPE_MASTER));
367 archive.
SetDouble(redGainKey, Fetch(PEAK_ICV_GAIN_TYPE_RED));
368 archive.
SetDouble(greenGainKey, Fetch(PEAK_ICV_GAIN_TYPE_GREEN));
369 archive.
SetDouble(blueGainKey, Fetch(PEAK_ICV_GAIN_TYPE_BLUE));
374 const auto version = archive.
GetInt(
"Version");
379 Apply(PEAK_ICV_GAIN_TYPE_MASTER,
static_cast<float>(archive.
GetDouble(masterGainKey)));
381 Apply(PEAK_ICV_GAIN_TYPE_RED,
static_cast<float>(archive.
GetDouble(redGainKey)));
382 Apply(PEAK_ICV_GAIN_TYPE_GREEN,
static_cast<float>(archive.
GetDouble(greenGainKey)));
383 Apply(PEAK_ICV_GAIN_TYPE_BLUE,
static_cast<float>(archive.
GetDouble(blueGainKey)));
393 Apply(PEAK_ICV_GAIN_TYPE_MASTER, 1.0F);
395 Apply(PEAK_ICV_GAIN_TYPE_RED, 1.0F);
396 Apply(PEAK_ICV_GAIN_TYPE_GREEN, 1.0F);
397 Apply(PEAK_ICV_GAIN_TYPE_BLUE, 1.0F);
402 Apply(PEAK_ICV_GAIN_TYPE_MASTER, value);
407 return Fetch(PEAK_ICV_GAIN_TYPE_MASTER);
412 Apply(PEAK_ICV_GAIN_TYPE_RED, value);
417 return Fetch(PEAK_ICV_GAIN_TYPE_RED);
422 Apply(PEAK_ICV_GAIN_TYPE_GREEN, value);
427 return Fetch(PEAK_ICV_GAIN_TYPE_GREEN);
432 Apply(PEAK_ICV_GAIN_TYPE_BLUE, value);
437 return Fetch(PEAK_ICV_GAIN_TYPE_BLUE);
442 peak_common_interval_f cRange{};
444 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetRange(m_handle, &cRange);
447 return { cRange.minimum, cRange.maximum };
457 auto needsProcessing = [&] {
460 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_NeedsProcessing(m_handle, &value);
471 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
474 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_ProcessInplace(m_handle, inputImageHandle);
480inline void GainModule::Apply(peak_icv_gain_type type,
const float value)
const
483 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_SetValue(m_handle, type, value);
487inline float GainModule::Fetch(peak_icv_gain_type type)
const
491 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
Enables or disables the 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
Gets whether this 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)