[libcamera-devel] [RFC PATCH 1/4] libcamera: Add a camera lens properties database

Jean-Michel Hautbois jeanmichel.hautbois at ideasonboard.com
Thu Jun 9 08:03:03 CEST 2022


Similarly to the sensors, we may want to use static properties based on
tuning or any other way to properly use a given lens model.

Re-use the cameraSensorProperties infrastructure in a simpler way for
now.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois at ideasonboard.com>
---
 .../internal/camera_lens_properties.h         | 22 +++++++
 src/libcamera/camera_lens_properties.cpp      | 59 +++++++++++++++++++
 src/libcamera/meson.build                     |  1 +
 3 files changed, 82 insertions(+)
 create mode 100644 include/libcamera/internal/camera_lens_properties.h
 create mode 100644 src/libcamera/camera_lens_properties.cpp

diff --git a/include/libcamera/internal/camera_lens_properties.h b/include/libcamera/internal/camera_lens_properties.h
new file mode 100644
index 00000000..73982550
--- /dev/null
+++ b/include/libcamera/internal/camera_lens_properties.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Google Inc.
+ *
+ * camera_lens_properties.h - Database of camera lens properties
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+
+#include <libcamera/control_ids.h>
+#include <libcamera/geometry.h>
+
+namespace libcamera {
+
+struct CameraLensProperties {
+	static const CameraLensProperties *get(const std::string &lens);
+};
+
+} /* namespace libcamera */
diff --git a/src/libcamera/camera_lens_properties.cpp b/src/libcamera/camera_lens_properties.cpp
new file mode 100644
index 00000000..dee73b43
--- /dev/null
+++ b/src/libcamera/camera_lens_properties.cpp
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Google Inc.
+ *
+ * camera_lens_properties.cpp - Database of camera lens properties
+ */
+
+#include "libcamera/internal/camera_lens_properties.h"
+
+#include <map>
+
+#include <libcamera/base/log.h>
+
+#include <libcamera/control_ids.h>
+
+/**
+ * \file camera_lens_properties.h
+ * \brief Database of camera lens properties
+ *
+ * The database of camera lenbs properties collects static information about
+ * camera sensors with lens devices that is not possible or desirable to
+ * retrieve from the device at run time.
+ *
+ * The database is indexed using the lens model.
+ * \todo should we use properties class for lens too ?
+ */
+
+namespace libcamera {
+
+LOG_DEFINE_CATEGORY(CameraLensProperties)
+
+/**
+ * \struct CameraLensProperties
+ * \brief Database of camera lens properties
+ */
+
+/**
+ * \brief Retrieve the properties associated with a lens
+ * \param lens The sensor model name as reported by properties::Model
+ * \return A pointer to the CameraLensProperties instance associated with a lens
+ * or nullptr if the lens is not supported
+ */
+const CameraLensProperties *CameraLensProperties::get(const std::string &lens)
+{
+	static const std::map<std::string, const CameraLensProperties> lensProps = {};
+
+	const auto it = lensProps.find(lens);
+	if (it == lensProps.end()) {
+		LOG(CameraLensProperties, Warning)
+			<< "No static properties available for '" << lens << "'";
+		LOG(CameraLensProperties, Warning)
+			<< "Please consider updating the camera lens properties database";
+		return nullptr;
+	}
+
+	return &it->second;
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index b57bee7e..475df3d6 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -6,6 +6,7 @@ libcamera_sources = files([
     'camera.cpp',
     'camera_controls.cpp',
     'camera_lens.cpp',
+    'camera_lens_properties.cpp',
     'camera_manager.cpp',
     'camera_sensor.cpp',
     'camera_sensor_properties.cpp',
-- 
2.34.1



More information about the libcamera-devel mailing list