[libcamera-devel] android: camera_device: Fix value of orientation metadata

Message ID 20200909073833.16465-1-email@uajain.com
State Accepted
Headers show
Series
  • [libcamera-devel] android: camera_device: Fix value of orientation metadata
Related show

Commit Message

Umang Jain Sept. 9, 2020, 7:38 a.m. UTC
Android's orientation metadata cannot have identical numerical
value to libcamera's rotation property. This is due to the fact
that libcamera's rotation property specify the correction angle
in anti-clockwise direction whereas Android's orientation metadata
specifies the value in clockwise direction. Fix that by computing
corresponding value for clockwise direction from libcamera's rotation
property.

Signed-off-by: Umang Jain <email@uajain.com>
---
 src/android/camera_device.cpp | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Laurent Pinchart Sept. 9, 2020, 7:42 a.m. UTC | #1
Hi Umang,

Thank you for the patch.

On Wed, Sep 09, 2020 at 01:08:33PM +0530, Umang Jain wrote:
> Android's orientation metadata cannot have identical numerical
> value to libcamera's rotation property. This is due to the fact
> that libcamera's rotation property specify the correction angle
> in anti-clockwise direction whereas Android's orientation metadata

s/anti-clockwise/anticlockwise/

> specifies the value in clockwise direction. Fix that by computing
> corresponding value for clockwise direction from libcamera's rotation
> property.
> 
> Signed-off-by: Umang Jain <email@uajain.com>
> ---
>  src/android/camera_device.cpp | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 2582991..35aa6c4 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -265,12 +265,17 @@ int CameraDevice::initialize()
>  	}
>  
>  	/*
> -	 * The Android orientation metadata and libcamera rotation property are
> -	 * defined differently but have identical numerical values for Android
> -	 * devices such as phones and tablets.
> +	 * The Android orientation metadata specifies its rotation correction
> +	 * value in clockwise direction whereas libcamera specifies the
> +	 * rotation property in anti-clockwise direction. Read the libcamera's
> +	 * rotation property(anti-clockwise) and compute the corresponding

s/property/property /

> +	 * value for clockwise direction as required by the Android orientation
> +	 * metadata.
>  	 */
> -	if (properties.contains(properties::Rotation))
> -		orientation_ = properties.get(properties::Rotation);
> +	if (properties.contains(properties::Rotation)) {
> +		int libcameraRotation = properties.get(properties::Rotation);

The variable could just be named rotation.

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

> +		orientation_ = (360 - libcameraRotation) % 360;
> +	}
>  
>  	int ret = camera_->acquire();
>  	if (ret) {

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 2582991..35aa6c4 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -265,12 +265,17 @@  int CameraDevice::initialize()
 	}
 
 	/*
-	 * The Android orientation metadata and libcamera rotation property are
-	 * defined differently but have identical numerical values for Android
-	 * devices such as phones and tablets.
+	 * The Android orientation metadata specifies its rotation correction
+	 * value in clockwise direction whereas libcamera specifies the
+	 * rotation property in anti-clockwise direction. Read the libcamera's
+	 * rotation property(anti-clockwise) and compute the corresponding
+	 * value for clockwise direction as required by the Android orientation
+	 * metadata.
 	 */
-	if (properties.contains(properties::Rotation))
-		orientation_ = properties.get(properties::Rotation);
+	if (properties.contains(properties::Rotation)) {
+		int libcameraRotation = properties.get(properties::Rotation);
+		orientation_ = (360 - libcameraRotation) % 360;
+	}
 
 	int ret = camera_->acquire();
 	if (ret) {