@@ -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);
}
@@ -48,6 +48,9 @@ private:
bool isCapturing_;
std::unique_ptr<CameraConfiguration> config_;
+ const ControlInfo *brightness_;
+ const ControlInfo *gain_;
+
ViewFinder *viewfinder_;
};