[libcamera-devel,v2,7/7] android: CameraDevice: Report queried test pattern modes
diff mbox series

Message ID 20210421042346.312854-8-hiroh@chromium.org
State Superseded
Headers show
Series
  • Report Android HAL client test pattern modes
Related show

Commit Message

Hirokazu Honda April 21, 2021, 4:23 a.m. UTC
Report test pattern modes obtained by Camera::controls().

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_device.cpp | 46 ++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 3d5b5f24..a96bc09b 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1090,12 +1090,50 @@  const camera_metadata_t *CameraDevice::getStaticMetadata()
 
 	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation_, 1);
 
-	std::vector<int32_t> testPatterModes = {
-		ANDROID_SENSOR_TEST_PATTERN_MODE_OFF,
+	const auto &testPatternsInfo =
+		controlsInfo.find(&controls::draft::TestPatternMode);
+	std::vector<int32_t> testPatternModes = {
+		ANDROID_SENSOR_TEST_PATTERN_MODE_OFF
 	};
+	if (testPatternsInfo != controlsInfo.end()) {
+		const auto &values = testPatternsInfo->second.values();
+		if (!values.empty()) {
+			testPatternModes.clear();
+			for (const auto &value : values) {
+				int aValue = -1;
+				switch (value.get<int32_t>()) {
+				case controls::draft::TestPatternModeOff:
+					aValue = ANDROID_SENSOR_TEST_PATTERN_MODE_OFF;
+					break;
+				case controls::draft::TestPatternModeSolidColor:
+					aValue = ANDROID_SENSOR_TEST_PATTERN_MODE_SOLID_COLOR;
+					break;
+				case controls::draft::TestPatternModeColorBars:
+					aValue = ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS;
+					break;
+				case controls::draft::TestPatternModeColorBarsFadeToGray:
+					aValue = ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY;
+					break;
+				case controls::draft::TestPatternModePn9:
+					aValue = ANDROID_SENSOR_TEST_PATTERN_MODE_PN9;
+					break;
+				case controls::draft::TestPatternModeCustom1:
+					aValue = ANDROID_SENSOR_TEST_PATTERN_MODE_CUSTOM1;
+					break;
+				default:
+					LOG(HAL, Error)
+						<< "Unknown test pattern mode: "
+						<< value.get<int32_t>();
+					continue;
+				}
+
+				testPatternModes.push_back(aValue);
+			}
+		}
+	}
 	staticMetadata_->addEntry(ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES,
-				  testPatterModes.data(),
-				  testPatterModes.size());
+				  testPatternModes.data(),
+				  testPatternModes.size());
 
 	uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN;
 	staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE,