IDS peak AFL v2.0.1
Loading...
Searching...
No Matches
peak_afl_generic_auto_white_balance.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
16
18
19#include <functional>
20#include <memory>
21
22namespace peak
23{
24namespace pipeline
25{
26namespace modules
27{
28namespace autofeature
29{
30namespace detail
31{
32class GenericWhiteBalance : public IController
33{
34 using ProcessingCallback = std::function<void()>;
35
36public:
37 explicit GenericWhiteBalance(peak::afl::Manager& manager, ProcessingCallback callback)
38 : IController(manager)
39 , m_controller{ peak::afl::Controller::Create(PEAK_AFL_CONTROLLER_TYPE_WHITE_BALANCE) }
40 , m_processingCallback{ std::move(callback) }
41 , m_skipFrames{ std::make_unique<features::SkipFrames>(m_controller) }
42 , m_roi{ std::make_unique<features::Roi>(m_controller) }
43 {
44 GetManager().AddController(m_controller);
45
46 m_controller->RegisterFinishedCallback([this]() { m_FinishedCallbackManager.TriggerCallbacks(); });
47
48 m_controller->RegisterProcessingCallback([this](peak_afl_process_data* data) {
49 auto* whitebalance = reinterpret_cast<peak_afl_process_data_whitebalance*>(data);
50 if (whitebalance->controller_component != PEAK_AFL_CONTROLLER_WHITEBALANCE_COMPONENT_HOST_GAIN)
51 {
52 return;
53 }
54
55 if (m_processingCallback)
56 {
57 m_processingCallback();
58 }
59 });
60 }
61
62 PEAK_COMMON_NO_DISCARD std::string GetName() const override
63 {
64 return "GenericWhitebalance";
65 }
66
67 void Serialize(peak::common::serialization::IArchive& archive) const override
68 {
69 for (const auto& feature :
70 std::initializer_list<const peak::common::serialization::ISerializable*>{ m_skipFrames.get(), m_roi.get() })
71 {
72 feature->Serialize(archive);
73 }
74
75 archive.SetString("Mode", ToString(GetMode()));
76 }
77
78 void Deserialize(const peak::common::serialization::IArchive& archive) override
79 {
80 for (const auto& feature :
81 std::initializer_list<peak::common::serialization::ISerializable*>{ m_skipFrames.get(), m_roi.get() })
82 {
83 feature->Deserialize(archive);
84 }
85
86 SetMode(detail::ToControllerMode(archive.GetString("Mode")));
87 }
88
89 void SetMode(ControllerMode mode) override
90 {
91 m_controller->SetMode(detail::ToCType(mode));
92 }
93
95 {
96 return detail::ToControllerMode(m_controller->GetMode());
97 }
98
99 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
100 {
101 return GetMode() != ControllerMode::Off;
102 }
103
104 void ResetToDefault() override
105 {
106 SetMode(ControllerMode::Off);
107 SkipFrames().Set(2);
108 Roi().Set({});
109 }
110
111 PEAK_COMMON_NO_DISCARD features::SkipFrames& SkipFrames() const
112 {
113 return *m_skipFrames;
114 }
115
116 PEAK_COMMON_NO_DISCARD features::Roi& Roi() const
117 {
118 return *m_roi;
119 }
120
122 {
124 }
125
126 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
127 {
128 return m_FinishedCallbackManager.RegisterCallback(callback);
129 }
130
131 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
132 {
133 m_FinishedCallbackManager.UnregisterCallback(callbackHandle);
134 }
135
136private:
137 std::shared_ptr<peak::afl::Controller> m_controller;
138
139 peak::core::TTriggerCallbackManager<IController::FinishedCallbackHandle, IController::FinishedCallback>
140 m_FinishedCallbackManager;
141 ProcessingCallback m_processingCallback{};
142
143 std::unique_ptr<features::SkipFrames> m_skipFrames{};
144 std::unique_ptr<features::Roi> m_roi{};
145};
146} // namespace detail
147} // namespace autofeature
148} // namespace modules
149} // namespace pipeline
150} // namespace peak
void AddController(const std::shared_ptr< Controller > &controller)
Add a controller to an automanager.
Definition peak_afl.hpp:2252
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.
Abstract base interface for all automatic controllers.
Definition peak_afl_icontroller.hpp:227
std::function< void()> FinishedCallback
Callback function type for operation completion notifications.
Definition peak_afl_icontroller.hpp:233
virtual std::string GetName() const =0
Gets the unique name of this controller.
peak::afl::Manager & GetManager()
Gets a reference to the API manager.
Definition peak_afl_icontroller.hpp:368
virtual bool IsRunning() const =0
Checks if the controller is currently running.
FinishedCallback * FinishedCallbackHandle
Handle type for managing callback registrations.
Definition peak_afl_icontroller.hpp:238
virtual ControllerType GetType() const =0
Gets the type of this controller.
virtual ControllerMode GetMode() const =0
Gets the current operational mode of this controller.
virtual void ResetToDefault()=0
Resets the controller to its default configuration.
@ PEAK_AFL_CONTROLLER_TYPE_WHITE_BALANCE
Automatic white balance controller.
Definition peak_afl.h:518
@ PEAK_AFL_CONTROLLER_WHITEBALANCE_COMPONENT_HOST_GAIN
Host-based software white balance.
Definition peak_afl.h:1022
ControllerMode
Controller operation mode enumeration.
Definition peak_afl_icontroller.hpp:59
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:40
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:78
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:61
@ WhiteBalance
Automatic white balance controller - manages color correction.
Definition peak_afl_icontroller.hpp:46
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:39
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:37