diff options
author | Christian Rauch <Rauch.Christian@gmx.de> | 2022-07-05 10:55:48 +0100 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-07-19 14:21:54 +0300 |
commit | 1c4d4801850559d6f919eef5c2ffbaf7675dbc46 (patch) | |
tree | d1686453c2d047565b9708bc9e03d375fcfa8578 /src/android/camera_capabilities.cpp | |
parent | ef77e2637985b61dc99669b4396647ad13acb204 (diff) |
libcamera: controls: Use std::optional to handle invalid control values
Previously, ControlList::get<T>() would use default constructed objects to
indicate that a ControlList does not have the requested Control. This has
several disadvantages: 1) It requires types to be default constructible,
2) it does not differentiate between a default constructed object and an
object that happens to have the same state as a default constructed object.
std::optional<T> additionally stores the information if the object is valid
or not, and therefore is more expressive than a default constructed object.
Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/android/camera_capabilities.cpp')
-rw-r--r-- | src/android/camera_capabilities.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index 6f197eb8..5304b2da 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -1042,7 +1042,7 @@ int CameraCapabilities::initializeStaticMetadata() /* Sensor static metadata. */ std::array<int32_t, 2> pixelArraySize; { - const Size &size = properties.get(properties::PixelArraySize); + const Size &size = properties.get(properties::PixelArraySize).value_or(Size{}); pixelArraySize[0] = size.width; pixelArraySize[1] = size.height; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, @@ -1050,10 +1050,10 @@ int CameraCapabilities::initializeStaticMetadata() } if (properties.contains(properties::UnitCellSize)) { - const Size &cellSize = properties.get<Size>(properties::UnitCellSize); + const auto &cellSize = properties.get<Size>(properties::UnitCellSize); std::array<float, 2> physicalSize{ - cellSize.width * pixelArraySize[0] / 1e6f, - cellSize.height * pixelArraySize[1] / 1e6f + cellSize->width * pixelArraySize[0] / 1e6f, + cellSize->height * pixelArraySize[1] / 1e6f }; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, physicalSize); @@ -1061,7 +1061,7 @@ int CameraCapabilities::initializeStaticMetadata() { const Span<const Rectangle> &rects = - properties.get(properties::PixelArrayActiveAreas); + properties.get(properties::PixelArrayActiveAreas).value_or(Span<const Rectangle>{}); std::vector<int32_t> data{ static_cast<int32_t>(rects[0].x), static_cast<int32_t>(rects[0].y), @@ -1080,7 +1080,7 @@ int CameraCapabilities::initializeStaticMetadata() /* Report the color filter arrangement if the camera reports it. */ if (properties.contains(properties::draft::ColorFilterArrangement)) { - uint8_t filterArr = properties.get(properties::draft::ColorFilterArrangement); + uint8_t filterArr = *properties.get(properties::draft::ColorFilterArrangement); staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, filterArr); } |