Show a patch.

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

{
    "id": 3623,
    "url": "https://patchwork.libcamera.org/api/patches/3623/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3623/",
    "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": "<20200430005226.18162-4-laurent.pinchart@ideasonboard.com>",
    "date": "2020-04-30T00:52:25",
    "name": "[libcamera-devel,3/4] libcamera: v4l2_pixelformat: Use maps to convert between DRM and V4L2",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "eacf77ca45f1cba58f1aa574a15173e58d7bd9d4",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/3623/mbox/",
    "series": [
        {
            "id": 856,
            "url": "https://patchwork.libcamera.org/api/series/856/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=856",
            "date": "2020-04-30T00:52:22",
            "name": "libcamera: Improve conversion between DRM and V4L2 formats",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/856/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3623/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3623/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DB6B7613B0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 02:52:31 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7CB00521\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 02:52:31 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"DgliySVE\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588207951;\n\tbh=lEgrlfuG0LzK4oz0NCVGwTHlz7lSF0qTsEd7URnmYmI=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DgliySVEY8BD7cKi8WBE/8Dcd5hIg6fOOMqhuDMSTPi/8npnehRxGopvbJ+3ZBt+z\n\tG2mVETL9rJBhyoq2xvlvEaieLSCWNditlosUbli7Sww4WiSjnRE5TOVtIecDQ/h5Ml\n\taBpTHDMmKEF3Y4SFuw2szsBaTu2UwDyUZQrw0yNM=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 30 Apr 2020 03:52:25 +0300",
        "Message-Id": "<20200430005226.18162-4-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.25.3",
        "In-Reply-To": "<20200430005226.18162-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20200430005226.18162-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/4] libcamera: v4l2_pixelformat: Use maps\n\tto convert between DRM and V4L2",
        "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>",
        "X-List-Received-Date": "Thu, 30 Apr 2020 00:52:32 -0000"
    },
    "content": "Replace the two big manual switch...case with maps. This should not just\nimprove efficiency when we will have a larger number of formats, but\nalso paves the way to storing more format information to create\nadditional helpers.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/v4l2_pixelformat.cpp | 204 +++++++++++++++--------------\n 1 file changed, 106 insertions(+), 98 deletions(-)",
    "diff": "diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\nindex 876f5de321f6..e1c96b9862c3 100644\n--- a/src/libcamera/v4l2_pixelformat.cpp\n+++ b/src/libcamera/v4l2_pixelformat.cpp\n@@ -41,6 +41,103 @@ LOG_DECLARE_CATEGORY(V4L2)\n  * explicit value() and implicit uint32_t conversion operators may be used.\n  */\n \n+namespace {\n+\n+struct PixelFormatInfo {\n+\t/* \\todo Add support for non-contiguous memory planes */\n+\tV4L2PixelFormat v4l2Format;\n+};\n+\n+const std::map<PixelFormat, PixelFormatInfo> pf2vpf{\n+\t/* RGB formats. */\n+\t{ PixelFormat(DRM_FORMAT_BGR888), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_RGB888), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_ABGR8888), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_ARGB8888), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_BGRA8888), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_RGBA8888), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),\n+\t} },\n+\n+\t/* YUV packed formats. */\n+\t{ PixelFormat(DRM_FORMAT_YUYV), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_YVYU), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_UYVY), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_VYUY), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),\n+\t} },\n+\n+\t/* YUV planar formats. */\n+\t{ PixelFormat(DRM_FORMAT_NV16), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_NV61), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_NV12), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_NV21), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),\n+\t} },\n+\n+\t/* Greyscale formats. */\n+\t{ PixelFormat(DRM_FORMAT_R8), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),\n+\t} },\n+\n+\t/* Compressed formats. */\n+\t{ PixelFormat(DRM_FORMAT_MJPEG), {\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),\n+\t} },\n+};\n+\n+const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{\n+\t/* RGB formats. */\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), PixelFormat(DRM_FORMAT_BGR888) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_BGR24), PixelFormat(DRM_FORMAT_RGB888) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), PixelFormat(DRM_FORMAT_ABGR8888) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_ABGR32), PixelFormat(DRM_FORMAT_ARGB8888) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_ARGB32), PixelFormat(DRM_FORMAT_BGRA8888) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_BGRA32), PixelFormat(DRM_FORMAT_RGBA8888) },\n+\n+\t/* YUV packed formats. */\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_YUYV), PixelFormat(DRM_FORMAT_YUYV) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_YVYU), PixelFormat(DRM_FORMAT_YVYU) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_UYVY), PixelFormat(DRM_FORMAT_UYVY) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_VYUY), PixelFormat(DRM_FORMAT_VYUY) },\n+\n+\t/* YUV planar formats. */\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_NV16), PixelFormat(DRM_FORMAT_NV16) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_NV61), PixelFormat(DRM_FORMAT_NV61) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_NV12), PixelFormat(DRM_FORMAT_NV12) },\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_NV21), PixelFormat(DRM_FORMAT_NV21) },\n+\n+\t/* Greyscale formats. */\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_GREY), PixelFormat(DRM_FORMAT_R8) },\n+\n+\t/* Compressed formats. */\n+\t{ V4L2PixelFormat(V4L2_PIX_FMT_MJPEG), PixelFormat(DRM_FORMAT_MJPEG) },\n+};\n+\n+} /* namespace */\n+\n /**\n  * \\fn V4L2PixelFormat::V4L2PixelFormat()\n  * \\brief Construct a V4L2PixelFormat with an invalid format\n@@ -109,60 +206,15 @@ std::string V4L2PixelFormat::toString() const\n  */\n PixelFormat V4L2PixelFormat::toPixelFormat() const\n {\n-\tswitch (fourcc_) {\n-\t/* RGB formats. */\n-\tcase V4L2_PIX_FMT_RGB24:\n-\t\treturn PixelFormat(DRM_FORMAT_BGR888);\n-\tcase V4L2_PIX_FMT_BGR24:\n-\t\treturn PixelFormat(DRM_FORMAT_RGB888);\n-\tcase V4L2_PIX_FMT_RGBA32:\n-\t\treturn PixelFormat(DRM_FORMAT_ABGR8888);\n-\tcase V4L2_PIX_FMT_ABGR32:\n-\t\treturn PixelFormat(DRM_FORMAT_ARGB8888);\n-\tcase V4L2_PIX_FMT_ARGB32:\n-\t\treturn PixelFormat(DRM_FORMAT_BGRA8888);\n-\tcase V4L2_PIX_FMT_BGRA32:\n-\t\treturn PixelFormat(DRM_FORMAT_RGBA8888);\n-\n-\t/* YUV packed formats. */\n-\tcase V4L2_PIX_FMT_YUYV:\n-\t\treturn PixelFormat(DRM_FORMAT_YUYV);\n-\tcase V4L2_PIX_FMT_YVYU:\n-\t\treturn PixelFormat(DRM_FORMAT_YVYU);\n-\tcase V4L2_PIX_FMT_UYVY:\n-\t\treturn PixelFormat(DRM_FORMAT_UYVY);\n-\tcase V4L2_PIX_FMT_VYUY:\n-\t\treturn PixelFormat(DRM_FORMAT_VYUY);\n-\n-\t/* YUY planar formats. */\n-\tcase V4L2_PIX_FMT_NV16:\n-\tcase V4L2_PIX_FMT_NV16M:\n-\t\treturn PixelFormat(DRM_FORMAT_NV16);\n-\tcase V4L2_PIX_FMT_NV61:\n-\tcase V4L2_PIX_FMT_NV61M:\n-\t\treturn PixelFormat(DRM_FORMAT_NV61);\n-\tcase V4L2_PIX_FMT_NV12:\n-\tcase V4L2_PIX_FMT_NV12M:\n-\t\treturn PixelFormat(DRM_FORMAT_NV12);\n-\tcase V4L2_PIX_FMT_NV21:\n-\tcase V4L2_PIX_FMT_NV21M:\n-\t\treturn PixelFormat(DRM_FORMAT_NV21);\n-\n-\t/* Greyscale formats. */\n-\tcase V4L2_PIX_FMT_GREY:\n-\t\treturn PixelFormat(DRM_FORMAT_R8);\n-\n-\t/* Compressed formats. */\n-\tcase V4L2_PIX_FMT_MJPEG:\n-\t\treturn PixelFormat(DRM_FORMAT_MJPEG);\n-\n-\t/* V4L2 formats not yet supported by DRM. */\n-\tdefault:\n+\tconst auto iter = vpf2pf.find(*this);\n+\tif (iter == vpf2pf.end()) {\n \t\tLOG(V4L2, Warning)\n \t\t\t<< \"Unsupported V4L2 pixel format \"\n \t\t\t<< toString();\n \t\treturn PixelFormat();\n \t}\n+\n+\treturn iter->second;\n }\n \n /**\n@@ -181,60 +233,16 @@ PixelFormat V4L2PixelFormat::toPixelFormat() const\n V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat,\n \t\t\t\t\t\t bool multiplanar)\n {\n-\tswitch (pixelFormat) {\n-\t/* RGB formats. */\n-\tcase DRM_FORMAT_BGR888:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_RGB24);\n-\tcase DRM_FORMAT_RGB888:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_BGR24);\n-\tcase DRM_FORMAT_ABGR8888:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_RGBA32);\n-\tcase DRM_FORMAT_ARGB8888:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_ABGR32);\n-\tcase DRM_FORMAT_BGRA8888:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_ARGB32);\n-\tcase DRM_FORMAT_RGBA8888:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_BGRA32);\n-\n-\t/* YUV packed formats. */\n-\tcase DRM_FORMAT_YUYV:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_YUYV);\n-\tcase DRM_FORMAT_YVYU:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_YVYU);\n-\tcase DRM_FORMAT_UYVY:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_UYVY);\n-\tcase DRM_FORMAT_VYUY:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_VYUY);\n-\n-\t/*\n-\t * YUY planar formats.\n-\t * \\todo Add support for non-contiguous memory planes\n-\t * \\todo Select the format variant not only based on \\a multiplanar but\n-\t * also take into account the formats supported by the device.\n-\t */\n-\tcase DRM_FORMAT_NV16:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV16);\n-\tcase DRM_FORMAT_NV61:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV61);\n-\tcase DRM_FORMAT_NV12:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV12);\n-\tcase DRM_FORMAT_NV21:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV21);\n-\n-\t/* Greyscale formats. */\n-\tcase DRM_FORMAT_R8:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_GREY);\n-\n-\t/* Compressed formats. */\n-\tcase DRM_FORMAT_MJPEG:\n-\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_MJPEG);\n-\n-\tdefault:\n+\tconst auto iter = pf2vpf.find(pixelFormat);\n+\tif (iter == pf2vpf.end()) {\n \t\tLOG(V4L2, Warning)\n \t\t\t<< \"Unsupported pixel format \"\n \t\t\t<< pixelFormat.toString();\n \t\treturn V4L2PixelFormat();\n \t}\n+\n+\tconst PixelFormatInfo &info = iter->second;\n+\treturn info.v4l2Format;\n }\n \n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "3/4"
    ]
}