Show a patch.

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

{
    "id": 2245,
    "url": "https://patchwork.libcamera.org/api/patches/2245/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2245/",
    "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": "<20191027234312.35284-8-jacopo@jmondi.org>",
    "date": "2019-10-27T23:43:09",
    "name": "[libcamera-devel,07/10] libcamera: v4l2_videodevice: Add PixelFormat conversion",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1450441e87502c3e0bed7de445da38a64cc09a41",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2245/mbox/",
    "series": [
        {
            "id": 559,
            "url": "https://patchwork.libcamera.org/api/series/559/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=559",
            "date": "2019-10-27T23:43:02",
            "name": "libcamera: Use DRM_FORMAT_* fourcc codes",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/559/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2245/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2245/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B6FFD61517\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Oct 2019 00:41:28 +0100 (CET)",
            "from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 6B07920003;\n\tSun, 27 Oct 2019 23:41:28 +0000 (UTC)"
        ],
        "X-Originating-IP": "93.2.121.143",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 28 Oct 2019 00:43:09 +0100",
        "Message-Id": "<20191027234312.35284-8-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.23.0",
        "In-Reply-To": "<20191027234312.35284-1-jacopo@jmondi.org>",
        "References": "<20191027234312.35284-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 07/10] libcamera: v4l2_videodevice: Add\n\tPixelFormat conversion",
        "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": "Sun, 27 Oct 2019 23:41:29 -0000"
    },
    "content": "Add support for the newly introduced PixelFormat type in the\nV4L2VideoDevice class by providing helper operations to translate\na PixelFormat to the corresponding V4L2-defined fourcc code and vice\nversa.\n\nMore work is needed to properly suppor the V4L2 multi-planar (*M)\nformats.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_videodevice.h |   5 +\n src/libcamera/v4l2_videodevice.cpp       | 141 +++++++++++++++++++++++\n 2 files changed, 146 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex 4b8cf9394eb9..fdf11b3a6ec9 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -13,6 +13,7 @@\n #include <linux/videodev2.h>\n \n #include <libcamera/geometry.h>\n+#include <libcamera/pixelformats.h>\n #include <libcamera/signal.h>\n \n #include \"formats.h\"\n@@ -155,6 +156,10 @@ public:\n \tstatic V4L2VideoDevice *fromEntityName(const MediaDevice *media,\n \t\t\t\t\t       const std::string &entity);\n \n+\tstatic PixelFormat toPixelFormat(uint32_t v4l2Fourcc);\n+\tuint32_t toV4L2Fourcc(PixelFormat pixelFormat);\n+\tstatic uint32_t toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar);\n+\n protected:\n \tstd::string logPrefix() const;\n \ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 208ab54199b1..89370698bcf1 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -17,6 +17,8 @@\n #include <unistd.h>\n #include <vector>\n \n+#include <linux/drm_fourcc.h>\n+\n #include <libcamera/buffer.h>\n #include <libcamera/event_notifier.h>\n \n@@ -1234,6 +1236,145 @@ V4L2VideoDevice *V4L2VideoDevice::fromEntityName(const MediaDevice *media,\n \treturn new V4L2VideoDevice(mediaEntity);\n }\n \n+/**\n+ * \\brief Convert a \\a v4l2Fourcc code to its corresponding PixelFormat\n+ * \\param[in] v4l2Fourcc A V4L2_PIX_FORMAT_* pixel code\n+ * \\return The PixelFormat corresponding to \\a v4l2Fourcc\n+ */\n+PixelFormat V4L2VideoDevice::toPixelFormat(uint32_t v4l2Fourcc)\n+{\n+\tswitch (v4l2Fourcc) {\n+\t/* RGB formats. */\n+\tcase V4L2_PIX_FMT_RGB24:\n+\t\treturn DRM_FORMAT_BGR888;\n+\tcase V4L2_PIX_FMT_BGR24:\n+\t\treturn DRM_FORMAT_RGB888;\n+\tcase V4L2_PIX_FMT_ARGB32:\n+\t\treturn DRM_FORMAT_BGRA8888;\n+\n+\t/* YUV packed formats. */\n+\tcase V4L2_PIX_FMT_YUYV:\n+\t\treturn DRM_FORMAT_YUYV;\n+\tcase V4L2_PIX_FMT_YVYU:\n+\t\treturn DRM_FORMAT_YVYU;\n+\tcase V4L2_PIX_FMT_UYVY:\n+\t\treturn DRM_FORMAT_UYVY;\n+\tcase V4L2_PIX_FMT_VYUY:\n+\t\treturn DRM_FORMAT_VYUY;\n+\n+\t/* YUY planar formats. */\n+\tcase V4L2_PIX_FMT_NV16:\n+\tcase V4L2_PIX_FMT_NV16M:\n+\t\treturn DRM_FORMAT_NV16;\n+\tcase V4L2_PIX_FMT_NV61:\n+\tcase V4L2_PIX_FMT_NV61M:\n+\t\treturn DRM_FORMAT_NV61;\n+\tcase V4L2_PIX_FMT_NV12:\n+\tcase V4L2_PIX_FMT_NV12M:\n+\t\treturn DRM_FORMAT_NV12;\n+\tcase V4L2_PIX_FMT_NV21:\n+\tcase V4L2_PIX_FMT_NV21M:\n+\t\treturn DRM_FORMAT_NV21;\n+\n+\t/* Compressed formats. */\n+\tcase V4L2_PIX_FMT_MJPEG:\n+\t\treturn DRM_FORMAT_MJPEG;\n+\n+\t/* V4L2 formats not yet supported by DRM. */\n+\tcase V4L2_PIX_FMT_GREY:\n+\tdefault:\n+\t\t/*\n+\t\t * \\todo We can't use LOG() in a static method of a Loggable\n+\t\t * class. Until we fix the logger, work around it.\n+\t\t */\n+\t\tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(),\n+\t\t\t\tLogError).stream()\n+\t\t\t<< \"Unsupported V4L2 pixel format \"\n+\t\t\t<< utils::hex(v4l2Fourcc);\n+\t\treturn 0;\n+\t}\n+}\n+\n+/**\n+ * \\brief Convert \\a PixelFormat to its corresponding V4L2 fourcc code\n+ * \\param[in] pixelFormat The PixelFormat to convert\n+ *\n+ * For multiplanar formats, the V4L2 format variant (contiguous or\n+ * non-contiguous planes) is selected automatically based on the capabilities\n+ * of the video device. If the video device supports the V4L2 multiplanar API,\n+ * non-contiguous formats are preferred.\n+ *\n+ * \\return The V4L2_PIX_FMT_* pixel format code corresponding to \\a pixelFormat\n+ */\n+uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat)\n+{\n+\treturn V4L2VideoDevice::toV4L2Fourcc(pixelFormat, caps_.isMultiplanar());\n+}\n+\n+/**\n+ * \\brief Convert \\a pixelFormat to its corresponding V4L2 fourcc code\n+ * \\param[in] pixelFormat The PixelFormat to convert\n+ * \\param[in] multiplanar V4L2 Multiplanar API support flag\n+ *\n+ * Multiple V4L2 formats may exist for one PixelFormat when the format uses\n+ * multiple planes, as V4L2 defines separate 4CCs for contiguous and separate\n+ * planes formats. Set the \\a multiplanar parameter to false to select a format\n+ * with contiguous planes, or to true to select a format with non-contiguous\n+ * planes.\n+ *\n+ * \\return The V4L2_PIX_FMT_* pixel format code corresponding to \\a pixelFormat\n+ */\n+uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar)\n+{\n+\tswitch (pixelFormat) {\n+\t/* RGB formats. */\n+\tcase DRM_FORMAT_BGR888:\n+\t\treturn V4L2_PIX_FMT_RGB24;\n+\tcase DRM_FORMAT_RGB888:\n+\t\treturn V4L2_PIX_FMT_BGR24;\n+\tcase DRM_FORMAT_BGRA8888:\n+\t\treturn V4L2_PIX_FMT_ARGB32;\n+\n+\t/* YUV packed formats. */\n+\tcase DRM_FORMAT_YUYV:\n+\t\treturn V4L2_PIX_FMT_YUYV;\n+\tcase DRM_FORMAT_YVYU:\n+\t\treturn V4L2_PIX_FMT_YVYU;\n+\tcase DRM_FORMAT_UYVY:\n+\t\treturn V4L2_PIX_FMT_UYVY;\n+\tcase DRM_FORMAT_VYUY:\n+\t\treturn 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 V4L2_PIX_FMT_NV16;\n+\tcase DRM_FORMAT_NV61:\n+\t\treturn V4L2_PIX_FMT_NV61;\n+\tcase DRM_FORMAT_NV12:\n+\t\treturn V4L2_PIX_FMT_NV12;\n+\tcase DRM_FORMAT_NV21:\n+\t\treturn V4L2_PIX_FMT_NV21;\n+\n+\t/* Compressed formats. */\n+\tcase DRM_FORMAT_MJPEG:\n+\t\treturn V4L2_PIX_FMT_MJPEG;\n+\t}\n+\n+\t/*\n+\t * \\todo We can't use LOG() in a static method of a Loggable\n+\t * class. Until we fix the logger, work around it.\n+\t */\n+\tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(), LogError).stream()\n+\t\t<< \"Unsupported V4L2 pixel format \"\n+\t\t<< utils::hex(pixelFormat);\n+\treturn 0;\n+}\n+\n /**\n  * \\class V4L2M2MDevice\n  * \\brief Memory-to-Memory video device\n",
    "prefixes": [
        "libcamera-devel",
        "07/10"
    ]
}