Show a patch.

GET /api/patches/10795/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 10795,
    "url": "https://patchwork.libcamera.org/api/patches/10795/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10795/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20201231155336.7058-2-sebastian.fricke.linux@gmail.com>",
    "date": "2020-12-31T15:53:33",
    "name": "[libcamera-devel,v2,1/4] libcamera: Add the fromV4L2PixelFormat function",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "17d28f1f06024a818624b821960f7b7998017b82",
    "submitter": {
        "id": 73,
        "url": "https://patchwork.libcamera.org/api/people/73/?format=api",
        "name": "Sebastian Fricke",
        "email": "sebastian.fricke.linux@gmail.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/10795/mbox/",
    "series": [
        {
            "id": 1564,
            "url": "https://patchwork.libcamera.org/api/series/1564/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1564",
            "date": "2020-12-31T15:53:32",
            "name": "Improve BayerFormat class",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/1564/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10795/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10795/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 D10FDC0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Dec 2020 15:54:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9C4A0615D5;\n\tThu, 31 Dec 2020 16:54:29 +0100 (CET)",
            "from mail-wm1-x333.google.com (mail-wm1-x333.google.com\n\t[IPv6:2a00:1450:4864:20::333])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 06D196031D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Dec 2020 16:54:29 +0100 (CET)",
            "by mail-wm1-x333.google.com with SMTP id 3so7518707wmg.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Dec 2020 07:54:29 -0800 (PST)",
            "from basti-TUXEDO-Book-XA1510.fritz.box\n\t(p200300d1ff267500b10aabf0e84cdf75.dip0.t-ipconnect.de.\n\t[2003:d1:ff26:7500:b10a:abf0:e84c:df75])\n\tby smtp.gmail.com with ESMTPSA id\n\ts63sm14595787wms.18.2020.12.31.07.54.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 31 Dec 2020 07:54:28 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"VTNpciI4\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=ehcOEaT5C+NVaJy0ibg5WmtOCyPhCQXd82wsNhVrHRg=;\n\tb=VTNpciI4p/GwJHjGK1Xo3c+ba3lsTIx+uR7ZocLmKfC5TG6H9gjxTaRyXRii1SrX7Z\n\th80BIV/YoCxFc6hBY4qa8SY831fgwiWW0zYAMg4Dah8pgCgLxvA/aAE4TMMum1orNwo7\n\tFgfoG9RhYMshkVuMsY+m+iBO/s2VotBG01VMCgnWTN4QOjZJI2IRerZJ5CrDeVjjBk1l\n\t/Pa04v7Xx9+w9HMp5ccyk9RcUc96EDi92WpzHmpTS+Kqa5Ep8GyGEYr4pRw1IuM4fe4d\n\t2yYlljdaDEyOGddZBrchKdmWai0j1X541FfzJqTlVknOvXCjTg8C9lyb/pINvi//XMvs\n\tMeZQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\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=ehcOEaT5C+NVaJy0ibg5WmtOCyPhCQXd82wsNhVrHRg=;\n\tb=gcXKIYmYDk3h2QZ7QSmA9oO+BcmibLtItSi7AB+19PDKH5V3O5LsnXLUsipDQz4mKR\n\tbq8EhiAhLbJ8myNS1U9Cw/A+nEw4seLLHljHdOctu1lyCphiiwGRtlZ/i6ef64I43xaw\n\tRe4lkwo6r0h5rcogtglZXp21kziLibl63KIaBvu4yg/niVluhJHmpomi1igsJnp60wXS\n\tBO8iESjPJDIHpfNWMY+sSfrJWSN+/Zr5qfL3lHJ5fIS8IhcVDtg+8ypMtfDfCvWCethX\n\t2TnHCHsrL3pniHxB3vqErTV9rp3Y+mrg+Jx+rstCY8qowaZIkZk5bckGo/tbA29C9lOW\n\te/SA==",
        "X-Gm-Message-State": "AOAM533m31JBhOeRdqdK5wkhrQ8E6bxnG6bIVTk51shq7uCctpIxq4ZH\n\tGdl+UL5PSDoDY/y+cNsyeqcWJRqzcB4=",
        "X-Google-Smtp-Source": "ABdhPJxMJAtnpEjryR6PB62QBMPnPRCeUNjyOV6CDbLvJtyTRfE6+9K+V2CZxliPnsp/VWhF3T2s+Q==",
        "X-Received": "by 2002:a05:600c:410d:: with SMTP id\n\tj13mr12390690wmi.95.1609430068758; \n\tThu, 31 Dec 2020 07:54:28 -0800 (PST)",
        "From": "Sebastian Fricke <sebastian.fricke.linux@gmail.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 31 Dec 2020 16:53:33 +0100",
        "Message-Id": "<20201231155336.7058-2-sebastian.fricke.linux@gmail.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20201231155336.7058-1-sebastian.fricke.linux@gmail.com>",
        "References": "<20201231155336.7058-1-sebastian.fricke.linux@gmail.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2 1/4] libcamera: Add the\n\tfromV4L2PixelFormat function",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add a static member function to get the corresponding Bayer-format\nfrom a given V4L2PixelFormat.\nReplace an existing method to instantiate an object from a matching\nV4l2PixelFormat, to not duplicate the code.\nThe motivation behind this patch is to align the overall structure\nof the BayerFormat class with other parts of the code base, such as\nthe V4L2PixelFormat class.\n\nRemove the v4l2ToBayer mapping table and use the bayerToV4l2 mapping\ntable by searching for a mapped element to get the corresponding key.\nThe downside of this approach is a slightly worse time complexity, but\nthe upside is a smaller codebase and lower memory consumption. As the\nfunction is probably not used very frequently, I tend to favor the\nmentioned upsides.\n\nSigned-off-by: Sebastian Fricke <sebastian.fricke.linux@gmail.com>\n---\n include/libcamera/internal/bayer_format.h |  1 +\n src/libcamera/bayer_format.cpp            | 63 +++++++----------------\n 2 files changed, 19 insertions(+), 45 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h\nindex 4280b76b..8efe1382 100644\n--- a/include/libcamera/internal/bayer_format.h\n+++ b/include/libcamera/internal/bayer_format.h\n@@ -48,6 +48,7 @@ public:\n \tstd::string toString() const;\n \n \tV4L2PixelFormat toV4L2PixelFormat() const;\n+\tstatic BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format);\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 c42792ff..26065b66 100644\n--- a/src/libcamera/bayer_format.cpp\n+++ b/src/libcamera/bayer_format.cpp\n@@ -7,6 +7,7 @@\n \n #include \"libcamera/internal/bayer_format.h\"\n \n+#include <algorithm>\n #include <map>\n \n #include <libcamera/transform.h>\n@@ -57,37 +58,6 @@ namespace libcamera {\n \n namespace {\n \n-const std::map<V4L2PixelFormat, BayerFormat> v4l2ToBayer{\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8), { BayerFormat::BGGR, 8, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8), { BayerFormat::GBRG, 8, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8), { BayerFormat::GRBG, 8, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8), { BayerFormat::RGGB, 8, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10), { BayerFormat::BGGR, 10, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10), { BayerFormat::GBRG, 10, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10), { BayerFormat::GRBG, 10, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10), { BayerFormat::RGGB, 10, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P), { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P), { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P), { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P), { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10), { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10), { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10), { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10), { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12), { BayerFormat::BGGR, 12, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12), { BayerFormat::GBRG, 12, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12), { BayerFormat::GRBG, 12, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12), { BayerFormat::RGGB, 12, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P), { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P), { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P), { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P), { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16), { BayerFormat::BGGR, 16, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16), { BayerFormat::GBRG, 16, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16), { BayerFormat::GRBG, 16, BayerFormat::None } },\n-\t{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16), { BayerFormat::RGGB, 16, BayerFormat::None } },\n-};\n-\n /* Define a slightly arbitrary ordering so that we can use a std::map. */\n struct BayerFormatComparator {\n \tconstexpr bool operator()(const BayerFormat &lhs, const BayerFormat &rhs) const\n@@ -155,20 +125,6 @@ const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator> bayerToV4l2{\n  * \\param[in] p The type of packing applied to the pixel values\n  */\n \n-/**\n- * \\brief Construct a BayerFormat from a V4L2PixelFormat\n- * \\param[in] v4l2Format The raw format to convert into a BayerFormat\n- */\n-BayerFormat::BayerFormat(V4L2PixelFormat v4l2Format)\n-\t: order(BGGR), packing(None)\n-{\n-\tconst auto it = v4l2ToBayer.find(v4l2Format);\n-\tif (it == v4l2ToBayer.end())\n-\t\tbitDepth = 0;\n-\telse\n-\t\t*this = it->second;\n-}\n-\n /**\n  * \\fn BayerFormat::isValid()\n  * \\brief Return whether a BayerFormat is valid\n@@ -217,6 +173,23 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const\n \treturn V4L2PixelFormat();\n }\n \n+/**\n+ * \\brief Convert \\a v4l2Format into the corresponding BayerFormat\n+ * \\param[in] v4l2Format The raw format to convert into a BayerFormat\n+ * \\return The BayerFormat corresponding to \\a v4l2Format\n+ */\n+BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format)\n+{\n+\tauto it = std::find_if(\n+\t\tbayerToV4l2.begin(),\n+\t\tbayerToV4l2.end(),\n+\t\t[v4l2Format](const auto &i) { return i.second == v4l2Format; });\n+\tif (it != bayerToV4l2.end())\n+\t\treturn it->first;\n+\n+\treturn BayerFormat();\n+}\n+\n /**\n  * \\brief Apply a transform to this BayerFormat\n  * \\param[in] t The transform to apply\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "1/4"
    ]
}