From patchwork Fri Oct 29 13:23:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14430 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 8D886C324F for ; Fri, 29 Oct 2021 13:23:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C0BF600C6; Fri, 29 Oct 2021 15:23:58 +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="SBBYklli"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DEC1600BE for ; Fri, 29 Oct 2021 15:23:50 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id u18so16178127wrg.5 for ; Fri, 29 Oct 2021 06:23:50 -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=SBBYklli9XYf9omlnWTiEP08T698bsGvYvVGfCEVaPXWgnJ/8VTyUYNzb8ONv2xLv6 AEto3UPBLW84YFuL6LTY0btFbwD3jjyVfCAMnwMYfOD8+f5TUrV3fBkBLFDG4piew5mK aBoXLxu9OB5YDHopWB9hqSPRLRi6C6YGfm0UIw36DhgzqNVs2fxLVPO40tA/85w00Xqv LbuEkdeqToLk1sNiXy7p1tsYCszEnotnMSpO2Vei5cTVRk2yT9ZqSs6fIb6RfEkY/GJx siFrY5YYzuiawwYrVwglu3kKd+zSiPjZLSnjTGkvOx8xR3pKO70G0D6KLF3AXD2hQT2r 1hpg== 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=j1bxCHEOwU/Gd6jwoS7L/YM+mPp9iHJbbxcT9qTepQJGtMiOaG5XsY8qSSPIxLk/TA MqwZrgPDA5ylSSe6DVCaiGMBTjleI9M3AUwEQOVaEyWeX3a9Qk5RMWlQ4mZnws6QGaPH lY9xAMR/Db6uazng9c06j7H+EXG1IbVaeERmxaX2JvO0bzbA1wBOtVu5a8LzYvAeYRAY 7NNV0XgRiab1la/+3krV3ERQumg2/vbNmSCVbzouJgL7YtmVF9igLOc97Bo45XbDHPQ/ EbZ03cUSoBIaw5w1bMR99inWkTiDUWcx3BExODiewFxRfSCv+WLiLBICxAF0DortM2Nf t7JA== X-Gm-Message-State: AOAM533JTFAFVyTsr61yuY042r1+lZ1vf5KsQX7PjOko0f4di/tB+JZh 4gllWlFDTyejcuOXhCbzBI2jWjdMX2IQWA== X-Google-Smtp-Source: ABdhPJyoiacREGvgbQ4IlQpuKP1SnEw1HM6H/5ns4reyAF6sGzQxkizKhR7eJDC+Sq0yoL0kAd+Uhw== X-Received: by 2002:a05:6000:18ce:: with SMTP id w14mr14391772wrq.230.1635513830165; Fri, 29 Oct 2021 06:23:50 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id l7sm111934wrf.31.2021.10.29.06.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 06:23:49 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 29 Oct 2021 14:23:42 +0100 Message-Id: <20211029132343.1629-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211029132343.1629-1-david.plowman@raspberrypi.com> References: <20211029132343.1629-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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