From patchwork Mon Aug 29 16:37:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 17231 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 36154C3272 for ; Mon, 29 Aug 2022 16:38:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E315161FCF; Mon, 29 Aug 2022 18:38:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661791092; bh=BJE/sijghjgSBi4m+tWWT8qpCRnDSH7pzLiDtsHQR6Y=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=nnrB+HE9bIAvviV74CBelN5fWVx4IDcVl740JOKdJaZPVT8CZdlPNodrdo4Pv3hy0 wXdZC0lss4bxBOxu5c2Tsh69UlCvOZKBGER8ZzJBk5eHOXP3KGpJZAuDY9QiGdNcu8 erRI30EQEROLPOB70o55vzrUZ9EU//GffmUPcGmAoWjT4waDCuhWtl95e0xF/eDg8k feHuoLBij/gSZcpFkZ+j4lyGDczmKKr84fTnMT4L77RQ3QQZd40+O8ctW+EaFGY/Ty OUyn3KQvmoSq8tFZc3N2Bd+odAskebTrlGhr7GpUq34zs56yTQ9+utRiGUkgykMw/5 Z2zeP5Jg7B2qg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2DE6E61FBA for ; Mon, 29 Aug 2022 18:38:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tX0dchPF"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [IPv6:2401:4900:1f3f:1548:78ac:4a3:edc3:c28a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E55EC505; Mon, 29 Aug 2022 18:38:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661791088; bh=BJE/sijghjgSBi4m+tWWT8qpCRnDSH7pzLiDtsHQR6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tX0dchPFM26CB+AtCuJZeamyipuTnMZBuAfmt2314fPWer3o8dVaVaDuMZpo6SqwX OEXNXw5Hh+bbIky3w44sPzjmmyKlNeSYdSXAF+mjh3wiwdNSj+akpY13AqX9FCvGC9 ZUYZq+kQhXUT/KJPPGnrfVTOjz+JLPE4IxOEgiU8= To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Aug 2022 22:07:39 +0530 Message-Id: <20220829163742.1006102-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829163742.1006102-1-umang.jain@ideasonboard.com> References: <20220829163742.1006102-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/7] libcamera: colorspace: Rectify the ColorSpace::Srgb preset X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rectify the ColorSpace::Srgb to denote that it does not use any Y'Cbcr encoding and uses full range. The kernel on the other hand, recommends to use Rec601 as the encoding for V4L2_COLORSPACE_SRGB. It is not very explicit but it can be inferred that the kernel assumes V4L2_COLORSPACE_SRGB is a YUV-encoded one. However, when the data is in RGB, no encoding is required (and this is denoted by YcbcrEncoding::None in libcamera). Hence, to be clear on the libcamera colorspace API, rectify the ColorSpace::Srgb preset to use YcbcrEncoding::None and full range. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/libcamera/color_space.cpp | 18 ++++++++++-------- src/libcamera/v4l2_device.cpp | 7 +++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp index 944d0e98..ec34620a 100644 --- a/src/libcamera/color_space.cpp +++ b/src/libcamera/color_space.cpp @@ -49,8 +49,13 @@ namespace libcamera { * - Rec.2020 * * Note that there is no guarantee of a 1:1 mapping between color space names - * and definitions in libcamera and V4L2. A notable difference is that the sYCC - * libcamera color space is called JPEG in V4L2 due to historical reasons. + * and definitions in libcamera and V4L2. Two notable differences are + * + * - The sRGB libcamera color space is defined for RGB formats only with no + * Y'CbCr encoding and a full quantization range, while the V4L2 SRGB color + * space has a Y'CbCr encoding and a limited quantization range. + * - The sYCC libcamera color space is called JPEG in V4L2 due to historical + * reasons. * * \todo Define the color space fully in the libcamera API to avoid referencing * V4L2 @@ -138,16 +143,13 @@ const ColorSpace ColorSpace::Raw = { }; /** - * \brief A constant representing the sRGB color space - * - * This is identical to the sYCC color space except that the Y'CbCr - * range is limited rather than full. + * \brief A constant representing the sRGB color space (RGB formats only) */ const ColorSpace ColorSpace::Srgb = { Primaries::Rec709, TransferFunction::Srgb, - YcbcrEncoding::Rec601, - Range::Limited + YcbcrEncoding::None, + Range::Full }; /** diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 301620f8..1d899657 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -746,7 +746,11 @@ void V4L2Device::eventAvailable() static const std::map v4l2ToColorSpace = { { V4L2_COLORSPACE_RAW, ColorSpace::Raw }, - { V4L2_COLORSPACE_SRGB, ColorSpace::Srgb }, + { V4L2_COLORSPACE_SRGB, { + ColorSpace::Primaries::Rec709, + ColorSpace::TransferFunction::Srgb, + ColorSpace::YcbcrEncoding::Rec601, + ColorSpace::Range::Limited } }, { V4L2_COLORSPACE_JPEG, ColorSpace::Sycc }, { V4L2_COLORSPACE_SMPTE170M, ColorSpace::Smpte170m }, { V4L2_COLORSPACE_REC709, ColorSpace::Rec709 }, @@ -772,7 +776,6 @@ static const std::map v4l2ToRange = { static const std::vector> colorSpaceToV4l2 = { { ColorSpace::Raw, V4L2_COLORSPACE_RAW }, - { ColorSpace::Srgb, V4L2_COLORSPACE_SRGB }, { ColorSpace::Sycc, V4L2_COLORSPACE_JPEG }, { ColorSpace::Smpte170m, V4L2_COLORSPACE_SMPTE170M }, { ColorSpace::Rec709, V4L2_COLORSPACE_REC709 },