[v3,0/3] Simple pipeline: proportional AGC, AWB stats fix, OV2740 black level
mbox series

Message ID 20260305-agc-proportional-v3-0-25abc1bfacca@jetm.me
Headers show
Series
  • Simple pipeline: proportional AGC, AWB stats fix, OV2740 black level
Related show

Message

Javier Tia March 5, 2026, 8:10 p.m. UTC
This series fixes AGC oscillation and an AWB statistics bug in the
Simple pipeline, and adds the OV2740 black level to the sensor helper.

Patch 1 replaces the fixed 10% bang-bang step in the AGC with a
proportional controller where step size scales with the MSV error.
This eliminates the brightness flicker observed on sensors with
non-trivial control latency (tested on OV2740 behind Intel
IPU6/IVSC).

Patch 2 fixes a bit-depth mismatch in the statistics gathering.
The SWSTATS_ACCUMULATE_LINE_STATS() macro divides the luminance value
for the histogram to normalize it to 8-bit range, but does not apply
the same normalization to the RGB sums. For 10-bit and 12-bit
unpacked Bayer formats, the sums are accumulated at native bit depth
while the AWB subtracts an 8-bit black level, under-correcting by 4x
or 16x respectively. This skews the AWB grey world gains, producing a
visible color cast (~9% green on the OV2740 with BLC=16). The fix
right-shifts the RGB sums in finishFrame() to normalize them to 8-bit
scale, matching the histogram and the 8-bit BLC used by AWB.

Patch 3 adds the OV2740 black level (4096, i.e. 0x40 at 10-bit) to
CameraSensorHelperOv2740, following the established pattern used by
OV5675, IMX219, and other sensors. This is the canonical location for
sensor calibration data and is used across all pipeline handlers.

Changes since v2:
- Dropped the OV2740 tuning file patch (was 3/4). Without a CCM it
  is identical to uncalibrated.yaml and adds no value. A proper
  tuning file with calibrated color matrices can be added later.
- Added Reviewed-by/Tested-by from Milan Zamazal on all patches.

Changes since v1:
- Added patch 2 (AWB stats normalization fix).
- Removed CCM from the OV2740 tuning file (dropped in v3).
- Moved black level from tuning file to CameraSensorHelper (patch 3)
  as suggested by Robert Mader.

Tested on ThinkPad X1 Carbon Gen 10 (Alder Lake, OV2740, IPU6 ISYS,
CachyOS kernel 6.19.3, libcamera 0.7.0).

Test results (converged frames, 6500K lighting, no CCM):

  With AWB fix (v2+):   R/G=0.984  B/G=0.985  (~1.5% residual)
  Without fix (v1):     R/G=0.910  B/G=0.904  (~9% green cast)
  BLC=0 control:        R/G=1.000  B/G=1.001  (proves the mismatch)

Signed-off-by: Javier Tia <floss@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

 .../libcamera/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(-)
---
base-commit: 14ba4d168085dd27aed9bcb043996d6a5f28867e
change-id: 20260305-agc-proportional-ba20bf95f40b

Best regards,