From patchwork Thu Nov 23 13:09:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 19232 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 7CB81C328F for ; Thu, 23 Nov 2023 13:09:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 92A7B629C2; Thu, 23 Nov 2023 14:09:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1700744954; bh=j0v0QcAOb0Zkm1Suzr7Srtec8wOMOhVyl34G5ZzYNrc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UQ02cHRnY140SHbSA79RlY4QPjWVMa2Ij9b+ZZ8viPJ9Z+BE0R3mqOyNonLyDManp cavD4gCpK7Jo6jVtNVab5n67OtJgMj/O1mGLMpafQd8f1ipDEVc/DYQNMe7lAm2NQD 1YBCaqWKoFdMvobSty39r0XB30tFi4Wk8VWKD6ybtLIA7jlYHjgugt1JcQIsnInNa+ H1hnVrY0gvYoj3sfA8YPFvXMLuwFitBILO23knEiy/jGHj6grC4vOVCjqRqtqvRC33 +qSwec35C8X+ARbLVr/gc1CE1md36rtvqtPQvM2JqJUf0vbzL9EcOVnd9TGV90sW29 5wan5eK5bxTfQ== Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 79744629AF for ; Thu, 23 Nov 2023 14:09:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="NxjnIUx9"; dkim-atps=neutral Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-507cee17b00so1069430e87.2 for ; Thu, 23 Nov 2023 05:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1700744951; x=1701349751; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8vWp/RL4W/zGsrOGnV1iqQZwboW+fjAjWQ/4xn9gKZ0=; b=NxjnIUx9zWJBjO1IPgClZ+iq1bYpfCp7zCAhoG0zKs+G+yUqmohcNnJNiWVJcnm2M0 q2rrqkmg8vUcebeiQWLbwzH+3JF/jr+tNpbLL1lB6aTv/Q5I2vhCimTB/GGHPObl8+Lv 7iAsDZvgWpy8NY0Qrk1uSxLGB1L/YtzgfCcW+Xna5E8HXKjtkTGYUpTIZlM8KgTbl7ge zP0fj+9Q7vYmZDitFZ6whBg7X7TdIcg1vC7pmpdM+yHxg6uDF+JiL223cjwgsouaduey 9u72rTFl1X5bZL2Saa1KvsHSHO/MSqUANj9FwN+TcUpO7USyD3MIJyUen848Z6QcgTvY zULQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700744951; x=1701349751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8vWp/RL4W/zGsrOGnV1iqQZwboW+fjAjWQ/4xn9gKZ0=; b=SIL2l0skak3i/LtsYMO3X+eRR67VMM05xGUluBR5he8+JHiMlWyDmTvzl1rbMswXi3 JSr7/1DJzfu2vhRG/crUbeumbNovnJ+q1Xl6zhBEuL9uaNwTEE3+bNx9MwgTyLNwbMZQ FTZcntZiyeBcqUdKeTQLL5zJmbQ51T7xUolVAttQSG9VYtRho9j8YxDz+MjzG9k8xRhJ fXFL25LoI8R+CiX+awC1EvctiM2tU326oZOMbarQgACe4Q0Mqf4IiQCA3/8RksnNkbeo SdTKgDFpgAtwEDc55dAg9690A7xjtVQoldhS3d1TWbOWR9buVCfq8yLulciDcftSTsyS BBCg== X-Gm-Message-State: AOJu0YzSvuATeKs3vkZVbxDeDKpp4E5q9Am1Qv9V85DXENYND+FPEHu4 ey/p6f5S3FQLETDNx0Xn9p61Gx6Ksut4vXC1ZHA= X-Google-Smtp-Source: AGHT+IEPRhD/KQhxCoa4eNsxlseoAtxXlQQTv8vUkNEQEvLKKQwmwRyUL6KpX5ZTFMGB/2Xgx/bFaQ== X-Received: by 2002:a05:6512:3248:b0:503:654:cf27 with SMTP id c8-20020a056512324800b005030654cf27mr3612222lfr.28.1700744951075; Thu, 23 Nov 2023 05:09:11 -0800 (PST) Received: from pi5-davidp.pitowers.org ([2a00:1098:3142:14:183e:6cc8:a436:a27c]) by smtp.gmail.com with ESMTPSA id v10-20020adff68a000000b00332c0e934aasm1593380wrp.44.2023.11.23.05.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:09:10 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 23 Nov 2023 13:09:05 +0000 Message-Id: <20231123130905.103934-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231123130905.103934-1-david.plowman@raspberrypi.com> References: <20231123130905.103934-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] ipa: rpi: awb: Make it 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 applications 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: Naushir Patuck Reviewed-by: Kieran Bingham --- 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;