From patchwork Fri Feb 3 09:17:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18244 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 D21AFC329D for ; Fri, 3 Feb 2023 09:17:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D87D625F3; Fri, 3 Feb 2023 10:17:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1675415866; bh=QiXxWahddJBjH0Y2496EO0ohusMMG86k6EqWrbFoh8I=; 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=yql4dOgYcTbWGWvoI7H7vd3tyB3El9mErHGwxPcHSUMtAAcCic674KuvivnuUJRSW mIsBzaDbdpJuZ3GH2kKbXi8AZND/n6iUtK9GPqS7ja7rLJudGNpQmyJU9+RrDKMCaX 1IF0CjHna0CqazCA9NB5mkbHHMJhzYRxzEw81szrsBYqf3cs6b86XQiWvAsUo78D8T aRMkgD+5ghrFRwHAs1o44Vz10xp4nGuQeQjnkE9uhgJnNQ1haoErYrdyFFdf+YkVf/ 5wrKPuN55KnIM7s5xUzrrnktsdjrtn6IHh2RegiOAB3SJaBXKfsXr+guTAQr4LmsGd iNu3m19XsNsdA== 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 07FDE625F0 for ; Fri, 3 Feb 2023 10:17:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="I8SCHb1P"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id q10-20020a1cf30a000000b003db0edfdb74so5272486wmq.1 for ; Fri, 03 Feb 2023 01:17:43 -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=zPHFslMm2RC6M7HPmlZDZ0wSiz5LyD2fZ96vieBis1Y=; b=I8SCHb1P9P+Yp+2WXSrGR9BqS5Gfmw7UJ6UlJfDuczA3vqjT0Hk7ixTAkcngzeCT8r XDhM90IriRnLlB2V/SAbeGET0hVDGQyiA3YxZse+O/0ZaTAdXNUXBu9Cv8HT9NAhkZhM dlemY/97GeJHDA+PFBn+JxzobKUHkm3XWy+GlNtv1nPWqSgdRRnmXpudxcYpuedOyYAu Rffel6jg16zkxIK/DW4LqGMoIclTGdWKatVNJm3oLobOpYY7v0j3cRSz9WWLPnOkAK+z XNVgfMLGgBnoGbr5MClCIXte7znPKjPI20Vb5TveyBkQ8JMhla8byVXkRFyBxWbCo308 h3lg== 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=zPHFslMm2RC6M7HPmlZDZ0wSiz5LyD2fZ96vieBis1Y=; b=OkMZu1UKktiU/KDGQLRh2wwsGGfodZMxZtMjn8+5/a6nh3eq93hHHWk6FkrZZueHuF J3R09pmUlcFtZ2GWVRakns9Dsa2r7/Wl5VWEQQIXSzt+lBmbPthmLR6z+4UlbaSdJsN6 mUzfZle5sFuo/I9dJMNoM9aswsU26OawAcepoW1gb3B/82EHfAQN68+R2SSDai+GR2S/ Tnxx1o7J5xshiZXL4KuoimYTQ7+iSNgkGKgR2gpeE3g28ddq0JMBpjE/qCaERVmVjLT6 VpPgXuFKpqZkBb033hxXGAEQ/UprdjIDPrCPRNG9YWQfto53x15Lti/gknriy4ycoW0c tvNQ== X-Gm-Message-State: AO0yUKX6jaY2cBYuQWo/piOliLJmtrre/r20+4iKNseYtx8q+d8GuU2Q E7y9YlvlYREu/M7OZmTdgWwnbnO9JiofYC7B/8OiGA== X-Google-Smtp-Source: AK7set/FJWZ9p0v1TEtr5B5AUTKYNEowlB1FKSOO3cNIN6+UZbnG19X0gSeETaznjT2xcaT7ycONdw== X-Received: by 2002:a7b:c388:0:b0:3db:2e6e:7826 with SMTP id s8-20020a7bc388000000b003db2e6e7826mr10717211wmj.5.1675415862272; Fri, 03 Feb 2023 01:17:42 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id az24-20020a05600c601800b003dc4baaedd3sm7468864wmb.37.2023.02.03.01.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 01:17:42 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Feb 2023 09:17:34 +0000 Message-Id: <20230203091734.22803-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230203091734.22803-1-naush@raspberrypi.com> References: <20230203091734.22803-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 | 11 +++++------ src/ipa/raspberrypi/raspberrypi.cpp | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 868c30f03d66..ea0c82b5c4c8 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"]; @@ -586,6 +584,7 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata) static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb, double weights[], double gain) { + constexpr unsigned int maxVal = 1 << Statistics::NormalisationFactorPow2; /* * Note how the calculation below means that equal weights give you * "average" metering (i.e. all pixels equally important). @@ -593,9 +592,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, (maxVal - 1) * region.counted); + double gAcc = std::min(region.val.gSum * gain, (maxVal - 1) * region.counted); + double bAcc = std::min(region.val.bSum * gain, (maxVal - 1) * region.counted); rSum += rAcc * weights[i]; gSum += gAcc * weights[i]; bSum += bAcc * weights[i]; @@ -608,7 +607,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 / maxVal; } /* diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index b8cce51522c0..614b8c6aacdb 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1377,11 +1377,17 @@ 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. + */ + constexpr unsigned int scale = Statistics::NormalisationFactorPow2 - 13; + 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 << scale, + stats->awb_stats[i].g_sum << scale, + stats->awb_stats[i].b_sum << scale }, stats->awb_stats[i].counted, stats->awb_stats[i].notcounted }); @@ -1391,9 +1397,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 << scale, + stats->agc_stats[i].g_sum << scale, + stats->agc_stats[i].b_sum << scale }, stats->agc_stats[i].counted, stats->awb_stats[i].notcounted });