Skip to content

media: apple: isp: correct each module's colour shading from its NVM - #3930

Open
RyanTheTide wants to merge 3 commits into
mainfrom
camera-all-v2/unit-colour-shading
Open

RyanTheTide wants to merge 3 commits into
mainfrom
camera-all-v2/unit-colour-shading

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

The setfile's lens shading tables (section 0xc003) are made for a typical module. Use this module's own NVM measurement (read by #3929) for the colour part of the correction:

  • Keep the stock brightness curve (the sum of the four stock gains at each table point).
  • Give each Bayer plane this module's colour ratio, (sum of the NVM planes) / (NVM plane), relative to the shading centre, so every plane leaves the same shape and a grey scene stays grey towards the corners; the centre keeps its stock gains.
  • The NVM grid can be stored turned by 180 degrees against the tables: use the orientation whose colour ratios are closer to the stock tables'.
  • Bilinear sampling at the grid's own knots, integer fixed point; the stock tables stay untouched if the grid or tables look wrong.
  • The spatial noise filter gains are then computed from the new tables, as today.

No tuning constants: every value comes from the setfile, the module's NVM or the existing snf_centre_dy.

Where each field comes from

  • Section 0xc003 layout (frame size at +6, four 18-byte records from +0xa with step x/y, offset, grid width/height, Q12 tables from +0x54): the existing parser in isp_setfile_snf_radial() / isp_setfile_fixup_h17() on main.
  • Record word 0 = the largest gain of its own table: checked on all 10 setfiles we ship (isp_1820_01 .. isp_8723_01), 44 of 44 records, all four records on one grid with words 5/6 zero. Structure only; no table values are used or quoted.
  • NVM grid layout (binary32 knot positions in [0,1], four planes, plane-major, x fastest, 8-bit samples; the 16-bit path follows the reported bit depth and has not been seen on our Macs yet): our own Linux dump of the raw 0x0511 reply on J713, see media: apple: isp: read per-module lens shading data from sensor NVM #3929.

Replaces #3902 with a new design. #3929 has merged; this is now on main alone.

Tested: K114s T6050 (7.3.0-k114sstack9) at 85d2365 pass: runs clean (NVM 19x17, orientation upright, reference point 24/21), 40/40 1920x1080 NV12 frames, 0 firmware errors, stock module restored; also on the combined tree with #3928. ARM64 KUnit apple-isp* 62/62 pass (CONFIG_WERROR=y, combined tree); checkpatch --strict clean.
Risk: two-way · every Mac whose module NVM has the grid: shading tables change.

Not yet (draft)

  • Image quality is not shown to be better yet. On K114s night-room captures the change is within capture-to-capture noise: corner brightness asymmetry improved once (0.120 -> 0.069), corner chroma moved both ways. A real-scene frame cannot separate shading from scene colour, so this stays a draft until a flat-field row (evenly lit white target) on an IMX958 Mac and an IMX558 Mac shows the corners getting more neutral.
  • Legacy-ABI row (J413/J615).
  • Open points from the J713 NVM dump, to be settled by the flat-field row before this leaves draft: (1) the samples run from 250 at the centre down to 1 (clipped) in the corners with a sharp central peak, so they are not linear brightness and the plane ratios used here may not mean what this design assumes; (2) the data does not decide the plane order or the orientation: the closeness-to-stock measure used for the 180-degree choice differs by under 1 % across plane orders and between the two orientations on J713.

The setfile's lens shading tables (section 0xc003) are made for a
typical module. Each module's NVM carries its own measured shading of
the four Bayer planes, which the previous change reads. Use it for the
colour part of the correction:

- Keep the stock brightness curve: the sum of the four stock gains at
  each table point, scaled from the point where it is lowest.
- Give each plane this module's colour ratio there, (sum of the NVM
  planes) / (NVM plane), relative to the same point. Every plane then
  leaves the same shape, so a grey scene stays grey towards the corners,
  and the centre keeps its stock gains.
- The NVM grid can be stored turned by 180 degrees against the tables.
  Use the orientation whose colour ratios are closer to the stock ones.
- Sample the NVM grid bilinearly at its own (non-uniform) knots, in
  integer fixed point. Leave the stock tables untouched if the grid or
  the tables look wrong (zero samples, knots out of order, tables that
  do not share one grid).
- Keep each record's leading field equal to its table's largest gain,
  as in every shipped setfile.

The spatial noise filter gains are computed afterwards, from the new
tables.

Add a KUnit test: colour flatness on a synthetic module in both
orientations, centre gains and record maxima, and rejection of bad
grids.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The reference point was the table point with the lowest stock gain sum.
In isp_2224_01XX.dat that point sits at the bottom edge, not at the
optical centre, so the per-module colour shading was normalised to an
edge of the frame there.

Use the table point at the shading centre instead: the frame's centre
moved down by the setfile's snf_centre_dy, the same centre the spatial
noise filter uses. Reject a centre outside the frame.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

#3929 merged on 12-02, so this merged main f02bd68 cleanly as 6115b30; the diff is now only this PR's two commits (isp-cam.c and its test). Local: arm64 LLVM W=1 isp-cam.o builds with no warnings. The K114s row at 85d2365 covers the unchanged code; the CI KUnit isp job runs the new test. Ready for review.

@RyanTheTide
RyanTheTide marked this pull request as ready for review December 5, 2026 01:32
@RyanTheTide
RyanTheTide requested review from a team as code owners December 5, 2026 01:32
@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

Merge readiness at 6115b30f: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text, pr-text / pr-text
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 6115b30f, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · every Mac whose module NVM has the grid: shading tables change. Not yet (draft) - Image quality is not shown to be better yet. On K114s night-room captures the change is within capture-to-capture noise: corner brightness asymmetry improved once (0.120 -> 0.069), corner chroma moved both ways. A real-scene frame cannot separate shading from scene colour, so this stays a draft until a flat-field row (evenly lit white target) on an IMX958 Mac and an IMX558 Mac shows the corners getting more neutral. - Legacy-ABI row (J413/J615). - Open points from the J713 NVM dump, to be settled by the flat-field row before this leaves draft: (1) the samples run from 250 at the centre down to 1 (clipped) in the corners with a sharp central peak, so they are not linear brightness and the plane ratios used here may not mean what this design assumes; (2) the data does not decide the plane order or the orientation: the closeness-to-stock measure used for the 180-degree choice differs by under 1 % across plane orders and between the two orientations on J713.

Areas: area:media

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant