libcamera: controls: Avoid double lookups
Now that the ControlList::get() function returns an instance of std::optional<>, we can replace the ControlList::contains() calls with a nullopt check on the return value of get(). This avoids double lookups of controls through the code base. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
This commit is contained in:
@@ -1143,18 +1143,17 @@ int PipelineHandlerIPU3::registerCameras()
|
||||
&IPU3CameraData::frameStart);
|
||||
|
||||
/* Convert the sensor rotation to a transformation */
|
||||
int32_t rotation = 0;
|
||||
if (data->properties_.contains(properties::Rotation))
|
||||
rotation = *(data->properties_.get(properties::Rotation));
|
||||
else
|
||||
const auto &rotation = data->properties_.get(properties::Rotation);
|
||||
if (!rotation)
|
||||
LOG(IPU3, Warning) << "Rotation control not exposed by "
|
||||
<< cio2->sensor()->id()
|
||||
<< ". Assume rotation 0";
|
||||
|
||||
int32_t rotationValue = rotation.value_or(0);
|
||||
bool success;
|
||||
data->rotationTransform_ = transformFromRotation(rotation, &success);
|
||||
data->rotationTransform_ = transformFromRotation(rotationValue, &success);
|
||||
if (!success)
|
||||
LOG(IPU3, Warning) << "Invalid rotation of " << rotation
|
||||
LOG(IPU3, Warning) << "Invalid rotation of " << rotationValue
|
||||
<< " degrees: ignoring";
|
||||
|
||||
ControlList ctrls = cio2->sensor()->getControls({ V4L2_CID_HFLIP });
|
||||
@@ -1330,8 +1329,9 @@ void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer)
|
||||
|
||||
request->metadata().set(controls::draft::PipelineDepth, 3);
|
||||
/* \todo Actually apply the scaler crop region to the ImgU. */
|
||||
if (request->controls().contains(controls::ScalerCrop))
|
||||
cropRegion_ = *(request->controls().get(controls::ScalerCrop));
|
||||
const auto &scalerCrop = request->controls().get(controls::ScalerCrop);
|
||||
if (scalerCrop)
|
||||
cropRegion_ = *scalerCrop;
|
||||
request->metadata().set(controls::ScalerCrop, cropRegion_);
|
||||
|
||||
if (frameInfos_.tryComplete(info))
|
||||
@@ -1455,13 +1455,12 @@ void IPU3CameraData::frameStart(uint32_t sequence)
|
||||
Request *request = processingRequests_.front();
|
||||
processingRequests_.pop();
|
||||
|
||||
if (!request->controls().contains(controls::draft::TestPatternMode))
|
||||
const auto &testPatternMode = request->controls().get(controls::draft::TestPatternMode);
|
||||
if (!testPatternMode)
|
||||
return;
|
||||
|
||||
const int32_t testPatternMode = *(request->controls().get(controls::draft::TestPatternMode));
|
||||
|
||||
int ret = cio2_.sensor()->setTestPatternMode(
|
||||
static_cast<controls::draft::TestPatternModeEnum>(testPatternMode));
|
||||
static_cast<controls::draft::TestPatternModeEnum>(*testPatternMode));
|
||||
if (ret) {
|
||||
LOG(IPU3, Error) << "Failed to set test pattern mode: "
|
||||
<< ret;
|
||||
@@ -1469,7 +1468,7 @@ void IPU3CameraData::frameStart(uint32_t sequence)
|
||||
}
|
||||
|
||||
request->metadata().set(controls::draft::TestPatternMode,
|
||||
testPatternMode);
|
||||
*testPatternMode);
|
||||
}
|
||||
|
||||
REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3)
|
||||
|
||||
@@ -1717,16 +1717,15 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &
|
||||
* Inform the sensor of the latest colour gains if it has the
|
||||
* V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set).
|
||||
*/
|
||||
if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) {
|
||||
libcamera::Span<const float> colourGains =
|
||||
*controls.get(libcamera::controls::ColourGains);
|
||||
const auto &colourGains = controls.get(libcamera::controls::ColourGains);
|
||||
if (notifyGainsUnity_ && colourGains) {
|
||||
/* The control wants linear gains in the order B, Gb, Gr, R. */
|
||||
ControlList ctrls(sensor_->controls());
|
||||
std::array<int32_t, 4> gains{
|
||||
static_cast<int32_t>(colourGains[1] * *notifyGainsUnity_),
|
||||
static_cast<int32_t>((*colourGains)[1] * *notifyGainsUnity_),
|
||||
*notifyGainsUnity_,
|
||||
*notifyGainsUnity_,
|
||||
static_cast<int32_t>(colourGains[0] * *notifyGainsUnity_)
|
||||
static_cast<int32_t>((*colourGains)[0] * *notifyGainsUnity_)
|
||||
};
|
||||
ctrls.set(V4L2_CID_NOTIFY_GAINS, Span<const int32_t>{ gains });
|
||||
|
||||
@@ -2053,8 +2052,9 @@ Rectangle RPiCameraData::scaleIspCrop(const Rectangle &ispCrop) const
|
||||
|
||||
void RPiCameraData::applyScalerCrop(const ControlList &controls)
|
||||
{
|
||||
if (controls.contains(controls::ScalerCrop)) {
|
||||
Rectangle nativeCrop = *controls.get<Rectangle>(controls::ScalerCrop);
|
||||
const auto &scalerCrop = controls.get<Rectangle>(controls::ScalerCrop);
|
||||
if (scalerCrop) {
|
||||
Rectangle nativeCrop = *scalerCrop;
|
||||
|
||||
if (!nativeCrop.width || !nativeCrop.height)
|
||||
nativeCrop = { 0, 0, 1, 1 };
|
||||
|
||||
Reference in New Issue
Block a user