From patchwork Thu Dec 31 15:53:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10795 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 D10FDC0F1A for ; Thu, 31 Dec 2020 15:54:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9C4A0615D5; Thu, 31 Dec 2020 16:54:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VTNpciI4"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06D196031D for ; Thu, 31 Dec 2020 16:54:29 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 3so7518707wmg.4 for ; Thu, 31 Dec 2020 07:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ehcOEaT5C+NVaJy0ibg5WmtOCyPhCQXd82wsNhVrHRg=; b=VTNpciI4p/GwJHjGK1Xo3c+ba3lsTIx+uR7ZocLmKfC5TG6H9gjxTaRyXRii1SrX7Z h80BIV/YoCxFc6hBY4qa8SY831fgwiWW0zYAMg4Dah8pgCgLxvA/aAE4TMMum1orNwo7 FgfoG9RhYMshkVuMsY+m+iBO/s2VotBG01VMCgnWTN4QOjZJI2IRerZJ5CrDeVjjBk1l /Pa04v7Xx9+w9HMp5ccyk9RcUc96EDi92WpzHmpTS+Kqa5Ep8GyGEYr4pRw1IuM4fe4d 2yYlljdaDEyOGddZBrchKdmWai0j1X541FfzJqTlVknOvXCjTg8C9lyb/pINvi//XMvs MeZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ehcOEaT5C+NVaJy0ibg5WmtOCyPhCQXd82wsNhVrHRg=; b=gcXKIYmYDk3h2QZ7QSmA9oO+BcmibLtItSi7AB+19PDKH5V3O5LsnXLUsipDQz4mKR bq8EhiAhLbJ8myNS1U9Cw/A+nEw4seLLHljHdOctu1lyCphiiwGRtlZ/i6ef64I43xaw Re4lkwo6r0h5rcogtglZXp21kziLibl63KIaBvu4yg/niVluhJHmpomi1igsJnp60wXS BO8iESjPJDIHpfNWMY+sSfrJWSN+/Zr5qfL3lHJ5fIS8IhcVDtg+8ypMtfDfCvWCethX 2TnHCHsrL3pniHxB3vqErTV9rp3Y+mrg+Jx+rstCY8qowaZIkZk5bckGo/tbA29C9lOW e/SA== X-Gm-Message-State: AOAM533m31JBhOeRdqdK5wkhrQ8E6bxnG6bIVTk51shq7uCctpIxq4ZH Gdl+UL5PSDoDY/y+cNsyeqcWJRqzcB4= X-Google-Smtp-Source: ABdhPJxMJAtnpEjryR6PB62QBMPnPRCeUNjyOV6CDbLvJtyTRfE6+9K+V2CZxliPnsp/VWhF3T2s+Q== X-Received: by 2002:a05:600c:410d:: with SMTP id j13mr12390690wmi.95.1609430068758; Thu, 31 Dec 2020 07:54:28 -0800 (PST) Received: from basti-TUXEDO-Book-XA1510.fritz.box (p200300d1ff267500b10aabf0e84cdf75.dip0.t-ipconnect.de. [2003:d1:ff26:7500:b10a:abf0:e84c:df75]) by smtp.gmail.com with ESMTPSA id s63sm14595787wms.18.2020.12.31.07.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 07:54:28 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Dec 2020 16:53:33 +0100 Message-Id: <20201231155336.7058-2-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201231155336.7058-1-sebastian.fricke.linux@gmail.com> References: <20201231155336.7058-1-sebastian.fricke.linux@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/4] libcamera: Add the fromV4L2PixelFormat function 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" Add a static member function to get the corresponding Bayer-format from a given V4L2PixelFormat. Replace an existing method to instantiate an object from a matching V4l2PixelFormat, to not duplicate the code. The motivation behind this patch is to align the overall structure of the BayerFormat class with other parts of the code base, such as the V4L2PixelFormat class. Remove the v4l2ToBayer mapping table and use the bayerToV4l2 mapping table by searching for a mapped element to get the corresponding key. The downside of this approach is a slightly worse time complexity, but the upside is a smaller codebase and lower memory consumption. As the function is probably not used very frequently, I tend to favor the mentioned upsides. Signed-off-by: Sebastian Fricke Reviewed-by: Laurent Pinchart --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 63 +++++++---------------- 2 files changed, 19 insertions(+), 45 deletions(-) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 4280b76b..8efe1382 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -48,6 +48,7 @@ public: std::string toString() const; V4L2PixelFormat toV4L2PixelFormat() const; + static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); BayerFormat transform(Transform t) const; Order order; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index c42792ff..26065b66 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -7,6 +7,7 @@ #include "libcamera/internal/bayer_format.h" +#include #include #include @@ -57,37 +58,6 @@ namespace libcamera { namespace { -const std::map v4l2ToBayer{ - { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8), { BayerFormat::BGGR, 8, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8), { BayerFormat::GBRG, 8, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8), { BayerFormat::GRBG, 8, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8), { BayerFormat::RGGB, 8, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10), { BayerFormat::BGGR, 10, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10), { BayerFormat::GBRG, 10, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10), { BayerFormat::GRBG, 10, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10), { BayerFormat::RGGB, 10, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P), { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P), { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P), { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P), { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10), { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10), { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10), { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10), { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12), { BayerFormat::BGGR, 12, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12), { BayerFormat::GBRG, 12, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12), { BayerFormat::GRBG, 12, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12), { BayerFormat::RGGB, 12, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P), { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P), { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P), { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P), { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16), { BayerFormat::BGGR, 16, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16), { BayerFormat::GBRG, 16, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16), { BayerFormat::GRBG, 16, BayerFormat::None } }, - { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16), { BayerFormat::RGGB, 16, BayerFormat::None } }, -}; - /* Define a slightly arbitrary ordering so that we can use a std::map. */ struct BayerFormatComparator { constexpr bool operator()(const BayerFormat &lhs, const BayerFormat &rhs) const @@ -155,20 +125,6 @@ const std::map bayerToV4l2{ * \param[in] p The type of packing applied to the pixel values */ -/** - * \brief Construct a BayerFormat from a V4L2PixelFormat - * \param[in] v4l2Format The raw format to convert into a BayerFormat - */ -BayerFormat::BayerFormat(V4L2PixelFormat v4l2Format) - : order(BGGR), packing(None) -{ - const auto it = v4l2ToBayer.find(v4l2Format); - if (it == v4l2ToBayer.end()) - bitDepth = 0; - else - *this = it->second; -} - /** * \fn BayerFormat::isValid() * \brief Return whether a BayerFormat is valid @@ -217,6 +173,23 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const return V4L2PixelFormat(); } +/** + * \brief Convert \a v4l2Format into the corresponding BayerFormat + * \param[in] v4l2Format The raw format to convert into a BayerFormat + * \return The BayerFormat corresponding to \a v4l2Format + */ +BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) +{ + auto it = std::find_if( + bayerToV4l2.begin(), + bayerToV4l2.end(), + [v4l2Format](const auto &i) { return i.second == v4l2Format; }); + if (it != bayerToV4l2.end()) + return it->first; + + return BayerFormat(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply