libcamera: camera_sensor: Cache rotationTransform_

The rotationTransform_ depends on a V4L2 control whose value does not
change for the whole lifetime of the camera.

Instead of re-calculating it everytime the camera is configured, cache
it at properties initialization time.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Jacopo Mondi 2023-10-19 16:01:22 +02:00 committed by Laurent Pinchart
parent b5f5a89bc3
commit 042649f044
2 changed files with 33 additions and 24 deletions

View file

@ -112,6 +112,7 @@ private:
Rectangle activeArea_; Rectangle activeArea_;
const BayerFormat *bayerFormat_; const BayerFormat *bayerFormat_;
bool supportFlips_; bool supportFlips_;
Transform rotationTransform_;
ControlList properties_; ControlList properties_;

View file

@ -462,18 +462,36 @@ int CameraSensor::initProperties()
const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION);
if (rotationControl != controls.end()) { if (rotationControl != controls.end()) {
/*
* validateTransform() compensates for the mounting rotation.
* However, as a camera sensor can only compensate rotations
* by applying H/VFlips, only rotation of 180 degrees are
* automatically compensated. The other valid rotations (Rot90
* and Rot270) require transposition, which the camera sensor
* cannot perform, so leave them untouched.
*/
propertyValue = rotationControl->second.def().get<int32_t>(); propertyValue = rotationControl->second.def().get<int32_t>();
/*
* Cache the Transform associated with the camera mounting
* rotation for later use in validateTransform().
*/
bool success;
rotationTransform_ = transformFromRotation(propertyValue, &success);
if (!success) {
LOG(CameraSensor, Warning)
<< "Invalid rotation of " << propertyValue
<< " degrees - ignoring";
rotationTransform_ = Transform::Identity;
}
/*
* Adjust property::Rotation as validateTransform() compensates
* for the mounting rotation. However, as a camera sensor can
* only compensate rotations by applying H/VFlips, only rotation
* of 180 degrees are automatically compensated. The other valid
* rotations (Rot90 and Rot270) require transposition, which the
* camera sensor cannot perform, so leave them untouched.
*/
if (propertyValue == 180 && supportFlips_) if (propertyValue == 180 && supportFlips_)
propertyValue = 0; propertyValue = 0;
properties_.set(properties::Rotation, propertyValue); properties_.set(properties::Rotation, propertyValue);
} else {
LOG(CameraSensor, Warning)
<< "Rotation control not available, default to 0 degrees";
rotationTransform_ = Transform::Identity;
} }
properties_.set(properties::PixelArraySize, pixelArraySize_); properties_.set(properties::PixelArraySize, pixelArraySize_);
@ -1123,21 +1141,11 @@ void CameraSensor::updateControlInfo()
*/ */
Transform CameraSensor::validateTransform(Transform *transform) const Transform CameraSensor::validateTransform(Transform *transform) const
{ {
/* Adjust the requested transform to compensate the sensor mounting rotation. */ /*
const ControlInfoMap &controls = subdev_->controls(); * Combine the requested transform to compensate the sensor mounting
int rotation = 0; * rotation.
*/
const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); Transform combined = *transform * rotationTransform_;
if (rotationControl != controls.end())
rotation = rotationControl->second.def().get<int32_t>();
bool success;
Transform rotationTransform = transformFromRotation(rotation, &success);
if (!success)
LOG(CameraSensor, Warning) << "Invalid rotation of " << rotation
<< " degrees - ignoring";
Transform combined = *transform * rotationTransform;
/* /*
* We combine the platform and user transform, but must "adjust away" * We combine the platform and user transform, but must "adjust away"
@ -1168,7 +1176,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const
* rise to this is the inverse of the rotation. (Recall that * rise to this is the inverse of the rotation. (Recall that
* combined = transform * rotationTransform.) * combined = transform * rotationTransform.)
*/ */
*transform = -rotationTransform; *transform = -rotationTransform_;
combined = Transform::Identity; combined = Transform::Identity;
} }