{"id":14253,"url":"https://patchwork.libcamera.org/api/patches/14253/?format=json","web_url":"https://patchwork.libcamera.org/patch/14253/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211022115537.2964533-2-naush@raspberrypi.com>","date":"2021-10-22T11:55:32","name":"[libcamera-devel,1/6] libcamera: bayer_format: Add conversion helpers to the BayerFormat class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f267574f3af0d6d332911b0939a7b25bcfd5907a","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14253/mbox/","series":[{"id":2649,"url":"https://patchwork.libcamera.org/api/series/2649/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2649","date":"2021-10-22T11:55:31","name":"Raspberry Pi: Conversion to media controller","version":1,"mbox":"https://patchwork.libcamera.org/series/2649/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14253/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14253/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0685DBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Oct 2021 11:55:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7836668F59;\n\tFri, 22 Oct 2021 13:55:44 +0200 (CEST)","from mail-wr1-x434.google.com (mail-wr1-x434.google.com\n\t[IPv6:2a00:1450:4864:20::434])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C4746012A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 13:55:42 +0200 (CEST)","by mail-wr1-x434.google.com with SMTP id i12so1875964wrb.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 04:55:42 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:f00d:ddf0:61b0:a4cd])\n\tby smtp.gmail.com with ESMTPSA id\n\tl5sm7853364wru.24.2021.10.22.04.55.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 22 Oct 2021 04:55:41 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"dddLCyk8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=1+yQGT8m0ouNkcWR6TMH7jsBxo1G5lAbrwkO3omOMbI=;\n\tb=dddLCyk8xzdbd3MIStqiyTHKBC29VqqPKykYVPK9Vg/sM2T7/pa0kUVC8B32JrbiHC\n\tG2vUguzbo8vmjNQHAnfqx42H7tIABzxAS7L7Rj4vx4Pb7WSYgkIj/HrbewYwZ13eTnLk\n\tbLRAxwdWBirxUJcE/6Ch6/PnQE6U5tZvM7y1o2baAHYymiiDEbZzceXk900qxxRsJ+S9\n\tG1+M/7uUoIvPyRtfb8sqwy8cbcf1Me7/4KMatvmvfkyIzfqeCdkCZmHFDHD0wKTMfUNg\n\t4lLkjBCj1MDts45oG3HFRsSV5ewibM63ZWbzhi/z4XMV9wZDWfzo8Q/krQ3nIPT+9BCz\n\trCZg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=1+yQGT8m0ouNkcWR6TMH7jsBxo1G5lAbrwkO3omOMbI=;\n\tb=wDGyvX+07LQ+wzbqDen0aQM9ITt4tUv2V15J+hSAlLeXCGmHphmHEnhYwYtPqdYx6m\n\tO8HBI/ZIJwG1yBc21E4gPZzzX+CY1asjwgWEvp0kC6hoiDkEPxjiTNN3XEYK0V7at6n2\n\tTpmlSOFCmT64oQO14c8edsBqt7dA8SCDXC/+eiaZITgbFlA5+qoNQOREKZZx1NyJ7rw+\n\tiEcCHPXHkPjRBJSpy+T7mgLIA7/XGAPUjIRBFFRtc1bhARohnAmhCwhjnJ3dHlzpv1tP\n\tM9zH3Ts4YxSj6bOFH37hxc5BVSUGgrbONxK/zcSEiJz85uAu1czw/AXYQ7s2xrf4pcIV\n\tHFPQ==","X-Gm-Message-State":"AOAM532/BdWlx8WsidHQJlUsOINRbgobua3CgESvFsC9fZxIQLVjV5D3\n\t6l0juxyWgkIKvA4MMnhr5h1wHn3zwxp7zA==","X-Google-Smtp-Source":"ABdhPJyTdNFsNsJdJ9U84JtNBld5TMfhAHuyi+RQOYU9nXC6gw4AX2iP0tX0OC4s/QmVGZ0hsjZlyw==","X-Received":"by 2002:adf:fe45:: with SMTP id\n\tm5mr15114630wrs.197.1634903741586; \n\tFri, 22 Oct 2021 04:55:41 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/6] libcamera: bayer_format: Add\n\tconversion helpers to the BayerFormat class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a BayerFormat::toMbusCode() member function to convert a BayerFormat to an\nmbus code defined by the V4L2 specification.\n\nAdd a BayerFormat::toPixelFormat() member function to convert a BayerFormat to a\nPixelFormat type. This conversion uses the existing bayerToV4l2 conversion\ntable.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n include/libcamera/internal/bayer_format.h |  4 +++\n src/libcamera/bayer_format.cpp            | 31 +++++++++++++++++++++++\n 2 files changed, 35 insertions(+)","diff":"diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h\nindex 723382d4168d..217da54e90a2 100644\n--- a/include/libcamera/internal/bayer_format.h\n+++ b/include/libcamera/internal/bayer_format.h\n@@ -10,6 +10,8 @@\n #include <stdint.h>\n #include <string>\n \n+#include <libcamera/pixel_format.h>\n+\n #include \"libcamera/internal/v4l2_pixelformat.h\"\n \n namespace libcamera {\n@@ -43,6 +45,7 @@ public:\n \t{\n \t}\n \n+\tunsigned int toMbusCode() const;\n \tstatic const BayerFormat &fromMbusCode(unsigned int mbusCode);\n \tbool isValid() const { return bitDepth != 0; }\n \n@@ -50,6 +53,7 @@ public:\n \n \tV4L2PixelFormat toV4L2PixelFormat() const;\n \tstatic BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format);\n+\tPixelFormat toPixelFormat() const;\n \tBayerFormat transform(Transform t) const;\n \n \tOrder order;\ndiff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp\nindex 11355f144f66..c138e7a09597 100644\n--- a/src/libcamera/bayer_format.cpp\n+++ b/src/libcamera/bayer_format.cpp\n@@ -169,6 +169,24 @@ const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{\n  * \\param[in] p The type of packing applied to the pixel values\n  */\n \n+/**\n+ * \\brief Retrieve the media bus code associated with a BayerFormat\n+ *\n+ * The media bus code numeric identifiers are defined by the V4L2 specification.\n+ */\n+unsigned int BayerFormat::toMbusCode() const\n+{\n+\tconst auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(),\n+\t\t\t\t     [this](const auto &p) {\n+\t\t\t\t\t     return p.second == *this;\n+\t\t\t\t     });\n+\n+\tif (it == mbusCodeToBayer.end())\n+\t\treturn it->first;\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Retrieve the BayerFormat associated with a media bus code\n  * \\param[in] mbusCode The media bus code to convert into a BayerFormat\n@@ -269,6 +287,19 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format)\n \treturn BayerFormat();\n }\n \n+/**\n+ * \\brief Convert a BayerFormat into the corresponding PixelFormat\n+ * \\return The PixelFormat corresponding to this BayerFormat\n+ */\n+PixelFormat BayerFormat::toPixelFormat() const\n+{\n+\tconst auto it = bayerToV4l2.find(*this);\n+\tif (it != bayerToV4l2.end())\n+\t\treturn PixelFormat(it->second);\n+\n+\treturn PixelFormat();\n+}\n+\n /**\n  * \\brief Apply a transform to this BayerFormat\n  * \\param[in] t The transform to apply\n","prefixes":["libcamera-devel","1/6"]}