[{"id":24588,"web_url":"https://patchwork.libcamera.org/comment/24588/","msgid":"<Yvr+VVArc7IbSISQ@pendragon.ideasonboard.com>","date":"2022-08-16T02:17:57","subject":"Re: [libcamera-devel] [RFC PATCH 1/4] libcamera: colorspace:\n\tRectify ColorSpace::Srgb preset","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Wed, Aug 03, 2022 at 12:27:16AM +0530, Umang Jain via libcamera-devel wrote:\n> Rectify the ColorSpace::Srgb to denote that it does not use\n> any Y'Cbcr encoding and uses full range.\n> \n> The kernel on the other hand, recommends to use Rec601 as the encoding\n> for V4L2_COLORSPACE_SRGB. It is not very explicit but it can be\n> inferred that the kernel assumes V4L2_COLORSPACE_SRGB is a YUV-encoded\n> one. However, when the data is in RGB, no encoding is required (and\n> this is denoted by YcbcrEncoding::None in libcamera).\n> \n> Hence, to be clear on the libcamera colorspace API, rectify the\n> ColorSpace::Srgb preset to use YcbcrEncoding::None.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/libcamera/color_space.cpp | 9 +++------\n>  src/libcamera/v4l2_device.cpp | 2 --\n>  2 files changed, 3 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp\n> index caf39760..73148228 100644\n> --- a/src/libcamera/color_space.cpp\n> +++ b/src/libcamera/color_space.cpp\n> @@ -254,16 +254,13 @@ const ColorSpace ColorSpace::Jpeg = {\n>  };\n>  \n>  /**\n> - * \\brief A constant representing the sRGB color space\n> - *\n> - * This is identical to the JPEG color space except that the Y'CbCr\n> - * range is limited rather than full.\n> + * \\brief A constant representing the sRGB color space (non-YUV format)\n\nI would write \"(RGB formats only)\" to be even clearer.\n\n>   */\n>  const ColorSpace ColorSpace::Srgb = {\n>  \tPrimaries::Rec709,\n>  \tTransferFunction::Srgb,\n> -\tYcbcrEncoding::Rec601,\n> -\tRange::Limited\n> +\tYcbcrEncoding::None,\n> +\tRange::Full\n>  };\n>  \n>  /**\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 3fc8438f..a4446fbf 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -746,7 +746,6 @@ void V4L2Device::eventAvailable()\n>  static const std::map<uint32_t, ColorSpace> v4l2ToColorSpace = {\n>  \t{ V4L2_COLORSPACE_RAW, ColorSpace::Raw },\n>  \t{ V4L2_COLORSPACE_JPEG, ColorSpace::Jpeg },\n> -\t{ V4L2_COLORSPACE_SRGB, ColorSpace::Srgb },\n\nThis will cause an issue, as V4L2Device::toColorSpace() will return\nnullopt if the kernel reports V4L2_COLORSPACE_SRGB. You should instead\nuse the kernel definition of the SRGB color space here:\n\n\t{ V4L2_COLORSPACE_SRGB, {\n\t\tColorSpace::Primaries::Rec709,\n\t\tColorSpace::TransferFunction::Srgb,\n\t\tColorSpace::YcbcrEncoding::Rec601,\n\t\tColorSpace::Range::Limited\n\t} },\n\nHowever, that won't be enough. V4L2Device::toColorSpace() also needs to\nset colorSpace.ycbcrEncoding to YcbcrEncoding::None and colorSpace.range\nto Range::Full if the format is an RGB format. I think it would be best\nto do so in a patch before this one.\n\n>  \t{ V4L2_COLORSPACE_SMPTE170M, ColorSpace::Smpte170m },\n>  \t{ V4L2_COLORSPACE_REC709, ColorSpace::Rec709 },\n>  \t{ V4L2_COLORSPACE_BT2020, ColorSpace::Rec2020 },\n> @@ -772,7 +771,6 @@ static const std::map<uint32_t, ColorSpace::Range> v4l2ToRange = {\n>  static const std::vector<std::pair<ColorSpace, v4l2_colorspace>> colorSpaceToV4l2 = {\n>  \t{ ColorSpace::Raw, V4L2_COLORSPACE_RAW },\n>  \t{ ColorSpace::Jpeg, V4L2_COLORSPACE_JPEG },\n> -\t{ ColorSpace::Srgb, V4L2_COLORSPACE_SRGB },\n\nThis, on the other hand, should be fine.\n\n>  \t{ ColorSpace::Smpte170m, V4L2_COLORSPACE_SMPTE170M },\n>  \t{ ColorSpace::Rec709, V4L2_COLORSPACE_REC709 },\n>  \t{ ColorSpace::Rec2020, V4L2_COLORSPACE_BT2020 },","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 036B4BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Aug 2022 02:18:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4259761FC0;\n\tTue, 16 Aug 2022 04:18:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 350B5603E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Aug 2022 04:18:11 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 925C6496;\n\tTue, 16 Aug 2022 04:18:10 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660616293;\n\tbh=iUB7To0JRbfibBw1EC0wD3jQzDxHx6rPBlJ47LVpvuQ=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=SAbc2NWgJz5kTff3h5U1b+aGOtHNv7ePpsOu3Gwo+y63tl0ObcO+tcP2N5yQYwmlZ\n\tzuDnwQQys3n7VDAsHyG96Ou2LorDAnliiNxhxUfllI+KTFrfhJ3qpLI+w8pyqHz48P\n\t86V268AjUT+EJpjZdOxwRxTHp0jGyv4EX+abur4QEOTgwR5RXc/pqvO+YnP7Nkil1F\n\tdvI99xSIcqwdWcPqxw2wA+Y3r7dVDU051IPNwau6wsmqVKqczouzBayNNXdWzYw+Lk\n\tvkn3BSjWwQJNdhAtdLDA+etiowIc3rFSSfSjlJsIvq+UEZnTG/c66ILPX7D48gbRBw\n\tbv6G75CoBWHcQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660616290;\n\tbh=iUB7To0JRbfibBw1EC0wD3jQzDxHx6rPBlJ47LVpvuQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gmQxpz1ZnR5c8HnGvgFc6FEofgQp2vdhweAX0HOTq7fpFyx3EdE7smYQ5wxm4Wd/o\n\tfwaPBQcZ+ecmSLJlEkCsg4OHPAOdYn1/W4M8mxfdjbm7RIxSCZPHKSJ26ixg/3cZy7\n\tc2dwOVPRDg07FIoH+4V1YSRCwL9bc45ICBpe4DXY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"gmQxpz1Z\"; dkim-atps=neutral","Date":"Tue, 16 Aug 2022 05:17:57 +0300","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<Yvr+VVArc7IbSISQ@pendragon.ideasonboard.com>","References":"<20220802185719.380855-1-umang.jain@ideasonboard.com>\n\t<20220802185719.380855-2-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220802185719.380855-2-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [RFC PATCH 1/4] libcamera: colorspace:\n\tRectify ColorSpace::Srgb preset","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"rishikeshdonadkar@gmail.com, libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]