summaryrefslogtreecommitdiff
path: root/src/libcamera/camera_sensor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcamera/camera_sensor.cpp')
-rw-r--r--src/libcamera/camera_sensor.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 3ca9d1c7..5d4cf79c 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -988,6 +988,65 @@ void CameraSensor::updateControlInfo()
* connected to the sensor
*/
+/**
+ * \brief Validate a transform request against the sensor capabilities
+ * \param[inout] transform The requested transformation, updated to match
+ * the sensor capabilities
+ *
+ * The requested \a transform is adjusted against the sensor rotation and its
+ * capabilities.
+ *
+ * In example, if the requested \a transform is Transform::Identity and the
+ * sensor rotation is 180 degrees, the resulting transform returned by the
+ * function is Transform::Rot180 to automatically correct the image, but only if
+ * the sensor can actually apply horizontal and vertical flips.
+ *
+ * \return A Transform instance that represents how \a transform is applied to
+ * the camera sensor
+ */
+Transform CameraSensor::validateTransform(Transform *transform) const
+{
+ /* Adjust the requested transform to the sensor rotation. */
+ int32_t rotation = properties().get(properties::Rotation).value_or(0);
+ bool success;
+
+ Transform rotationTransform = transformFromRotation(rotation, &success);
+ if (!success)
+ LOG(CameraSensor, Warning) << "Invalid rotation of " << rotation
+ << " degrees - ignoring";
+
+ Transform combined = *transform * rotationTransform;
+
+ /*
+ * The camera sensor cannot do Transpose. Adjust any combined result
+ * that includes a transpose by flipping the transpose bit to notify
+ * applications they either get the transform they requested, or have
+ * to do a simple transpose themselves (they don't have to worry about
+ * the other possible cases).
+ */
+ if (!!(combined & Transform::Transpose)) {
+ /*
+ * Flipping the transpose bit in "transform" flips it in the
+ * combined result too (as it's the last thing that happens),
+ * which is of course clearing it.
+ */
+ *transform ^= Transform::Transpose;
+ combined &= ~Transform::Transpose;
+ }
+
+ /*
+ * If the sensor can do no transforms, then combined must be changed to
+ * the identity and the sensor rotation must be cleared from the
+ * requested "transform".
+ */
+ if (!supportFlips_ && !!combined) {
+ *transform = -rotationTransform;
+ combined = Transform::Identity;
+ }
+
+ return combined;
+}
+
std::string CameraSensor::logPrefix() const
{
return "'" + entity_->name() + "'";