From patchwork Tue Aug 9 14:35:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 17040 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 73611C3272 for ; Tue, 9 Aug 2022 14:36:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17A176332F; Tue, 9 Aug 2022 16:36:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660055762; bh=awl4xklTtuUU5Mb59OEOY17zUCdX1Th1MBNR3eCSro8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GmAdukRs3IqVWyG0RcWHiv0Ji1sTKPtJLoPa3/1dfJdNJeKvb+xhH9dnDbjg6DEls VPP9AaSNlfsLBNlvxP5ZI0Ks8mrRg3aVI0LtkWGJAM45+/ric0TA2N5h4IMg4GoHRB 8AtWKm2M179GajwQuY4DAzpY0eprGPnXBLj2mrUlq3+Z3Dr1nrgeM20uy3/lpPBaK8 MOIQUV3qd8qUNynXJQE8kVs9ueaprReIak1vvBWB0Z0dNW++oDR2XdGNOSRVIEKDGN scUl2G0puIbXBA2XkDg/Tqt1USCW3kmXRyOiZuUyLMBkwOGvl3ZTYSd65ajzPeMafa YO5h0zqonbTow== Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB71A61FAA for ; Tue, 9 Aug 2022 16:36:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WlL/bmKF"; dkim-atps=neutral Received: by mail-pj1-x102e.google.com with SMTP id p14-20020a17090a74ce00b001f4d04492faso12359394pjl.4 for ; Tue, 09 Aug 2022 07:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=pPvN2mIa4PubgtmGzgfN7j7/BdvXVBboFMCswkgpSAQ=; b=WlL/bmKF0yH4CzBCmqR+mKG52M43X2O9nLLOVvkZkPVvQ+sFh8nyoU4wl5Xjljn2tH XqkFMAaDe9N2rk9+le2KiYBRgpKuIGQ6uA0/1usS2+KFI0BVH7yFQtAEBixilN8reExo 5eVTQm9wqSk3bFi5zjuHBPXlEjndYgkgotNHPnOF9UjwQDL8tndIuA6MedV11oOp7Jj8 ZybNtuYmWNhVrf3t/lXpkOiF3xEPwOl/iNKRkDMUV25WZreKx8dKKyHju5sH0klUs/FR +vnDaXOBvWTkAPG9bFqjyOVZXCsioqWOFUIjDT0KB4d1VHuqlWrB2Ylf3Xn2QZuyxxlt Ridg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=pPvN2mIa4PubgtmGzgfN7j7/BdvXVBboFMCswkgpSAQ=; b=eRMDLxvsQQ+oLMdi2dfPt977ZRwlxx7vJwCj8KQbNQ16DsPdiXPw4h5uA9omC9tV7n OmnaM7XS4hebV7hKBh0wkU3oEAcAcou1uZm7s6Tx8ZWZ+bcwxXjV4Ho3F+Wbt7sHcIyQ 4t09HDPGHdG5xwlwzCSjzVFW5wlgxQClsbsRa0fMpQp8c/3UbWKYR3a8P2F3O+qPjx2h uK//aDlvQNv+iyCnkweSsGF3kaejoqLuy/06VCx3F9lRQEBJNC+Y3KfoLasLOLg4Z2Z3 vBk2rY+Yk12qwBBd71MeZ+uB2g5YtZvO8uahajSIzYq2x8FrBJAwsB+Z9f5ZDPnkZ2X1 V2aQ== X-Gm-Message-State: ACgBeo1DOoz/qY57LbI6C0cWiGAafJXAFH/cwUjTq1rDF2Py5xyy6R5o B9qf397gvmSCbdZDrVE8/eUCHzKgVRF8NChV X-Google-Smtp-Source: AA6agR4sNxXlJhl+4iE/anhRbe9OrSOMS1Se/+OfeMFMlIbpuEWyWjjAv1y7fFtq3EpCDRysf2VB8A== X-Received: by 2002:a17:903:24e:b0:16b:a02d:41fc with SMTP id j14-20020a170903024e00b0016ba02d41fcmr23933162plh.121.1660055759104; Tue, 09 Aug 2022 07:35:59 -0700 (PDT) Received: from localhost.localdomain ([49.36.99.220]) by smtp.googlemail.com with ESMTPSA id h12-20020a17090ac38c00b001f4fb21c11asm10269264pjt.21.2022.08.09.07.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 07:35:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Aug 2022 20:05:30 +0530 Message-Id: <20220809143531.7473-2-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220809143531.7473-1-rishikeshdonadkar@gmail.com> References: <20220809143531.7473-1-rishikeshdonadkar@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] gstreamer: Provide ColorSpace => colorimetry mappings 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: Rishikesh Donadkar via libcamera-devel From: Rishikesh Donadkar Reply-To: Rishikesh Donadkar Cc: Rishikesh Donadkar , nicolas.dufresne@collabora.com, vedantparanjape160201@gmail.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide libcamera::ColorSpace => colorimetry mappings via: - GstVideoColorimetry colorimetry_from_colorspace(colorspace); Read the ColorSpace from the StreamConfiguration, convert it to colorimetry and update the colorimetry into the caps. This patch handles colorimetry in libcamera->GStreamer direction. Colorimetry support form GStreamer->libcamera direction is provided the next patch. Signed-off-by: Rishikesh Donadkar Signed-off-by: Umang Jain --- src/gstreamer/gstlibcamera-utils.cpp | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index c97c0d43..dbb47c5a 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -45,6 +45,65 @@ static struct { /* \todo NV42 is used in libcamera but is not mapped in GStreamer yet. */ }; +static GstVideoColorimetry +colorimetry_from_colorspace(const ColorSpace &colorSpace) +{ + GstVideoColorimetry colorimetry; + + switch (colorSpace.primaries) { + case ColorSpace::Primaries::Raw: + colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN; + break; + case ColorSpace::Primaries::Smpte170m: + colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M; + break; + case ColorSpace::Primaries::Rec709: + colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case ColorSpace::Primaries::Rec2020: + colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + } + + switch (colorSpace.transferFunction) { + case ColorSpace::TransferFunction::Linear: + colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA10; + break; + case ColorSpace::TransferFunction::Srgb: + colorimetry.transfer = GST_VIDEO_TRANSFER_SRGB; + break; + case ColorSpace::TransferFunction::Rec709: + colorimetry.transfer = GST_VIDEO_TRANSFER_BT709; + break; + } + + switch (colorSpace.ycbcrEncoding) { + case ColorSpace::YcbcrEncoding::None: + colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + break; + case ColorSpace::YcbcrEncoding::Rec601: + colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT601; + break; + case ColorSpace::YcbcrEncoding::Rec709: + colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT709; + break; + case ColorSpace::YcbcrEncoding::Rec2020: + colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + break; + } + + switch (colorSpace.range) { + case ColorSpace::Range::Full: + colorimetry.range = GST_VIDEO_COLOR_RANGE_0_255; + break; + case ColorSpace::Range::Limited: + colorimetry.range = GST_VIDEO_COLOR_RANGE_16_235; + break; + } + + return colorimetry; +} + static GstVideoFormat pixel_format_to_gst_format(const PixelFormat &format) { @@ -139,6 +198,18 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg "width", G_TYPE_INT, stream_cfg.size.width, "height", G_TYPE_INT, stream_cfg.size.height, nullptr); + + if (stream_cfg.colorSpace) { + GstVideoColorimetry colorimetry = colorimetry_from_colorspace(stream_cfg.colorSpace.value()); + gchar *colorimetry_str = gst_video_colorimetry_to_string(&colorimetry); + + if (colorimetry_str) + gst_structure_set(s, "colorimetry", G_TYPE_STRING, colorimetry_str, nullptr); + else + g_error("Got invalid colorimetry from ColorSpace: %s", + ColorSpace::toString(stream_cfg.colorSpace).c_str()); + } + gst_caps_append_structure(caps, s); return caps;