[libcamera-devel,RFC,v2,9/9,PoC] QCam: Control demo: A SineWave Brightness

Message ID 20190621161401.28337-10-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • Libcamera Controls
Related show

Commit Message

Kieran Bingham June 21, 2019, 4:14 p.m. UTC
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@ideasonboard.com>
---
 src/qcam/main_window.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch

diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 8c55941f137b..1449e020c815 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>
@@ -219,6 +220,13 @@  void MainWindow::stopCapture()
 	config_.reset();
 }
 
+int SineWaveValue(Buffer *buffer)
+{
+	unsigned int millisec = buffer->timestamp() / 1000000;
+	constexpr float rads = 2 * M_PI / 180;
+	return sin(0.036 * rads * millisec) * 100;
+}
+
 void MainWindow::requestComplete(Request *request,
 				 const std::map<Stream *, Buffer *> &buffers)
 {
@@ -260,6 +268,14 @@  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.
+	 */
+	/* How do we deal with max/min/defaults etc? */
+	request->controls()[ManualBrightness] = SineWaveValue(buffer);
+	request->controls().update(ManualGain, SineWaveValue(buffer));
+
 	request->setBuffers(buffers);
 	camera_->queueRequest(request);
 }