From patchwork Thu Dec 9 10:12:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15097 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 8886DC324B for ; Thu, 9 Dec 2021 10:13:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E7EB6088B; Thu, 9 Dec 2021 11:13:41 +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="PmevTKvg"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73FE36086A for ; Thu, 9 Dec 2021 11:13:36 +0100 (CET) Received: by mail-wm1-x330.google.com with SMTP id o19-20020a1c7513000000b0033a93202467so3661628wmc.2 for ; Thu, 09 Dec 2021 02:13:36 -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=R1YEICgfdgsmW9t4ujB9VSgCIG1ak5d76cb+q5rcH2M=; b=PmevTKvgqticNKUuX1s7g3oqZtnlnX1X0H5nFvPg3jJg3TAORQErKCQyKk0z0YYibV NChP36fJhQ6AK6avwaOFBE0F+18Nrj2S9GNz3egr4FXabi6qwTX8mtjBLcM8ZoWJnQZi Uq1va0qjq08bvzkzZ2HiCnuZc+uU06+X3mXP1rBj20cI1DlwEAT3oTl0160mT15yUfo0 rk21DBIEF7IXMpluLrKFSYAMIsK2CC0yzMPeNjH56S6gxZkvo01GZ/0pKQBgqwff8rjW DMKzELNLBwlnBcnNapJ5TNXCGnP2ZNyNvlHoJWF4avAW0ohc0aPjXSvnl+6A1hzTjRKL 615w== 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=R1YEICgfdgsmW9t4ujB9VSgCIG1ak5d76cb+q5rcH2M=; b=OoEfORGJosNmnnSJEIu580h9R9Sc0D9PcpGiwK2q5YdwJWbZe/EGwkqA1EXzWFWWGb Y35snhH1ytXL6Flgywqo26UAXr8vJkgh/qy2r1S5jZD1ZpTpF/2ih7Ut2G/feToDqqmp /PPz6MGrM2FIQQCLKKWXdEnHWhBNvRlTHEGQvgZyPUvEhCg3H3mGZroZuuJ+0wlrsZ8l Cq2n9BdlF73o4nLq5QmRfG2iciZcGyTyhIDrDG27qAGpeuH5rRWtXBofflzbyNYZ2tLx nSFVOgVUHWPFNSa/o6g/w+pA/DmvWZotEKblU+bktGHhq83RPn2mx2RVSOqUksYLj+qb G7+g== X-Gm-Message-State: AOAM533tv0eqit+MoHHG+8bIPo3oAzb1+ORYZbAFuT9850tMY0I1lLUu NLpe7tQAsKRq9baj0buJBQE8Fo0dYjlgBSPT X-Google-Smtp-Source: ABdhPJxmgj8JfyawN5UJsPeaYUXA7Qfrw0KrMHONTsJ88pr1+fNMQ1k3bf0r+NDzCZ52XbiLp3puiw== X-Received: by 2002:a1c:208b:: with SMTP id g133mr6002527wmg.128.1639044815908; Thu, 09 Dec 2021 02:13:35 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id j8sm5079449wrh.16.2021.12.09.02.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 02:13:35 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org, Laurent Pinchart , Kieran Bingham , Hans Verkuil , Tomasz Figa , Jacopo Mondi , Naushir Patuck Date: Thu, 9 Dec 2021 10:12:44 +0000 Message-Id: <20211209101245.6187-8-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211209101245.6187-1-david.plowman@raspberrypi.com> References: <20211209101245.6187-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 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 --- include/libcamera/camera.h | 10 +++++ src/libcamera/camera.cpp | 84 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index a7759ccb..5bb06584 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -69,6 +70,15 @@ public: protected: CameraConfiguration(); + enum class ColorSpaceFlag { + None, + StreamsShareColorSpace, + }; + + using ColorSpaceFlags = Flags; + + Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None); + std::vector config_; }; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 400a7cf0..87ef8d72 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,88 @@ std::size_t CameraConfiguration::size() const return config_.size(); } +namespace { + +bool isRaw(const PixelFormat &pixFmt) +{ + const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt); + return info.isValid() && + info.colourEncoding == PixelFormatInfo::ColourEncodingRAW; +} + +} /* namespace */ + +/** + * \enum CameraConfiguration::ColorSpaceFlag + * \brief Specify the behaviour of validateColorSpaces + * \var ColorSpaceFlag::None + * \brief No extra validation of color spaces is required + * \var ColorSpaceFlag::StreamsShareColorSpace + * \brief Non-raw output streams must share the same color space + */ + +/** + * \typedef CameraConfiguration::ColorSpaceFlags + * \brief A bitwise combination of ColorSpaceFlag values + */ + +/** + * \brief Check the color spaces requested for each stream + * \param[in] flags Flags to control the behaviour of this function + * + * 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. + * \retval CameraConfiguration::Invalid The configuration is invalid and can't + * be adjusted. This may only occur in extreme cases such as when the + * configuration is empty. + * \retval CameraConfigutation::Adjusted The configuration has been adjusted + * and is now valid. Parameters may have changed for any stream, and stream + * configurations may have been removed. The caller shall check the + * configuration carefully. + * \retval CameraConfiguration::Valid The configuration was already valid and + * hasn't been adjusted. + */ +CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceFlags flags) +{ + 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 || !(flags & ColorSpaceFlag::StreamsShareColorSpace)) + 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