From patchwork Thu Nov 24 10:38:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17866 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 98B7BBDE6B for ; Thu, 24 Nov 2022 10:38:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 500E66331B; Thu, 24 Nov 2022 11:38:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669286328; bh=sTGi7RgxaxNbxoWSQSrBl7HG/qhIfv5sSuH0VB65uFY=; 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=gfGeBlK/DMF0aBm169KN8rlPTClmlCKAkZatj3jY3TNLJNJsj829UFIJvTNiaDAGb DCGc7Pbgnlr7TdbRP8gcBdJRfwo1VyozQyDFuqT/k4foKCPAcZJNITDBIqaisD+nvE Gmr/r8KY2jFJyEp2bBSb+Pqya/B0+Z67yKI0+XxbYwt/mwAgyc0GHgjNc5jntsnWZ2 tQ0nJTPZEFWlYxr6r6qxDOdfAsHoJG+uwYRSVvf1kYcwGLjXm4Bob3jjV8mxoWJdNi yPUKMWlKMuxanW/Dq3Z/n9bBuuOJdN8FTxhgDDFwgnQhi88sLs+rv6drsQHVADp9v8 52j+zOUyzwE7Q== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DB78363325 for ; Thu, 24 Nov 2022 11:38:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="X8Dbr3vy"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id bs21so1858225wrb.4 for ; Thu, 24 Nov 2022 02:38: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=p1mDNy10gWoZUW3LMkb06Ux8rbvmE8YDIyd+biq7Yk0=; b=X8Dbr3vyosce7VXOkrNCZnu3OEldS1CUgJ/ZpBT33DvRaMaNo/ScJDZ2Zd7bzlDo6o MYLeTN7MIw/zwlOKj4vgQ7Cq/Pq5RwczXetTVQsxmm5Dip1ukqJCOVVPhmHcoV/UFu26 Oi3MD/9Mlo6P2Hs12vFyi9LzLtEs+Jn0QpLZ/h0qCHJg3AyNttrIG+Q0gPNaxp9KrWZi 87uWnEEesyjBceAiAXzgLY2Blx/tcyEUZWSkxmehdv5Is1esQ9WlUXkUkagZxv6FmwB5 N1RFYmh25w9kuqsAU8ERNwOjVir65a25/qQGzTZPOEe3uVFf7TdpOZTpkjgv5vhoAeXG uNzw== 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=p1mDNy10gWoZUW3LMkb06Ux8rbvmE8YDIyd+biq7Yk0=; b=BRMS6OZQ1If7jcBFlzG0bTB8ifrpZk07aqcN7bzNk2kCIxjwqxT/mov979QvTuq1tY TIUtcGyx/3GT3fYZouxLLefJ7uLTX7VgjbC1GDN55OGjsaPWxM0qq73Av+BObQd9jFrT vJEuwQnFugfAThXCPX5Jh5PirSTXJbY0aYFB64gOy/y2k8K/S0PkuBU6o5IbwDg5VGG6 YzEBWdBiuzqfqz01fQZAQOndHIt8s6gShEl4MavY4eG4xcqBsVKCaR3GjiuS7sZmA6Yq 1KyaohrmQsKViTvEMgI1RawTRVQjvW7wTK2qxjUzCI6GDgWDGmxrZZvAVjvViAPS6XNE rotQ== X-Gm-Message-State: ANoB5plbHnKpVNx4KhlYb59sK779Uvc52ToeSzxqsgp+FjLxeAvY8+7q 7kDxC5nIedJWSyzO07RWuEEWsFscNW6CDQ== X-Google-Smtp-Source: AA0mqf494r2jvx462NG0h5HZUl4zV+rzNvbpeJJBemn7q7BlLDmgNBWer05iUfcCZ9ghtwqI6MJQOg== X-Received: by 2002:a5d:68c1:0:b0:236:8a38:4deb with SMTP id p1-20020a5d68c1000000b002368a384debmr19629002wrw.487.1669286323204; Thu, 24 Nov 2022 02:38:43 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id s16-20020adff810000000b002368a6deaf8sm995103wrp.57.2022.11.24.02.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 02:38:42 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Nov 2022 10:38:32 +0000 Message-Id: <20221124103832.6172-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124103832.6172-1-naush@raspberrypi.com> References: <20221124103832.6172-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- 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 a7f0e954407d..e400e478162f 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"]; @@ -592,9 +590,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]; @@ -607,7 +605,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 44527357243d..ac1875d203ae 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1132,11 +1132,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 }); @@ -1146,9 +1150,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 });