From patchwork Thu Oct 28 08:46:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14381 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 F0F05C324E for ; Thu, 28 Oct 2021 08:47:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1D6A60157; Thu, 28 Oct 2021 10:47:03 +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="jZtakmNQ"; 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 8D23E600C5 for ; Thu, 28 Oct 2021 10:46:56 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id b12so4351330wrh.4 for ; Thu, 28 Oct 2021 01:46:56 -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=AQhsv8etWZt5rB647X08XTKP+f4z+ciJxLxbIs36LKg=; b=jZtakmNQmmcpsc8dBGVBtmVK7RADULtSkVMmmIrRFNYzwY7ZBqrQnX+AY7/V2eYtAR 7lzmn3e09HAPyFnwjyMOq2nTv8qjIUt76KNyTVYcvqdEG/1qSzytxuORuSDfExcfW7a3 SqZY6/PtL9x1qGlXTCLulNsGAX9wQKlB2fGe0+n6xT0FHmBCVtFtBuufyh9ZBMA5IstH oQp6jlik+Uh2DjJFMj4k7FRpz/IXFnihy2PqyFl2p49X6ShlCkTsegPBqxMvRfrXFGGP aGDJi9eMT1TXtcJqnnfQ6bljpDvOr3fKhf8XU/xXNEWcqkaLi1nMX61z3yakkspUWxaQ 9oYQ== 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=AQhsv8etWZt5rB647X08XTKP+f4z+ciJxLxbIs36LKg=; b=d/NLc/JftL5iyKAlTkwYJrf+B0JZEOsriYtr7jsbvETxbg2oz4H/hC7eWbGCSawxJq SCiuXi4kNFGdMzaUo+avUIAa5ImFIwj/ggkvigdg5XKfajIEiBp1M7bzxRcn4Uh42Y9p FH3vBHqjJYxje5LB5uY6NItC7NZGHDa5H3QX53HbgUZTLp8/UG89iLD8qJXtLqyA/iHw llCScWAQ6sY5rJodz65guiSZk0S6arI5wuKDxtET/qSLykfuQfh+KEqjVXRgm1Ckm2+W gRUqp2GQl8k3Ao4wugBaqKH/FKELDtuzbo1SyXGbNGj04l7otie8hUPPoMB8CPPz/Tc7 111w== X-Gm-Message-State: AOAM5326o2mDa1Grmryvx0QvDkxK7aEtcU4BMqEvwT63p7IwmrqvP028 v13MxwKOb/2mXMFEex59hGvXOzYSFhDQze6g X-Google-Smtp-Source: ABdhPJz6Jod+p07Wl9A8i9OckdPHs+fqoN05SVe2PKzcAAi9wzBkQRvPl0ECG4LkTFvQowXL4ctlbw== X-Received: by 2002:adf:c183:: with SMTP id x3mr3993052wre.90.1635410816019; 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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:55 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:41 +0100 Message-Id: <20211028084646.453775-6-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 05/10] libcamera: bayer_format: Rework BayerFormat conversion table 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" Rename the bayerToV4l2 conversion table to bayerToFormat. Update the table to hold both the PixelFormat and V4L2PixelFormat conversions for a given BayerFormat. This will allow converting between BayerFormat and PixelFormat types in a subsequent change. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/libcamera/bayer_format.cpp | 112 ++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 1c1e849a7e31..8665a025f7e0 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -13,6 +13,7 @@ #include +#include #include /** @@ -84,37 +85,74 @@ struct BayerFormatComparator { } }; -const std::map bayerToV4l2{ - { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) }, - { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) }, - { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) }, - { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) }, - { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) }, - { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) }, - { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) }, - { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) }, - { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) }, - { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) }, - { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) }, - { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) }, - { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) }, - { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) }, - { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) }, - { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) }, - { { BayerFormat::MONO, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) }, - { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) }, +struct Formats { + PixelFormat pixelFormat; + V4L2PixelFormat v4l2Format; +}; + +const std::map bayerToFormat{ + { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, + { formats::SBGGR8, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) } }, + { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, + { formats::SGBRG8, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) } }, + { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, + { formats::SGRBG8, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) } }, + { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, + { formats::SRGGB8, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) } }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, + { formats::SBGGR10, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) } }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, + { formats::SGBRG10, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) } }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, + { formats::SGRBG10, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) } }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, + { formats::SRGGB10, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) } }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, + { formats::SBGGR10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) } }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, + { formats::SGBRG10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) } }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, + { formats::SGRBG10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) } }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, + { formats::SRGGB10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) } }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, + { formats::SBGGR10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) } }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, + { formats::SGBRG10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) } }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, + { formats::SGRBG10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) } }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, + { formats::SRGGB10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) } }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, + { formats::SBGGR12, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) } }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, + { formats::SGBRG12, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) } }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, + { formats::SGRBG12, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) } }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, + { formats::SRGGB12, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) } }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, + { formats::SBGGR12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) } }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, + { formats::SGBRG12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) } }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, + { formats::SGRBG12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) } }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, + { formats::SRGGB12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) } }, + { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, + { formats::SBGGR16, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) } }, + { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, + { formats::SGBRG16, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) } }, + { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, + { formats::SGRBG16, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) } }, + { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, + { formats::SRGGB16, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) } }, + { { BayerFormat::MONO, 8, BayerFormat::Packing::None }, + { formats::R8, V4L2PixelFormat(V4L2_PIX_FMT_GREY) } }, + { { BayerFormat::MONO, 10, BayerFormat::Packing::None }, + { formats::R10, V4L2PixelFormat(V4L2_PIX_FMT_Y10) } }, + { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, + { formats::R10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) } }, }; const std::unordered_map mbusCodeToBayer{ @@ -245,9 +283,9 @@ bool operator==(const BayerFormat &lhs, const BayerFormat &rhs) */ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const { - const auto it = bayerToV4l2.find(*this); - if (it != bayerToV4l2.end()) - return it->second; + const auto it = bayerToFormat.find(*this); + if (it != bayerToFormat.end()) + return it->second.v4l2Format; return V4L2PixelFormat(); } @@ -259,11 +297,11 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const */ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) { - auto it = std::find_if(bayerToV4l2.begin(), bayerToV4l2.end(), + auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(), [v4l2Format](const auto &i) { - return i.second == v4l2Format; + return i.second.v4l2Format == v4l2Format; }); - if (it != bayerToV4l2.end()) + if (it != bayerToFormat.end()) return it->first; return BayerFormat();