17#include <peak_icv_c/algorithms/preprocessing/peak_icv_tone_curve_correction.h>
26class DigitalBlackFeature;
140 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
149 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
184 PEAK_COMMON_NO_DISCARD
float GetGamma()
const;
263#ifndef DOXYGEN_SHOULD_SKIP_THIS
268 PEAK_COMMON_NO_DISCARD
float FetchGamma()
const;
269 void ApplyGamma(
float value)
const;
270 PEAK_COMMON_NO_DISCARD
float FetchDigitalBlack()
const;
271 void ApplyDigitalBlack(
float value)
const;
272 void SetGammaEnabled(
bool enabled);
273 void SetDigitalBlackEnabled(
bool enabled);
274 PEAK_COMMON_NO_DISCARD
bool IsGammaEnabled()
const;
275 PEAK_COMMON_NO_DISCARD
bool IsDigitalBlackEnabled()
const;
277 static constexpr int moduleVersion{ 1 };
278 static constexpr auto gammaKey{
"Gamma" };
279 static constexpr auto digitalBlackKey{
"DigitalBlack" };
281 static constexpr auto gammaDefault = 1.0F;
282 static constexpr auto digitalBlackDefault = 0.0F;
284 peak_icv_tone_curve_correction_handle m_handle{};
285 bool m_gammaEnabled{
true };
286 bool m_digitalBlackEnabled{
true };
288 float m_gamma{ gammaDefault };
289 float m_digitalBlack{ digitalBlackDefault };
295 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_Create(&m_handle);
301 if (m_handle !=
nullptr)
303 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_Destroy(m_handle);
309 m_handle = std::exchange(other.m_handle,
nullptr);
310 m_gammaEnabled = other.m_gammaEnabled;
311 m_gamma = other.m_gamma;
312 m_digitalBlackEnabled = other.m_digitalBlackEnabled;
313 m_digitalBlack = other.m_digitalBlack;
320 if (m_handle !=
nullptr)
323 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_Destroy(m_handle);
327 m_handle = std::exchange(other.m_handle,
nullptr);
328 m_gammaEnabled = other.m_gammaEnabled;
329 m_gamma = other.m_gamma;
330 m_digitalBlackEnabled = other.m_digitalBlackEnabled;
331 m_digitalBlack = other.m_digitalBlack;
339 archive.
SetInt(
"Version", moduleVersion);
344 gammaArchive->SetBool(
"Enabled", m_gammaEnabled);
345 digitalBlackArchive->SetBool(
"Enabled", m_digitalBlackEnabled);
347 gammaArchive->SetDouble(
"Value", m_gamma);
348 digitalBlackArchive->SetDouble(
"Value", m_digitalBlack);
351 archive.
SetArchive(digitalBlackKey, digitalBlackArchive);
356 const auto version = archive.
GetInt(
"Version");
360 const auto gammaArchive = archive.
GetArchive(gammaKey);
361 const auto digitalBlackArchive = archive.
GetArchive(digitalBlackKey);
363 m_gammaEnabled = gammaArchive->GetBool(
"Enabled");
364 m_digitalBlackEnabled = digitalBlackArchive->GetBool(
"Enabled");
366 m_gamma =
static_cast<float>(gammaArchive->GetDouble(
"Value"));
367 m_digitalBlack =
static_cast<float>(digitalBlackArchive->GetDouble(
"Value"));
369 ApplyGamma(m_gammaEnabled ? m_gamma : gammaDefault);
370 ApplyDigitalBlack(m_digitalBlackEnabled ? m_digitalBlack : digitalBlackDefault);
375 SetGammaEnabled(enabled);
376 SetDigitalBlackEnabled(enabled);
381 return m_gammaEnabled || m_digitalBlackEnabled;
386 return "ToneCurveCorrection";
391 ApplyGamma(gammaDefault);
392 m_gamma = gammaDefault;
393 ApplyDigitalBlack(digitalBlackDefault);
394 m_digitalBlack = digitalBlackDefault;
409 peak_common_interval_f cRange{};
411 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_GetGammaRange(m_handle, &cRange);
414 return peak::common::detail::BackendAccessor<peak::common::IntervalF>::CreateInstance(cRange);
419 peak_common_interval_f cRange{};
421 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_GetDigitalBlackRange(m_handle, &cRange);
424 return peak::common::detail::BackendAccessor<peak::common::IntervalF>::CreateInstance(cRange);
439 if (!m_digitalBlackEnabled)
441 return m_digitalBlack;
443 return FetchDigitalBlack();
448 m_digitalBlack = digitalBlack;
450 if (m_digitalBlackEnabled)
452 ApplyDigitalBlack(digitalBlack);
463 auto needsProcessing = [&] {
466 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_NeedsProcessing(m_handle, &value);
487 if (!isSupportedMonoImage && !isSupportedColorImage)
492 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
495 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_ProcessInplace(m_handle, inputImageHandle);
501inline float ToneCurveCorrectionModule::FetchGamma()
const
505 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_GetGamma(m_handle, &value);
510inline void ToneCurveCorrectionModule::ApplyGamma(
float value)
const
513 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_SetGamma(m_handle, value);
517inline float ToneCurveCorrectionModule::FetchDigitalBlack()
const
521 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_GetDigitalBlack(m_handle, &value);
526inline void ToneCurveCorrectionModule::ApplyDigitalBlack(
float value)
const
529 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ToneCurveCorrection_SetDigitalBlack(m_handle, value);
533inline void ToneCurveCorrectionModule::SetGammaEnabled(
bool enabled)
535 m_gammaEnabled = enabled;
537 ApplyGamma(enabled ? m_gamma : gammaDefault);
540inline void ToneCurveCorrectionModule::SetDigitalBlackEnabled(
bool enabled)
542 m_digitalBlackEnabled = enabled;
544 ApplyDigitalBlack(enabled ? m_digitalBlack : digitalBlackDefault);
547inline bool ToneCurveCorrectionModule::IsGammaEnabled()
const
549 return m_gammaEnabled;
552inline bool ToneCurveCorrectionModule::IsDigitalBlackEnabled()
const
554 return m_digitalBlackEnabled;
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 std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive 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 std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
virtual void SetArchive(const std::string &key, const std::shared_ptr< IArchive > &value)=0
Stores a nested archive object.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
peak::common::PixelFormat GetPixelFormat() const
Provides the pixel format of the image.
Tone curve correction is an image pipeline module that applies digital black correction and inverse g...
~ToneCurveCorrectionModule() override
const char * GetType() const override
Returns the type of the module for serialization purposes.
void SetDigitalBlack(float digitalBlack)
Sets the digital black used for digital black correction.
peak::common::IntervalF GetDigitalBlackRange() const
Returns the valid range for the digital black correction value.
ToneCurveCorrectionModule & operator=(const ToneCurveCorrectionModule &other)=delete
Copy assignment for class ToneCurveCorrectionModule is deleted.
void SetGamma(float gamma)
Sets the gamma correction exponent.
float GetGamma() const
Gets the current gamma correction exponent.
peak::common::IntervalF GetGammaRange() const
Returns the valid range for the gamma correction exponent.
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the object's internal state into the provided archive.
ToneCurveCorrectionModule(const ToneCurveCorrectionModule &other)=delete
Copy constructor for class ToneCurveCorrectionModule is deleted.
peak::icv::Image Process(const peak::icv::Image &input) const
Processes the input image and returns a tone curve corrected output image.
void SetEnabled(bool enabled) override
Enables or disables the module.
ToneCurveCorrectionModule()
Creates an instance of class ToneCurveCorrectionModule with default values for gamma and black.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
void ResetToDefault() override
Resets all settings to the default values for gamma and black.
float GetDigitalBlack() const
Gets the current digital black used for correction.
bool IsEnabled() const override
Gets whether this module is currently enabled.
Digital black applies digital black correction to an image.
Gamma applies an inverse gamma transformation to an image.
Interface for a module used within a pipeline.
@ Mono12
Mono 12-Bit pixel format.
@ BGR10p32
BGR 10-Bit packed 32-bit format.
@ Mono16
Mono 16-Bit pixel format.
@ Mono10
Mono 10-Bit pixel format.
@ Mono8
Mono 8-Bit pixel format.
@ RGB10p32
RGB 10-Bit packed 32-bit format.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)