From patchwork Sun Jul 3 07:33:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 16524 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 D5D1EBE173 for ; Sun, 3 Jul 2022 07:34:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E16A6564E; Sun, 3 Jul 2022 09:34:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656833651; bh=1be0cULGX9WjRXUnQ3WYCT+hSTxYbW0VRIrm7vonzRc=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qIHRi/9q56SahZfMnG9HDPZ+1ipLCKPa4vpy2j5vLTPDeJ18Ta/x3IUmDD9AOgwqi JOA90GAF/kJXTVEH51ZhBpTdQrkUiiStQC+kaspz14BbetHDawMHvBrKIMOiihBWTi qkwh9Yvp5Kh3ef8pQ129/PbdXOHb/+gN8VwNRz0quFi7rhXHeso/MjDLxc/LywEmDe le3uVgguzABGcoQm8gRiYuvF1I/bjKcEXh9lJnf+RrvAhhKgNBrbVL+aAQY9SU50iX 3lMtAhamfrXL9QKdsb6Oci+osmyZNQCuvOq5vSvCYIcugMhZzA5zXh4yDgVYQy5ZZe iVWJCVgTy6tNw== Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E5B561FB0 for ; Sun, 3 Jul 2022 09:34:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mqXWRA/w"; dkim-atps=neutral Received: by mail-pj1-x1033.google.com with SMTP id j1-20020a17090aeb0100b001ef777a7befso1308171pjz.0 for ; Sun, 03 Jul 2022 00:34:10 -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=cvCl0z382EYdkVPSkS58OKglurMkpOPZlcquWibtLi8=; b=mqXWRA/wfvwac8bzFe20xC8z1RPZ+TvpXL3ErGo3zqAufpXvIi0UKk/Jbc15GmevEm MCpdM5K8mDNjSMAX5+f+TmldQaj/ycCJJyyis1NHWZ9LNdTdoPFQMBp1ExCCcbzv3HKD NVkD3QnSwzssmfAirQ0kzhfGYwIhQQJY1BORI7J0KCSYOtECMRlTfn4l3eg+M3pjqXgH nxcA8efOjWMnNOshBSFqPo10FbB0rEbwdJJutRn7abpZ38ZQ9dBfbtd2007UxXF6rjtz Cg5nR6VKpY7tCELoXZZrUrQzuFlpHpECzIyyO62BZglNJHCb4lyN3o7aE57eYCXSSL23 kofA== 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=cvCl0z382EYdkVPSkS58OKglurMkpOPZlcquWibtLi8=; b=QQDU1KrVFi4NcyLmuZdEGZamhuw2nVd/alS+Dj13bwFG2HNeE2lLrJFMwlGa4LCsZy DpKNaw9qcolHgmsM59MYx4xH8rC36o+Ikfw7oUnazUu53q3NAOt/YSyo+G2D7O3ErzyR vk/8Vqit4Mfako2LAkKzriDJyaiVkqopsVZ4Cw0yWFT0lPop8/IdfRHA6X1kiTy+Vd9u ZYQz4He790+im65bLz0E1AjkkJ3RPGkqWQOV2eMHBlRjLc2fi9U5YJhURSn6bLtCE9Qe Vyno/nqGWSVVPayvrw1dBVD8j95BkQqjJdBBum0Du8KqoZftIFAgIqpLG0RJaFUMrlIE VFHw== X-Gm-Message-State: AJIora8Jtm/+twsfWExU/ohS22e80skCd7sI502AynUKAJkCX+rOAeyy XjHlOn6zNK++gWYy7dj72A4ypJpJsDU1YbYt X-Google-Smtp-Source: AGRyM1u0Ig2PP8/NdwgzMHfiDKlGNNwC2DLJcjcbJYN1Ib+07UHAJoKkNRZtarK3OAOb4GXsa1WMZw== X-Received: by 2002:a17:902:7d86:b0:16a:53f:4d36 with SMTP id a6-20020a1709027d8600b0016a053f4d36mr29125219plm.34.1656833648516; Sun, 03 Jul 2022 00:34:08 -0700 (PDT) Received: from localhost.localdomain ([2402:8100:30af:f358:3ebf:ad3f:f834:3344]) by smtp.googlemail.com with ESMTPSA id l11-20020a170903120b00b0016b953872a7sm10300285plh.201.2022.07.03.00.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 00:34:08 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 3 Jul 2022 13:03:54 +0530 Message-Id: <20220703073358.76643-1-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/5] gstreamer: Convert form colorspace to 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 between the libcamera colorspace and GStreamer colorimetry and find the closest colorimetry corresponding to the colorspace in stream configuration. Signed-off-by: Rishikesh Donadkar --- 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 3f242286..20c39919 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -45,6 +45,34 @@ 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 const std::map ToGstVideoColorPrimaries = { + { ColorSpace::Primaries::Smpte170m, GST_VIDEO_COLOR_PRIMARIES_SMPTE170M }, + { ColorSpace::Primaries::Rec709, GST_VIDEO_COLOR_PRIMARIES_BT709 }, + { ColorSpace::Primaries::Rec2020, GST_VIDEO_COLOR_PRIMARIES_BT2020 }, +}; + +static const std::map ToGstVideoTransferFunction = { + { ColorSpace::TransferFunction::Srgb, GST_VIDEO_TRANSFER_SRGB }, + { ColorSpace::TransferFunction::Rec709, GST_VIDEO_TRANSFER_BT709 }, +}; + +static const std::map ToGstVideoColorMatrix = { + { ColorSpace::YcbcrEncoding::Rec601, GST_VIDEO_COLOR_MATRIX_BT601 }, + { ColorSpace::YcbcrEncoding::Rec709, GST_VIDEO_COLOR_MATRIX_BT709 }, + { ColorSpace::YcbcrEncoding::Rec2020, GST_VIDEO_COLOR_MATRIX_BT2020 }, +}; + +static const std::map ToGstVideoColorRange = { + { ColorSpace::Range::Full, GST_VIDEO_COLOR_RANGE_0_255 }, + { ColorSpace::Range::Limited, GST_VIDEO_COLOR_RANGE_16_235 }, +}; + static GstVideoFormat pixel_format_to_gst_format(const PixelFormat &format) { @@ -87,6 +115,49 @@ bare_structure_from_format(const PixelFormat &format) } } +static const gchar * +colorimerty_from_colorspace(std::optional colorSpace) +{ + const gchar *colorimetry_str; + GstVideoColorimetry colorimetry; + + auto iterColorimetry = std::find_if(ColorSpaceTocolorimetry.begin(), ColorSpaceTocolorimetry.end(), + [&colorSpace](const auto &item) { + return colorSpace == item.first; + }); + if (iterColorimetry != ColorSpaceTocolorimetry.end()) { + colorimetry_str = (gchar *)iterColorimetry->second.c_str(); + return colorimetry_str; + } + + auto iterPrimaries = ToGstVideoColorPrimaries.find(colorSpace->primaries); + if (iterPrimaries != ToGstVideoColorPrimaries.end()) + colorimetry.primaries = iterPrimaries->second; + else + colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN; + + auto iterTransferFunction = ToGstVideoTransferFunction.find(colorSpace->transferFunction); + if (iterTransferFunction != ToGstVideoTransferFunction.end()) + colorimetry.transfer = iterTransferFunction->second; + else + colorimetry.transfer = GST_VIDEO_TRANSFER_UNKNOWN; + + auto iterYcbcrEncoding = ToGstVideoColorMatrix.find(colorSpace->ycbcrEncoding); + if (iterYcbcrEncoding != ToGstVideoColorMatrix.end()) + colorimetry.matrix = iterYcbcrEncoding->second; + else + colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN; + + auto iterRange = ToGstVideoColorRange.find(colorSpace->range); + if (iterRange != ToGstVideoColorRange.end()) + colorimetry.range = iterRange->second; + else + colorimetry.range = GST_VIDEO_COLOR_RANGE_UNKNOWN; + + colorimetry_str = gst_video_colorimetry_to_string(&colorimetry); + return colorimetry_str; +} + GstCaps * gst_libcamera_stream_formats_to_caps(const StreamFormats &formats) {