From patchwork Sat Feb 29 16:42:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2947 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A73DD627AB for ; Sat, 29 Feb 2020 17:43:32 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 38742A28; Sat, 29 Feb 2020 17:43:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994612; bh=0dCmsokvOcYVUCdhUmP3Cy39eRfW/7lNRK5xMNbW5WI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bufR7iu9YzbfkIPUlFim0BBc+VIdptVZ9o0guabSFkzrIaxfCuPOrBMQVzyIoAe3z 27UxqzZUXaRDNsfaLfT2/rBD3KrmXRCoIAkHKQdVXhlcvvJmbnVc7gTXcLCAo9gBqB u1YqMsDx15C2Z4GzWdC9xm+7VKZBhGhU39UM/N00= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:52 +0200 Message-Id: <20200229164254.23604-30-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 29/31] DNI: test array controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Feb 2020 16:43:36 -0000 From: Jacopo Mondi Define a fictional array control and register it in the VIMC pipeline handler. Add a test to exercise it. Do not include, just a proof of concept. The test could be included once we'll have real array controls defined. Signed-off-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/libcamera/control_ids.yaml | 5 ++ src/libcamera/pipeline/vimc.cpp | 5 ++ test/controls/array_controls.cpp | 107 +++++++++++++++++++++++++++++++ test/controls/meson.build | 1 + 4 files changed, 118 insertions(+) create mode 100644 test/controls/array_controls.cpp diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml index 4befec746a59..14adb0dc78e8 100644 --- a/src/libcamera/control_ids.yaml +++ b/src/libcamera/control_ids.yaml @@ -50,4 +50,9 @@ controls: type: int32_t description: Specify a fixed gain parameter + - BayerGains: + type: float + description: Gains to apply to the four Bayer colour components for white balance + size: [4] + ... diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 5d3d12fef30b..3fa4d222e06e 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -451,6 +451,11 @@ int VimcCameraData::init(MediaDevice *media) ctrls.emplace(id, range); } + /* Register a compound control. */ + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::BayerGains), + std::forward_as_tuple(0.5f, 4.0f)); + controlInfo_ = std::move(ctrls); /* Initialize the camera properties. */ diff --git a/test/controls/array_controls.cpp b/test/controls/array_controls.cpp new file mode 100644 index 000000000000..b75219d82c37 --- /dev/null +++ b/test/controls/array_controls.cpp @@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * array_controls.cpp - Array controls test + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "camera_controls.h" + +#include "camera_test.h" +#include "test.h" + +using namespace std; +using namespace libcamera; + +class ArrayControlsTest : public CameraTest, public Test +{ +public: + ArrayControlsTest() + : CameraTest("VIMC Sensor B") + { + } + +protected: + int init() override + { + return status_; + } + + template + int compareValues(const Span &span, const R &value) + { + if (value.size() != span.size()) { + cerr << "set(" << typeid(T).name() << ") and get() dimension mismatch" << endl; + return TestFail; + } + + for (unsigned int i = 0; i < value.size(); ++i) { + if (value[i] != span[i]) { + cerr << "set(" << typeid(T).name() << ") and get() value mismatch" << endl; + return TestFail; + } + } + + return TestPass; + } + + int run() override + { + CameraControlValidator validator(camera_.get()); + ControlList list(controls::controls, &validator); + + /* + * Test array control get and set. set() is tested using + * std::initializer_list, std::array, std::vector, and Span() + * constructed from both an array and a vector as from a plain + * C array. Const and non-const versions are compile-tested. + */ + constexpr float const_array[4] = { 1.1, 1.0, 1.2, 0.9 }; + float array[4] = { 1.1, 1.0, 1.2, 0.9 }; + + list.set(controls::BayerGains, { 1.1f, 1.0f, 1.2f, 0.9f }); + list.set(controls::BayerGains, Span(const_array)); + list.set(controls::BayerGains, Span(array)); + list.set(controls::BayerGains, const_array); + list.set(controls::BayerGains, array); + + if (compareValues(list.get(controls::BayerGains), Span(array)) == TestFail) + return TestFail; + + constexpr std::array const_std_array{ 1.3, 0.9, 1.5, 0.8 }; + std::array std_array{ 1.3, 0.9, 1.5, 0.8 }; + + list.set(controls::BayerGains, Span(const_std_array)); + list.set(controls::BayerGains, Span(std_array)); + list.set(controls::BayerGains, const_std_array); + list.set(controls::BayerGains, std_array); + + if (compareValues(list.get(controls::BayerGains), std_array) == TestFail) + return TestFail; + + const std::vector const_vector{ 1.0, 1.0, 1.0, 1.0 }; + std::vector vector{ 1.0, 1.0, 1.0, 1.0 }; + + list.set(controls::BayerGains, Span(const_vector)); + list.set(controls::BayerGains, Span(vector)); + list.set(controls::BayerGains, const_vector); + list.set(controls::BayerGains, vector); + + if (compareValues(list.get(controls::BayerGains), const_vector) == TestFail) + return TestFail; + + return TestPass; + } +}; + +TEST_REGISTER(ArrayControlsTest) diff --git a/test/controls/meson.build b/test/controls/meson.build index f0850df28c8a..9d9b6ed1d666 100644 --- a/test/controls/meson.build +++ b/test/controls/meson.build @@ -1,4 +1,5 @@ control_tests = [ + [ 'array_controls', 'array_controls.cpp'], [ 'control_info', 'control_info.cpp' ], [ 'control_list', 'control_list.cpp' ], [ 'control_range', 'control_range.cpp' ],