[{"id":13735,"web_url":"https://patchwork.libcamera.org/comment/13735/","msgid":"<CAEmqJPrQs4Zy77M4u6W_CvcNm+te84xjsqOH2nJNNOVwHORVXA@mail.gmail.com>","date":"2020-11-17T10:40:50","subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: ipa: raspberrypi:\n\tagc: Improve centre-weighted luminance calucation","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\n\nOn Mon, 16 Nov 2020 at 16:49, David Plowman <david.plowman@raspberrypi.com>\nwrote:\n\n> Previously the calculation computed Y for each region before returning\n> the weighted average, which \"baked in\" the over-importance of small\n> statistics regions. The revised calculation will treat all pixels\n> equally when the region weights are the same, making it easier to\n> use. With the previous scheme, proper \"average\" metering was difficult\n> to implement.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\n> ---\n>  src/ipa/raspberrypi/controller/rpi/agc.cpp | 25 +++++++++++++---------\n>  1 file changed, 15 insertions(+), 10 deletions(-)\n>\n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> index d29b1156..ead28398 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> @@ -386,18 +386,23 @@ static double compute_initial_Y(bcm2835_isp_stats\n> *stats, Metadata *image_metada\n>         awb.gain_r = awb.gain_g = awb.gain_b = 1.0; // in case no metadata\n>         if (image_metadata->Get(\"awb.status\", awb) != 0)\n>                 LOG(RPiAgc, Warning) << \"Agc: no AWB status found\";\n> -       double Y_sum = 0, weight_sum = 0;\n> +       // Note how the calculation below means that equal weights give you\n> +       // \"average\" metering (i.e. all pixels equally important).\n> +       double R_sum = 0, G_sum = 0, B_sum = 0, pixel_sum = 0;\n>         for (int i = 0; i < AGC_STATS_SIZE; i++) {\n> -               if (regions[i].counted == 0)\n> -                       continue;\n> -               weight_sum += weights[i];\n> -               double Y = regions[i].r_sum * awb.gain_r * .299 +\n> -                          regions[i].g_sum * awb.gain_g * .587 +\n> -                          regions[i].b_sum * awb.gain_b * .114;\n> -               Y /= regions[i].counted;\n> -               Y_sum += Y * weights[i];\n> +               R_sum += regions[i].r_sum * weights[i];\n> +               G_sum += regions[i].g_sum * weights[i];\n> +               B_sum += regions[i].b_sum * weights[i];\n> +               pixel_sum += regions[i].counted * weights[i];\n>         }\n> -       return Y_sum / weight_sum / (1 << PIPELINE_BITS);\n> +       if (pixel_sum == 0.0) {\n> +               LOG(RPiAgc, Warning) << \"compute_initial_Y: pixel_sum is\n> zero\";\n> +               return 0;\n> +       }\n> +       double Y_sum = R_sum * awb.gain_r * .299 +\n> +                      G_sum * awb.gain_g * .587 +\n> +                      B_sum * awb.gain_b * .114;\n> +       return Y_sum / pixel_sum / (1 << PIPELINE_BITS);\n>  }\n>\n>  // We handle extra gain through EV by adjusting our Y targets. However,\n> you\n> --\n> 2.20.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C04F5BE082\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 17 Nov 2020 10:41:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 49A5D63323;\n\tTue, 17 Nov 2020 11:41:08 +0100 (CET)","from mail-lf1-x142.google.com (mail-lf1-x142.google.com\n\t[IPv6:2a00:1450:4864:20::142])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 960EA6331F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Nov 2020 11:41:07 +0100 (CET)","by mail-lf1-x142.google.com with SMTP id f11so29439762lfs.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Nov 2020 02:41:07 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"VmYm0kIO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=Vi7Qbd+trfv68bsDDVfMtPeb9C/ybxfg+vksuwN20zI=;\n\tb=VmYm0kIO4aG4JJnKoKPCNlrp9g3yQO1wHZO0Mj9X8gyF8E1h+cV9BjLCgeYNAtzAUf\n\tdl6627NMOcaXiwJ64FTOlrTs1N+5A5OgFco/yj2FdJ6yYISh3FXQqrRZ5GRvL+wlkPWk\n\tLv7fZNjkX/FvaxMyT9JPa7t+MpIBsmgtQ4iJvZP9q194xwUc8mhdEXcVSe+Kh4+gov5u\n\tr4b6fgqcg+/NAlTXpGnNGewUdcWlJ7f+frkNRN35ygm49BtHlCbw5mjnJC7MDtqxkFbl\n\tWvJNG8asPdX9ZhiJTy1FPeSFwNNIG0MY2SZIUHjmFj3Bma3x5jPwv203Nt5QlZzi0ZE+\n\tY2Tg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=Vi7Qbd+trfv68bsDDVfMtPeb9C/ybxfg+vksuwN20zI=;\n\tb=LGE+izuw7SaCyTU7OZ+UyO9UcXexlobtd/6YgwNTyfr4rQCct2rrHkWRcEmB5//J49\n\tu1KTnsLpyg1MtrNFVvb1ZXFW+pUt0+Nfi6U34vMxDDKw17Ny23Lgonyyo/mJRmTaj7WZ\n\tC3/iHHP+1XKthzLc60jVZri4SU4ocntXpO50PihBQz0QPQzJiZMQpAoTt1Mlsef7Eivz\n\t2iEwgQ4sWpTaSm42cKHkmjkLnbz1CsVDEm5IWn+ZJChkCtpR6JjX3PdNJD0FoxTCk1mp\n\tXXj1lJOIbhA1JXxbXRQNdVs9Nu5i68iFETk5spBLxEyYT5ToIi4qV5ykoqvQAmchwRQa\n\t6USg==","X-Gm-Message-State":"AOAM5324faS+3uaVCGdBoBcfrIjiJxIeaOSIm1md5Q3u1LVntH3JtS70\n\t2cgc0qU8tJgo4cbO7dgieFuo10Loy8dFWjxnSjywplx/aBsS7w==","X-Google-Smtp-Source":"ABdhPJyA6bzrf/gaEFf42RpyC+/oJU6xYclkI/hrZ0NUMlsmghJ9qWAJndZ6nM32EeRmYH0QZMou+ZQvPWOxhSpIVsI=","X-Received":"by 2002:a19:418d:: with SMTP id\n\to135mr1567318lfa.329.1605609666959; \n\tTue, 17 Nov 2020 02:41:06 -0800 (PST)","MIME-Version":"1.0","References":"<20201116164918.2055-1-david.plowman@raspberrypi.com>\n\t<20201116164918.2055-5-david.plowman@raspberrypi.com>","In-Reply-To":"<20201116164918.2055-5-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Tue, 17 Nov 2020 10:40:50 +0000","Message-ID":"<CAEmqJPrQs4Zy77M4u6W_CvcNm+te84xjsqOH2nJNNOVwHORVXA@mail.gmail.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: ipa: raspberrypi:\n\tagc: Improve centre-weighted luminance calucation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"multipart/mixed;\n\tboundary=\"===============3043286945963014182==\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]