{"id":16919,"url":"https://patchwork.libcamera.org/api/1.1/patches/16919/?format=json","web_url":"https://patchwork.libcamera.org/patch/16919/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20220802185719.380855-3-umang.jain@ideasonboard.com>","date":"2022-08-02T18:57:17","name":"[libcamera-devel,RFC,2/4] libcamera: colorspace: Adjust colorspace of YUV streams","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ce52f8c8a4cf88bd6128940ff2df1f794b72f86f","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/1.1/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16919/mbox/","series":[{"id":3360,"url":"https://patchwork.libcamera.org/api/1.1/series/3360/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3360","date":"2022-08-02T18:57:15","name":"Colorspace adjustments and gstreamer mapping","version":1,"mbox":"https://patchwork.libcamera.org/series/3360/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16919/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16919/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 92296C3275\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Aug 2022 18:57:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5189463312;\n\tTue,  2 Aug 2022 20:57:34 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 93D45603E7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Aug 2022 20:57:32 +0200 (CEST)","from perceval.ideasonboard.com (unknown\n\t[IPv6:2401:4900:1f3f:85c2:5ee8:5bb8:aca7:5517])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 044B525B;\n\tTue,  2 Aug 2022 20:57:30 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659466654;\n\tbh=TEGpV3flB5XViFvlMSyN0wI+yMDxiS/1IVfJrpNnqtg=;\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=K39bGTetJ1ulgIhCgN7HYQwLwykLyQPW2EvKZAux4IxBEfIvgckVnGHMtSf1ioUOl\n\tX0NasYi5XpcFfWnr3QPD+phOowvIzCtCA2WzDOmXjwbht7DbewEVMB/h3CN3cBLVGM\n\tF/H/0WOofRvphPp66B2pTQDE7vB+VvMXE4bfXK6NZBbN/7c8FGo2qaAb8CiV6R2hH0\n\tR6JpvGdsZI+surdsgJXnKSHZ/UwNdnad/6InMlz+P7OmHxO2QS5g6pv7fbt6n1f1wy\n\tUvBAEqLZRdik4RF5WNAwFPnQ/8SJIQKk8pKbiQ8zOEERoNBPqSYGC/xoNSEf6BQy7H\n\tlcftq4oxDxn3g==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659466652;\n\tbh=TEGpV3flB5XViFvlMSyN0wI+yMDxiS/1IVfJrpNnqtg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OHvS77umUzTOXl1NOBlRC75cXxUzuffkTHvTdXp8BxiWFr9drr99TGUQMsLsQp/pU\n\tEq613wkYcTJ/kYNQka3iF3rHMowKGqnSNR6n4Itm3/EDqhP6Aw+W3ZjUxzyXz9CUxo\n\ttD6yIpyGeIwk3mFgBHUPhcNOzXKkKTzsRUTk1Y3E="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"OHvS77um\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  3 Aug 2022 00:27:17 +0530","Message-Id":"<20220802185719.380855-3-umang.jain@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20220802185719.380855-1-umang.jain@ideasonboard.com>","References":"<20220802185719.380855-1-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH 2/4] 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>","Cc":"rishikeshdonadkar@gmail.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 |  6 ++++\n src/libcamera/camera.cpp        | 11 ++++++\n src/libcamera/color_space.cpp   | 61 +++++++++++++++++++++++++++++++++\n 3 files changed, 78 insertions(+)","diff":"diff --git a/include/libcamera/color_space.h b/include/libcamera/color_space.h\nindex 0d39fbc0..113e2715 100644\n--- a/include/libcamera/color_space.h\n+++ b/include/libcamera/color_space.h\n@@ -12,6 +12,8 @@\n \n namespace libcamera {\n \n+struct StreamConfiguration;\n+\n class ColorSpace\n {\n public:\n@@ -59,6 +61,10 @@ public:\n \n \tstd::string toString() const;\n \tstatic std::string toString(const std::optional<ColorSpace> &colorSpace);\n+\tColorSpace adjust(const StreamConfiguration &cfg);\n+\n+private:\n+\tColorSpace adjustYuv(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 3910915c..05135d16 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -386,6 +386,17 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF\n \tif (index < 0 || !(flags & ColorSpaceFlag::StreamsShareColorSpace))\n \t\treturn status;\n \n+\t/*\n+\t * \\todo Question StreamsShareColorSpace <> an adjusted colorspace\n+\t * interation.\n+\t */\n+\tif (config_[index].colorSpace) {\n+\t\tColorSpace oldColorspace = config_[index].colorSpace.value();\n+\t\tColorSpace newColorspace = oldColorspace.adjust(config_[index]);\n+\t\tif (oldColorspace != newColorspace)\n+\t\t\tconfig_[index].colorSpace = newColorspace;\n+\t}\n+\n \t/* Make all output color spaces the same, if requested. */\n \tfor (auto &cfg : config_) {\n \t\tif (!isRaw(cfg.pixelFormat) &&\ndiff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp\nindex 73148228..ff3f76d9 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@@ -193,6 +197,63 @@ std::string ColorSpace::toString() const\n \treturn ss.str();\n }\n \n+/**\n+ * \\brief Adjust colospace when stream configuration contains YUV stream\n+ * \\param[in] config Stream configuration\n+ *\n+ * This function adjust the stream's colorspace if it consists a YUV stream\n+ * and has no Y'Cbcr encoding specified. The function shall update the\n+ * Y'Cbcr encoding based on the transfer function and primaries fields.\n+ *\n+ * \\return The adjusted colorspace\n+ */\n+ColorSpace\n+ColorSpace::adjustYuv(const StreamConfiguration &cfg)\n+{\n+\tColorSpace cs = *this;\n+\tbool isYUV = (PixelFormatInfo::info(cfg.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+\n+\t\t/* \\todo: Determine if range needs to be adjusted in some cases? */\n+\t}\n+\n+\treturn cs;\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+ * \\return The adjusted colorspace according to the stream configuration\n+ */\n+ColorSpace\n+ColorSpace::adjust(const StreamConfiguration &config)\n+{\n+\treturn adjustYuv(config);\n+}\n+\n /**\n  * \\brief Assemble and return a readable string representation of an\n  * optional ColorSpace\n","prefixes":["libcamera-devel","RFC","2/4"]}