From patchwork Fri Sep 15 13:06:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19026 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 2F07FC32B1 for ; Fri, 15 Sep 2023 13:07:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 501B462918; Fri, 15 Sep 2023 15:07:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694783237; bh=Bjqt1BC/qeXCOGnSbabt151Jc4j/SYVO0ZOFPLYMUaA=; 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=ckc1enNV+OZAjVK1Rati5N1jqwWC8kuBZhMbQ5Fvwwcwo3akSyif6Y9JcGDmOuBqo 59/ckBAkQ+m5KOP0n1CtdnAX1M0mKdkHnyFOl5mqsoPbl7jiTnfl5xxY81RDl1JGdq IyiHD8GHx4TnRRh8jYiiODNYjSoPdi/He5SSFr0qYI3J8OwuQkVXhkkLt9VF9KUV6a tlmKgXHkuSpmViux5MpVR7pg+ike7gtoD1ib7VRWjju7dAW27RWeTKsuZ254qXKE8Z Ss/7rAN3UBiDzyCCyJW5VX2xy+NP/y2SPKkZf81eruW7DbdjCU1NNFv7uDGhcsCyiS 9BCRm1I7QTyVQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0692462927 for ; Fri, 15 Sep 2023 15:07:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="B5PtuB+V"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A128208C; Fri, 15 Sep 2023 15:05:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1694783137; bh=Bjqt1BC/qeXCOGnSbabt151Jc4j/SYVO0ZOFPLYMUaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B5PtuB+V+yhQV6srnLGvMPkaJ4ely480w2B+xCZ9cKSpddeMRD+2T316FUgmdsPDJ cinbcRO4czHeR/EPuwI7hE9T95/4RZY+Fg6F0d/PmhcjEAGF4FXhKKKDpNhd1nKHAF +Ah9iKZfhhFUxXNTc4OJ8ptN6KTxX6wo1cXQSEFc= To: libcamera-devel@lists.libcamera.org Date: Fri, 15 Sep 2023 15:06:45 +0200 Message-ID: <20230915130650.35691-8-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230915130650.35691-1-jacopo.mondi@ideasonboard.com> References: <20230915130650.35691-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 07/12] libcamera: rpi: Make isRaw/isYuv/isRgb static functions 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" From: Naushir Patuck Move the existing isRaw()/isYuv()/isRgb()into a static function of PipelineHandlerBase. This will allow then to be shared with the pipeline handler derived class. Signed-off-by: Naushir Patuck Signed-off-by: Jacopo Mondi Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 52 +++++++++---------- .../pipeline/rpi/common/pipeline_base.h | 4 ++ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 2d787f4b99ed..d8e1ebc106af 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -37,12 +37,6 @@ namespace { constexpr unsigned int defaultRawBitDepth = 12; -bool isRaw(const PixelFormat &pixFmt) -{ - /* This test works for both Bayer and raw mono formats. */ - return BayerFormat::fromPixelFormat(pixFmt).isValid(); -} - PixelFormat mbusCodeToPixelFormat(unsigned int mbus_code, BayerFormat::Packing packingReq) { @@ -91,22 +85,6 @@ std::optional findValidColorSpace(const ColorSpace &colourSpace) return std::nullopt; } -bool isRgb(const PixelFormat &pixFmt) -{ - const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt); - return info.colourEncoding == PixelFormatInfo::ColourEncodingRGB; -} - -bool isYuv(const PixelFormat &pixFmt) -{ - /* The code below would return true for raw mono streams, so weed those out first. */ - if (isRaw(pixFmt)) - return false; - - const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt); - return info.colourEncoding == PixelFormatInfo::ColourEncodingYUV; -} - } /* namespace */ /* @@ -129,7 +107,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validateColorSpaces([[maybe_ for (auto cfg : config_) { /* First fix up raw streams to have the "raw" colour space. */ - if (isRaw(cfg.pixelFormat)) { + if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) { /* If there was no value here, that doesn't count as "adjusted". */ if (cfg.colorSpace && cfg.colorSpace != ColorSpace::Raw) status = Adjusted; @@ -156,13 +134,13 @@ CameraConfiguration::Status RPiCameraConfiguration::validateColorSpaces([[maybe_ if (cfg.colorSpace == ColorSpace::Raw) continue; - if (isYuv(cfg.pixelFormat) && cfg.colorSpace != yuvColorSpace_) { + if (PipelineHandlerBase::isYuv(cfg.pixelFormat) && cfg.colorSpace != yuvColorSpace_) { /* Again, no value means "not adjusted". */ if (cfg.colorSpace) status = Adjusted; cfg.colorSpace = yuvColorSpace_; } - if (isRgb(cfg.pixelFormat) && cfg.colorSpace != rgbColorSpace_) { + if (PipelineHandlerBase::isRgb(cfg.pixelFormat) && cfg.colorSpace != rgbColorSpace_) { /* Be nice, and let the YUV version count as non-adjusted too. */ if (cfg.colorSpace && cfg.colorSpace != yuvColorSpace_) status = Adjusted; @@ -199,7 +177,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() std::vector rawStreams, outStreams; for (const auto &[index, cfg] : utils::enumerate(config_)) { - if (isRaw(cfg.pixelFormat)) + if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) rawStreams.emplace_back(index, &cfg); else outStreams.emplace_back(index, &cfg); @@ -347,6 +325,28 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() return status; } +bool PipelineHandlerBase::isRgb(const PixelFormat &pixFmt) +{ + const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt); + return info.colourEncoding == PixelFormatInfo::ColourEncodingRGB; +} + +bool PipelineHandlerBase::isYuv(const PixelFormat &pixFmt) +{ + /* The code below would return true for raw mono streams, so weed those out first. */ + if (PipelineHandlerBase::isRaw(pixFmt)) + return false; + + const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt); + return info.colourEncoding == PixelFormatInfo::ColourEncodingYUV; +} + +bool PipelineHandlerBase::isRaw(const PixelFormat &pixFmt) +{ + /* This test works for both Bayer and raw mono formats. */ + return BayerFormat::fromPixelFormat(pixFmt).isValid(); +} + V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice *dev, const V4L2SubdeviceFormat &format, BayerFormat::Packing packingReq) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 3e7c487fb0bf..135b74392140 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -213,6 +213,10 @@ public: { } + static bool isRgb(const PixelFormat &pixFmt); + static bool isYuv(const PixelFormat &pixFmt); + static bool isRaw(const PixelFormat &pixFmt); + static V4L2DeviceFormat toV4L2DeviceFormat(const V4L2VideoDevice *dev, const V4L2SubdeviceFormat &format, BayerFormat::Packing packingReq);