Skip to content

LR-EDIT-LIGHT-HIGHLIGHTS: partly clipped highlights take the colour of bright neighbours; previews clip before averaging (#548) - #602

Closed
radialmonster wants to merge 1 commit into
storytold:mainfrom
radialmonster:highlight-partial-clip
Closed

radialmonster wants to merge 1 commit into
storytold:mainfrom
radialmonster:highlight-partial-clip

Conversation

@radialmonster

@radialmonster radialmonster commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Binned previews and thumbnails now decide clipping per sensor sample before averaging. On coarse bins, that removes the green speckles and colour noise in clipped areas reported in #548. Rebased onto #607, which rewrote highlight::reconstruct, and reduced, as asked in review, to what #607 doesn't cover.

Change

  • develop_binned_masked: when the raw is binned for a preview or thumbnail, each colour keeps its block mean together with a mask of which colours had a clipped sample. Previously, averaging first let a few clipped samples hide in the mean, and the reconstruction couldn't see them.
  • reconstruct_masked: main's reconstruct_with (LR-EDIT-LIGHT-HIGHLIGHTS: clipped highlights stay neutral when darkened (#523) #607) now takes the "which channels are clipped" check as a parameter. The plain path passes main's own value test, so LR-EDIT-LIGHT-HIGHLIGHTS: clipped highlights stay neutral when darkened (#523) #607's logic runs unchanged: dark-detail weighting, the demosaic ring, desaturation as more channels clip, and neutral cores. A test proves that a mask built from the values gives byte-identical output to reconstruct_with.
  • Fully masked blocks: a block where every colour is masked becomes neutral at its own brightest channel, not lifted to the full clip level. Lifting it would turn a specular point into a white speckle.
  • Denoise: the denoised version of a photo uses the same mask.

This is decoder-side: it changes the camera RGB that comes out of binning and reconstruction, before any settings apply. It also fixes broken output, so under docs/process-versions.md it isn't gated on a process. Exports and 1:1 views don't bin and are byte-identical to main.

Measurements

CC0 Huawei DNGs from raw.pixls.us. A speckle is a bright pixel whose green exceeds red, blue and its 3 × 3 median by more than 8 levels. C* is the mean chroma in the bright areas of main's render.

File, 500 px Speckles, main → this PR C*, main → this PR
WAS-LX1A, default 4032 → 311 27.8 → 10.6
WAS-LX1A, Highlights −100 4058 → 86 32.1 → 12.7
PRA-LX1, default 1299 → 5 29.5 → 17.7
PRA-LX1, Highlights −100 1268 → 5 32.9 → 16.4

The 500 px renders also move closer to a downscaled 1000 px render: the bright-area difference goes 11.7 → 8.9 on WAS-LX1A and 21.9 → 12.0 on PRA-LX1 at −100. The 1000 px renders are identical between main and this PR. The #548 iPhone 15 Pro Max DNG has a GainMap in OpcodeList3, so it's never binned. It's byte-identical here, and its cloud tint is fixed by #607.

PRA-LX1 at 500 px: main (green speckles) vs this PR WAS-LX1A at 500 px: main vs this PR

Left: main 5436951. Right: this PR. Default settings, 500 px.

Tests

RENDER_CACHE_VERSION is 42 (main is 37, and our other open PRs use 38–41 and 43), so adjust it at merge.

Part of #548.

@AlexChambers

Copy link
Copy Markdown
Contributor

@radialmonster heads-up: #602 and my #607 both rework partly clipped reconstruction in crates/raw/src/highlight.rs, starting from different reports (your #548 iPhone, my #523 Sony), so they'll conflict and the maintainers would face two rewrites of the same step. The ideas overlap a lot. Both take colour only from bright unclipped neighbours and ignore dark detail and demosaic edge pixels. #607 also does three things #602 doesn't seem to:

#586 is complementary: it's about recognising clipping, and #607 would sit on top of it fine.

Proposal: I run #602 against #607's tests and cases, you run #607 on your iPhone 15 Pro Max file and the Huawei DNGs, and then we fold the two into one PR on top of #586, whichever base you prefer, so the maintainers review a single reconstruction change. Does that work for you?

@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you @radialmonster! The binned mask fixing the green speckles of #548 is a real improvement.

#657 landed #607 (AlexChambers), which rewrites highlight::reconstruct too: dark-detail weighting, the demosaic ring, and desaturation as more channels clip. It also landed your #586, with one fix on your branch: the saturation search no longer underflows on a negative or NaN black level. #602 now conflicts with both. Could you rebase it onto main, keeping only what #607 doesn't cover (develop_binned_masked plus a masked variant of the new reconstruct), and re-measure on the #548 files?

Please join our Discord if you haven't already: https://discord.gg/artcraft

@radialmonster

Copy link
Copy Markdown
Contributor Author

@AlexChambers thanks, and agreed that one reconstruction change is better than two. Since #607 has landed, I'll do it the way echelon asked: rebase #602 onto main and keep only what #607 doesn't cover, which is the binned mask for the coarse-bin green speckles plus a masked variant of the new reconstruct. Then I'll re-measure on the #548 iPhone 15 Pro Max and Huawei files. I'll also run your #607 tests and cases against it, so nothing you fixed regresses.

…before averaging (storytold#548)

Rework of storytold#602 on top of storytold#607's highlight reconstruction, keeping only what
storytold#607 doesn't cover. Small previews and thumbnails bin the mosaic (8 x 8 at
500 px); a colour with one clipped sample in its block used to take the
block's maximum, so a specular point turned the block's green to the clip
level and reconstruction kept it: green speckles.

- raw: RawImage::develop_binned_masked keeps every channel its block mean and
  returns a mask of the colours that had a clipped sample (develop_binned and
  the camera-look proxy keep the maximum rule).
- highlight: reconstruct_masked is storytold#607's reconstruct_with with the clipped
  channels taken from the mask (sources, rim, rebuild and fade unchanged); a
  masked mean is a lower bound, and a fully masked block becomes the clipped
  white at its own brightest channel rather than lifted to the clip level.
  A mask built from the values reproduces reconstruct_with exactly (test).
- engine: previews/thumbnails (and their denoised twin) use the mask.

RENDER_CACHE_VERSION 42 (main + 5; adjust at merge).
@radialmonster
radialmonster force-pushed the highlight-partial-clip branch from ec39ca1 to 7c9feb5 Compare October 10, 2026 08:21
@radialmonster

Copy link
Copy Markdown
Contributor Author

@echelon @AlexChambers rebased onto main and reduced to what #607 doesn't cover: develop_binned_masked plus a masked variant of the new reconstruct. #607's reconstruction runs unchanged; the mask only decides which channels count as clipped on coarse bins, and a test shows a value-built mask matches reconstruct_with byte for byte. All 11 of #607's highlight tests pass.

Re-measured on the CC0 Huawei DNGs at 500 px: green speckles 4032 → 311 (WAS-LX1A) and 1299 → 5 (PRA-LX1), with bright-area chroma down from 28–33 to 11–18. Exports and 1:1 views are byte-identical to main. The #548 iPhone DNG has a gain map and is never binned, so #607 alone covers it. Details and crops are in the updated description.

@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you @radialmonster! The #548 fix landed in #692, from the maintainer merge on this branch (ec39ca1). It keeps #607's reconstruction as the core and adds your binned mask (clipping decided before averaging) with reconstruct_masked. The regression test fails without it. Your later push (7c9feb5) replaced that merge, so GitHub still shows this PR as open. If it has anything beyond what landed, please open a follow-up on top of main; otherwise this can be closed.

Please join our Discord if you haven't already: https://discord.gg/artcraft

mysbryce pushed a commit to mysbryce/lightcraft that referenced this pull request Oct 10, 2026
# Conflicts:
#	crates/engine/src/media.rs
@radialmonster

Copy link
Copy Markdown
Contributor Author

Thanks @echelon! The binned mask with reconstruct_masked on top of #607 is all this branch adds, and it landed in #692. Closing.

clydecbrown pushed a commit to clydecbrown/lightcraft that referenced this pull request Oct 26, 2026
LR-EDIT-DETAIL-DENOISE: AI Denoise follows Auto Sync, starts at import, one batch row (upstream storytold#2932)
emmertex added a commit to clydecbrown/lightcraft that referenced this pull request Oct 26, 2026
…ow and recipe formats everywhere

The model set-up flow went with the built-in denoiser (fork storytold#599), but its messages stayed in
some catalogs, and fork storytold#602 / storytold#594 added format messages to some catalogs only:
every_catalog_carries_every_message failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
emmertex added a commit to clydecbrown/lightcraft that referenced this pull request Oct 26, 2026
i18n: every catalog carries every message again (after fork storytold#602)
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.

3 participants