From patchwork Fri Dec 18 16:47:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10685 X-Patchwork-Delegate: jacopo@jmondi.org 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 B060BC0F1A for ; Fri, 18 Dec 2020 16:47:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BFE361FF6; Fri, 18 Dec 2020 17:47:56 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F3E5061596 for ; Fri, 18 Dec 2020 17:47:50 +0100 (CET) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id C180A20009 for ; Fri, 18 Dec 2020 16:47:50 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 18 Dec 2020 17:47:49 +0100 Message-Id: <20201218164754.81422-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201218164754.81422-1-jacopo@jmondi.org> References: <20201218164754.81422-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/9] libcamera: camera_sensor: Register ColorFilterArrangement 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Inspect the list of media bus codes supported by the camera sensor in order to deduce the color filter arrangement and register the ColorFilterArrangement draft property. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 1628ba9c892b..2b78eb4cb530 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -17,6 +17,7 @@ #include +#include "libcamera/internal/bayer_format.h" #include "libcamera/internal/formats.h" #include "libcamera/internal/sysfs.h" #include "libcamera/internal/utils.h" @@ -178,10 +179,6 @@ int CameraSensor::init() if (ret < 0) return ret; - ret = initProperties(); - if (ret) - return ret; - /* Enumerate, sort and cache media bus codes and sizes. */ formats_ = subdev_->formats(pad_); if (formats_.empty()) { @@ -210,6 +207,10 @@ int CameraSensor::init() */ resolution_ = sizes_.back(); + ret = initProperties(); + if (ret) + return ret; + return 0; } @@ -307,6 +308,33 @@ int CameraSensor::initProperties() properties_.set(properties::PixelArrayActiveAreas, { crop }); } + /* Color filter arrangement, default to the generic 'RGB' */ + int32_t cfa = properties::draft::RGB; + for (const auto &format : formats_) { + unsigned int mbusCode = format.first; + BayerFormat bayerFormat(mbusCode); + if (!bayerFormat.isValid()) + continue; + + /* Report the CFA ordering of the first valid RAW Bayer format. */ + switch (bayerFormat.order) { + case BayerFormat::BGGR: + cfa = properties::draft::BGGR; + break; + case BayerFormat::GBRG: + cfa = properties::draft::GBRG; + break; + case BayerFormat::GRBG: + cfa = properties::draft::GRBG; + break; + case BayerFormat::RGGB: + cfa = properties::draft::RGGB; + break; + } + break; + } + properties_.set(properties::draft::ColorFilterArrangement, cfa); + return 0; }