From patchwork Fri Nov 10 16:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 19206 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 B4835BDE6B for ; Fri, 10 Nov 2023 16:14:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 170AA629B6; Fri, 10 Nov 2023 17:14:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1699632878; bh=gRcMOWzjBiVTTYDKFeK8kIY2Z+sHNFMn9Tz1Dvtz4sQ=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=1BoIw/jQokCNXKYN7EG++AVDixw68CVpWWlq2VX4QrSp88TkTVm5iAhogp49k2kE8 NZZtvJxNsk8aJQoEOhpHV+vyEH24lN8TBH7iDKw4FAW6dG//tRzNjXL0Mkg4PmfvUL Ztmec7iAd1hgPYJsOEr2bB6qjyfJDlHOUVBYaU/eTLaHEX+b+C8K4DzfIclgzTW1ij Qb+KmsKDHhsAAP3ttgE0xCTFf5/qYdLMYv/dwqHaEv9cfde8+pa0SLBJFlPVEzd9TT ojGablglR9/msVSwsyix0AOfSVfKLk9HSnNM4YYo5axLEy6j3e19guJaFRH/CcqCgB ifBE7CUQYP4xg== Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BFF661DB6 for ; Fri, 10 Nov 2023 17:14:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dElLd/ZN"; dkim-atps=neutral Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-32f87b1c725so1448683f8f.3 for ; Fri, 10 Nov 2023 08:14:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1699632875; x=1700237675; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+Y5t0BVJB50ee+3vSFOAvozfznYlHKOdVYI3EtNlGVM=; b=dElLd/ZNHaMxwyMHwb4o8Aiaq18z17RNlMx0BWtTbjXAkeaY6vxxpySmXz7QyioL0R Nza4Iwhxo3hqR7fEEZPx2L+I/s1qyMXxFYh+IGBN5rUxQ56AJCzwq3pikuFnrF+7FvxM DLm94pCbnRR9YPfxDn1AHsx+L9HHmUT6vm7tlUQV6wtSKQC7Mi/uEJ2rijwKp87UcEtu 57QbRk1e3Nilt1SjXCiaS9CmM1fxNMPAGf/v2VJOr9mKrQkNO8PfEpU3wsTUH3Zom2b3 ATg8R0BTGu/lZcd111UWGhndkkAJf6LKSvROHnWRhISKAgec1JKaLs1PG9hP9zA5Tfh7 KwwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699632875; x=1700237675; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+Y5t0BVJB50ee+3vSFOAvozfznYlHKOdVYI3EtNlGVM=; b=KgCqDLwCXPpD/n+zImllgG0oSY5F67KD6cAiPLm9imfDFJu0ewAAVKgZRPUNOr3Jln XydqM1TEQyN8No0Tt1K1NP+1dLsCrJ88xcps/BxXKd/qM7vMPKPn5y1DPU7LSzLsLHQa 1qYUT+jrwCoFjGXAT8JNGIDL8V8YSqSSZf/OtERWF4yjl857yflMGkdVUAiFeZc+1VxM HgfHmwh1E4O7bJhe3z9YIaGyrpWUZ7dFO3RMGWcynSDtNkSNUp8+CzQ2VlynCUlO2AOv RaNniJCznGd/dYj33BYHyX1VnmcKt8+BsZ87kow1oHPLEB+jye9D7WG+kSebLRFX+Cnc xIaw== X-Gm-Message-State: AOJu0YxTJcLvi5xvnORb0eLMFZ7c6bZk9XNczTTT9FE6F3oTkCqqpHFU Odn1BHoAd0lkwDFsluQuthAA7BS+faAKug1yo3U= X-Google-Smtp-Source: AGHT+IFY2u5i++uHJkNGaZpy53E3pNAvFldOKv2nzXbAaDjHdQ31cHI6XgPU8N3xdbYbpdW6xJwE0w== X-Received: by 2002:a5d:44c7:0:b0:32d:885e:633 with SMTP id z7-20020a5d44c7000000b0032d885e0633mr6884194wrr.19.1699632875383; Fri, 10 Nov 2023 08:14:35 -0800 (PST) Received: from pi5-davidp.pitowers.org ([2a00:1098:3142:14:183e:6cc8:a436:a27c]) by smtp.gmail.com with ESMTPSA id i9-20020adfe489000000b0032da8fb0d05sm2167468wrm.110.2023.11.10.08.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 08:14:34 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 10 Nov 2023 16:14:33 +0000 Message-Id: <20231110161433.413382-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: rpi: awb: Make is possible to set the colour temperature directly 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: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" ColourTemperature is now exported as a writable control so that algorithms can set it directly. The AWB algorithm class now requires a method to be provided to perform this operation. The method should clamp the passed value to the calibrated range known to the algorithm. The default range is set very wide to cover all conceivable future AWB calibrations. It will always be clamped before use. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/ipa/rpi/common/ipa_base.cpp | 20 ++++++++++++++++++++ src/ipa/rpi/controller/awb_algorithm.h | 1 + src/ipa/rpi/controller/rpi/awb.cpp | 18 ++++++++++++++++++ src/ipa/rpi/controller/rpi/awb.h | 1 + 4 files changed, 40 insertions(+) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 97a32522..cd1d6e3d 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -80,6 +80,7 @@ const ControlInfoMap::Map ipaColourControls{ { &controls::AwbEnable, ControlInfo(false, true) }, { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, + { &controls::ColourTemperature, ControlInfo(100, 100000) }, { &controls::Saturation, ControlInfo(0.0f, 32.0f, 1.0f) }, }; @@ -972,6 +973,25 @@ void IpaBase::applyControls(const ControlList &controls) break; } + case controls::COLOUR_TEMPERATURE: { + /* Silently ignore this control for a mono sensor. */ + if (monoSensor_) + break; + + auto temperatureK = ctrl.second.get(); + RPiController::AwbAlgorithm *awb = dynamic_cast( + controller_.getAlgorithm("awb")); + if (!awb) { + LOG(IPARPI, Warning) + << "Could not set COLOUR_TEMPERATURE - no AWB algorithm"; + break; + } + + awb->setColourTemperature(temperatureK); + /* This metadata will get reported back automatically. */ + break; + } + case controls::BRIGHTNESS: { RPiController::ContrastAlgorithm *contrast = dynamic_cast( controller_.getAlgorithm("contrast")); diff --git a/src/ipa/rpi/controller/awb_algorithm.h b/src/ipa/rpi/controller/awb_algorithm.h index 8462c4db..d966dfa8 100644 --- a/src/ipa/rpi/controller/awb_algorithm.h +++ b/src/ipa/rpi/controller/awb_algorithm.h @@ -18,6 +18,7 @@ public: virtual unsigned int getConvergenceFrames() const = 0; virtual void setMode(std::string const &modeName) = 0; virtual void setManualGains(double manualR, double manualB) = 0; + virtual void setColourTemperature(double temperatureK) = 0; virtual void enableAuto() = 0; virtual void disableAuto() = 0; }; diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index 5ae0c2fa..0918e20d 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -275,6 +275,24 @@ void Awb::setManualGains(double manualR, double manualB) } } +void Awb::setColourTemperature(double temperatureK) +{ + if (!config_.bayes) { + LOG(RPiAwb, Warning) << "AWB uncalibrated - cannot set colour temperature"; + return; + } + + temperatureK = config_.ctR.domain().clip(temperatureK); + manualR_ = 1 / config_.ctR.eval(temperatureK); + manualB_ = 1 / config_.ctB.eval(temperatureK); + + syncResults_.temperatureK = temperatureK; + syncResults_.gainR = manualR_; + syncResults_.gainG = 1.0; + syncResults_.gainB = manualB_; + prevSyncResults_ = syncResults_; +} + void Awb::switchMode([[maybe_unused]] CameraMode const &cameraMode, Metadata *metadata) { diff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h index e7d49cd8..dbd79eda 100644 --- a/src/ipa/rpi/controller/rpi/awb.h +++ b/src/ipa/rpi/controller/rpi/awb.h @@ -97,6 +97,7 @@ public: unsigned int getConvergenceFrames() const override; void setMode(std::string const &name) override; void setManualGains(double manualR, double manualB) override; + void setColourTemperature(double temperatureK) override; void enableAuto() override; void disableAuto() override; void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;