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; }