{"id":17198,"url":"https://patchwork.libcamera.org/api/patches/17198/?format=json","web_url":"https://patchwork.libcamera.org/patch/17198/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","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-5-umang.jain@ideasonboard.com>","date":"2022-08-24T16:24:23","name":"[libcamera-devel,v2,4/6] libcamera: colorspace: Adjust colorspace of YUV streams","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1c5824178cde8cf624c78e8d8b2ca9cf6d20102b","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":{"id":12,"url":"https://patchwork.libcamera.org/api/users/12/?format=json","username":"uajain","first_name":"Umang","last_name":"Jain","email":"umang.jain@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/17198/mbox/","series":[{"id":3434,"url":"https://patchwork.libcamera.org/api/series/3434/?format=json","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/17198/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17198/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 7F2CCC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Aug 2022 16:24:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 46F4961FBF;\n\tWed, 24 Aug 2022 18:24:46 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8694060E26\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Aug 2022 18:24:44 +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 7B70D2B3;\n\tWed, 24 Aug 2022 18:24:43 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661358286;\n\tbh=IjV1sn2fP2b8d4xLppdD595LhjYUwBxlhRcWyEruQp0=;\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=FieXyJEQU66omex9gvLTpCvSNbGYGQs481a13xbdaBzXsXMewfqUphjTTMB1NuMCv\n\tq3oHS/E2ofQjs5Gn+sOQxwKiiOhqhGBwFzi1j1sfVGS16Bv7CoLtV81jeUjo03NsSq\n\t6kpwXc5rbr6kseHzEMl9e3FQgabFHQB+XTqQjEPtP97ZZuiexz7wKh0G4rAdGwAbVb\n\t4JkgewhmUyzeBxdFgYvvRAAQfHXfCtYf5hrGPw3R6Ol5ah3ET4kdvH8am5Smtn/4d3\n\tDZzGRxqthbRNCZPL/NyAKpTY6AjcSqzd7hJ98xANHid5Nm6F3Z5p2SfppviSb9qhfL\n\taUG90COmQgi5Q==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661358284;\n\tbh=IjV1sn2fP2b8d4xLppdD595LhjYUwBxlhRcWyEruQp0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=UDYWMdzu2nishxBMbnXfwQNY53zxacDm1NCqqUZrSyKNLucADiCNYShBkSzfl+tpZ\n\tUvFoqiJLzQb6raUSX1taB+8pDX+VuH9OjY3N5XbmuTXOgdmVQtWfIaGjKJMmfa3/dd\n\t3UZBi9MCZt5M8qpAN4U9f+I+fv3iSb9uNoPUv88k="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"UDYWMdzu\"; dkim-atps=neutral","To":"libcamera-devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 24 Aug 2022 21:54:23 +0530","Message-Id":"<20220824162425.71087-5-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 4/6] libcamera: colorspace: Adjust\n\tcolorspace of YUV streams","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":"If a YUV stream is requested with no Y'CbCr encoding, we need to adjust\nit to provide a Y'CbCr encoding. Depending on the transfer function and\nprimaries specified, a Y'CbCr encoding is picked up.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n include/libcamera/color_space.h |  7 ++++++\n src/libcamera/camera.cpp        |  7 ++++++\n src/libcamera/color_space.cpp   | 42 +++++++++++++++++++++++++++++++++\n 3 files changed, 56 insertions(+)","diff":"diff --git a/include/libcamera/color_space.h b/include/libcamera/color_space.h\nindex 8030a264..3ee1d28f 100644\n--- a/include/libcamera/color_space.h\n+++ b/include/libcamera/color_space.h\n@@ -12,6 +12,9 @@\n \n namespace libcamera {\n \n+class CameraConfiguration;\n+struct StreamConfiguration;\n+\n class ColorSpace\n {\n public:\n@@ -59,6 +62,10 @@ public:\n \n \tstd::string toString() const;\n \tstatic std::string toString(const std::optional<ColorSpace> &colorSpace);\n+\n+private:\n+\tfriend class CameraConfiguration;\n+\tvoid adjust(const StreamConfiguration &cfg);\n };\n \n bool operator==(const ColorSpace &lhs, const ColorSpace &rhs);\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex a5c3aabe..cdf3c112 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -383,6 +383,13 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF\n \t\t}\n \t}\n \n+\tif (config_[index].colorSpace) {\n+\t\tColorSpace oldColorspace = config_[index].colorSpace.value();\n+\t\tconfig_[index].colorSpace->adjust(config_[index]);\n+\t\tif (oldColorspace != config_[index].colorSpace)\n+\t\t\tstatus = Adjusted;\n+\t}\n+\n \tif (index < 0 || !(flags & ColorSpaceFlag::StreamsShareColorSpace))\n \t\treturn status;\n \ndiff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp\nindex cb47acf9..7beddcbc 100644\n--- a/src/libcamera/color_space.cpp\n+++ b/src/libcamera/color_space.cpp\n@@ -13,6 +13,10 @@\n #include <sstream>\n #include <utility>\n \n+#include <libcamera/stream.h>\n+\n+#include \"libcamera/internal/formats.h\"\n+\n /**\n  * \\file color_space.h\n  * \\brief Class and enums to represent color spaces\n@@ -203,6 +207,44 @@ std::string ColorSpace::toString() const\n \treturn ss.str();\n }\n \n+/**\n+ * \\brief Adjust the colorspace depending on the stream configuration\n+ * \\param[in] config Stream configuration\n+ *\n+ * This function adjust the stream's colorspace depending on various factors\n+ * as reflected by the \\a config.\n+ *\n+ * - If the stream's colorspace consists a YUV stream and has no Y'Cbcr\n+ *   encoding specified, the Y'Cbcr encoding is updated based on the transfer\n+ *   function and primaries fields.\n+ */\n+void ColorSpace::adjust(const StreamConfiguration &config)\n+{\n+\tColorSpace *cs = this;\n+\tbool isYUV = (PixelFormatInfo::info(config.pixelFormat).colourEncoding ==\n+\t\t      PixelFormatInfo::ColourEncodingYUV);\n+\n+\tif (isYUV && cs->ycbcrEncoding == YcbcrEncoding::None) {\n+\t\tif (cs->transferFunction == TransferFunction::Rec709) {\n+\t\t\tswitch (cs->primaries) {\n+\t\t\t/* Raw should never happen */\n+\t\t\tcase Primaries::Raw:\n+\t\t\tcase Primaries::Smpte170m:\n+\t\t\t\tcs->ycbcrEncoding = YcbcrEncoding::Rec601;\n+\t\t\t\tbreak;\n+\t\t\tcase Primaries::Rec709:\n+\t\t\t\tcs->ycbcrEncoding = YcbcrEncoding::Rec709;\n+\t\t\t\tbreak;\n+\t\t\tcase Primaries::Rec2020:\n+\t\t\t\tcs->ycbcrEncoding = YcbcrEncoding::Rec2020;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t} else if (cs->transferFunction == TransferFunction::Srgb) {\n+\t\t\tcs->ycbcrEncoding = YcbcrEncoding::Rec601;\n+\t\t}\n+\t}\n+}\n+\n /**\n  * \\brief Assemble and return a readable string representation of an\n  * optional ColorSpace\n","prefixes":["libcamera-devel","v2","4/6"]}