Show a patch.

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

{
    "id": 17251,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17251/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17251/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20220830074725.1059643-3-umang.jain@ideasonboard.com>",
    "date": "2022-08-30T07:47:20",
    "name": "[libcamera-devel,v4,2/7] libcamera: v4l2_device: Adjust colorspace based on pixel format",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "2f55f6be8c2045bf83754a42f7a4bf9101670602",
    "submitter": {
        "id": 86,
        "url": "https://patchwork.libcamera.org/api/1.1/people/86/?format=api",
        "name": "Umang Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "delegate": {
        "id": 12,
        "url": "https://patchwork.libcamera.org/api/1.1/users/12/?format=api",
        "username": "uajain",
        "first_name": "Umang",
        "last_name": "Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/17251/mbox/",
    "series": [
        {
            "id": 3452,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3452/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3452",
            "date": "2022-08-30T07:47:18",
            "name": "Colospace adjustment and gstreamer mapping",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3452/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17251/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17251/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 0EE7FC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Aug 2022 07:47:42 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CAD1B61FC7;\n\tTue, 30 Aug 2022 09:47:41 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 43B5561FB9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Aug 2022 09:47:41 +0200 (CEST)",
            "from umang.jainideasonboard.com (unknown\n\t[IPv6:2401:4900:1f3f:1548:78ac:4a3:edc3:c28a])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 66C41481;\n\tTue, 30 Aug 2022 09:47:39 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661845661;\n\tbh=YqjMQP/yqXTzS70rx2uwu27GT7lMJ5U35FUq+fek4Gc=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=G8lyKVgVXHbvoCFOS1MRYFIZLkbYMCDdJsvSrS//QsTdbkFrPA7RehDvN3fiFKjUq\n\tpaVnSjd77RKzTJ7XoMtZJA7xwquX9uBRPvWE1KSNZW0TszrNwtZLcGERlIfUZYQ5mm\n\tFmnJGFs9NXtPOlBYWkD7DIr9o4gLW/vHCFB0Bycys5rDWa6fM3Fbdka6KPt2WWxLo6\n\tii3tU77Z1KhcuqxU1WyxN7xS4yI/I31FnvKaU2r5ue6N1XTqEiHNSggQpY689KHREd\n\tu1rjCYKk1TNAU5VOTLZgxw6w9mP0Etc4rp5FLJKHmt5PimMm5mMj3USbblx3YLKU4u\n\tBP8HVH1nHTFDg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661845661;\n\tbh=YqjMQP/yqXTzS70rx2uwu27GT7lMJ5U35FUq+fek4Gc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=vvBYdWQel3o1M4mVVJLg30SfHCfLw8J9+BvaGpw2+1FI7V6S6MjR5UxZBfii0Q+r2\n\tRHT9zoeU/XQ8ymSUv1L12q6rVmJWGReddyMyXMHyTejVCFcXD27Ut6Z4VZHpxzPWoa\n\thZs70G3qiNssuhrGxSg2t+NdSbCqVy9HNfUGZDSM="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"vvBYdWQe\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 30 Aug 2022 13:17:20 +0530",
        "Message-Id": "<20220830074725.1059643-3-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.37.2",
        "In-Reply-To": "<20220830074725.1059643-1-umang.jain@ideasonboard.com>",
        "References": "<20220830074725.1059643-1-umang.jain@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 2/7] libcamera: v4l2_device: Adjust\n\tcolorspace based on pixel format",
        "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>",
        "From": "Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Umang Jain <umang.jain@ideasonboard.com>",
        "Cc": "rishikeshdonadkar@gmail.com",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "V4L2 has no \"none\" YCbCr encoding, and thus reports an encoding for all\nformats, including RGB and raw formats. This causes the libcamera\nColorSpace to report incorrect encodings for non-YUV formats. Fix it by\noverriding the encoding reported by the kernel to YCbCrEncoding::None\nfor non-YUV pixel formats and media bus formats.\n\nSimilarly, override the quantization range of non-YUV formats to full\nrange, as limited range isn't used for RGB and raw formats.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_device.h |  5 +++-\n src/libcamera/v4l2_device.cpp            | 29 +++++++++++++++++++----\n src/libcamera/v4l2_subdevice.cpp         | 30 ++++++++++++++++++++++--\n src/libcamera/v4l2_videodevice.cpp       | 12 ++++++----\n 4 files changed, 65 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex a52a5f2c..75304be1 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -22,6 +22,8 @@\n #include <libcamera/color_space.h>\n #include <libcamera/controls.h>\n \n+#include \"libcamera/internal/formats.h\"\n+\n namespace libcamera {\n \n class EventNotifier;\n@@ -59,7 +61,8 @@ protected:\n \tint fd() const { return fd_.get(); }\n \n \ttemplate<typename T>\n-\tstatic std::optional<ColorSpace> toColorSpace(const T &v4l2Format);\n+\tstatic std::optional<ColorSpace> toColorSpace(const T &v4l2Format,\n+\t\t\t\t\t\t      PixelFormatInfo::ColourEncoding colourEncoding);\n \n \ttemplate<typename T>\n \tstatic int fromColorSpace(const std::optional<ColorSpace> &colorSpace, T &v4l2Format);\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex b22a981f..301620f8 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -24,6 +24,7 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n \n+#include \"libcamera/internal/formats.h\"\n #include \"libcamera/internal/sysfs.h\"\n \n /**\n@@ -805,6 +806,7 @@ static const std::map<ColorSpace::Range, v4l2_quantization> rangeToV4l2 = {\n /**\n  * \\brief Convert the color space fields in a V4L2 format to a ColorSpace\n  * \\param[in] v4l2Format A V4L2 format containing color space information\n+ * \\param[in] colourEncoding Type of colour encoding\n  *\n  * The colorspace, ycbcr_enc, xfer_func and quantization fields within a\n  * V4L2 format structure are converted to a corresponding ColorSpace.\n@@ -816,7 +818,8 @@ static const std::map<ColorSpace::Range, v4l2_quantization> rangeToV4l2 = {\n  * \\retval std::nullopt One or more V4L2 color space fields were not recognised\n  */\n template<typename T>\n-std::optional<ColorSpace> V4L2Device::toColorSpace(const T &v4l2Format)\n+std::optional<ColorSpace> V4L2Device::toColorSpace(const T &v4l2Format,\n+\t\t\t\t\t\t   PixelFormatInfo::ColourEncoding colourEncoding)\n {\n \tauto itColor = v4l2ToColorSpace.find(v4l2Format.colorspace);\n \tif (itColor == v4l2ToColorSpace.end())\n@@ -839,6 +842,14 @@ std::optional<ColorSpace> V4L2Device::toColorSpace(const T &v4l2Format)\n \t\t\treturn std::nullopt;\n \n \t\tcolorSpace.ycbcrEncoding = itYcbcrEncoding->second;\n+\n+\t\t/*\n+\t\t * V4L2 has no \"none\" encoding, override the value returned by\n+\t\t * the kernel for non-YUV formats as YCbCr encoding isn't\n+\t\t * applicable in that case.\n+\t\t */\n+\t\tif (colourEncoding != PixelFormatInfo::ColourEncodingYUV)\n+\t\t\tcolorSpace.ycbcrEncoding = ColorSpace::YcbcrEncoding::None;\n \t}\n \n \tif (v4l2Format.quantization != V4L2_QUANTIZATION_DEFAULT) {\n@@ -847,14 +858,24 @@ std::optional<ColorSpace> V4L2Device::toColorSpace(const T &v4l2Format)\n \t\t\treturn std::nullopt;\n \n \t\tcolorSpace.range = itRange->second;\n+\n+\t\t/*\n+\t\t * \"Limited\" quantization range is only meant for YUV formats.\n+\t\t * Override the range to \"Full\" for all other formats.\n+\t\t */\n+\t\tif (colourEncoding != PixelFormatInfo::ColourEncodingYUV)\n+\t\t\tcolorSpace.range = ColorSpace::Range::Full;\n \t}\n \n \treturn colorSpace;\n }\n \n-template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_pix_format &);\n-template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_pix_format_mplane &);\n-template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_mbus_framefmt &);\n+template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_pix_format &,\n+\t\t\t\t\t\t\t    PixelFormatInfo::ColourEncoding);\n+template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_pix_format_mplane &,\n+\t\t\t\t\t\t\t    PixelFormatInfo::ColourEncoding);\n+template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_mbus_framefmt &,\n+\t\t\t\t\t\t\t    PixelFormatInfo::ColourEncoding);\n \n /**\n  * \\brief Fill in the color space fields of a V4L2 format from a ColorSpace\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 07a0bb07..95bfde34 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -503,7 +503,20 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \tformat->size.width = subdevFmt.format.width;\n \tformat->size.height = subdevFmt.format.height;\n \tformat->mbus_code = subdevFmt.format.code;\n-\tformat->colorSpace = toColorSpace(subdevFmt.format);\n+\n+\tPixelFormatInfo::ColourEncoding colourEncoding;\n+\tauto iter = formatInfoMap.find(subdevFmt.format.code);\n+\tif (iter != formatInfoMap.end()) {\n+\t\tcolourEncoding = iter->second.colourEncoding;\n+\t} else {\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Unknown subdev format \"\n+\t\t\t<< utils::hex(subdevFmt.format.code, 4)\n+\t\t\t<< \", defaulting to RGB encoding\";\n+\n+\t\tcolourEncoding = PixelFormatInfo::ColourEncodingRGB;\n+\t}\n+\tformat->colorSpace = toColorSpace(subdevFmt.format, colourEncoding);\n \n \treturn 0;\n }\n@@ -549,7 +562,20 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \tformat->size.width = subdevFmt.format.width;\n \tformat->size.height = subdevFmt.format.height;\n \tformat->mbus_code = subdevFmt.format.code;\n-\tformat->colorSpace = toColorSpace(subdevFmt.format);\n+\n+\tPixelFormatInfo::ColourEncoding colourEncoding;\n+\tauto iter = formatInfoMap.find(subdevFmt.format.code);\n+\tif (iter != formatInfoMap.end()) {\n+\t\tcolourEncoding = iter->second.colourEncoding;\n+\t} else {\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Unknown subdev format \"\n+\t\t\t<< utils::hex(subdevFmt.format.code, 4)\n+\t\t\t<< \", defaulting to RGB encoding\";\n+\n+\t\tcolourEncoding = PixelFormatInfo::ColourEncodingRGB;\n+\t}\n+\tformat->colorSpace = toColorSpace(subdevFmt.format, colourEncoding);\n \n \treturn 0;\n }\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 5a2d0e5b..0e3f5436 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -931,7 +931,8 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n \tformat->size.height = pix->height;\n \tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n \tformat->planesCount = pix->num_planes;\n-\tformat->colorSpace = toColorSpace(*pix);\n+\tformat->colorSpace =\n+\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n \n \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n@@ -987,7 +988,8 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n \t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n \t}\n-\tformat->colorSpace = toColorSpace(*pix);\n+\tformat->colorSpace =\n+\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n \n \treturn 0;\n }\n@@ -1011,7 +1013,8 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n \tformat->planesCount = 1;\n \tformat->planes[0].bpl = pix->bytesperline;\n \tformat->planes[0].size = pix->sizeimage;\n-\tformat->colorSpace = toColorSpace(*pix);\n+\tformat->colorSpace =\n+\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n \n \treturn 0;\n }\n@@ -1053,7 +1056,8 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n \tformat->planesCount = 1;\n \tformat->planes[0].bpl = pix->bytesperline;\n \tformat->planes[0].size = pix->sizeimage;\n-\tformat->colorSpace = toColorSpace(*pix);\n+\tformat->colorSpace =\n+\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n \n \treturn 0;\n }\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "2/7"
    ]
}