[libcamera-devel,RFC,v2,5/5] android: camera_device: Propagate the requested test pattern mode
diff mbox series

Message ID 20210622023654.969162-5-hiroh@chromium.org
State Accepted
Headers show
Series
  • [libcamera-devel,RFC,v2,1/5] libcamera: camera_sensor: Reverse the key and value of test pattern mode map
Related show

Commit Message

Hirokazu Honda June 22, 2021, 2:36 a.m. UTC
Propagate the requested test pattern mode to libcamera::Camera
through libcamera::Request and also set the android metadata to
the test pattern mode contained by the complete Request.

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

Comments

Jacopo Mondi June 22, 2021, 10:55 a.m. UTC | #1
Hi Hiro,

On Tue, Jun 22, 2021 at 11:36:54AM +0900, Hirokazu Honda wrote:
> Propagate the requested test pattern mode to libcamera::Camera
> through libcamera::Request and also set the android metadata to
> the test pattern mode contained by the complete Request.
>
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> ---
>  src/android/camera_device.cpp | 50 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 8c71fd06..5c2100ad 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1933,16 +1933,57 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)
>  		return 0;
>
>  	/* Translate the Android request settings to libcamera controls. */
> +	ControlList &controls = descriptor->request_->controls();
>  	camera_metadata_ro_entry_t entry;
>  	if (settings.getEntry(ANDROID_SCALER_CROP_REGION, &entry)) {
>  		const int32_t *data = entry.data.i32;
>  		Rectangle cropRegion{ data[0], data[1],
>  				      static_cast<unsigned int>(data[2]),
>  				      static_cast<unsigned int>(data[3]) };
> -		ControlList &controls = descriptor->request_->controls();
>  		controls.set(controls::ScalerCrop, cropRegion);
>  	}
>
> +	if (settings.getEntry(ANDROID_SENSOR_TEST_PATTERN_MODE, &entry)) {
> +		const int32_t data = *entry.data.i32;
> +		switch (data) {
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_OFF:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeOff);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_SOLID_COLOR:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeSolidColor);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeColorBars);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeColorBarsFadeToGray);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_PN9:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModePn9);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_CUSTOM1:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeCustom1);
> +			break;
> +
> +		default:
> +			LOG(HAL, Error)
> +				<< "Unknown test pattern mode: " << data;
> +
> +			return -EINVAL;
> +		}
> +	}
> +
>  	return 0;
>  }
>
> @@ -2429,6 +2470,13 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
>  		resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect);
>  	}
>
> +	if (metadata.contains(controls::draft::TestPatternMode)) {
> +		const int32_t testPatternMode =
> +			metadata.get(controls::draft::TestPatternMode);
> +		resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
> +					 testPatternMode);
> +	}
> +
>  	/*
>  	 * Return the result metadata pack even is not valid: get() will return
>  	 * nullptr.
> --
> 2.32.0.288.g62a8d224e6-goog
>
Laurent Pinchart June 28, 2021, 3:42 a.m. UTC | #2
Hi Hiro,

Thank you for the patch.

On Tue, Jun 22, 2021 at 11:36:54AM +0900, Hirokazu Honda wrote:
> Propagate the requested test pattern mode to libcamera::Camera
> through libcamera::Request and also set the android metadata to
> the test pattern mode contained by the complete Request.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  src/android/camera_device.cpp | 50 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 8c71fd06..5c2100ad 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1933,16 +1933,57 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)
>  		return 0;
>  
>  	/* Translate the Android request settings to libcamera controls. */
> +	ControlList &controls = descriptor->request_->controls();
>  	camera_metadata_ro_entry_t entry;
>  	if (settings.getEntry(ANDROID_SCALER_CROP_REGION, &entry)) {
>  		const int32_t *data = entry.data.i32;
>  		Rectangle cropRegion{ data[0], data[1],
>  				      static_cast<unsigned int>(data[2]),
>  				      static_cast<unsigned int>(data[3]) };
> -		ControlList &controls = descriptor->request_->controls();
>  		controls.set(controls::ScalerCrop, cropRegion);
>  	}
>  
> +	if (settings.getEntry(ANDROID_SENSOR_TEST_PATTERN_MODE, &entry)) {
> +		const int32_t data = *entry.data.i32;
> +		switch (data) {
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_OFF:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeOff);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_SOLID_COLOR:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeSolidColor);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeColorBars);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeColorBarsFadeToGray);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_PN9:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModePn9);
> +			break;
> +
> +		case ANDROID_SENSOR_TEST_PATTERN_MODE_CUSTOM1:
> +			controls.set(controls::draft::TestPatternMode,
> +				     controls::draft::TestPatternModeCustom1);

As ControlList::set() is an inline function, it would be move efficient
to declare a local variable to set the mode, and have a single
controls.set() call after the switch.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +			break;
> +
> +		default:
> +			LOG(HAL, Error)
> +				<< "Unknown test pattern mode: " << data;
> +
> +			return -EINVAL;
> +		}
> +	}
> +
>  	return 0;
>  }
>  
> @@ -2429,6 +2470,13 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
>  		resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect);
>  	}
>  
> +	if (metadata.contains(controls::draft::TestPatternMode)) {
> +		const int32_t testPatternMode =
> +			metadata.get(controls::draft::TestPatternMode);
> +		resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
> +					 testPatternMode);
> +	}
> +
>  	/*
>  	 * Return the result metadata pack even is not valid: get() will return
>  	 * nullptr.

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 8c71fd06..5c2100ad 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1933,16 +1933,57 @@  int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)
 		return 0;
 
 	/* Translate the Android request settings to libcamera controls. */
+	ControlList &controls = descriptor->request_->controls();
 	camera_metadata_ro_entry_t entry;
 	if (settings.getEntry(ANDROID_SCALER_CROP_REGION, &entry)) {
 		const int32_t *data = entry.data.i32;
 		Rectangle cropRegion{ data[0], data[1],
 				      static_cast<unsigned int>(data[2]),
 				      static_cast<unsigned int>(data[3]) };
-		ControlList &controls = descriptor->request_->controls();
 		controls.set(controls::ScalerCrop, cropRegion);
 	}
 
+	if (settings.getEntry(ANDROID_SENSOR_TEST_PATTERN_MODE, &entry)) {
+		const int32_t data = *entry.data.i32;
+		switch (data) {
+		case ANDROID_SENSOR_TEST_PATTERN_MODE_OFF:
+			controls.set(controls::draft::TestPatternMode,
+				     controls::draft::TestPatternModeOff);
+			break;
+
+		case ANDROID_SENSOR_TEST_PATTERN_MODE_SOLID_COLOR:
+			controls.set(controls::draft::TestPatternMode,
+				     controls::draft::TestPatternModeSolidColor);
+			break;
+
+		case ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS:
+			controls.set(controls::draft::TestPatternMode,
+				     controls::draft::TestPatternModeColorBars);
+			break;
+
+		case ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY:
+			controls.set(controls::draft::TestPatternMode,
+				     controls::draft::TestPatternModeColorBarsFadeToGray);
+			break;
+
+		case ANDROID_SENSOR_TEST_PATTERN_MODE_PN9:
+			controls.set(controls::draft::TestPatternMode,
+				     controls::draft::TestPatternModePn9);
+			break;
+
+		case ANDROID_SENSOR_TEST_PATTERN_MODE_CUSTOM1:
+			controls.set(controls::draft::TestPatternMode,
+				     controls::draft::TestPatternModeCustom1);
+			break;
+
+		default:
+			LOG(HAL, Error)
+				<< "Unknown test pattern mode: " << data;
+
+			return -EINVAL;
+		}
+	}
+
 	return 0;
 }
 
@@ -2429,6 +2470,13 @@  CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
 		resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect);
 	}
 
+	if (metadata.contains(controls::draft::TestPatternMode)) {
+		const int32_t testPatternMode =
+			metadata.get(controls::draft::TestPatternMode);
+		resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
+					 testPatternMode);
+	}
+
 	/*
 	 * Return the result metadata pack even is not valid: get() will return
 	 * nullptr.