Repository navigation
LR-EDIT-EFFECTS-GRAIN: grain skips a degenerate frame instead of producing NaN pixels - #3003
Conversation
…oducing NaN pixels A zero-width crop mapped output pixels to NaN/inf grain coordinates, so grain turned the whole render into NaN (CPU path and GPU params). Grain is now skipped when the frame has no finite mapping, grain_noise returns 0 for non-finite coordinates, and a non-finite grain term is never added. Sources: own design. (cherry picked from commit 4023853) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Grain guards and regression tests crates/pipeline/src/finish.rs, crates/pipeline/src/tests.rs |
Grain parameters are created only when scale, dimensions, and the output-to-normalized transform meet finite and non-degenerate checks. Non-finite coordinates produce zero noise, and non-finite grain values are not added to encoded color. Tests cover non-finite coordinates and a zero-width crop with grain enabled. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: echelon, mdlmarkham
Merge Risk: 
Minimal · up to f621d
-
No actionable merge-blocking risk remains from the reviewed change.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the core change: grain now skips a degenerate frame rather than producing NaN pixels. The raw summary and PR objectives confirm this. The changes to grain_noise, FinishParams::new, grain application, and the added tests all address non-finite grain output on zero-width crops. The title includes a tracker-style prefix (LR-EDIT-EFFECTS-GRAIN), which is acceptable and does not make it misleading.
-
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
FredApps
left a comment
There was a problem hiding this comment.
Approving at f621d24. I read the whole diff.
- Skip grain on a degenerate frame:
FinishParamscomputesout_to_normonce and enables grain only whenpx_per_long, the output size and every entry of that matrix are finite and positive. A zero-width crop therefore turns grain off for both the CPU and GPU paths, since both read the same params. - Per-pixel guards:
grain_noisereturns 0 for a non-finite coordinate and the grain add is skipped whenkis not finite, so a NaN cannot reach the pixel from either place. - Tests: a unit test covers NaN and infinite coordinates, and a render test with a zero-width crop and grain at 60 checks that every sample in the F32 output is finite.
The normal path is unchanged for a finite frame: the same values are computed in the same order. I found no defect. The gate is green at this head. I read the code and did not run it.
Problem: with Grain on, a crop of zero width (e.g. dragging a crop edge onto the other) mapped pixels to NaN/infinite grain coordinates, so the render came out as NaN pixels (CPU path, and the GPU grain params).
Change (
crates/pipeline/src/finish.rs): grain is skipped when the frame has no finite mapping (non-finite/zero scale orout_to_norm),grain_noisereturns 0 for non-finite coordinates, and a non-finite grain term is never added. Kept minimal, since grain is being reworked in #2330 / #1060.Tests: new
grain_noise_is_finite_for_degenerate_coordinates(unit) andzero_width_crop_with_grain_renders_finite_pixels(hostile-input render, asserts every sample finite). Rancargo test -p lightcraft-pipeline grain/zero_width(pass),cargo fmt,cargo clippy -p lightcraft-pipeline --all-targets -D warnings(clean).Refs #2330, #1060
🤖 Generated with Claude Code
Summary by CodeRabbit