From patchwork Fri Oct 22 11:55:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14253 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 0685DBF415 for ; Fri, 22 Oct 2021 11:55:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7836668F59; Fri, 22 Oct 2021 13:55:44 +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="dddLCyk8"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C4746012A for ; Fri, 22 Oct 2021 13:55:42 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id i12so1875964wrb.7 for ; Fri, 22 Oct 2021 04:55:42 -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=1+yQGT8m0ouNkcWR6TMH7jsBxo1G5lAbrwkO3omOMbI=; b=dddLCyk8xzdbd3MIStqiyTHKBC29VqqPKykYVPK9Vg/sM2T7/pa0kUVC8B32JrbiHC G2vUguzbo8vmjNQHAnfqx42H7tIABzxAS7L7Rj4vx4Pb7WSYgkIj/HrbewYwZ13eTnLk bLRAxwdWBirxUJcE/6Ch6/PnQE6U5tZvM7y1o2baAHYymiiDEbZzceXk900qxxRsJ+S9 G1+M/7uUoIvPyRtfb8sqwy8cbcf1Me7/4KMatvmvfkyIzfqeCdkCZmHFDHD0wKTMfUNg 4lLkjBCj1MDts45oG3HFRsSV5ewibM63ZWbzhi/z4XMV9wZDWfzo8Q/krQ3nIPT+9BCz rCZg== 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=1+yQGT8m0ouNkcWR6TMH7jsBxo1G5lAbrwkO3omOMbI=; b=wDGyvX+07LQ+wzbqDen0aQM9ITt4tUv2V15J+hSAlLeXCGmHphmHEnhYwYtPqdYx6m O8HBI/ZIJwG1yBc21E4gPZzzX+CY1asjwgWEvp0kC6hoiDkEPxjiTNN3XEYK0V7at6n2 TpmlSOFCmT64oQO14c8edsBqt7dA8SCDXC/+eiaZITgbFlA5+qoNQOREKZZx1NyJ7rw+ iEcCHPXHkPjRBJSpy+T7mgLIA7/XGAPUjIRBFFRtc1bhARohnAmhCwhjnJ3dHlzpv1tP M9zH3Ts4YxSj6bOFH37hxc5BVSUGgrbONxK/zcSEiJz85uAu1czw/AXYQ7s2xrf4pcIV HFPQ== X-Gm-Message-State: AOAM532/BdWlx8WsidHQJlUsOINRbgobua3CgESvFsC9fZxIQLVjV5D3 6l0juxyWgkIKvA4MMnhr5h1wHn3zwxp7zA== X-Google-Smtp-Source: ABdhPJyTdNFsNsJdJ9U84JtNBld5TMfhAHuyi+RQOYU9nXC6gw4AX2iP0tX0OC4s/QmVGZ0hsjZlyw== X-Received: by 2002:adf:fe45:: with SMTP id m5mr15114630wrs.197.1634903741586; Fri, 22 Oct 2021 04:55:41 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:f00d:ddf0:61b0:a4cd]) by smtp.gmail.com with ESMTPSA id l5sm7853364wru.24.2021.10.22.04.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 04:55:41 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Oct 2021 12:55:32 +0100 Message-Id: <20211022115537.2964533-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211022115537.2964533-1-naush@raspberrypi.com> References: <20211022115537.2964533-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/6] libcamera: bayer_format: Add conversion helpers to the 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 a BayerFormat::toMbusCode() member function to convert a BayerFormat to an mbus code defined by the V4L2 specification. Add a BayerFormat::toPixelFormat() member function to convert a BayerFormat to a PixelFormat type. This conversion uses the existing bayerToV4l2 conversion table. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- include/libcamera/internal/bayer_format.h | 4 +++ src/libcamera/bayer_format.cpp | 31 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 723382d4168d..217da54e90a2 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 { @@ -43,6 +45,7 @@ public: { } + unsigned int toMbusCode() const; static const BayerFormat &fromMbusCode(unsigned int mbusCode); bool isValid() const { return bitDepth != 0; } @@ -50,6 +53,7 @@ public: V4L2PixelFormat toV4L2PixelFormat() const; static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); + PixelFormat toPixelFormat() const; BayerFormat transform(Transform t) const; Order order; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 11355f144f66..c138e7a09597 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -169,6 +169,24 @@ const std::unordered_map mbusCodeToBayer{ * \param[in] p The type of packing applied to the pixel values */ +/** + * \brief Retrieve the media bus code associated with a BayerFormat + * + * The media bus code numeric identifiers are defined by the V4L2 specification. + */ +unsigned int BayerFormat::toMbusCode() const +{ + const auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(), + [this](const auto &p) { + return p.second == *this; + }); + + if (it == mbusCodeToBayer.end()) + return it->first; + + return 0; +} + /** * \brief Retrieve the BayerFormat associated with a media bus code * \param[in] mbusCode The media bus code to convert into a BayerFormat @@ -269,6 +287,19 @@ 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 = bayerToV4l2.find(*this); + if (it != bayerToV4l2.end()) + return PixelFormat(it->second); + + return PixelFormat(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply