Repository navigation
media: apple: isp, arm64: dts: t6050-j714s: cut the camera's grain 5x as macOS does - #2233
Conversation
ee565c5 to
efc79c5
Compare
|
This fixes the J813 (M5 Air, T8142) camera too. The J813 loads the same IMX958 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:
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.
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. |
|
@sithglan Thanks for testing, I will include J813 |
efc79c5 to
846d89b
Compare
|
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 ( We can run it on our M4 Pro and A18 Pro cameras once it is keyed that way. |
846d89b to
c594128
Compare
|
@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
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 ( 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. |
|
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 |
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]>
c594128 to
ec78739
Compare
|
@RyanTheTide Done in ec78739. The comments in 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. |
|
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. |
|
Review (merge lane), head The noise filter recompute is bounds-safe:
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 Local checks on the merge into integration/aurora
Follow-ups, none blocking:
Merging. The camera rows on M1 Pro, M2, M4 Pro and A18 Pro, and the J813 at its DT's config, are post-merge. |
51b75cb
into
aurora-silicon:integration/aurora
…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.
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.
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_PRIORITYnow 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):
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.
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:
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, includingisp_test_snf_radial. checkpatch--strictreports nothing, and the module builds clean with W=1.