From patchwork Tue Nov 22 11:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17834 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 09348C3286 for ; Tue, 22 Nov 2022 11:22:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BBF2C632F8; Tue, 22 Nov 2022 12:22:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669116154; bh=o3ITZHbe6aFynDHRpdIvstbdwMQ8TCOwVNf8A98D2/c=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AfDQfV4wNuxZDlXIzOk9v2VFrvhh25eRiAwpPaK7g+Ahkp2P0A5EcZsTmVcW86Ey1 pEG3h0zgNyo3RZ+CyIeDXWcu/eOa21jKTX/MLGUx9ZbtVusvg/OYslv36J9f3KzHvB 7zgl1J2PIdiM9Jk+QeTvFHaZmSI7INorfxqTnqsFW3cC0sLQXFYIu6znPT+X80oU/J 8Kx9+yTF+KHV04/Ii+MsB05AduJsh4XiR5ugakn5FXaGoyMNlyKcH+fA5ktS08IDeO t/2ogvJwebAdGN1X2/Sw4BRdN/n5bpTOdkhNyi4jh2lObsydnSw/JeLSsNXcjW1tkz /DMaqvfoJOEoA== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E03886331A for ; Tue, 22 Nov 2022 12:22:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qh/ZpMeJ"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id v124-20020a1cac82000000b003cf7a4ea2caso14969149wme.5 for ; Tue, 22 Nov 2022 03:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=cEBBhUzHrYHZA7FKrwtQWXcsENcHMTeNMYFSTGUqYVw=; b=qh/ZpMeJU1CeRA9khp+YGCOojxzVgYNkSdrKDY/maoxzcAyrp67JiX9THYi/hZ4jRg 1S98yOK4LjFeTjcPI3ARnZq7W7iCHvKJkJ0pqiUpnojUQ55tA6xXzrzaPD3RmXIOFjva 117mL0pjb/nPLDMauiK4+aSASnEkMfn9kEPBA3VOzHA4ASZYS03xAz+C/yOSp0MJhxfW 8VjQlTR3Y8Dx868vdWM0ibuDw6qxv1ASqahl5aW9rDYYlrLukmypV7CsaVCUMNyPprpy 715IrHiNSXDquVdHRNq9GM+ZZwFShxuaeyrqbbvTJIypKCU1gY1DEyoeefzLhcGuw4h4 oQxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cEBBhUzHrYHZA7FKrwtQWXcsENcHMTeNMYFSTGUqYVw=; b=FpEx1Ni/wRxeI+pAAhBKQ93mpbiAXBCiLRYrD/tG8j+Zz6hBePLwb92udtRaijklsY WHKI94fghiNddtX/bZg5X0qf8yK+bUtqBcNHuD4vQjZM/INFPrm7oXqiiBhY1oGaJv58 GUgcxwAj6iAqoMlyO8chLWIau4ojTFNyJ/CtnW9Y7YHaEB8JqYPPA6qkA68nmUTVWy8F yQY053DXMdsd7qCkhkpuiY8kRgbSC44ZZ4m9iYFvxRCtS4sYm6k8neW1NHSJDexfuK9E rquWhCEjSLQLCfJ+r2Zf22pK52KP6tmW57f+0nf/6ISE2PGhqKoTwGi0kSmwvn1Sho6u iXTA== X-Gm-Message-State: ANoB5pn+pjjuheVsmVBeE9estYt0hntZsl58K0luLiyP2o1jM7W9WwOt wBPOV9a3PnTQ8Wpexg5fUFUvx8F/xujrOQ== X-Google-Smtp-Source: AA0mqf7R+tmk+7GaU/py51HBlR7+8CzvHxJEWpefABBdOOqdO+cscrTZ0CD5X7ynNzgPOeyyAaqJRA== X-Received: by 2002:a7b:c2aa:0:b0:3cf:5d41:bea1 with SMTP id c10-20020a7bc2aa000000b003cf5d41bea1mr3630138wmk.118.1669116150287; Tue, 22 Nov 2022 03:22:30 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q125-20020a1c4383000000b003c6cd82596esm21400388wma.43.2022.11.22.03.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 03:22:29 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Nov 2022 11:22:24 +0000 Message-Id: <20221122112224.31691-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122112224.31691-1-naush@raspberrypi.com> References: <20221122112224.31691-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 5/5] ipa: raspberrypi: Normalise region sums to 16-bits X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The VC4 ISP uses a pipeline bit-depth of 13-bits. The AGC algorithm needs to know this bit-depth when computing the Y value for the image. Instead of hardcoding the VC4 bit-depth in the AGC source code, normalise all region sums to 16-bits when filling the Statistics structure. AWB and ALSC are agonistic about pipline depth, so do not need chaning. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++------ src/ipa/raspberrypi/raspberrypi.cpp | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 79c83e0a9eae..358af8f2544b 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -28,8 +28,6 @@ LOG_DEFINE_CATEGORY(RPiAgc) #define NAME "rpi.agc" -static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */ - int AgcMeteringMode::read(const libcamera::YamlObject ¶ms) { const YamlObject &yamlWeights = params["weights"]; @@ -593,9 +591,9 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb, for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) { uint32_t counted, uncounted; auto s = stats->agcRegions.get(i, counted, uncounted); - double rAcc = std::min(s.rSum * gain, ((1 << PipelineBits) - 1) * counted); - double gAcc = std::min(s.gSum * gain, ((1 << PipelineBits) - 1) * counted); - double bAcc = std::min(s.bSum * gain, ((1 << PipelineBits) - 1) * counted); + double rAcc = std::min(s.rSum * gain, ((1 << 16) - 1) * counted); + double gAcc = std::min(s.gSum * gain, ((1 << 16) - 1) * counted); + double bAcc = std::min(s.bSum * gain, ((1 << 16) - 1) * counted); rSum += rAcc * weights[i]; gSum += gAcc * weights[i]; bSum += bAcc * weights[i]; @@ -608,7 +606,7 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb, double ySum = rSum * awb.gainR * .299 + gSum * awb.gainG * .587 + bSum * awb.gainB * .114; - return ySum / pixelSum / (1 << PipelineBits); + return ySum / pixelSum / (1 << 16); } /* diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 8fcfa0b3ea50..fcecd60bcf6d 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1132,19 +1132,26 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co /* RGB histograms are not used, so do not populate them. */ statistics->yHist = std::move(RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS)); + /* + * All region sums are based on a 13-bit pipeline bit-depth. Normalise + * this to 16-bits for the AGC/AWB/ALSC algorithms. + */ statistics->awbRegions.init(DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y); for (i = 0; i < statistics->awbRegions.numRegions(); i++) - statistics->awbRegions.set(i, { stats->awb_stats[i].r_sum, - stats->awb_stats[i].g_sum, - stats->awb_stats[i].b_sum }, + statistics->awbRegions.set(i, { stats->awb_stats[i].r_sum << 3, + stats->awb_stats[i].g_sum << 3, + stats->awb_stats[i].b_sum << 3 }, stats->awb_stats[i].counted, stats->awb_stats[i].notcounted); - /* There are only ever 15 regions computed by the firmware, but the HW defines AGC_REGIONS == 16! */ + /* + * There are only ever 15 regions computed by the firmware due to zoning, + * but the HW defines AGC_REGIONS == 16! + */ statistics->agcRegions.init(15); for (i = 0; i < statistics->agcRegions.numRegions(); i++) - statistics->agcRegions.set(i, { stats->agc_stats[i].r_sum, - stats->agc_stats[i].g_sum, - stats->agc_stats[i].b_sum }, + statistics->agcRegions.set(i, { stats->agc_stats[i].r_sum << 3, + stats->agc_stats[i].g_sum << 3, + stats->agc_stats[i].b_sum << 3 }, stats->agc_stats[i].counted, 0); statistics->focusRegions.init(4, 3);