From patchwork Fri Mar 27 11:31:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3356 Return-Path: Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 383B76040E for ; Fri, 27 Mar 2020 12:29:00 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.localdomain (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id E9DD9E0008 for ; Fri, 27 Mar 2020 11:28:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 27 Mar 2020 12:31:51 +0100 Message-Id: <20200327113152.348570-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200327113152.348570-1-jacopo@jmondi.org> References: <20200327113152.348570-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFCv2 1/2] libcamera: camera_sensor: Define CameraSensorInfo 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-List-Received-Date: Fri, 27 Mar 2020 11:29:00 -0000 Define the CameraSensorInfo structure that reports the current image sensor configuration. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 106 ++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 19 +++++ 2 files changed, 125 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 09771fc40bbb..df1d82d29f74 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -30,6 +30,112 @@ namespace libcamera { LOG_DEFINE_CATEGORY(CameraSensor); +/** + * \struct CameraSensorInfo + * \brief Report the image sensor characteristics + * + * The structure reports image sensor characteristics used by IPA modules to + * tune their algorithms based on the image sensor model currently in use and + * its configuration. + * + * The here reported information describe the sensor's intrinsics + * characteristics, such as its pixel array size and the sensor model name, + * as well as information relative to the currently configured mode, such as + * the produced image size and the bit depth of the requested image format. + * + * Instances of this structure are meant to be assembled by the CameraSensor + * class and its specialized subclasses by inspecting the sensor static + * properties as well as the currently configured sensor mode. + */ + +/** + * \var CameraSensorInfo::name + * \brief The image sensor name + */ + +/** + * \var CameraSensorInfo::bitsPerPixel + * \brief The bits per-pixel of the image format produced by the image sensor + */ + +/** + * \var CameraSensorInfo::activeAreaSize + * \brief The size of the active pixel array area of the sensor + * + * \todo Reference the corresponding property + */ + +/** + * \var CameraSensorInfo::analogCrop + * \brief The portion of the pixel array active area which is read-out and + * processed + * + * The analog crop rectangle top-left corner is defined as the displacement from + * from the top-left corner of the pixel array active area. The rectangle + * horizontal and vertical sizes define the portion of the pixel matrix which + * is read-out and provided to the sensor's on-board ISP before any analog + * processing takes place. + */ + +/** + * \var CameraSensorInfo::outputSize + * \brief The size of the images produced by the camera sensor + * + * The output image size defines the horizontal and vertical sizes of the images + * produced by the image sensor. The final output image size is defined as the + * end result of the sensor's on-board ISP pipeline processing stages, applied + * on the pixel array matrix analog crop rectangle. Each ISP processing stage + * that applies pixel sub-sampling techniques, such as pixel binning or + * skipping, or perform additional digital cropping concur in the definition + * of the final output image size. + */ + +/** + * \var CameraSensorInfo::horizontalBinning + * \brief The binning factor, in the horizontal direction, of the image sensor + * configuration + * + * \todo Remove this field and compute the binning factor in the IPA + */ + +/** + * \var CameraSensorInfo::verticalBinning + * \brief The binning factor, in the vertical direction, of the image sensor + * configuration + * + * \todo Remove this field and compute the binning factor in the IPA + */ + +/** + * \var CameraSensorInfo::horizontalScaling + * \brief The horizontal scaling factor, calculated as the ratio between + * the active pixel array horizontal size and the horizontal size of the + * output image + * + * \todo Remove this field and compute the scaling factor in the IPA + */ + +/** + * \var CameraSensorInfo::verticalScaling + * \brief The vertical scaling factor, calculated as the ratio between + * the active pixel array vertical size and the vertical size of the + * output image + * + * \todo Remove this field and compute the scaling factor in the IPA + */ + +/** + * \var CameraSensorInfo::noiseFactor + * \brief Scaling of the noise compared to the native sensor mode + * + * \todo Improve this description + */ + +/** + * \var CameraSensorInfo::lineDuration + * \brief Line scan-out duration in nanoseconds + */ + /** * \class CameraSensor * \brief A camera sensor based on V4L2 subdevices diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 6e4d2b0118bc..acc6022cf0e8 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -24,6 +24,25 @@ class V4L2Subdevice; struct V4L2SubdeviceFormat; +struct CameraSensorInfo { + std::string name; + + uint32_t bitsPerPixel; + + Size activeAreaSize; + Rectangle analogCrop; + Size outputSize; + + uint8_t horizontalBinning; + uint8_t verticalBinning; + double horizontalScaling; + double verticalScaling; + + double noiseFactor; + + double lineDuration; +}; + class CameraSensor : protected Loggable { public: From patchwork Fri Mar 27 11:31:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3357 Return-Path: Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A58CF6040E for ; Fri, 27 Mar 2020 12:29:00 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.localdomain (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 64B80E0008 for ; Fri, 27 Mar 2020 11:29:00 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 27 Mar 2020 12:31:52 +0100 Message-Id: <20200327113152.348570-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200327113152.348570-1-jacopo@jmondi.org> References: <20200327113152.348570-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFCv2 2/2] libcamera: camera_sensor: Add method to get sensor info 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-List-Received-Date: Fri, 27 Mar 2020 11:29:00 -0000 Add method to retrieve the CameraSensorInfo to the CameraSensor class. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 127 ++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 1 + 2 files changed, 128 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index df1d82d29f74..23204b05d062 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -11,10 +11,13 @@ #include #include #include +#include #include #include #include +#include + #include #include "formats.h" @@ -30,6 +33,101 @@ namespace libcamera { LOG_DEFINE_CATEGORY(CameraSensor); +namespace { + +const std::map mbusToBppMap = { + { V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE, 16 }, + { V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, 16 }, + { V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, 16 }, + { V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, 16 }, + { V4L2_MBUS_FMT_BGR565_2X8_BE, 16 }, + { V4L2_MBUS_FMT_BGR565_2X8_LE, 16 }, + { V4L2_MBUS_FMT_RGB565_2X8_BE, 16 }, + { V4L2_MBUS_FMT_RGB565_2X8_LE, 16 }, + { V4L2_MBUS_FMT_RGB666_1X18, 18 }, + { V4L2_MBUS_FMT_RGB888_1X24, 24 }, + { V4L2_MBUS_FMT_RGB888_2X12_BE, 24 }, + { V4L2_MBUS_FMT_RGB888_2X12_LE, 24 }, + { V4L2_MBUS_FMT_ARGB8888_1X32, 32 }, + { V4L2_MBUS_FMT_Y8_1X8, 8 }, + { V4L2_MBUS_FMT_UV8_1X8, 8 }, + { V4L2_MBUS_FMT_UYVY8_1_5X8, 40 }, + { V4L2_MBUS_FMT_VYUY8_1_5X8, 40 }, + { V4L2_MBUS_FMT_YUYV8_1_5X8, 40 }, + { V4L2_MBUS_FMT_YVYU8_1_5X8, 40 }, + { V4L2_MBUS_FMT_UYVY8_2X8, 16 }, + { V4L2_MBUS_FMT_VYUY8_2X8, 16 }, + { V4L2_MBUS_FMT_YUYV8_2X8, 16 }, + { V4L2_MBUS_FMT_YVYU8_2X8, 16 }, + { V4L2_MBUS_FMT_Y10_1X10, 10 }, + { V4L2_MBUS_FMT_UYVY10_2X10, 20 }, + { V4L2_MBUS_FMT_VYUY10_2X10, 20 }, + { V4L2_MBUS_FMT_YUYV10_2X10, 20 }, + { V4L2_MBUS_FMT_YVYU10_2X10, 20 }, + { V4L2_MBUS_FMT_Y12_1X12, 12 }, + { V4L2_MBUS_FMT_UYVY8_1X16, 16 }, + { V4L2_MBUS_FMT_VYUY8_1X16, 16 }, + { V4L2_MBUS_FMT_YUYV8_1X16, 16 }, + { V4L2_MBUS_FMT_YVYU8_1X16, 16 }, + { V4L2_MBUS_FMT_YDYUYDYV8_1X16, 16 }, + { V4L2_MBUS_FMT_UYVY10_1X20, 20 }, + { V4L2_MBUS_FMT_VYUY10_1X20, 20 }, + { V4L2_MBUS_FMT_YUYV10_1X20, 20 }, + { V4L2_MBUS_FMT_YVYU10_1X20, 20 }, + { V4L2_MBUS_FMT_YUV10_1X30, 30 }, + { V4L2_MBUS_FMT_AYUV8_1X32, 32 }, + { V4L2_MBUS_FMT_UYVY12_2X12, 24 }, + { V4L2_MBUS_FMT_VYUY12_2X12, 24 }, + { V4L2_MBUS_FMT_YUYV12_2X12, 24 }, + { V4L2_MBUS_FMT_YVYU12_2X12, 24 }, + { V4L2_MBUS_FMT_UYVY12_1X24, 24 }, + { V4L2_MBUS_FMT_VYUY12_1X24, 24 }, + { V4L2_MBUS_FMT_YUYV12_1X24, 24 }, + { V4L2_MBUS_FMT_YVYU12_1X24, 24 }, + { V4L2_MBUS_FMT_SBGGR8_1X8, 8 }, + { V4L2_MBUS_FMT_SGBRG8_1X8, 8 }, + { V4L2_MBUS_FMT_SGRBG8_1X8, 8 }, + { V4L2_MBUS_FMT_SRGGB8_1X8, 8 }, + { V4L2_MBUS_FMT_SBGGR10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SGBRG10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_1X10, 10 }, + { V4L2_MBUS_FMT_SGBRG10_1X10, 10 }, + { V4L2_MBUS_FMT_SGRBG10_1X10, 10 }, + { V4L2_MBUS_FMT_SRGGB10_1X10, 10 }, + { V4L2_MBUS_FMT_SBGGR12_1X12, 24 }, + { V4L2_MBUS_FMT_SGBRG12_1X12, 24 }, + { V4L2_MBUS_FMT_SGRBG12_1X12, 24 }, + { V4L2_MBUS_FMT_SRGGB12_1X12, 24 }, + { V4L2_MBUS_FMT_JPEG_1X8, 8 }, + { V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8, 8 }, + { V4L2_MBUS_FMT_AHSV8888_1X32, 32 }, +}; + +uint8_t mbusToBpp(uint32_t mbus_code) +{ + const auto it = mbusToBppMap.find(mbus_code); + if (it == mbusToBppMap.end()) { + LOG(CameraSensor, Error) << "Unsupported media bus format: " + << mbus_code; + /* Return 8 to avoid divisions by 0. */ + return 8; + } + + return it->second; +} + +}; /* namespace */ + /** * \struct CameraSensorInfo * \brief Report the image sensor characteristics @@ -482,6 +580,35 @@ int CameraSensor::setControls(ControlList *ctrls) * \return The list of camera sensor properties */ +/** + * \brief Assemble and return the camera sensor info + * + * This method is meant to be overridden by CameraSensor specialized sub-classes + * to report more detailed information about the camera sensor configuration. + * + * The base class implementation provides a stub implementation to support + * camera sensor without an associated sub-class specialization. + * + * \return An instance of CameraSensorInfo describing the sensor configuration + */ +CameraSensorInfo CameraSensor::sensorInfo() const +{ + CameraSensorInfo info{}; + + /* Get format on pad #0 by default for generic camera sensor. */ + V4L2SubdeviceFormat format{}; + int ret = subdev_->getFormat(0, &format); + if (ret) + return {}; + + info.name = "generic_sensor"; + info.bitsPerPixel = mbusToBpp(format.mbus_code); + info.outputSize.width = format.size.width; + info.outputSize.height = format.size.height; + + return info; +} + std::string CameraSensor::logPrefix() const { return "'" + subdev_->entity()->name() + "'"; diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index acc6022cf0e8..94374a4d01dd 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -69,6 +69,7 @@ public: int setControls(ControlList *ctrls); const ControlList &properties() const { return properties_; } + virtual CameraSensorInfo sensorInfo() const; protected: std::string logPrefix() const;