Skip to content

fix(camera-preview): prefer better accepted per-photo colour fits - #2587

Draft
FooVoo wants to merge 1 commit into
storytold:mainfrom
FooVoo:fix/profile-colour-selection
Draft

FooVoo wants to merge 1 commit into
storytold:mainfrom
FooVoo:fix/profile-colour-selection

Conversation

@FooVoo

@FooVoo FooVoo commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Update: this PR is a draft. The local port to current main failed fresh sparse-colour/small-subject validation and has not been pushed. See the latest validation reply; earlier CI and photo results below describe the original published head, not a validated current-main fix.

Problem

An accepted pooled camera profile can produce a worse starting look than the photo's own accepted colour fit. The ordered search stops at the first profile that passes the neutral-fallback gates, without comparing it with the per-photo alternative. A Sony A6000 foliage diagnostic reproduced this: both fits used the same sensor/reference samples, but the profile had higher gamma-domain fitting error and worse rendered camera-JPEG appearance.

Changes

  • Compare the accepted profile look with an accepted per-photo colour fit using the same final fitting samples, tone method, edge filter and dark-scene setting.
  • Score both completed looks, including hue, tone and chroma, with the existing gamma-domain colour-pair selection objective. Select the per-photo fit only when its finite error is strictly lower; retain the profile on a tie, an unusable alternative or nonfinite scores.
  • Preserve the existing absolute/highlight acceptance gates, clipped-pixel refit behavior, unprofiled and partial fallbacks, and DRO handling.
  • Bump camera-look version 12 to 13 and render-cache version 69 to 70, since selection can change stored looks and rendered pixels without changing profile files.
  • Add synthetic regressions for both selection outcomes, successful/failed clipped refits, the unclipped-only search path and sparse-colour profile fallback; document the selection limits.
Input Before After
Accepted profile and better accepted per-photo fit First accepted profile wins Lower gamma error wins on the same fitting samples
Better profile, unusable alternative, tie or nonfinite comparison Profile retained Profile retained
No profile or partial fallback Existing fitting path Existing fitting path

The PR contains only crates/engine/src/camera_preview.rs, crates/engine/src/media.rs and docs/camera-preview-colour.md. It adds no dependencies or public API. It does not change RAW decoding, profile bytes, proxy resolution, acceptance thresholds or clipping policy, and does not bundle the experimental A6000 profile.

Validation

Fresh full local CI passed on upstream base c66014e65f019264f982b7a720e5a7d9df9ab408 plus the exact three-file patch submitted here, with no temporary workaround:

cargo xtask ci --summary-md

All eight stages passed: formatting, strict workspace Clippy, HEIF, workspace tests, parity, dependency layers, asset attribution and WebAssembly. The run took 46m 01s, including clean-checkout rebuilds. The harness reported 4,652 passing test executions, 0 failed and 40 ignored, including all 82 camera-preview tests. CI additionally recorded 169 availability skips: 137 corpus, 24 fonts and 8 model tests. The checkout had 0 of 451 pinned RAWs and no craft-fonts. The pipeline GPU was Apple M2 through Metal, using Rust 1.97.1 on macOS/aarch64. Existing WebAssembly warnings in unchanged code did not fail the checks. These are local results; no GitHub-hosted CI result is claimed.

The synthetic coverage includes a biased profile that still passes the existing gates, a better profile when both fits pass, and sparse-colour scenes that need a profile. The accepted-look tests cover the original, successful unclipped-refit, failed-refit and unclipped-only search paths.

Earlier photographic diagnostics used the identical Rust source files and runtime base, before rebasing this focused patch onto the current README-only upstream update. All 100 fresh-process CPU exports completed: 50 originals, each with the experimental profile directory enabled and disabled. All 50 original hashes and the experiment's profile hash remained unchanged. The 25 A6000 exports with the trial profile disabled stayed pixel-identical to the pre-change baseline. These measurements are separate from the fresh CI run above. The same source-identical binary also completed a 1600×1000 headless demo snapshot in 3.15 seconds; the resulting app view was visually inspected.

Mean CIE76 against embedded camera JPEGs, lower is closer:

A6000 diagnostic split Per-photo baseline Unguarded trial profile Selection guard
Training, 12 photos 6.0400 5.8820 5.9068
Reused validation, 6 photos 6.8568 6.7512 6.7725
Style challenges, 7 photos 5.7250 6.6780 5.8748
Foliage challenge 10.3727 12.3278 10.3727

Five of seven challenges return to their per-photo baselines; the foliage pixels match that baseline exactly. Two challenge regressions remain, at +0.7274 and +0.3213 relative to the per-photo baseline. The stairwell gives up the trial profile's benefit (8.7166 to 9.0716); the night-city result retains its improvement (4.9562 baseline to 4.8147). Five training images also lose small trial-profile improvements, +0.0392 to +0.1886.

The guard also affects bundled profiles. Across 25 A7CR controls, candidate-directory and empty-directory outputs remain identical to each other, but 14 photos change relative to the old algorithm: 12 improve and 2 worsen. The other 11 remain unchanged. Mean error changes from 2.8896 to 2.5579; the two regressions are +0.1763 and +0.6384, with the latter about 1 L* darker on average.

These are reused, same-photographer appearance diagnostics, not an untouched holdout or calibrated colour-accuracy result. Comparisons use aspect-preserving BOX reduction to 200 px, a centered common intersection, central 80% ROI and reference-defined clipping masks; A7CR orientation/framing was reviewed before scoring with no post-score exclusions. They do not validate full-resolution detail or all cameras.

This is a selection guard, not a fix for every fitting-proxy/full-render difference. Nonlinear colour/tone operations occur at different resolutions and in different orders, and the gamma fitting objective differs from final Lab error. The legacy colour scoring split can overlap broader chroma training, so it is not independent final validation. Additional per-photo fitting is bounded but has not had a controlled performance benchmark. The trial profile still fails its original promotion criteria and remains unbundled.

Test data

The regression tests generate their own sensor/reference samples and need no photo downloads. No private originals, embedded JPEGs, profile experiment, source paths, capture dates or photo archive are included. Only aggregate diagnostic measurements are reported here.

Summary by CodeRabbit

  • Improvements
    • Camera-profiled photo previews can now better reflect each photo’s individual colour, while retaining the camera profile when it produces the better result.
    • Colour fitting now handles clipped pixels more effectively, with fallback behavior when a fitting attempt cannot be completed.
  • Other
    • Updated preview and thumbnail cache versions, so affected cached results may be refreshed.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The camera preview fitting flow now refits selected looks on unclipped pixels and compares accepted camera-profile and per-photo colour fits. The look version advances to 13, and the render-cache version advances to 70.

Changes: Camera look selection

Layer / File(s) Summary
Selected look refitting
crates/engine/src/camera_preview.rs
The fitting flow refits the all-pixel attempt on unclipped pixels and retains the all-pixel result if refitting fails. If the all-pixel search fails, it searches unclipped pixels and falls back to fit_partial if needed. The look version advances to 13.
Profile and per-photo colour comparison
crates/engine/src/camera_preview.rs, crates/engine/src/media.rs, docs/camera-preview-colour.md
For profile attempts, the code compares the profile fit with a per-photo fit on the same cohort and attempt. It selects the per-photo fit only when its finite error is lower. Tests cover selection outcomes. The documentation describes the fitting and comparison behavior, and the render-cache version advances to 70.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • storytold/lightcraft#1912: The PR compares accepted profile and per-photo colour fits, but the issue also concerns a missing profile, sharpening, or halos, which this change does not establish as fixed.
  • storytold/lightcraft#2307: The PR changes profile-versus-per-photo colour selection, but it does not establish a change to monochrome-preview handling.

Suggested reviewers: echelon

Merge Risk: Minimal · up to e9741

The reported DRO selection concern does not require a change. The PR is mergeable after normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preferring an accepted per-photo colour fit when it is better than the camera-profile fit.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Finishing Touches

🧪 Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.99.0)

Clippy execution timed out

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
ℹ️ Recent review info

⚙️ Run configuration

📥 Commits

Reviewing files that changed from the base of the PR and between c66014e and e97414e.

📒 Files selected for processing: 3

  • crates/engine/src/camera_preview.rs
  • crates/engine/src/media.rs
  • docs/camera-preview-colour.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@wanikhawar wanikhawar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts with main, please rebase. The change itself reads correctly.

@wanikhawar

Copy link
Copy Markdown
Contributor

Needs a rebase and a port: fit_look_with now lives in camera_preview/look_fit.rs, LOOK_VERSION is 29 and RENDER_CACHE_VERSION is 90 on main, so the bumps need to follow. One design point: the profile and the per-photo look are both scored on the pairs the per-photo fit was trained on, so the per-photo fit, which has more freedom, is favoured in-sample. The profile exists to generalise when a photo shows little of a colour (see the held-out numbers in docs/camera-preview-colour.md). Please add held-out evidence (dE against the camera JPEG with the selection on and off, or scoring on pairs held out from both fits) so this does not regress those cases. Also check the ordering against #5019, #5000 and #3972, which change the same selection path.

@FooVoo

FooVoo commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I’m checking the current selection path and the overlap with #5019, #5000 and #3972 before porting this change. The existing measurements were reused diagnostics, so I won’t treat them as independent validation.

If this still addresses a separate gap, I’ll update it against current main and add held-out evidence, including sparse-colour scenes where the pooled profile should help. If the change is already covered or superseded, I’ll close this PR with the relevant links.

@FooVoo
FooVoo marked this pull request as draft December 3, 2026 12:09
@FooVoo

FooVoo commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

The port still addresses a separate gap on current main; #5019, #5000, #3972 and #4975 do not replace the accepted-profile comparison. I am keeping this PR as a draft because the revised approach has not passed photographic validation. The local port has not been pushed.

The first fresh 32-photo evaluation failed a frozen sparse-colour criterion. I then froze one conservative revision: retain the pooled profile unless the per-photo proxy MSE improves by more than 2%. This is an engineering margin, not a statistical guarantee. There was no threshold sweep, profile retraining or post-score exclusion.

The second frozen evaluation used 23 unseen originals after face and near-duplicate screening: 14 A6000 photos from 14 capture occasions and 9 A7CR photos from 3 shared occasions. A7CR is file-unseen, not occasion-independent. The profile bytes were unchanged. All 46 fresh-process CPU exports completed with unchanged original hashes; geometry was reviewed before scoring.

Camera Photos Broad mean CIE76, selection off Revised guard
A6000 14 4.9299 4.8687
A7CR 9 2.1638 1.8042

The means improved, but the frozen criteria failed: an A6000 flower worsened by 0.7145 on its 2,549-pixel colour mask and 2.3011 on its 12-pixel subject mask; an A7CR image worsened by 5.5233 on its 24-pixel colour mask. These masks were defined from the reference before exports and retain their measured limitations. Highlight and combined black-or-white endpoint criteria passed where evaluable; 3 colour masks and 8 highlight masks had insufficient pixels for evaluation. This is camera-JPEG appearance validation at 200 px after 1200 px rendering, not calibrated colour accuracy or full-resolution detail validation.

The original regression fails against unchanged main. The local port passes all 2,073 engine unit tests (9 ignored), including 128 camera-preview tests (1 ignored), strict engine Clippy and the engine WebAssembly check. The full local CI attempt stopped at 19 UI-test drop_non_drop diagnostics under Rust 1.97.1; the same 19 diagnostics were reproduced on unchanged main at 10b363c. That is a separate upstream blocker, not an explanation for the photographic regressions. No full-CI pass is claimed.

I have stopped threshold tuning and preserved both evaluations. The next step is design only, addressing the small-subject regressions as well as the scoring split's overlap with chroma training; a shared withheld pixel partition alone would not establish better final renders. No private originals, references, paths or capture dates are included here.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants