[RFC,v9,0/6] LSC for SoftISP simple pipeline
mbox series

Message ID 20260720095951.49979-1-mzamazal@redhat.com
Headers show
Series
  • LSC for SoftISP simple pipeline
Related show

Message

Milan Zamazal July 20, 2026, 9:59 a.m. UTC
Lens shading correction for software GPU ISP.  Based on the initial work
by Hans’s students, taken over and significantly modified and eventually
reworked to use LSC from libipa (the ongoing work by Jacopo and others).

The LSC is not implemented for CPU ISP within this series; it may be
added later if needed.

It’s RFC because:

- It’s not yet completely tested although it seems to be working in my
  environment.
- It’s based on the libipa patches not yet merged.
- Further changes will be needed once GPU ISP multipass is merged.

Example YAML for grid based LSC, no-op values, place it after Awb:

  - Lsc:
      sets:
        - ct: 6500
          r: [
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
          ]
          g: [
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
          ]
          b: [
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
          ]

Example YAML for polynomial based LSC, no-op values, place it after Awb:

 - Lsc:
     type: "polynomial"
     sets:
       - ct: 6500
         r:
           cx: 0.0
           cy: 0.0
           k0: 0.0
           k1: 0.0
           k2: 0.0
           k3: 0.0
           k4: 0.0
         g:
           cx: 0.0
           cy: 0.0
           k0: 0.0
           k1: 0.0
           k2: 0.0
           k3: 0.0
           k4: 0.0
         b:
           cx: 0.0
           cy: 0.0
           k0: 0.0
           k1: 0.0
           k2: 0.0
           k3: 0.0
           k4: 0.0

Changes in v9:
- Rebased on the latest master.

Changes in v8:
- LscValueType removed.
- A named constant introduced for minimum temperature change.
- A clarification comment added to the LUT value computation.
- lsc-enabled shader flag and the related variables removed.
- Wording corrections suggested by Bryan.

Changes in v7:
- Updated for libipa patches v5 (temperature access).

Changes in v6:
- Rebased on Jacopo’s libipa patches (v3).
- Not updating LSC tables on small or no temperature changes.
- Using libipa LSC algorithms; the implementation in ‘simple’ IPA
  algorithm reduced to the minimum needed.
- Grid tables are defined using integers rather than floats, because
  libipa LSC supports only quantised values and not floats.
- New boolean uniform to enable or disable LSC dynamically, rather than
  only in shaders compile time; to be able to honour the LSC control.
- Specific handling of polynomial LSC removed.  Polynomial LSC is
  already handled by libipa, by making a grid-based LSC from it.  While
  a direct polynomial computation may be a bit faster with a minimum
  number of the polynomial coefficients, the simplicity wins.  If we
  liked to have direct polynomial LSC computation, it should be
  implemented with help of libipa.

Changes in v5:
- ‘grids’ tuning file item renamed to ‘sets’ for consistency with rkisp1.
- Underscores appended to Lsc::lsc* names.
- Other minor stylistic changes.
- Proof-of-concept polynomial LSC implemented.

Changes in v4:
- glFilterParam -> param
- Indentation changes in the shaders.
- A commit message part about temperature reworded.
- Updated for YamlObject -> ValueNode.
- New constant kLscValuesPerCell to distinguish between the constants
  for the params array size (values) and for the stride (bytes).
- The lookup array switched to floats and the texture to half-floats.

Changes in v3:
- LSC scripts patch dropped due to missing licences.
- DO_LSC -> APPLY_LSC
- textureUniformLsc_ is assigned unconditionally now.
- New constant DebayerParams::kLscBytesPerCell.
- LSC values in the tuning file are floats now and converted to bytes internally.
- Source code comments added to clarify the usage of the byte LUTs.

Changes in v2:
- Remaining issues from the reviews (hopefully) addressed.
- Especially there is only a single texture now and LSC is fully
  conditional.
- Major cleanup, hacks removed or replaced, typo fixes, cosmetic
  changes, making linters happy, etc.
- See
  https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056883.html
  for an example how to add the grid data.

Milan Zamazal (1):
  libcamera: software_isp: Pass LSC availability to debayering

Xander Pronk (5):
  libcamera: software_isp: egl: Add filter parameter to
    createTexture2D()
  libcamera: software_isp: Add LSC data to DebayerParams
  ipa: simple: Add LSC algorithm
  libcamera: shaders: Add LSC support
  libcamera: software_isp: debayer_egl: Add LSC support

 include/libcamera/internal/egl.h              |   6 +-
 .../internal/software_isp/debayer_params.h    |   9 ++
 .../internal/software_isp/software_isp.h      |   1 +
 include/libcamera/ipa/soft.mojom              |   4 +-
 src/ipa/simple/algorithms/lsc.cpp             | 100 ++++++++++++++++++
 src/ipa/simple/algorithms/lsc.h               |  50 +++++++++
 src/ipa/simple/algorithms/meson.build         |   1 +
 src/ipa/simple/ipa_context.h                  |   6 ++
 src/ipa/simple/soft_simple.cpp                |   7 +-
 src/libcamera/egl.cpp                         |  19 ++--
 src/libcamera/shaders/bayer_1x_packed.frag    |   8 ++
 src/libcamera/shaders/bayer_unpacked.frag     |   8 ++
 src/libcamera/software_isp/debayer.cpp        |  29 +++++
 src/libcamera/software_isp/debayer.h          |   3 +-
 src/libcamera/software_isp/debayer_cpu.cpp    |   3 +-
 src/libcamera/software_isp/debayer_cpu.h      |   3 +-
 src/libcamera/software_isp/debayer_egl.cpp    |  37 ++++++-
 src/libcamera/software_isp/debayer_egl.h      |  10 +-
 src/libcamera/software_isp/software_isp.cpp   |   5 +-
 19 files changed, 290 insertions(+), 19 deletions(-)
 create mode 100644 src/ipa/simple/algorithms/lsc.cpp
 create mode 100644 src/ipa/simple/algorithms/lsc.h

Comments

Robert Mader July 20, 2026, 12:19 p.m. UTC | #1
Hi Milan, thanks a lot for updating and rebasing the series!

On 20.07.26 11:59, Milan Zamazal wrote:
> Lens shading correction for software GPU ISP.  Based on the initial work
> by Hans’s students, taken over and significantly modified and eventually
> reworked to use LSC from libipa (the ongoing work by Jacopo and others).
>
> The LSC is not implemented for CPU ISP within this series; it may be
> added later if needed.
>
> It’s RFC because:
>
> - It’s not yet completely tested although it seems to be working in my
>    environment.
> - It’s based on the libipa patches not yet merged.
> - Further changes will be needed once GPU ISP multipass is merged.
>
> Example YAML for grid based LSC, no-op values, place it after Awb:
>
>    - Lsc:
>        sets:
>          - ct: 6500
>            r: [
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
>            ]
>            g: [
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
>            ]
>            b: [
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
>            ]

I wonder how compatible this implementation is with the RPi alsc 
algorithm - which would be great as it'd allow us to reuse the tuning 
data for e.g. the IMX355.

Instead of RGB the values are stored as luminance_lut, calibrations_Cr 
and calibrations_Cb - and only the later two using ct. Further more it 
uses 32x32 instead of 16x16 values - and finally it uses floats (1.0 
instead of 64).

It *looks* to me like we could add a script to convert those values, 
assuming the algorithms work similar in the end. What do you think / do 
you think that should work? Would it possibly even make sense to adopt 
the RPi format?

Best regards,

Robert

>
> Example YAML for polynomial based LSC, no-op values, place it after Awb:
>
>   - Lsc:
>       type: "polynomial"
>       sets:
>         - ct: 6500
>           r:
>             cx: 0.0
>             cy: 0.0
>             k0: 0.0
>             k1: 0.0
>             k2: 0.0
>             k3: 0.0
>             k4: 0.0
>           g:
>             cx: 0.0
>             cy: 0.0
>             k0: 0.0
>             k1: 0.0
>             k2: 0.0
>             k3: 0.0
>             k4: 0.0
>           b:
>             cx: 0.0
>             cy: 0.0
>             k0: 0.0
>             k1: 0.0
>             k2: 0.0
>             k3: 0.0
>             k4: 0.0
>
> Changes in v9:
> - Rebased on the latest master.
>
> Changes in v8:
> - LscValueType removed.
> - A named constant introduced for minimum temperature change.
> - A clarification comment added to the LUT value computation.
> - lsc-enabled shader flag and the related variables removed.
> - Wording corrections suggested by Bryan.
>
> Changes in v7:
> - Updated for libipa patches v5 (temperature access).
>
> Changes in v6:
> - Rebased on Jacopo’s libipa patches (v3).
> - Not updating LSC tables on small or no temperature changes.
> - Using libipa LSC algorithms; the implementation in ‘simple’ IPA
>    algorithm reduced to the minimum needed.
> - Grid tables are defined using integers rather than floats, because
>    libipa LSC supports only quantised values and not floats.
> - New boolean uniform to enable or disable LSC dynamically, rather than
>    only in shaders compile time; to be able to honour the LSC control.
> - Specific handling of polynomial LSC removed.  Polynomial LSC is
>    already handled by libipa, by making a grid-based LSC from it.  While
>    a direct polynomial computation may be a bit faster with a minimum
>    number of the polynomial coefficients, the simplicity wins.  If we
>    liked to have direct polynomial LSC computation, it should be
>    implemented with help of libipa.
>
> Changes in v5:
> - ‘grids’ tuning file item renamed to ‘sets’ for consistency with rkisp1.
> - Underscores appended to Lsc::lsc* names.
> - Other minor stylistic changes.
> - Proof-of-concept polynomial LSC implemented.
>
> Changes in v4:
> - glFilterParam -> param
> - Indentation changes in the shaders.
> - A commit message part about temperature reworded.
> - Updated for YamlObject -> ValueNode.
> - New constant kLscValuesPerCell to distinguish between the constants
>    for the params array size (values) and for the stride (bytes).
> - The lookup array switched to floats and the texture to half-floats.
>
> Changes in v3:
> - LSC scripts patch dropped due to missing licences.
> - DO_LSC -> APPLY_LSC
> - textureUniformLsc_ is assigned unconditionally now.
> - New constant DebayerParams::kLscBytesPerCell.
> - LSC values in the tuning file are floats now and converted to bytes internally.
> - Source code comments added to clarify the usage of the byte LUTs.
>
> Changes in v2:
> - Remaining issues from the reviews (hopefully) addressed.
> - Especially there is only a single texture now and LSC is fully
>    conditional.
> - Major cleanup, hacks removed or replaced, typo fixes, cosmetic
>    changes, making linters happy, etc.
> - See
>    https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056883.html
>    for an example how to add the grid data.
>
> Milan Zamazal (1):
>    libcamera: software_isp: Pass LSC availability to debayering
>
> Xander Pronk (5):
>    libcamera: software_isp: egl: Add filter parameter to
>      createTexture2D()
>    libcamera: software_isp: Add LSC data to DebayerParams
>    ipa: simple: Add LSC algorithm
>    libcamera: shaders: Add LSC support
>    libcamera: software_isp: debayer_egl: Add LSC support
>
>   include/libcamera/internal/egl.h              |   6 +-
>   .../internal/software_isp/debayer_params.h    |   9 ++
>   .../internal/software_isp/software_isp.h      |   1 +
>   include/libcamera/ipa/soft.mojom              |   4 +-
>   src/ipa/simple/algorithms/lsc.cpp             | 100 ++++++++++++++++++
>   src/ipa/simple/algorithms/lsc.h               |  50 +++++++++
>   src/ipa/simple/algorithms/meson.build         |   1 +
>   src/ipa/simple/ipa_context.h                  |   6 ++
>   src/ipa/simple/soft_simple.cpp                |   7 +-
>   src/libcamera/egl.cpp                         |  19 ++--
>   src/libcamera/shaders/bayer_1x_packed.frag    |   8 ++
>   src/libcamera/shaders/bayer_unpacked.frag     |   8 ++
>   src/libcamera/software_isp/debayer.cpp        |  29 +++++
>   src/libcamera/software_isp/debayer.h          |   3 +-
>   src/libcamera/software_isp/debayer_cpu.cpp    |   3 +-
>   src/libcamera/software_isp/debayer_cpu.h      |   3 +-
>   src/libcamera/software_isp/debayer_egl.cpp    |  37 ++++++-
>   src/libcamera/software_isp/debayer_egl.h      |  10 +-
>   src/libcamera/software_isp/software_isp.cpp   |   5 +-
>   19 files changed, 290 insertions(+), 19 deletions(-)
>   create mode 100644 src/ipa/simple/algorithms/lsc.cpp
>   create mode 100644 src/ipa/simple/algorithms/lsc.h
>
David Plowman July 20, 2026, 12:52 p.m. UTC | #2
Hi everyone

On Mon, 20 Jul 2026 at 13:19, Robert Mader <robert.mader@collabora.com> wrote:
>
> Hi Milan, thanks a lot for updating and rebasing the series!
>
> On 20.07.26 11:59, Milan Zamazal wrote:
> > Lens shading correction for software GPU ISP.  Based on the initial work
> > by Hans’s students, taken over and significantly modified and eventually
> > reworked to use LSC from libipa (the ongoing work by Jacopo and others).
> >
> > The LSC is not implemented for CPU ISP within this series; it may be
> > added later if needed.
> >
> > It’s RFC because:
> >
> > - It’s not yet completely tested although it seems to be working in my
> >    environment.
> > - It’s based on the libipa patches not yet merged.
> > - Further changes will be needed once GPU ISP multipass is merged.
> >
> > Example YAML for grid based LSC, no-op values, place it after Awb:
> >
> >    - Lsc:
> >        sets:
> >          - ct: 6500
> >            r: [
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> >            ]
> >            g: [
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> >            ]
> >            b: [
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> >            ]
>
> I wonder how compatible this implementation is with the RPi alsc
> algorithm - which would be great as it'd allow us to reuse the tuning
> data for e.g. the IMX355.
>
> Instead of RGB the values are stored as luminance_lut, calibrations_Cr
> and calibrations_Cb - and only the later two using ct. Further more it
> uses 32x32 instead of 16x16 values - and finally it uses floats (1.0
> instead of 64).
>
> It *looks* to me like we could add a script to convert those values,
> assuming the algorithms work similar in the end. What do you think / do
> you think that should work? Would it possibly even make sense to adopt
> the RPi format?

To use the Pi format tables I would:

Scale all three tables down to 16x16 (or you could do this at the
end). You might worry about about whether to preserve the corner
values or not, but realistically, any sensible scheme is likely to be
"good enough".

Use the luminance table for the green channel. We've never bothered
varying luminance correction according to colour temperature as we've
never noticed much effect, but there's no reason that one couldn't.

Multiply the Cr and Cb tables elementwise by the luminance table.
Normalise the resulting tables so that that the minimum gain in each
table is 1.0. These will be the red and blue correction tables.

(If anyone wonders why we separate Cr/Cb and luminance tables, it's so
that you can do less luminance correction without sacrificing the
colour correction.)

Hope that clarifies things a bit!

David

>
> Best regards,
>
> Robert
>
> >
> > Example YAML for polynomial based LSC, no-op values, place it after Awb:
> >
> >   - Lsc:
> >       type: "polynomial"
> >       sets:
> >         - ct: 6500
> >           r:
> >             cx: 0.0
> >             cy: 0.0
> >             k0: 0.0
> >             k1: 0.0
> >             k2: 0.0
> >             k3: 0.0
> >             k4: 0.0
> >           g:
> >             cx: 0.0
> >             cy: 0.0
> >             k0: 0.0
> >             k1: 0.0
> >             k2: 0.0
> >             k3: 0.0
> >             k4: 0.0
> >           b:
> >             cx: 0.0
> >             cy: 0.0
> >             k0: 0.0
> >             k1: 0.0
> >             k2: 0.0
> >             k3: 0.0
> >             k4: 0.0
> >
> > Changes in v9:
> > - Rebased on the latest master.
> >
> > Changes in v8:
> > - LscValueType removed.
> > - A named constant introduced for minimum temperature change.
> > - A clarification comment added to the LUT value computation.
> > - lsc-enabled shader flag and the related variables removed.
> > - Wording corrections suggested by Bryan.
> >
> > Changes in v7:
> > - Updated for libipa patches v5 (temperature access).
> >
> > Changes in v6:
> > - Rebased on Jacopo’s libipa patches (v3).
> > - Not updating LSC tables on small or no temperature changes.
> > - Using libipa LSC algorithms; the implementation in ‘simple’ IPA
> >    algorithm reduced to the minimum needed.
> > - Grid tables are defined using integers rather than floats, because
> >    libipa LSC supports only quantised values and not floats.
> > - New boolean uniform to enable or disable LSC dynamically, rather than
> >    only in shaders compile time; to be able to honour the LSC control.
> > - Specific handling of polynomial LSC removed.  Polynomial LSC is
> >    already handled by libipa, by making a grid-based LSC from it.  While
> >    a direct polynomial computation may be a bit faster with a minimum
> >    number of the polynomial coefficients, the simplicity wins.  If we
> >    liked to have direct polynomial LSC computation, it should be
> >    implemented with help of libipa.
> >
> > Changes in v5:
> > - ‘grids’ tuning file item renamed to ‘sets’ for consistency with rkisp1.
> > - Underscores appended to Lsc::lsc* names.
> > - Other minor stylistic changes.
> > - Proof-of-concept polynomial LSC implemented.
> >
> > Changes in v4:
> > - glFilterParam -> param
> > - Indentation changes in the shaders.
> > - A commit message part about temperature reworded.
> > - Updated for YamlObject -> ValueNode.
> > - New constant kLscValuesPerCell to distinguish between the constants
> >    for the params array size (values) and for the stride (bytes).
> > - The lookup array switched to floats and the texture to half-floats.
> >
> > Changes in v3:
> > - LSC scripts patch dropped due to missing licences.
> > - DO_LSC -> APPLY_LSC
> > - textureUniformLsc_ is assigned unconditionally now.
> > - New constant DebayerParams::kLscBytesPerCell.
> > - LSC values in the tuning file are floats now and converted to bytes internally.
> > - Source code comments added to clarify the usage of the byte LUTs.
> >
> > Changes in v2:
> > - Remaining issues from the reviews (hopefully) addressed.
> > - Especially there is only a single texture now and LSC is fully
> >    conditional.
> > - Major cleanup, hacks removed or replaced, typo fixes, cosmetic
> >    changes, making linters happy, etc.
> > - See
> >    https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056883.html
> >    for an example how to add the grid data.
> >
> > Milan Zamazal (1):
> >    libcamera: software_isp: Pass LSC availability to debayering
> >
> > Xander Pronk (5):
> >    libcamera: software_isp: egl: Add filter parameter to
> >      createTexture2D()
> >    libcamera: software_isp: Add LSC data to DebayerParams
> >    ipa: simple: Add LSC algorithm
> >    libcamera: shaders: Add LSC support
> >    libcamera: software_isp: debayer_egl: Add LSC support
> >
> >   include/libcamera/internal/egl.h              |   6 +-
> >   .../internal/software_isp/debayer_params.h    |   9 ++
> >   .../internal/software_isp/software_isp.h      |   1 +
> >   include/libcamera/ipa/soft.mojom              |   4 +-
> >   src/ipa/simple/algorithms/lsc.cpp             | 100 ++++++++++++++++++
> >   src/ipa/simple/algorithms/lsc.h               |  50 +++++++++
> >   src/ipa/simple/algorithms/meson.build         |   1 +
> >   src/ipa/simple/ipa_context.h                  |   6 ++
> >   src/ipa/simple/soft_simple.cpp                |   7 +-
> >   src/libcamera/egl.cpp                         |  19 ++--
> >   src/libcamera/shaders/bayer_1x_packed.frag    |   8 ++
> >   src/libcamera/shaders/bayer_unpacked.frag     |   8 ++
> >   src/libcamera/software_isp/debayer.cpp        |  29 +++++
> >   src/libcamera/software_isp/debayer.h          |   3 +-
> >   src/libcamera/software_isp/debayer_cpu.cpp    |   3 +-
> >   src/libcamera/software_isp/debayer_cpu.h      |   3 +-
> >   src/libcamera/software_isp/debayer_egl.cpp    |  37 ++++++-
> >   src/libcamera/software_isp/debayer_egl.h      |  10 +-
> >   src/libcamera/software_isp/software_isp.cpp   |   5 +-
> >   19 files changed, 290 insertions(+), 19 deletions(-)
> >   create mode 100644 src/ipa/simple/algorithms/lsc.cpp
> >   create mode 100644 src/ipa/simple/algorithms/lsc.h
> >
> --
> Robert Mader
> Consultant Software Developer
>
> Collabora Ltd.
> Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
> Registered in England & Wales, no. 5513718
>
Milan Zamazal July 20, 2026, 1:58 p.m. UTC | #3
David Plowman <david.plowman@raspberrypi.com> writes:

> Hi everyone
>
> On Mon, 20 Jul 2026 at 13:19, Robert Mader <robert.mader@collabora.com> wrote:
>>
>> Hi Milan, thanks a lot for updating and rebasing the series!
>>
>> On 20.07.26 11:59, Milan Zamazal wrote:
>> > Lens shading correction for software GPU ISP.  Based on the initial work
>> > by Hans’s students, taken over and significantly modified and eventually
>> > reworked to use LSC from libipa (the ongoing work by Jacopo and others).
>> >
>> > The LSC is not implemented for CPU ISP within this series; it may be
>> > added later if needed.
>> >
>> > It’s RFC because:
>> >
>> > - It’s not yet completely tested although it seems to be working in my
>> >    environment.
>> > - It’s based on the libipa patches not yet merged.
>> > - Further changes will be needed once GPU ISP multipass is merged.
>> >
>> > Example YAML for grid based LSC, no-op values, place it after Awb:
>> >
>> >    - Lsc:
>> >        sets:
>> >          - ct: 6500
>> >            r: [
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
>> >            ]
>> >            g: [
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
>> >            ]
>> >            b: [
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
>> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
>> >            ]
>>
>> I wonder how compatible this implementation is with the RPi alsc
>> algorithm - which would be great as it'd allow us to reuse the tuning
>> data for e.g. the IMX355.
>>
>> Instead of RGB the values are stored as luminance_lut, calibrations_Cr
>> and calibrations_Cb - and only the later two using ct. Further more it
>> uses 32x32 instead of 16x16 values - and finally it uses floats (1.0
>> instead of 64).
>>
>> It *looks* to me like we could add a script to convert those values,
>> assuming the algorithms work similar in the end. What do you think / do
>> you think that should work? Would it possibly even make sense to adopt
>> the RPi format?
>
> To use the Pi format tables I would:
>
> Scale all three tables down to 16x16 (or you could do this at the
> end). You might worry about about whether to preserve the corner
> values or not, but realistically, any sensible scheme is likely to be
> "good enough".

32x32 can be used in software ISP if preferred, I don't see any obvious
penalty.

The other stuff should be either addressed in libipa or subject to the
conversion.

> Use the luminance table for the green channel. We've never bothered
> varying luminance correction according to colour temperature as we've
> never noticed much effect, but there's no reason that one couldn't.
>
> Multiply the Cr and Cb tables elementwise by the luminance table.
> Normalise the resulting tables so that that the minimum gain in each
> table is 1.0. These will be the red and blue correction tables.
>
> (If anyone wonders why we separate Cr/Cb and luminance tables, it's so
> that you can do less luminance correction without sacrificing the
> colour correction.)
>
> Hope that clarifies things a bit!

Thank you for clarification!

> David
>
>>
>> Best regards,
>>
>> Robert
>>
>> >
>> > Example YAML for polynomial based LSC, no-op values, place it after Awb:
>> >
>> >   - Lsc:
>> >       type: "polynomial"
>> >       sets:
>> >         - ct: 6500
>> >           r:
>> >             cx: 0.0
>> >             cy: 0.0
>> >             k0: 0.0
>> >             k1: 0.0
>> >             k2: 0.0
>> >             k3: 0.0
>> >             k4: 0.0
>> >           g:
>> >             cx: 0.0
>> >             cy: 0.0
>> >             k0: 0.0
>> >             k1: 0.0
>> >             k2: 0.0
>> >             k3: 0.0
>> >             k4: 0.0
>> >           b:
>> >             cx: 0.0
>> >             cy: 0.0
>> >             k0: 0.0
>> >             k1: 0.0
>> >             k2: 0.0
>> >             k3: 0.0
>> >             k4: 0.0
>> >
>> > Changes in v9:
>> > - Rebased on the latest master.
>> >
>> > Changes in v8:
>> > - LscValueType removed.
>> > - A named constant introduced for minimum temperature change.
>> > - A clarification comment added to the LUT value computation.
>> > - lsc-enabled shader flag and the related variables removed.
>> > - Wording corrections suggested by Bryan.
>> >
>> > Changes in v7:
>> > - Updated for libipa patches v5 (temperature access).
>> >
>> > Changes in v6:
>> > - Rebased on Jacopo’s libipa patches (v3).
>> > - Not updating LSC tables on small or no temperature changes.
>> > - Using libipa LSC algorithms; the implementation in ‘simple’ IPA
>> >    algorithm reduced to the minimum needed.
>> > - Grid tables are defined using integers rather than floats, because
>> >    libipa LSC supports only quantised values and not floats.
>> > - New boolean uniform to enable or disable LSC dynamically, rather than
>> >    only in shaders compile time; to be able to honour the LSC control.
>> > - Specific handling of polynomial LSC removed.  Polynomial LSC is
>> >    already handled by libipa, by making a grid-based LSC from it.  While
>> >    a direct polynomial computation may be a bit faster with a minimum
>> >    number of the polynomial coefficients, the simplicity wins.  If we
>> >    liked to have direct polynomial LSC computation, it should be
>> >    implemented with help of libipa.
>> >
>> > Changes in v5:
>> > - ‘grids’ tuning file item renamed to ‘sets’ for consistency with rkisp1.
>> > - Underscores appended to Lsc::lsc* names.
>> > - Other minor stylistic changes.
>> > - Proof-of-concept polynomial LSC implemented.
>> >
>> > Changes in v4:
>> > - glFilterParam -> param
>> > - Indentation changes in the shaders.
>> > - A commit message part about temperature reworded.
>> > - Updated for YamlObject -> ValueNode.
>> > - New constant kLscValuesPerCell to distinguish between the constants
>> >    for the params array size (values) and for the stride (bytes).
>> > - The lookup array switched to floats and the texture to half-floats.
>> >
>> > Changes in v3:
>> > - LSC scripts patch dropped due to missing licences.
>> > - DO_LSC -> APPLY_LSC
>> > - textureUniformLsc_ is assigned unconditionally now.
>> > - New constant DebayerParams::kLscBytesPerCell.
>> > - LSC values in the tuning file are floats now and converted to bytes internally.
>> > - Source code comments added to clarify the usage of the byte LUTs.
>> >
>> > Changes in v2:
>> > - Remaining issues from the reviews (hopefully) addressed.
>> > - Especially there is only a single texture now and LSC is fully
>> >    conditional.
>> > - Major cleanup, hacks removed or replaced, typo fixes, cosmetic
>> >    changes, making linters happy, etc.
>> > - See
>> >    https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056883.html
>> >    for an example how to add the grid data.
>> >
>> > Milan Zamazal (1):
>> >    libcamera: software_isp: Pass LSC availability to debayering
>> >
>> > Xander Pronk (5):
>> >    libcamera: software_isp: egl: Add filter parameter to
>> >      createTexture2D()
>> >    libcamera: software_isp: Add LSC data to DebayerParams
>> >    ipa: simple: Add LSC algorithm
>> >    libcamera: shaders: Add LSC support
>> >    libcamera: software_isp: debayer_egl: Add LSC support
>> >
>> >   include/libcamera/internal/egl.h              |   6 +-
>> >   .../internal/software_isp/debayer_params.h    |   9 ++
>> >   .../internal/software_isp/software_isp.h      |   1 +
>> >   include/libcamera/ipa/soft.mojom              |   4 +-
>> >   src/ipa/simple/algorithms/lsc.cpp             | 100 ++++++++++++++++++
>> >   src/ipa/simple/algorithms/lsc.h               |  50 +++++++++
>> >   src/ipa/simple/algorithms/meson.build         |   1 +
>> >   src/ipa/simple/ipa_context.h                  |   6 ++
>> >   src/ipa/simple/soft_simple.cpp                |   7 +-
>> >   src/libcamera/egl.cpp                         |  19 ++--
>> >   src/libcamera/shaders/bayer_1x_packed.frag    |   8 ++
>> >   src/libcamera/shaders/bayer_unpacked.frag     |   8 ++
>> >   src/libcamera/software_isp/debayer.cpp        |  29 +++++
>> >   src/libcamera/software_isp/debayer.h          |   3 +-
>> >   src/libcamera/software_isp/debayer_cpu.cpp    |   3 +-
>> >   src/libcamera/software_isp/debayer_cpu.h      |   3 +-
>> >   src/libcamera/software_isp/debayer_egl.cpp    |  37 ++++++-
>> >   src/libcamera/software_isp/debayer_egl.h      |  10 +-
>> >   src/libcamera/software_isp/software_isp.cpp   |   5 +-
>> >   19 files changed, 290 insertions(+), 19 deletions(-)
>> >   create mode 100644 src/ipa/simple/algorithms/lsc.cpp
>> >   create mode 100644 src/ipa/simple/algorithms/lsc.h
>> >
>> --
>> Robert Mader
>> Consultant Software Developer
>>
>> Collabora Ltd.
>> Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
>> Registered in England & Wales, no. 5513718
>>
Jacopo Mondi July 20, 2026, 2:57 p.m. UTC | #4
Hi Robert, Milan

On Mon, Jul 20, 2026 at 02:19:31PM +0200, Robert Mader wrote:
> Hi Milan, thanks a lot for updating and rebasing the series!

Milan, just an heads-up.

I am about to send out v6 and I had to change the LscAlgorithm
interface, so this will need a rebase

I largely prefer the implementation in v5 for what is worth, your
input would be valuable there.

>
> On 20.07.26 11:59, Milan Zamazal wrote:
> > Lens shading correction for software GPU ISP.  Based on the initial work
> > by Hans’s students, taken over and significantly modified and eventually
> > reworked to use LSC from libipa (the ongoing work by Jacopo and others).
> >
> > The LSC is not implemented for CPU ISP within this series; it may be
> > added later if needed.
> >
> > It’s RFC because:
> >
> > - It’s not yet completely tested although it seems to be working in my
> >    environment.
> > - It’s based on the libipa patches not yet merged.
> > - Further changes will be needed once GPU ISP multipass is merged.
> >
> > Example YAML for grid based LSC, no-op values, place it after Awb:
> >
> >    - Lsc:
> >        sets:
> >          - ct: 6500
> >            r: [
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> >            ]
> >            g: [
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> >            ]
> >            b: [
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> >            ]
>
> I wonder how compatible this implementation is with the RPi alsc algorithm -
> which would be great as it'd allow us to reuse the tuning data for e.g. the
> IMX355.
>
> Instead of RGB the values are stored as luminance_lut, calibrations_Cr and
> calibrations_Cb - and only the later two using ct. Further more it uses
> 32x32 instead of 16x16 values - and finally it uses floats (1.0 instead of
> 64).

I guess the direction where we want to go for platforms using libIPA
is to define a platform independent LSC tables format, where gains are
expressed as floats in the tuning file.

Let's keep in mind compatibility with rpi when we'll get there.

>
> It *looks* to me like we could add a script to convert those values,

That's what we did in the past

> assuming the algorithms work similar in the end. What do you think / do you
> think that should work? Would it possibly even make sense to adopt the RPi
> format?

It seems to me the rpi format is organized as

        - Calibration_Cr
           - ct: xxx
             table: []
           - ct: yyy
             table: []
        - Calibration_Cb
           - ct: xxx
             table: []
           - ct: yyy
             table: []
        - luminance_lut:
           - ct: xxx
             table: []
           - ct: yyy
             table: []

While we have tables in

        - ct: xxx
          r: []
          b: []
          g: []

        - ct: yyy
          r: []
          b: []
          g: []

I don't think there are specific merits in any of the two formats, but
they're quiet different at the moment

>
> Best regards,
>
> Robert
>
> >
> > Example YAML for polynomial based LSC, no-op values, place it after Awb:
> >
> >   - Lsc:
> >       type: "polynomial"
> >       sets:
> >         - ct: 6500
> >           r:
> >             cx: 0.0
> >             cy: 0.0
> >             k0: 0.0
> >             k1: 0.0
> >             k2: 0.0
> >             k3: 0.0
> >             k4: 0.0
> >           g:
> >             cx: 0.0
> >             cy: 0.0
> >             k0: 0.0
> >             k1: 0.0
> >             k2: 0.0
> >             k3: 0.0
> >             k4: 0.0
> >           b:
> >             cx: 0.0
> >             cy: 0.0
> >             k0: 0.0
> >             k1: 0.0
> >             k2: 0.0
> >             k3: 0.0
> >             k4: 0.0
> >
> > Changes in v9:
> > - Rebased on the latest master.
> >
> > Changes in v8:
> > - LscValueType removed.
> > - A named constant introduced for minimum temperature change.
> > - A clarification comment added to the LUT value computation.
> > - lsc-enabled shader flag and the related variables removed.
> > - Wording corrections suggested by Bryan.
> >
> > Changes in v7:
> > - Updated for libipa patches v5 (temperature access).
> >
> > Changes in v6:
> > - Rebased on Jacopo’s libipa patches (v3).
> > - Not updating LSC tables on small or no temperature changes.
> > - Using libipa LSC algorithms; the implementation in ‘simple’ IPA
> >    algorithm reduced to the minimum needed.
> > - Grid tables are defined using integers rather than floats, because
> >    libipa LSC supports only quantised values and not floats.
> > - New boolean uniform to enable or disable LSC dynamically, rather than
> >    only in shaders compile time; to be able to honour the LSC control.
> > - Specific handling of polynomial LSC removed.  Polynomial LSC is
> >    already handled by libipa, by making a grid-based LSC from it.  While
> >    a direct polynomial computation may be a bit faster with a minimum
> >    number of the polynomial coefficients, the simplicity wins.  If we
> >    liked to have direct polynomial LSC computation, it should be
> >    implemented with help of libipa.
> >
> > Changes in v5:
> > - ‘grids’ tuning file item renamed to ‘sets’ for consistency with rkisp1.
> > - Underscores appended to Lsc::lsc* names.
> > - Other minor stylistic changes.
> > - Proof-of-concept polynomial LSC implemented.
> >
> > Changes in v4:
> > - glFilterParam -> param
> > - Indentation changes in the shaders.
> > - A commit message part about temperature reworded.
> > - Updated for YamlObject -> ValueNode.
> > - New constant kLscValuesPerCell to distinguish between the constants
> >    for the params array size (values) and for the stride (bytes).
> > - The lookup array switched to floats and the texture to half-floats.
> >
> > Changes in v3:
> > - LSC scripts patch dropped due to missing licences.
> > - DO_LSC -> APPLY_LSC
> > - textureUniformLsc_ is assigned unconditionally now.
> > - New constant DebayerParams::kLscBytesPerCell.
> > - LSC values in the tuning file are floats now and converted to bytes internally.
> > - Source code comments added to clarify the usage of the byte LUTs.
> >
> > Changes in v2:
> > - Remaining issues from the reviews (hopefully) addressed.
> > - Especially there is only a single texture now and LSC is fully
> >    conditional.
> > - Major cleanup, hacks removed or replaced, typo fixes, cosmetic
> >    changes, making linters happy, etc.
> > - See
> >    https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056883.html
> >    for an example how to add the grid data.
> >
> > Milan Zamazal (1):
> >    libcamera: software_isp: Pass LSC availability to debayering
> >
> > Xander Pronk (5):
> >    libcamera: software_isp: egl: Add filter parameter to
> >      createTexture2D()
> >    libcamera: software_isp: Add LSC data to DebayerParams
> >    ipa: simple: Add LSC algorithm
> >    libcamera: shaders: Add LSC support
> >    libcamera: software_isp: debayer_egl: Add LSC support
> >
> >   include/libcamera/internal/egl.h              |   6 +-
> >   .../internal/software_isp/debayer_params.h    |   9 ++
> >   .../internal/software_isp/software_isp.h      |   1 +
> >   include/libcamera/ipa/soft.mojom              |   4 +-
> >   src/ipa/simple/algorithms/lsc.cpp             | 100 ++++++++++++++++++
> >   src/ipa/simple/algorithms/lsc.h               |  50 +++++++++
> >   src/ipa/simple/algorithms/meson.build         |   1 +
> >   src/ipa/simple/ipa_context.h                  |   6 ++
> >   src/ipa/simple/soft_simple.cpp                |   7 +-
> >   src/libcamera/egl.cpp                         |  19 ++--
> >   src/libcamera/shaders/bayer_1x_packed.frag    |   8 ++
> >   src/libcamera/shaders/bayer_unpacked.frag     |   8 ++
> >   src/libcamera/software_isp/debayer.cpp        |  29 +++++
> >   src/libcamera/software_isp/debayer.h          |   3 +-
> >   src/libcamera/software_isp/debayer_cpu.cpp    |   3 +-
> >   src/libcamera/software_isp/debayer_cpu.h      |   3 +-
> >   src/libcamera/software_isp/debayer_egl.cpp    |  37 ++++++-
> >   src/libcamera/software_isp/debayer_egl.h      |  10 +-
> >   src/libcamera/software_isp/software_isp.cpp   |   5 +-
> >   19 files changed, 290 insertions(+), 19 deletions(-)
> >   create mode 100644 src/ipa/simple/algorithms/lsc.cpp
> >   create mode 100644 src/ipa/simple/algorithms/lsc.h
> >
> --
> Robert Mader
> Consultant Software Developer
>
> Collabora Ltd.
> Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
> Registered in England & Wales, no. 5513718
>
Laurent Pinchart July 20, 2026, 4:46 p.m. UTC | #5
On Mon, Jul 20, 2026 at 04:57:51PM +0200, Jacopo Mondi wrote:
> Hi Robert, Milan
> 
> On Mon, Jul 20, 2026 at 02:19:31PM +0200, Robert Mader wrote:
> > Hi Milan, thanks a lot for updating and rebasing the series!
> 
> Milan, just an heads-up.
> 
> I am about to send out v6 and I had to change the LscAlgorithm
> interface, so this will need a rebase
> 
> I largely prefer the implementation in v5 for what is worth, your
> input would be valuable there.
> 
> > On 20.07.26 11:59, Milan Zamazal wrote:
> > > Lens shading correction for software GPU ISP.  Based on the initial work
> > > by Hans’s students, taken over and significantly modified and eventually
> > > reworked to use LSC from libipa (the ongoing work by Jacopo and others).
> > >
> > > The LSC is not implemented for CPU ISP within this series; it may be
> > > added later if needed.
> > >
> > > It’s RFC because:
> > >
> > > - It’s not yet completely tested although it seems to be working in my
> > >    environment.
> > > - It’s based on the libipa patches not yet merged.
> > > - Further changes will be needed once GPU ISP multipass is merged.
> > >
> > > Example YAML for grid based LSC, no-op values, place it after Awb:
> > >
> > >    - Lsc:
> > >        sets:
> > >          - ct: 6500
> > >            r: [
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> > >            ]
> > >            g: [
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> > >            ]
> > >            b: [
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
> > >              64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
> > >            ]
> >
> > I wonder how compatible this implementation is with the RPi alsc algorithm -
> > which would be great as it'd allow us to reuse the tuning data for e.g. the
> > IMX355.
> >
> > Instead of RGB the values are stored as luminance_lut, calibrations_Cr and
> > calibrations_Cb - and only the later two using ct. Further more it uses
> > 32x32 instead of 16x16 values - and finally it uses floats (1.0 instead of
> > 64).
> 
> I guess the direction where we want to go for platforms using libIPA
> is to define a platform independent LSC tables format, where gains are
> expressed as floats in the tuning file.
> 
> Let's keep in mind compatibility with rpi when we'll get there.
> 
> > It *looks* to me like we could add a script to convert those values,
> 
> That's what we did in the past
> 
> > assuming the algorithms work similar in the end. What do you think / do you
> > think that should work? Would it possibly even make sense to adopt the RPi
> > format?
> 
> It seems to me the rpi format is organized as
> 
>         - Calibration_Cr
>            - ct: xxx
>              table: []
>            - ct: yyy
>              table: []
>         - Calibration_Cb
>            - ct: xxx
>              table: []
>            - ct: yyy
>              table: []
>         - luminance_lut:
>            - ct: xxx
>              table: []
>            - ct: yyy
>              table: []
> 
> While we have tables in
> 
>         - ct: xxx
>           r: []
>           b: []
>           g: []
> 
>         - ct: yyy
>           r: []
>           b: []
>           g: []
> 
> I don't think there are specific merits in any of the two formats, but
> they're quiet different at the moment

It probably doesn't matter too much indeed as all the data is parsed in
one go and stored in ad-hoc data structures. All other things being
equal, I'd pick the format that results in the YAML file being easier to
manually read and edit.

RGB vs. YCbCr on the other hand matters more. Do we want to support
YCbCr in libipa ? Can we do so later while preserving backward
compatibility with RGB and keeping the code clean ?

> > > Example YAML for polynomial based LSC, no-op values, place it after Awb:
> > >
> > >   - Lsc:
> > >       type: "polynomial"
> > >       sets:
> > >         - ct: 6500
> > >           r:
> > >             cx: 0.0
> > >             cy: 0.0
> > >             k0: 0.0
> > >             k1: 0.0
> > >             k2: 0.0
> > >             k3: 0.0
> > >             k4: 0.0
> > >           g:
> > >             cx: 0.0
> > >             cy: 0.0
> > >             k0: 0.0
> > >             k1: 0.0
> > >             k2: 0.0
> > >             k3: 0.0
> > >             k4: 0.0
> > >           b:
> > >             cx: 0.0
> > >             cy: 0.0
> > >             k0: 0.0
> > >             k1: 0.0
> > >             k2: 0.0
> > >             k3: 0.0
> > >             k4: 0.0
> > >
> > > Changes in v9:
> > > - Rebased on the latest master.
> > >
> > > Changes in v8:
> > > - LscValueType removed.
> > > - A named constant introduced for minimum temperature change.
> > > - A clarification comment added to the LUT value computation.
> > > - lsc-enabled shader flag and the related variables removed.
> > > - Wording corrections suggested by Bryan.
> > >
> > > Changes in v7:
> > > - Updated for libipa patches v5 (temperature access).
> > >
> > > Changes in v6:
> > > - Rebased on Jacopo’s libipa patches (v3).
> > > - Not updating LSC tables on small or no temperature changes.
> > > - Using libipa LSC algorithms; the implementation in ‘simple’ IPA
> > >    algorithm reduced to the minimum needed.
> > > - Grid tables are defined using integers rather than floats, because
> > >    libipa LSC supports only quantised values and not floats.
> > > - New boolean uniform to enable or disable LSC dynamically, rather than
> > >    only in shaders compile time; to be able to honour the LSC control.
> > > - Specific handling of polynomial LSC removed.  Polynomial LSC is
> > >    already handled by libipa, by making a grid-based LSC from it.  While
> > >    a direct polynomial computation may be a bit faster with a minimum
> > >    number of the polynomial coefficients, the simplicity wins.  If we
> > >    liked to have direct polynomial LSC computation, it should be
> > >    implemented with help of libipa.
> > >
> > > Changes in v5:
> > > - ‘grids’ tuning file item renamed to ‘sets’ for consistency with rkisp1.
> > > - Underscores appended to Lsc::lsc* names.
> > > - Other minor stylistic changes.
> > > - Proof-of-concept polynomial LSC implemented.
> > >
> > > Changes in v4:
> > > - glFilterParam -> param
> > > - Indentation changes in the shaders.
> > > - A commit message part about temperature reworded.
> > > - Updated for YamlObject -> ValueNode.
> > > - New constant kLscValuesPerCell to distinguish between the constants
> > >    for the params array size (values) and for the stride (bytes).
> > > - The lookup array switched to floats and the texture to half-floats.
> > >
> > > Changes in v3:
> > > - LSC scripts patch dropped due to missing licences.
> > > - DO_LSC -> APPLY_LSC
> > > - textureUniformLsc_ is assigned unconditionally now.
> > > - New constant DebayerParams::kLscBytesPerCell.
> > > - LSC values in the tuning file are floats now and converted to bytes internally.
> > > - Source code comments added to clarify the usage of the byte LUTs.
> > >
> > > Changes in v2:
> > > - Remaining issues from the reviews (hopefully) addressed.
> > > - Especially there is only a single texture now and LSC is fully
> > >    conditional.
> > > - Major cleanup, hacks removed or replaced, typo fixes, cosmetic
> > >    changes, making linters happy, etc.
> > > - See
> > >    https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056883.html
> > >    for an example how to add the grid data.
> > >
> > > Milan Zamazal (1):
> > >    libcamera: software_isp: Pass LSC availability to debayering
> > >
> > > Xander Pronk (5):
> > >    libcamera: software_isp: egl: Add filter parameter to
> > >      createTexture2D()
> > >    libcamera: software_isp: Add LSC data to DebayerParams
> > >    ipa: simple: Add LSC algorithm
> > >    libcamera: shaders: Add LSC support
> > >    libcamera: software_isp: debayer_egl: Add LSC support
> > >
> > >   include/libcamera/internal/egl.h              |   6 +-
> > >   .../internal/software_isp/debayer_params.h    |   9 ++
> > >   .../internal/software_isp/software_isp.h      |   1 +
> > >   include/libcamera/ipa/soft.mojom              |   4 +-
> > >   src/ipa/simple/algorithms/lsc.cpp             | 100 ++++++++++++++++++
> > >   src/ipa/simple/algorithms/lsc.h               |  50 +++++++++
> > >   src/ipa/simple/algorithms/meson.build         |   1 +
> > >   src/ipa/simple/ipa_context.h                  |   6 ++
> > >   src/ipa/simple/soft_simple.cpp                |   7 +-
> > >   src/libcamera/egl.cpp                         |  19 ++--
> > >   src/libcamera/shaders/bayer_1x_packed.frag    |   8 ++
> > >   src/libcamera/shaders/bayer_unpacked.frag     |   8 ++
> > >   src/libcamera/software_isp/debayer.cpp        |  29 +++++
> > >   src/libcamera/software_isp/debayer.h          |   3 +-
> > >   src/libcamera/software_isp/debayer_cpu.cpp    |   3 +-
> > >   src/libcamera/software_isp/debayer_cpu.h      |   3 +-
> > >   src/libcamera/software_isp/debayer_egl.cpp    |  37 ++++++-
> > >   src/libcamera/software_isp/debayer_egl.h      |  10 +-
> > >   src/libcamera/software_isp/software_isp.cpp   |   5 +-
> > >   19 files changed, 290 insertions(+), 19 deletions(-)
> > >   create mode 100644 src/ipa/simple/algorithms/lsc.cpp
> > >   create mode 100644 src/ipa/simple/algorithms/lsc.h
> > >
> > --
> > Robert Mader
> > Consultant Software Developer
> >
> > Collabora Ltd.
> > Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
> > Registered in England & Wales, no. 5513718
> >