From patchwork Mon Jul 1 20:15:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1572 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 62B76619E5 for ; Mon, 1 Jul 2019 22:15:33 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0522F524 for ; Mon, 1 Jul 2019 22:15:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562012132; bh=PIlqXsOiLQbKLx2Pi8tqvo7q5gEcHawdRl3WYeCSX6M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GOidttDp7gDmV+gxp9C4TVsmDYKe8efoYMnyVgt0hkDg0fRWwJgAAOs/It9ufJHLD wXCMScazgtnDu/h8J18AyNojcWa7ononZ9F8bmG1A48A2YbZzHtZ19IS8s3B6VO2xT i1Vy9l13rxcq5KoaqqOf02IjiubnhUlMCWfNBOZE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Jul 2019 23:15:04 +0300 Message-Id: <20190701201504.28487-14-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190701201504.28487-1-laurent.pinchart@ideasonboard.com> References: <20190701201504.28487-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 13/13] [PoC] QCam: Control demo: A SineWave Brightness X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jul 2019 20:15:33 -0000 From: Kieran Bingham 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 Signed-off-by: Laurent Pinchart --- 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 #include #include #include @@ -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 &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 config_; + const ControlInfo *brightness_; + const ControlInfo *gain_; + ViewFinder *viewfinder_; };