<div dir="ltr"><div dir="ltr">Hi David,<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 16 Nov 2020 at 16:49, David Plowman <<a href="mailto:david.plowman@raspberrypi.com">david.plowman@raspberrypi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Previously the calculation computed Y for each region before returning<br>
the weighted average, which "baked in" the over-importance of small<br>
statistics regions. The revised calculation will treat all pixels<br>
equally when the region weights are the same, making it easier to<br>
use. With the previous scheme, proper "average" metering was difficult<br>
to implement.<br>
<br>
Signed-off-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></div><div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
src/ipa/raspberrypi/controller/rpi/agc.cpp | 25 +++++++++++++---------<br>
1 file changed, 15 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp<br>
index d29b1156..ead28398 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp<br>
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp<br>
@@ -386,18 +386,23 @@ static double compute_initial_Y(bcm2835_isp_stats *stats, Metadata *image_metada<br>
awb.gain_r = awb.gain_g = awb.gain_b = 1.0; // in case no metadata<br>
if (image_metadata->Get("awb.status", awb) != 0)<br>
LOG(RPiAgc, Warning) << "Agc: no AWB status found";<br>
- double Y_sum = 0, weight_sum = 0;<br>
+ // Note how the calculation below means that equal weights give you<br>
+ // "average" metering (i.e. all pixels equally important).<br>
+ double R_sum = 0, G_sum = 0, B_sum = 0, pixel_sum = 0;<br>
for (int i = 0; i < AGC_STATS_SIZE; i++) {<br>
- if (regions[i].counted == 0)<br>
- continue;<br>
- weight_sum += weights[i];<br>
- double Y = regions[i].r_sum * awb.gain_r * .299 +<br>
- regions[i].g_sum * awb.gain_g * .587 +<br>
- regions[i].b_sum * awb.gain_b * .114;<br>
- Y /= regions[i].counted;<br>
- Y_sum += Y * weights[i];<br>
+ R_sum += regions[i].r_sum * weights[i];<br>
+ G_sum += regions[i].g_sum * weights[i];<br>
+ B_sum += regions[i].b_sum * weights[i];<br>
+ pixel_sum += regions[i].counted * weights[i];<br>
}<br>
- return Y_sum / weight_sum / (1 << PIPELINE_BITS);<br>
+ if (pixel_sum == 0.0) {<br>
+ LOG(RPiAgc, Warning) << "compute_initial_Y: pixel_sum is zero";<br>
+ return 0;<br>
+ }<br>
+ double Y_sum = R_sum * awb.gain_r * .299 +<br>
+ G_sum * awb.gain_g * .587 +<br>
+ B_sum * awb.gain_b * .114;<br>
+ return Y_sum / pixel_sum / (1 << PIPELINE_BITS);<br>
}<br>
<br>
// We handle extra gain through EV by adjusting our Y targets. However, you<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
libcamera-devel mailing list<br>
<a href="mailto:libcamera-devel@lists.libcamera.org" target="_blank">libcamera-devel@lists.libcamera.org</a><br>
<a href="https://lists.libcamera.org/listinfo/libcamera-devel" rel="noreferrer" target="_blank">https://lists.libcamera.org/listinfo/libcamera-devel</a><br>
</blockquote></div></div>