From b140ebd9b7b267e63c13bc8a37bbfd6fc16368b7 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 18 Jan 2024 15:57:18 +0100 Subject: [PATCH] Use the aaav2 code in libmegapixels --- src/process_pipeline.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/process_pipeline.c b/src/process_pipeline.c index d198877..9972aaa 100644 --- a/src/process_pipeline.c +++ b/src/process_pipeline.c @@ -418,20 +418,38 @@ process_image_for_preview(const uint8_t *image) uint32_t *center = g_malloc_n(width * height * sizeof(uint32_t), 1); glReadPixels( 0, height, width, height, GL_RGBA, GL_UNSIGNED_BYTE, center); - libmegapixels_aaa_software_statistics( - center, width, height, &state_proc.stats); - float w_gain = 0.02f; - float t_gain = 0.01f; - state_proc.red += (state_proc.stats.temp * +w_gain) + - (state_proc.stats.tint * t_gain); - state_proc.blue += (state_proc.stats.temp * -w_gain) + - (state_proc.stats.tint * t_gain); - state_proc.blacklevel -= state_proc.stats.blacklevel * 0.001f; + libmegapixels_aaa_set_matrix(&state_proc.stats, + state_proc.calibration.color_matrix_1, + state_proc.calibration.color_matrix_2); + libmegapixels_aaa_software_statistics( + &state_proc.stats, center, width, height); + + state_proc.blacklevel -= (float)state_proc.stats.blacklevel * 0.001f; state_proc.blacklevel = clamp_float(state_proc.blacklevel, 0.0f, 0.07f); - state_proc.red = clamp_float(state_proc.red, 0.5f, 3.0f); - state_proc.blue = clamp_float(state_proc.blue, 0.5f, 3.0f); + + float r = state_proc.stats.avg_r; + float g = state_proc.stats.avg_g; + float b = state_proc.stats.avg_b; + + // Revert the current gains set on the preview + b /= state_proc.red; + b /= state_proc.blue; + + float t = 2.0f; + if (r < t && g < t && b < t) { + // Don't try to AWB on very dark frames + } else { + // Calculate the new R/B gains based on the average color of + // the frame + float new_r = g / clamp_float(r, 1.0f, 999.0f); + float new_b = g / clamp_float(b, 1.0f, 999.0f); + + state_proc.red = clamp_float(new_r, 0.01f, 4.0f); + state_proc.blue = clamp_float(new_b, 0.01f, 4.0f); + } + gles2_debayer_set_shading(gles2_debayer, state_proc.red, state_proc.blue,