From patchwork Wed Aug 24 16:24:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 17197 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 286CFC3272 for ; Wed, 24 Aug 2022 16:24:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DA73561FBC; Wed, 24 Aug 2022 18:24:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661358283; bh=IFJrV8sGTED81EbaRi7SSg8dl8ouFKuBrP3ii/r6w8Q=; 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=LjcA+RGtZtL9hDA7WMHCeO9+yi8rt7JKzMoZl+8SAi+h4ZCyUg519ja9qE49d/uvF KPVjlFtpWeD4J7wTgq1jKU3zroP1F7KQy6++lrT9RovvgCguu6yNcUeXrrZF7dCmEs 5oLvRRik8F48SEu77TXCVFfFz8SDrt0fumd9BneHcUz/fCkA46ZhEFu0KLO/xSDz/n RWFCQCLs8rgRn6Uoc1GogKUO+xrw7KGaUalPnn8lqHAMopZlKezzpu6e8hQuHVAT2M HMHUunQGercCCHzliO6RneyGnaWujkCujR0FX/w2eISuHvfOKiwIXwfjtuZRrvpOMz 1UlRG+OoMyuOw== 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 76CCA60E26 for ; Wed, 24 Aug 2022 18:24:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IuXEzYeH"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [IPv6:2401:4900:1f3f:806e:6647:8e5c:f441:ca9a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 66C582B3; Wed, 24 Aug 2022 18:24:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661358282; bh=IFJrV8sGTED81EbaRi7SSg8dl8ouFKuBrP3ii/r6w8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IuXEzYeHenlMmNL8Ls2gkN26pvBIN84fAmJwHC+6YK6W9hwgofNCmXV2UvgLH2831 hIxzUK+EeDXCd04WvCgFy62e8piFzUHW3Niek6bGrUBoMBjTjbN3XKaWsxM2uoh/6c xDMngFGnvedXIZP6zj5d9lzG6ANAqRddqZtSEbxg= To: libcamera-devel Date: Wed, 24 Aug 2022 21:54:22 +0530 Message-Id: <20220824162425.71087-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220824162425.71087-1-umang.jain@ideasonboard.com> References: <20220824162425.71087-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/6] 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. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/libcamera/color_space.cpp | 14 +++++++------- src/libcamera/v4l2_device.cpp | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp index f0d6109a..cb47acf9 100644 --- a/src/libcamera/color_space.cpp +++ b/src/libcamera/color_space.cpp @@ -47,7 +47,10 @@ namespace libcamera { * * 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. + * libcamera color space is called JPEG in V4L2 due to historical reasons. On + * a similar note, the sRGB colorspace defined in the kernel assumes a Y'CbCr + * encoding to it which is not true. Hence the ColorSpace::sRGB is defined + * differently in libcamera (with no Y'CbCr encoding and full range). * * \todo Define the color space fully in the libcamera API to avoid referencing * V4L2 @@ -250,16 +253,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 1fb08b9d..a9e34ee1 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 },