From patchwork Mon Jul 24 12:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18878 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E6AB5BDC71 for ; Mon, 24 Jul 2023 12:39:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 975F8628CC; Mon, 24 Jul 2023 14:39:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690202362; bh=wyT8uP/9d/bafQbibSZu2mwhkPJaSLjDCV9gHLqlIF8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gYEyu+TYvfcRAsCyp9R5SwWBYVbPZv/gLVY21Jwnrxl67t2Tnv64fMqPQWm6VkEIh LqfBojI1XpppbEi/xajva+ckmplcIBFqkHDDjfo/3fEWwblQqyRfaQO+3i24s08S4H yaLUmkuOt0HfMnSn6q5dZowBzmz1djeHeFKfu/cM9moGnmeeQg/GDlDLOvEAI5pVS2 QSIi4egaoop6qyjI1qxA2lgzIwhjAovimGo1wN9kdSv82lSc2nxXTUgfBk2MQVfguW HBQvM5enmRG1MjFt0YbR36LQ/Z79VldKt3E/VjbnVDvuNSFZ/xZCzgZkRw16U51MSQ 7VqnEJycQwBUw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 81253628C4 for ; Mon, 24 Jul 2023 14:39:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WV5tRrz9"; dkim-atps=neutral Received: from uno.localdomain (mob-5-91-20-233.net.vodafone.it [5.91.20.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 93C24735; Mon, 24 Jul 2023 14:38:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690202301; bh=wyT8uP/9d/bafQbibSZu2mwhkPJaSLjDCV9gHLqlIF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WV5tRrz9/Xw73uWOqjsORHmxyV2jPU3uxFJ1FLXW7TxxgF1LUanNL4U3bry7PMUko kixp6VYdMv0EkWtC2gOaFqDJo/XDbLZ6Gp87DXGU93k61tzZ2gLy4I+byWu0x97cIK tyMAvgF54gUZZDlNQ+0ObfzLrQjgg0+MZ0eBYdiM= To: libcamera-devel@lists.libcamera.org Date: Mon, 24 Jul 2023 14:39:05 +0200 Message-Id: <20230724123907.29086-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230724123907.29086-1-jacopo.mondi@ideasonboard.com> References: <20230724123907.29086-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] libcamera: camera: Introduce SensorConfiguration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Introduce SensorConfiguration in the libcamera API. The SensorConfiguration is part of the CameraConfiguration class and allows applications to control the sensor settings. Signed-off-by: Jacopo Mondi Reviewed-by: Naushir Patuck --- include/libcamera/camera.h | 43 +++++++++ src/libcamera/camera.cpp | 180 +++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 004bc89455f5..b2aa8d467feb 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -30,6 +31,47 @@ class FrameBufferAllocator; class PipelineHandler; class Request; +class SensorConfiguration +{ +public: + unsigned int bitDepth = 0; + + Rectangle analogCrop; + + struct { + unsigned int binX = 1; + unsigned int binY = 1; + } binning; + + struct { + unsigned int xOddInc = 1; + unsigned int xEvenInc = 1; + unsigned int yOddInc = 1; + unsigned int yEvenInc = 1; + } skipping; + + Size outputSize; + + bool valid() const + { + return validate() != Invalid; + } + + explicit operator bool() const + { + return validate() == Populated; + } + +private: + enum Status { + Unpopulated, + Populated, + Invalid, + }; + + Status validate() const; +}; + class CameraConfiguration { public: @@ -66,6 +108,7 @@ public: bool empty() const; std::size_t size() const; + SensorConfiguration sensorConfig; Transform transform; protected: diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 0eecee766f00..b58d120cd802 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -97,6 +97,21 @@ * implemented in the above order at the hardware level. The libcamera pipeline * handlers translate the pipeline model to the real hardware configuration. * + * \subsection camera-sensor-mode Camera Sensor Model + * + * libcamera allows applications to control the configuration of the camera + * sensor, particularly it allows to control the frame geometry and frame + * delivery rate of the sensor. + * + * The camera sensor configuration applies to all streams produced by a camera + * from the same image source. + * + * More details about the libcamera implemented camera sensor model are + * available in the libcamera camera-sensor-model documentation page. + * + * The sensor configuration is specified by applications by populating the + * CameraConfiguration::sensorConfig class member. + * * \subsection digital-zoom Digital Zoom * * Digital zoom is implemented as a combination of the cropping and scaling @@ -111,6 +126,161 @@ namespace libcamera { LOG_DECLARE_CATEGORY(Camera) +/** + * \class SensorConfiguration + * \brief Camera sensor configuration + * + * The SensorConfiguration class collects parameters to control the operations + * of the camera sensor, accordingly to the abstract camera sensor model + * implemented by libcamera. + * + * \todo Applications shall fully populate all fields of the + * CameraConfiguration::sensorConfig class members before validating the + * CameraConfiguration. If the SensorConfiguration is not fully populated, or if + * any of its parameters cannot be applied to the sensor in use, the + * CameraConfiguration validation process will fail and return + * CameraConfiguration::Status::Invalid. + * + * Applications that populate the SensorConfiguration class members are + * expected to be highly-specialized applications that know what sensor + * they are operating with and what parameters are valid for the sensor in use. + * + * A detailed description of the abstract camera sensor model implemented by + * libcamera and the description of its configuration parameters is available + * in the libcamera documentation camera-sensor-model file. + */ + +/** + * \enum SensorConfiguration::Status + * \brief The sensor configuration validation status + */ + +/** + * \var SensorConfiguration::bitDepth + * \brief The sensor image format bit depth + * + * The number of bits (resolution) used to represent a pixel sample. + */ + +/** + * \var SensorConfiguration::analogCrop + * \brief The analog crop rectangle + * + * The selected portion of the active pixel array used to produce the image + * frame. + */ + +/** + * \var SensorConfiguration::binning + * \brief Sensor binning configuration + * + * Refer to the camera-sensor-model documentation for an accurate description + * of the binning operations. Disabled by default. + */ + +/** + * \var SensorConfiguration::binX + * \brief Horizontal binning factor + * + * The horizontal binning factor. Default to 1. + */ + +/** + * \var SensorConfiguration::binY + * \brief Vertical binning factor + * + * The vertical binning factor. Default to 1. + */ + +/** + * \var SensorConfiguration::skipping + * \brief The sensor skipping configuration + * + * Refer to the camera-sensor-model documentation for an accurate description + * of the skipping operations. + * + * If no skipping is performed, all the structure fields should be + * set to 1. Disabled by default. + */ + +/** + * \var SensorConfiguration::xOddInc + * \brief Horizontal increment for odd rows. Default to 1. + */ + +/** + * \var SensorConfiguration::xEvenInc + * \brief Horizontal increment for even rows. Default to 1. + */ + +/** + * \var SensorConfiguration::yOddInc + * \brief Vertical increment for odd columns. Default to 1. + */ + +/** + * \var SensorConfiguration::yEvenInc + * \brief Vertical increment for even columns. Default to 1. + */ + +/** + * \var SensorConfiguration::outputSize + * \brief The frame output (visible) size + * + * The size of the data frame as received by the host processor. + */ + +/** + * \fn SensorConfiguration::valid() const + * \brief Validate the SensorConfiguration + * + * Validate the sensor configuration. + * + * \todo A sensor configuration is valid (or well-formed) if it's either + * completely un-populated or fully populated. For now allows to populate + * the bitDepth and the outputSize only. + * + * \return True if the SensorConfiguration is either fully populated or + * un-populated, false otherwise + */ + +/** + * \fn SensorConfiguration::operator bool() const + * \brief Test if a SensorConfiguration is fully populated + * \return True if the SensorConfiguration is fully populated + */ + +/** + * \brief Validate the sensor configuration + * + * \todo A sensor configuration is valid (or well-formed) if it's either + * completely un-populated or fully populated. For now allows to populate + * the bitDepth and the outputSize only. + * + * \return The sensor configuration status + * \retval Unpopulated The sensor configuration is fully unpopulated + * \retval Populated The sensor configuration is fully populated + * \retval Invalid The sensor configuration is invalid (not fully populated + * and not fully unpopulated) + */ +SensorConfiguration::Status SensorConfiguration::validate() const +{ + if (bitDepth && binning.binX && binning.binY && + skipping.xOddInc && skipping.yOddInc && + skipping.xEvenInc && skipping.yEvenInc && + !outputSize.isNull()) + return Populated; + + if (!bitDepth && + binning.binX <= 1 && binning.binY <= 1 && + skipping.xOddInc <= 1 && skipping.yOddInc <= 1 && + skipping.xEvenInc <= 1 && skipping.yEvenInc <= 1 && + outputSize.isNull()) + return Unpopulated; + + return Invalid; +} + /** * \class CameraConfiguration * \brief Hold configuration for streams of the camera @@ -391,6 +561,16 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF return status; } +/** + * \var CameraConfiguration::sensorConfig + * \brief The camera sensor configuration + * + * The sensorConfig field allows to control the configuration of the camera + * sensor. Refer to the camera-sensor-model documentation and to the + * SensorConfiguration class documentation for details about the sensor + * configuration process. + */ + /** * \var CameraConfiguration::transform * \brief User-specified transform to be applied to the image