From patchwork Wed Dec 1 15:44:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14980 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 C606CC3252 for ; Wed, 1 Dec 2021 15:45:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6572560820; Wed, 1 Dec 2021 16:45:12 +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="O4Tizd0u"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7BCD460746 for ; Wed, 1 Dec 2021 16:45:08 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id t9so36266397wrx.7 for ; Wed, 01 Dec 2021 07:45:08 -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=hdblI0WBXeyTejRYwVT6qZCUGz4IKvH5clh91jOGakA=; b=O4Tizd0ufv8BPCCjyRZQwG0k7nQK+CIq2C8R6lANccuvIxA4dew6KWhWaijcnTiDJq xTObLvyCzJonU+4Z3fAJhtfia1Y7kxqwJ4/hTVw727tUQmwxNfrnXhwtCeqIsOkid8r4 /9P3cCOWmQxAk5YyIVXhwvZjwaWBDneEzXfkiO2q4633qfpZ1gxfx+HUtqprCEXrSAbU aw/jIEpkkdu8fmRKlzOZpmQ5j/RzEeOVsBCKPZkJ+HvTVoC0+Qf1xWRU8o99jwuMzjna KHuxG8E3KTIxKTkI/cy8XEHOyK4MtX0oEPImhdWsRe+f0e9L4gJ1fI0XpYEHnD0RxCcX meVw== 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=hdblI0WBXeyTejRYwVT6qZCUGz4IKvH5clh91jOGakA=; b=BqxTk4/J1Vw2+vk6IdJT7ehJXvu4GA0yRmXbJpW7t/FDJXGf2TlLxKpaqhwXjxtlOs 2VB3iGRWSiEA1q8M0tMZkf1yGWSdEp2wr28WEqJfPl5iutTdSN/n1F9uhVe8quyuZH2g dv15zldsegpnWxwPQD5FzO8SvF4gk6TBilp6+P32i9ACB7vYuR9Nfxxpnc6bzk6vS5X4 qly+l9qVqd44sJyZRM0Kj4uuEhKF01DUDe6+eEaI/R3kIanV0OQg91YxDh/oQmwtIVwH 2mli2d8MJdIxh02/uL/xfjph8NCnT3ay+NnoCt2Qp6Xdj0SOibscWxT+rVjjWHaemdCZ IsjQ== X-Gm-Message-State: AOAM530LVOMTQL1j0beF3zBHNxKj0STCR+joj0s/Iyd6mrSFmITVfxUk CgsNl3ugHjxTE1HbPl7lWVMCTfezTUy7jUkY X-Google-Smtp-Source: ABdhPJyT5wRzPpQCPtL9exMksCcsQ65Dmyqxf4Az/sFoep42HO+20b1XEsVCrCqO9FJQlAtkg+IgUQ== X-Received: by 2002:a5d:648e:: with SMTP id o14mr7477279wri.141.1638373508039; Wed, 01 Dec 2021 07:45:08 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id y7sm148209wrw.55.2021.12.01.07.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 07:45:07 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org, Laurent Pinchart , Kieran Bingham , Jacopo Mondi , Hans Verkuil , Tomasz Figa , Naushir Patuck Date: Wed, 1 Dec 2021 15:44:33 +0000 Message-Id: <20211201154434.23127-8-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211201154434.23127-1-david.plowman@raspberrypi.com> References: <20211201154434.23127-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 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 | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 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..a6a93dd0 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,73 @@ 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 the color spaces requested for each stream + * \param[in] shareOutputColorSpaces Force all 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. + * \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(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)) { + if (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