IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_afl_generic_auto_white_balance.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
12
14
15#include <functional>
16#include <memory>
17
18namespace peak
19{
20namespace pipeline
21{
22namespace modules
23{
24namespace autofeature
25{
26namespace detail
27{
28class GenericWhiteBalance : public IController
29{
30 using ProcessingCallback = std::function<void()>;
31
32public:
33 explicit GenericWhiteBalance(peak::afl::Manager& manager, ProcessingCallback callback)
34 : IController(manager)
35 , m_controller{ peak::afl::Controller::Create(PEAK_AFL_CONTROLLER_TYPE_WHITE_BALANCE) }
36 , m_processingCallback{ std::move(callback) }
37 , m_skipFrames{ std::make_unique<features::SkipFrames>(m_controller) }
38 , m_roi{ std::make_unique<features::Roi>(m_controller) }
39 {
40 GetManager().AddController(m_controller);
41
42 m_controller->RegisterFinishedCallback([this]() { m_FinishedCallbackManager.TriggerCallbacks(); });
43
44 m_controller->RegisterProcessingCallback([this](peak_afl_process_data* data) {
45 auto* whitebalance = reinterpret_cast<peak_afl_process_data_whitebalance*>(data);
46 if (whitebalance->controller_component != PEAK_AFL_CONTROLLER_WHITEBALANCE_COMPONENT_HOST_GAIN)
47 {
48 return;
49 }
50
51 if (m_processingCallback)
52 {
53 m_processingCallback();
54 }
55 });
56 }
57
58 PEAK_COMMON_NO_DISCARD std::string GetName() const override
59 {
60 return "GenericWhitebalance";
61 }
62
63 void Serialize(peak::common::serialization::IArchive& archive) const override
64 {
65 for (const auto& feature :
66 std::initializer_list<const peak::common::serialization::ISerializable*>{ m_skipFrames.get(), m_roi.get() })
67 {
68 feature->Serialize(archive);
69 }
70
71 archive.SetString("Mode", ToString(GetMode()));
72 }
73
74 void Deserialize(const peak::common::serialization::IArchive& archive) override
75 {
76 for (const auto& feature :
77 std::initializer_list<peak::common::serialization::ISerializable*>{ m_skipFrames.get(), m_roi.get() })
78 {
79 feature->Deserialize(archive);
80 }
81
82 SetMode(detail::ToControllerMode(archive.GetString("Mode")));
83 }
84
85 void SetMode(ControllerMode mode) override
86 {
87 m_controller->SetMode(detail::ToCType(mode));
88 }
89
90 PEAK_COMMON_NO_DISCARD ControllerMode GetMode() const override
91 {
92 return detail::ToControllerMode(m_controller->GetMode());
93 }
94
95 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
96 {
97 return GetMode() != ControllerMode::Off;
98 }
99
100 void ResetToDefault() override
101 {
102 SetMode(ControllerMode::Off);
103 SkipFrames().Set(2);
104 Roi().Set({});
105 }
106
107 PEAK_COMMON_NO_DISCARD features::SkipFrames& SkipFrames() const
108 {
109 return *m_skipFrames;
110 }
111
112 PEAK_COMMON_NO_DISCARD features::Roi& Roi() const
113 {
114 return *m_roi;
115 }
116
117 PEAK_COMMON_NO_DISCARD ControllerType GetType() const override
118 {
120 }
121
122 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
123 {
124 return m_FinishedCallbackManager.RegisterCallback(callback);
125 }
126
127 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
128 {
129 m_FinishedCallbackManager.UnregisterCallback(callbackHandle);
130 }
131
132private:
133 std::shared_ptr<peak::afl::Controller> m_controller;
134
135 peak::core::TTriggerCallbackManager<IController::FinishedCallbackHandle, IController::FinishedCallback>
136 m_FinishedCallbackManager;
137 ProcessingCallback m_processingCallback{};
138
139 std::unique_ptr<features::SkipFrames> m_skipFrames{};
140 std::unique_ptr<features::Roi> m_roi{};
141};
142} // namespace detail
143} // namespace autofeature
144} // namespace modules
145} // namespace pipeline
146} // namespace peak
void AddController(const std::shared_ptr< Controller > &controller)
Add a controller to an automanager.
Definition peak_afl.hpp:2299
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:223
std::function< void()> FinishedCallback
Callback function type for operation completion notifications.
Definition peak_afl_icontroller.hpp:229
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:364
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:234
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:515
@ PEAK_AFL_CONTROLLER_WHITEBALANCE_COMPONENT_HOST_GAIN
Host-based software white balance.
Definition peak_afl.h:1019
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
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:57
@ WhiteBalance
Automatic white balance controller - manages color correction.
Definition peak_afl_icontroller.hpp:42
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