Show a patch.

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

{
    "id": 17196,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17196/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17196/",
    "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": "<20220824162425.71087-3-umang.jain@ideasonboard.com>",
    "date": "2022-08-24T16:24:21",
    "name": "[libcamera-devel,v2,2/6] libcamera: v4l2_device: Adjust colorspace if pixel format is RGB",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "3aa1afce1e5d6daaa855174e5b4d4d2d6025cefc",
    "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/17196/mbox/",
    "series": [
        {
            "id": 3434,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3434/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3434",
            "date": "2022-08-24T16:24:19",
            "name": "Colorspace adjustments and gstreamer mappings",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3434/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17196/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17196/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 A6D0DC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Aug 2022 16:24:41 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7340F61FC6;\n\tWed, 24 Aug 2022 18:24: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 58C1D60E26\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Aug 2022 18:24:40 +0200 (CEST)",
            "from umang.jainideasonboard.com (unknown\n\t[IPv6:2401:4900:1f3f:806e:6647:8e5c:f441:ca9a])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4AC892B3;\n\tWed, 24 Aug 2022 18:24:39 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661358281;\n\tbh=X5ZpqRFDht5x/EbcVssn9BdJntD9iFERZb7xAp2vsG4=;\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:\n\tFrom;\n\tb=lLykAQYkWuqgVfyxY6fGVzjOKBE+3CQ516yad+X41Z3d4psWcM4TOLL/oRZdtFzXq\n\tQrxAUZjGKWqRUZPvQrOLA3TaXgSZGfYqHWv2VPvK2E/OO0Azhd+nRKhAqNXYd+H5iF\n\tQXFHMS6gqkyVHcPyyu+p4WS42jTemdHOIZHnPK7gcXspyEug0i6xGaW1b5MRE4wRYw\n\thSo9W5gIbcSTJCQHPMKDUxL8OfH8GcdG+lON1ayumagksWtL5z3PyeQQNaAovdzmAU\n\t7OKGJVyxCHurwD/gihoyQ1mIAnT1eXQkTE00rgPyD2SkasWHo3Nib1HtxasHQoRrAc\n\tyAyAwM55JT2vg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661358280;\n\tbh=X5ZpqRFDht5x/EbcVssn9BdJntD9iFERZb7xAp2vsG4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=sZOL0Y9qDmbIcBppalAf/VoN89P09KrMWYLCDCP1ejxBbfAfWxkmyuqn77k5txQah\n\tU8uH4UnVc5xxQA8u3F6/11HLMrLifMZ52DWc00vyn3KQOhJpIdGDagdruh/yuempT8\n\t9f5HZgj3LsqOBa95flc6ltUF8hxtLB/oUPkcyS10="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"sZOL0Y9q\"; dkim-atps=neutral",
        "To": "libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Wed, 24 Aug 2022 21:54:21 +0530",
        "Message-Id": "<20220824162425.71087-3-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.37.2",
        "In-Reply-To": "<20220824162425.71087-1-umang.jain@ideasonboard.com>",
        "References": "<20220824162425.71087-1-umang.jain@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 2/6] libcamera: v4l2_device: Adjust\n\tcolorspace if pixel format is RGB",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The V4L2_COLORSPACE_SRGB colorspace maps to ColorSpace::Srgb.\nThis is wrong as the V4L2_COLORSPACE_SRGB is ill-defined (defines\nRec 601 Y'CbCr encoding and limited range) in the kernel.\n\nThe RGB pixel formats should not use any Y'CbCr encoding and is always\nfull range. Adjust the colorspace before reporting back to the\nuserspace in such a situation.\n\nMoving forwards, the ColorSpace::Srgb will be defined in the true sense\nfor RGB pixel formats.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_device.h |  5 ++++-\n src/libcamera/v4l2_device.cpp            | 19 +++++++++++++++----\n src/libcamera/v4l2_subdevice.cpp         | 10 ++++++++--\n src/libcamera/v4l2_videodevice.cpp       | 12 ++++++++----\n 4 files changed, 35 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex a52a5f2c..5ae2ef8a 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      const 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..1fb08b9d 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@@ -816,7 +817,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   const PixelFormatInfo::ColourEncoding &colourEncoding)\n {\n \tauto itColor = v4l2ToColorSpace.find(v4l2Format.colorspace);\n \tif (itColor == v4l2ToColorSpace.end())\n@@ -839,6 +841,9 @@ std::optional<ColorSpace> V4L2Device::toColorSpace(const T &v4l2Format)\n \t\t\treturn std::nullopt;\n \n \t\tcolorSpace.ycbcrEncoding = itYcbcrEncoding->second;\n+\n+\t\tif (colourEncoding == PixelFormatInfo::ColourEncodingRGB)\n+\t\t\tcolorSpace.ycbcrEncoding = ColorSpace::YcbcrEncoding::None;\n \t}\n \n \tif (v4l2Format.quantization != V4L2_QUANTIZATION_DEFAULT) {\n@@ -847,14 +852,20 @@ std::optional<ColorSpace> V4L2Device::toColorSpace(const T &v4l2Format)\n \t\t\treturn std::nullopt;\n \n \t\tcolorSpace.range = itRange->second;\n+\n+\t\tif (colourEncoding == PixelFormatInfo::ColourEncodingRGB)\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    const PixelFormatInfo::ColourEncoding &);\n+template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_pix_format_mplane &,\n+\t\t\t\t\t\t\t    const PixelFormatInfo::ColourEncoding &);\n+template std::optional<ColorSpace> V4L2Device::toColorSpace(const struct v4l2_mbus_framefmt &,\n+\t\t\t\t\t\t\t    const 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 ab74b9f0..a52c414f 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -502,7 +502,10 @@ 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+\tauto iter = formatInfoMap.find(format->mbus_code);\n+\tif (iter == formatInfoMap.end())\n+\t\treturn -EINVAL;\n+\tformat->colorSpace = toColorSpace(subdevFmt.format, iter->second.colourEncoding);\n \n \treturn 0;\n }\n@@ -548,7 +551,10 @@ 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+\tauto iter = formatInfoMap.find(format->mbus_code);\n+\tif (iter == formatInfoMap.end())\n+\t\treturn -EINVAL;\n+\tformat->colorSpace = toColorSpace(subdevFmt.format, iter->second.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",
        "v2",
        "2/6"
    ]
}