From patchwork Thu Nov 18 15:19:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14631 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 3CBB5BF415 for ; Thu, 18 Nov 2021 15:20:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E2E35603C9; Thu, 18 Nov 2021 16:20:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PmhMNfpp"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C2DC6038A for ; Thu, 18 Nov 2021 16:20:30 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id b184-20020a1c1bc1000000b0033140bf8dd5so5073952wmb.5 for ; Thu, 18 Nov 2021 07:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e9vLi2M3N7esEcpYN4gESMpiB1Tm8dGAXoq3VzNR2x4=; b=PmhMNfppy2HSu2E5gW+vG7BLArB4EdsouHEIIjqw3/3uhAYnQBHhsCHNTzfO19VFQM 6auh3Zt93yIh+6xHIM3cOgKRvDhB64s1p3fTF/N8+0wKjKjQvk7JvO5S4b0pJ96V7iJS K00v5RNjnn2ao2sQhi4TS0Oyzu+YbnC9R/YGJEiVz+PpQOOX4PNtM7+cKvKpqqCSsYcH GY+2ayBhvqhY7Dc6Pl3aS9QMvYHC3hU6l30M8GpNWBXsJnM8KmaTqgTzMWkil8BzpE+u Jun9d+vVc6k++6zIiyTrGCLcFGlCJS0NpqRiXveEnIeaHpYJ9URDCCv2wnH6F5dkgKLG f9Mg== 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=e9vLi2M3N7esEcpYN4gESMpiB1Tm8dGAXoq3VzNR2x4=; b=rMSPljn639hlGD2OKMWEf63qANki2OnRh0KdCJ73LtrQMetbSX3is7KPTxAzJhSUv0 hECU8WXmjOpL3ZsV3OiGYOj3DLVpEY6UOpGf+zEYZab1YvP9K+PZWzt9hOY42xpGAEJC A4KFGcjmdxFbqX1f09WuejUkH00a/tPGo1VWB2wQMW9y3Ql70OPlCF2p7ejnLu7SfsKm J2Vn6fL/25T8tuoeskFNxGg3eajm0pDzJmrO1N6p+ExuJ+SAywgZTokTQ7cxBO8lUN6O x4eIlWGVJGPd6to1Bx63ZfQ9WCi95cxfpd6YXgBACUmasTXKc1PvEDwejMsLfok7h9aJ zjoA== X-Gm-Message-State: AOAM530OTKQqpHsG0ru9Cq7N2VGkUeJNgthn2SR1iCCJ7NEy511cltmL TTtrFVpHgZbPb9lva76b0X228g== X-Google-Smtp-Source: ABdhPJzRbAaHY/mJvm64joUeBIgYmzNLtHqd1my/s8wJO/SBKh0wG/CU0oaHySU7C8LET8LHShAZ4g== X-Received: by 2002:a1c:8015:: with SMTP id b21mr10641552wmd.161.1637248830116; Thu, 18 Nov 2021 07:20:30 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id p12sm147367wro.33.2021.11.18.07.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 07:20:29 -0800 (PST) From: David Plowman To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, hverkuil-cisco@xs4all.nl, tfiga@google.com, jacopo@jmondi.org, naush@raspberrypi.com, libcamera-devel@lists.libcamera.org Date: Thu, 18 Nov 2021 15:19:32 +0000 Message-Id: <20211118151933.15627-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211118151933.15627-1-david.plowman@raspberrypi.com> References: <20211118151933.15627-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 6/7] libcamera: Add validateColorSpaces to CameraConfiguration class 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This method forces raw streams to have the "raw" color space, and also optionally makes all output streams to share the same color space as some platforms may require this. Signed-off-by: David Plowman --- include/libcamera/camera.h | 2 ++ src/libcamera/camera.cpp | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 601ee46e..fdab4410 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -69,6 +69,8 @@ public: protected: CameraConfiguration(); + Status validateColorSpaces(bool sharedColorSpace); + std::vector config_; }; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 400a7cf0..c1541685 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -20,6 +20,7 @@ #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_controls.h" +#include "libcamera/internal/formats.h" #include "libcamera/internal/pipeline_handler.h" /** @@ -314,6 +315,56 @@ std::size_t CameraConfiguration::size() const return config_.size(); } +static bool isRaw(const PixelFormat &pixFmt) +{ + const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt); + return info.isValid() && + info.colourEncoding == PixelFormatInfo::ColourEncodingRAW; +} + +CameraConfiguration::Status CameraConfiguration::validateColorSpaces(bool sharedColorSpace) +{ + Status status = Valid; + + /* Find the largest non-raw stream (if any). */ + int index = -1; + for (unsigned int i = 0; i < config_.size(); i++) { + const StreamConfiguration &cfg = config_[i]; + if (!isRaw(cfg.pixelFormat) && (index < 0 || cfg.size > config_[i].size)) + index = i; + } + + /* + * Here we force raw streams to the correct color space. We handle + * the case where all output streams are to share a color space, + * which will match the color space of the largest (non-raw) stream. + */ + for (auto &cfg : config_) { + std::optional initialColorSpace = cfg.colorSpace; + + if (isRaw(cfg.pixelFormat)) + cfg.colorSpace = ColorSpace::Raw; + else if (sharedColorSpace) { + /* + * When all outputs share a color space, use the biggest + * output if that was set. If that was blank, but this + * stream's is not, then use this stream's color space for + * largest stream. + * (index must be != -1 if there are any non-raw streams.) + */ + if (config_[index].colorSpace) + cfg.colorSpace = config_[index].colorSpace; + else if (cfg.colorSpace) + config_[index].colorSpace = cfg.colorSpace; + } + + if (cfg.colorSpace != initialColorSpace) + status = Adjusted; + } + + return status; +} + /** * \var CameraConfiguration::transform * \brief User-specified transform to be applied to the image