From patchwork Wed Jul 29 11:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9070 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 7CF43BD86F for ; Wed, 29 Jul 2020 11:25:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E99FA613C6; Wed, 29 Jul 2020 13:25:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aSOr9iE7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B94DC6039D for ; Wed, 29 Jul 2020 13:25:28 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3783231F; Wed, 29 Jul 2020 13:25:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596021928; bh=g9HHEzOn2o5jDpI2r9rI/lRulfkHTPZVImGukbpkles=; h=From:To:Cc:Subject:Date:From; b=aSOr9iE7nt3CvgkyzZQPXUONB/aNWEzRlQYNf14DDGW+G5CSzyULTGNUeajnKLBK5 A1SR6St5X1CeWzNJEXbjbmEw2NWHFb70PUQqqg9OfG5ReE/JK6brFCcuvzrf8JuxSc 5QtV1uEwM0rY9RIcWldkSqm/My9RRqMG+okqvE1E= From: Kieran Bingham To: libcamera devel Date: Wed, 29 Jul 2020 12:25:24 +0100 Message-Id: <20200729112524.498276-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: formats: add planeCount helper 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" Determine the number of planes used by a format by counting the number of PxielFormatPlaneInfo entries with a valid entry. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- include/libcamera/internal/formats.h | 2 ++ src/libcamera/formats.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 0bb151044294..beeaab1ae2f5 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -45,6 +45,8 @@ public: unsigned int frameSize(const Size &size, const std::array &strides) const; + unsigned int planeCount() const; + /* \todo Add support for non-contiguous memory planes */ const char *name; PixelFormat format; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index cd63c15cb926..70d31fb36c37 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -805,4 +805,26 @@ PixelFormatInfo::frameSize(const Size &size, return sum; } +/** + * \brief Identify the number of planes represented by the format + * + * This function counts the number of planes which have a valid configuration + * and uses that to determine the number of planes used by the format. + * + * \return The number of planes used by the format + */ +unsigned int PixelFormatInfo::planeCount() const +{ + unsigned int count = 0; + + for (const PixelFormatPlaneInfo &p : planes) { + if (p.bytesPerGroup == 0) + break; + + count++; + } + + return count; +} + } /* namespace libcamera */