From patchwork Tue Dec 13 11:48:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18000 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 DDD06BDE6B for ; Tue, 13 Dec 2022 11:48:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A4AA26336B; Tue, 13 Dec 2022 12:48:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670932134; bh=WCd5Yg2ao//5cMiTWI7RL+O49Lp+oN5KbKipJ45uZ20=; 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=utLrL6MqrjLxGawt8JEZBTS3EXI0GzeELX3GmY+p+fCckWQoNYfS7Y4tsuaDSsFG2 /DbjMOCDuxi2LmE86JeS+VNSPEe2TAGoFQxAQYUmOHg6URY+x0o7k/T2ow790eyDFv KWLFXXOkTBTDB5USpGImE4ngVMfMui8aelSGhixQJmuzDUpXdBugYbPj+ucCFXpORI 3UHrzUhHlI96mtc5u+UV83TcYQ5vb6BzAoq+DmPGmj54do+hWmPcjPJJBaFCFaylJZ x4ahB61C+Rw81dgZ2YS8SWgAYGw+Zque0ngZ+PATP4jUbshJV+xMbLYfO3fNEsRrZ6 NYMd2zjQL7YOw== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DB6F163364 for ; Tue, 13 Dec 2022 12:48:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="q/fWJoBy"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id i7so691759wrv.8 for ; Tue, 13 Dec 2022 03:48:51 -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=FaD2be+yF2ADNeJbCXDRJDi2/VL2T516BxJINXKCmzU=; b=q/fWJoBymzUZHc6DKcKhCEf9HsIsm5E5VAUleIx3Dxh2sGxcywexv2niDkVbDPoUIj P27JMh6ajBXZQBfcIwqOgA/SCm7FdaK2L1XgZMSiCpPEwVYoSp0XGKtv18+ZQ/Zy1Z1w pXmCuBossnBlbu4BChpvYsixUWh/9N4aHymhGDFJPvnED3qYrvZhX0CpJyoXdboCOMfB x9Pq9F7TUk6n59Aib2yEw1++DwQ/sjp+qio25ggJvnbCr7SoRZYkhLtTQ4aSF11aFhRE INY9c8gVJx9QMtBS6CIUrT22o4pd+EOkaY2+CET9OR/oDI6FiUKiDxh3IwE63qC8FiWT AVSQ== 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=FaD2be+yF2ADNeJbCXDRJDi2/VL2T516BxJINXKCmzU=; b=5ZIIBQehTwRhKEOm2S1YYfAXZnyupCTMcGcv4Si9+jEsQhEAYhlXOwU+DSiNjiBrZv z5wOZrKpJ1njzq1aGpqdGluS8w5rN3bgg7OSI9MstYvkH+0TsaT/5DRG0ILLQxAn5Jnm f7X9i9sJkwo9acmnGRKytOJ69n98fAce2Dd0TtAq/O4ehbC1hrNBRoXSYVsrJLIqeD58 7SwUIbzLq30GaHmQfDapN/OA6E6hUrwRBpu42y3Gi5zisQ7ds2HRSRF+oOv8HufWY+oy P9moX/nwWIxeWOBJMKkVNOxn+F/A6u7OJCMNmh2ZoocCSgH0hAGI2rjIyis18wzLXvAo b9cQ== X-Gm-Message-State: ANoB5pkhVLJfIV9FMflZCQo58xjHeUqRu9gC5KtTDrSfRXzV4XkV74NU +UuUIhJzz9Wyln39M8T1z3RN6oI79YTBQo4j X-Google-Smtp-Source: AA0mqf75dQdM6gw9cfiZc+Z/779n+ldVMgptmeuTECkh5DrFSJJOIegVLwTe0Pi1pf0z9u3WgJs+3Q== X-Received: by 2002:adf:a193:0:b0:246:e6df:86ea with SMTP id u19-20020adfa193000000b00246e6df86eamr13618219wru.25.1670932131289; Tue, 13 Dec 2022 03:48:51 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id j8-20020a5d4528000000b0024287d9d4a8sm11574541wra.74.2022.12.13.03.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 03:48:50 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Dec 2022 11:48:36 +0000 Message-Id: <20221213114836.15473-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221213114836.15473-1-naush@raspberrypi.com> References: <20221213114836.15473-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 agnostic about pipeline depth, so do not need changing. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++------ src/ipa/raspberrypi/raspberrypi.cpp | 16 ++++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 868c30f03d66..7ec8292d32ff 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, double rSum = 0, gSum = 0, bSum = 0, pixelSum = 0; for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) { auto ®ion = stats->agcRegions.get(i); - double rAcc = std::min(region.val.rSum * gain, ((1 << PipelineBits) - 1) * region.counted); - double gAcc = std::min(region.val.gSum * gain, ((1 << PipelineBits) - 1) * region.counted); - double bAcc = std::min(region.val.bSum * gain, ((1 << PipelineBits) - 1) * region.counted); + double rAcc = std::min(region.val.rSum * gain, ((1 << 16) - 1) * region.counted); + double gAcc = std::min(region.val.gSum * gain, ((1 << 16) - 1) * region.counted); + double bAcc = std::min(region.val.bSum * gain, ((1 << 16) - 1) * region.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 cff079bbafb3..50fdeb4f0478 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1154,11 +1154,15 @@ 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 }); @@ -1168,9 +1172,9 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co */ 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, stats->awb_stats[i].notcounted });