From patchwork Mon Jul 11 15:37:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 16588 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 71811BE173 for ; Mon, 11 Jul 2022 15:38:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 33CD563314; Mon, 11 Jul 2022 17:38:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657553895; bh=Zl+9vM7+8kBDEy6q+NzqQN+ttnRwn2yb/D3tfz014G8=; 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=avc8lhXV6jZRSLuAOgjuw5BiFefIii1434x49lZyb96NO7tp9kGLX0S5dpMrmw7UL Ws5RQ/qxkmX2gglKjGY3NRUEqa2rZiGOwinT83K2maY3/3+z6BIGdbF8UdgfQdswfl yJ754XMgVnVyhSjl2vQK6+JEfFJzX1+yPlbrNWd0rua61LKsimOjHeyA244Z1dy/JD o+ZDNShowE+tDO8tEPrUmjrXfGCFRWB9K2NfkVc1zFi+YNQZCIZxItis68tjwVAEJF 48CrvzkQmKgZawCIxNSpTA3rWPb/txw9gNKJURL2WCDuML/z1E4rH9HoTeKPA+4hhd Kaae+kBMmblhg== Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D232E62752 for ; Mon, 11 Jul 2022 17:38:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KcH7gjsf"; dkim-atps=neutral Received: by mail-pl1-x630.google.com with SMTP id r1so4732806plo.10 for ; Mon, 11 Jul 2022 08:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NS5pu0DCGUGMfH4dnx5Vf+qPgIETX9SXZ9Vco7I7X2A=; b=KcH7gjsfr7uM6VTzACZ7CdjFTk3i+yOAPn8NLwi/loddjV1k/UH1WHJuIgeBxO0pYu A/NHdxRClFbZiJj/BUZOqn4Ohpwv6XiKncNPMvOofaQ7W2fzWMyg4t07wNaU0HEJZtL5 nxLKWptu69TLWNusue4A0WAc99ZGBiDk/x7TXqZ/tSx5b9j9pCAqxDKNiIEB4aMRb3n1 zqpf9F3bca/L3WuKmalAM7xPfYwKIiQI/AstC4OclcXzngM5EJ9BUrPVGrtbZ84Zonym UQUuwoLAu1zU6O4tAXjX4OvF97Uc4v+52MvgGocItmxGDRHcCmfOAtARjhll14qMwAlt WJ5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NS5pu0DCGUGMfH4dnx5Vf+qPgIETX9SXZ9Vco7I7X2A=; b=VtJvOUjh+Oc1s9dQSD16x/NORHyvll1Uo5j99ABOqbvInDtP2CtcPEksDnrlWIE+F8 mSORXUWk1/8oLM+OfSFG8N8q9DY+7lN0fgGQ9ON4EuDJF55X8wlzHDgoLIfbLMSHQ+3e BuhkO3cH0LDq4cuV4jPOuUjVICZdvoe1jauy4pcITYyHIZmyZOMz3xCrJkJC1wTJsgsR whjA9n7OWfVtlSYXfQhQmGFLJ/uQPzSOqBnKh4ltfqEgmQ0gvreNcY4zoJ7/qunTWiKZ M3Jpsxw1EMS9dUoGZdcDYDNjGnmgN0yCseC26+F6XHjyfOwL0aR9jLgGxPFpAZCQ1hWR iygA== X-Gm-Message-State: AJIora//42358+/hRgO900OIMIEpjrpomA6JRGsy0+4ebRNmOAJMsraJ Q4GtdbKSDDEaFl+fwoRi/LZKP5KIrqw= X-Google-Smtp-Source: AGRyM1tQZSUGmO5mRu/V3HSZGc1ogfTSkE09uOhMRqxfYI1SCRIpLuiCaDxeACuX8QPl+FWcIIG/AQ== X-Received: by 2002:a17:902:c952:b0:16c:1cdd:9077 with SMTP id i18-20020a170902c95200b0016c1cdd9077mr19492012pla.168.1657553892227; Mon, 11 Jul 2022 08:38:12 -0700 (PDT) Received: from localhost.localdomain ([103.124.170.70]) by smtp.googlemail.com with ESMTPSA id u18-20020a17090a891200b001ef87123615sm4891268pjn.37.2022.07.11.08.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 08:38:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Jul 2022 21:07:07 +0530 Message-Id: <20220711153711.36679-2-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711153711.36679-1-rishikeshdonadkar@gmail.com> References: <20220711153711.36679-1-rishikeshdonadkar@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/5] gstreamer: convert from libcamera colorspace to GStreamer colorimetry. 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" Libcamera StreamConfiguration class has colorSpace attribute, which holds the colorspace that is being applied to the camera after the validation of the camera configuration. Add a std::map that will map libcamera colorspace to GStreamer colorimetry and find the colorimetry corresponding to the colorspace that is being applied to the camera.If the colorimetry is found, the helper function libcamera_colorimetry_to_gst_string() will take in a std::string representation of colorimetry and convert it into G_TYPE_STRING so that it can be pushed into the caps. No need to check if the colorimetry if found is valid as we are working with known predefined colorimetry. Signed-off-by: Rishikesh Donadkar --- src/gstreamer/gstlibcamera-utils.cpp | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index c97c0d43..43837602 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -45,6 +45,12 @@ static struct { /* \todo NV42 is used in libcamera but is not mapped in GStreamer yet. */ }; +static const std::vector> ColorSpaceToColorimetry = { + { ColorSpace::Srgb, GST_VIDEO_COLORIMETRY_SRGB }, + { ColorSpace::Rec709, GST_VIDEO_COLORIMETRY_BT709 }, + { ColorSpace::Rec2020, GST_VIDEO_COLORIMETRY_BT2020 }, +}; + static GstVideoFormat pixel_format_to_gst_format(const PixelFormat &format) { @@ -87,6 +93,30 @@ bare_structure_from_format(const PixelFormat &format) } } +static gchar * +libcamera_colorimetry_to_gst_string(const std::string &colorimetry_str) +{ + gchar *colorimetry_gst_string = (gchar *)colorimetry_str.c_str(); + return colorimetry_gst_string; +} + +static gchar * +colorimetry_from_colorspace(ColorSpace colorSpace) +{ + gchar *colorimetry_gst_string = nullptr; + + auto iterColorimetry = std::find_if(ColorSpaceToColorimetry.begin(), ColorSpaceToColorimetry.end(), + [&colorSpace](const auto &item) { + return colorSpace == item.first; + }); + if (iterColorimetry != ColorSpaceToColorimetry.end()) { + const std::string &colrorimetry_string = iterColorimetry->second; + colorimetry_gst_string = libcamera_colorimetry_to_gst_string(colrorimetry_string); + } + + return colorimetry_gst_string; +} + GstCaps * gst_libcamera_stream_formats_to_caps(const StreamFormats &formats) {