IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_gain_module.hpp
Go to the documentation of this file.
1
11#pragma once
12
17#include <peak_icv_c/algorithms/preprocessing/peak_icv_gain.h>
18
19namespace peak
20{
21namespace pipeline
22{
23
24namespace detail
25{
26
34class GainModule final : public modules::IGain
35{
36public:
42 GainModule();
43
49 ~GainModule() override;
50
58 GainModule(const GainModule& other) = delete;
59
65 GainModule(GainModule&& other) noexcept;
66
74 GainModule& operator=(const GainModule& other) = delete;
75
81 GainModule& operator=(GainModule&& other) noexcept;
82
90 void SetEnabled(bool enabled) override;
91
99 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
100
112 void Serialize(peak::common::serialization::IArchive& archive) const override;
113
114
129 void Deserialize(const peak::common::serialization::IArchive& archive) override;
130
138 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
139
145 void ResetToDefault() override;
146
159 void SetMaster(float value) override;
160
168 PEAK_COMMON_NO_DISCARD float GetMaster() const override;
169
182 void SetRed(float value) override;
183
191 PEAK_COMMON_NO_DISCARD float GetRed() const override;
192
205 void SetGreen(float value) override;
206
214 PEAK_COMMON_NO_DISCARD float GetGreen() const override;
215
228 void SetBlue(float value) override;
229
237 PEAK_COMMON_NO_DISCARD float GetBlue() const override;
238
250
271
293
294private:
295 void Apply(peak_icv_gain_type type, float value) const;
296
297 PEAK_COMMON_NO_DISCARD float Fetch(peak_icv_gain_type type) const;
298
299 static constexpr int moduleVersion = 1;
300 static constexpr auto masterGainKey = "MasterGain";
301 static constexpr auto redGainKey = "RedGain";
302 static constexpr auto greenGainKey = "GreenGain";
303 static constexpr auto blueGainKey = "BlueGain";
304
305 peak_icv_gain_handle m_handle{};
306 bool m_enabled{ true };
307};
308
310{
312 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Create(&m_handle);
313 });
314}
315
317{
318 if (m_handle != nullptr)
319 {
320 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
321 }
322}
323
324inline GainModule::GainModule(GainModule&& other) noexcept
325{
326 m_handle = std::exchange(other.m_handle, nullptr);
327 m_enabled = other.m_enabled;
328}
329
331{
332 if (this != &other)
333 {
334 if (m_handle != nullptr)
335 {
337 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
338 });
339 }
340
341 m_handle = std::exchange(other.m_handle, nullptr);
342 m_enabled = other.m_enabled;
343 }
344
345 return *this;
346}
347
348inline void GainModule::SetEnabled(const bool enabled)
349{
350 m_enabled = enabled;
351}
352
353inline bool GainModule::IsEnabled() const
354{
355 return m_enabled;
356}
357
359{
360 archive.SetInt("Version", moduleVersion);
361 archive.SetBool("Enabled", IsEnabled());
362
363 archive.SetDouble(masterGainKey, Fetch(PEAK_ICV_GAIN_TYPE_MASTER));
364 archive.SetDouble(redGainKey, Fetch(PEAK_ICV_GAIN_TYPE_RED));
365 archive.SetDouble(greenGainKey, Fetch(PEAK_ICV_GAIN_TYPE_GREEN));
366 archive.SetDouble(blueGainKey, Fetch(PEAK_ICV_GAIN_TYPE_BLUE));
367}
368
370{
371 const auto version = archive.GetInt("Version");
373
374 SetEnabled(archive.GetBool("Enabled"));
375
376 Apply(PEAK_ICV_GAIN_TYPE_MASTER, static_cast<float>(archive.GetDouble(masterGainKey)));
377
378 Apply(PEAK_ICV_GAIN_TYPE_RED, static_cast<float>(archive.GetDouble(redGainKey)));
379 Apply(PEAK_ICV_GAIN_TYPE_GREEN, static_cast<float>(archive.GetDouble(greenGainKey)));
380 Apply(PEAK_ICV_GAIN_TYPE_BLUE, static_cast<float>(archive.GetDouble(blueGainKey)));
381}
382
383inline const char* GainModule::GetType() const
384{
385 return "Gain";
386}
387
389{
390 Apply(PEAK_ICV_GAIN_TYPE_MASTER, 1.0F);
391
392 Apply(PEAK_ICV_GAIN_TYPE_RED, 1.0F);
393 Apply(PEAK_ICV_GAIN_TYPE_GREEN, 1.0F);
394 Apply(PEAK_ICV_GAIN_TYPE_BLUE, 1.0F);
395}
396
397inline void GainModule::SetMaster(const float value)
398{
399 Apply(PEAK_ICV_GAIN_TYPE_MASTER, value);
400}
401
402inline float GainModule::GetMaster() const
403{
404 return Fetch(PEAK_ICV_GAIN_TYPE_MASTER);
405}
406
407inline void GainModule::SetRed(const float value)
408{
409 Apply(PEAK_ICV_GAIN_TYPE_RED, value);
410}
411
412inline float GainModule::GetRed() const
413{
414 return Fetch(PEAK_ICV_GAIN_TYPE_RED);
415}
416
417inline void GainModule::SetGreen(const float value)
418{
419 Apply(PEAK_ICV_GAIN_TYPE_GREEN, value);
420}
421
422inline float GainModule::GetGreen() const
423{
424 return Fetch(PEAK_ICV_GAIN_TYPE_GREEN);
425}
426
427inline void GainModule::SetBlue(const float value)
428{
429 Apply(PEAK_ICV_GAIN_TYPE_BLUE, value);
430}
431
432inline float GainModule::GetBlue() const
433{
434 return Fetch(PEAK_ICV_GAIN_TYPE_BLUE);
435}
436
438{
439 peak_common_interval_f cRange{};
441 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetRange(m_handle, &cRange);
442 });
443
444 return { cRange.minimum, cRange.maximum };
445}
446
448{
449 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
450}
451
453{
454 auto needsProcessing = [&] {
455 bool value{};
457 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_NeedsProcessing(m_handle, &value);
458 });
459 return value;
460 };
461
462 if (!IsEnabled() || !needsProcessing())
463 {
464 return input;
465 }
466
467 const auto& inputImage = input.AnyCast<peak::icv::Image>();
468 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
469
471 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_ProcessInplace(m_handle, inputImageHandle);
472 });
473
474 return peak::common::Any{ inputImage };
475}
476
477inline void GainModule::Apply(peak_icv_gain_type type, const float value) const
478{
480 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_SetValue(m_handle, type, value);
481 });
482}
483
484inline float GainModule::Fetch(peak_icv_gain_type type) const
485{
486 float value{};
488 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetValue(m_handle, type, &value);
489 });
490 return value;
491}
492
493} // namespace detail
494} // namespace pipeline
495} // namespace peak
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.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)