Patch Detail
Show a patch.
GET /api/1.1/patches/17229/?format=api
{ "id": 17229, "url": "https://patchwork.libcamera.org/api/1.1/patches/17229/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17229/", "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": "<20220829163742.1006102-3-umang.jain@ideasonboard.com>", "date": "2022-08-29T16:37:37", "name": "[libcamera-devel,v3,2/7] libcamera: v4l2_device: Adjust colorspace based on pixel format", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "dc43f3e750fb4732c715806a31ce0a7fc4e3f6c8", "submitter": { "id": 86, "url": "https://patchwork.libcamera.org/api/1.1/people/86/?format=api", "name": "Umang Jain", "email": "umang.jain@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17229/mbox/", "series": [ { "id": 3447, "url": "https://patchwork.libcamera.org/api/1.1/series/3447/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3447", "date": "2022-08-29T16:37:35", "name": "Colorspace adjustments and gstreamer mappings", "version": 3, "mbox": "https://patchwork.libcamera.org/series/3447/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17229/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17229/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 20E92C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Aug 2022 16:38:08 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CF97F61FC8;\n\tMon, 29 Aug 2022 18:38:07 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3826C61FC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Aug 2022 18:38:05 +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 2472A8BD;\n\tMon, 29 Aug 2022 18:38:03 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661791087;\n\tbh=ujuqE6ma3HkGef1NirHTwKRyN2252ckQIpdhAhMr73Y=;\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=dF8wCsF4jH3zk8WMLlCdQVfZWdNE4fg6SEzkUrBLy15h0OdCv4VGiM/WXYHZ+/kOH\n\tumWr0V8n4ACE7jv0Q6+AMpyMA1BUmfsXqZRC88+dNQBpQn/rM74V+MqCBi8f0ax67N\n\trwtF50ykuGumK49reF6jfSzDRJPToayDH5ESNBy8wRe66eyJrfWyekNmhYOf9c4zh1\n\tbYu+GfqYO7c1YkORU8Cph0dE14t6Hd0hNcgniehr8Hd7sA8FCuVZ6oJvLJXcNeUZEF\n\tElog/E8SckUwPprYmxDfNqQ9RQmjt4aCX4s5GyYp5RG5M7gfE3vpM4Vo8cfjTKNPmc\n\t3tO0OquC8XGAQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661791084;\n\tbh=ujuqE6ma3HkGef1NirHTwKRyN2252ckQIpdhAhMr73Y=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Pth+zvDhn1pE//1sOYqrKdGSpLrF0GAUWPUMHOTLovNYJq6yLDZEp8pRJ8mnfx73+\n\tJb/nqcpJRVVqKzcuTMtTxbxrnhxneZFoyDMou+NLnujZg0P6QhIlf+yJOSO6O7hpD+\n\th7tlXPCS1QPbcIuAvDgLJYpkf17dIHwqX0PeUcnw=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Pth+zvDh\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 29 Aug 2022 22:07:37 +0530", "Message-Id": "<20220829163742.1006102-3-umang.jain@ideasonboard.com>", "X-Mailer": "git-send-email 2.37.2", "In-Reply-To": "<20220829163742.1006102-1-umang.jain@ideasonboard.com>", "References": "<20220829163742.1006102-1-umang.jain@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 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>", "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>\n---\n include/libcamera/internal/v4l2_device.h | 5 +++-\n src/libcamera/v4l2_device.cpp | 29 ++++++++++++++++++---\n src/libcamera/v4l2_subdevice.cpp | 32 ++++++++++++++++++++++--\n src/libcamera/v4l2_videodevice.cpp | 12 ++++++---\n 4 files changed, 67 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..0389f1b3 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -502,8 +502,22 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \n \tformat->size.width = subdevFmt.format.width;\n \tformat->size.height = subdevFmt.format.height;\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+\n \tformat->mbus_code = subdevFmt.format.code;\n-\tformat->colorSpace = toColorSpace(subdevFmt.format);\n+\tformat->colorSpace = toColorSpace(subdevFmt.format, colourEncoding);\n \n \treturn 0;\n }\n@@ -548,8 +562,22 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \n \tformat->size.width = subdevFmt.format.width;\n \tformat->size.height = subdevFmt.format.height;\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+\n \tformat->mbus_code = subdevFmt.format.code;\n-\tformat->colorSpace = toColorSpace(subdevFmt.format);\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", "v3", "2/7" ] }