IDS peak ICV v1.3.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
130 void Deserialize(const peak::common::serialization::IArchive& archive) override;
131
139 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
140
148 void ResetToDefault() override;
149
162 void SetMaster(float value) override;
163
171 PEAK_COMMON_NO_DISCARD float GetMaster() const override;
172
185 void SetRed(float value) override;
186
194 PEAK_COMMON_NO_DISCARD float GetRed() const override;
195
208 void SetGreen(float value) override;
209
217 PEAK_COMMON_NO_DISCARD float GetGreen() const override;
218
231 void SetBlue(float value) override;
232
240 PEAK_COMMON_NO_DISCARD float GetBlue() const override;
241
252 PEAK_COMMON_NO_DISCARD peak::common::IntervalF GetRange() const;
253
273 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
274
295 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
296
297private:
298 void Apply(peak_icv_gain_type type, float value) const;
299
300 PEAK_COMMON_NO_DISCARD float Fetch(peak_icv_gain_type type) const;
301
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";
307
308 peak_icv_gain_handle m_handle{};
309 bool m_enabled{ true };
310};
311
313{
315 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Create(&m_handle);
316 });
317}
318
320{
321 if (m_handle != nullptr)
322 {
323 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
324 }
325}
326
327inline GainModule::GainModule(GainModule&& other) noexcept
328{
329 m_handle = std::exchange(other.m_handle, nullptr);
330 m_enabled = other.m_enabled;
331}
332
334{
335 if (this != &other)
336 {
337 if (m_handle != nullptr)
338 {
340 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
341 });
342 }
343
344 m_handle = std::exchange(other.m_handle, nullptr);
345 m_enabled = other.m_enabled;
346 }
347
348 return *this;
349}
350
351inline void GainModule::SetEnabled(const bool enabled)
352{
353 m_enabled = enabled;
354}
355
356inline bool GainModule::IsEnabled() const
357{
358 return m_enabled;
359}
360
362{
363 archive.SetInt("Version", moduleVersion);
364 archive.SetBool("Enabled", IsEnabled());
365
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));
370}
371
373{
374 const auto version = archive.GetInt("Version");
376
377 SetEnabled(archive.GetBool("Enabled"));
378
379 Apply(PEAK_ICV_GAIN_TYPE_MASTER, static_cast<float>(archive.GetDouble(masterGainKey)));
380
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)));
384}
385
386inline const char* GainModule::GetType() const
387{
388 return "Gain";
389}
390
392{
393 Apply(PEAK_ICV_GAIN_TYPE_MASTER, 1.0F);
394
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);
398}
399
400inline void GainModule::SetMaster(const float value)
401{
402 Apply(PEAK_ICV_GAIN_TYPE_MASTER, value);
403}
404
405inline float GainModule::GetMaster() const
406{
407 return Fetch(PEAK_ICV_GAIN_TYPE_MASTER);
408}
409
410inline void GainModule::SetRed(const float value)
411{
412 Apply(PEAK_ICV_GAIN_TYPE_RED, value);
413}
414
415inline float GainModule::GetRed() const
416{
417 return Fetch(PEAK_ICV_GAIN_TYPE_RED);
418}
419
420inline void GainModule::SetGreen(const float value)
421{
422 Apply(PEAK_ICV_GAIN_TYPE_GREEN, value);
423}
424
425inline float GainModule::GetGreen() const
426{
427 return Fetch(PEAK_ICV_GAIN_TYPE_GREEN);
428}
429
430inline void GainModule::SetBlue(const float value)
431{
432 Apply(PEAK_ICV_GAIN_TYPE_BLUE, value);
433}
434
435inline float GainModule::GetBlue() const
436{
437 return Fetch(PEAK_ICV_GAIN_TYPE_BLUE);
438}
439
441{
442 peak_common_interval_f cRange{};
444 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetRange(m_handle, &cRange);
445 });
446
447 return { cRange.minimum, cRange.maximum };
448}
449
451{
452 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
453}
454
456{
457 auto needsProcessing = [&] {
458 bool value{};
460 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_NeedsProcessing(m_handle, &value);
461 });
462 return value;
463 };
464
465 if (!IsEnabled() || !needsProcessing())
466 {
467 return input;
468 }
469
470 const auto& inputImage = input.AnyCast<peak::icv::Image>();
471 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
472
474 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_ProcessInplace(m_handle, inputImageHandle);
475 });
476
477 return peak::common::Any{ inputImage };
478}
479
480inline void GainModule::Apply(peak_icv_gain_type type, const float value) const
481{
483 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_SetValue(m_handle, type, value);
484 });
485}
486
487inline float GainModule::Fetch(peak_icv_gain_type type) const
488{
489 float value{};
491 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetValue(m_handle, type, &value);
492 });
493 return value;
494}
495
496} // namespace detail
497} // namespace pipeline
498} // 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
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)