summaryrefslogtreecommitdiff
path: root/src/libcamera/camera_sensor.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo.mondi@ideasonboard.com>2022-11-24 10:33:06 +0100
committerJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-01-30 11:04:50 +0100
commit6f6e1bf704feec3a9bcfc1f5490ae82fe8d63065 (patch)
tree1144cde876d28953d34c9973d561b14d1c7e8a90 /src/libcamera/camera_sensor.cpp
parent1a614866a29ce1e3c185d72975ad9fc37c4f99bd (diff)
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 <jacopo.mondi@ideasonboard.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Diffstat (limited to 'src/libcamera/camera_sensor.cpp')
-rw-r--r--src/libcamera/camera_sensor.cpp23
1 files changed, 23 insertions, 0 deletions
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<unsigned int> &mbu
.mbus_code = bestCode,
.size = *bestSize,
.colorSpace = ColorSpace::Raw,
+ .transform = Transform::Identity,
};
return format;
@@ -760,12 +761,34 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &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<int32_t>(!!(format->transform &
+ Transform::HFlip)));
+ flipCtrls.set(V4L2_CID_VFLIP,
+ static_cast<int32_t>(!!(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;