Skip to content

feat(process): expose the demosaic algorithm - #1032

Merged
marcinz606 merged 1 commit into
mainfrom
feat/demosaic
Aug 31, 2026
Merged

feat(process): expose the demosaic algorithm#1032
marcinz606 merged 1 commit into
mainfrom
feat/demosaic

Conversation

@marcinz606

Copy link
Copy Markdown
Owner

Closes #1030.

The CFA interpolation was decided by hardcoded branches. It is now a user choice, made separately for the preview and for export, in a new Demosaic panel under Calibration.

What it does

  • DemosaicMode (Auto, Linear, VNG, PPG, AHD, DCB, DHT, AAHD) and two sticky ProcessConfig fields, demosaic_preview and demosaic_export, both defaulting to Auto.
  • Auto is exactly the old behaviour on each path: a half-size LINEAR decode on screen, AHD for export. An existing edit renders identically, verified byte-identical against AHD on a Bayer NEF.
  • The dropdown is built from rawpy's isSupported at runtime, so a libraw built without the GPL demosaic packs never offers a value it cannot run. An unrecognised persisted value resolves back to Auto.
  • A source with no CFA (scanner TIFF, Pakon, linear DNG) still decodes LINEAR whatever is selected. NonStandardFileWrapper.postprocess ignores demosaic_algorithm outright.

Notes

  • An explicit preview algorithm drops half_size. Libraw bins 2x2 quads and never reaches the interpolator, so the fast path would silently ignore the choice. The panel hint says Auto and Linear are the fastest for the preview.
  • get_best_demosaic_algorithm(raw, mode) stays the single resolver; every decode site routes through it rather than re-deriving the rule.
  • Cache keys the change had to reach: PreviewCacheKey, source_token (the preview field only, or an export-only change would re-decode the open frame), ImageProcessor._source_cache_key, and the export detect_key.
  • Threaded through Linear Output too, including its triplet, stitch and bracket branches.

Left alone deliberately: thumbnails, autodetect and capture metering. They feed classifiers and contact-sheet tiles, and wiring thumbnails in would force a cache-version bump for no visible gain.

Verification

make lint, make type and 5365 tests green. On a real Bayer NEF: export Auto is byte-identical to AHD, DHT and VNG differ; the preview differs under VNG at the same output size.

Docs: new USER_GUIDE §4.2 with its panel:demosaic marker (4.2 to 4.4 renumbered, references updated) and the PIPELINE.md decode bullet.

The CFA interpolation was decided by hardcoded branches: AHD for a mosaiced
sensor, LINEAR for anything already de-mosaiced, and a separate fast rule in
the preview path. Both choices are now the user's, picked separately for the
preview and for export, in a new Demosaic panel under Calibration.

Auto keeps the old behaviour on both paths and is the default, so an existing
edit renders identically (verified byte-identical against AHD on a Bayer NEF).

The dropdown is built from rawpy's isSupported at runtime, so a libraw without
the GPL demosaic packs never offers a value it cannot run, and an unrecognised
persisted value resolves back to Auto. A source with no CFA still decodes
LINEAR whatever is selected.

An explicit preview algorithm drops half_size: libraw bins 2x2 quads and never
reaches the interpolator, so the fast path would ignore the choice.

Cache keys the change had to reach: PreviewCacheKey, source_token (the preview
field only, or an export-only change would re-decode the open frame),
_source_cache_key and the export detect_key.
@github-actions

Copy link
Copy Markdown

Preview load metrics (github-linux-x64)

format cold load throughput
CR2 0.584 s 38.38 MPx/s
NEF 0.511 s 48.15 MPx/s
ARW 0.185 s 109.32 MPx/s
RAF 1.599 s 10.17 MPx/s
DNG 0.536 s 44.70 MPx/s

fixtures: rawsamples.ch · sha: f16f107 · full JSON

@marcinz606
marcinz606 merged commit 139c293 into main Aug 31, 2026
2 checks passed
@marcinz606
marcinz606 deleted the feat/demosaic branch August 31, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant