mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-13 07:19:45 +03:00
libcamera: Use CameraConfiguration::orientation
Replace the usage of CameraConfiguration::transform with the newly introduced CameraConfiguration::orientation. Rework and rename the CameraSensor::validateTransform(transform) to CameraSensor::computeTransform(orientation), that given the desired image orientation computes the Transform that pipeline handlers should apply to the sensor to obtain it. Port all pipeline handlers to use the newly introduced function. This commit breaks existing applications as it removes the public CameraConfiguration::transform in favour of CameraConfiguration::orientation. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
a28f871836
commit
c65e40b848
11 changed files with 67 additions and 87 deletions
|
@ -24,7 +24,6 @@
|
||||||
#include <libcamera/orientation.h>
|
#include <libcamera/orientation.h>
|
||||||
#include <libcamera/request.h>
|
#include <libcamera/request.h>
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
#include <libcamera/transform.h>
|
|
||||||
|
|
||||||
namespace libcamera {
|
namespace libcamera {
|
||||||
|
|
||||||
|
@ -94,7 +93,6 @@ public:
|
||||||
std::size_t size() const;
|
std::size_t size() const;
|
||||||
|
|
||||||
std::optional<SensorConfiguration> sensorConfig;
|
std::optional<SensorConfiguration> sensorConfig;
|
||||||
Transform transform;
|
|
||||||
Orientation orientation;
|
Orientation orientation;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -33,6 +33,8 @@ class SensorConfiguration;
|
||||||
|
|
||||||
struct CameraSensorProperties;
|
struct CameraSensorProperties;
|
||||||
|
|
||||||
|
enum class Orientation;
|
||||||
|
|
||||||
class CameraSensor : protected Loggable
|
class CameraSensor : protected Loggable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -76,7 +78,7 @@ public:
|
||||||
|
|
||||||
CameraLens *focusLens() { return focusLens_.get(); }
|
CameraLens *focusLens() { return focusLens_.get(); }
|
||||||
|
|
||||||
Transform validateTransform(Transform *transform) const;
|
Transform computeTransform(Orientation *orientation) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string logPrefix() const override;
|
std::string logPrefix() const override;
|
||||||
|
|
|
@ -291,8 +291,7 @@ bool SensorConfiguration::isValid() const
|
||||||
* \brief Create an empty camera configuration
|
* \brief Create an empty camera configuration
|
||||||
*/
|
*/
|
||||||
CameraConfiguration::CameraConfiguration()
|
CameraConfiguration::CameraConfiguration()
|
||||||
: transform(Transform::Identity), orientation(Orientation::Rotate0),
|
: orientation(Orientation::Rotate0), config_({})
|
||||||
config_({})
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,19 +539,6 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF
|
||||||
* from the same image source.
|
* from the same image source.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* \var CameraConfiguration::transform
|
|
||||||
* \brief User-specified transform to be applied to the image
|
|
||||||
*
|
|
||||||
* The transform is a user-specified 2D plane transform that will be applied
|
|
||||||
* to the camera images by the processing pipeline before being handed to
|
|
||||||
* the application.
|
|
||||||
*
|
|
||||||
* The usual 2D plane transforms are allowed here (horizontal/vertical
|
|
||||||
* flips, multiple of 90-degree rotations etc.), but the validate() function
|
|
||||||
* may adjust this field at its discretion if the selection is not supported.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \var CameraConfiguration::orientation
|
* \var CameraConfiguration::orientation
|
||||||
* \brief The desired orientation of the images produced by the camera
|
* \brief The desired orientation of the images produced by the camera
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <libcamera/camera.h>
|
#include <libcamera/camera.h>
|
||||||
|
#include <libcamera/orientation.h>
|
||||||
#include <libcamera/property_ids.h>
|
#include <libcamera/property_ids.h>
|
||||||
|
|
||||||
#include <libcamera/base/utils.h>
|
#include <libcamera/base/utils.h>
|
||||||
|
@ -466,7 +467,7 @@ int CameraSensor::initProperties()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cache the Transform associated with the camera mounting
|
* Cache the Transform associated with the camera mounting
|
||||||
* rotation for later use in validateTransform().
|
* rotation for later use in computeTransform().
|
||||||
*/
|
*/
|
||||||
bool success;
|
bool success;
|
||||||
rotationTransform_ = transformFromRotation(propertyValue, &success);
|
rotationTransform_ = transformFromRotation(propertyValue, &success);
|
||||||
|
@ -1109,69 +1110,64 @@ void CameraSensor::updateControlInfo()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Validate a transform request against the sensor capabilities
|
* \brief Compute the Transform that gives the requested \a orientation
|
||||||
* \param[inout] transform The requested transformation, updated to match
|
* \param[inout] orientation The desired image orientation
|
||||||
* the sensor capabilities
|
|
||||||
*
|
*
|
||||||
* The input \a transform is the transform that the caller wants, and it is
|
* This function computes the Transform that the pipeline handler should apply
|
||||||
* adjusted according to the capabilities of the sensor to represent the
|
* to the CameraSensor to obtain the requested \a orientation.
|
||||||
* "nearest" transform that can actually be delivered.
|
|
||||||
*
|
*
|
||||||
* The returned Transform is the transform applied to the sensor in order to
|
* The intended caller of this function is the validate() implementation of
|
||||||
* produce the input \a transform, It is also validated against the sensor's
|
* pipeline handlers, that pass in the application requested
|
||||||
* ability to perform horizontal and vertical flips.
|
* CameraConfiguration::orientation and obtain a Transform to apply to the
|
||||||
|
* camera sensor, likely at configure() time.
|
||||||
*
|
*
|
||||||
* For example, if the requested \a transform is Transform::Identity and the
|
* If the requested \a orientation cannot be obtained, the \a orientation
|
||||||
* sensor rotation is 180 degrees, the output transform will be
|
* parameter is adjusted to report the current image orientation and
|
||||||
* Transform::Rot180 to correct the images so that they appear to have
|
* Transform::Identity is returned.
|
||||||
* Transform::Identity, but only if the sensor can apply horizontal and vertical
|
|
||||||
* flips.
|
|
||||||
*
|
*
|
||||||
* \return A Transform instance that represents which transformation has been
|
* If the requested \a orientation can be obtained, the function computes a
|
||||||
* applied to the camera sensor
|
* Transform and does not adjust \a orientation.
|
||||||
|
*
|
||||||
|
* Pipeline handlers are expected to verify if \a orientation has been
|
||||||
|
* adjusted by this function and set the CameraConfiguration::status to
|
||||||
|
* Adjusted accordingly.
|
||||||
|
*
|
||||||
|
* \return A Transform instance that applied to the CameraSensor produces images
|
||||||
|
* with \a orientation
|
||||||
*/
|
*/
|
||||||
Transform CameraSensor::validateTransform(Transform *transform) const
|
Transform CameraSensor::computeTransform(Orientation *orientation) const
|
||||||
{
|
{
|
||||||
/*
|
Orientation mountingOrientation = transformToOrientation(rotationTransform_);
|
||||||
* Combine the requested transform to compensate the sensor mounting
|
|
||||||
* rotation.
|
|
||||||
*/
|
|
||||||
Transform combined = rotationTransform_ * *transform;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We combine the platform and user transform, but must "adjust away"
|
* If we cannot do any flips we cannot change the native camera mounting
|
||||||
* any combined result that includes a transposition, as we can't do
|
* orientation.
|
||||||
* those. In this case, flipping only the transpose bit is helpful to
|
|
||||||
* 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)) {
|
if (!supportFlips_) {
|
||||||
/*
|
*orientation = mountingOrientation;
|
||||||
* Flipping the transpose bit in "transform" flips it in the
|
return Transform::Identity;
|
||||||
* combined result too (as it's the last thing that happens),
|
|
||||||
* which is of course clearing it.
|
|
||||||
*/
|
|
||||||
*transform ^= Transform::Transpose;
|
|
||||||
combined &= ~Transform::Transpose;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We also check if the sensor doesn't do h/vflips at all, in which
|
* Now compute the required transform to obtain 'orientation' starting
|
||||||
* case we clear them, and the application will have to do everything.
|
* from the mounting rotation.
|
||||||
|
*
|
||||||
|
* As a note:
|
||||||
|
* orientation / mountingOrientation = transform
|
||||||
|
* mountingOrientation * transform = orientation
|
||||||
*/
|
*/
|
||||||
if (!supportFlips_ && !!combined) {
|
Transform transform = *orientation / mountingOrientation;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the sensor can do no transforms, then combined must be
|
* If transform contains any Transpose we cannot do it, so adjust
|
||||||
* changed to the identity. The only user transform that gives
|
* 'orientation' to report the image native orientation and return Identity.
|
||||||
* rise to this is the inverse of the rotation. (Recall that
|
|
||||||
* combined = rotationTransform * transform.)
|
|
||||||
*/
|
*/
|
||||||
*transform = -rotationTransform_;
|
if (!!(transform & Transform::Transpose)) {
|
||||||
combined = Transform::Identity;
|
*orientation = mountingOrientation;
|
||||||
|
return Transform::Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return combined;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CameraSensor::logPrefix() const
|
std::string CameraSensor::logPrefix() const
|
||||||
|
|
|
@ -187,9 +187,9 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
|
||||||
* rotation and store the final combined transform that configure() will
|
* rotation and store the final combined transform that configure() will
|
||||||
* need to apply to the sensor to save us working it out again.
|
* need to apply to the sensor to save us working it out again.
|
||||||
*/
|
*/
|
||||||
Transform requestedTransform = transform;
|
Orientation requestedOrientation = orientation;
|
||||||
combinedTransform_ = data_->cio2_.sensor()->validateTransform(&transform);
|
combinedTransform_ = data_->cio2_.sensor()->computeTransform(&orientation);
|
||||||
if (transform != requestedTransform)
|
if (orientation != requestedOrientation)
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
|
|
||||||
/* Cap the number of entries to the available streams. */
|
/* Cap the number of entries to the available streams. */
|
||||||
|
|
|
@ -481,9 +481,9 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform requestedTransform = transform;
|
Orientation requestedOrientation = orientation;
|
||||||
Transform combined = sensor->validateTransform(&transform);
|
combinedTransform_ = data_->sensor_->computeTransform(&orientation);
|
||||||
if (transform != requestedTransform)
|
if (orientation != requestedOrientation)
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -595,8 +595,6 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
|
||||||
if (sensorFormat_.size.isNull())
|
if (sensorFormat_.size.isNull())
|
||||||
sensorFormat_.size = sensor->resolution();
|
sensorFormat_.size = sensor->resolution();
|
||||||
|
|
||||||
combinedTransform_ = combined;
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,9 +174,9 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
|
||||||
* rotation and store the final combined transform that configure() will
|
* rotation and store the final combined transform that configure() will
|
||||||
* need to apply to the sensor to save us working it out again.
|
* need to apply to the sensor to save us working it out again.
|
||||||
*/
|
*/
|
||||||
Transform requestedTransform = transform;
|
Orientation requestedOrientation = orientation;
|
||||||
combinedTransform_ = data_->sensor_->validateTransform(&transform);
|
combinedTransform_ = data_->sensor_->computeTransform(&orientation);
|
||||||
if (transform != requestedTransform)
|
if (orientation != requestedOrientation)
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
|
|
||||||
rawStreams_.clear();
|
rawStreams_.clear();
|
||||||
|
@ -1234,7 +1234,8 @@ int CameraData::configureIPA(const CameraConfiguration *config, ipa::RPi::Config
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always send the user transform to the IPA. */
|
/* Always send the user transform to the IPA. */
|
||||||
params.transform = static_cast<unsigned int>(config->transform);
|
Transform transform = config->orientation / Orientation::Rotate0;
|
||||||
|
params.transform = static_cast<unsigned int>(transform);
|
||||||
|
|
||||||
/* Ready the IPA - it must know about the sensor resolution. */
|
/* Ready the IPA - it must know about the sensor resolution. */
|
||||||
ret = ipa_->configure(sensorInfo_, params, result);
|
ret = ipa_->configure(sensorInfo_, params, result);
|
||||||
|
|
|
@ -889,9 +889,9 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
|
||||||
if (config_.empty())
|
if (config_.empty())
|
||||||
return Invalid;
|
return Invalid;
|
||||||
|
|
||||||
Transform requestedTransform = transform;
|
Orientation requestedOrientation = orientation;
|
||||||
combinedTransform_ = sensor->validateTransform(&transform);
|
combinedTransform_ = sensor->computeTransform(&orientation);
|
||||||
if (transform != requestedTransform)
|
if (orientation != requestedOrientation)
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
|
|
||||||
/* Cap the number of entries to the available streams. */
|
/* Cap the number of entries to the available streams. */
|
||||||
|
|
|
@ -111,8 +111,8 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
|
||||||
if (config_.empty())
|
if (config_.empty())
|
||||||
return Invalid;
|
return Invalid;
|
||||||
|
|
||||||
if (transform != Transform::Identity) {
|
if (orientation != Orientation::Rotate0) {
|
||||||
transform = Transform::Identity;
|
orientation = Orientation::Rotate0;
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,8 +128,8 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()
|
||||||
if (config_.empty())
|
if (config_.empty())
|
||||||
return Invalid;
|
return Invalid;
|
||||||
|
|
||||||
if (transform != Transform::Identity) {
|
if (orientation != Orientation::Rotate0) {
|
||||||
transform = Transform::Identity;
|
orientation = Orientation::Rotate0;
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -329,7 +329,6 @@ PYBIND11_MODULE(_libcamera, m)
|
||||||
.def_property_readonly("size", &CameraConfiguration::size)
|
.def_property_readonly("size", &CameraConfiguration::size)
|
||||||
.def_property_readonly("empty", &CameraConfiguration::empty)
|
.def_property_readonly("empty", &CameraConfiguration::empty)
|
||||||
.def_readwrite("sensor_config", &CameraConfiguration::sensorConfig)
|
.def_readwrite("sensor_config", &CameraConfiguration::sensorConfig)
|
||||||
.def_readwrite("transform", &CameraConfiguration::transform);
|
|
||||||
.def_readwrite("orientation", &CameraConfiguration::orientation);
|
.def_readwrite("orientation", &CameraConfiguration::orientation);
|
||||||
|
|
||||||
pyCameraConfigurationStatus
|
pyCameraConfigurationStatus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue