From patchwork Mon Nov 1 09:15:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14440 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 9C77CC324F for ; Mon, 1 Nov 2021 09:15:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 30AFA60329; Mon, 1 Nov 2021 10:15:21 +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="W6Nf2gX5"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D14C60123 for ; Mon, 1 Nov 2021 10:15:17 +0100 (CET) Received: by mail-wm1-x32c.google.com with SMTP id v127so12816751wme.5 for ; Mon, 01 Nov 2021 02:15:17 -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=4h+Hq4Z7h1kX/XifGZPKWYh0O2oL6hH6gJ4EJSh8gwU=; b=W6Nf2gX5QmXPlUV8hdaZujjALynBXnx7iaeYLrjiXeiLL9ZTDWkk5Y7W1RB8GV7lz7 Q0K48guCqkkK6oxVV+eNQQ7rMhHk+xTvv37ycXZuVBB+z2cpxsaVOgd0iP6j/K0/L+rT bvr8yke3Dddxod+hJ8uJDKg+ZHbF9jozLebKeQi9iVHPYbAQz8nrDRVvBkT4OHLSDOYW 6j78ffEXIFSw2cma4lzQ9+RF/WCE7pgV5HrkjJVV4a6lfsT2WJjG8awCH8aGA0Ak0TF1 NuR7ITRBeOyEQSFGXIXFQEHwgApN1xqe8pD8Gxrgn29BTrjvk4qur/B7aomA4O9u34TL 80pA== 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=4h+Hq4Z7h1kX/XifGZPKWYh0O2oL6hH6gJ4EJSh8gwU=; b=ivlfA9A+XF/zECdXf/CyOARQaZjNffFClpmqQ03b7SGOM1sBW6l1HZpxw0BIlaM0p5 vp2LGX7Kvvs9weZEGkQUk4qQugVC63OjMzLTm65rM7Nw6/itLgjdpPoIajZYwuhvcmML L/eCCMrISjSWRKbez5gLDn/jLwBQrPv6CW2cXcHYa07Csmx7PdE/WumkhO2TMLCbSbr3 sGDXZN3c2oFXnOW7YpgbSXQNcV1SSK67Qgoj/9/HzT19Ow1j/PgCpF7Eo4nWaBcqglps RD8aTo0772MPmT6vtcIyi6mvdKP9A9H+1d82HM8xE83ZBhuF3XYubecW6T0pUsUPCLc4 zadQ== X-Gm-Message-State: AOAM53249oOCFiuKnfb7K9RHy/NPkLaZU59lPBQCO+GJYbVOT9ajS28G w0ztnDIpEAwNNuWattgnXzGKt9Lxuk9bn5Tn X-Google-Smtp-Source: ABdhPJzZ0FODq536f1KvQlM7wKlj4K/pXksuN498qj61E3y3VlW3XSNowc0ZtnKOnhfbCkaQgsN/yg== X-Received: by 2002:a05:600c:253:: with SMTP id 19mr6986662wmj.179.1635758116454; Mon, 01 Nov 2021 02:15:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:16 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:04 +0000 Message-Id: <20211101091510.23204-6-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 05/11] 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 | 110 ++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 1c1e849a7e31..120115ce8f62 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -13,6 +13,7 @@ #include +#include #include /** @@ -84,37 +85,72 @@ 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::CSI2 }, + { formats::R10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) } }, }; const std::unordered_map mbusCodeToBayer{ @@ -245,9 +281,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 +295,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();