summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-12-16 16:40:59 +0100
committerStefan Klug <stefan.klug@ideasonboard.com>2024-12-17 11:19:36 +0100
commit60e94a0d9957a8dd25ed78ae4c16c2918644671f (patch)
tree4f48de5dc976293708143bf8a7d05c159368423f
parent041377839bf9d254608f18643d35cfdb4df1a371 (diff)
libcamera: camera_sensor: Add parameter to limit returned sensor size
The getFormat function takes the aspect ratio and the area of the requested size into account when choosing the best sensor size. In case the sensor is connected to an rkisp1 the maximum supported frame size of the ISP is another constraining factor for the selection of the best format. Add a maxSize parameter to support such a constraint. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
-rw-r--r--include/libcamera/internal/camera_sensor.h2
-rw-r--r--src/libcamera/sensor/camera_sensor.cpp3
-rw-r--r--src/libcamera/sensor/camera_sensor_legacy.cpp9
3 files changed, 11 insertions, 3 deletions
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index d030e254..605ea813 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -53,7 +53,7 @@ public:
virtual V4L2SubdeviceFormat
getFormat(const std::vector<unsigned int> &mbusCodes,
- const Size &size) const = 0;
+ const Size &size, const Size maxSize = Size()) const = 0;
virtual int setFormat(V4L2SubdeviceFormat *format,
Transform transform = Transform::Identity) = 0;
virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0;
diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
index 208a1603..a131ac22 100644
--- a/src/libcamera/sensor/camera_sensor.cpp
+++ b/src/libcamera/sensor/camera_sensor.cpp
@@ -116,6 +116,7 @@ CameraSensor::~CameraSensor() = default;
* \brief Retrieve the best sensor format for a desired output
* \param[in] mbusCodes The list of acceptable media bus codes
* \param[in] size The desired size
+ * \param[in] maxSize The maximum size
*
* Media bus codes are selected from \a mbusCodes, which lists all acceptable
* codes in decreasing order of preference. Media bus codes supported by the
@@ -134,6 +135,8 @@ CameraSensor::~CameraSensor() = default;
* bandwidth.
* - The desired \a size shall be supported by one of the media bus code listed
* in \a mbusCodes.
+ * - The desired \a size shall fit into the maximum size \a maxSize if it is not
+ * null.
*
* When multiple media bus codes can produce the same size, the code at the
* lowest position in \a mbusCodes is selected.
diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp
index 17d6fa68..32989c19 100644
--- a/src/libcamera/sensor/camera_sensor_legacy.cpp
+++ b/src/libcamera/sensor/camera_sensor_legacy.cpp
@@ -74,7 +74,8 @@ public:
Size resolution() const override;
V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
- const Size &size) const override;
+ const Size &size,
+ const Size maxSize) const override;
int setFormat(V4L2SubdeviceFormat *format,
Transform transform = Transform::Identity) override;
int tryFormat(V4L2SubdeviceFormat *format) const override;
@@ -699,7 +700,7 @@ Size CameraSensorLegacy::resolution() const
V4L2SubdeviceFormat
CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,
- const Size &size) const
+ const Size &size, Size maxSize) const
{
unsigned int desiredArea = size.width * size.height;
unsigned int bestArea = UINT_MAX;
@@ -716,6 +717,10 @@ CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,
for (const SizeRange &range : formats->second) {
const Size &sz = range.max;
+ if (!maxSize.isNull() &&
+ (sz.width > maxSize.width || sz.height > maxSize.height))
+ continue;
+
if (sz.width < size.width || sz.height < size.height)
continue;