[{"id":24876,"web_url":"https://patchwork.libcamera.org/comment/24876/","msgid":"<20220901034038.GF27075@pyrite.rasen.tech>","date":"2022-09-01T03:40:38","subject":"Re: [libcamera-devel] [PATCH v4 4/7] libcamera: colorspace: Rectify\n\tthe ColorSpace::Srgb preset","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"On Tue, Aug 30, 2022 at 01:17: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 and full range.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/libcamera/color_space.cpp | 18 ++++++++++--------\n>  src/libcamera/v4l2_device.cpp |  7 +++++--\n>  2 files changed, 15 insertions(+), 10 deletions(-)\n> \n> diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp\n> index 944d0e98..ec34620a 100644\n> --- a/src/libcamera/color_space.cpp\n> +++ b/src/libcamera/color_space.cpp\n> @@ -49,8 +49,13 @@ namespace libcamera {\n>   * - <a href=\"https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/colorspaces-details.html#col-bt2020\">Rec.2020</a>\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> + * 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>   *\n>   * \\todo Define the color space fully in the libcamera API to avoid referencing\n>   * V4L2\n> @@ -138,16 +143,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 301620f8..1d899657 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 },\n> -- \n> 2.37.2\n>","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 2CCB2C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  1 Sep 2022 03:40:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A096861FC8;\n\tThu,  1 Sep 2022 05:40:50 +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 463FA61F9A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 Sep 2022 05:40:49 +0200 (CEST)","from pyrite.rasen.tech (unknown [50.228.9.220])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A4C0B481;\n\tThu,  1 Sep 2022 05:40:47 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662003650;\n\tbh=Wt6f3HPEIRs0KsiTPmVJAnnUq1u0hRmXi115OZJoE1Y=;\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=gp5gHTUwvs3MuH06+ynwBE1k00drmAUz2B+iNrz4ysQdGrfkgoYVgarXPRVcRNDZ9\n\t0TFvOF/a31ghEHo7xYrb0x3sqKSYzXPo7F7c+5BOOkv2WgyiNBN7rc7B4/zZfQ8Lug\n\tgX07gixZLpqtJdH7eTK98xPIMHzZ1NKXLzoapJvQXvG5LQIqPY7KCLyAABASYIlEgM\n\tFA1sqdmkCs7qNnRmzhdaW8nlLOP8WorvchttHkS/ifU5EfTbus4Sb6pZzj56s6wley\n\twSmL/k/OwWA/u4d5vT8LnuRLPXiAzmvED9KKBIRRW3i4iQ/7OpoJU6gysJa21oW+qS\n\tfsdBvfc8iqp+A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1662003648;\n\tbh=Wt6f3HPEIRs0KsiTPmVJAnnUq1u0hRmXi115OZJoE1Y=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=HS1LVqo2rtrgZw91OEWrbIoCa5TLkzHm5wWMP51FTB48VmlWBRg9/7ZM4hZplewmI\n\tHqIrwD1n6GaeSWe8SXFkPs51FEWkw3vHDQTBq1g38+Ei2MqamBBGzAC2b0xOWQV7Wg\n\t4rvJ/SSsRC6OGdz6qBQwGjbvB+rdRUw4l2IkFVhg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"HS1LVqo2\"; dkim-atps=neutral","Date":"Wed, 31 Aug 2022 23:40:38 -0400","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<20220901034038.GF27075@pyrite.rasen.tech>","References":"<20220830074725.1059643-1-umang.jain@ideasonboard.com>\n\t<20220830074725.1059643-5-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220830074725.1059643-5-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 4/7] 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":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@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>"}}]