mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 00:25:07 +03:00
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:
parent
1c4d480185
commit
f995ff25a3
7 changed files with 72 additions and 76 deletions
|
@ -1049,8 +1049,8 @@ int CameraCapabilities::initializeStaticMetadata()
|
|||
pixelArraySize);
|
||||
}
|
||||
|
||||
if (properties.contains(properties::UnitCellSize)) {
|
||||
const auto &cellSize = properties.get<Size>(properties::UnitCellSize);
|
||||
const auto &cellSize = properties.get<Size>(properties::UnitCellSize);
|
||||
if (cellSize) {
|
||||
std::array<float, 2> physicalSize{
|
||||
cellSize->width * pixelArraySize[0] / 1e6f,
|
||||
cellSize->height * pixelArraySize[1] / 1e6f
|
||||
|
@ -1079,11 +1079,10 @@ int CameraCapabilities::initializeStaticMetadata()
|
|||
sensitivityRange);
|
||||
|
||||
/* Report the color filter arrangement if the camera reports it. */
|
||||
if (properties.contains(properties::draft::ColorFilterArrangement)) {
|
||||
uint8_t filterArr = *properties.get(properties::draft::ColorFilterArrangement);
|
||||
const auto &filterArr = properties.get(properties::draft::ColorFilterArrangement);
|
||||
if (filterArr)
|
||||
staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,
|
||||
filterArr);
|
||||
}
|
||||
*filterArr);
|
||||
|
||||
const auto &exposureInfo = controlsInfo.find(&controls::ExposureTime);
|
||||
if (exposureInfo != controlsInfo.end()) {
|
||||
|
|
|
@ -305,9 +305,9 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
|
|||
*/
|
||||
const ControlList &properties = camera_->properties();
|
||||
|
||||
if (properties.contains(properties::Location)) {
|
||||
int32_t location = *properties.get(properties::Location);
|
||||
switch (location) {
|
||||
const auto &location = properties.get(properties::Location);
|
||||
if (location) {
|
||||
switch (*location) {
|
||||
case properties::CameraLocationFront:
|
||||
facing_ = CAMERA_FACING_FRONT;
|
||||
break;
|
||||
|
@ -355,9 +355,9 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
|
|||
* value for clockwise direction as required by the Android orientation
|
||||
* metadata.
|
||||
*/
|
||||
if (properties.contains(properties::Rotation)) {
|
||||
int rotation = *properties.get(properties::Rotation);
|
||||
orientation_ = (360 - rotation) % 360;
|
||||
const auto &rotation = properties.get(properties::Rotation);
|
||||
if (rotation) {
|
||||
orientation_ = (360 - *rotation) % 360;
|
||||
if (cameraConfigData && cameraConfigData->rotation != -1 &&
|
||||
orientation_ != cameraConfigData->rotation) {
|
||||
LOG(HAL, Warning)
|
||||
|
@ -1564,25 +1564,24 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
|
|||
const int64_t timestamp = metadata.get(controls::SensorTimestamp).value_or(0);
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, timestamp);
|
||||
|
||||
if (metadata.contains(controls::draft::PipelineDepth)) {
|
||||
uint8_t pipeline_depth = *metadata.get<int32_t>(controls::draft::PipelineDepth);
|
||||
const auto &pipelineDepth = metadata.get(controls::draft::PipelineDepth);
|
||||
if (pipelineDepth)
|
||||
resultMetadata->addEntry(ANDROID_REQUEST_PIPELINE_DEPTH,
|
||||
pipeline_depth);
|
||||
}
|
||||
*pipelineDepth);
|
||||
|
||||
if (metadata.contains(controls::ExposureTime)) {
|
||||
int64_t exposure = *metadata.get(controls::ExposureTime) * 1000ULL;
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, exposure);
|
||||
}
|
||||
const auto &exposureTime = metadata.get(controls::ExposureTime);
|
||||
if (exposureTime)
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME,
|
||||
*exposureTime * 1000ULL);
|
||||
|
||||
if (metadata.contains(controls::FrameDuration)) {
|
||||
int64_t duration = *metadata.get(controls::FrameDuration) * 1000;
|
||||
const auto &frameDuration = metadata.get(controls::FrameDuration);
|
||||
if (frameDuration)
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_FRAME_DURATION,
|
||||
duration);
|
||||
}
|
||||
*frameDuration * 1000);
|
||||
|
||||
if (metadata.contains(controls::ScalerCrop)) {
|
||||
Rectangle crop = *metadata.get(controls::ScalerCrop);
|
||||
const auto &scalerCrop = metadata.get(controls::ScalerCrop);
|
||||
if (scalerCrop) {
|
||||
const Rectangle &crop = *scalerCrop;
|
||||
int32_t cropRect[] = {
|
||||
crop.x, crop.y, static_cast<int32_t>(crop.width),
|
||||
static_cast<int32_t>(crop.height),
|
||||
|
@ -1590,11 +1589,10 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
|
|||
resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect);
|
||||
}
|
||||
|
||||
if (metadata.contains(controls::draft::TestPatternMode)) {
|
||||
const int32_t testPatternMode = *metadata.get(controls::draft::TestPatternMode);
|
||||
const auto &testPatternMode = metadata.get(controls::draft::TestPatternMode);
|
||||
if (testPatternMode)
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
|
||||
testPatternMode);
|
||||
}
|
||||
*testPatternMode);
|
||||
|
||||
/*
|
||||
* Return the result metadata pack even is not valid: get() will return
|
||||
|
|
|
@ -228,11 +228,7 @@ void CameraHalManager::cameraRemoved(std::shared_ptr<Camera> cam)
|
|||
|
||||
int32_t CameraHalManager::cameraLocation(const Camera *cam)
|
||||
{
|
||||
const ControlList &properties = cam->properties();
|
||||
if (!properties.contains(properties::Location))
|
||||
return -1;
|
||||
|
||||
return *properties.get(properties::Location);
|
||||
return cam->properties().get(properties::Location).value_or(-1);
|
||||
}
|
||||
|
||||
CameraDevice *CameraHalManager::cameraDeviceFromHalId(unsigned int id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue