IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_afl_basic_auto_brightness.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
18
21
22#include <utility>
23#include <vector>
24
25namespace peak
26{
27namespace pipeline
28{
29namespace modules
30{
31namespace autofeature
32{
33
53
66PEAK_COMMON_NO_DISCARD inline std::string ToString(AutoBrightnessPolicy policy)
67{
68 switch (policy)
69 {
71 return "ExposureAndGain";
73 return "ExposureOnly";
75 return "GainOnly";
76 }
77
79}
80
81inline std::ostream& operator<<(std::ostream& os, AutoBrightnessPolicy policy)
82{
83 return os << ToString(policy);
84}
85
86namespace detail
87{
88
89PEAK_COMMON_NO_DISCARD inline AutoBrightnessPolicy ToAutoBrightnessPolicy(const std::string& name)
90{
91 if (name == "ExposureAndGain")
92 {
94 }
95 if (name == "ExposureOnly")
96 {
98 }
99 if (name == "GainOnly")
100 {
102 }
103
104 throw peak::afl::error::InternalErrorException("Invalid brightness policy!", PEAK_AFL_STATUS_ERROR);
105}
106} // namespace detail
143{
144 using ProcessingCallback = std::function<void()>;
145
146public:
147 friend BrightnessComponent;
148
165 explicit BasicAutoBrightness(peak::afl::Manager& manager, ProcessingCallback callback)
166 : IController(manager)
167 , m_genericController{ manager, std::move(callback), { BrightnessComponentType::Exposure, BrightnessComponentType::Gain } }
168 {}
169
176 ~BasicAutoBrightness() override = default;
177
197 void SetMode(ControllerMode mode) override
198 {
199 auto* exposureComponent = GetExposureComponent();
200 if (exposureComponent != nullptr)
201 {
202 const auto controllerMode = (m_policy == AutoBrightnessPolicy::ExposureOnly
204 mode :
206
207 exposureComponent->SetMode(controllerMode);
208 }
209
210 auto* gainComponent = GetGainComponent();
211 if (gainComponent != nullptr)
212 {
213 const auto controllerMode = (m_policy == AutoBrightnessPolicy::GainOnly || m_policy == AutoBrightnessPolicy::ExposureAndGain) ?
214 mode :
216
217 gainComponent->SetMode(controllerMode);
218 }
219
220 m_cachedMode = mode;
221 }
222
240 PEAK_COMMON_NO_DISCARD ControllerMode GetMode() const override
241 {
242 auto* const exposureComponent = GetExposureComponent();
243 if (exposureComponent != nullptr)
244 {
245 if (exposureComponent->GetMode() == ControllerMode::Continuous)
246 {
248 }
249 }
250
251 auto* const gainComponent = GetGainComponent();
252 if (gainComponent != nullptr)
253 {
254 return gainComponent->GetMode();
255 }
256
257 return ControllerMode::Off;
258 }
259
271 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
272 {
273 return GetMode() != ControllerMode::Off;
274 }
275
291 {
292 m_genericController.AnalysisAlgorithm().Set(algorithm);
293 }
294
307 {
308 return m_genericController.AnalysisAlgorithm().Get();
309 }
310
326 void SetAutoPercentile(double value)
327 {
328 m_genericController.AutoPercentile().Set(value);
329 }
330
342 PEAK_COMMON_NO_DISCARD double GetAutoPercentile() const
343 {
344 return m_genericController.AutoPercentile().Get();
345 }
346
358 PEAK_COMMON_NO_DISCARD RangeD GetAutoPercentileRange() const
359 {
360 return m_genericController.AutoPercentile().GetRange();
361 }
362
378 void SetAutoTarget(uint32_t value)
379 {
380 m_genericController.AutoTarget().Set(value);
381 }
382
394 PEAK_COMMON_NO_DISCARD uint32_t GetAutoTarget() const
395 {
396 return m_genericController.AutoTarget().Get();
397 }
398
410 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetAutoTargetRange() const
411 {
412 return m_genericController.AutoTarget().GetRange();
413 }
414
431 void SetAutoTolerance(uint32_t value)
432 {
433 m_genericController.AutoTolerance().Set(value);
434 }
435
447 PEAK_COMMON_NO_DISCARD uint32_t GetAutoTolerance() const
448 {
449 return m_genericController.AutoTolerance().Get();
450 }
451
463 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetAutoToleranceRange() const
464 {
465 return m_genericController.AutoTolerance().GetRange();
466 }
467
484 void SetSkipFrames(uint32_t value)
485 {
486 m_genericController.SkipFrames().Set(value);
487 }
488
500 PEAK_COMMON_NO_DISCARD uint32_t GetSkipFrames() const
501 {
502 return m_genericController.SkipFrames().Get();
503 }
504
516 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetSkipFramesRange() const
517 {
518 return m_genericController.SkipFrames().GetRange();
519 }
520
537 {
538 m_genericController.Roi().Set(roi);
539 }
540
552 PEAK_COMMON_NO_DISCARD peak::common::Rectangle GetRoi()
553 {
554 return m_genericController.Roi().Get();
555 }
556
575 {
576 m_policy = policy;
577 SetMode(m_cachedMode);
578 }
579
591 PEAK_COMMON_NO_DISCARD AutoBrightnessPolicy GetPolicy() const
592 {
593 return m_policy;
594 }
595
613 void ResetToDefault() override
614 {
616 m_cachedMode = ControllerMode::Off;
617 m_genericController.ResetToDefault();
618 }
619
637 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
638 {
639 return m_genericController.RegisterFinishedCallback(callback);
640 }
641
654 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
655 {
656 m_genericController.UnregisterFinishedCallback(callbackHandle);
657 }
658
676 void SetExposureLimit(const IntervalD& interval)
677 {
678 auto* component = GetExposureComponent();
679 if (component == nullptr)
680 {
682 "Exposure component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
683 }
684
685 component->SetLimit(interval);
686 }
687
701 PEAK_COMMON_NO_DISCARD IntervalD GetExposureLimit() const
702 {
703 auto* component = GetExposureComponent();
704 if (component != nullptr)
705 {
706 return component->GetLimit();
707 }
708
710 "Exposure component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
711 }
712
730 void SetGainLimit(const IntervalD& interval)
731 {
732 auto* component = GetGainComponent();
733 if (component == nullptr)
734 {
736 "Gain component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
737 }
738
739 component->SetLimit(interval);
740 }
741
755 PEAK_COMMON_NO_DISCARD IntervalD GetGainLimit() const
756 {
757 auto* component = GetGainComponent();
758 if (component != nullptr)
759 {
760 return component->GetLimit();
761 }
762
764 "Gain component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
765 }
766
767private:
769 detail::GenericAutoBrightness m_genericController;
770 ControllerMode m_cachedMode{ ControllerMode::Off };
771
780 BrightnessComponent* GetExposureComponent() const
781 {
782 return m_genericController.GetComponent(BrightnessComponentType::Exposure);
783 }
784
793 BrightnessComponent* GetGainComponent() const
794 {
795 return m_genericController.GetComponent(BrightnessComponentType::Gain);
796 }
797
806 PEAK_COMMON_NO_DISCARD std::string GetName() const override
807 {
808 return "BasicAutoBrightness";
809 }
810
823 void Serialize(peak::common::serialization::IArchive& archive) const override
824 {
825 m_genericController.Serialize(archive);
826
827 archive.SetString("Policy", ToString(m_policy));
828 }
829
843 void Deserialize(const peak::common::serialization::IArchive& archive) override
844 {
845 m_genericController.Deserialize(archive);
846
847 m_cachedMode = GetMode();
848 SetPolicy(detail::ToAutoBrightnessPolicy(archive.GetString("Policy")));
849 }
850
859 PEAK_COMMON_NO_DISCARD ControllerType GetType() const override
860 {
861 return m_genericController.GetType();
862 }
863};
864
865} // namespace autofeature
866} // namespace modules
867} // namespace pipeline
868} // namespace peak
Central coordination object for automatic camera feature control.
Definition peak_afl.hpp:708
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:436
The exception thrown when a functionality is not supported.
Definition peak_afl.hpp:461
virtual std::string GetString(const std::string &key) const =0
Retrieves a string value by key.
virtual void SetString(const std::string &key, const std::string &value)=0
Stores a UTF-8 string.
void SetRoi(const peak::common::Rectangle &roi)
Sets the region of interest (ROI) for selective brightness analysis.
Definition peak_afl_basic_auto_brightness.hpp:536
void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
Unregisters a previously registered completion callback.
Definition peak_afl_basic_auto_brightness.hpp:654
peak::common::RangeU GetSkipFramesRange() const
Gets the valid range for skip frames values.
Definition peak_afl_basic_auto_brightness.hpp:516
peak::common::RangeU GetAutoToleranceRange() const
Gets the valid range for tolerance values.
Definition peak_afl_basic_auto_brightness.hpp:463
BrightnessAnalysisAlgorithm GetAnalysisAlgorithm() const
Gets the current brightness analysis algorithm.
Definition peak_afl_basic_auto_brightness.hpp:306
BasicAutoBrightness(peak::afl::Manager &manager, ProcessingCallback callback)
Constructs a BasicAutoBrightness controller with the specified manager and callback.
Definition peak_afl_basic_auto_brightness.hpp:165
void SetAutoTarget(uint32_t value)
Sets the target brightness value.
Definition peak_afl_basic_auto_brightness.hpp:378
void SetGainLimit(const IntervalD &interval)
Sets the gain limits for the gain component.
Definition peak_afl_basic_auto_brightness.hpp:730
void SetAutoTolerance(uint32_t value)
Sets the tolerance value for brightness stability control.
Definition peak_afl_basic_auto_brightness.hpp:431
ControllerMode GetMode() const override
Gets the current operation mode of the brightness controller.
Definition peak_afl_basic_auto_brightness.hpp:240
uint32_t GetSkipFrames() const
Gets the current number of frames to skip.
Definition peak_afl_basic_auto_brightness.hpp:500
uint32_t GetAutoTolerance() const
Gets the current tolerance value for brightness stability control.
Definition peak_afl_basic_auto_brightness.hpp:447
peak::common::Rectangle GetRoi()
Gets the current region of interest (ROI) for brightness analysis.
Definition peak_afl_basic_auto_brightness.hpp:552
void SetExposureLimit(const IntervalD &interval)
Sets the exposure time limits for the exposure component.
Definition peak_afl_basic_auto_brightness.hpp:676
IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback &callback)
Registers a callback function to be invoked when brightness adjustment completes.
Definition peak_afl_basic_auto_brightness.hpp:637
void SetPolicy(AutoBrightnessPolicy policy)
Sets the brightness adjustment policy.
Definition peak_afl_basic_auto_brightness.hpp:574
uint32_t GetAutoTarget() const
Gets the current target brightness value.
Definition peak_afl_basic_auto_brightness.hpp:394
void SetMode(ControllerMode mode) override
Sets the operation mode for the brightness controller.
Definition peak_afl_basic_auto_brightness.hpp:197
void SetAutoPercentile(double value)
Sets the percentile value for brightness calculation.
Definition peak_afl_basic_auto_brightness.hpp:326
AutoBrightnessPolicy GetPolicy() const
Gets the current brightness adjustment policy.
Definition peak_afl_basic_auto_brightness.hpp:591
double GetAutoPercentile() const
Gets the current percentile value for brightness calculation.
Definition peak_afl_basic_auto_brightness.hpp:342
IntervalD GetGainLimit() const
Gets the current gain limits for the gain component.
Definition peak_afl_basic_auto_brightness.hpp:755
void SetSkipFrames(uint32_t value)
Sets the number of frames to skip for performance optimization.
Definition peak_afl_basic_auto_brightness.hpp:484
IntervalD GetExposureLimit() const
Gets the current exposure time limits for the exposure component.
Definition peak_afl_basic_auto_brightness.hpp:701
void ResetToDefault() override
Resets all controller settings to their default values.
Definition peak_afl_basic_auto_brightness.hpp:613
peak::common::RangeU GetAutoTargetRange() const
Gets the valid range for target brightness values.
Definition peak_afl_basic_auto_brightness.hpp:410
bool IsRunning() const override
Checks if the brightness controller is currently running.
Definition peak_afl_basic_auto_brightness.hpp:271
void SetAnalysisAlgorithm(BrightnessAnalysisAlgorithm algorithm)
Sets the brightness analysis algorithm.
Definition peak_afl_basic_auto_brightness.hpp:290
RangeD GetAutoPercentileRange() const
Gets the valid range for percentile values.
Definition peak_afl_basic_auto_brightness.hpp:358
~BasicAutoBrightness() override=default
Destructor for BasicAutoBrightness.
Abstract base interface for all automatic controllers.
Definition peak_afl_icontroller.hpp:223
@ PEAK_AFL_STATUS_NOT_SUPPORTED
Feature or operation not supported.
Definition peak_afl.h:462
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:416
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:396
ControllerMode
Controller operation mode enumeration.
Definition peak_afl_icontroller.hpp:55
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:36
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:74
@ Continuous
Continuous operation - automatic processing on every frame.
Definition peak_afl_icontroller.hpp:59
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:57
AutoBrightnessPolicy
Auto brightness control policy enumeration.
Definition peak_afl_basic_auto_brightness.hpp:45
BrightnessAnalysisAlgorithm
Brightness analysis algorithm enumeration.
Definition peak_afl_brightness_algorithm.hpp:36
@ GainOnly
Use only gain adjustments, keeping exposure time constant.
Definition peak_afl_basic_auto_brightness.hpp:51
@ ExposureOnly
Use only exposure time adjustments, keeping gain constant.
Definition peak_afl_basic_auto_brightness.hpp:49
@ ExposureAndGain
Use both exposure time and gain adjustments for optimal brightness control.
Definition peak_afl_basic_auto_brightness.hpp:47
@ Gain
Automatic gain component - automatic gain control.
Definition peak_afl_brightness_component.hpp:48
@ Exposure
Exposure time component - controls sensor integration time.
Definition peak_afl_brightness_component.hpp:38
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:231
detail::RangeT< uint32_t > RangeU
Alias for a range of 32-bit unsigned integers.
Definition peak_common_range.hpp:222
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:35
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:33
peak::common::detail::RangeT< double > RangeD
Type alias for double-precision range values.
Definition peak_afl_ifeature.hpp:22
peak::common::detail::IntervalT< double > IntervalD
Type alias for double-precision interval values.
Definition peak_afl_ifeature.hpp:24