From patchwork Thu Nov 24 12:12:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 17887 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 754C3BDE6B for ; Thu, 24 Nov 2022 12:12:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 45FCC63321; Thu, 24 Nov 2022 13:12:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669291950; bh=cMyh8jAUSIrQxf42ySkdTyCgVYV2cIDPeSWBXmpbK9I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=av5Tn1KkMTdW7ere3Nb7GgcTsL2K+34eSj7ZgMrgbrCFJa1HQ9UsWLMuM3w5H88Zk +tJ7NdBGQnL3Q3tqzUGTlOQOJfkRnpepKOPyJ34/8TQowhnWpMzhxB7iLVKLJCw90o V8Fzn6xg9aLGH7t4B6ZqZCdDtDT/LalCMufVqjnnsAGNblNVaLXXTuWjKSY7/5r94X Dbmp80ijNjMnl3du3t3FC0ah5CHbu8oQjSs41AzFlXsTI90CKd+raYRaHIBaV9xPMB g0lasnw1Z08iPpgJd2jMhjz+q6vii1QAdQmCDCY7VBNHf4C5RX4TlqGmwhEM/zXtPi YZYgYQ5lbJSfg== Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A5A36331A for ; Thu, 24 Nov 2022 13:12:27 +0100 (CET) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 6B1D24000E; Thu, 24 Nov 2022 12:12:26 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Nov 2022 13:12:12 +0100 Message-Id: <20221124121220.47000-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221124121220.47000-1-jacopo@jmondi.org> References: <20221124121220.47000-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/9] libcamera: bayer_format: Add toMbusCode method 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 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman This makes it easier to perform transformations on Bayer type mbus codes by converting them to a BayerFormat, doing the transform, and then converting them back again. Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 78ba3969913d..3601dccb7228 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -47,6 +47,7 @@ public: } static const BayerFormat &fromMbusCode(unsigned int mbusCode); + unsigned int toMbusCode() const; bool isValid() const { return bitDepth != 0; } std::string toString() const; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index f27cc1662d25..fdbc4af1dcc0 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -226,6 +226,17 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode) return it->second; } +/** + * \brief Retrieve the media bus code corresponding this this BayerFormat + * \return The corresponding media bus code, or zero if none was found + */ +unsigned int BayerFormat::toMbusCode() const +{ + auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(), + [this](const auto &i) { return i.second == *this; }); + return it != mbusCodeToBayer.end() ? it->first : 0; +} + /** * \fn BayerFormat::isValid() * \brief Return whether a BayerFormat is valid