From patchwork Mon Nov 23 07:37:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10463 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 48142BE08A for ; Mon, 23 Nov 2020 07:38:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1110263320; Mon, 23 Nov 2020 08:38:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="rxN2a/78"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A4A963327 for ; Mon, 23 Nov 2020 08:38:34 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id r17so17621935wrw.1 for ; Sun, 22 Nov 2020 23:38:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QATcowDQnYv31Wl12U+LjUBs2LFP1uTTOOAJsc0CaZk=; b=rxN2a/7885WjDU4E+/cuKRoaa3F0Hz4WJOZQ4mgH4y/cMTOrZys8po5EY5+XEANrPU mqmqZU+6m9xYan4rTRZZNsqduuQ47gzs3GFYH//s7kyBzczeZUedx5LTDWhhHCZvacDg papNWPF6xJwKLcVwn85l4ixeFJQtmA5Dul1FCl0seRmEVIwcQ6Lq5Sz0wUrLqRlPeQ3M 9Q1T30GvI7l2EiM1uV0lXdILa3gyNBkyfDg/xRVDVgsghmqWR+MYbXwK72wmHzwrHAW9 Kbt1zuvdRVir0UOeuECd/IZ/ykZssmJiRL1IGwox1YEIptJDwWFA7jYPub/q0CxTwcvm HHDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QATcowDQnYv31Wl12U+LjUBs2LFP1uTTOOAJsc0CaZk=; b=SYhIYnBQ2ZWYoOkn8zvo1AEJtuPOP+eeOEB+0r8/Ok2soRBHIj1Bg7+hVopwj6AkKJ P6szz/vuHiyFenw2ez+ELw+xqtloVqf8YV3s7iuHQsiB9j5611oJiztYcclI0pQ5ShE3 77YbJ+HaJnT3KfZEFqyU0yaMuYXa5H6H+6R1ykXP0E8HMhqU7Fe6I1pGZpkSEdVlv2Ci mEgh1rq+2uX+xzBbYqZeYkCpaX82iIDIq1P6Ut5OboeiOSLZmmpDcOksclNa8qteOCfC fHq/RyGuoXN+hsEdR6eFk6rVokkUK9yWxHUUKBFLmuhB7whermXPeAczoDau7Q8Oe4U/ 4Fjg== X-Gm-Message-State: AOAM530RLHstQq+O0F5tcIUCqcgGvB4WtCLijqyFriAqPagdFadKuc/m yByrJiVMfiNy0QXwvkj4Rz7Te6WAEh0SK2bA X-Google-Smtp-Source: ABdhPJxtTz78BBXcL1pf6MAVI2HT0pWVTG8gxgVd3lQu/A9QMWdae96iurU91PdWmruCs7fyMDECEw== X-Received: by 2002:adf:c452:: with SMTP id a18mr30006592wrg.189.1606117113639; Sun, 22 Nov 2020 23:38:33 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id h15sm17841822wrw.15.2020.11.22.23.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 23:38:33 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Nov 2020 07:37:58 +0000 Message-Id: <20201123073804.3125-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201123073804.3125-1-david.plowman@raspberrypi.com> References: <20201123073804.3125-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/10] libcamera: ipa: raspberrypi: agc: Improve centre-weighted luminance calucation 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" Previously the calculation computed Y for each region before returning the weighted average, which "baked in" the over-importance of small statistics regions. The revised calculation will treat all pixels equally when the region weights are the same, making it easier to use. With the previous scheme, proper "average" metering was difficult to implement. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 9a5d84f7..f0c70a0a 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -385,18 +385,23 @@ static double compute_initial_Y(bcm2835_isp_stats *stats, Metadata *image_metada awb.gain_r = awb.gain_g = awb.gain_b = 1.0; // in case no metadata if (image_metadata->Get("awb.status", awb) != 0) LOG(RPiAgc, Warning) << "Agc: no AWB status found"; - double Y_sum = 0, weight_sum = 0; + // Note how the calculation below means that equal weights give you + // "average" metering (i.e. all pixels equally important). + double R_sum = 0, G_sum = 0, B_sum = 0, pixel_sum = 0; for (int i = 0; i < AGC_STATS_SIZE; i++) { - if (regions[i].counted == 0) - continue; - weight_sum += weights[i]; - double Y = regions[i].r_sum * awb.gain_r * .299 + - regions[i].g_sum * awb.gain_g * .587 + - regions[i].b_sum * awb.gain_b * .114; - Y /= regions[i].counted; - Y_sum += Y * weights[i]; + R_sum += regions[i].r_sum * weights[i]; + G_sum += regions[i].g_sum * weights[i]; + B_sum += regions[i].b_sum * weights[i]; + pixel_sum += regions[i].counted * weights[i]; } - return Y_sum / weight_sum / (1 << PIPELINE_BITS); + if (pixel_sum == 0.0) { + LOG(RPiAgc, Warning) << "compute_initial_Y: pixel_sum is zero"; + return 0; + } + double Y_sum = R_sum * awb.gain_r * .299 + + G_sum * awb.gain_g * .587 + + B_sum * awb.gain_b * .114; + return Y_sum / pixel_sum / (1 << PIPELINE_BITS); } // We handle extra gain through EV by adjusting our Y targets. However, you