From 6f6e1bf704feec3a9bcfc1f5490ae82fe8d63065 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Thu, 24 Nov 2022 10:33:06 +0100 Subject: libcamera: camera_sensor: Apply flips at setFormat() Augment the CameraSensor::setFormat() function to configure horizontal and vertical flips before applying the image format on the sensor. Applying flips before format is crucial as they might change the Bayer pattern ordering. To allow users of the CameraSensor class to specify a Transform, add to the V4L2SubdeviceFormat class a 'transform' member, by default initialized to Transform::Identity. Moving the handling of H/V flips to the CameraSensor class allows to remove quite some boilerplate code from the IPU3 and RaspberryPi pipeline handlers. No functional changes intended. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- src/libcamera/camera_sensor.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/libcamera/camera_sensor.cpp') diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index a8668547..b772337e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -751,6 +751,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu .mbus_code = bestCode, .size = *bestSize, .colorSpace = ColorSpace::Raw, + .transform = Transform::Identity, }; return format; @@ -760,12 +761,34 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu * \brief Set the sensor output format * \param[in] format The desired sensor output format * + * If flips are writable they are configured according to the desired Transform. + * Transform::Identity always corresponds to H/V flip being disabled if the + * controls are writable. Flips are set before the new format is applied as + * they can effectively change the Bayer pattern ordering. + * * The ranges of any controls associated with the sensor are also updated. * * \return 0 on success or a negative error code otherwise */ int CameraSensor::setFormat(V4L2SubdeviceFormat *format) { + /* Configure flips if the sensor supports that. */ + if (supportFlips_) { + ControlList flipCtrls(subdev_->controls()); + + flipCtrls.set(V4L2_CID_HFLIP, + static_cast(!!(format->transform & + Transform::HFlip))); + flipCtrls.set(V4L2_CID_VFLIP, + static_cast(!!(format->transform & + Transform::VFlip))); + + int ret = subdev_->setControls(&flipCtrls); + if (ret) + return ret; + } + + /* Apply format on the subdev. */ int ret = subdev_->setFormat(pad_, format); if (ret) return ret; -- cgit v1.2.1