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:
Laurent Pinchart
2022-07-11 01:09:09 +03:00
parent 1c4d480185
commit f995ff25a3
7 changed files with 72 additions and 76 deletions

View File

@@ -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 };