Skip to content

media: apple: isp, arm64: dts: t6050-j714s: cut the camera's grain 5x as macOS does - #2233

Merged
DjDeveloperr merged 3 commits into
aurora-silicon:integration/aurorafrom
Isaac-Duarte:j714s/isp-hmca
Nov 20, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-silicon:integration/aurorafrom
Isaac-Duarte:j714s/isp-hmca

Conversation

@Isaac-Duarte

@Isaac-Duarte Isaac-Duarte commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The J714s webcam is much grainier than on macOS, worst in a dim room. The firmware's noise filter settings don't explain it. The setfile's spatial noise filter table does: it ships flat. This PR computes that table from the setfile's lens shading tables, lets H17 auto exposure slow to 15 fps in low light, and moves the J714s sizes to the binned sensor mode.

Before and after on a J714s, same wall, same lamp, 1920x1080. The top row is the full frame and the bottom row is 1:1 from the centre. "Before" runs the old driver settings: config 6 with its crop, the flat 0xc404 and the frame rate held. Frame-to-frame luma noise drops from 18.6 to 1.2 and colour noise from 5.9/3.6 to 0.8/0.6 (Cb/Cr) at the same brightness.

J714s camera before/after

Noise filter gains (the main fix). Section 0xc404 of a setfile holds the spatial noise filter's gain by distance from the optical centre, and every setfile at hand ships it flat. Lens shading correction (section 0xc003) multiplies the signal, and its noise, by a gain that grows towards the edges. The driver now sets the filter's gain at each radius to the inverse of the mean shading gain there, averaged over the four colour tables and the four corner directions, so the filter follows that noise. It does so at setfile load, in integer arithmetic, whenever the setfile has 0xc003, a flat 0xc404 and no 0xc407. A 0xc404 that ships tuned is kept. The setfile doesn't carry the optical centre, so the setfile table entry does: 156 shading-frame pixels above the frame's for the IMX958 and IMX814, the frame's own for the other sensors. All eight setfiles at hand (1820/1822, 1921/1922/1925, 2224, 8720/8723) qualify, so this changes the filter beyond the J714s. It has been measured on the J714s and, by @sithglan, on the J813 (below). For isp_2224_01XX its output matches a floating-point computation of the same formula to within one count in one of 257 entries. Malformed sections, sizes that would overflow, and tables that don't cover the frame all fall back to the stock table. A KUnit test checks the computed gains for a synthetic setfile, with a centred and an offset optical centre. It also checks that a tuned table is kept, and checks the fallbacks.

Auto exposure may slow to 15 fps by default. V4L2_CID_EXPOSURE_AUTO_PRIORITY now defaults to 1 on H17 firmware, so in low light auto exposure lengthens the exposure down to 15 fps before it raises the gain. Clearing it still holds the frame rate. This departs from the V4L2 default (constant frame rate). Older firmware keeps the V4L2 default.

Binned sensor config (DT). The J714s sizes move from config 6 (full-resolution 3040x2880, the first of two stacked frames) to config 8 (the same field of view binned 2x2 to 1520x1440), with the crops centred in binned pixels. The driver derives 1280x960 and 960x1280 only without upscaling, which the smaller binned crops no longer allow, so they are listed as presets too. With the computed gains, I compared every candidate config at 1920x1080 in a lamp-lit room. The numbers are frame-to-frame noise (standard deviation, 8-bit, mean of three frame pairs, with the 1% largest changes dropped):

config luma Cb Cr
8, binned (this PR) 0.9 0.6 0.5
5, 1920x2160 5.8 1.5 1.3
6, 3040x5760 (until now) 5.3 1.3 1.2
7, 3040x2880 5.3 1.4 1.2
0, 3072x3024 4.8 1.3 1.1

A second, more detailed scene gave 1.5-1.8 luma for config 8 against 4.5-4.9 for the others. Binning costs fine detail: magnified, skin and hair look smoother, and edges step from the upscale. At the sizes the camera is viewed at, the lower noise matters more.

Measured on a J714s at 1920x1080, in the same dim room, from the 45th frame. Grain is the standard deviation of (frame − 9x9 box blur) over the centre quarter.

luma grain colour noise
before (flat 0xc404) 11.9 0.73
with the computed 0xc404 2.4 0.46

Allowing 15 fps alone gave about 10% less luma noise and a brighter picture in the same scene.

On a J813, @sithglan measured this series at the J813's config 7: luma grain 12.7 → 3.6 and frame-to-frame luma 19.8 → 4.7. Config 8 also suits the J813 (neutral colour, lowest noise); config 10 keeps the firmware's default white point (magenta). Moving the J813 presets is a separate DT change.

#2194 (J815 2226 setfiles) also edits isp_ch_load_setfile(), so whichever PR lands second needs a small rebase.

Testing:

  • Rebased onto integration/aurora 26294e8. The only conflict was the new sensor-name field in the setfile table.
  • J714s (M5 Pro), running integration/aurora c33c5fd plus local patches. None of those patches touch the ISP driver, and c33c5fd's ISP driver is identical to this PR's base. The ISP module was built from this branch and loaded on that kernel.
  • The final DT presets ran from the installed c33c5fd DTB with exactly this PR's preset changes applied (not a DTB built from this branch). 1920x1080, 1280x720, 640x480, 1280x960 and 960x1280 stream, centred, with no dark edges.
  • 1760x1328, 1328x1760, 1552x1552 and 1080x1920 (every size taller than 1280) deliver no frames on the J714s. They fail the same way with the old config 6 and its crops, so the failure predates this PR. It is left for a separate fix.
  • Final module checks:
    • 1920x1080 capture: luma grain 2.46.
    • The final module, with the grain fix toggled by a throwaway parameter in the same dim scene: frame-to-frame luma 12.1 off, 1.07 on (measured before the gate moved from platform ids to the setfile contents; the J714s table is unchanged by that).
    • Exposure priority reads back as 1.
    • Sensor configs 0, 5, 6, 7 and 8 all stream at 1920x1080. The table above comes from a throwaway build that switched config and crop by module parameter.
  • tools/ci-local.sh (host tests and DT checks, merged onto the current integration/aurora) passes on the final commits: all 427 host tests, and DT checks with no new warnings. KUnit in arm64 QEMU passes 49/49, including isp_test_snf_radial. checkpatch --strict reports nothing, and the module builds clean with W=1.
  • Not tested:
    • The exposure priority default on other H17 machines.
    • Suspend/resume while streaming.

@Isaac-Duarte Isaac-Duarte changed the title media: apple: isp, arm64: dts: t6050-j714s: cut the camera's grain 5x as macOS does; add zoom media: apple: isp, arm64: dts: t6050-j714s: cut the camera's grain 5x as macOS does Nov 19, 2026
@sithglan

Copy link
Copy Markdown
Contributor

This fixes the J813 (M5 Air, T8142) camera too. The J813 loads the same IMX958 isp_2224_01XX.dat (28660 bytes), so the 0xc404 change applies to it as is. In this file 0xc404 ships flat too, and the shading tables parse (four 49x49 tables, frame 3072x3024), so the driver doesn't fall back.

I built the PR's three driver files as a module for my J813 kernel. Its ISP driver is identical to this PR's base, 0abc2f3. I measured one scene in morning room light at 1920x1080, frames 45-74:

  • Grain is your measure: frame − 9x9 box, over the centre quarter.
  • Frame-to-frame noise is the standard deviation of the difference over the whole frame, divided by √2, with the 1% largest changes dropped. Its scale may differ from yours.
J813, 1920x1080 luma grain frame-to-frame Y Cb Cr mean U/V
stock driver, config 7 (J813 DT) 12.7 19.8 7.1 5.4 –
this PR, config 7 (J813 DT) 3.6 4.7 1.6 1.4 128.0/127.0
this PR, config 8 (binned) 3.6 2.2 0.9 0.7 127.2/127.3
this PR, config 10 (binned) 4.5 6.1 2.5 1.9 157.4/165.1

After the PR runs I ran the stock and the PR config-7 cases again. Both gave the same numbers as before, so the light didn't change.

  • Noise filter gains: at config 7 they account for all of the improvement.
  • Exposure priority: it had no effect at this light. The stream stayed at 30 fps with the control at 0 or 1, on both the stock and the patched driver.
  • Binned configs on the J813: 8 and 10 are both 1520x1440.
    • Config 8 behaves as it does on your J714s. The colour is neutral at all four J813 preset sizes (U/V 127.3-128.0 / 127.1-127.6). Frame-to-frame luma over the centre quarter is 0.54-0.59, against 1.51-2.13 in config 7.
    • In config 10 the firmware AWB stays at its default white point, which gives the magenta cast. That is why the J813 presets were moved to config 7.
    • So the J813 presets should follow this PR to config 8. That is a separate DT change.

I ran config 8 by remapping the J813's config-7 presets to it (crops halved) with a throwaway module parameter, not from a DTB. I didn't test suspend/resume while streaming or dimmer light.

@Isaac-Duarte

Copy link
Copy Markdown
Contributor Author

@sithglan Thanks for testing, I will include J813

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for this, a 5x grain cut on the J714s camera is a big visible win, and computing the radial gains from the lens shading tables is a nice way to do it.

One change before it goes in. The recompute is enabled through a fixed list of platform ids in the setfile table (isp-cam.c:98, {0x74, 0x71} on the IMX958 entry). In this tree we select behaviour by what the hardware or its data describes, not by the list of machines it was tried on. The condition the code actually needs is in the setfile itself: a spatial noise filter section (0xc404) that ships flat, plus lens shading tables to derive it from. Could the recompute run whenever that holds, for any sensor, with the optical-centre offset coming from the setfile or the ADT rather than a per-entry constant? If a sensor really must keep the flat filter, a comment naming why would cover it.

We can run it on our M4 Pro and A18 Pro cameras once it is keyed that way.

@Isaac-Duarte

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Done in c594128. I went back to camerad to see what it keys on, and the commit message had it wrong.

When it runs. camerad recomputes 0xc404 for any sensor whose setfile has the lens shading tables (0xc003) and a 0xc404 section. A RadialGainEnable preference gates it, and it defaults to on. When the setfile also has 0xc407, camerad fills 0xc404 with a different routine. The 0x74 I quoted wasn't the gate. The driver now:

  • runs for any setfile with 0xc003 and a flat 0xc404 and no 0xc407;
  • keeps a 0xc404 that ships tuned, as you suggested;
  • has no platform list, so isp->platform_id is no longer used here.

Optical centre. This isn't in the setfile, and camerad doesn't read it from the ADT either. It hard-codes it in a switch on sensor id, next to its other per-sensor defaults: 0x958 and 0x814 at −156 shading-frame pixels, 0x923 at −600, and 0 for every other sensor. So the offset stays in the setfile table entry, which is keyed by sensor. IMX814 (isp_2123_01XX) now gets −156 too, and every other entry uses the frame centre.

What this turns on. All eight setfiles I have locally ship 0xc404 flat and parse cleanly: 1820/1822 (M1), 1921/1922/1925, 2224, 8720/8723. So this changes the filter on those machines too. Measured only on the J714s and on sithglan's J813. Results from your M4 Pro and A18 Pro runs would be very welcome.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for c594128. Running the recompute for any setfile that ships a flat 0xc404 with lens shading tables, keeping a tuned 0xc404 as it is, and the per-sensor centre offset is the shape we asked for. Since this now changes the filter on other Macs too, we will run camera rows on our M1 Pro, M2, M4 Pro and A18 Pro.

One small request: the code comments in isp-cam.c and the commit message describe what the macOS camera daemon does internally. Please describe the condition and the computation only by the setfile sections and the math, without referring to macOS internals.

In low light, auto exposure either raises the gain or lengthens the
exposure, which slows the frame rate. The driver held the rate unless
userspace set V4L2_CID_EXPOSURE_AUTO_PRIORITY, which nothing does by
default, so on the H17 cameras it raised the gain, and the picture was
grainy and dark in dim light.

Default the control to 1 on H17 firmware, so that the exposure
lengthens down to the driver's 15 fps minimum before the gain rises; no
H17 preset asks for a higher minimum. On a J714s in a dim room this
brightens the picture and lowers the luma noise by about 10%. Clearing
the control still holds the frame rate. This departs from the V4L2
default, under which the frame rate stays constant; the older firmware
keeps the V4L2 default.

Signed-off-by: Isaac Duarte <[email protected]>
The J714s camera is very grainy, most of all in dim light. Neither the
temporal nor the multi-band noise filter settings change that: the
spatial noise filter's gains in the setfile do.

Section 0xc404 of a setfile holds the spatial noise filter's gain by
distance from the optical centre, and every setfile at hand ships it
flat. Lens shading correction (section 0xc003) multiplies the signal,
and with it the noise, by a gain that grows towards the edges. Setting
the filter's gain at each radius to the inverse of the mean shading
gain there, averaged over the four colour tables and the directions to
the four frame corners, lets the filter follow that noise and filter
it.

Compute that table at setfile load, in integer arithmetic, whenever the
setfile has the lens shading tables, a flat 0xc404 and no 0xc407 section;
a 0xc404 that ships tuned is kept. The setfile does not carry the
optical centre, so the setfile table entry does: 156 shading-frame
pixels above the frame's for the IMX958 and IMX814, the frame's own
otherwise. For isp_2224_01XX the integer result matches a
floating-point computation of the same formula to within one count in
one of the 257 entries. On a J714s in a dim room the luma grain drops
from 11.9 to 2.4 (standard deviation of the high-pass luma) and the
colour noise from 0.73 to 0.46, at the same brightness and without
visible loss of detail. On a J813, which loads the same setfile, in
room light at its config 7, the luma grain drops from 12.7 to 3.6 and
the frame to frame luma noise from 19.8 to 4.7. A setfile whose
sections do not parse, or whose tables do not cover the frame, keeps
its stock gains.

Signed-off-by: Isaac Duarte <[email protected]>
The camera sizes come from sensor config 6, two stacked full-resolution
3040x2880 frames of which the ISP processes the first. Its picture is
grainy indoors, even with the noise filter gains the previous commit
computes.

Config 8 delivers the same field of view binned 2x2 to 1520x1440. With
those gains, on a J714s at 1920x1080 in a lamp-lit room, the frame to
frame noise (standard deviation, 8-bit) of each candidate config was:

  config                        luma   Cb    Cr
  8, binned (this commit)       0.9    0.6   0.5
  5, 1920x2160                  5.8    1.5   1.3
  6, 3040x5760 (until now)      5.3    1.3   1.2
  7, 3040x2880                  5.3    1.4   1.2
  0, 3072x3024                  4.8    1.3   1.1

and 1.5-1.8 luma against 4.5-4.9 in a second, more detailed scene.

Binning costs fine detail: magnified, skin and hair look smoother and
edges step from the upscale. At the sizes the camera is viewed at, the
lower noise matters more. Use config 8 for all sizes, with the crops
centred in binned pixels. The driver derives 1280x960 and 960x1280
from the presets only without upscaling, which the smaller binned crops
no longer allow, so list them too. The derived square shrinks from
2026x2026 to 1012x1012.

Signed-off-by: Isaac Duarte <[email protected]>
@Isaac-Duarte

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Done in ec78739. The comments in isp-cam.c and the commit message now describe the condition and the computation only by the setfile sections and the math. I did the same for the exposure priority comment in isp-v4l2.c, the other two commit messages and the PR description.

The branch is also rebased onto 26294e8. The only conflict was the new sensor name field in the setfile table. Nothing else changed in the code.

Thanks for running the M1 Pro, M2, M4 Pro and A18 Pro rows.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for ec78739. Describing the condition and the computation by the setfile sections and the math, in the comments, the commit messages and the description, covers our last request. We will post the camera rows from our M1 Pro, M2, M4 Pro and A18 Pro here.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Review (merge lane), head ec78739aa1cc:

The noise filter recompute is bounds-safe:

  • Every read and write stays inside the section length.
  • The 0xc404 size is checked exactly, and the table size check is done in 64-bit, so the overflow case is rejected.
  • Interpolation indices are clamped, and no divisor can be zero.
  • All writes happen after the whole table is computed, so every bail-out leaves the stock table byte-identical.

The function and the KUnit cases also pass under ASan/UBSan with 300k random and truncated setfiles. The table is written into the setfile buffer before CH_SET_FILE_LOAD and recomputed on every stream start, so it is the same after resume. On the DT side, the config 8 crops are even, centred and inside 1520x1440, and the aspect ratios match the outputs.

Local checks on the merge into integration/aurora 1473d156d6ca, rechecked on the current tip 4c4cbf086071:

  • The ISP objects and the J714s DTB build with W=1.
  • The isp host tests pass (24/24).

Follow-ups, none blocking:

  • Neither success nor "table not flat" logs anything. A dev_dbg when the table is computed would let the M1/M2/M4/A18 rows tell computed from stock.
  • The first u32 of 0xc404 is zeroed without being part of the "flat" test. Either include it in the test or leave it alone.
  • With the -156 centre offset, radii past the nearer (top) corners extrapolate the shading grid by up to ~3 cells. Clamping r to each corner's distance would avoid that.
  • Copy the validated record fields into locals instead of re-reading them from data_surf. That is hardening only.
  • media: apple: isp: Load the camera module tuning the DT names (J815: IMX958 2226_02) #2194: both PRs append a field to struct isp_setfile, and the 2224 entry here is positional. Designated initializers (as the IMX814 entry already uses) would turn the second rebase into a no-op. The J815 2226 entries need their own centre offset.

Merging. The camera rows on M1 Pro, M2, M4 Pro and A18 Pro, and the J813 at its DT's config, are post-merge.

@DjDeveloperr
DjDeveloperr merged commit 51b75cb into aurora-silicon:integration/aurora Nov 20, 2026
2 checks passed
allanclempe added a commit to allanclempe/omarchy-m4 that referenced this pull request Nov 20, 2026
…close it

Most of the grain comes from the ISP's spatial noise filter, whose gain
table ships flat in the IMX958 setfile (checked on this Mac's file) and
which aurora-silicon/linux#2233 now computes from the lens shading
tables, plus the unbinned sensor config the J616c presets select. Neither
fix has reached the installed kernel. The document maps every stage
macOS applies against what Linux sends, compares the reverse-engineering
paths (measurement and reading the camera stack over a hypervisor trace),
lists what to copy from macOS next time and what the camera lab should
measure. JOURNEY 9.40 gets the findings and corrects the earlier
white-balance reading.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants