[v5,0/3] ipa: simple: Proportional AGC and statistics normalization
mbox series

Message ID 177810597783.688418.1631246733707368646@jetm.me
Headers show
Series
  • ipa: simple: Proportional AGC and statistics normalization
Related show

Message

Javier Tia May 6, 2026, 9:45 p.m. UTC
The AGC in the simple pipeline uses a fixed ~10% step per frame regardless
of how far the current exposure is from the target. With a hysteresis dead
band of only +/-4%, the controller overshoots near the optimal value,
causing visible brightness oscillation (flicker).

This series replaces the bang-bang controller with a proportional one
(patch 1/3), fixes a bit-depth mismatch in the statistics sums used by
AWB (patch 2/3), and adds the OV2740 black level calibration needed for
correct BLC subtraction (patch 3/3).

Tested on OV2740 behind Intel IPU6 ISYS (ThinkPad X1 Carbon Gen 10).
A 40-frame capture with all three patches shows smooth monotonic brightness
convergence from frame 4 onwards with no oscillation.

Changes since v4:
- Patch 1/3: Added kExpMaxStep = 0.15 to clamp the proportional step,
  bounding corrections to +/-15% even when the scene changes dramatically.
  This addresses Barnabas's question on v4 about large-error behavior.
- Patch 2/3: Rebased; diff context updated for the multi-threading refactor
  in swstats_cpu (6e53e72e), which restructured finishFrame() to aggregate
  from a stats_ vector before applying the shift. No functional change.

Regarding Kieran's question on patch 1/3 (gain model): the proportional
step `again * factor` has the same linearity assumption as the old fixed
step `again * 11/10`. Both multiply the current register value by a
scalar. For devices without a calibrated gain model the register value
is already used as a linear proxy in the original code. This change only
affects the step magnitude, not the direction logic or gain model
assumption. Devices without a gain model should behave the same or better.

Regarding Kieran's question on whether 3/3 is needed for the flicker fix:
patch 1/3 alone cures the flicker. Patch 3/3 improves AWB color accuracy
by providing the correct black level baseline (BLC=16) for channel gain
calculation, but it is independent of the oscillation fix.

Link to v4: https://lore.kernel.org/libcamera-devel/20260306-agc-proportional-v4-0-e87c7e0d837a@jetm.me/

Javier Tia (3):
  ipa: simple: agc: Replace bang-bang controller with proportional
  libcamera: software_isp: Normalize statistics sums to 8-bit
  ipa: libipa: camera_sensor_helper: Add OV2740 black level

 .../internal/software_isp/swstats_cpu.h       |  1 +
 src/ipa/libipa/camera_sensor_helper.cpp       |  2 +
 src/ipa/simple/algorithms/agc.cpp             | 73 +++++++++++++------
 src/libcamera/software_isp/swstats_cpu.cpp    |  9 +++
 4 files changed, 61 insertions(+), 24 deletions(-)