From patchwork Wed Oct 20 11:08:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14199 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 3DD83C324E for ; Wed, 20 Oct 2021 11:08:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED60868F71; Wed, 20 Oct 2021 13:08:36 +0200 (CEST) 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="EryKXKyt"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A5DE668F64 for ; Wed, 20 Oct 2021 13:08:31 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 67-20020a1c1946000000b0030d4c90fa87so9268930wmz.2 for ; Wed, 20 Oct 2021 04:08:31 -0700 (PDT) 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=/DkWsC49pTR4LtQbKMXqaDsUcUfiAkrci28YuUbz4pg=; b=EryKXKytDszuoNQQe4JsV9U3GFRqmxL0OPKwdOyPqzXrq45p6U3dPWCLdhOO5UTwfG q1taqsHbf/FyJGVN5ZFCJrOc9iQvmSUcQrsoIGpa9yRPYKbDL/k3HEAB0/GikVWeJwR9 9sl/cB2oUiMqL9MvnQt2XGTFhlZjKGQLhjWefhkmLIy3XKoqI/A3Dz+2ImqW2vKZv+YF bl72cwe80o6is3KNBVnMVOpuq8FQDVt5EOi0ZhkzdTpxQO4tPSXG9JlPw3Biau26LUMN Qgcqf4BSvYZWJ1ifzHsEt5AiIv0UcTZD23zFsgOjBBbkl7qc+pwGvTz5mbnaPGF5gW4d THGA== 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=/DkWsC49pTR4LtQbKMXqaDsUcUfiAkrci28YuUbz4pg=; b=tzwSGmlwexbVrBtnNadi+R0WqnRvAQNqO6SOvz4afTgqk/Ds6dmA/nZ1J76orU9Zsz IoQTuRCl6CDCfRwGkDLWM+efSqn+VDzIeB4/T1u2/cQh6phejg55Tn6/P/LWih+wSNRs ksJZWvGjlHxrY7KpwvCy07ACjIfgKKVb1nxxThhZ2uQ+r8Iw0gON7J2EKfUY18JEakol 8iPwbFS3cE/g+ny9t+PwrJ2m77TBH6Fi/MBnx97iH0212tzdiLMksvypkI3ZBAKhhLiY M5hbOeaptcDBI+aWsMcohQ3NAJ/sAdX++u13MRXo1Y5Ho3InaXbmW0QAPwl1iORE/8/y 6Niw== X-Gm-Message-State: AOAM532o0P+QQY3d3VBXx5JRmEG+0Mqmb25+WRIxwysuhmhsn8xHF0Vm 94RN9rMlE2NRXAjI4kgUKj1jkLa8JiIExA== X-Google-Smtp-Source: ABdhPJzDsF7AyeXeP+Id459Q+EGISvZ0qi3DR44d4F0DhcnEDscCfUUVIhKpZVvho2f2OZRO1xxKLQ== X-Received: by 2002:a1c:f008:: with SMTP id a8mr12857449wmb.140.1634728111145; Wed, 20 Oct 2021 04:08:31 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id f20sm1929654wmq.38.2021.10.20.04.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 04:08:30 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Oct 2021 12:08:24 +0100 Message-Id: <20211020110825.12902-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211020110825.12902-1-david.plowman@raspberrypi.com> References: <20211020110825.12902-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 checks that the requested color spaces are sensible and do not contain any undefined enum values. It also initialises the "actual" color space field to the same value as the one requested, in the expectation that the rest of the validate() method will be able to check this. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck --- include/libcamera/camera.h | 2 ++ src/libcamera/camera.cpp | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 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 71809bcd..79451ef4 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -19,6 +19,7 @@ #include #include "libcamera/internal/camera.h" +#include "libcamera/internal/formats.h" #include "libcamera/internal/pipeline_handler.h" /** @@ -313,6 +314,58 @@ 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.width * cfg.size.height > config_[i].size.width * config_[i].size.height)) + index = i; + } + + /* + * Here we force raw streams to the correct color space and signal + * an error if we encounter anything undefined. We handle the case + * where all output streams are to share a color space, which we + * choose to be the color space of the largest stream. + */ + for (auto &cfg : config_) { + ColorSpace initialColorSpace = cfg.requestedColorSpace; + + if (isRaw(cfg.pixelFormat)) + cfg.requestedColorSpace = ColorSpace::Raw; + else if (!cfg.requestedColorSpace.isFullyDefined()) { + LOG(Camera, Error) << "Stream has undefined color space"; + cfg.requestedColorSpace = ColorSpace::Jpeg; + } else if (sharedColorSpace) + cfg.requestedColorSpace = config_[index].requestedColorSpace; + + if (cfg.requestedColorSpace != initialColorSpace) + status = Adjusted; + + /* + * We also initialise the actual color space as if the + * hardware can do what we want. But note that the rest + * of the validate() method may change this. + */ + cfg.actualColorSpace = cfg.requestedColorSpace; + } + + return status; +} + /** * \var CameraConfiguration::transform * \brief User-specified transform to be applied to the image