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 From patchwork Thu Dec 31 15:53:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10796 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 687A7C0F1A for ; Thu, 31 Dec 2020 15:54:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 33855615B2; Thu, 31 Dec 2020 16:54:34 +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="osYXTBqp"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 768346031D for ; Thu, 31 Dec 2020 16:54:32 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id i9so20397581wrc.4 for ; Thu, 31 Dec 2020 07:54:32 -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=lPJc7eMqmCuuqQDJUp+L5inJ3xbXv9i5YL4l+Jypyu4=; b=osYXTBqpexYfFDs2+fLXx+YVp0zDKqAGffZAdqFbLpmxA5etMGfzxRj/8c6Cm+qHZq LQJt+oMwPjAr1p4MaWmZG2sNzIMBdGgVD2Yn3xogK8XwW3E7oPUCcwnfx13jU8PkuIaN ZFEG7VCR9XnY3sUlu4YmRyKlrlZ/zBf70CCZc0NwMayfMfa/h79xcXSbvxMCP48O1vcG jNWcvng6q3/YomKlGA8CE5QY7rKNCLlhzUEN20DQNQINMl4vNbsRVT2ouoFf7b/e+9gh f2VIM5ot2+HWyGYw8OaTWHlDBy7ry7adohN2Wsn/8qQYn8JdMKySx19xhAaZ4+mEw0Of 8hbw== 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=lPJc7eMqmCuuqQDJUp+L5inJ3xbXv9i5YL4l+Jypyu4=; b=WLM+m4ZlMYYNKkrGF+JZWZTTSQwE15XT0ukGSSHzoKlkJCD4odcJz2/mWwqGHxIZh9 nVwjGmp3toADfD/ah/+0vJ1O3ZVOqZlq0eUBGektnzDNfF2Tq7tg5s/fmdA4L+aqHjZj IbGbW4FmprtQOrV/AJXasOUCsN2Qkzz8azszcv0ev6m+cLVInOkDadOreSWRPmY1m3rm Xp8Lu7b+MtKqTjSbl43v99KAztwAmxLyOxL96ZJA7GKkSDhpD9uxzEZY9992W75fzP1r C3y6z+tV3EyZEKtWpePVmWfeGu8HiznbPLrJ/jOZzilSDWrevX52BejwmSvofKGvBwQX gkiw== X-Gm-Message-State: AOAM530dpqJYZvCFb27Cznr1DT8U2G/6wunji8GXsNSwEcvMYZfp/onc 1Fw97tM1XWEEqxlhZsIwAOYHIWiPxJA= X-Google-Smtp-Source: ABdhPJxCi+/+erB7nTAj3Aq22K32N2/VdV3Sa2F99YfQDQu85+VcpLbeuZZbL/5EcHB7GzFB3iin5A== X-Received: by 2002:a5d:5227:: with SMTP id i7mr66899659wra.68.1609430072259; Thu, 31 Dec 2020 07:54:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 07:54:31 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Dec 2020 16:53:34 +0100 Message-Id: <20201231155336.7058-3-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 2/4] libcamera: Overload ==/!= operators for BayerFormats 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" Enable to test two Bayer formats for equality by checking if the order of the color channels, the bit depth of the pattern, and the packing scheme match. Additionally, add the reverse operation (!=), which negates the equality test result. Signed-off-by: Sebastian Fricke --- include/libcamera/internal/bayer_format.h | 7 +++++++ src/libcamera/bayer_format.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 8efe1382..298756e3 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -57,6 +57,13 @@ public: Packing packing; }; +bool operator==(const BayerFormat &lhs, const BayerFormat &rhs); +static inline bool operator!=(const BayerFormat &lhs, + const BayerFormat &rhs) +{ + return !(lhs == rhs); +} + } /* namespace libcamera */ #endif /* __LIBCAMERA_INTERNAL_BAYER_FORMAT_H__ */ diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 26065b66..b8635e15 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -160,6 +160,16 @@ std::string BayerFormat::toString() const return result; } +/** + * \brief Compare two BayerFormats for equality + * \return True if order, bitDepth and packing are equal, otherwise false + */ +bool operator==(const BayerFormat &lhs, const BayerFormat &rhs) +{ + return lhs.order == rhs.order && lhs.bitDepth == rhs.bitDepth && + lhs.packing == rhs.packing; +} + /** * \brief Convert a BayerFormat into the corresponding V4L2PixelFormat * \return The V4L2PixelFormat corresponding to this BayerFormat From patchwork Thu Dec 31 15:53:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10797 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 C0664C0F1A for ; Thu, 31 Dec 2020 15:54:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8C2BE615B4; Thu, 31 Dec 2020 16:54:36 +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="bGl1bYKb"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB7796031D for ; Thu, 31 Dec 2020 16:54:34 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id a6so7572641wmc.2 for ; Thu, 31 Dec 2020 07:54:34 -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=JeKcmpfqab8zYgc9B7pPMg9/TDryKELzcuN4CWwnkkc=; b=bGl1bYKb6E/1Xz6guYvWt1eEjU2ZDKibgZ2ATtado99IZtafW7ypcSrG136mYQMHPq oYWjGUFFuks3/aevRgql0DJDmCgZaPvC5T3rmW+lLe+0M2tYP1AehRW7BqjaQ9WX+jHG AltExtjliYRJc3QisSqwMevicB/42jQdISynHGvoGZhFOWh2yMqkQpCMGr1rbXjeRZ7C xiw2u38d8delI411Me81OcKCHDhAg/AlwN7SkbySXH6Gftfq1xJikMswM92UrGdVBsJM dih0O0wMdQ7DLKK80FPH04+Kn3M+On7NWWDFZhDWlQlnFjhbyYIoQUZBm9lNyJbNQFLJ 9sMA== 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=JeKcmpfqab8zYgc9B7pPMg9/TDryKELzcuN4CWwnkkc=; b=HiYV/dW7lMXC6vmLvakVy8pXZ/lFlJW2zk5r6/6pCTf7Eo49UTt71lr5OwZndn4cz6 aWN5xG7s4GM/ti1zHe7r6SqItYYnD7PmdxiOt0ph6gBD+wb7xT2yjKihZm3AdCe4vbLb jX0vY77xuyO8I+sMdT0fffEbtq4StjmfA7kQ1nRKvhSbVBvzGwAmO6gyE/Ho1kxAB8Bz pTVcGqHx1rhOMS+IoJI+BR5iPdWImbNmj/fAIYvXY1m4G2z1G3tElEWk7I8ciXR/No4u P02m1yIV2iqyX+l6UyAcOKmHggeqbBq42jSMlVIuNjh+9wUJ/HAusD+jN9UDGx8md4oC QYWQ== X-Gm-Message-State: AOAM533RoibtTLlq9excPUvy8Y750FBNd1OYLnUHQf0NDvDOBuIMArmJ rjyfm1wubkADSHnVpfa/lQksSl5pN4U= X-Google-Smtp-Source: ABdhPJxOydR6C76iB4zmOYoxjMAXI82A1NM11Y4z645obukiGBNgpEug9oJBR8Qx+WiC58gWTh5WgQ== X-Received: by 2002:a7b:c246:: with SMTP id b6mr12520083wmj.154.1609430074585; Thu, 31 Dec 2020 07:54:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 07:54:34 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Dec 2020 16:53:35 +0100 Message-Id: <20201231155336.7058-4-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 3/4] libcamera: pipeline: rpi: Adjust to new implementation 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" Remove the construction of a BayerFormat from a V4L2PixelFormat through the old constructor. Add the new 'fromV4L2PixelFormat' static member function. Signed-off-by: Sebastian Fricke --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 7a5f5881..8ca9b9cf 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -358,7 +358,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() */ V4L2PixelFormat fourcc = sensorFormat.fourcc; if (data_->flipsAlterBayerOrder_) { - BayerFormat bayer(fourcc); + BayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc); bayer.order = data_->nativeBayerOrder_; bayer = bayer.transform(combined); fourcc = bayer.toV4L2PixelFormat(); @@ -1007,7 +1007,7 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) BayerFormat bayerFormat; for (const auto &iter : dev->formats()) { V4L2PixelFormat v4l2Format = iter.first; - bayerFormat = BayerFormat(v4l2Format); + bayerFormat = BayerFormat::fromV4L2PixelFormat(v4l2Format); if (bayerFormat.isValid()) break; } From patchwork Thu Dec 31 15:53:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10798 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 28247C0F1A for ; Thu, 31 Dec 2020 15:54:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E855361D25; Thu, 31 Dec 2020 16:54:37 +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="mQcbRPzY"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 11B0B6031D for ; Thu, 31 Dec 2020 16:54:37 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id r4so7512403wmh.5 for ; Thu, 31 Dec 2020 07:54:37 -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=zuTY42ZMfo1siGVlU7k9dyTzIsNOKpMhoGanuRaVzjs=; b=mQcbRPzYPctM3GI3KCBLVxM6Q9Wk3es2noFD7li0ZJUSD2eXdMrJ7UOe8ddBD8TJv2 DFtilakc/WvBgQ846uzlniFD74qNm3dnVUylRVh8BPzTK1gghEF2+r+nhztRdLbsf4VW PdiOocqysVPUyyqutFMbvUpbJKH6YPDziBjoa/O+aDXum5FeG/aatFlF5HHlswV7CD9/ ut5DrfRhg86W09g0yiXhCbzPchd+b3A8ml9oujeqE50A6DZHiFnhFA8KKv+ReI6mB7/G meIw1aB9/B3j21uxS7qOdQa3rSDo1SVLkQXWzTi0NtLjGzt8FjCLNj6jhfpAsF/GK/2w ZG0A== 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=zuTY42ZMfo1siGVlU7k9dyTzIsNOKpMhoGanuRaVzjs=; b=LqkOuzfup3Eszt8dLwgJfMrVvJpBdmGCP20TnP7uCTuwdtrL1gT1fkuBiLK6mdM8Ja jliZqDDHw6VBFmbYNEm5tYAEl5rojuzFqUJVY8U/Y7LDJJUFaY1DoE0ULBoS2BO+jxDw J9367/01MI4zOmQLNwqyYxJbj2XDWsQfKKNtUWjVXe5IG/E72mDFc/v2at2i7mwr0KdC 8WNjVyy8vtXwmoxAmnMuHv6cyPg6I1n1RPJId6ByLJyFtdnyxMw2X+scVML58UahProx hFdU08uQ1svglNnFInh6plA4kAd76wELzad9pxFU8R3v9EdkGaBGDltyZdMv83E0x0EB svGw== X-Gm-Message-State: AOAM531yNqNGyFnaw3shmeuJick9TLQOYQsxJtTSfaEiZCTT6QngsbT7 xza9CUWRiWVEpLJj4h/NDew6DxnMBoo= X-Google-Smtp-Source: ABdhPJwkbJITxDzvhq/jnZwMV8rXApBDRlyFI8icMCuu5vjmujnu4wRStiTae7TxM5Au/nWU838dlw== X-Received: by 2002:a7b:c45a:: with SMTP id l26mr12451474wmi.91.1609430076766; Thu, 31 Dec 2020 07:54:36 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 07:54:36 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Dec 2020 16:53:36 +0100 Message-Id: <20201231155336.7058-5-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 4/4] test: Add unit tests for the BayerFormat class 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" Test all of the present methods including the newly implemented `fromV4L2PixelFormat`, as well as the new operators `==/!=`. Signed-off-by: Sebastian Fricke Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: David Plowman --- test/bayer_format.cpp | 202 ++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 203 insertions(+) create mode 100644 test/bayer_format.cpp diff --git a/test/bayer_format.cpp b/test/bayer_format.cpp new file mode 100644 index 00000000..dd7aa8cb --- /dev/null +++ b/test/bayer_format.cpp @@ -0,0 +1,202 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Sebastian Fricke + * + * bayer_format.cpp - BayerFormat class tests + */ + +#include + +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class BayerFormatTest : public Test +{ +protected: + int run() + { + /* + * An empty Bayer format has to be invalid. + */ + BayerFormat bayerFmt = BayerFormat(); + if (bayerFmt.isValid()) { + cout << "An empty BayerFormat " + << "has to be invalid." << endl; + return TestFail; + } + + /* + * A correct Bayer format has to be valid. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + if (!bayerFmt.isValid()) { + cout << "A correct BayerFormat " + << "has to be valid." << endl; + return TestFail; + } + + /* + * Two bayer formats created with the same order and bit depth + * have to be equal. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8, + BayerFormat::None); + if (bayerFmt != bayerFmtExpect) { + cout << "Two BayerFormat object created with the same " + << "order and bitDepth must be equal." << endl; + return TestFail; + } + + /* + * Two Bayer formats created with the same order but with a + * different bitDepth are not equal. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12, + BayerFormat::None); + if (bayerFmt == bayerFmtExpect) { + cout << "Two BayerFormat object created with the same " + << "order, but different bit depths are not equal." + << endl; + return TestFail; + } + + /* + * Create a Bayer format with a V4L2PixelFormat and check if we + * get the same format after converting back to the V4L2 Format. + */ + V4L2PixelFormat v4l2FmtExpect = V4L2PixelFormat( + V4L2_PIX_FMT_SBGGR8); + bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2FmtExpect); + V4L2PixelFormat v4l2Fmt = bayerFmt.toV4L2PixelFormat(); + if (v4l2Fmt != v4l2FmtExpect) { + cout << "Expected: '" << v4l2FmtExpect.toString() + << "' got: '" << v4l2Fmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Use a Bayer format that is not found in the mapping table + * and verify that no matching V4L2PixelFormat is found. + */ + v4l2FmtExpect = V4L2PixelFormat(); + bayerFmt = BayerFormat(BayerFormat::BGGR, 24, + BayerFormat::None); + v4l2Fmt = bayerFmt.toV4L2PixelFormat(); + if (v4l2Fmt != v4l2FmtExpect) { + cout << "Expected: empty V4L2PixelFormat got: '" + << v4l2Fmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Check if we get the expected Bayer format BGGR8 + * when we convert the V4L2PixelFormat (V4L2_PIX_FMT_SBGGR8) + * to a Bayer format. + */ + bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8, + BayerFormat::None); + v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8); + bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt); + if (bayerFmt != bayerFmtExpect) { + cout << "Expected BayerFormat '" + << bayerFmtExpect.toString() << "'," + << "got: '" << bayerFmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Confirm that a V4L2PixelFormat that is not found in + * the conversion table, doesn't yield a Bayer format. + */ + bayerFmtExpect = BayerFormat(); + V4L2PixelFormat v4l2FmtUnknown = V4L2PixelFormat( + V4L2_PIX_FMT_BGRA444); + bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2FmtUnknown); + if (bayerFmt != bayerFmtExpect) { + cout << "Expected empty BayerFormat got: '" + << bayerFmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Test if a valid Bayer format can be converted to a + * string representation. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + if (bayerFmt.toString() != "BGGR-8") { + cout << "String representation != 'BGGR8' (got: '" + << bayerFmt.toString() << "' ) " << endl; + return TestFail; + } + + /* + * Determine if an empty Bayer format results in no + * string representation. + */ + bayerFmt = BayerFormat(); + if (bayerFmt.toString() != "INVALID") { + cout << "String representation != 'INVALID' (got: '" + << bayerFmt.toString() << "' ) " << endl; + return TestFail; + } + + /* + * Perform a horizontal Flip and make sure that the + * order is adjusted accordingly. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8, + BayerFormat::None); + BayerFormat hFlipFmt = bayerFmt.transform(Transform::HFlip); + if (hFlipFmt != bayerFmtExpect) { + cout << "horizontal flip of 'BGGR-8' " + << "should result in '" + << bayerFmtExpect.toString() << "', got: '" + << hFlipFmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Perform a vertical Flip and make sure that + * the order is adjusted accordingly. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8, + BayerFormat::None); + BayerFormat vFlipFmt = bayerFmt.transform(Transform::VFlip); + if (vFlipFmt != bayerFmtExpect) { + cout << "vertical flip of 'BGGR-8' " + << "should result in '" + << bayerFmtExpect.toString() << "', got: '" + << vFlipFmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Perform a transposition and make sure that nothing changes. + * Transpositions are not implemented as sensors are not + * expected to support this functionality. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat transposeFmt = bayerFmt.transform( + Transform::Transpose); + if (transposeFmt.toString() != "BGGR-8") { + cout << "Transposition is not supported " + << "format should be 'BGGR-8', got: '" + << transposeFmt.toString() << "'" << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(BayerFormatTest); + diff --git a/test/meson.build b/test/meson.build index 0a1d434e..e985b0a0 100644 --- a/test/meson.build +++ b/test/meson.build @@ -23,6 +23,7 @@ public_tests = [ ] internal_tests = [ + ['bayer-format', 'bayer_format.cpp'], ['byte-stream-buffer', 'byte-stream-buffer.cpp'], ['camera-sensor', 'camera-sensor.cpp'], ['event', 'event.cpp'],