[libcamera-devel] [PATCH v4 13/13] [PoC] QCam: Control demo: A SineWave Brightness
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Jul 1 22:15:04 CEST 2019
From: Kieran Bingham <kieran.bingham at ideasonboard.com>
As an example of how to add a control to each request, set the
Brightness value with a changing value against the buffer time stamps.
The Brightness will go up and down following a sine wave to visualise
the control effect on the video stream.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
Changes since v2:
- Take controls min/max values into account
---
src/qcam/main_window.cpp | 29 ++++++++++++++++++++++++++++-
src/qcam/main_window.h | 3 +++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 16b123132dd9..bfd3af1e4b92 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -5,6 +5,7 @@
* main_window.cpp - qcam - Main application window
*/
+#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
@@ -21,7 +22,8 @@
using namespace libcamera;
MainWindow::MainWindow(const OptionsParser::Options &options)
- : options_(options), isCapturing_(false)
+ : options_(options), isCapturing_(false),
+ brightness_(nullptr), gain_(nullptr)
{
int ret;
@@ -88,6 +90,14 @@ int MainWindow::openCamera()
std::cout << "Using camera " << camera_->name() << std::endl;
+ const ControlInfoMap &controls = camera_->controls();
+ auto iter = controls.find(Brightness);
+ if (iter != controls.end())
+ brightness_ = &iter->second;
+ iter = controls.find(ManualGain);
+ if (iter != controls.end())
+ gain_ = &iter->second;
+
camera_->requestCompleted.connect(this, &MainWindow::requestComplete);
return 0;
@@ -184,6 +194,14 @@ void MainWindow::stopCapture()
config_.reset();
}
+static int sineWaveValue(Buffer *buffer, const ControlInfo *info)
+{
+ unsigned int millisec = buffer->timestamp() / 1000000;
+ constexpr float rads = 2 * M_PI / 180;
+ return (sin(0.036 * rads * millisec) + 1) / 2 *
+ (info->max().getInt() - info->min().getInt());
+}
+
void MainWindow::requestComplete(Request *request,
const std::map<Stream *, Buffer *> &buffers)
{
@@ -213,6 +231,15 @@ void MainWindow::requestComplete(Request *request,
return;
}
+ /*
+ * A demonstration control, which has a distinct visual effect.
+ * Scale the brightness up and down with a sine wave.
+ */
+ if (brightness_)
+ request->controls()[Brightness] = sineWaveValue(buffer, brightness_);
+ if (gain_)
+ request->controls()[ManualGain] = sineWaveValue(buffer, gain_);
+
request->setBuffers(buffers);
camera_->queueRequest(request);
}
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index fe565cbcb460..0a52399edc74 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -48,6 +48,9 @@ private:
bool isCapturing_;
std::unique_ptr<CameraConfiguration> config_;
+ const ControlInfo *brightness_;
+ const ControlInfo *gain_;
+
ViewFinder *viewfinder_;
};
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list