From patchwork Mon Dec 6 10:50:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15048 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 BC887BDB13 for ; Mon, 6 Dec 2021 10:51:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 64AD560872; Mon, 6 Dec 2021 11:51:31 +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="QvfVYvKD"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96C2760882 for ; Mon, 6 Dec 2021 11:51:25 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id az34-20020a05600c602200b0033bf8662572so7328657wmb.0 for ; Mon, 06 Dec 2021 02:51:25 -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=tv3O2cAwn+Kn6H1MBehwoCfF/wdQzrC35hxIG5RHyWI=; b=QvfVYvKD7oPnr4rLWDite3Xu2xnCv67rZV0E3i8R1CIRnjtfSzB2FbXnRiYPQW803n TIVGlDv8h9TBFruetqQDxgx7LwUyMpEsfxh4dnsMDBNqpbFirCt1jWcTm678v7TpHoPw ex07iUGlFSybpP+0R9KkHwP/pUopLMXcfkcr0iiZ93qq74MRTwRevk8TW1CPJkgh5x6Z rKK4LwtKYgy6wWkn9THhyBX3Tohb16vvSD5tHYY+MG18fnqKA7MbjRLJnvsYqI/Lj4iz KaK1E5Od7lTqa0p/r6zR7fLP0vjsndqCirh/mW/fIDpTX/WmygmiNEGXjbLb6yGgQZOm N7uA== 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=tv3O2cAwn+Kn6H1MBehwoCfF/wdQzrC35hxIG5RHyWI=; b=NvlDk21y/0KeONqikbaKF8kYJTvH6UyNJuo2SYLPw8Fvr2FNKHapOMGKVbqMJRSty2 72VwNWdtIWJFrN9DphLDogpyToNUxYL9kr40Q1Fzg/uGoM+wxFS8qtGx0UEmYtsJa1Kh 7F38RwD73VVkEacwJIhQalIT551vIIvxA4Lx9zmJI77UFc3aM3ZJXaC2OGvq1LbnbVt4 MyR84E1CV4ZPl+P9hWFfLzoPxzC2UpUp7NNndmkMS3KsBkggqtEMmrFsvCJClyy3ZUrd i9lrkrjojbvDmy8pTlBMloGtUKo+oOqlCkVH2c+VfbHEwi0gvX3zgdujxIUty3nuvfQs X/PA== X-Gm-Message-State: AOAM533IS/ynXsWg6Pm+EdHLbSk1kUxBpXnsn6MB3zCpt2SxkhB08Rw+ RV9s/j1h7YqYDkFKuDv20D1rKcR/3p1P4nh+ X-Google-Smtp-Source: ABdhPJyT89CBV3D6FitkSCS9gqNX/NlMSgadA9P9qpGfVWlqqOcExiMYkIHVBtKVEJpJtYfJz9j5Rw== X-Received: by 2002:a05:600c:350a:: with SMTP id h10mr22752368wmq.62.1638787885135; Mon, 06 Dec 2021 02:51:25 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id r7sm10878186wrq.29.2021.12.06.02.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 02:51:24 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org, naush@raspberrypi.com, jacopo@jmondi.org, tfiga@google.com, hverkuil-cisco@xs4all.nl, kieran.bingham@ideasonboard.com, laurent.pinchart@ideasonboard.com Date: Mon, 6 Dec 2021 10:50:30 +0000 Message-Id: <20211206105032.13876-8-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211206105032.13876-1-david.plowman@raspberrypi.com> References: <20211206105032.13876-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 7/8] 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 Reviewed-by: Jacopo Mondi --- include/libcamera/camera.h | 2 ++ src/libcamera/camera.cpp | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index a7759ccb..fdcb66ab 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -69,6 +69,8 @@ public: protected: CameraConfiguration(); + Status validateColorSpaces(bool shareOutputColorSpaces); + std::vector config_; }; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 400a7cf0..388af4f7 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -14,12 +14,14 @@ #include #include +#include #include #include #include #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_controls.h" +#include "libcamera/internal/formats.h" #include "libcamera/internal/pipeline_handler.h" /** @@ -314,6 +316,63 @@ 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; +} + +/** + * \brief Check and update the color spaces requested for each stream + * \param[in] shareOutputColorSpaces Force all non-raw output streams to share + * the same color space + * + * This function performs certain consistency checks on the color spaces of + * the streams and may adjust them so that: + * + * - Any raw streams have the Raw color space + * - If shareOutputColorSpaces is set, all output streams are forced to share + * the same color space (this may be a constraint on some platforms). + * + * It is optional for a pipeline handler to use this method. + * + * \return A CameraConfiguration::Status value that describes the validation + * status (same as CameraConfiguration::validate). + */ +CameraConfiguration::Status CameraConfiguration::validateColorSpaces(bool shareOutputColorSpaces) +{ + Status status = Valid; + + /* + * 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). + */ + int index = -1; + for (auto [i, cfg] : utils::enumerate(config_)) { + if (isRaw(cfg.pixelFormat) && cfg.colorSpace != ColorSpace::Raw) { + cfg.colorSpace = ColorSpace::Raw; + status = Adjusted; + } + else if (cfg.colorSpace && (index == -1 || cfg.size > config_[i].size)) + index = i; + } + + if (index < 0 || !shareOutputColorSpaces) + return status; + + /* Make all output color spaces the same, if requested. */ + for (auto &cfg : config_) { + if (!isRaw(cfg.pixelFormat) && + cfg.colorSpace != config_[index].colorSpace) { + cfg.colorSpace = config_[index].colorSpace; + status = Adjusted; + } + } + + return status; +} + /** * \var CameraConfiguration::transform * \brief User-specified transform to be applied to the image