@@ -21,6 +21,7 @@
#include <libcamera/color_space.h>
#include <libcamera/controls.h>
+#include <libcamera/transform.h>
#include "libcamera/internal/formats.h"
@@ -49,6 +50,8 @@ public:
void updateControlInfo();
+ Transform setTransform(Transform transform, bool test = false);
+
protected:
V4L2Device(const std::string &deviceNode);
~V4L2Device();
@@ -674,6 +674,43 @@ void V4L2Device::updateControlInfo()
}
}
+/*
+ * \brief Set or test setting the device's flip controls according to \a transform
+ * \param[in] transform Transform to request
+ * \param[in] test If true, merely test what would be set, otherwise actually set it
+ *
+ * This function checks whether a given \a transform is supported by the device's
+ * V4L2_CID_HFLIP and V4L2_CID_VFLIP controls and optionally sets them.
+ *
+ * If \a test is true, it merely checks what the device can accept and returns what
+ * would be programmed into the device. If \a test is false, then the device is
+ * actually programmed with updated flip values too.
+ *
+ * \return The transform that has been or would be set
+ */
+Transform V4L2Device::setTransform(Transform transform, bool test)
+{
+ Transform actualTransform = Transform::Identity;
+ ControlList controls;
+
+ if (controlInfo(V4L2_CID_HFLIP)) {
+ Transform hflip = transform & Transform::HFlip;
+ actualTransform |= hflip;
+ controls.set(V4L2_CID_HFLIP, static_cast<int32_t>(!!hflip));
+ }
+
+ if (controlInfo(V4L2_CID_VFLIP)) {
+ Transform vflip = transform & Transform::VFlip;
+ actualTransform |= vflip;
+ controls.set(V4L2_CID_HFLIP, static_cast<int32_t>(!!vflip));
+ }
+
+ if (!test)
+ setControls(&controls);
+
+ return actualTransform;
+}
+
/*
* \brief Update the value of the first \a count V4L2 controls in \a ctrls using
* values in \a v4l2Ctrls
The setTransform method provides a convenient way of setting the V4L2 device's horizontal and vertical flip controls (where these are available) according to a libcamera Transform. Additionally, the caller can ask not to set the controls but merely find out whether the transform is supported by the device. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> --- include/libcamera/internal/v4l2_device.h | 3 ++ src/libcamera/v4l2_device.cpp | 37 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+)