From: Balakrishnan Sambath Add adaptive black level offset based on histogram minimum and pixel statistics. Apply conservative correction for high black levels and gentle correction for low levels to prevent overcorrection and improve dynamic range. Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c index bb2dd69a83f0..2706a27a2506 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1349,7 +1349,27 @@ static void isc_wb_update(struct isc_ctrls *ctrls) * we stretch this color to the full range by substracting * this value from the color component. */ - offset[c] = ctrls->hist_minmax[c][HIST_MIN_INDEX]; + if (hist_min > 5 && hist_min < 60 && total_pixels > 1000) { + /* + * Basic adaptive black level offset correction + * (Simplified version for kernel fallback) + */ + if (hist_min > 20) + /* Conservative for high levels */ + offset[c] = hist_min - 4; + else if (hist_min > 10) + /* Moderate correction */ + offset[c] = hist_min - 2; + else + /* Gentle correction */ + offset[c] = hist_min - 1; + + offset[c] = max(1U, offset[c]); /* Ensure minimum of 1 */ + } else { + /* Use default behavior for edge cases */ + offset[c] = hist_min; + } + /* * The offset is always at least 1. If the offset is 1, we do * not need to adjust it, so our result must be zero. -- 2.34.1