From patchwork Tue Jan 26 18:48:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 11024 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 2FF92C0F2B for ; Tue, 26 Jan 2021 18:49:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F2B736831F; Tue, 26 Jan 2021 19:49:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=posteo.net header.i=@posteo.net header.b="KRMUj23m"; dkim-atps=neutral Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 352E668318 for ; Tue, 26 Jan 2021 19:49:06 +0100 (CET) Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id B77D9160063 for ; Tue, 26 Jan 2021 19:49:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1611686945; bh=pVuAQnOqNuAWBI3sg8dF4GMG/86bozPkwcNbIwDQFIA=; h=From:To:Cc:Subject:Date:From; b=KRMUj23mYrAuFocdpRf8KgpnnNoQIKST/Bm0GJDQqMxuh8a5N8SnpDI1W/Vqa8wHx aI/gvmtZqIY0vFFBT50WrbJVk5n1I76eBxthMMEBZ4DwcJuXX+YWpTX65Ppz6ZCltq 1g+tEC680NaEkCzK7pTB+pYQb70vuRq7/B7Qn6janO7HnUj7hgBmw877rSrc5Gh7w7 zLQP5UuSfTOhTPqKgxDvqkYkpvW4sjDwGwtq1Q+9sjJ8zNltox+mDvQbrba0tiayUi 00tF4xJqWl4DpqUcqYQhZOWvOM8go4AO0xSG8bQAkOJKceC4KbarTUhq5tR3Ytd192 /xzp9Ge3eoBvA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DQG3h6pF7z6tm9; Tue, 26 Jan 2021 19:49:04 +0100 (CET) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jan 2021 19:48:50 +0100 Message-Id: <20210126184854.46156-2-sebastian.fricke@posteo.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126184854.46156-1-sebastian.fricke@posteo.net> References: <20210126184854.46156-1-sebastian.fricke@posteo.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/5] 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 BayerFormat from a given V4L2PixelFormat. 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. The downside of this change 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. Reviewed-by: Laurent Pinchart Signed-off-by: Sebastian Fricke --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 18 ++++++++++++++++++ .../pipeline/raspberrypi/raspberrypi.cpp | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index dc86f6ee..4f338bd7 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -49,6 +49,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 a6a40be0..9eb83898 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 @@ -272,6 +273,23 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const return V4L2PixelFormat(); } +/** + * \brief Convert \a v4l2Format to 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 diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 524cc960..236aa107 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 Tue Jan 26 18:48:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 11025 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 9095FC0F2B for ; Tue, 26 Jan 2021 18:49:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 623A268325; Tue, 26 Jan 2021 19:49:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=posteo.net header.i=@posteo.net header.b="ORVEw45n"; dkim-atps=neutral Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91E1D68318 for ; Tue, 26 Jan 2021 19:49:11 +0100 (CET) Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 308AF240102 for ; Tue, 26 Jan 2021 19:49:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1611686951; bh=UgHDgb/71kG2zzqdTX3HyhKfUPPnvJv+f1MZXScVXY0=; h=From:To:Cc:Subject:Date:From; b=ORVEw45n5BWWh99XCe7cRU2v+WOQrIzLoZLLQEppmdY3wqXGpPYSgUVYyKz5wLIqH k5vVv4pOyfgL90itXeNkjVDMKOLd7gfD3xNaWa+zTtCd2p/vyh4Ozky7BOB/CpmJiZ 3f2p/Pyyqw71rsSsutmgmlMtmz0sdFRh7FD/Lj8qzQBAmv9EuwE1nyZNOP/gT4PDFV K8wskGcseH2F9gKwtA4joPX2YLL1FGvcOBrkcYBwF42GPqjIYf6mKGKuu3bN6p9OGn KUcKrd1BLOeYT2FA1yscTTTRVovofn7tV2OThzpFaDMT7KhhJ819YDAM0LKYUYTMaQ JoqJ5wEK3QdwQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DQG3p2JMYz6tmb; Tue, 26 Jan 2021 19:49:10 +0100 (CET) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jan 2021 19:48:51 +0100 Message-Id: <20210126184854.46156-3-sebastian.fricke@posteo.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126184854.46156-1-sebastian.fricke@posteo.net> References: <20210126184854.46156-1-sebastian.fricke@posteo.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/5] libcamera: Remove unnecessary constructor 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" The new `fromV4l2PixelFormat` static member function renders an old BayerFormat constructor useless, remove it together with the `v4l2ToBayer` mapping table. The new function searches for a matching mapped value instead of a matching key, therefore the `bayerToV4l2` table is sufficient. Signed-off-by: Sebastian Fricke Reviewed-by: Laurent Pinchart --- include/libcamera/internal/bayer_format.h | 1 - src/libcamera/bayer_format.cpp | 45 ----------------------- 2 files changed, 46 deletions(-) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 4f338bd7..62814154 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -42,7 +42,6 @@ public: { } - explicit BayerFormat(V4L2PixelFormat v4l2Format); static const BayerFormat &fromMbusCode(unsigned int mbusCode); bool isValid() const { return bitDepth != 0; } diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 9eb83898..1acf91d4 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -61,37 +61,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 @@ -194,20 +163,6 @@ const std::unordered_map mbusCodeToBayer{ * \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; -} - /** * \brief Retrieve the BayerFormat associated with a media bus code * \param[in] mbusCode The media bus code to convert into a BayerFormat From patchwork Tue Jan 26 18:48:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 11026 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 EF22DC0F2B for ; Tue, 26 Jan 2021 18:49:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1D7D68325; Tue, 26 Jan 2021 19:49:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=posteo.net header.i=@posteo.net header.b="O/UtsOXt"; dkim-atps=neutral Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F0BB6831B for ; Tue, 26 Jan 2021 19:49:13 +0100 (CET) Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 63CE4160065 for ; Tue, 26 Jan 2021 19:49:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1611686952; bh=+00HLx0KNbfNb3pJkp3DsR3jnsaHQiRJZjK7sADvAMI=; h=From:To:Cc:Subject:Date:From; b=O/UtsOXty7ld0Mvi/1tmY/2MxICd90a6q3iJHFjgvjNpzsIMHl1szZ/4T8lMSbZX0 W1R0H60Zmj0hkAfFoBtk5ZBxyQ9ZeWse+IF+U4pj+0f/B4PA221AnwzeMLtYg2qhws H50TaChDwtIfpOi0jFoeewyjoLg+1NhxocpHFBWCmhrdmQn3zka/U//Xi1IkcVNvFF 2dFEPAY0G5Vf9x5xurYcQSXAwxjorIHg8/GCwUg43gRzc7kKnDb3qwfbah2CEuehEn SqoEyaW6EK87fzzyPqCHPhr3KsfIwbJ1UKbPducGTDzXmbQIFq3hdtzahNOxcG1JIa 7sM/DY5F48Dhw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DQG3q4HmWz6tm9; Tue, 26 Jan 2021 19:49:11 +0100 (CET) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jan 2021 19:48:52 +0100 Message-Id: <20210126184854.46156-4-sebastian.fricke@posteo.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126184854.46156-1-sebastian.fricke@posteo.net> References: <20210126184854.46156-1-sebastian.fricke@posteo.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/5] 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 Reviewed-by: Laurent Pinchart Reviewed-by: Laurent Pinchart --- include/libcamera/internal/bayer_format.h | 6 ++++++ src/libcamera/bayer_format.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 62814154..5b8c1dc9 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -57,6 +57,12 @@ 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 1acf91d4..d4e7f142 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -215,6 +215,23 @@ 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; +} + +/** + * \fn bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs) + * \brief Compare two BayerFormats for inequality + * \return True if either order, bitdepth or packing are not equal, otherwise + * false. + */ + /** * \brief Convert a BayerFormat into the corresponding V4L2PixelFormat * \return The V4L2PixelFormat corresponding to this BayerFormat From patchwork Tue Jan 26 18:48:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 11027 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 82FEBC0F2B for ; Tue, 26 Jan 2021 18:49:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2E67F68331; Tue, 26 Jan 2021 19:49:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=posteo.net header.i=@posteo.net header.b="SjgioRzT"; dkim-atps=neutral Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB7B86831D for ; Tue, 26 Jan 2021 19:49:13 +0100 (CET) Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 8C7F62400FF for ; Tue, 26 Jan 2021 19:49:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1611686953; bh=FNWKW/f0pRuFSFWTBHX5dD9QOT5+GCUXbyd0LRC3eyI=; h=From:To:Cc:Subject:Date:From; b=SjgioRzTEklb4SJD+zDN8OnKREJQ8uNhTgHmoSUbf7chfQ5TaPHS5s0dwrPTy5Ujo +Z8ZYjWL29yZDcCaP1vXmBEmjT5QXN5KWts4k8PsR4N/xr39VcWZw9iV9Ue4f/RPPJ eEt9H3TQxnWaZdtVk9HD07+EDgHHcX8CVPv8jcf7G1g8Rshz+OxemHT5rI9vFtkdBn s9omU0Co42+0OM0qBjMDCPsptSlOenAmQ1aR+1PYeTojmgO0C/FLEWU7JPTCUljdhd 3uYUigPTwkHlLG/Bkc9MObZmpL3EFcrwJKd+iFroBCa1PqlCcwWoft9S/An5+VaFNT NYXcc4jPuxifQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DQG3r6Z6dz6tm8; Tue, 26 Jan 2021 19:49:12 +0100 (CET) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jan 2021 19:48:53 +0100 Message-Id: <20210126184854.46156-5-sebastian.fricke@posteo.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126184854.46156-1-sebastian.fricke@posteo.net> References: <20210126184854.46156-1-sebastian.fricke@posteo.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/5] libcamera: Add the transpose transformation 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" To transpose a BayerFormat means to flip it over its main-diagonal. For example: G B G R -> R G B G The main-diagonal goes from the top left to the bottom right. This means, that the only two orders affected by a transpose are GBRG & GRBG. When a transpose is used in combination with horizontal and/or vertical flips it is performed with the lowest priority. Therefore add the functionality by switching GBRG (index 1) with GRBG (index 2), after the flips have been applied. Signed-off-by: Sebastian Fricke Reviewed-by: Laurent Pinchart Reviewed-by: David Plowman --- src/libcamera/bayer_format.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index d4e7f142..e06cd6e8 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -272,10 +272,6 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) * The transformed image would have a GRBG order. The bit depth and modifiers * are not affected. * - * Note that transpositions are ignored as the order of a transpose with - * respect to the flips would have to be defined, and sensors are not expected - * to support transposition. - * * \return The transformed Bayer format */ BayerFormat BayerFormat::transform(Transform t) const @@ -292,6 +288,11 @@ BayerFormat BayerFormat::transform(Transform t) const if (!!(t & Transform::VFlip)) result.order = static_cast(result.order ^ 2); + if (!!(t & Transform::Transpose) && result.order == 1) + result.order = static_cast(2); + else if (!!(t & Transform::Transpose) && result.order == 2) + result.order = static_cast(1); + return result; } From patchwork Tue Jan 26 18:48:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 11028 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 15EF5C0F2B for ; Tue, 26 Jan 2021 18:49:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DABB468328; Tue, 26 Jan 2021 19:49:17 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=posteo.net header.i=@posteo.net header.b="XoOomGw8"; dkim-atps=neutral Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C98668318 for ; Tue, 26 Jan 2021 19:49:15 +0100 (CET) Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 42A552400FC for ; Tue, 26 Jan 2021 19:49:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1611686955; bh=p4guerxYT6XCR8Sx1YJ/pZQdRHxcrsGsZMPxWlJTB7E=; h=From:To:Cc:Subject:Date:From; b=XoOomGw8moDgWdcWP1KlhYywUzccySEYP/oFPFZXQhdsSmG4Q2+Z6IqqobGxiDhsD uUQkLZl8EJmMhRj0z3+fStZqqsjpDr3vRJB6hyavhVSWbIdOQ633fYFGlwRG9S0b8V W6OH7vGquv7z+bIlWwt/mE/siZyMk1nJnIYeay7Ys3plyGV72hlIlDQBBrGeGmmnn0 1yLRZj2LsS11SMHgGL42MfCzO/l5I1ez/9n5M9xCYB0TKNI6hfuacLJ0WiEIgaBJLa E1LwMEy1c16MSyoBtvAm4QjAgfOI6WVEeDl2tV+gpuKkz0crkR7gzGjNc7t0Oc8mMz +vYDzBKsorIUw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DQG3t4NLQz6tm8; Tue, 26 Jan 2021 19:49:14 +0100 (CET) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jan 2021 19:48:54 +0100 Message-Id: <20210126184854.46156-6-sebastian.fricke@posteo.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126184854.46156-1-sebastian.fricke@posteo.net> References: <20210126184854.46156-1-sebastian.fricke@posteo.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/5] 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 `==/!=`. Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: David Plowman Signed-off-by: Sebastian Fricke --- test/bayer_format.cpp | 210 ++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 211 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..f763500f --- /dev/null +++ b/test/bayer_format.cpp @@ -0,0 +1,210 @@ +/* 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; + if (bayerFmt.isValid()) { + cerr << "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()) { + cerr << "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) { + cerr << "Comparison of identical formats failed." + << 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) { + cerr << "Comparison of divergent formats failed." + << 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) { + cerr << "Expected: '" << v4l2FmtExpect.toString() + << "' got: '" << v4l2Fmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Use an empty Bayer format and verify that no matching + * V4L2PixelFormat is found. + */ + v4l2FmtExpect = V4L2PixelFormat(); + bayerFmt = BayerFormat(); + v4l2Fmt = bayerFmt.toV4L2PixelFormat(); + if (v4l2Fmt != v4l2FmtExpect) { + cerr << "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) { + cerr << "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. + */ + V4L2PixelFormat v4l2FmtUnknown = V4L2PixelFormat( + V4L2_PIX_FMT_BGRA444); + bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2FmtUnknown); + if (bayerFmt.isValid()) { + cerr << "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") { + cerr << "String representation != 'BGGR-8' (got: '" + << bayerFmt.toString() << "' ) " << endl; + return TestFail; + } + + /* + * Determine if an empty Bayer format results in no + * string representation. + */ + bayerFmt = BayerFormat(); + if (bayerFmt.toString() != "INVALID") { + cerr << "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) { + cerr << "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) { + cerr << "Vertical flip of 'BGGR-8' should result in '" + << bayerFmtExpect.toString() << "', got: '" + << vFlipFmt.toString() << "'" << endl; + return TestFail; + } + + /* + * Perform a transposition on a pixel order with both green + * pixels on the bottom left to top right diagonal and make + * sure, that it doesn't change. + */ + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat transposeFmt = bayerFmt.transform( + Transform::Transpose); + if (transposeFmt != bayerFmt) { + cerr << "Transpose with both green pixels on the " + << "antidiagonal, should not change the order " + << " result: '" << transposeFmt.toString() << "'" + << endl; + return TestFail; + } + + /* + * Perform a transposition on an pixel order with red and blue + * on the bottom left to top right diagonal and make sure + * that their positions are switched. + */ + bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::None); + bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8, + BayerFormat::None); + transposeFmt = bayerFmt.transform(Transform::Transpose); + if (transposeFmt != bayerFmtExpect) { + cerr << "Transpose with the red & blue pixels on the " + << "antidiagonal, should switch their position " + << " result: '" << transposeFmt.toString() << "'" + << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(BayerFormatTest); diff --git a/test/meson.build b/test/meson.build index 7f0682ad..709b47aa 100644 --- a/test/meson.build +++ b/test/meson.build @@ -27,6 +27,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'],