From patchwork Fri Nov 26 10:40: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: 14802 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 D90DFC324F for ; Fri, 26 Nov 2021 10:41:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 75538604FB; Fri, 26 Nov 2021 11:41:13 +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="nInGg2E1"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 00BBE604FB for ; Fri, 26 Nov 2021 11:41:04 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id y196so7709171wmc.3 for ; Fri, 26 Nov 2021 02:41:03 -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=lQA2w7ytVML8JdHRQ+4Ft1+guf03qBPRjj4QjqFWCO4=; b=nInGg2E1KFRogqn1VjojU8rl9XX3D4hgc4rKKyPbeds8PJJvUBezda/+5csm+UXrM/ WmQW0/Kp+0PECl6w9R3vbLP01UMrOc7qVFfqPNeUgwNBH7R98X7thlS/mciKJkTnmY+y pRU/EKQ9rxTYy1tuy67kwsEt16N0d8Xi6crC48d0fZ+Q+J5drXyQ0y8mdPZtFfvm3xYw XIbRafm8Snz9udeaJVRrw0Gxd7+FcGLM/sxEA36djcTjJnBJRf+S5oaOZpnd+9svD7sX BmbU5y5MjxCjRd6M6T0u4Z8vgqNppebsGXDrfxbADHLR81/O2Qn4nHtCA8Jep3Ck5+Jh 3obw== 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=lQA2w7ytVML8JdHRQ+4Ft1+guf03qBPRjj4QjqFWCO4=; b=Q+8x7YeCJsyCxdx30cDN8wASPmRL76RHFYBzq2Stm87/kX/XQfQR9K59RRE7yF9uRs NzJMpFHpL3CKnoJDwq8zLHdFlT3GL8stMehlb1eLWU4AzgWvOzc5OBYgzMjZ0DL42ItK 0GEhbn/z71S0ccSGs0azfX7JWjeTBLdBtbXNLpsojUwVE68MXyTnMfeNHoPNjSJYf0E9 aWbiR6nvqL0kqtzsWxWTzuYYrar7Lr637NDgwJrMCKhlLhpG4X1F4MGcRt9VPYePz+eH PhHU6StytRzoInpB3AYBlfGRaQRgLSYSoZsWSj0rsue11P7ifXWaCWxiqUYXotXl9dC0 DxdA== X-Gm-Message-State: AOAM533tdTFGPmsFqU2Ny7t2vGfYFcOS+DJ/CnJ/VKIuuJMksUM0ErVn pOH/ljPpGqsEBqA5TZeXqB4xvg== X-Google-Smtp-Source: ABdhPJy/bppEN57LazOMLYWuohtUrIZQQX929gcu87Sj6o4ITYMFlUMhpMbTSw+y22S5TgHBOP+0FQ== X-Received: by 2002:a7b:c844:: with SMTP id c4mr14214111wml.148.1637923263658; Fri, 26 Nov 2021 02:41:03 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id y7sm5106795wrw.55.2021.11.26.02.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Nov 2021 02:41:03 -0800 (PST) From: David Plowman To: Laurent Pinchart , Kieran Bingham , Hans Verkuil , Tomasz Figa , Jacopo Mondi , Naushir Patuck , libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 10:40:44 +0000 Message-Id: <20211126104045.4756-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211126104045.4756-1-david.plowman@raspberrypi.com> References: <20211126104045.4756-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index a7759ccb..32a7f812 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..dd06f600 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,43 @@ 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 shareOuputColorSpaces) +{ + 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; + else if (cfg.colorSpace && (index == -1 || cfg.size > config_[i].size)) + index = i; + } + + /* Make all output color spaces the same, if requested. */ + if (index >= 0 && shareOuputColorSpaces) { + 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