summaryrefslogtreecommitdiff
path: root/src/qcam/dng_writer.cpp
diff options
context:
space:
mode:
authorChristian Rauch <Rauch.Christian@gmx.de>2022-07-05 10:55:48 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-07-19 14:21:54 +0300
commit1c4d4801850559d6f919eef5c2ffbaf7675dbc46 (patch)
treed1686453c2d047565b9708bc9e03d375fcfa8578 /src/qcam/dng_writer.cpp
parentef77e2637985b61dc99669b4396647ad13acb204 (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/qcam/dng_writer.cpp')
-rw-r--r--src/qcam/dng_writer.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
index 34c8df5a..4b5d8276 100644
--- a/src/qcam/dng_writer.cpp
+++ b/src/qcam/dng_writer.cpp
@@ -392,7 +392,7 @@ int DNGWriter::write(const char *filename, const Camera *camera,
TIFFSetField(tif, TIFFTAG_MAKE, "libcamera");
if (cameraProperties.contains(properties::Model)) {
- std::string model = cameraProperties.get(properties::Model);
+ std::string model = *cameraProperties.get(properties::Model);
TIFFSetField(tif, TIFFTAG_MODEL, model.c_str());
/* \todo set TIFFTAG_UNIQUECAMERAMODEL. */
}
@@ -438,16 +438,15 @@ int DNGWriter::write(const char *filename, const Camera *camera,
const double eps = 1e-2;
if (metadata.contains(controls::ColourGains)) {
- Span<const float> const &colourGains = metadata.get(controls::ColourGains);
- if (colourGains[0] > eps && colourGains[1] > eps) {
- wbGain = Matrix3d::diag(colourGains[0], 1, colourGains[1]);
- neutral[0] = 1.0 / colourGains[0]; /* red */
- neutral[2] = 1.0 / colourGains[1]; /* blue */
+ const auto &colourGains = metadata.get(controls::ColourGains);
+ if ((*colourGains)[0] > eps && (*colourGains)[1] > eps) {
+ wbGain = Matrix3d::diag((*colourGains)[0], 1, (*colourGains)[1]);
+ neutral[0] = 1.0 / (*colourGains)[0]; /* red */
+ neutral[2] = 1.0 / (*colourGains)[1]; /* blue */
}
}
if (metadata.contains(controls::ColourCorrectionMatrix)) {
- Span<const float> const &coeffs = metadata.get(controls::ColourCorrectionMatrix);
- Matrix3d ccmSupplied(coeffs);
+ Matrix3d ccmSupplied(*metadata.get(controls::ColourCorrectionMatrix));
if (ccmSupplied.determinant() > eps)
ccm = ccmSupplied;
}
@@ -515,7 +514,8 @@ int DNGWriter::write(const char *filename, const Camera *camera,
uint32_t whiteLevel = (1 << info->bitsPerSample) - 1;
if (metadata.contains(controls::SensorBlackLevels)) {
- Span<const int32_t> levels = metadata.get(controls::SensorBlackLevels);
+ Span<const int32_t> levels =
+ *metadata.get(controls::SensorBlackLevels);
/*
* The black levels control is specified in R, Gr, Gb, B order.
@@ -593,13 +593,13 @@ int DNGWriter::write(const char *filename, const Camera *camera,
TIFFSetField(tif, EXIFTAG_DATETIMEDIGITIZED, strTime);
if (metadata.contains(controls::AnalogueGain)) {
- float gain = metadata.get(controls::AnalogueGain);
+ float gain = *metadata.get(controls::AnalogueGain);
uint16_t iso = std::min(std::max(gain * 100, 0.0f), 65535.0f);
TIFFSetField(tif, EXIFTAG_ISOSPEEDRATINGS, 1, &iso);
}
if (metadata.contains(controls::ExposureTime)) {
- float exposureTime = metadata.get(controls::ExposureTime) / 1e6;
+ float exposureTime = *metadata.get(controls::ExposureTime) / 1e6;
TIFFSetField(tif, EXIFTAG_EXPOSURETIME, exposureTime);
}