From patchwork Thu Jul 7 09:43:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 16567 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 0E01CBE173 for ; Thu, 7 Jul 2022 09:45:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BCE176048D; Thu, 7 Jul 2022 11:45:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657187109; bh=vrmX0jagPaiuqOHcRlTN4eBQIdjthx/IP+2DusFR41M=; 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=j4X5G1MML/CIVPJ4IeRUy9qkpeNjxQucVDaI/QEgpk0aiBRw4o9SrmbPbxmGL5/c+ tLOEMHcHHI2O2NNnqtO69FyM1OnSbRl3RiwJaHT4L9NstzHRd9/fQlyGfN/+jc0bdo ZthnQQk5AIr0F3RHeasC4X/vAxshAlikaELlTHYZU37syYurBazOQlfQOkuLtHwT2l NVKj8GEvJIlCmUdsZS7RY+RfgKC5NqoNBO/JOVe4+a/+1hTLSLOoQnFias3zrp4Xa9 cImH9Y4W5VxdWGaln0EyY/8lUjalJI+McxpZ9rYKtVul/xfZBP2r/6ZsN+6LCtSkwA 0RYcA7iorYp7A== Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97DBA60401 for ; Thu, 7 Jul 2022 11:45:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NxUSjJMt"; dkim-atps=neutral Received: by mail-pf1-x435.google.com with SMTP id x184so4905141pfx.2 for ; Thu, 07 Jul 2022 02:45:07 -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=tyDMdzAvFdoqw+pj00jWOccwYIWcruJQCOAJ7uJJFD0=; b=NxUSjJMt3qRBrfu2tu/11f7mmOdh4FjDQ7IU2m5nuf82d16L23+umPdOln0KJIgWDN LcpS/HXWP2RGp5ymxVqoR2ePebtvUNiYHjMjScgn0kucEGcrwcMzTR7nCTq0X+s1Er5x 7X6pl+YP8KT6RpmNZxdZ5CsEBcIEx6Pc4npe6gGabuZyksBNzlsdMWSYo3bZWqm1Rr4v fvMSAWnSLjcxHe4phlVGKdKynLonhWhmKfTN3shGL13YY2CHe9EEECvJ0pBy9dKeYFYu dkWfT2sT8VA0uO3ltjoHX/d/N4vIwZwa70Q+9FaKlCCI8bGive+yizNZFTKiTalDNUZv V3TA== 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=tyDMdzAvFdoqw+pj00jWOccwYIWcruJQCOAJ7uJJFD0=; b=ajbtkaC9oQdwvXsnj9crSl/kPdc2UKdt++bs67Rc9LReJ0osmJrshYrHfC3NRNXMv6 98mxk44fURhrOIV/CaYQq5JecXTj8ypTzYVyeCV9rIz2lqYPgN/dfLaL094U452rbU3y HUpgPoUbixHYw+CTktO1TW35d3XWRutl/a4NqrMItOXg5/+CxLT3bn6Fu1YIcGQjanRs xhFh0nfiFXd2Pbou9NZn89yzGhvDuM3j5EFzI2np30AXAijxXJAr1Id0ei2opRFW69HL PyOIK3L1lLr8GZumtL+f5AtKjvpYFC5d/ymb6KuALc6bXrnQb44h6PtAeOdMcZUT0d8H gmdg== X-Gm-Message-State: AJIora+OukIZtiHsdjZ1/3+YBps/WAHf7J3YaC2a7rRdahoLTQv6OZMr NOiXaJAAxot+OFudrfRaBzeGY7qQvH0= X-Google-Smtp-Source: AGRyM1tIv/f1M0IzdzN4p8SLR5jgPUcpvkhByHoCAo3TfI6aIVyZI70wawZyLSQWsfA3h3+mg9nj2Q== X-Received: by 2002:a63:2bd0:0:b0:412:2f70:f0ac with SMTP id r199-20020a632bd0000000b004122f70f0acmr19319758pgr.465.1657187105816; Thu, 07 Jul 2022 02:45:05 -0700 (PDT) Received: from localhost.localdomain ([2402:8100:30ae:d446:13ee:d079:112a:ac10]) by smtp.googlemail.com with ESMTPSA id p2-20020a1709027ec200b00168f08d0d12sm24530712plb.89.2022.07.07.02.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 02:45:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 7 Jul 2022 15:13:59 +0530 Message-Id: <20220707094402.28730-2-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707094402.28730-1-rishikeshdonadkar@gmail.com> References: <20220707094402.28730-1-rishikeshdonadkar@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/4] gstreamer: convert from libcamera colorspace toGStreamer 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. Map the libcamera colorspace to GStreamer colorimetry and find the colorimetry corresponding to the colorspace that is being applied to the camera. This colorimetry if found will be pushed in the caps. Signed-off-by: Rishikesh Donadkar --- src/gstreamer/gstlibcamera-utils.cpp | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index c97c0d43..60ac8c8e 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,32 @@ bare_structure_from_format(const PixelFormat &format) } } +static gchar * +colorimerty_from_colorspace(std::optional colorSpace) +{ + gchar *colorimetry_str = nullptr; + gchar *colorimetry_found = nullptr; + GstVideoColorimetry colorimetry; + gboolean isColorimetryValid; + + auto iterColorimetry = std::find_if(ColorSpaceTocolorimetry.begin(), ColorSpaceTocolorimetry.end(), + [&colorSpace](const auto &item) { + return colorSpace == item.first; + }); + if (iterColorimetry != ColorSpaceTocolorimetry.end()) { + colorimetry_found = (gchar *)iterColorimetry->second.c_str(); + isColorimetryValid = gst_video_colorimetry_from_string(&colorimetry, colorimetry_found); + } + if (isColorimetryValid) { + colorimetry_str = gst_video_colorimetry_to_string(&colorimetry); + return colorimetry_str; + } else { + g_free(colorimetry_found); + g_free(colorimetry_str); + return nullptr; + } +} + GstCaps * gst_libcamera_stream_formats_to_caps(const StreamFormats &formats) {