From patchwork Mon Nov 15 16:12: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: 14612 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 9641EC324E for ; Mon, 15 Nov 2021 16:13:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2F075603C4; Mon, 15 Nov 2021 17:13:10 +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="lA6ZNaof"; dkim-atps=neutral Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 361356036C for ; Mon, 15 Nov 2021 17:13:02 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso16261036wml.1 for ; Mon, 15 Nov 2021 08:13:02 -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=px+J59JTE8VA+7mmTv2pDwc8QWJMkP/Tl3k7zA7RZOc=; b=lA6ZNaofLCd2+JjkqogeuZmcmMVGLhUM0+6CRZ/fT5UjGckn0jQdjkOGAEWqRKXR/E IXPN/VF0pA9gBQ93pdcytpcDFrCNjlsiIIHZt/vf16z+aY/Ba32DsQptFaM/fOU6jMwo vOoaK2QAdwUgSHU9fqAR/PIa4Pm1pLTcEcapGVJTl9svYQK8chEM2QjU02VzkehD+BhD Cj0DHn3EhadopDhW3zbj4QhsIYqBpNzRWOPDlKHulDxjbGBXBkivDTIImUmdsQE3rX0w UGl+iJ/9oeet8igx9xqgTe7+CBcPhdYbnxNcPhFbUhV2Xv7pndDCKU63FwPzH+xPV2Ey RwcA== 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=yfSNita43E3M4trlgtKhPShpTToqLhWruydQr+2BuHqT6UvzUL5U5Dcd3O3srLZCvq NAkKMi39A8ZWRdgB94el2/HWsG7SAZH8NVlCs9IW/dk/EOcAHAr0nV7AOA7Gx1bRwXZ+ eHQ267KNljGmt5VgvlVdNd/tPmFLTp1HpEJwTMbrj5cH+0H6SuK3sgshrPqR13ZebB6j tkeL9YvV8/gRS7W9xgdWJZfdWa4KhWhM8NvGdwVOWA0zf/8CPgnqsC1yowQhOeQbYZXB x4IvAh33OV0Co/UGbZ7ba9D5YicXFkAU+bkSoCi+xW9uhl86/utGUGh9O6KoobX5jjyP IEPg== X-Gm-Message-State: AOAM5327/dUILYCspqVS7kEA+VzJjGFVwEAlYGJrb8S6b/yiCxFkijZJ oEhdv+cJW27BV2flIsOQxC31KA== X-Google-Smtp-Source: ABdhPJyptZyIeKPnPgLThjbBMaTNmFu5bpz/Rvnt+zx3TsroBHz4L0QZtNMkI5iITapygenVuwP19g== X-Received: by 2002:a1c:7ed3:: with SMTP id z202mr42913048wmc.110.1636992781945; Mon, 15 Nov 2021 08:13:01 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id j40sm16315615wms.16.2021.11.15.08.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 08:13:01 -0800 (PST) From: David Plowman To: hverkuil-cisco@xs4all.nl, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, jacopo@jmondi.org, tfiga@google.com, naush@raspberrypi.com, libcamera-devel@lists.libcamera.org Date: Mon, 15 Nov 2021 16:12:04 +0000 Message-Id: <20211115161205.24335-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211115161205.24335-1-david.plowman@raspberrypi.com> References: <20211115161205.24335-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