[v2,0/9] Implement polynomial lsc support
mbox series

Message ID 20240913075750.35115-1-stefan.klug@ideasonboard.com
Headers show
Series
  • Implement polynomial lsc support
Related show

Message

Stefan Klug Sept. 13, 2024, 7:57 a.m. UTC
Hi all,

Polynomial functions allow a precise representation of the lensshading.
The formula used here is from the DNG specification [2] page 110.
Initial implementations in libtuning show that the overall error is
quite low, but it is not yet clear if the ability to model the lens
shading is sufficient for all cases.

The huge benefit of polynomials is that they can be easily resampled for
arbitrary crop rectangles. In case of the rkisp1 the hardware is
configured using a 17x17 grid of gains.  Resampling these for a
arbitrary crop rectangle on the sensor leads to a degradation in
quality. This can either be mitigated using a higher resolution grid as
basis or by describing the lens shading using polynomials. This series
implements the latter.

Patches 1-4 replace the matrix interpolator with a generic interpolator
class. This is only refactoring without functional changes.

Patch 5 Uses the new interpolator for the current lsc algorithm.

Patch 6-9 Implement a loader for polynomial lens shading coefficients.
Sampling for the current sensor crop rectangle is done at load time.

[1] https://patchwork.libcamera.org/project/libcamera/list/?series=4514
[1] https://helpx.adobe.com/content/dam/help/en/photoshop/pdf/DNG_Spec_1_7_1_0.pdf

Changes in v2:
- Renamed polynomial class to LscPolynomial to better expresss the
  intent.
- Fixed some stylistic issues form review
- Added test for interpolator
- Improved interpolator efficiency
- Add docs for LscPolynomial

Stefan Klug (9):
  ipa: libipa: Add generic Interpolator class
  test: ipa: libipa: Add tets for Interpolator
  ipa: rkisp1: Use generic Interpolator class
  ipa: rkisp1: Remove MatrixInterpolator
  ipa: rkisp1: Use interpolator in lsc
  ipa: rkisp1: Move loader functions into helper class
  ipa: libipa: Add lsc polynomial class
  ipa: rkisp1: Add sensor info to context
  ipa: rkisp1: Add polynomial LSC loader

 src/ipa/libipa/interpolator.cpp        | 156 ++++++++++
 src/ipa/libipa/interpolator.h          | 131 ++++++++
 src/ipa/libipa/lsc_polynomial.cpp      |  81 +++++
 src/ipa/libipa/lsc_polynomial.h        | 104 +++++++
 src/ipa/libipa/matrix_interpolator.cpp | 103 -------
 src/ipa/libipa/matrix_interpolator.h   | 120 --------
 src/ipa/libipa/meson.build             |   6 +-
 src/ipa/rkisp1/algorithms/ccm.cpp      |  18 +-
 src/ipa/rkisp1/algorithms/ccm.h        |   6 +-
 src/ipa/rkisp1/algorithms/lsc.cpp      | 409 +++++++++++++++----------
 src/ipa/rkisp1/algorithms/lsc.h        |  13 +-
 src/ipa/rkisp1/ipa_context.h           |   2 +
 src/ipa/rkisp1/rkisp1.cpp              |   4 +-
 test/ipa/libipa/interpolator.cpp       |  55 ++++
 test/ipa/libipa/meson.build            |  15 +
 test/ipa/meson.build                   |   1 +
 16 files changed, 815 insertions(+), 409 deletions(-)
 create mode 100644 src/ipa/libipa/interpolator.cpp
 create mode 100644 src/ipa/libipa/interpolator.h
 create mode 100644 src/ipa/libipa/lsc_polynomial.cpp
 create mode 100644 src/ipa/libipa/lsc_polynomial.h
 delete mode 100644 src/ipa/libipa/matrix_interpolator.cpp
 delete mode 100644 src/ipa/libipa/matrix_interpolator.h
 create mode 100644 test/ipa/libipa/interpolator.cpp
 create mode 100644 test/ipa/libipa/meson.build