IDS peak ICV v1.2.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
146 void ResetToDefault() override;
147
160 void SetMaster(float value) override;
161
169 PEAK_COMMON_NO_DISCARD float GetMaster() const override;
170
183 void SetRed(float value) override;
184
192 PEAK_COMMON_NO_DISCARD float GetRed() const override;
193
206 void SetGreen(float value) override;
207
215 PEAK_COMMON_NO_DISCARD float GetGreen() const override;
216
229 void SetBlue(float value) override;
230
238 PEAK_COMMON_NO_DISCARD float GetBlue() const override;
239
250 PEAK_COMMON_NO_DISCARD peak::common::IntervalF GetRange() const;
251
271 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
272
293 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
294
295private:
296 void Apply(peak_icv_gain_type type, float value) const;
297
298 PEAK_COMMON_NO_DISCARD float Fetch(peak_icv_gain_type type) const;
299
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";
305
306 peak_icv_gain_handle m_handle{};
307 bool m_enabled{ true };
308};
309
311{
313 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Create(&m_handle);
314 });
315}
316
318{
319 if (m_handle != nullptr)
320 {
321 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
322 }
323}
324
325inline GainModule::GainModule(GainModule&& other) noexcept
326{
327 m_handle = std::exchange(other.m_handle, nullptr);
328 m_enabled = other.m_enabled;
329}
330
332{
333 if (this != &other)
334 {
335 if (m_handle != nullptr)
336 {
338 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_Destroy(m_handle);
339 });
340 }
341
342 m_handle = std::exchange(other.m_handle, nullptr);
343 m_enabled = other.m_enabled;
344 }
345
346 return *this;
347}
348
349inline void GainModule::SetEnabled(const bool enabled)
350{
351 m_enabled = enabled;
352}
353
354inline bool GainModule::IsEnabled() const
355{
356 return m_enabled;
357}
358
360{
361 archive.SetInt("Version", moduleVersion);
362 archive.SetBool("Enabled", IsEnabled());
363
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));
368}
369
371{
372 const auto version = archive.GetInt("Version");
374
375 SetEnabled(archive.GetBool("Enabled"));
376
377 Apply(PEAK_ICV_GAIN_TYPE_MASTER, static_cast<float>(archive.GetDouble(masterGainKey)));
378
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)));
382}
383
384inline const char* GainModule::GetType() const
385{
386 return "Gain";
387}
388
390{
391 Apply(PEAK_ICV_GAIN_TYPE_MASTER, 1.0F);
392
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);
396}
397
398inline void GainModule::SetMaster(const float value)
399{
400 Apply(PEAK_ICV_GAIN_TYPE_MASTER, value);
401}
402
403inline float GainModule::GetMaster() const
404{
405 return Fetch(PEAK_ICV_GAIN_TYPE_MASTER);
406}
407
408inline void GainModule::SetRed(const float value)
409{
410 Apply(PEAK_ICV_GAIN_TYPE_RED, value);
411}
412
413inline float GainModule::GetRed() const
414{
415 return Fetch(PEAK_ICV_GAIN_TYPE_RED);
416}
417
418inline void GainModule::SetGreen(const float value)
419{
420 Apply(PEAK_ICV_GAIN_TYPE_GREEN, value);
421}
422
423inline float GainModule::GetGreen() const
424{
425 return Fetch(PEAK_ICV_GAIN_TYPE_GREEN);
426}
427
428inline void GainModule::SetBlue(const float value)
429{
430 Apply(PEAK_ICV_GAIN_TYPE_BLUE, value);
431}
432
433inline float GainModule::GetBlue() const
434{
435 return Fetch(PEAK_ICV_GAIN_TYPE_BLUE);
436}
437
439{
440 peak_common_interval_f cRange{};
442 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetRange(m_handle, &cRange);
443 });
444
445 return { cRange.minimum, cRange.maximum };
446}
447
449{
450 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
451}
452
454{
455 auto needsProcessing = [&] {
456 bool value{};
458 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_NeedsProcessing(m_handle, &value);
459 });
460 return value;
461 };
462
463 if (!IsEnabled() || !needsProcessing())
464 {
465 return input;
466 }
467
468 const auto& inputImage = input.AnyCast<peak::icv::Image>();
469 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
470
472 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_ProcessInplace(m_handle, inputImageHandle);
473 });
474
475 return peak::common::Any{ inputImage };
476}
477
478inline void GainModule::Apply(peak_icv_gain_type type, const float value) const
479{
481 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_SetValue(m_handle, type, value);
482 });
483}
484
485inline float GainModule::Fetch(peak_icv_gain_type type) const
486{
487 float value{};
489 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Gain_GetValue(m_handle, type, &value);
490 });
491 return value;
492}
493
494} // namespace detail
495} // namespace pipeline
496} // 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.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)