From patchwork Mon Nov 1 09:15:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14442 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 82A9BC324E for ; Mon, 1 Nov 2021 09:15:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 374AA60326; Mon, 1 Nov 2021 10:15:22 +0100 (CET) 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="CC54aEAQ"; 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 5700B600C8 for ; Mon, 1 Nov 2021 10:15:18 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id j128-20020a1c2386000000b003301a98dd62so8282498wmj.5 for ; Mon, 01 Nov 2021 02:15:18 -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=CC54aEAQgdstehTc4vf/gb45MzoUJImCC5bBe/aCpHbkY33409EL3gxNUHfGwsxn7U oDaz+urJ98BgxMZdszkwDCK3uAE6RklCGxwwCLk5uvpSGhR/fvUfcr0ejCKivQSHEbwx Czl2SB8Uyp1ed/1B5nTL1+qrbT+UjephMfIf8FEgvJe8oZqrJEsht9mJf+MJ3nK6so7h nmf3/V0TnPUTPdKo1aOYlRKdXEOKfrcrqJ1smzYZLKHUK4R5KkbxbIhXXwB5zbFbFVCm Lw5anrtqOut5L/qSCxbvmrXJw1I5g1s2VdDDWh9E8PHseAA3dQVAFkye1dTh3Zp2H1xt dsRA== 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=vO6JUGiEiWESJE28akCAzcZGli1sqfUrI1BGUQkifZr1jg0bXicT/MjVDpv7M6KZCy bP5kBsbepUZfSKyNcvRZI8gKT1Udm8vpRAPdaMDz/ngCt3SDb2w/ZPZBDrf1sGlmZ2/+ CQ2bofuSS0+IK6TWRMCMpqb1ZZkSi0FCqf9epFqli8NRt3LabCcZ9LYuEcpl3qncTmEZ +FikpZOE/k6NV+mnmX+NJfv49eM5GLEaIVXxuFdUEGydVa39GgREyT8R29PKDRwH7bXL GYLncLT6e640ih4601E/xHM4+onq+ulm6yRiFydmSGb+Rd9jJMyq0A0Xm7eJzi4MXP0i GF7A== X-Gm-Message-State: AOAM533hJq6trqXAlUz/6gaH9vl+TDVTAbr0+CLgS32HLjkvuMICeoRz 06WRzhRLj9CkSl2QL7Pl61/DpmmtISoRIyQG X-Google-Smtp-Source: ABdhPJxKOdXT/TzHVMjPROpVPMncNJCfvVUj236lj7KOreA4P/HOK1Q+L8HbVJxO/mdrdf0F6Vp9aw== X-Received: by 2002:a05:600c:202:: with SMTP id 2mr11958755wmi.134.1635758117905; Mon, 01 Nov 2021 02:15:17 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:17 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:06 +0000 Message-Id: <20211101091510.23204-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 07/11] 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