From patchwork Thu Dec 11 14:25:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 25490 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 5B891C3257 for ; Thu, 11 Dec 2025 14:28:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 133DB6160B; Thu, 11 Dec 2025 15:28:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HVqPwx/u"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B81A6609D8 for ; Thu, 11 Dec 2025 15:28:36 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-47a8195e515so1693445e9.0 for ; Thu, 11 Dec 2025 06:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1765463311; x=1766068111; 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=R6MONtYv/U587Gk6sl+5sb0/xFQPsx0UvTJxHsyYYws=; b=HVqPwx/uhwps09R4P0f8rc41kkEPRPg036Rrsnikdm3QjPBfPyn3gavVasLsdOXwaX CZ7jXgxbi4zg6L9bZ8XllrJiDDrlHd0a6qAMTT1jeZRNcXT0L7kBbYJtr6sIhMy8pzU1 677o+hQPytER0TJMBPtG+jACLFlHQaqHFWfAt+ztPM4FQ0KWscPQlrpeAtMvrLsKRw6D P0RjORit5+SP9WxUYTz9o7PCXNZBs8dtns5UMdDu8noakOGOivpigcevjaPxUrPOMPvM Tl37Il2vvrsvD6cK3ddFEvIlCZ1bw0uTK3nVDgj9PG2Q4f9V1O96wtzIrbkmTc7tjod4 FRkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765463311; x=1766068111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R6MONtYv/U587Gk6sl+5sb0/xFQPsx0UvTJxHsyYYws=; b=G4lHW74TPyOrOukK88TA0aVXD4dbe3j1C1hSk7/wrQEPBxgMdEAlcxSNeNggYHbmOq 4Jo2KdBldAdoYg3mjQZKoR1RPoWpZMCkaFLLp6wQLimmq2yA99V7/H5UYzg/gKPB2TQt ICzvcNskN3LzxK9fvi+2hPkVYgS/IdTpiSEOgrf+ytI1gHYk9rS3lsb94/SAsfGLtNlc VuuoGwbS1ZdcRW8QO0Xp/7Hslc/+g+mrw9qkn+tXOsmi2bS0tShR6S8OATL4Nt4sPR6p zthtBuXStOcasw/+tllDq8NwpYkmNmJmP/O4jq9DDOuq6BZEHb0uMRj33nB37BMQeksu vkzA== X-Gm-Message-State: AOJu0YwgNOMXQlYnCiv+oo3Mw+tTUv+L/4Pp7uBGAqifqYwPaAWeMmSm IzDvW+yVp9vbgryxZjE/gv0BgOo6/2tNPTo2OH4zdoeVdyWSGCtar36B3srSPpPE3NuBMP66VF9 xQNPZ X-Gm-Gg: AY/fxX7RoRCVwmkoYG6TrQeNClvnHNcua8FIivqlhmCFohBN5MPsedUguMglRccL+5W +OVxbgxZ56Yffld9RFwc5HapmxCVm7IG+eg9BEGVc8qZG0vnm94QwgLYzKHCtzwuLiQtXNxUAXi 2VIUFyOVWJxuYw5LeeqTmsbA42Ew29e/crsohQFm5AciBc2pU+pyupqhK4Xa1eRplyGcJ4R0JI8 uLV7rX2dlZbD34f1BhyiIaUbA8OtuVCcMpdD0GG3lgouAfvCAo35t+yGSIe5q6lGYoR7OtR21EX ZK84Gt1rHEjEw4PSzHgJjghavqvYmKEcSChztE0aVXuJWNbm8bLfK/XUtnsdNSGuXGXUeZaPAQJ Ug5yABV2ViQepAdzS6nufpvqjiPRjTSLb+IApitn95y1uHVzuX2teSCZjpJ71idtWQM7jRzLEOs ns2sltUNrj79vsv0+WkXgAsnHtc9qfH6Ozd/uA2fM0h993othglEui78NClwHG6anW6DdP1iMoH vr7Epi67J+3kX80tNv73AXpOLNzkQ== X-Google-Smtp-Source: AGHT+IE+Sq4IhKgGiki8bd0M+aiKZtY0e01JFtKU5WBTas0LKhCXqIDISxfmVh9Lu8Y/Lc33ygXsGw== X-Received: by 2002:a05:600c:1d0e:b0:477:582e:7a81 with SMTP id 5b1f17b1804b1-47a8bd12774mr15844975e9.4.1765463310438; Thu, 11 Dec 2025 06:28:30 -0800 (PST) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a89da4756sm39999505e9.6.2025.12.11.06.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:28:28 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: Peter Bailey Subject: [PATCH v2 1/4] ipa: rpi: controller: awb: Separate Bayesian AWB into AwbBayes Date: Thu, 11 Dec 2025 14:25:57 +0000 Message-ID: <20251211142824.26635-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211142824.26635-1-david.plowman@raspberrypi.com> References: <20251211142824.26635-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 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" From: Peter Bailey Move parts of the AWB algorithm specific to the Bayesian algorithm into a new class. This will make it easier to add new AWB algorithms in the future. Signed-off-by: Peter Bailey --- src/ipa/rpi/controller/meson.build | 1 + src/ipa/rpi/controller/rpi/awb.cpp | 409 +++------------------ src/ipa/rpi/controller/rpi/awb.h | 99 ++--- src/ipa/rpi/controller/rpi/awb_bayes.cpp | 444 +++++++++++++++++++++++ 4 files changed, 533 insertions(+), 420 deletions(-) create mode 100644 src/ipa/rpi/controller/rpi/awb_bayes.cpp diff --git a/src/ipa/rpi/controller/meson.build b/src/ipa/rpi/controller/meson.build index bdc53e3b..90d9e285 100644 --- a/src/ipa/rpi/controller/meson.build +++ b/src/ipa/rpi/controller/meson.build @@ -10,6 +10,7 @@ rpi_ipa_controller_sources = files([ 'rpi/agc_channel.cpp', 'rpi/alsc.cpp', 'rpi/awb.cpp', + 'rpi/awb_bayes.cpp', 'rpi/black_level.cpp', 'rpi/cac.cpp', 'rpi/ccm.cpp', diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index 365b595f..de5fa59b 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -1,20 +1,14 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi Ltd + * Copyright (C) 2025, Raspberry Pi Ltd * * AWB control algorithm */ - -#include -#include -#include - -#include +#include "awb.h" #include "../lux_status.h" #include "alsc_status.h" -#include "awb.h" using namespace RPiController; using namespace libcamera; @@ -23,39 +17,6 @@ LOG_DEFINE_CATEGORY(RPiAwb) constexpr double kDefaultCT = 4500.0; -#define NAME "rpi.awb" - -/* - * todo - the locking in this algorithm needs some tidying up as has been done - * elsewhere (ALSC and AGC). - */ - -int AwbMode::read(const libcamera::YamlObject ¶ms) -{ - auto value = params["lo"].get(); - if (!value) - return -EINVAL; - ctLo = *value; - - value = params["hi"].get(); - if (!value) - return -EINVAL; - ctHi = *value; - - return 0; -} - -int AwbPrior::read(const libcamera::YamlObject ¶ms) -{ - auto value = params["lux"].get(); - if (!value) - return -EINVAL; - lux = *value; - - prior = params["prior"].get(ipa::Pwl{}); - return prior.empty() ? -EINVAL : 0; -} - static int readCtCurve(ipa::Pwl &ctR, ipa::Pwl &ctB, const libcamera::YamlObject ¶ms) { if (params.size() % 3) { @@ -92,11 +53,25 @@ static int readCtCurve(ipa::Pwl &ctR, ipa::Pwl &ctB, const libcamera::YamlObject return 0; } +int AwbMode::read(const libcamera::YamlObject ¶ms) +{ + auto value = params["lo"].get(); + if (!value) + return -EINVAL; + ctLo = *value; + + value = params["hi"].get(); + if (!value) + return -EINVAL; + ctHi = *value; + + return 0; +} + int AwbConfig::read(const libcamera::YamlObject ¶ms) { int ret; - bayes = params["bayes"].get(1); framePeriod = params["frame_period"].get(10); startupFrames = params["startup_frames"].get(10); convergenceFrames = params["convergence_frames"].get(3); @@ -111,23 +86,6 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) ctBInverse = ctB.inverse().first; } - if (params.contains("priors")) { - for (const auto &p : params["priors"].asList()) { - AwbPrior prior; - ret = prior.read(p); - if (ret) - return ret; - if (!priors.empty() && prior.lux <= priors.back().lux) { - LOG(RPiAwb, Error) << "AwbConfig: Prior must be ordered in increasing lux value"; - return -EINVAL; - } - priors.push_back(prior); - } - if (priors.empty()) { - LOG(RPiAwb, Error) << "AwbConfig: no AWB priors configured"; - return -EINVAL; - } - } if (params.contains("modes")) { for (const auto &[key, value] : params["modes"].asDict()) { ret = modes[key].read(value); @@ -142,13 +100,10 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) } } - minPixels = params["min_pixels"].get(16.0); - minG = params["min_G"].get(32); - minRegions = params["min_regions"].get(10); deltaLimit = params["delta_limit"].get(0.2); - coarseStep = params["coarse_step"].get(0.2); transversePos = params["transverse_pos"].get(0.01); transverseNeg = params["transverse_neg"].get(0.01); + if (transversePos <= 0 || transverseNeg <= 0) { LOG(RPiAwb, Error) << "AwbConfig: transverse_pos/neg must be > 0"; return -EINVAL; @@ -157,29 +112,21 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) sensitivityR = params["sensitivity_r"].get(1.0); sensitivityB = params["sensitivity_b"].get(1.0); - if (bayes) { - if (ctR.empty() || ctB.empty() || priors.empty() || - defaultMode == nullptr) { - LOG(RPiAwb, Warning) - << "Bayesian AWB mis-configured - switch to Grey method"; - bayes = false; - } - } - whitepointR = params["whitepoint_r"].get(0.0); - whitepointB = params["whitepoint_b"].get(0.0); - if (bayes == false) + if (hasCtCurve() && defaultMode != nullptr) { + greyWorld = false; + } else { + greyWorld = true; sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */ - /* - * The biasProportion parameter adds a small proportion of the counted - * pixles to a region biased to the biasCT colour temperature. - * - * A typical value for biasProportion would be between 0.05 to 0.1. - */ - biasProportion = params["bias_proportion"].get(0.0); - biasCT = params["bias_ct"].get(kDefaultCT); + } + return 0; } +bool AwbConfig::hasCtCurve() const +{ + return !ctR.empty() && !ctB.empty(); +} + Awb::Awb(Controller *controller) : AwbAlgorithm(controller) { @@ -199,16 +146,6 @@ Awb::~Awb() asyncThread_.join(); } -char const *Awb::name() const -{ - return NAME; -} - -int Awb::read(const libcamera::YamlObject ¶ms) -{ - return config_.read(params); -} - void Awb::initialise() { frameCount_ = framePhase_ = 0; @@ -217,7 +154,7 @@ void Awb::initialise() * just in case the first few frames don't have anything meaningful in * them. */ - if (!config_.ctR.empty() && !config_.ctB.empty()) { + if (!config_.greyWorld) { syncResults_.temperatureK = config_.ctR.domain().clamp(4000); syncResults_.gainR = 1.0 / config_.ctR.eval(syncResults_.temperatureK); syncResults_.gainG = 1.0; @@ -282,7 +219,7 @@ void Awb::setManualGains(double manualR, double manualB) syncResults_.gainR = prevSyncResults_.gainR = manualR_; syncResults_.gainG = prevSyncResults_.gainG = 1.0; syncResults_.gainB = prevSyncResults_.gainB = manualB_; - if (config_.bayes) { + if (!config_.greyWorld) { /* Also estimate the best corresponding colour temperature from the curves. */ double ctR = config_.ctRInverse.eval(config_.ctRInverse.domain().clamp(1 / manualR_)); double ctB = config_.ctBInverse.eval(config_.ctBInverse.domain().clamp(1 / manualB_)); @@ -294,7 +231,7 @@ void Awb::setManualGains(double manualR, double manualB) void Awb::setColourTemperature(double temperatureK) { - if (!config_.bayes) { + if (config_.greyWorld) { LOG(RPiAwb, Warning) << "AWB uncalibrated - cannot set colour temperature"; return; } @@ -433,10 +370,10 @@ void Awb::asyncFunc() } } -static void generateStats(std::vector &zones, - StatisticsPtr &stats, double minPixels, - double minG, Metadata &globalMetadata, - double biasProportion, double biasCtR, double biasCtB) +void Awb::generateStats(std::vector &zones, + StatisticsPtr &stats, double minPixels, + double minG, Metadata &globalMetadata, + double biasProportion, double biasCtR, double biasCtB) { std::scoped_lock l(globalMetadata); @@ -450,9 +387,9 @@ static void generateStats(std::vector &zones, zone.R = region.val.rSum / region.counted; zone.B = region.val.bSum / region.counted; /* - * Add some bias samples to allow the search to tend to a - * bias CT in failure cases. - */ + * Add some bias samples to allow the search to tend to a + * bias CT in failure cases. + */ const unsigned int proportion = biasProportion * region.counted; zone.R += proportion * biasCtR; zone.B += proportion * biasCtB; @@ -469,29 +406,7 @@ static void generateStats(std::vector &zones, } } -void Awb::prepareStats() -{ - zones_.clear(); - /* - * LSC has already been applied to the stats in this pipeline, so stop - * any LSC compensation. We also ignore config_.fast in this version. - */ - const double biasCtR = config_.bayes ? config_.ctR.eval(config_.biasCT) : 0; - const double biasCtB = config_.bayes ? config_.ctB.eval(config_.biasCT) : 0; - generateStats(zones_, statistics_, config_.minPixels, - config_.minG, getGlobalMetadata(), - config_.biasProportion, biasCtR, biasCtB); - /* - * apply sensitivities, so values appear to come from our "canonical" - * sensor. - */ - for (auto &zone : zones_) { - zone.R *= config_.sensitivityR; - zone.B *= config_.sensitivityB; - } -} - -double Awb::computeDelta2Sum(double gainR, double gainB) +double Awb::computeDelta2Sum(double gainR, double gainB, double whitepointR, double whitepointB) { /* * Compute the sum of the squared colour error (non-greyness) as it @@ -499,8 +414,8 @@ double Awb::computeDelta2Sum(double gainR, double gainB) */ double delta2Sum = 0; for (auto &z : zones_) { - double deltaR = gainR * z.R - 1 - config_.whitepointR; - double deltaB = gainB * z.B - 1 - config_.whitepointB; + double deltaR = gainR * z.R - 1 - whitepointR; + double deltaB = gainB * z.B - 1 - whitepointB; double delta2 = deltaR * deltaR + deltaB * deltaB; /* LOG(RPiAwb, Debug) << "deltaR " << deltaR << " deltaB " << deltaB << " delta2 " << delta2; */ delta2 = std::min(delta2, config_.deltaLimit); @@ -509,39 +424,14 @@ double Awb::computeDelta2Sum(double gainR, double gainB) return delta2Sum; } -ipa::Pwl Awb::interpolatePrior() +double Awb::interpolateQuadatric(libcamera::ipa::Pwl::Point const &a, + libcamera::ipa::Pwl::Point const &b, + libcamera::ipa::Pwl::Point const &c) { /* - * Interpolate the prior log likelihood function for our current lux - * value. - */ - if (lux_ <= config_.priors.front().lux) - return config_.priors.front().prior; - else if (lux_ >= config_.priors.back().lux) - return config_.priors.back().prior; - else { - int idx = 0; - /* find which two we lie between */ - while (config_.priors[idx + 1].lux < lux_) - idx++; - double lux0 = config_.priors[idx].lux, - lux1 = config_.priors[idx + 1].lux; - return ipa::Pwl::combine(config_.priors[idx].prior, - config_.priors[idx + 1].prior, - [&](double /*x*/, double y0, double y1) { - return y0 + (y1 - y0) * - (lux_ - lux0) / (lux1 - lux0); - }); - } -} - -static double interpolateQuadatric(ipa::Pwl::Point const &a, ipa::Pwl::Point const &b, - ipa::Pwl::Point const &c) -{ - /* - * Given 3 points on a curve, find the extremum of the function in that - * interval by fitting a quadratic. - */ + * Given 3 points on a curve, find the extremum of the function in that + * interval by fitting a quadratic. + */ const double eps = 1e-3; ipa::Pwl::Point ca = c - a, ba = b - a; double denominator = 2 * (ba.y() * ca.x() - ca.y() * ba.x()); @@ -554,180 +444,6 @@ static double interpolateQuadatric(ipa::Pwl::Point const &a, ipa::Pwl::Point con return a.y() < c.y() - eps ? a.x() : (c.y() < a.y() - eps ? c.x() : b.x()); } -double Awb::coarseSearch(ipa::Pwl const &prior) -{ - points_.clear(); /* assume doesn't deallocate memory */ - size_t bestPoint = 0; - double t = mode_->ctLo; - int spanR = 0, spanB = 0; - /* Step down the CT curve evaluating log likelihood. */ - while (true) { - double r = config_.ctR.eval(t, &spanR); - double b = config_.ctB.eval(t, &spanB); - double gainR = 1 / r, gainB = 1 / b; - double delta2Sum = computeDelta2Sum(gainR, gainB); - double priorLogLikelihood = prior.eval(prior.domain().clamp(t)); - double finalLogLikelihood = delta2Sum - priorLogLikelihood; - LOG(RPiAwb, Debug) - << "t: " << t << " gain R " << gainR << " gain B " - << gainB << " delta2_sum " << delta2Sum - << " prior " << priorLogLikelihood << " final " - << finalLogLikelihood; - points_.push_back(ipa::Pwl::Point({ t, finalLogLikelihood })); - if (points_.back().y() < points_[bestPoint].y()) - bestPoint = points_.size() - 1; - if (t == mode_->ctHi) - break; - /* for even steps along the r/b curve scale them by the current t */ - t = std::min(t + t / 10 * config_.coarseStep, mode_->ctHi); - } - t = points_[bestPoint].x(); - LOG(RPiAwb, Debug) << "Coarse search found CT " << t; - /* - * We have the best point of the search, but refine it with a quadratic - * interpolation around its neighbours. - */ - if (points_.size() > 2) { - unsigned long bp = std::min(bestPoint, points_.size() - 2); - bestPoint = std::max(1UL, bp); - t = interpolateQuadatric(points_[bestPoint - 1], - points_[bestPoint], - points_[bestPoint + 1]); - LOG(RPiAwb, Debug) - << "After quadratic refinement, coarse search has CT " - << t; - } - return t; -} - -void Awb::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior) -{ - int spanR = -1, spanB = -1; - config_.ctR.eval(t, &spanR); - config_.ctB.eval(t, &spanB); - double step = t / 10 * config_.coarseStep * 0.1; - int nsteps = 5; - double rDiff = config_.ctR.eval(t + nsteps * step, &spanR) - - config_.ctR.eval(t - nsteps * step, &spanR); - double bDiff = config_.ctB.eval(t + nsteps * step, &spanB) - - config_.ctB.eval(t - nsteps * step, &spanB); - ipa::Pwl::Point transverse({ bDiff, -rDiff }); - if (transverse.length2() < 1e-6) - return; - /* - * unit vector orthogonal to the b vs. r function (pointing outwards - * with r and b increasing) - */ - transverse = transverse / transverse.length(); - double bestLogLikelihood = 0, bestT = 0, bestR = 0, bestB = 0; - double transverseRange = config_.transverseNeg + config_.transversePos; - const int maxNumDeltas = 12; - /* a transverse step approximately every 0.01 r/b units */ - int numDeltas = floor(transverseRange * 100 + 0.5) + 1; - numDeltas = numDeltas < 3 ? 3 : (numDeltas > maxNumDeltas ? maxNumDeltas : numDeltas); - /* - * Step down CT curve. March a bit further if the transverse range is - * large. - */ - nsteps += numDeltas; - for (int i = -nsteps; i <= nsteps; i++) { - double tTest = t + i * step; - double priorLogLikelihood = - prior.eval(prior.domain().clamp(tTest)); - double rCurve = config_.ctR.eval(tTest, &spanR); - double bCurve = config_.ctB.eval(tTest, &spanB); - /* x will be distance off the curve, y the log likelihood there */ - ipa::Pwl::Point points[maxNumDeltas]; - int bestPoint = 0; - /* Take some measurements transversely *off* the CT curve. */ - for (int j = 0; j < numDeltas; j++) { - points[j][0] = -config_.transverseNeg + - (transverseRange * j) / (numDeltas - 1); - ipa::Pwl::Point rbTest = ipa::Pwl::Point({ rCurve, bCurve }) + - transverse * points[j].x(); - double rTest = rbTest.x(), bTest = rbTest.y(); - double gainR = 1 / rTest, gainB = 1 / bTest; - double delta2Sum = computeDelta2Sum(gainR, gainB); - points[j][1] = delta2Sum - priorLogLikelihood; - LOG(RPiAwb, Debug) - << "At t " << tTest << " r " << rTest << " b " - << bTest << ": " << points[j].y(); - if (points[j].y() < points[bestPoint].y()) - bestPoint = j; - } - /* - * We have NUM_DELTAS points transversely across the CT curve, - * now let's do a quadratic interpolation for the best result. - */ - bestPoint = std::max(1, std::min(bestPoint, numDeltas - 2)); - ipa::Pwl::Point rbTest = ipa::Pwl::Point({ rCurve, bCurve }) + - transverse * interpolateQuadatric(points[bestPoint - 1], - points[bestPoint], - points[bestPoint + 1]); - double rTest = rbTest.x(), bTest = rbTest.y(); - double gainR = 1 / rTest, gainB = 1 / bTest; - double delta2Sum = computeDelta2Sum(gainR, gainB); - double finalLogLikelihood = delta2Sum - priorLogLikelihood; - LOG(RPiAwb, Debug) - << "Finally " - << tTest << " r " << rTest << " b " << bTest << ": " - << finalLogLikelihood - << (finalLogLikelihood < bestLogLikelihood ? " BEST" : ""); - if (bestT == 0 || finalLogLikelihood < bestLogLikelihood) - bestLogLikelihood = finalLogLikelihood, - bestT = tTest, bestR = rTest, bestB = bTest; - } - t = bestT, r = bestR, b = bestB; - LOG(RPiAwb, Debug) - << "Fine search found t " << t << " r " << r << " b " << b; -} - -void Awb::awbBayes() -{ - /* - * May as well divide out G to save computeDelta2Sum from doing it over - * and over. - */ - for (auto &z : zones_) - z.R = z.R / (z.G + 1), z.B = z.B / (z.G + 1); - /* - * Get the current prior, and scale according to how many zones are - * valid... not entirely sure about this. - */ - ipa::Pwl prior = interpolatePrior(); - prior *= zones_.size() / (double)(statistics_->awbRegions.numRegions()); - prior.map([](double x, double y) { - LOG(RPiAwb, Debug) << "(" << x << "," << y << ")"; - }); - double t = coarseSearch(prior); - double r = config_.ctR.eval(t); - double b = config_.ctB.eval(t); - LOG(RPiAwb, Debug) - << "After coarse search: r " << r << " b " << b << " (gains r " - << 1 / r << " b " << 1 / b << ")"; - /* - * Not entirely sure how to handle the fine search yet. Mostly the - * estimated CT is already good enough, but the fine search allows us to - * wander transverely off the CT curve. Under some illuminants, where - * there may be more or less green light, this may prove beneficial, - * though I probably need more real datasets before deciding exactly how - * this should be controlled and tuned. - */ - fineSearch(t, r, b, prior); - LOG(RPiAwb, Debug) - << "After fine search: r " << r << " b " << b << " (gains r " - << 1 / r << " b " << 1 / b << ")"; - /* - * Write results out for the main thread to pick up. Remember to adjust - * the gains from the ones that the "canonical sensor" would require to - * the ones needed by *this* sensor. - */ - asyncResults_.temperatureK = t; - asyncResults_.gainR = 1.0 / r * config_.sensitivityR; - asyncResults_.gainG = 1.0; - asyncResults_.gainB = 1.0 / b * config_.sensitivityB; -} - void Awb::awbGrey() { LOG(RPiAwb, Debug) << "Grey world AWB"; @@ -765,32 +481,3 @@ void Awb::awbGrey() asyncResults_.gainG = 1.0; asyncResults_.gainB = gainB; } - -void Awb::doAwb() -{ - prepareStats(); - LOG(RPiAwb, Debug) << "Valid zones: " << zones_.size(); - if (zones_.size() > config_.minRegions) { - if (config_.bayes) - awbBayes(); - else - awbGrey(); - LOG(RPiAwb, Debug) - << "CT found is " - << asyncResults_.temperatureK - << " with gains r " << asyncResults_.gainR - << " and b " << asyncResults_.gainB; - } - /* - * we're done with these; we may as well relinquish our hold on the - * pointer. - */ - statistics_.reset(); -} - -/* Register algorithm with the system. */ -static Algorithm *create(Controller *controller) -{ - return (Algorithm *)new Awb(controller); -} -static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h index 2fb91254..8b2d8d1d 100644 --- a/src/ipa/rpi/controller/rpi/awb.h +++ b/src/ipa/rpi/controller/rpi/awb.h @@ -1,42 +1,33 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi Ltd + * Copyright (C) 2025, Raspberry Pi Ltd * * AWB control algorithm */ #pragma once -#include #include +#include #include -#include - #include "../awb_algorithm.h" #include "../awb_status.h" -#include "../statistics.h" - #include "libipa/pwl.h" namespace RPiController { -/* Control algorithm to perform AWB calculations. */ - struct AwbMode { int read(const libcamera::YamlObject ¶ms); double ctLo; /* low CT value for search */ double ctHi; /* high CT value for search */ }; -struct AwbPrior { - int read(const libcamera::YamlObject ¶ms); - double lux; /* lux level */ - libcamera::ipa::Pwl prior; /* maps CT to prior log likelihood for this lux level */ -}; - struct AwbConfig { - AwbConfig() : defaultMode(nullptr) {} + AwbConfig() + : defaultMode(nullptr) {} int read(const libcamera::YamlObject ¶ms); + bool hasCtCurve() const; + /* Only repeat the AWB calculation every "this many" frames */ uint16_t framePeriod; /* number of initial frames for which speed taken as 1.0 (maximum) */ @@ -47,27 +38,13 @@ struct AwbConfig { libcamera::ipa::Pwl ctB; /* function maps CT to b (= B/G) */ libcamera::ipa::Pwl ctRInverse; /* inverse of ctR */ libcamera::ipa::Pwl ctBInverse; /* inverse of ctB */ - /* table of illuminant priors at different lux levels */ - std::vector priors; + /* AWB "modes" (determines the search range) */ std::map modes; AwbMode *defaultMode; /* mode used if no mode selected */ - /* - * minimum proportion of pixels counted within AWB region for it to be - * "useful" - */ - double minPixels; - /* minimum G value of those pixels, to be regarded a "useful" */ - uint16_t minG; - /* - * number of AWB regions that must be "useful" in order to do the AWB - * calculation - */ - uint32_t minRegions; + /* clamp on colour error term (so as not to penalise non-grey excessively) */ double deltaLimit; - /* step size control in coarse search */ - double coarseStep; /* how far to wander off CT curve towards "more purple" */ double transversePos; /* how far to wander off CT curve towards "more green" */ @@ -82,14 +59,8 @@ struct AwbConfig { * sensor's B/G) */ double sensitivityB; - /* The whitepoint (which we normally "aim" for) can be moved. */ - double whitepointR; - double whitepointB; - bool bayes; /* use Bayesian algorithm */ - /* proportion of counted samples to add for the search bias */ - double biasProportion; - /* CT target for the search bias */ - double biasCT; + + bool greyWorld; /* don't use the ct curve when in grey world mode */ }; class Awb : public AwbAlgorithm @@ -97,9 +68,7 @@ class Awb : public AwbAlgorithm public: Awb(Controller *controller = NULL); ~Awb(); - char const *name() const override; - void initialise() override; - int read(const libcamera::YamlObject ¶ms) override; + virtual void initialise() override; unsigned int getConvergenceFrames() const override; void initialValues(double &gainR, double &gainB) override; void setMode(std::string const &name) override; @@ -110,6 +79,11 @@ public: void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; void prepare(Metadata *imageMetadata) override; void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + + static double interpolateQuadatric(libcamera::ipa::Pwl::Point const &a, + libcamera::ipa::Pwl::Point const &b, + libcamera::ipa::Pwl::Point const &c); + struct RGB { RGB(double r = 0, double g = 0, double b = 0) : R(r), G(g), B(b) @@ -123,10 +97,30 @@ public: } }; -private: - bool isAutoEnabled() const; +protected: /* configuration is read-only, and available to both threads */ AwbConfig config_; + /* + * The following are for the asynchronous thread to use, though the main + * thread can set/reset them if the async thread is known to be idle: + */ + std::vector zones_; + StatisticsPtr statistics_; + double lux_; + AwbMode *mode_; + AwbStatus asyncResults_; + + virtual void doAwb() = 0; + virtual void prepareStats() = 0; + double computeDelta2Sum(double gainR, double gainB, double whitepointR, double whitepointB); + void awbGrey(); + static void generateStats(std::vector &zones, + StatisticsPtr &stats, double minPixels, + double minG, Metadata &globalMetadata, + double biasProportion, double biasCtR, double biasCtB); + +private: + bool isAutoEnabled() const; std::thread asyncThread_; void asyncFunc(); /* asynchronous thread function */ std::mutex mutex_; @@ -152,6 +146,7 @@ private: AwbStatus syncResults_; AwbStatus prevSyncResults_; std::string modeName_; + /* * The following are for the asynchronous thread to use, though the main * thread can set/reset them if the async thread is known to be idle: @@ -159,20 +154,6 @@ private: void restartAsync(StatisticsPtr &stats, double lux); /* copy out the results from the async thread so that it can be restarted */ void fetchAsyncResults(); - StatisticsPtr statistics_; - AwbMode *mode_; - double lux_; - AwbStatus asyncResults_; - void doAwb(); - void awbBayes(); - void awbGrey(); - void prepareStats(); - double computeDelta2Sum(double gainR, double gainB); - libcamera::ipa::Pwl interpolatePrior(); - double coarseSearch(libcamera::ipa::Pwl const &prior); - void fineSearch(double &t, double &r, double &b, libcamera::ipa::Pwl const &prior); - std::vector zones_; - std::vector points_; /* manual r setting */ double manualR_; /* manual b setting */ @@ -196,4 +177,4 @@ static inline Awb::RGB operator*(Awb::RGB const &rgb, double d) return d * rgb; } -} /* namespace RPiController */ +} // namespace RPiController diff --git a/src/ipa/rpi/controller/rpi/awb_bayes.cpp b/src/ipa/rpi/controller/rpi/awb_bayes.cpp new file mode 100644 index 00000000..09233cec --- /dev/null +++ b/src/ipa/rpi/controller/rpi/awb_bayes.cpp @@ -0,0 +1,444 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi Ltd + * + * AWB control algorithm + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "../awb_algorithm.h" +#include "../awb_status.h" +#include "../lux_status.h" +#include "../statistics.h" +#include "libipa/pwl.h" + +#include "alsc_status.h" +#include "awb.h" + +using namespace libcamera; + +LOG_DECLARE_CATEGORY(RPiAwb) + +constexpr double kDefaultCT = 4500.0; + +#define NAME "rpi.awb" + +/* + * todo - the locking in this algorithm needs some tidying up as has been done + * elsewhere (ALSC and AGC). + */ + +namespace RPiController { + +struct AwbPrior { + int read(const libcamera::YamlObject ¶ms); + double lux; /* lux level */ + libcamera::ipa::Pwl prior; /* maps CT to prior log likelihood for this lux level */ +}; + +struct AwbBayesConfig { + AwbBayesConfig() {} + int read(const libcamera::YamlObject ¶ms, AwbConfig &config); + /* table of illuminant priors at different lux levels */ + std::vector priors; + /* + * minimum proportion of pixels counted within AWB region for it to be + * "useful" + */ + double minPixels; + /* minimum G value of those pixels, to be regarded a "useful" */ + uint16_t minG; + /* + * number of AWB regions that must be "useful" in order to do the AWB + * calculation + */ + uint32_t minRegions; + /* step size control in coarse search */ + double coarseStep; + /* The whitepoint (which we normally "aim" for) can be moved. */ + double whitepointR; + double whitepointB; + bool bayes; /* use Bayesian algorithm */ + /* proportion of counted samples to add for the search bias */ + double biasProportion; + /* CT target for the search bias */ + double biasCT; +}; + +class AwbBayes : public Awb +{ +public: + AwbBayes(Controller *controller = NULL); + ~AwbBayes(); + char const *name() const override; + int read(const libcamera::YamlObject ¶ms) override; + +protected: + void prepareStats() override; + void doAwb() override; + +private: + AwbBayesConfig bayesConfig_; + void awbBayes(); + libcamera::ipa::Pwl interpolatePrior(); + double coarseSearch(libcamera::ipa::Pwl const &prior); + void fineSearch(double &t, double &r, double &b, libcamera::ipa::Pwl const &prior); + std::vector points_; +}; + +int AwbPrior::read(const libcamera::YamlObject ¶ms) +{ + auto value = params["lux"].get(); + if (!value) + return -EINVAL; + lux = *value; + + prior = params["prior"].get(ipa::Pwl{}); + return prior.empty() ? -EINVAL : 0; +} + +int AwbBayesConfig::read(const libcamera::YamlObject ¶ms, AwbConfig &config) +{ + int ret; + + bayes = params["bayes"].get(1); + + if (params.contains("priors")) { + for (const auto &p : params["priors"].asList()) { + AwbPrior prior; + ret = prior.read(p); + if (ret) + return ret; + if (!priors.empty() && prior.lux <= priors.back().lux) { + LOG(RPiAwb, Error) << "AwbConfig: Prior must be ordered in increasing lux value"; + return -EINVAL; + } + priors.push_back(prior); + } + if (priors.empty()) { + LOG(RPiAwb, Error) << "AwbConfig: no AWB priors configured"; + return -EINVAL; + } + } + + minPixels = params["min_pixels"].get(16.0); + minG = params["min_G"].get(32); + minRegions = params["min_regions"].get(10); + coarseStep = params["coarse_step"].get(0.2); + + if (bayes) { + if (!config.hasCtCurve() || priors.empty() || + config.defaultMode == nullptr) { + LOG(RPiAwb, Warning) + << "Bayesian AWB mis-configured - switch to Grey method"; + bayes = false; + } + } + whitepointR = params["whitepoint_r"].get(0.0); + whitepointB = params["whitepoint_b"].get(0.0); + if (bayes == false) { + config.sensitivityR = config.sensitivityB = 1.0; /* nor do sensitivities make any sense */ + config.greyWorld = true; /* prevent the ct curve being used in manual mode */ + } + /* + * The biasProportion parameter adds a small proportion of the counted + * pixles to a region biased to the biasCT colour temperature. + * + * A typical value for biasProportion would be between 0.05 to 0.1. + */ + biasProportion = params["bias_proportion"].get(0.0); + biasCT = params["bias_ct"].get(kDefaultCT); + return 0; +} + +AwbBayes::AwbBayes(Controller *controller) + : Awb(controller) +{ +} + +AwbBayes::~AwbBayes() +{ +} + +char const *AwbBayes::name() const +{ + return NAME; +} + +int AwbBayes::read(const libcamera::YamlObject ¶ms) +{ + int ret; + + ret = config_.read(params); + if (ret) + return ret; + + ret = bayesConfig_.read(params, config_); + if (ret) + return ret; + + return 0; +} + +void AwbBayes::prepareStats() +{ + zones_.clear(); + /* + * LSC has already been applied to the stats in this pipeline, so stop + * any LSC compensation. We also ignore config_.fast in this version. + */ + const double biasCtR = bayesConfig_.bayes ? config_.ctR.eval(bayesConfig_.biasCT) : 0; + const double biasCtB = bayesConfig_.bayes ? config_.ctB.eval(bayesConfig_.biasCT) : 0; + generateStats(zones_, statistics_, bayesConfig_.minPixels, + bayesConfig_.minG, getGlobalMetadata(), + bayesConfig_.biasProportion, biasCtR, biasCtB); + /* + * apply sensitivities, so values appear to come from our "canonical" + * sensor. + */ + for (auto &zone : zones_) { + zone.R *= config_.sensitivityR; + zone.B *= config_.sensitivityB; + } +} + +ipa::Pwl AwbBayes::interpolatePrior() +{ + /* + * Interpolate the prior log likelihood function for our current lux + * value. + */ + if (lux_ <= bayesConfig_.priors.front().lux) + return bayesConfig_.priors.front().prior; + else if (lux_ >= bayesConfig_.priors.back().lux) + return bayesConfig_.priors.back().prior; + else { + int idx = 0; + /* find which two we lie between */ + while (bayesConfig_.priors[idx + 1].lux < lux_) + idx++; + double lux0 = bayesConfig_.priors[idx].lux, + lux1 = bayesConfig_.priors[idx + 1].lux; + return ipa::Pwl::combine(bayesConfig_.priors[idx].prior, + bayesConfig_.priors[idx + 1].prior, + [&](double /*x*/, double y0, double y1) { + return y0 + (y1 - y0) * + (lux_ - lux0) / (lux1 - lux0); + }); + } +} + +double AwbBayes::coarseSearch(ipa::Pwl const &prior) +{ + points_.clear(); /* assume doesn't deallocate memory */ + size_t bestPoint = 0; + double t = mode_->ctLo; + int spanR = 0, spanB = 0; + /* Step down the CT curve evaluating log likelihood. */ + while (true) { + double r = config_.ctR.eval(t, &spanR); + double b = config_.ctB.eval(t, &spanB); + double gainR = 1 / r, gainB = 1 / b; + double delta2Sum = computeDelta2Sum(gainR, gainB, bayesConfig_.whitepointR, bayesConfig_.whitepointB); + double priorLogLikelihood = prior.eval(prior.domain().clamp(t)); + double finalLogLikelihood = delta2Sum - priorLogLikelihood; + LOG(RPiAwb, Debug) + << "t: " << t << " gain R " << gainR << " gain B " + << gainB << " delta2_sum " << delta2Sum + << " prior " << priorLogLikelihood << " final " + << finalLogLikelihood; + points_.push_back(ipa::Pwl::Point({ t, finalLogLikelihood })); + if (points_.back().y() < points_[bestPoint].y()) + bestPoint = points_.size() - 1; + if (t == mode_->ctHi) + break; + /* for even steps along the r/b curve scale them by the current t */ + t = std::min(t + t / 10 * bayesConfig_.coarseStep, mode_->ctHi); + } + t = points_[bestPoint].x(); + LOG(RPiAwb, Debug) << "Coarse search found CT " << t; + /* + * We have the best point of the search, but refine it with a quadratic + * interpolation around its neighbours. + */ + if (points_.size() > 2) { + unsigned long bp = std::min(bestPoint, points_.size() - 2); + bestPoint = std::max(1UL, bp); + t = interpolateQuadatric(points_[bestPoint - 1], + points_[bestPoint], + points_[bestPoint + 1]); + LOG(RPiAwb, Debug) + << "After quadratic refinement, coarse search has CT " + << t; + } + return t; +} + +void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior) +{ + int spanR = -1, spanB = -1; + config_.ctR.eval(t, &spanR); + config_.ctB.eval(t, &spanB); + double step = t / 10 * bayesConfig_.coarseStep * 0.1; + int nsteps = 5; + double rDiff = config_.ctR.eval(t + nsteps * step, &spanR) - + config_.ctR.eval(t - nsteps * step, &spanR); + double bDiff = config_.ctB.eval(t + nsteps * step, &spanB) - + config_.ctB.eval(t - nsteps * step, &spanB); + ipa::Pwl::Point transverse({ bDiff, -rDiff }); + if (transverse.length2() < 1e-6) + return; + /* + * unit vector orthogonal to the b vs. r function (pointing outwards + * with r and b increasing) + */ + transverse = transverse / transverse.length(); + double bestLogLikelihood = 0, bestT = 0, bestR = 0, bestB = 0; + double transverseRange = config_.transverseNeg + config_.transversePos; + const int maxNumDeltas = 12; + /* a transverse step approximately every 0.01 r/b units */ + int numDeltas = floor(transverseRange * 100 + 0.5) + 1; + numDeltas = numDeltas < 3 ? 3 : (numDeltas > maxNumDeltas ? maxNumDeltas : numDeltas); + /* + * Step down CT curve. March a bit further if the transverse range is + * large. + */ + nsteps += numDeltas; + for (int i = -nsteps; i <= nsteps; i++) { + double tTest = t + i * step; + double priorLogLikelihood = + prior.eval(prior.domain().clamp(tTest)); + double rCurve = config_.ctR.eval(tTest, &spanR); + double bCurve = config_.ctB.eval(tTest, &spanB); + /* x will be distance off the curve, y the log likelihood there */ + ipa::Pwl::Point points[maxNumDeltas]; + int bestPoint = 0; + /* Take some measurements transversely *off* the CT curve. */ + for (int j = 0; j < numDeltas; j++) { + points[j][0] = -config_.transverseNeg + + (transverseRange * j) / (numDeltas - 1); + ipa::Pwl::Point rbTest = ipa::Pwl::Point({ rCurve, bCurve }) + + transverse * points[j].x(); + double rTest = rbTest.x(), bTest = rbTest.y(); + double gainR = 1 / rTest, gainB = 1 / bTest; + double delta2Sum = computeDelta2Sum(gainR, gainB, bayesConfig_.whitepointR, bayesConfig_.whitepointB); + points[j][1] = delta2Sum - priorLogLikelihood; + LOG(RPiAwb, Debug) + << "At t " << tTest << " r " << rTest << " b " + << bTest << ": " << points[j].y(); + if (points[j].y() < points[bestPoint].y()) + bestPoint = j; + } + /* + * We have NUM_DELTAS points transversely across the CT curve, + * now let's do a quadratic interpolation for the best result. + */ + bestPoint = std::max(1, std::min(bestPoint, numDeltas - 2)); + ipa::Pwl::Point rbTest = ipa::Pwl::Point({ rCurve, bCurve }) + + transverse * interpolateQuadatric(points[bestPoint - 1], + points[bestPoint], + points[bestPoint + 1]); + double rTest = rbTest.x(), bTest = rbTest.y(); + double gainR = 1 / rTest, gainB = 1 / bTest; + double delta2Sum = computeDelta2Sum(gainR, gainB, bayesConfig_.whitepointR, bayesConfig_.whitepointB); + double finalLogLikelihood = delta2Sum - priorLogLikelihood; + LOG(RPiAwb, Debug) + << "Finally " + << tTest << " r " << rTest << " b " << bTest << ": " + << finalLogLikelihood + << (finalLogLikelihood < bestLogLikelihood ? " BEST" : ""); + if (bestT == 0 || finalLogLikelihood < bestLogLikelihood) + bestLogLikelihood = finalLogLikelihood, + bestT = tTest, bestR = rTest, bestB = bTest; + } + t = bestT, r = bestR, b = bestB; + LOG(RPiAwb, Debug) + << "Fine search found t " << t << " r " << r << " b " << b; +} + +void AwbBayes::awbBayes() +{ + /* + * May as well divide out G to save computeDelta2Sum from doing it over + * and over. + */ + for (auto &z : zones_) + z.R = z.R / (z.G + 1), z.B = z.B / (z.G + 1); + /* + * Get the current prior, and scale according to how many zones are + * valid... not entirely sure about this. + */ + ipa::Pwl prior = interpolatePrior(); + prior *= zones_.size() / (double)(statistics_->awbRegions.numRegions()); + prior.map([](double x, double y) { + LOG(RPiAwb, Debug) << "(" << x << "," << y << ")"; + }); + double t = coarseSearch(prior); + double r = config_.ctR.eval(t); + double b = config_.ctB.eval(t); + LOG(RPiAwb, Debug) + << "After coarse search: r " << r << " b " << b << " (gains r " + << 1 / r << " b " << 1 / b << ")"; + /* + * Not entirely sure how to handle the fine search yet. Mostly the + * estimated CT is already good enough, but the fine search allows us to + * wander transverely off the CT curve. Under some illuminants, where + * there may be more or less green light, this may prove beneficial, + * though I probably need more real datasets before deciding exactly how + * this should be controlled and tuned. + */ + fineSearch(t, r, b, prior); + LOG(RPiAwb, Debug) + << "After fine search: r " << r << " b " << b << " (gains r " + << 1 / r << " b " << 1 / b << ")"; + /* + * Write results out for the main thread to pick up. Remember to adjust + * the gains from the ones that the "canonical sensor" would require to + * the ones needed by *this* sensor. + */ + asyncResults_.temperatureK = t; + asyncResults_.gainR = 1.0 / r * config_.sensitivityR; + asyncResults_.gainG = 1.0; + asyncResults_.gainB = 1.0 / b * config_.sensitivityB; +} + +void AwbBayes::doAwb() +{ + prepareStats(); + LOG(RPiAwb, Debug) << "Valid zones: " << zones_.size(); + if (zones_.size() > bayesConfig_.minRegions) { + if (bayesConfig_.bayes) + awbBayes(); + else + awbGrey(); + LOG(RPiAwb, Debug) + << "CT found is " + << asyncResults_.temperatureK + << " with gains r " << asyncResults_.gainR + << " and b " << asyncResults_.gainB; + } + /* + * we're done with these; we may as well relinquish our hold on the + * pointer. + */ + statistics_.reset(); +} + +/* Register algorithm with the system. */ +static Algorithm *create(Controller *controller) +{ + return (Algorithm *)new AwbBayes(controller); +} +static RegisterAlgorithm reg(NAME, &create); + +} /* namespace RPiController */ From patchwork Thu Dec 11 14:25:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 25491 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 EC2FEC326B for ; Thu, 11 Dec 2025 14:28:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3499661616; Thu, 11 Dec 2025 15:28:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DW7pOpWO"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 67CB7609D8 for ; Thu, 11 Dec 2025 15:28:37 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4779a637712so1406015e9.1 for ; Thu, 11 Dec 2025 06:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1765463312; x=1766068112; 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=EE0+fp1z+dfnHRZCgpaLCnOWtwuf7r2DlhqUT7OIOlY=; b=DW7pOpWOhV+z1d3TTA7vE7wMj2irxBUpWm6FX30Gf8OaBMEFSaRWGdW4HGXcaByxvs 8R/pOFYFTlmSm3wkmTEM3oRjnXj2W2UTlRVd5jFR5D6x0jcQSjP79QnSObdRrksryhjY DyXF1/1/AjZpyKgq9ObKqcToIEyQUSrfR3Dop66Fc7SWpjndo1ttpEqGy4QV4VS8FEMJ 4D5Tbguoa5Tg6rLaO6oUvWf7o5T4IRPX2CVbJvnyFBbUtw+vUYPiezPhoJL8XIvkvnRN f54Hyhvyq2qKrG8mUPJ4R/T6uqLS09l3aVbFSWQhsTuD2arb9aSKbw6M21mmguuEUW9q LqFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765463312; x=1766068112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EE0+fp1z+dfnHRZCgpaLCnOWtwuf7r2DlhqUT7OIOlY=; b=PC6vACEgyFyU3h3oe/Y6BFMAAVPUDlbOVJhg/TEz5Lj+IAsnXQRV/mUINQF8MHy8v5 vHpj/Uwhg2N66QsKMIK5yhLBLq8bz7az+yqlw2bDiDhq47iE9oNvzIBuYneMnEY0R7VN JPojqLmXYUsA2LE4q0OtvRV3gsjnBpMT0Xy9PjzbORn3oB8SttETTmdP8VQsHtIkhA/c BFQTZVKggv8ORJD/cPI5rQyRK8cL6FVg9SDunkhl4NyTHHraM7dkcZNAZtN97RVTWgOQ Y2eUmRpzOEsDxN0R65XV6/+IZcRZqBiIP5LHFb+bFIqYkSJleV6RIGOGLE7/3CwjTNv4 Fmvw== X-Gm-Message-State: AOJu0YyiKnRZ2+DCPD5jt+VI1mLBTEg9zUC4atNBiyACsNIDX6H1LYIs SbDkNwa3L60u1wHP9FLozSk1+ZwrcnhLVSM7w+N6kCCzPgMC1vC2wysB3Q8OSmq7vbEYYJmrjEy drul2 X-Gm-Gg: AY/fxX5lA8aPyycS21b/mCQuhgE3WtUah9jtyciRrnT2mPUVFONA/RJRD3qdNijy9G/ q68b0H1aKbKwdrtN7zxAlet7YdsCr6R088pawv03w9lfUQ4XSs7/uF/t7ww3Dm+mySat9tv20JJ Bq1dOcltgdPGw14Jp+utNZuhl9GJ8CeAjWB/bUvgYaR3BlNhn+0UVP0v1fK+iGSvSVcCi7H75jf h1fZuNnCGvAHLxmj6C1AIarMLSuNqvqo0OY1X6qRWz3HdK1wG4cKIuqcrTc1Zdqop1+i7X7Utet /Tp/sqjcslr+V8VglYs2P/HHmzdjIOF2xx2rT6gmsd3atxkTM/CDmGc3az1wszky/f1Afrmpupr poTY2NysAB9Mi0ku9IcWA44ZsoEZGQ9idn9cSwlm/GrW+ZkkXBHxMnfKTYOVaJR3iJrwMOnLz7Z gS9WbmcKCMvA9r6DYcvge6xxM1BiK3+l/KCQ72KZYJRYg4I6dn4NYFmLzzfendE39KhJs1m/bdQ UWAXFskRVp2koj9fU/Sl9z/i+rNwg== X-Google-Smtp-Source: AGHT+IFExl7mSM9K8heJj3fmy+6k5JQ+7opFFpkib5pFXKAEoQsI/yyiuDrqJbhGLVVeRhqP+3Qhlg== X-Received: by 2002:a05:600c:3111:b0:477:a1a2:d829 with SMTP id 5b1f17b1804b1-47a83759f64mr59615265e9.13.1765463311488; Thu, 11 Dec 2025 06:28:31 -0800 (PST) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a89da4756sm39999505e9.6.2025.12.11.06.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:28:30 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: Peter Bailey Subject: [PATCH v2 2/4] ipa: rpi: controller: awb: Add Neural Network AWB Date: Thu, 11 Dec 2025 14:25:58 +0000 Message-ID: <20251211142824.26635-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211142824.26635-1-david.plowman@raspberrypi.com> References: <20251211142824.26635-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 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" From: Peter Bailey Add an AWB algorithm which uses neural networks. Signed-off-by: Peter Bailey --- meson_options.txt | 5 + src/ipa/rpi/controller/meson.build | 9 + src/ipa/rpi/controller/rpi/awb_nn.cpp | 446 ++++++++++++++++++++++++++ 3 files changed, 460 insertions(+) create mode 100644 src/ipa/rpi/controller/rpi/awb_nn.cpp diff --git a/meson_options.txt b/meson_options.txt index 5954e028..89eece52 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -78,6 +78,11 @@ option('qcam', value : 'disabled', description : 'Compile the qcam test application') +option('rpi-awb-nn', + type : 'feature', + value : 'auto', + description : 'Enable the Raspberry Pi Neural Network AWB algorithm') + option('test', type : 'boolean', value : false, diff --git a/src/ipa/rpi/controller/meson.build b/src/ipa/rpi/controller/meson.build index 90d9e285..9c261d99 100644 --- a/src/ipa/rpi/controller/meson.build +++ b/src/ipa/rpi/controller/meson.build @@ -33,6 +33,15 @@ rpi_ipa_controller_deps = [ libcamera_private, ] +tflite_dep = dependency('tensorflow-lite', required : false) + +if tflite_dep.found() + rpi_ipa_controller_sources += files([ + 'rpi/awb_nn.cpp', + ]) + rpi_ipa_controller_deps += tflite_dep +endif + rpi_ipa_controller_lib = static_library('rpi_ipa_controller', rpi_ipa_controller_sources, include_directories : libipa_includes, dependencies : rpi_ipa_controller_deps) diff --git a/src/ipa/rpi/controller/rpi/awb_nn.cpp b/src/ipa/rpi/controller/rpi/awb_nn.cpp new file mode 100644 index 00000000..35d1270e --- /dev/null +++ b/src/ipa/rpi/controller/rpi/awb_nn.cpp @@ -0,0 +1,446 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2025, Raspberry Pi Ltd + * + * AWB control algorithm using neural network + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "../awb_algorithm.h" +#include "../awb_status.h" +#include "../lux_status.h" +#include "libipa/pwl.h" + +#include "alsc_status.h" +#include "awb.h" + +using namespace libcamera; + +LOG_DECLARE_CATEGORY(RPiAwb) + +constexpr double kDefaultCT = 4500.0; + +/* + * The neural networks are trained to work on images rendered at a canonical + * colour temperature. That value is 5000K, which must be reproduced here. + */ +constexpr double kNetworkCanonicalCT = 5000.0; + +#define NAME "rpi.nn.awb" + +namespace RPiController { + +struct AwbNNConfig { + AwbNNConfig() {} + int read(const libcamera::YamlObject ¶ms, AwbConfig &config); + + /* An empty model will check default locations for model.tflite */ + std::string model; + float minTemp; + float maxTemp; + + bool enableNn; + + /* CCM matrix for canonical network CT */ + double ccm[9]; +}; + +class AwbNN : public Awb +{ +public: + AwbNN(Controller *controller = NULL); + ~AwbNN(); + char const *name() const override; + void initialise() override; + int read(const libcamera::YamlObject ¶ms) override; + +protected: + void doAwb() override; + void prepareStats() override; + +private: + bool isAutoEnabled() const; + AwbNNConfig nnConfig_; + void transverseSearch(double t, double &r, double &b); + RGB processZone(RGB zone, float red_gain, float blue_gain); + void awbNN(); + void loadModel(); + + libcamera::Size zoneSize_; + std::unique_ptr model_; + std::unique_ptr interpreter_; +}; + +int AwbNNConfig::read(const libcamera::YamlObject ¶ms, AwbConfig &config) +{ + model = params["model"].get(""); + minTemp = params["min_temp"].get(2800.0); + maxTemp = params["max_temp"].get(7600.0); + + for (int i = 0; i < 9; i++) + ccm[i] = params["ccm"][i].get(0.0); + + enableNn = params["enable_nn"].get(1); + + if (enableNn) { + if (!config.hasCtCurve()) { + LOG(RPiAwb, Error) << "CT curve not specified"; + enableNn = false; + } + + if (!model.empty() && model.find(".tflite") == std::string::npos) { + LOG(RPiAwb, Error) << "Model must be a .tflite file"; + enableNn = false; + } + + bool validCcm = true; + for (int i = 0; i < 9; i++) + if (ccm[i] == 0.0) + validCcm = false; + + if (!validCcm) { + LOG(RPiAwb, Error) << "CCM not specified or invalid"; + enableNn = false; + } + + if (!enableNn) { + LOG(RPiAwb, Warning) << "Neural Network AWB mis-configured - switch to Grey method"; + } + } + + if (!enableNn) { + config.sensitivityR = config.sensitivityB = 1.0; + config.greyWorld = true; + } + + return 0; +} + +AwbNN::AwbNN(Controller *controller) + : Awb(controller) +{ + zoneSize_ = getHardwareConfig().awbRegions; +} + +AwbNN::~AwbNN() +{ +} + +char const *AwbNN::name() const +{ + return NAME; +} + +int AwbNN::read(const libcamera::YamlObject ¶ms) +{ + int ret; + + ret = config_.read(params); + if (ret) + return ret; + + ret = nnConfig_.read(params, config_); + if (ret) + return ret; + + return 0; +} + +static bool checkTensorShape(TfLiteTensor *tensor, const int *expectedDims, const int expectedDimsSize) +{ + if (tensor->dims->size != expectedDimsSize) + return false; + + for (int i = 0; i < tensor->dims->size; i++) { + if (tensor->dims->data[i] != expectedDims[i]) { + return false; + } + } + return true; +} + +static std::string buildDimString(const int *dims, const int dimsSize) +{ + std::string s = "["; + for (int i = 0; i < dimsSize; i++) { + s += std::to_string(dims[i]); + if (i < dimsSize - 1) + s += ","; + else + s += "]"; + } + return s; +} + +void AwbNN::loadModel() +{ + std::string modelPath; + if (getTarget() == "bcm2835") { + modelPath = "/ipa/rpi/vc4/awb_model.tflite"; + } else { + modelPath = "/ipa/rpi/pisp/awb_model.tflite"; + } + + if (nnConfig_.model.empty()) { + std::string root = utils::libcameraSourcePath(); + if (!root.empty()) { + modelPath = root + modelPath; + } else { + modelPath = LIBCAMERA_DATA_DIR + modelPath; + } + + if (!File::exists(modelPath)) { + LOG(RPiAwb, Error) << "No model file found in standard locations"; + nnConfig_.enableNn = false; + return; + } + } else { + modelPath = nnConfig_.model; + } + + LOG(RPiAwb, Debug) << "Attempting to load model from: " << modelPath; + + model_ = tflite::FlatBufferModel::BuildFromFile(modelPath.c_str()); + + if (!model_) { + LOG(RPiAwb, Error) << "Failed to load model from " << modelPath; + nnConfig_.enableNn = false; + return; + } + + tflite::MutableOpResolver resolver; + tflite::ops::builtin::BuiltinOpResolver builtin_resolver; + resolver.AddAll(builtin_resolver); + tflite::InterpreterBuilder(*model_, resolver)(&interpreter_); + if (!interpreter_) { + LOG(RPiAwb, Error) << "Failed to build interpreter for model " << nnConfig_.model; + nnConfig_.enableNn = false; + return; + } + + interpreter_->AllocateTensors(); + TfLiteTensor *inputTensor = interpreter_->input_tensor(0); + TfLiteTensor *inputLuxTensor = interpreter_->input_tensor(1); + TfLiteTensor *outputTensor = interpreter_->output_tensor(0); + if (!inputTensor || !inputLuxTensor || !outputTensor) { + LOG(RPiAwb, Error) << "Model missing input or output tensor"; + nnConfig_.enableNn = false; + return; + } + + const int expectedInputDims[] = { 1, (int)zoneSize_.height, (int)zoneSize_.width, 3 }; + const int expectedInputLuxDims[] = { 1 }; + const int expectedOutputDims[] = { 1 }; + + if (!checkTensorShape(inputTensor, expectedInputDims, 4)) { + LOG(RPiAwb, Error) << "Model input tensor dimension mismatch. Expected: " << buildDimString(expectedInputDims, 4) + << ", Got: " << buildDimString(inputTensor->dims->data, inputTensor->dims->size); + nnConfig_.enableNn = false; + return; + } + + if (!checkTensorShape(inputLuxTensor, expectedInputLuxDims, 1)) { + LOG(RPiAwb, Error) << "Model input lux tensor dimension mismatch. Expected: " << buildDimString(expectedInputLuxDims, 1) + << ", Got: " << buildDimString(inputLuxTensor->dims->data, inputLuxTensor->dims->size); + nnConfig_.enableNn = false; + return; + } + + if (!checkTensorShape(outputTensor, expectedOutputDims, 1)) { + LOG(RPiAwb, Error) << "Model output tensor dimension mismatch. Expected: " << buildDimString(expectedOutputDims, 1) + << ", Got: " << buildDimString(outputTensor->dims->data, outputTensor->dims->size); + nnConfig_.enableNn = false; + return; + } + + if (inputTensor->type != kTfLiteFloat32 || inputLuxTensor->type != kTfLiteFloat32 || outputTensor->type != kTfLiteFloat32) { + LOG(RPiAwb, Error) << "Model input and output tensors must be float32"; + nnConfig_.enableNn = false; + return; + } + + LOG(RPiAwb, Info) << "Model loaded successfully from " << modelPath; + LOG(RPiAwb, Debug) << "Model validation successful - Input Image: " + << buildDimString(expectedInputDims, 4) + << ", Input Lux: " << buildDimString(expectedInputLuxDims, 1) + << ", Output: " << buildDimString(expectedOutputDims, 1) << " floats"; +} + +void AwbNN::initialise() +{ + Awb::initialise(); + + if (nnConfig_.enableNn) { + loadModel(); + if (!nnConfig_.enableNn) { + LOG(RPiAwb, Warning) << "Neural Network AWB failed to load - switch to Grey method"; + config_.greyWorld = true; + config_.sensitivityR = config_.sensitivityB = 1.0; + } + } +} + +void AwbNN::prepareStats() +{ + zones_.clear(); + /* + * LSC has already been applied to the stats in this pipeline, so stop + * any LSC compensation. We also ignore config_.fast in this version. + */ + generateStats(zones_, statistics_, 0.0, 0.0, getGlobalMetadata(), 0.0, 0.0, 0.0); + /* + * apply sensitivities, so values appear to come from our "canonical" + * sensor. + */ + for (auto &zone : zones_) { + zone.R *= config_.sensitivityR; + zone.B *= config_.sensitivityB; + } +} + +void AwbNN::transverseSearch(double t, double &r, double &b) +{ + int spanR = -1, spanB = -1; + config_.ctR.eval(t, &spanR); + config_.ctB.eval(t, &spanB); + + const int diff = 10; + double rDiff = config_.ctR.eval(t + diff, &spanR) - + config_.ctR.eval(t - diff, &spanR); + double bDiff = config_.ctB.eval(t + diff, &spanB) - + config_.ctB.eval(t - diff, &spanB); + + ipa::Pwl::Point transverse({ bDiff, -rDiff }); + if (transverse.length2() < 1e-6) + return; + + transverse = transverse / transverse.length(); + double transverseRange = config_.transverseNeg + config_.transversePos; + const int maxNumDeltas = 12; + int numDeltas = floor(transverseRange * 100 + 0.5) + 1; + numDeltas = numDeltas < 3 ? 3 : (numDeltas > maxNumDeltas ? maxNumDeltas : numDeltas); + + ipa::Pwl::Point points[maxNumDeltas]; + int bestPoint = 0; + + for (int i = 0; i < numDeltas; i++) { + points[i][0] = -config_.transverseNeg + + (transverseRange * i) / (numDeltas - 1); + ipa::Pwl::Point rbTest = ipa::Pwl::Point({ r, b }) + + transverse * points[i].x(); + double rTest = rbTest.x(), bTest = rbTest.y(); + double gainR = 1 / rTest, gainB = 1 / bTest; + double delta2Sum = computeDelta2Sum(gainR, gainB, 0.0, 0.0); + points[i][1] = delta2Sum; + if (points[i].y() < points[bestPoint].y()) + bestPoint = i; + } + + bestPoint = std::clamp(bestPoint, 1, numDeltas - 2); + ipa::Pwl::Point rbBest = ipa::Pwl::Point({ r, b }) + + transverse * interpolateQuadatric(points[bestPoint - 1], + points[bestPoint], + points[bestPoint + 1]); + double rBest = rbBest.x(), bBest = rbBest.y(); + + r = rBest, b = bBest; +} + +AwbNN::RGB AwbNN::processZone(AwbNN::RGB zone, float redGain, float blueGain) +{ + /* + * Renders the pixel at canonical network colour temperature + */ + RGB zoneGains = zone; + + zoneGains.R *= redGain; + zoneGains.G *= 1.0; + zoneGains.B *= blueGain; + + RGB zoneCcm; + + zoneCcm.R = nnConfig_.ccm[0] * zoneGains.R + nnConfig_.ccm[1] * zoneGains.G + nnConfig_.ccm[2] * zoneGains.B; + zoneCcm.G = nnConfig_.ccm[3] * zoneGains.R + nnConfig_.ccm[4] * zoneGains.G + nnConfig_.ccm[5] * zoneGains.B; + zoneCcm.B = nnConfig_.ccm[6] * zoneGains.R + nnConfig_.ccm[7] * zoneGains.G + nnConfig_.ccm[8] * zoneGains.B; + + return zoneCcm; +} + +void AwbNN::awbNN() +{ + float *inputData = interpreter_->typed_input_tensor(0); + float *inputLux = interpreter_->typed_input_tensor(1); + + float redGain = 1.0 / config_.ctR.eval(kNetworkCanonicalCT); + float blueGain = 1.0 / config_.ctB.eval(kNetworkCanonicalCT); + + for (uint i = 0; i < zoneSize_.height; i++) { + for (uint j = 0; j < zoneSize_.width; j++) { + uint zoneIdx = i * zoneSize_.width + j; + + RGB processedZone = processZone(zones_[zoneIdx] * (1.0 / 65535), redGain, blueGain); + uint baseIdx = zoneIdx * 3; + + inputData[baseIdx + 0] = static_cast(processedZone.R); + inputData[baseIdx + 1] = static_cast(processedZone.G); + inputData[baseIdx + 2] = static_cast(processedZone.B); + } + } + + inputLux[0] = static_cast(lux_); + + TfLiteStatus status = interpreter_->Invoke(); + if (status != kTfLiteOk) { + LOG(RPiAwb, Error) << "Model inference failed with status: " << status; + return; + } + + float *outputData = interpreter_->typed_output_tensor(0); + + double t = outputData[0]; + + LOG(RPiAwb, Debug) << "Model output temperature: " << t; + + t = std::clamp(t, mode_->ctLo, mode_->ctHi); + + double r = config_.ctR.eval(t); + double b = config_.ctB.eval(t); + + transverseSearch(t, r, b); + + LOG(RPiAwb, Debug) << "After transverse search: Temperature: " << t << " Red gain: " << 1.0 / r << " Blue gain: " << 1.0 / b; + + asyncResults_.temperatureK = t; + asyncResults_.gainR = 1.0 / r * config_.sensitivityR; + asyncResults_.gainG = 1.0; + asyncResults_.gainB = 1.0 / b * config_.sensitivityB; +} + +void AwbNN::doAwb() +{ + prepareStats(); + if (zones_.size() == (zoneSize_.width * zoneSize_.height) && nnConfig_.enableNn) + awbNN(); + else + awbGrey(); + statistics_.reset(); +} + +/* Register algorithm with the system. */ +static Algorithm *create(Controller *controller) +{ + return (Algorithm *)new AwbNN(controller); +} +static RegisterAlgorithm reg(NAME, &create); + +} /* namespace RPiController */ From patchwork Thu Dec 11 14:25:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 25492 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 62326C3257 for ; Thu, 11 Dec 2025 14:28:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 25A4461611; Thu, 11 Dec 2025 15:28:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="KVIGp16U"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C5ACA609D8 for ; Thu, 11 Dec 2025 15:28:39 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-477632b0621so1166045e9.2 for ; Thu, 11 Dec 2025 06:28:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1765463318; x=1766068118; 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=N8NQVZIfa3n6pCIMXHC7zSmvquRdnC5K6hTQKElvxqE=; b=KVIGp16Uxg5W2jRyKzd44OCLIFG7SXF2Cn3VVUwIKiJH8sukb3z3lfUhIT4BTlQiQY 4lra4xwbM9Ua4e/1Eln+r+QjBszzowajN/YYADN+VEIUYuwe25ImeN5d0oc1Je6ot8uI oUZBoEb/6cXFabTfKASsz9ZlZTjQp0s4m+Jx+bsU5uI9vLiN4VPxgTXbMpBksAf6BjB3 uMgHeRVjzvfX/AIlCQP44Meg+ozogZRUNSiQHRLPfZUzwZI+ZA+kNNX06HJpZSIGkvoT ToIN0Z3LQEnmZa1Mv8YyIAcVyLfTlcAZMe8J8/moDWsimMKn0YOVxc9NX/cDXbeRAlyZ o+TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765463318; x=1766068118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=N8NQVZIfa3n6pCIMXHC7zSmvquRdnC5K6hTQKElvxqE=; b=WDSYqUtEgmbPkt+MAswu/k1Iary6p3UTJzHBvnZIZ+rXU/Iu6s+8LvJTYFeLEvTq9i dZkHKTpcZH5iMV2TCkFMO8e4mMBAl5IrnWdBjybn2Lqmhzl8lwZ5+8//HNZ3sbom62E8 U3ayhxgbR8cI5hj3L4mV3R6nGrFqgG9ZU9wZWqmJ0Gyte0qAby757dPuVgG3Z7QL+EIF cCbriy9Gns1KCNWoG047y9HmCeDIGelj8UThoggziZd8IOwYebWd/Y+GBu++UOvcPGje e8XKlLXJ4Sw4d9BMIOjiFYqgRmGo33BWryEO6ctvv/pRnCyNYW73R0pfe+zG/BYs+Yhm uovg== X-Gm-Message-State: AOJu0YwhXBGA+v2bF8TcSwIIOnqxjFzbzZn4lT2vHKYcZwy0ESjGw/gK TApOx8VNIAKGhSmVw7LI2ADMsEkbCW7EF2PakzbQbSyFI1Qr7fcPWn4qunAhLaFN/h8dOxy/V1K JLn4y X-Gm-Gg: AY/fxX72MqpDL80aARwtB1YQyWquS5DzJgFy0Jrq+CRJhE8ezqn9E5f+nu9agCFva7A +QAv/oMQZ87fugtvSmGIjXJmDSZqWxRC5aWJvW7nB5B73qRmmBpJbQ3483FubQ7g5Sw0/JqNTv+ 1JBB9mwSwZ1uJv52I5gg75luTa81Po0jj5JPcA4aG00kO5fq+/BTbL09D3sYluBKA/jMmejwpWT /aav9Tiswj2SB/LGHN8cK91IBTyXmD9sSxGW7agbygy/hYmp0+A1xaha/INAQU8sMbDkz8x4hIR XjO1QBNKKEVUnmmAb5fvOgAlVNQTqP56Z9n6ozzwN/dGVwR4TIhjnjNR3UaVu5DGGpHXr3888E2 qT6j0GJ+J0zTdROOLeTBHkd9kpALg5EQ00iIK6SnlrUxL9IZMYdpMVADbgK4tpbArlJHYmN4JN4 sMJYAVDJiLZbzDQZ0+GBhI76p3TZ+2tA1LHAlDnO+niaieupBS+M4ktXMDLB6zZ7ICdJzNLxDm1 jU4Bi7rBo8fubXy81oN9KPYiIoGRA== X-Google-Smtp-Source: AGHT+IEVH5Ewcj0cCLIupuzOYkj8PTTKOUZcmamm6ZzfJ3rwtz9rtA14FkysBUn4PIWrh9JILJ6CNA== X-Received: by 2002:a05:600c:4e92:b0:477:9976:9e1a with SMTP id 5b1f17b1804b1-47a8374de44mr64900855e9.6.1765463318017; Thu, 11 Dec 2025 06:28:38 -0800 (PST) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a89da4756sm39999505e9.6.2025.12.11.06.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:28:31 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: Peter Bailey Subject: [PATCH v2 3/4] ipa: rpi: controller: Ignore algorithms that are not enabled Date: Thu, 11 Dec 2025 14:25:59 +0000 Message-ID: <20251211142824.26635-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211142824.26635-1-david.plowman@raspberrypi.com> References: <20251211142824.26635-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 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" From: Peter Bailey Algorithms may now contain an "enabled" field which can be set to false to disable it and prevent it from being loaded. If not present, algorithms are treated as enabled by default for backwards compatability. We additionally prevent duplicate versions of the same algorithm type (such as AWB) from loading, and flag an error. This will prevent undefined behaviour if (for example) two distinct AWB algorithms are trying to run simultaneously. Signed-off-by: Peter Bailey --- src/ipa/rpi/controller/controller.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index df45dcd3..88de6f36 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -145,6 +145,14 @@ int Controller::read(char const *filename) int Controller::createAlgorithm(const std::string &name, const YamlObject ¶ms) { + /* Any algorithm may be disabled by setting "enabled" to false. */ + bool enabled = params["enabled"].get(true); + LOG(RPiController, Debug) + << "Algorithm " << name << ": " + << (enabled ? "enabled" : "disabled"); + if (!enabled) + return 0; + auto it = getAlgorithms().find(name); if (it == getAlgorithms().end()) { LOG(RPiController, Warning) @@ -152,6 +160,16 @@ int Controller::createAlgorithm(const std::string &name, const YamlObject ¶m return 0; } + /* Do not allow duplicate versions of algorithms (e.g. AWB) to run. */ + size_t pos = name.find_last_of('.'); + std::string const &algoType = + pos == std::string::npos ? name : name.substr(pos + 1); + if (getAlgorithm(algoType)) { + LOG(RPiController, Error) + << "Algorithm type '" << algoType << "' already exists"; + return -1; + } + Algorithm *algo = (*it->second)(this); int ret = algo->read(params); if (ret) From patchwork Thu Dec 11 14:26:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 25493 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 EDD15C3257 for ; Thu, 11 Dec 2025 14:28:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E28E6161F; Thu, 11 Dec 2025 15:28:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Yg/Pe4Fa"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF09161603 for ; Thu, 11 Dec 2025 15:28:42 +0100 (CET) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-477b5e0323bso813295e9.0 for ; Thu, 11 Dec 2025 06:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1765463321; x=1766068121; 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=zTMN39BF9BstHzakjdvxIJN4iFqzDjGoU62DbeVKL54=; b=Yg/Pe4FaBnNUDLYvrIgZ/3xxO0zslJXtY8aGORrbVvqEgeJN/Q3E5we8zmhpV1GOqg XuODYxk1FGU1gJyyTICkIl4OEAcRyXp39yOknfCRj/5rYy59XN5YdQL1xSjCXZN7YvS+ BFNYiXW42w/capRGkLzHzpE46lY5IMZpfuqGPe1y9AqMjEt5SKep9SlaSHrM1vfUnPku yRjT5h2ciKuccPCuX18/e/6xhKKUBVlwUXCWjqqII2D+Iipl9cnaf3J28U9W4MUtAgv3 7ds+8OMhvx3MrWOzGrhlWfmtP9nR6UN3+1crFw7zYKkuIWTqW/AjeMMd75XRvs+CnCFe CHrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765463321; x=1766068121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zTMN39BF9BstHzakjdvxIJN4iFqzDjGoU62DbeVKL54=; b=VOb+D0Ai2K9LY8kz4jDR0OQZVl0cZtG62Xy/RI+1WgJn8yIG48InBhAZIiT9opx9J9 36bNmrkn2U39pyiwUqwKrw6RHd1UtlLv7itTdrpH3MNvWgyn8lYxDTSUJ4n4lTbMlUxF kU0XjkVDvdmTHw2fTtTlA6tV9W7h+BwbbZpAZaAvv3XupqE3vD6O+InfxwFPwP2QjrQY BF0OWF6FiLzxn29xaJQt4WeR3VgWBthJsOAFIEyTV19LPqg97F6OzCnf/Rshu6akNbYt Bh3Gnm2tuAInmrFeYJKJsvNlCNI5RC8bBOiw3TREdnfQJ7l0kpMuBmXfsqPg7/OvsvvF lGNw== X-Gm-Message-State: AOJu0YwTprLuol5TQ2UNSkC8bQb6Ey+PyuW9AyrO2KzOKe+b9VRd9K4F b+7ncHaHEjc/UKev+TWbTi5BaX09+S9oHjvRbsfaaeyED0mt9k0e9nlAjjnAFm6nHrNzXTs7wc+ WWcqp X-Gm-Gg: AY/fxX7ho8sZR+mLUOThiXeKHJvlL3Y/ihpciiiiM9YOX92eOR2JGS04gZJpSSZnBOw QVvcg3fmbX5ADlbBt8+c8Am641wo4p/R9Zc85JlIIU3JLurODQU+yWuxZv6mOx0DTpPlqLqYPp+ rm2Ivpsl7a9qcYfudr4Vx/krtrJTzt+TL2nziMdZCeT6wbFWR3As77/MUNJg0BtJdXb+zg7NcB4 /fe12ybj8OkNH9wLG7RjH+hycliZxFxRTmImVVvWoqK6nRilfeASgKtkJ61RCXCI9e1wKRzVdu4 aSnKl339sBvVeVznbLZdbDFPI85JoybzPXJNESO0/c+KV6nyH0U0lacwR3keLMPcAuXuq7dC8aF ACsHOI1m2W3fEN7ZeQpDFGYxHRT6cSLFW1+Y4ERMyp0X/lUojjsqKLdIOlSsFZppVbK0s1CDUH3 n/kcgF23GD7j0dvRhHKQyEt3HYhobvWh10etjt4JBS7PO2KcOz4RCth48UHsZHlnV+umB7+5K3M Jn4n8ZP/5ZBsb64OxWQ4PzK/DO1RQ== X-Google-Smtp-Source: AGHT+IEyRS+PlJdMatX19+2v/ZTD19Nbv2NYurHNa/ABZVRfw6DlAuhFWloGcy0MUwsWrNsu8SiiJg== X-Received: by 2002:a05:600c:4d98:b0:477:5639:ff66 with SMTP id 5b1f17b1804b1-47a89ed5c1emr16318915e9.13.1765463320843; Thu, 11 Dec 2025 06:28:40 -0800 (PST) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a89da4756sm39999505e9.6.2025.12.11.06.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:28:38 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: Peter Bailey Subject: [PATCH v2 4/4] ipa: rpi: pisp: vc4: Update tuning files for new AWB Date: Thu, 11 Dec 2025 14:26:00 +0000 Message-ID: <20251211142824.26635-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211142824.26635-1-david.plowman@raspberrypi.com> References: <20251211142824.26635-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 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" From: Peter Bailey Update the tuning files to include the new AWB algorithm. It is enabled by setting "enabled" to true for the AWB algorithm that you want, and the same field to false for the one you don't want. Note that you may enable only one of the two algorithms! The AWB models themselves are not included with libcamera. They will be supplied from the Raspberry Pi software repositories. Signed-off-by: Peter Bailey --- src/ipa/rpi/pisp/data/imx219.json | 67 +++++++++++++++- src/ipa/rpi/pisp/data/imx296.json | 66 +++++++++++++++- src/ipa/rpi/pisp/data/imx296_16mm.json | 66 +++++++++++++++- src/ipa/rpi/pisp/data/imx296_6mm.json | 66 +++++++++++++++- src/ipa/rpi/pisp/data/imx477.json | 65 ++++++++++++++++ src/ipa/rpi/pisp/data/imx477_16mm.json | 67 +++++++++++++++- src/ipa/rpi/pisp/data/imx477_6mm.json | 67 +++++++++++++++- src/ipa/rpi/pisp/data/imx477_scientific.json | 81 +++++++++++++++++++- src/ipa/rpi/pisp/data/imx500.json | 69 +++++++++++++++++ src/ipa/rpi/pisp/data/imx708.json | 66 +++++++++++++++- src/ipa/rpi/pisp/data/imx708_wide.json | 64 ++++++++++++++++ src/ipa/rpi/pisp/data/ov5647.json | 65 ++++++++++++++++ src/ipa/rpi/vc4/data/imx219.json | 66 ++++++++++++++++ src/ipa/rpi/vc4/data/imx296.json | 66 ++++++++++++++++ src/ipa/rpi/vc4/data/imx477.json | 71 +++++++++++++++++ src/ipa/rpi/vc4/data/imx500.json | 69 +++++++++++++++++ src/ipa/rpi/vc4/data/imx708.json | 74 ++++++++++++++++++ src/ipa/rpi/vc4/data/imx708_wide.json | 64 ++++++++++++++++ src/ipa/rpi/vc4/data/ov5647.json | 66 ++++++++++++++++ 19 files changed, 1277 insertions(+), 8 deletions(-) diff --git a/src/ipa/rpi/pisp/data/imx219.json b/src/ipa/rpi/pisp/data/imx219.json index df620b0f..c8dc65a3 100644 --- a/src/ipa/rpi/pisp/data/imx219.json +++ b/src/ipa/rpi/pisp/data/imx219.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -195,6 +196,70 @@ "transverse_neg": 0.034 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2860.0, 0.9514, 0.4156, + 2960.0, 0.9289, 0.4372, + 3603.0, 0.8305, 0.5251, + 4650.0, 0.6756, 0.6433, + 5858.0, 0.6193, 0.6807, + 7580.0, 0.5019, 0.7495 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.03392, + "transverse_neg": 0.034, + "ccm": + [ + 2.2229345364238413, -0.7596721523178808, -0.46326238410596027, + -0.6834893874172185, 2.7118816887417223, -1.02839940397351, + -0.2613746357615894, -0.668015927152318, 1.9293905629139072 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1205,6 +1270,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx296.json b/src/ipa/rpi/pisp/data/imx296.json index 9ea9a69b..3cfda121 100644 --- a/src/ipa/rpi/pisp/data/imx296.json +++ b/src/ipa/rpi/pisp/data/imx296.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -194,6 +195,69 @@ "transverse_neg": 0.02154 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2875.0, 0.4699, 0.3209, + 3610.0, 0.4089, 0.4265, + 4640.0, 0.3281, 0.5417, + 5912.0, 0.2992, 0.5771, + 7630.0, 0.2285, 0.6524 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.01783, + "transverse_neg": 0.02154, + "ccm": + [ + 2.1073753846153847, -0.8054946153846154, -0.30188076923076923, + -0.43306999999999995, 2.162828076923077, -0.7297680769230768, + -0.126655, -0.5027626923076922, 1.6294176923076922 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1212,6 +1276,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx296_16mm.json b/src/ipa/rpi/pisp/data/imx296_16mm.json index 0c95d81e..c64bcb65 100644 --- a/src/ipa/rpi/pisp/data/imx296_16mm.json +++ b/src/ipa/rpi/pisp/data/imx296_16mm.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -194,6 +195,69 @@ "transverse_neg": 0.02154 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2875.0, 0.4699, 0.3209, + 3610.0, 0.4089, 0.4265, + 4640.0, 0.3281, 0.5417, + 5912.0, 0.2992, 0.5771, + 7630.0, 0.2285, 0.6524 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.01783, + "transverse_neg": 0.02154, + "ccm": + [ + 2.1073753846153847, -0.8054946153846154, -0.30188076923076923, + -0.43306999999999995, 2.162828076923077, -0.7297680769230768, + -0.126655, -0.5027626923076922, 1.6294176923076922 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1265,6 +1329,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx296_6mm.json b/src/ipa/rpi/pisp/data/imx296_6mm.json index 37ca85fb..b980221f 100644 --- a/src/ipa/rpi/pisp/data/imx296_6mm.json +++ b/src/ipa/rpi/pisp/data/imx296_6mm.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -194,6 +195,69 @@ "transverse_neg": 0.02154 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2875.0, 0.4699, 0.3209, + 3610.0, 0.4089, 0.4265, + 4640.0, 0.3281, 0.5417, + 5912.0, 0.2992, 0.5771, + 7630.0, 0.2285, 0.6524 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.01783, + "transverse_neg": 0.02154, + "ccm": + [ + 2.1073753846153847, -0.8054946153846154, -0.30188076923076923, + -0.43306999999999995, 2.162828076923077, -0.7297680769230768, + -0.126655, -0.5027626923076922, 1.6294176923076922 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1265,6 +1329,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx477.json b/src/ipa/rpi/pisp/data/imx477.json index 4806cdb1..829f5e9f 100644 --- a/src/ipa/rpi/pisp/data/imx477.json +++ b/src/ipa/rpi/pisp/data/imx477.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -195,6 +196,70 @@ "transverse_neg": 0.02255 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2850.0, 0.4307, 0.3957, + 2960.0, 0.4159, 0.4313, + 3580.0, 0.3771, 0.5176, + 4559.0, 0.3031, 0.6573, + 5881.0, 0.2809, 0.6942, + 7600.0, 0.2263, 0.7762 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.02634, + "transverse_neg": 0.02255, + "ccm": + [ + 2.1643743343419066, -0.972589984871407, -0.19177768532526474, + -0.3769567095310136, 2.0993768608169443, -0.722416815431165, + -0.11786965204236007, -0.4893621633888049, 1.607231815431165 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/pisp/data/imx477_16mm.json b/src/ipa/rpi/pisp/data/imx477_16mm.json index 65f73bf3..72161ff5 100644 --- a/src/ipa/rpi/pisp/data/imx477_16mm.json +++ b/src/ipa/rpi/pisp/data/imx477_16mm.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -195,6 +196,70 @@ "transverse_neg": 0.02255 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2850.0, 0.4307, 0.3957, + 2960.0, 0.4159, 0.4313, + 3580.0, 0.3771, 0.5176, + 4559.0, 0.3031, 0.6573, + 5881.0, 0.2809, 0.6942, + 7600.0, 0.2263, 0.7762 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.02634, + "transverse_neg": 0.02255, + "ccm": + [ + 2.1643743343419066, -0.972589984871407, -0.19177768532526474, + -0.3769567095310136, 2.0993768608169443, -0.722416815431165, + -0.11786965204236007, -0.4893621633888049, 1.607231815431165 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1258,6 +1323,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx477_6mm.json b/src/ipa/rpi/pisp/data/imx477_6mm.json index 2c9c65a1..d7a42443 100644 --- a/src/ipa/rpi/pisp/data/imx477_6mm.json +++ b/src/ipa/rpi/pisp/data/imx477_6mm.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -195,6 +196,70 @@ "transverse_neg": 0.02255 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2850.0, 0.4307, 0.3957, + 2960.0, 0.4159, 0.4313, + 3580.0, 0.3771, 0.5176, + 4559.0, 0.3031, 0.6573, + 5881.0, 0.2809, 0.6942, + 7600.0, 0.2263, 0.7762 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.02634, + "transverse_neg": 0.02255, + "ccm": + [ + 2.1643743343419066, -0.972589984871407, -0.19177768532526474, + -0.3769567095310136, 2.0993768608169443, -0.722416815431165, + -0.11786965204236007, -0.4893621633888049, 1.607231815431165 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1258,6 +1323,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx477_scientific.json b/src/ipa/rpi/pisp/data/imx477_scientific.json index 3b7e7e31..a57b3f3c 100644 --- a/src/ipa/rpi/pisp/data/imx477_scientific.json +++ b/src/ipa/rpi/pisp/data/imx477_scientific.json @@ -64,6 +64,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -164,6 +165,84 @@ "coarse_step": 0.1 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2000.0, 0.6331025775790707, 0.27424225990946915, + 2200.0, 0.5696117366212947, 0.3116091368689487, + 2400.0, 0.5204264653110015, 0.34892179554105873, + 2600.0, 0.48148675531667223, 0.38565229719076793, + 2800.0, 0.450085403501908, 0.42145684622485047, + 3000.0, 0.42436130159169017, 0.45611835670028816, + 3200.0, 0.40300023695527337, 0.48950766215198593, + 3400.0, 0.3850520052612984, 0.5215567075837261, + 3600.0, 0.36981508088230314, 0.5522397906415475, + 4100.0, 0.333468007836758, 0.5909770465167908, + 4600.0, 0.31196097364221376, 0.6515706327327178, + 5100.0, 0.2961860409294588, 0.7068178946570284, + 5600.0, 0.2842607232745885, 0.7564837749584288, + 6100.0, 0.2750265787051251, 0.8006183524920533, + 6600.0, 0.2677057225584924, 0.8398879225373039, + 7100.0, 0.2617955199757274, 0.8746456080032436, + 7600.0, 0.25693714288250125, 0.905569559506562, + 8100.0, 0.25287531441063316, 0.9331696750390895, + 8600.0, 0.24946601483331993, 0.9576820904825795 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.0238, + "transverse_neg": 0.04429, + "coarse_step": 0.1, + "ccm": + [ + 2.003815467921944, -1.0081613204143252, 0.005840157117467748, + -0.18090523909630973, 1.597736399205449, -0.4326323675585491, + 0.05055066369087284, -0.6057020512156361, 1.5577256973300102 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -546,6 +625,6 @@ "rpi.sync": { } - } + } ] } \ No newline at end of file diff --git a/src/ipa/rpi/pisp/data/imx500.json b/src/ipa/rpi/pisp/data/imx500.json index 59a2aac5..878a597e 100644 --- a/src/ipa/rpi/pisp/data/imx500.json +++ b/src/ipa/rpi/pisp/data/imx500.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -199,6 +200,74 @@ "transverse_neg": 0.02678 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2800, + "hi": 7700 + }, + "incandescent": + { + "lo": 2800, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 7600 + } + }, + "ct_curve": + [ + 2800.0, 0.7115, 0.3579, + 2860.0, 0.6671, 0.4058, + 2880.0, 0.6641, 0.4089, + 3580.0, 0.5665, 0.5113, + 3650.0, 0.5621, 0.5159, + 4500.0, 0.4799, 0.5997, + 4570.0, 0.4752, 0.6046, + 5648.0, 0.4139, 0.6657, + 5717.0, 0.4118, 0.6678, + 7600.0, 0.3625, 0.7162 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.02822, + "transverse_neg": 0.02678, + "ccm": + [ + 1.6753287012987015, -0.4685774582560297, -0.20675124304267162, + -0.3610687012987013, 1.906408293135436, -0.5453335807050093, + -0.057295510204081634, -0.48813066790352505, 1.5454261781076069 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/pisp/data/imx708.json b/src/ipa/rpi/pisp/data/imx708.json index f720926a..5483690f 100644 --- a/src/ipa/rpi/pisp/data/imx708.json +++ b/src/ipa/rpi/pisp/data/imx708.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -194,6 +195,69 @@ "transverse_neg": 0.01831 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2964.0, 0.7451, 0.3213, + 3610.0, 0.6119, 0.4443, + 4640.0, 0.5168, 0.5419, + 5910.0, 0.4436, 0.6229, + 7590.0, 0.3847, 0.6921 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.01752, + "transverse_neg": 0.01831, + "ccm": + [ + 1.5407949606299214, -0.3714970078740158, -0.16929511811023623, + -0.2801589763779528, 1.649028503937008, -0.36886236220472446, + 0.004032519685039371, -0.5251851181102363, 1.521162598425197 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { @@ -1305,6 +1369,6 @@ "rpi.sync": { } - } + } ] } diff --git a/src/ipa/rpi/pisp/data/imx708_wide.json b/src/ipa/rpi/pisp/data/imx708_wide.json index 61eae816..dad774ec 100644 --- a/src/ipa/rpi/pisp/data/imx708_wide.json +++ b/src/ipa/rpi/pisp/data/imx708_wide.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -194,6 +195,69 @@ "transverse_neg": 0.01376 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2868.0, 0.6419, 0.3613, + 3603.0, 0.5374, 0.4787, + 4620.0, 0.4482, 0.5813, + 5901.0, 0.3883, 0.6514, + 7610.0, 0.3279, 0.7232 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.01908, + "transverse_neg": 0.01376, + "ccm": + [ + 1.5820866588602653, -0.39406808743169397, -0.1880145042935207, + -0.3101711553473849, 1.756938087431694, -0.44677099921935987, + -0.018062732240437158, -0.5139293442622951, 1.5319991100702577 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/pisp/data/ov5647.json b/src/ipa/rpi/pisp/data/ov5647.json index b2ea8a89..dded3f84 100644 --- a/src/ipa/rpi/pisp/data/ov5647.json +++ b/src/ipa/rpi/pisp/data/ov5647.json @@ -109,6 +109,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -195,6 +196,70 @@ "transverse_neg": 0.03906 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7700 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8000 + } + }, + "ct_curve": + [ + 2873.0, 1.0463, 0.5142, + 2965.0, 1.0233, 0.5284, + 3606.0, 0.8947, 0.6314, + 4700.0, 0.7665, 0.7897, + 5890.0, 0.7055, 0.8933, + 7600.0, 0.6482, 1.0119 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.04072, + "transverse_neg": 0.03906, + "ccm": + [ + 2.041588151260504, -0.5494553781512606, -0.49214025210084034, + -0.5116488235294118, 1.9901442857142857, -0.47849546218487393, + -0.10519773109243696, -0.641700168067227, 1.7468953781512604 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/imx219.json b/src/ipa/rpi/vc4/data/imx219.json index c2ed49a0..6ff5cec4 100644 --- a/src/ipa/rpi/vc4/data/imx219.json +++ b/src/ipa/rpi/vc4/data/imx219.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -128,6 +129,71 @@ "transverse_neg": 0.04881 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 8000 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8600 + } + }, + "ct_curve": + [ + 2498.0, 0.9309, 0.3599, + 2911.0, 0.8682, 0.4283, + 2919.0, 0.8358, 0.4621, + 3627.0, 0.7646, 0.5327, + 4600.0, 0.6079, 0.6721, + 5716.0, 0.5712, 0.7017, + 8575.0, 0.4331, 0.8037 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.04791, + "transverse_neg": 0.04881, + "ccm": + [ + 2.2229345364238413, -0.7596721523178808, -0.46326238410596027, + -0.6834893874172185, 2.7118816887417223, -1.02839940397351, + -0.2613746357615894, -0.668015927152318, 1.9293905629139072 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/imx296.json b/src/ipa/rpi/vc4/data/imx296.json index 905de887..63f4e7af 100644 --- a/src/ipa/rpi/vc4/data/imx296.json +++ b/src/ipa/rpi/vc4/data/imx296.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -128,6 +129,71 @@ "transverse_neg": 0.02374 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 7600 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 7600 + } + }, + "ct_curve": + [ + 2500.0, 0.5386, 0.2458, + 2800.0, 0.4883, 0.3303, + 2900.0, 0.4855, 0.3349, + 3620.0, 0.4203, 0.4367, + 4560.0, 0.3455, 0.5444, + 5600.0, 0.2948, 0.6124, + 7400.0, 0.2336, 0.6894 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.03093, + "transverse_neg": 0.02374, + "ccm": + [ + 2.1073753846153847, -0.8054946153846154, -0.30188076923076923, + -0.43306999999999995, 2.162828076923077, -0.7297680769230768, + -0.126655, -0.5027626923076922, 1.6294176923076922 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/imx477.json b/src/ipa/rpi/vc4/data/imx477.json index 02f910dd..c14ee5cd 100644 --- a/src/ipa/rpi/vc4/data/imx477.json +++ b/src/ipa/rpi/vc4/data/imx477.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -133,6 +134,76 @@ "transverse_neg": 0.04429 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 8000 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8600 + } + }, + "ct_curve": + [ + 2360.0, 0.6009, 0.3093, + 2848.0, 0.5071, 0.4, + 2903.0, 0.4905, 0.4392, + 3628.0, 0.4261, 0.5564, + 3643.0, 0.4228, 0.5623, + 4660.0, 0.3529, 0.68, + 5579.0, 0.3227, 0.7, + 6125.0, 0.3129, 0.71, + 6671.0, 0.3065, 0.72, + 7217.0, 0.3014, 0.73, + 7763.0, 0.295, 0.74, + 9505.0, 0.2524, 0.7856 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.0238, + "transverse_neg": 0.04429, + "ccm": + [ + 2.1643743343419066, -0.972589984871407, -0.19177768532526474, + -0.3769567095310136, 2.0993768608169443, -0.722416815431165, + -0.11786965204236007, -0.4893621633888049, 1.607231815431165 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/imx500.json b/src/ipa/rpi/vc4/data/imx500.json index 224ffb92..303a882f 100644 --- a/src/ipa/rpi/vc4/data/imx500.json +++ b/src/ipa/rpi/vc4/data/imx500.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -131,6 +132,74 @@ "transverse_neg": 0.02626 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2800, + "hi": 8000 + }, + "incandescent": + { + "lo": 2800, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 7600 + } + }, + "ct_curve": + [ + 2800.0, 0.7126, 0.3567, + 2860.0, 0.6681, 0.4042, + 2880.0, 0.6651, 0.4074, + 3580.0, 0.5674, 0.5091, + 3650.0, 0.5629, 0.5137, + 4500.0, 0.4792, 0.5982, + 4570.0, 0.4752, 0.6022, + 5648.0, 0.4137, 0.6628, + 5717.0, 0.4116, 0.6648, + 7600.0, 0.3609, 0.7138 + ], + "sensitivity_r": 1.0, + "sensitivity_b": 1.0, + "transverse_pos": 0.02798, + "transverse_neg": 0.02626, + "ccm": + [ + 1.6856933395176252, -0.4760917810760668, -0.20960155844155848, + -0.3666382560296846, 1.9130496103896104, -0.5464153432282004, + -0.060413803339517624, -0.4878164935064935, 1.5482282745825604 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/imx708.json b/src/ipa/rpi/vc4/data/imx708.json index 430e1250..02c88433 100644 --- a/src/ipa/rpi/vc4/data/imx708.json +++ b/src/ipa/rpi/vc4/data/imx708.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -136,6 +137,79 @@ "transverse_neg": 0.03061 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 8000 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8600 + } + }, + "ct_curve": + [ + 2498.0, 0.8733, 0.2606, + 2821.0, 0.7707, 0.3245, + 2925.0, 0.7338, 0.3499, + 2926.0, 0.7193, 0.3603, + 2951.0, 0.7144, 0.3639, + 2954.0, 0.7111, 0.3663, + 3578.0, 0.6038, 0.4516, + 3717.0, 0.5861, 0.4669, + 3784.0, 0.5786, 0.4737, + 4485.0, 0.5113, 0.5368, + 4615.0, 0.4994, 0.5486, + 4671.0, 0.4927, 0.5554, + 5753.0, 0.4274, 0.6246, + 5773.0, 0.4265, 0.6256, + 7433.0, 0.3723, 0.6881 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.03148, + "transverse_neg": 0.03061, + "ccm": + [ + 1.5407949606299214, -0.3714970078740158, -0.16929511811023623, + -0.2801589763779528, 1.649028503937008, -0.36886236220472446, + 0.004032519685039371, -0.5251851181102363, 1.521162598425197 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/imx708_wide.json b/src/ipa/rpi/vc4/data/imx708_wide.json index f9077332..86e1d2dc 100644 --- a/src/ipa/rpi/vc4/data/imx708_wide.json +++ b/src/ipa/rpi/vc4/data/imx708_wide.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -126,6 +127,69 @@ "transverse_neg": 0.01601 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 8000 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8600 + } + }, + "ct_curve": + [ + 2750.0, 0.7881, 0.2849, + 2940.0, 0.7559, 0.3103, + 3650.0, 0.6291, 0.4206, + 4625.0, 0.5336, 0.5161, + 5715.0, 0.4668, 0.5898 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.01165, + "transverse_neg": 0.01601, + "ccm": + [ + 1.5820866588602653, -0.39406808743169397, -0.1880145042935207, + -0.3101711553473849, 1.756938087431694, -0.44677099921935987, + -0.018062732240437158, -0.5139293442622951, 1.5319991100702577 + ], + "enable_nn": 1 + } + }, { "rpi.agc": { diff --git a/src/ipa/rpi/vc4/data/ov5647.json b/src/ipa/rpi/vc4/data/ov5647.json index 80b18907..ca5972d1 100644 --- a/src/ipa/rpi/vc4/data/ov5647.json +++ b/src/ipa/rpi/vc4/data/ov5647.json @@ -41,6 +41,7 @@ { "rpi.awb": { + "enabled": true, "priors": [ { "lux": 0, @@ -128,6 +129,71 @@ "transverse_neg": 0.04313 } }, + { + "rpi.nn.awb": + { + "enabled": false, + "modes": + { + "auto": + { + "lo": 2500, + "hi": 8000 + }, + "incandescent": + { + "lo": 2500, + "hi": 3000 + }, + "tungsten": + { + "lo": 3000, + "hi": 3500 + }, + "fluorescent": + { + "lo": 4000, + "hi": 4700 + }, + "indoor": + { + "lo": 3000, + "hi": 5000 + }, + "daylight": + { + "lo": 5500, + "hi": 6500 + }, + "cloudy": + { + "lo": 7000, + "hi": 8600 + } + }, + "ct_curve": + [ + 2500.0, 1.0289, 0.4503, + 2803.0, 0.9428, 0.5108, + 2914.0, 0.9406, 0.5127, + 3605.0, 0.8261, 0.6249, + 4540.0, 0.7331, 0.7533, + 5699.0, 0.6715, 0.8627, + 8625.0, 0.6081, 1.0012 + ], + "sensitivity_r": 1.05, + "sensitivity_b": 1.05, + "transverse_pos": 0.0321, + "transverse_neg": 0.04313, + "ccm": + [ + 2.041588151260504, -0.5494553781512606, -0.49214025210084034, + -0.5116488235294118, 1.9901442857142857, -0.47849546218487393, + -0.10519773109243696, -0.641700168067227, 1.7468953781512604 + ], + "enable_nn": 1 + } + }, { "rpi.agc": {