From patchwork Fri Dec 16 14:33:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18035 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 5D647C328E for ; Fri, 16 Dec 2022 14:33:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE16A633A3; Fri, 16 Dec 2022 15:33:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671201229; bh=AjsZ5OBxjl+SqU7Re2waHsIwAPXf1FOEa0JjUaSIn9U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=G+idHKnW2ZQpbG+kl2rjFhtBI1LX2GdHvUOA3OV4muJWs4yZJC0KUn0zix3te6nyY xJJd4BMzgSE9g1yKpcn2tftGRAJbQuxF7jB3lbbRNqW8jVAmXzWnIXkdV6VENmZb7d lfcRBwOSFmYkJxLrRva0u2nySuty3jPCspinOn8YL3v4uSR4TIhwG6JCFalJFQU1n2 usfespGaLmVGtBEV66LzycFdnKWb7s8ncN+eLC4c8hpjjVCzKEwkFmuzIPXfzKrfn4 aw4bnGucF4SPEmwdLsd3jnchuCTqmvLY70ez7I47jZZt9NEuE18kKm6qFuzGp6SyiC 4iko8JgTSmQ3w== Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 923746339A for ; Fri, 16 Dec 2022 15:33:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="CJjEyuhf"; dkim-atps=neutral Received: by mail-ej1-x629.google.com with SMTP id b2so6567806eja.7 for ; Fri, 16 Dec 2022 06:33:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K49KIMd4v47JvPDJ6npG1gv54cNQtVc9KB/uy2SBRng=; b=CJjEyuhfC4ikK33ptAK90b9QarT9HbxsZCkGNwW/+vMavXExZURnwtFGMq0dUPzEww SKqy+K0HXY6BPAyeICBFmszt+R8+kCGBJUzggeqoqw3KLAWEycnSdi6mUTKHO43CizKH b08aY1meLxZtJe2auvd5VP5FF1M07PBF1ZktaEGq+4Tdlu3ZZuubtjGOy1l2jLV44eNw 4roDuIBEYqUwDtbq9Lnu27ARqyqTgf1Jq+8qgY4oNt6zog3Vqr2uYgUUZQMCUtBa7erl 1zLwU3m8NlPBIDUIsVMDepDvB0b5YskAV9LXb+6zZG+zKV1j0/n+t8IDvrJM5TJJrAaZ E99A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K49KIMd4v47JvPDJ6npG1gv54cNQtVc9KB/uy2SBRng=; b=7xa+V9Z/dp1AK/I9IGQbFaftq7wPQ2qqjXLB7TQN5gAuPWhNFCF16AJTwYKYjA/yFH /uXbr4otffouuk3V061j+S9l0cP2AfH6AWmYqvmTvtYW+TvX/HSfbQLiRuvSD0Qp+ax3 Oz0WoylSjfx0kZCyx2it0V11/bc5YLoAc4veD+PRVX96vU8oeAOpvX8E1BAgPlukDoeH sa6IuQzXgHI0Zai9ezHPzLWOYz47PL7XF+eVoLLRnFlYeqdP2LZBZKJQNKD/XF0/oFON vagcfPWOuwQrWbxCA+iC5Fe5nzU1VixGKwJS6IYjIQ+0eUstCq4dPkO4ua1YFrZ91uVz qmsw== X-Gm-Message-State: ANoB5pmQNxKXtiu4BzSf4dQVZTR9e2uHmezYpzlib1cpkBBKu/VYtymT DvKBzX5pavDIdEEttqAQH5sqI0X28lxt7d1B X-Google-Smtp-Source: AA0mqf4zQpnvMpC2qRAI46ZxyyN0Z8LCgMPKM/O45Eo9+szWv6U5AXBhcyXKflNIAEufCHw6vDBLRA== X-Received: by 2002:a17:906:a886:b0:7c1:8f53:83a0 with SMTP id ha6-20020a170906a88600b007c18f5383a0mr12165568ejb.13.1671201227961; Fri, 16 Dec 2022 06:33:47 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id mb4-20020a170906eb0400b0073dd8e5a39fsm907903ejb.156.2022.12.16.06.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 06:33:47 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Dec 2022 14:33:42 +0000 Message-Id: <20221216143344.8177-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221216143344.8177-1-david.plowman@raspberrypi.com> References: <20221216143344.8177-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: camera: fix validateColorSpaces to choose the correct "main" colour space 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The intention is that the "main" colour space is the colour space of the largest non-raw stream. Unfortunately the use of "config_[i].size" is clearly incorrect, and has been copied from prior versions of the code. This small change merely corrects the error. Signed-off-by: David Plowman --- src/libcamera/camera.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 2d947a44..0da167a7 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -361,6 +361,7 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF * largest non-raw stream with a defined color space (if there is one). */ std::optional colorSpace; + Size size; for (auto [i, cfg] : utils::enumerate(config_)) { if (!cfg.colorSpace) @@ -369,9 +370,10 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF if (cfg.colorSpace->adjust(cfg.pixelFormat)) status = Adjusted; - if (cfg.colorSpace != ColorSpace::Raw && - (!colorSpace || cfg.size > config_[i].size)) + if (cfg.colorSpace != ColorSpace::Raw && cfg.size > size) { colorSpace = cfg.colorSpace; + size = cfg.size; + } } if (!colorSpace || !(flags & ColorSpaceFlag::StreamsShareColorSpace)) From patchwork Fri Dec 16 14:33:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18036 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 E0F8FC3200 for ; Fri, 16 Dec 2022 14:33:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8FE06633A5; Fri, 16 Dec 2022 15:33:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671201232; bh=QhaPnfHsQyN18DFbE/ITvSBem1Qe71uKP2mAuiFWaBU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HXe+g2EhEBhnHg4ohsDbp9UiHF8V0ReMB9y2xuOcMy5xqVgLtvnR4a7scyCHAUud4 6jI7y0fBwcl/yG503VFUTswfdUlf/jsn13e5n+qV0LoEJHas4THz3IDVAikgZD8m/Q GTw5Wc1jj2oehVHVpnVaZVsvkTB8eb+vHJ6IOrTko7RkMkzOV1dcq3etiEs/AoQh6j KgF48Cs3egST16HLkSjGUJMsoXIKEgIehvbTSTmrd97esPGmxXI0OfofunaF1uQG5V 3OSBix5pDy30o73xqaT5ktF1MYCB6+EilN3CAW9sdbZvj04iA1SLLMLZaAFJ3eHgqq nAFCnM66kG0wg== Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 529146339A for ; Fri, 16 Dec 2022 15:33:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="QBhq41tw"; dkim-atps=neutral Received: by mail-ej1-x632.google.com with SMTP id t17so6643456eju.1 for ; Fri, 16 Dec 2022 06:33:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wm7vFBxaO4oAVnSNjseltZOQRGnDDL5NMbu478QBPD8=; b=QBhq41twK/6MFRYMUOnquBBy+QRC24XZKMqj0iYGikD/1La7zjoeAOVfhE7Hfm7K+8 TFX8Zl0IKOOSrsghDYI2/jUDbKmDQjd85Vssiim+OgACu/oCaVjD/9JMyu4ZzhgV2+iu 1Lx3wW6depF6cP3gwdgpKh7hVhvt6k2HA+ryjuoDwisTM5YWHi6XsdZbVTdwzs67I1CM R2EpQwPa+9Xu58hoyeN3FwXcbiUKrxT2VIC088LmK/hPH0Cjo83qdOVhI1sj1zTELnAH 2/JkgRk37Xf+pEadIAuhok1RPxG/VoNcZDBnMtuCVKCj0pi5ez1abIUDhkybZCYTW/8o Q4vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wm7vFBxaO4oAVnSNjseltZOQRGnDDL5NMbu478QBPD8=; b=iBYakKgbw2erEQTDZqjXPueN4RLgCKP1DOEZRncSzKb+gzcN0z+ZkBic4uwbm79IJY 2U4zJYzFrU98/wlw01+zDwXh/67lbo6VOE3QSTn9zaGII3FiGbBsCeiPWe9UUmbR1s9r 5GY+JOc/XNSGcFEPBhhGyfSenzZylPNk3ZzJMQxQBWajHhd56x27E3y5KNk+Fcvru5Yz ZeQ5sZepmgVQrjDsfVikemDIDwf3SMB303MZQ27/w6/sDNH0Uv7RRmsbWBQdizRBeTyY +B33cDdb1qaeVX9wmVGxNef0x1nAk3VR1D3Npe4KVOiQByeYebCWP9wkfSizmFD5GI7V R+pw== X-Gm-Message-State: ANoB5pkrKlQniNch2Lwf50/Sj/x8F3T4Y/uAJIKjJGrn0RlB1e65C7Fg QIhSNfp2g9XZB6T/rOZnQSIFKoZbSk5s1eRB X-Google-Smtp-Source: AA0mqf5W6TXdB9uezE/rb1smyDsDP8DBUsuMX6v+PwKHvzI9q7CAuft4KknnHEOR88HTEFJJUwXueg== X-Received: by 2002:a17:906:a852:b0:7c0:e0d8:9500 with SMTP id dx18-20020a170906a85200b007c0e0d89500mr26884793ejb.75.1671201228669; Fri, 16 Dec 2022 06:33:48 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id mb4-20020a170906eb0400b0073dd8e5a39fsm907903ejb.156.2022.12.16.06.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 06:33:48 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Dec 2022 14:33:43 +0000 Message-Id: <20221216143344.8177-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221216143344.8177-1-david.plowman@raspberrypi.com> References: <20221216143344.8177-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: camera: Fix validateColorSpaces not to loose YCbCr encodings 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When sharing the same colour spaces across streams, the "main" stream might be an RGB stream so we must stop its YCbCr information (encoding and range) from overwriting other YUV streams. Instead we also make a note of the largest stream with YCbCr information. We take the primaries and transfer function from the original "main" stream, but the YCbCr encoding and range from this second stream. Signed-off-by: David Plowman --- src/libcamera/camera.cpp | 47 +++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 0da167a7..e0a5d03d 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -358,10 +358,13 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF /* * Set all raw streams to the Raw color space, and make a note of the - * largest non-raw stream with a defined color space (if there is one). + * largest non-raw stream with a defined color space (if there is one), and + * also the largest stream with YCbCr encoding information. */ std::optional colorSpace; + std::optional ycbcrColorSpace; Size size; + Size ycbcrSize; for (auto [i, cfg] : utils::enumerate(config_)) { if (!cfg.colorSpace) @@ -370,22 +373,56 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF if (cfg.colorSpace->adjust(cfg.pixelFormat)) status = Adjusted; - if (cfg.colorSpace != ColorSpace::Raw && cfg.size > size) { + if (cfg.colorSpace == ColorSpace::Raw) + continue; + + if (cfg.size > size) { colorSpace = cfg.colorSpace; size = cfg.size; } + + if (cfg.colorSpace->ycbcrEncoding != ColorSpace::YcbcrEncoding::None && + cfg.size > ycbcrSize) { + ycbcrColorSpace = cfg.colorSpace; + ycbcrSize = cfg.size; + } } if (!colorSpace || !(flags & ColorSpaceFlag::StreamsShareColorSpace)) return status; - /* Make all output color spaces the same, if requested. */ + /* + * Make all output color spaces the same, if requested. Note that when sharing like + * this, we copy the primaries and transfer function from the principal stream + * (the variable "colorSpace") but we mustn't use its ycbcrEncoding or range because + * it may be an RGB stream. So we take these fields instead from the "ycbcrColorSpace". + */ for (auto &cfg : config_) { - if (cfg.colorSpace != ColorSpace::Raw && - cfg.colorSpace != colorSpace) { + if (!cfg.colorSpace) { cfg.colorSpace = colorSpace; status = Adjusted; } + + if (cfg.colorSpace == ColorSpace::Raw) + continue; + + /* Ensure the primaries and transferFunction match the "main" stream. */ + if (cfg.colorSpace->primaries != colorSpace->primaries || + cfg.colorSpace->transferFunction != colorSpace->transferFunction) { + cfg.colorSpace->primaries = colorSpace->primaries; + cfg.colorSpace->transferFunction = colorSpace->transferFunction; + status = Adjusted; + } + + if (cfg.colorSpace->ycbcrEncoding != ColorSpace::YcbcrEncoding::None) { + /* Set these from the ycbcrColorSpace (which we note must exist). */ + if (ycbcrColorSpace->ycbcrEncoding != cfg.colorSpace->ycbcrEncoding || + ycbcrColorSpace->range != cfg.colorSpace->range) { + cfg.colorSpace->ycbcrEncoding = ycbcrColorSpace->ycbcrEncoding; + cfg.colorSpace->range = ycbcrColorSpace->range; + status = Adjusted; + } + } } return status; From patchwork Fri Dec 16 14:33:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18037 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 7E57BC3200 for ; Fri, 16 Dec 2022 14:33:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 39A656339A; Fri, 16 Dec 2022 15:33:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671201234; bh=eV5HFJXm9Z1pBsbWQBHCKYlzvJ3p+++ZrVJAkvfDmMM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bwDHj70P89Zm21XseWXsIkxsCOF8M0cpsI5CaZ6I1Jgpsdun4bYF2u8QmFPPYZLjN lP19lyuFcSYCQA/J9NzYuKqZfVyN08WLgQ5/d+7VcuLoO99UKKCyKTmq35694jh5dR ljrd2/XZrely19FL66yw++fc5ogZBlwPk4Yd8scA9lQ2Hj1kXh7xdvcxePlDvnYUqS x55Qk5VFj2EqP/A0Atxd8w7tEx4Xu7lITZM8IMwtrRdqRFtUv8eu5R9lx4OL35o1Pl 9qKUBDIC4S3R++Aw4Oxd2g2TvBlmy8g3hY7LC+aTZTPlQ1TZh27ogOkfouU4u9QPat baHje6mwFLZtw== Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BFE96339E for ; Fri, 16 Dec 2022 15:33:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pY90ILlO"; dkim-atps=neutral Received: by mail-ej1-x62f.google.com with SMTP id ud5so6616293ejc.4 for ; Fri, 16 Dec 2022 06:33:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r9aZV0AFWGsOMolbu6TRUsUyPIXMvru1Qfz14ROxvqE=; b=pY90ILlOIsGu9SXLESXbX2ysfwfTV3+WAlVwAMUlyPzhEz8QGlU8yIpvbTVyvhKSSj vIWMspRtVxCfc+st1UZCkwbFWmZXqXfPnprOLdE6fBvQdO0FLfRpzR6UfeDw5Mr5+Hw/ brqJeNRS3qCYpeAB8CYngCE9ZGZsd3x6fGJwo2RirjGCCu60DYLiKSrEaMVL4ui02DG6 +P4CWuCwT5cZHSC4IcY/SxidNqKB7NqLfd1MtUba/XvNrjgYZ4rFTkVvxKARw4kbHKce 06I602GwXqDpsU7p0LW3r3tuLDBYqsUU5eRkY7+Yded3IGYzDwJPm3f66uK+sb3CFwdO w0BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r9aZV0AFWGsOMolbu6TRUsUyPIXMvru1Qfz14ROxvqE=; b=DHUDVJCah1O1K4JvbjqftvEg9/FWTwBLqD7sxVOEdStpgMufAM41zheTpkABRk+vlC DMrGucyhGBlY/oCOnX8UGPdii2Z87T/Qos+r7tEA9t80IByjJ18IxgL+ESDgo2QfMC3C IoWsUt7dWq3EDAubNQsW5hg6SNKn6fhYVCQThQlIx4tbcYakWYAiPykwSm4kIU2SvY2A Koa+SKzWp5h5p1rnjYueGZoe1GG38r00kWaY4gWDGDyh9YU3jPoeRy5oigzQIvvKpUFL 6a9Ig4grn1goqstvOemq/1/x1VmpKrYZa0ljO5mnX0uBO0+SlkxqPgO9ZhzhrE5B9V9h Aevw== X-Gm-Message-State: ANoB5plcVXOuMGABer0cBKvskcYSw1yuqppdaKFXrAbQGGPZE4y2RmsL zLuk5jOcm7opu3tjIqn4b47HdNWc0CWEpmE5 X-Google-Smtp-Source: AA0mqf731Uq25b8P7xlNj4NDIiWE32/ANCnqC2xJVLchA9+6HYv6jmG6jl4tlQFNm/ABo6ErGk/pHg== X-Received: by 2002:a17:906:4a9a:b0:7c1:2529:2760 with SMTP id x26-20020a1709064a9a00b007c125292760mr26778538eju.27.1671201229354; Fri, 16 Dec 2022 06:33:49 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id mb4-20020a170906eb0400b0073dd8e5a39fsm907903ejb.156.2022.12.16.06.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 06:33:49 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Dec 2022 14:33:44 +0000 Message-Id: <20221216143344.8177-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221216143344.8177-1-david.plowman@raspberrypi.com> References: <20221216143344.8177-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Fix colour spaces by handling missing YCbCr information 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In this patch we fix up colour spaces by adding the YCbCr information that is now not present for streams with an RGB output format. We need this information so that colour spaces are translated into the V4L2 ones that the Raspberry Pi hardware drivers will interpret correctly. Related to this, the YCbCr information is once again removed before the actual colour space is returned to us, so we have to be more careful about how we check that we got what we expected. Signed-off-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 8569df17..f2d10d2a 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -357,6 +357,39 @@ RPiCameraConfiguration::RPiCameraConfiguration(const RPiCameraData *data) { } +static const std::vector validColorSpaces = { + ColorSpace::Sycc, + ColorSpace::Smpte170m, + ColorSpace::Rec709 +}; + +static std::optional fixColorSpace(const std::optional &colorSpace, + CameraConfiguration::Status &status) +{ + if (!colorSpace) + return std::nullopt; + + /* + * We prefer to restore any YCbCr encoding and range information that may have been + * removed from RGB streams. This ensures the colour spaces will be converted correctly + * into the colour spaces that the drivers handle, namely V4L2_COLORSPACE_JPEG, + * V4L2_COLORSPACE_SMPTE170M and V4L2_COLORSPACE_REC709. + * + * Luckily, the primaries and transfer function are enough for us to deduce exactly which + * ColorSpace was originally intended. + */ + for (const auto &cs : validColorSpaces) { + if (colorSpace->primaries == cs.primaries && + colorSpace->transferFunction == cs.transferFunction) + return cs; + } + + /* If nothing was matched, ask for sYCC. */ + LOG(RPI, Debug) << "No match for colour space " << colorSpace->toString(); + status = CameraConfiguration::Adjusted; + return ColorSpace::Sycc; +} + CameraConfiguration::Status RPiCameraConfiguration::validate() { Status status = Valid; @@ -533,7 +566,26 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() V4L2DeviceFormat format; format.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); format.size = cfg.size; - format.colorSpace = cfg.colorSpace; + /* + * Make sure the colour space is the one we want converted for our drivers, with + * the YCbCr information restored. status will be set to Adjusted if we didn't + * like the input colour space. + */ + format.colorSpace = fixColorSpace(cfg.colorSpace, status); + + /* + * When it comes back, RGB streams will have had the YCbCr information + * overwritten again, so let's figure out what we really expect to be + * returned. + */ + auto checkColorSpace = format.colorSpace; + if (checkColorSpace) { + const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRGB) { + checkColorSpace->ycbcrEncoding = ColorSpace::YcbcrEncoding::None; + checkColorSpace->range = ColorSpace::Range::Full; + } + } LOG(RPI, Debug) << "Try color space " << ColorSpace::toString(cfg.colorSpace); @@ -542,7 +594,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() if (ret) return Invalid; - if (cfg.colorSpace != format.colorSpace) { + if (checkColorSpace != format.colorSpace) { status = Adjusted; LOG(RPI, Debug) << "Color space changed from "