From patchwork Thu Oct 28 08:46:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14382 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 9FE51BF415 for ; Thu, 28 Oct 2021 08:47:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 43A3260158; Thu, 28 Oct 2021 10:47:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="RuTlLia2"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 61212600B6 for ; Thu, 28 Oct 2021 10:46:57 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 192so3458055wme.3 for ; Thu, 28 Oct 2021 01:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YPq00NOuoRgq46bBhppDBKpNY7cAdhvldaSzvXvOLbo=; b=RuTlLia2DBcIksf1GDNyjNuQUhVW1x2Xp/FE4BTPeWs4wwQjtrZzLmloxgX37RtSRR Bp1q4IJc6o33Tru6yrmOPmRxR/4MFxFYBjto4xwINc1nwZrOuQCnBlMmTVuNwHgBG8i1 vI75rlfqjEA4TnRe61gwXVjJcKZMmiJnZ+/Kw5j9IN+7ARyM1GI3Hj0SnNm9G3xhYF/i Ur6Pp++nY/EKEXw2CAqgZpfvHNYYLfw+rKUWt15CdVJIxW0cMLpTAOhbU6DXBuOH7jke AXsGfg1uP6sKW4lKdDjbudEQhfycY/jt+mPakUS53oU9LHtBfiRnHfUt4/p7ynm4kPR2 ZEOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YPq00NOuoRgq46bBhppDBKpNY7cAdhvldaSzvXvOLbo=; b=3ZNuxzxXzPvfQeu6hwsfTeI4szzYbnfi8zeJxX6o6j9l7QyEEiKUSKyLt9xzQf9EVb Veifo5x8ETAhvdTrmKo9YqBTS/dh/MQc5ZC8Cw2KJzvvJjQtNFJlS5UEqYUq5Aw8yPvD 0CeE+Ow95xFuKffuiXt3YOQbbxTrfanFIzc9v7q9cxyFZdcvILqUsuVq6ZJG8j7d2VoS D3eGYiAU6XjstOs0y9gExp+PPUmpIJP4+bB6+NTgiO+0lZCo1oKYWVtoERxJDTTTJ1Hy WKXyNsqWdzCU++5SVfY8kzjYBptCvQjitgavyTkECbHTZVj0/T2niNNN1UKOV79t/0pB NGsw== X-Gm-Message-State: AOAM531bmEC6y53dYaDq0q+2UaedyquSDCeJLKnT8o3HuSIaeChmTYEO n6ubri91H20XWlX1Xu1/kDfMW3BPb9wZJMZQ X-Google-Smtp-Source: ABdhPJzSkUjhXmqMP+MI9FvkWilAEB5Mmv6MIjdfVOxFjynnQyST7Hg9SPsLLScv61Xt08bD5pmAmQ== X-Received: by 2002:a1c:2541:: with SMTP id l62mr11048667wml.11.1635410816905; Thu, 28 Oct 2021 01:46:56 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:56 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:42 +0100 Message-Id: <20211028084646.453775-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/10] libcamera: bayer_format: Add PixelFormat conversion helpers to 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" Add BayerFormat::toPixelFormat() and BayerFormat::fromPixelFormat() helper functions to convert between BayerFormat and PixelFormat types. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/bayer_format.h | 4 ++++ src/libcamera/bayer_format.cpp | 29 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index d9a56d744a25..79a25b52582d 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -10,6 +10,8 @@ #include #include +#include + #include "libcamera/internal/v4l2_pixelformat.h" namespace libcamera { @@ -50,6 +52,8 @@ public: V4L2PixelFormat toV4L2PixelFormat() const; static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); + PixelFormat toPixelFormat() const; + static BayerFormat fromPixelFormat(PixelFormat format); BayerFormat transform(Transform t) const; Order order; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 8665a025f7e0..1805d6fbbab9 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -307,6 +307,35 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) return BayerFormat(); } +/** + * \brief Convert a BayerFormat into the corresponding PixelFormat + * \return The PixelFormat corresponding to this BayerFormat + */ +PixelFormat BayerFormat::toPixelFormat() const +{ + const auto it = bayerToFormat.find(*this); + if (it != bayerToFormat.end()) + return it->second.pixelFormat; + + return PixelFormat(); +} + +/** + * \brief Convert a PixelFormat into the corresponding BayerFormat + * \return The BayerFormat corresponding to this PixelFormat + */ +BayerFormat BayerFormat::fromPixelFormat(PixelFormat format) +{ + const auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(), + [format](const auto &i) { + return i.second.pixelFormat == format; + }); + if (it != bayerToFormat.end()) + return it->first; + + return BayerFormat(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply