From patchwork Wed Jul 6 08:00:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 16553 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 B00D5BE173 for ; Wed, 6 Jul 2022 08:00:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 190376330C; Wed, 6 Jul 2022 10:00:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657094454; bh=lOg2e0M7Qb1Tx3gcj7aV6lPIqz8315g2G1bf1B0C+I8=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ZHuA5NTo0lR2o5uUPxgwSuiW0p8HXm7cmQgsk46VB0/2JIWNC9XwjRId1bIziP3X9 gXu/i7o4Q9Sa86k8ZpqbsLQ+9vFiqZTJwxB2VSoyMe6ZMDBZKaINolMnlFPgRc2Ood i2e4ngafGHndB+LJ9L1fk//qLEBPk2OI8/u0Jf3W4s9Wjmvj6h4ykxl9ohkmqaK9es kv3PwG5RoGoc/LTWafXzXSb7vbiHfxAyqYWYUPLrLxA4OiVWUV8SJdiFT7WLjkqZpn +QR6hGxDAQXeT79qc3PKkQthYcgBkdAGtlZmuJ8ApdrenlqJBx3rLRkSisUzq8eGis jgeSAeKzhkY4w== Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3E81060400 for ; Wed, 6 Jul 2022 10:00:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XWqZzkJJ"; dkim-atps=neutral Received: by mail-pg1-x530.google.com with SMTP id r22so6504251pgr.2 for ; Wed, 06 Jul 2022 01:00:52 -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:mime-version :content-transfer-encoding; bh=gl2s/NLrVgPI1gElVXAXpUWq298V4jDcVInQ60p73IA=; b=XWqZzkJJTaDGf9YoZ4mb3goliY+lDBXUImljgccILBG6OfTt6z/mGAf3tICtKKGpyp QNs4qcRRUFXMJImRU2rA78L4DS9E3SxSlOqIjthK0ONNxxK4Ink9Zj/KKx10IKwoFvhs JfFrb1g9qOZCfHvG6K1vKsntcoRrJcc+v7DDIvCmCmejbdoKAM8GBMzrfJzc9J4ZD7sU EtKSb83H822CfkSaAlvzjvbTKQ9V+Y1qW3N0joMHDHOquJ/MAvYL4oiZEbRq/rTG07PY +RzYERF8++F/EWup8zcgQonljZ6uhkRMkVTvj6WWEIJeYffymq/5zw7P7zbjkVaL2Rza yoLg== 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:mime-version :content-transfer-encoding; bh=gl2s/NLrVgPI1gElVXAXpUWq298V4jDcVInQ60p73IA=; b=lvZfFru2BMXeeqzM3Op1jzSijuZeIHqCarpfLGIiJ1GtTyu0vxdlWtgsfqI7AlQfEY CZWT1Qq9rhcYlxwewY6/SuSeQZZ+F5jkdvinrfec/sOCs3TUqdUi/UsBIh8vTjLCkMlN CQRxvVGNPMuEZiPmXVPbcRaW9pdw5N7/6d42yyxSldLEVJgeZRX3WDsp3hqAZ0PnaGKa 5MwzMdTBDohHAa4Qfrev3VTXswKoLzBIGHqWgNXnvhzh8iuVv/9eV5PHTSMM8tJmXpEI rA/cIiJphFnzB+6vs53XA3NQsQJBdHRj38utVYZUIqS7FkX9aLkmfgEfPbLjE+uS3ETN e1Ag== X-Gm-Message-State: AJIora8XAM//6SWJHG47qauZOOLZ5yRbcMRcezsPxYQ8YtXlEc5iUEwV zp+/ru04lZmheZcUwkhyqcltWQUI8T0= X-Google-Smtp-Source: AGRyM1vHpGaP+dXTfCsknebq4qAcYPrPI53uTJxIojl36ICLQBTSy66iQNzTvClqsP2PunzAa1xkdw== X-Received: by 2002:a63:455:0:b0:412:99f3:c9a4 with SMTP id 82-20020a630455000000b0041299f3c9a4mr1294214pge.6.1657094449188; Wed, 06 Jul 2022 01:00:49 -0700 (PDT) Received: from localhost.localdomain ([103.124.170.117]) by smtp.googlemail.com with ESMTPSA id b16-20020a170903229000b001696751796asm25013049plh.139.2022.07.06.01.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 01:00:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Jul 2022 13:30:29 +0530 Message-Id: <20220706080030.30929-1-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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. 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 --- .vscode/settings.json | 10 +++++++++ src/gstreamer/gstlibcamera-utils.cpp | 32 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..ff799f4b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "files.associations": { + "hash_map": "cpp", + "*.tcc": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "string_view": "cpp" + } +} \ No newline at end of file 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) {