@@ -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]
+
...
@@ -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. */
new file mode 100644
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * array_controls.cpp - Array controls test
+ */
+
+#include <iostream>
+#include <typeinfo>
+#include <vector>
+
+#include <libcamera/camera.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
+#include <libcamera/span.h>
+
+#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<typename T, typename R>
+ int compareValues(const Span<T> &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 float>(const_array));
+ list.set(controls::BayerGains, Span<float>(array));
+ list.set(controls::BayerGains, const_array);
+ list.set(controls::BayerGains, array);
+
+ if (compareValues(list.get(controls::BayerGains), Span<const float>(array)) == TestFail)
+ return TestFail;
+
+ constexpr std::array<float, 4> const_std_array{ 1.3, 0.9, 1.5, 0.8 };
+ std::array<float, 4> std_array{ 1.3, 0.9, 1.5, 0.8 };
+
+ list.set(controls::BayerGains, Span<const float>(const_std_array));
+ list.set(controls::BayerGains, Span<float>(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<float> const_vector{ 1.0, 1.0, 1.0, 1.0 };
+ std::vector<float> vector{ 1.0, 1.0, 1.0, 1.0 };
+
+ list.set(controls::BayerGains, Span<const float>(const_vector));
+ list.set(controls::BayerGains, Span<float>(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)
@@ -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' ],