From patchwork Thu Nov 4 13:58:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14463 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 2D198BDB1C for ; Thu, 4 Nov 2021 13:58:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C92F760361; Thu, 4 Nov 2021 14:58:34 +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="IXYf3K6j"; 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 B1EA26035D for ; Thu, 4 Nov 2021 14:58:26 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id d72-20020a1c1d4b000000b00331140f3dc8so4362043wmd.1 for ; Thu, 04 Nov 2021 06:58:26 -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=px+J59JTE8VA+7mmTv2pDwc8QWJMkP/Tl3k7zA7RZOc=; b=IXYf3K6jDwavl2ZDFSmb3tXf0KRsuVbKLNjGl8xam9XHnObNPyEKIa+kTaTwHF7xts RQaLIvVjPJR9BzJ+555RBC7Ru7J5rv+RzfEi35mVzs7qdMZfVFR8QwhKV75tmMntzsHn CdMelkbUs8NrnRN1WbTrAGAPDhpP8VoURsJh1Pe3bvDvp+FrLokAhTkUUsKCbz828QRb YpOYbPo3sgBcCSu/FAtNQiziWb3Hs8IJJXqP7lzgh+WgexlTzOouPMnM2wkWTl3IMOqK 1RSEMIlqX2c+3mmS6OaUSK85iV2M5p7e1Yv7Hnbgiu1LB2UuFmwvuDlemjaI8ewJ7IGm 3BSQ== 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=px+J59JTE8VA+7mmTv2pDwc8QWJMkP/Tl3k7zA7RZOc=; b=aGSxNxOm7e7ZiHU5/1db8Dte4YT+vLtGBauMXrJv++HX0PvBb9BRrjyeHNyhSdULSW oSxEhdZ7JSucEmXA3+bUbH5h1dlRtSmo4JS7ljmieUoybsrNW1Jra9zMMc3sZIPbWx++ Yb+ymuNpSg4GMrKIgm88E/NX5uintPBMCwAWcAsvw6Dvh5gRn0h7PROuAX6/WW5Pb2bi tl84deKSQeS0SffQBTY/0DZuGhN1voimuY6lVOjoXqaR4tfN9DarBzVSHWTGv1h74A3I 64VVt+VnWDnOxn+KxSYJfPc1OL4CKmbZ5/Gp1llJX87cWnum5+pDmdE/rF9i8CyGRWFK By0g== X-Gm-Message-State: AOAM533v6zLAI+cHdZ1qJNEZbFUVghQFek7HUd2200wLyntASnY+h2O2 2IXTO7wygRq8L7wJUJF9QO/uC+ycYtMP5Q== X-Google-Smtp-Source: ABdhPJwA+c23AiLtC1MtRkKctoXHEGgncjNSDRkjmTkjhsZ2/qpiUzyuspsJ8KqZZXIERsNkFVLkTg== X-Received: by 2002:a05:600c:b46:: with SMTP id k6mr3157967wmr.45.1636034306184; Thu, 04 Nov 2021 06:58:26 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id i20sm2264736wmq.41.2021.11.04.06.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 06:58:25 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Nov 2021 13:58:04 +0000 Message-Id: <20211104135805.5269-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211104135805.5269-1-david.plowman@raspberrypi.com> References: <20211104135805.5269-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 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 400a7cf0..90e9460b 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,56 @@ 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 > config_[i].size)) + 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