[{"id":24766,"web_url":"https://patchwork.libcamera.org/comment/24766/","msgid":"<Ywa1bK2WadKn5/W0@pendragon.ideasonboard.com>","date":"2022-08-24T23:34:04","subject":"Re: [libcamera-devel] [PATCH v2 3/6] libcamera: colorspace: Rectify\n\tthe 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 24, 2022 at 09:54:22PM +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 | 14 +++++++-------\n>  src/libcamera/v4l2_device.cpp |  7 +++++--\n>  2 files changed, 12 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp\n> index f0d6109a..cb47acf9 100644\n> --- a/src/libcamera/color_space.cpp\n> +++ b/src/libcamera/color_space.cpp\n> @@ -47,7 +47,10 @@ namespace libcamera {\n>   *\n>   * Note that there is no guarantee of a 1:1 mapping between color space names\n>   * and definitions in libcamera and V4L2. A notable difference is that the sYCC\n> - * libcamera color space is called JPEG in V4L2 due to historical reasons.\n> + * libcamera color space is called JPEG in V4L2 due to historical reasons. On\n> + * a similar note, the sRGB colorspace defined in the kernel assumes a Y'CbCr\n> + * encoding to it which is not true. Hence the ColorSpace::sRGB is defined\n> + * differently in libcamera (with no Y'CbCr encoding and full range).\n\n * and definitions in libcamera and V4L2. Two notable differences are\n *\n * - The sRGB libcamera color space is defined for RGB formats only with no\n *   Y'CbCr encoding and a full quantization range, while the V4L2 SRGB color\n *   space has a Y'CbCr encoding and a limited quantization range.\n * - The sYCC libcamera color space is called JPEG in V4L2 due to historical\n *   reasons.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>   *\n>   * \\todo Define the color space fully in the libcamera API to avoid referencing\n>   * V4L2\n> @@ -250,16 +253,13 @@ const ColorSpace ColorSpace::Raw = {\n>  };\n>  \n>  /**\n> - * \\brief A constant representing the sRGB color space\n> - *\n> - * This is identical to the sYCC color space except that the Y'CbCr\n> - * range is limited rather than full.\n> + * \\brief A constant representing the sRGB color space (RGB formats only)\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 1fb08b9d..a9e34ee1 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -746,7 +746,11 @@ void V4L2Device::eventAvailable()\n>  \n>  static const std::map<uint32_t, ColorSpace> v4l2ToColorSpace = {\n>  \t{ V4L2_COLORSPACE_RAW, ColorSpace::Raw },\n> -\t{ V4L2_COLORSPACE_SRGB, ColorSpace::Srgb },\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{ V4L2_COLORSPACE_JPEG, ColorSpace::Sycc },\n>  \t{ V4L2_COLORSPACE_SMPTE170M, ColorSpace::Smpte170m },\n>  \t{ V4L2_COLORSPACE_REC709, ColorSpace::Rec709 },\n> @@ -772,7 +776,6 @@ static const std::map<uint32_t, ColorSpace::Range> v4l2ToRange = {\n>  \n>  static const std::vector<std::pair<ColorSpace, v4l2_colorspace>> colorSpaceToV4l2 = {\n>  \t{ ColorSpace::Raw, V4L2_COLORSPACE_RAW },\n> -\t{ ColorSpace::Srgb, V4L2_COLORSPACE_SRGB },\n>  \t{ ColorSpace::Sycc, V4L2_COLORSPACE_JPEG },\n>  \t{ ColorSpace::Smpte170m, V4L2_COLORSPACE_SMPTE170M },\n>  \t{ ColorSpace::Rec709, V4L2_COLORSPACE_REC709 },","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 0D466C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Aug 2022 23:34:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6BC8861FC1;\n\tThu, 25 Aug 2022 01:34:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 928DD61F9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Aug 2022 01:34:10 +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 E256D2B3;\n\tThu, 25 Aug 2022 01:34:09 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661384052;\n\tbh=M4+CxKzO0lPZKRxA0HTmre/G6huD0BbGLXfMUHfpYn4=;\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=PoOcOiXNxmODMXjz7jTrB8IrwQ7Bt7mnDecBcm9o7h0meD4+jMZgH7QyNSvS9IZlv\n\tW4u8l/7xhPbT+wvRic8fJNhEVt9CD+SyTzj3rhnvun3P+3sU10GszWzd72BB974W6Z\n\tSr+x/atvUYI0IF2pxI8buWIc5fsonFwzINYAXKGa7klDXYnWzl8i+JH85RHEwwJg5J\n\tn8uMBQzPv7xoBnLe2dvTWvjcLb0PHl7JplkNhIKmr38O+lfKtk+obIwVp6cdChs5uJ\n\tC+yFgeXpM17bvV7gL73oZ4LGcqzxjqbGzOqeTSyKow4nxpmS0ORRMu3xgPpQp+ZIdH\n\tm9EEWX8572l4A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661384050;\n\tbh=M4+CxKzO0lPZKRxA0HTmre/G6huD0BbGLXfMUHfpYn4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MysTF32jzCHv4g4W1Fw7tu+kIE09wd/atoltUE722qlcz2JPsDoRu64wCpDgGiEEC\n\t4+9VnLDksw5QQNxjumsukrnadrFL4+IcPWNKo/Fz4ObmyuzWm4bayet8AcTHAu+0BT\n\t57TRCBvCDT6l4TC13bADo9RSpSvWUhHFeHAV0E40="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"MysTF32j\"; dkim-atps=neutral","Date":"Thu, 25 Aug 2022 02:34:04 +0300","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<Ywa1bK2WadKn5/W0@pendragon.ideasonboard.com>","References":"<20220824162425.71087-1-umang.jain@ideasonboard.com>\n\t<20220824162425.71087-4-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220824162425.71087-4-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 3/6] libcamera: colorspace: Rectify\n\tthe 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":"libcamera-devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]