From patchwork Mon Nov 16 16:49:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10433 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 73F11BE082 for ; Mon, 16 Nov 2020 16:49:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 347DB632DB; Mon, 16 Nov 2020 17:49:30 +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="XsgOcAoZ"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 99E0D632CA for ; Mon, 16 Nov 2020 17:49:28 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id d142so24363792wmd.4 for ; Mon, 16 Nov 2020 08:49:28 -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=FX6HZ/72E1uEy6eG+0sP6T7FgtQ8d+tG9LreXqCwQJA=; b=XsgOcAoZ9Zhw30bzQUzHkrWo4WxJWpZh0YHGZbxZDlDfe7WuC3wYRZtFumySiOkz1z 1l6yHgzLiTTKvgmxOX1fBa633xlNYdLrHi3FcfHPFAZiitvNr8/0HW1OU/CqwIr/qE/g pTV2s1mF3jJ7+15NEbWEi6E9BHvg/bbRj6wqrFKiqolEufz7Jn6Qqr1NlADj1FX8dB67 a6aJTUUFQHuZKo3epS5676sXzKJVRQAvuRQlsRTwK560ERCsRjUOgI8MhOwVp1q/bCHx aywGZN4XKdjChuFy4iUw67MDqzCROCT7m9hf4+nZv8nleNS/QuQIEcrsHARZwDdCptf4 Oj0A== 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=FX6HZ/72E1uEy6eG+0sP6T7FgtQ8d+tG9LreXqCwQJA=; b=c34JGJAQdHdiTXo4ou869UMlew+y2HDhfRRKJWOyehWeHiBSe9ks9rcrTxOZR6cmjG iCRVzO/cqO+Hs1gasfKH3VVejxWot1oc+o5N0oefSMk4R/Kd7ITEwCfv3071JiEfRScW 4VkngxEHfSMQJo/cv7UEpjdHjsIuvT306CIvjZzDB9YjNBdiLeNafmR+HSFjRfahpHPF axJ3GqK9zVm5fiEPRcxFuILHQ6IXmOlXGWqCIH12ol+DAnmcZ1kJhZWwhKE9hZQsNn9k JI24HW3iiktbxRoxHl3KjWruK3B/IYK4NYCSglU4AXnTFTnclOe/UBBctobKZsNlSpJQ TiWQ== X-Gm-Message-State: AOAM533zokIk32jOqNIaT417sMNoC0lluhrL12RmppIfvhnjwOqEEVIj XsaLMHNZlNCCiXszDXnCL5/SP89IgF80QQ== X-Google-Smtp-Source: ABdhPJzYCQu+19OTMC4l0xpWn9ykV9KHJJ9Vq1j/BP2TxpVcayNJjJS//mQ2L0/QhaSuWYRz/MnuVw== X-Received: by 2002:a1c:7c02:: with SMTP id x2mr12803544wmc.64.1605545368018; Mon, 16 Nov 2020 08:49:28 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id q16sm23716973wrn.13.2020.11.16.08.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:49:27 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Nov 2020 16:49:12 +0000 Message-Id: <20201116164918.2055-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201116164918.2055-1-david.plowman@raspberrypi.com> References: <20201116164918.2055-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 d29b1156..ead28398 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -386,18 +386,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