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) { From patchwork Wed Jul 6 08:00: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: 16554 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 C789FBE173 for ; Wed, 6 Jul 2022 08:01:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 93B9363313; Wed, 6 Jul 2022 10:01:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657094470; bh=urL573M7ZJB65es0bfiX8bMi9EWtxAR4MosajrRkJg0=; 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=3fH+bwpFXGwoHxw+lW9OKGlM9oHyJg45C6y1sy/JDkCD03kQwbHfR0KoRDtoASAoU opCYFeLp0c0xso1VQMe5/DNRYGPpmVy5fkZVhcvZJEyIXjW/aMzpwWtph3w7Nbjs4P pIg3fOK656Q6T7cOJ8AJQCcBBszNn9b7lvV/dpkU/hKkVis7Hv6qyJZ79826ti/YZV uiJRUYrcKemubw0oBxkkI/vZ3fI+/BHLqIIdpWNKxzEefbd54hga5gaNqbrN00nFP1 FH3kHbZ2e3tYxcuHlURL3sWIdgnkRPzde238x5Mp+S+Ocwy3HjN4mKDXQCDTN0mwVJ 9avi+2uZ3KDDA== Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A75A60400 for ; Wed, 6 Jul 2022 10:01:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Wc/bHTPu"; dkim-atps=neutral Received: by mail-pg1-x52b.google.com with SMTP id bf13so357657pgb.11 for ; Wed, 06 Jul 2022 01:01:09 -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=OGXpw4fZPKOP+bWSilv5kaumz+JHKfmnJqHFwEvTFys=; b=Wc/bHTPuTRS4mLtBB/4ON9OwaZ/7q/yWMWO35dmuPGmbe1N3bnaBVBjkKvrzPoJ5x3 Fha3tfW8n/dOGbI1LGadVCs0rUS9c6VGbMdDRdD0ya0hLz6pNncu0p6Ex94L/Hv+UZrn rG8erzf8cjbdzFuJ9WAKBwtlWGpwkeTygCZCn7gR3P3yiCsEVyonNiTFG5n5S6IXKVwt d2c6T2Y839tIA8vzvMiLGyHGEQ9JOE1AUvG1akXb2HdS+LpfQq0Tj3eTOtTDX+eY5zgd QKsDrgO/g1bTAU/VQNGmE5wsnc9AWRQ/WwGHgdXGTBnzVlojPmGtnxVRrG9j345GReJi datQ== 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=OGXpw4fZPKOP+bWSilv5kaumz+JHKfmnJqHFwEvTFys=; b=Tqz5+WZXnCtKUzw/ghykZfBx5cOlXM2XJ4Yz0d98fT/YL2m2N6sqZFWvnpfBkwWxNP pnL5dMOZlaicXRMRDf4dinNtx1XlwL/Vh6nhBS+bbp9JMMAI7m4zQrKyZSfte/wrKg4p EM/B5DJPqJofVdmSqL8z6MtKrn8n8lTWOVWxKAkzLE4kdAEbJk6FkvGfqhg8phWSH5uh hsMb3d7QpDoh2GXDqnbpoyiuovpQYTAVhHiGXzEQmt0lFCHmaPjxm7FCM6k0s/vrcZHL monfMNLDYFyQHN93/IFkgFPBqe+GJvLwT6POas4xt5DyiihvBSL4p8hrjOZD1jL58DUn y5pA== X-Gm-Message-State: AJIora8ESoT3yT0SSZqoYeCcvya8/A3w/TwWTUa86fAcKvFIsNHbrVFD hxPquQCwEdW3oS0NoFvN9STK2Hh1s7Y= X-Google-Smtp-Source: AGRyM1v6goG8wCq1TDXoBSfdg3gcwPIO4jVkmFYvSw4JUEkCMlauibo037PwHYKixHM7eJPgMQHJUw== X-Received: by 2002:a63:f256:0:b0:40d:5509:2126 with SMTP id d22-20020a63f256000000b0040d55092126mr32435147pgk.566.1657094467631; Wed, 06 Jul 2022 01:01:07 -0700 (PDT) Received: from localhost.localdomain ([103.124.170.117]) by smtp.googlemail.com with ESMTPSA id b16-20020a170903229000b001696751796asm25013049plh.139.2022.07.06.01.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 01:01:07 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Jul 2022 13:30:30 +0530 Message-Id: <20220706080030.30929-2-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706080030.30929-1-rishikeshdonadkar@gmail.com> References: <20220706080030.30929-1-rishikeshdonadkar@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/5] gstreamer: Update the obtained colorimetry in caps. 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" If the colorspace is set in the StreamConfiguration, get the colorimetry as a result of conversion from the previous patch and update it into the caps. Signed-off-by: Rishikesh Donadkar --- src/gstreamer/gstlibcamera-utils.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index 60ac8c8e..c155dd0c 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -166,11 +166,23 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg { GstCaps *caps = gst_caps_new_empty(); GstStructure *s = bare_structure_from_format(stream_cfg.pixelFormat); + gchar *colorimetry = nullptr; + std::optional colorspace = stream_cfg.colorSpace; gst_structure_set(s, "width", G_TYPE_INT, stream_cfg.size.width, "height", G_TYPE_INT, stream_cfg.size.height, nullptr); + + if (colorspace) { + colorimetry = colorimerty_from_colorspace(colorspace); + if (colorimetry) + gst_structure_set(s, + "colorimetry", G_TYPE_STRING, colorimetry, nullptr); + } else { + g_free(colorimetry); + } + gst_caps_append_structure(caps, s); return caps;