[libcamera-devel,v2,1/5] libcamera: camera_sensor: Verify flips support
diff mbox series

Message ID 20230114194712.23272-2-jacopo.mondi@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: camera_sensor: Centralize flips handling
Related show

Commit Message

Jacopo Mondi Jan. 14, 2023, 7:47 p.m. UTC
During the camera sensor driver validation, verify if the sensor
supports horizontal and vertical flips and store a flag as
CameraSensor::supportFlips_ class member.

The flag will be later inspected when applying flips.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 include/libcamera/internal/camera_sensor.h |  1 +
 src/libcamera/camera_sensor.cpp            | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

David Plowman Jan. 16, 2023, 11:54 a.m. UTC | #1
Hi Jacopo

Thanks for the patch!

On Sat, 14 Jan 2023 at 19:47, Jacopo Mondi
<jacopo.mondi@ideasonboard.com> wrote:
>
> During the camera sensor driver validation, verify if the sensor
> supports horizontal and vertical flips and store a flag as
> CameraSensor::supportFlips_ class member.
>
> The flag will be later inspected when applying flips.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

This looks good to me! I know that we should at some point consider
handling h and v flips separately, but obviously that will be a
separate future change.

Reviewed-by: David Plowman <david.plowman@raspberrypi.com>

Thanks!
David

> ---
>  include/libcamera/internal/camera_sensor.h |  1 +
>  src/libcamera/camera_sensor.cpp            | 18 +++++++++++++++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index b9f4d7867854..878f3c28a3c9 100644
> --- a/include/libcamera/internal/camera_sensor.h
> +++ b/include/libcamera/internal/camera_sensor.h
> @@ -101,6 +101,7 @@ private:
>         Size pixelArraySize_;
>         Rectangle activeArea_;
>         const BayerFormat *bayerFormat_;
> +       bool supportFlips_;
>
>         ControlList properties_;
>
> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
> index a210aa4fa370..83ac075a4265 100644
> --- a/src/libcamera/camera_sensor.cpp
> +++ b/src/libcamera/camera_sensor.cpp
> @@ -55,7 +55,8 @@ LOG_DEFINE_CATEGORY(CameraSensor)
>   */
>  CameraSensor::CameraSensor(const MediaEntity *entity)
>         : entity_(entity), pad_(UINT_MAX), staticProps_(nullptr),
> -         bayerFormat_(nullptr), properties_(properties::properties)
> +         bayerFormat_(nullptr), supportFlips_(false),
> +         properties_(properties::properties)
>  {
>  }
>
> @@ -247,6 +248,21 @@ int CameraSensor::validateSensorDriver()
>                 }
>         }
>
> +       /*
> +        * Verify if sensor supports horizontal/vertical flips
> +        *
> +        * \todo Handle horizontal and vertical flips independently.
> +        */
> +       const struct v4l2_query_ext_ctrl *hflipInfo = subdev_->controlInfo(V4L2_CID_HFLIP);
> +       const struct v4l2_query_ext_ctrl *vflipInfo = subdev_->controlInfo(V4L2_CID_VFLIP);
> +       if (hflipInfo && !(hflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY) &&
> +           vflipInfo && !(vflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY))
> +               supportFlips_ = true;
> +
> +       if (!supportFlips_)
> +               LOG(CameraSensor, Warning)
> +                       << "Camera sensor does not support horizontal/vertical flip";
> +
>         /*
>          * Make sure the required selection targets are supported.
>          *
> --
> 2.39.0
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index b9f4d7867854..878f3c28a3c9 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -101,6 +101,7 @@  private:
 	Size pixelArraySize_;
 	Rectangle activeArea_;
 	const BayerFormat *bayerFormat_;
+	bool supportFlips_;
 
 	ControlList properties_;
 
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index a210aa4fa370..83ac075a4265 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -55,7 +55,8 @@  LOG_DEFINE_CATEGORY(CameraSensor)
  */
 CameraSensor::CameraSensor(const MediaEntity *entity)
 	: entity_(entity), pad_(UINT_MAX), staticProps_(nullptr),
-	  bayerFormat_(nullptr), properties_(properties::properties)
+	  bayerFormat_(nullptr), supportFlips_(false),
+	  properties_(properties::properties)
 {
 }
 
@@ -247,6 +248,21 @@  int CameraSensor::validateSensorDriver()
 		}
 	}
 
+	/*
+	 * Verify if sensor supports horizontal/vertical flips
+	 *
+	 * \todo Handle horizontal and vertical flips independently.
+	 */
+	const struct v4l2_query_ext_ctrl *hflipInfo = subdev_->controlInfo(V4L2_CID_HFLIP);
+	const struct v4l2_query_ext_ctrl *vflipInfo = subdev_->controlInfo(V4L2_CID_VFLIP);
+	if (hflipInfo && !(hflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY) &&
+	    vflipInfo && !(vflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY))
+		supportFlips_ = true;
+
+	if (!supportFlips_)
+		LOG(CameraSensor, Warning)
+			<< "Camera sensor does not support horizontal/vertical flip";
+
 	/*
 	 * Make sure the required selection targets are supported.
 	 *