Repository navigation
Issue #1377: exports bin a raw two by two when half the sensor is enough - #1561
Merged
Merged
Conversation
Step 2 of the plan on #1377. An export of a raw not yet decoded reads it binned by the smallest block the sensor allows that leaves 1.15x the source pixels the output needs (EXPORT_BIN_MARGIN), kept at that size so the pipeline takes it to the output in one Lanczos step (LoadOptions::keep_binned). Before, an output up to 2560 px took the preview level's block and a box fit to 2560 px, and a larger one demosaiced the whole sensor. Measured (4-core container, no GPU, 3 synthetic 45 MP DNGs, interleaved): 3000 px 3.61 -> 1.95 s wall, 12.0 -> 6.2 CPU-s, 1.86 -> 1.06 GB peak per photo; 2048 px unchanged in time, sharper. Visual check: the new bin_sharpness example, SSIM vs a full AHD demosaic >= 0.998 on demo scenes 1024-3840 px; zone plate 0.96-0.998 (old box path 0.64-0.80). Manual: output/export-size-sharpen.mdx. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011VFDrfcYF2xSBoosZAu8dw
This was referenced Nov 27, 2026
…-1en860-binning # Conflicts: # crates/engine/src/media.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Andrew · project thread
Part of #1377 (step 2 of the plan). Stacked on #1554 (the bench this measures with). This PR's own commit is
41b24651.Problem
An export chose its raw source by size band, not by the size asked for. Up to 2560 px it took the preview level's block: binned by 2, then box-fitted to 2560, then Lanczos to the output. That's two resamples, and the box aliases fine detail. One pixel more, and it demosaiced the whole sensor, which is the 72 % CPU cliff blwfish measured at 2561 px. The step as planned ("demosaic at reduced size for small exports") turned out to be mostly in place already for 2048 px. The gaps were the soft box step and everything from 2561 px to half the sensor.
Change
Session::bin_for_export(media.rs): an export of a raw that isn't decoded yet asks for a sourceEXPORT_BIN_MARGIN(1.15) times the pixels the output needs (crop included), withLoadOptions::keep_binned. That happens only when half the sensor has them. Otherwise nothing changes: large exports, tight crops, small sensors, and a source already decoded (the loupe's) are left alone.files::export_bin_factor: withkeep_binned, the loader bins by the smallest block the sensor allows that leaves that many pixels. It keeps the binned size, with no box fit, so the pipeline goes to the output in one Lanczos step. It's the smallest block, not the largest, because a box over a larger block aliases (see the zone plate below).DecodedSource::serveskeeps an export's binned source from standing in for a view's level.bin_sharpnessexample: the visual check (SSIM and detail kept against a full AHD demosaic, crops written totarget/bench/bin-sharpness/).Not in this PR: anything on the GPU (step 3), lanes (step 4).
How it was checked
cargo xtask ci --quick: fmt, brand, docs, notes, i18n, windows and clippy pass. Twotests_preview_preptiming tests failed in the full run on this 4-core container (the background build made 1 job where the test expects 0 while the window renders). Both pass when rerun alone (28/28 in the module). They don't touch the export path. parity, layers, assets and wasm pass when run separately.tests_export_binning.rs):export_bin_factornever leaves fewer pixels than asked.Visual check (
bin_sharpness, an RGGB 8256 × 5504 raw of each scene; SSIM against a full AHD demosaic, Lanczos to the output):Speed (
export45_bench, 4-core container, no GPU, 3 synthetic 45 MP DNGs, two interleaved before/after runs, per photo):At 2048 px the colour finish gets cheaper (0.21 → 0.09 s) and the render dearer (0.72 → 0.91 s, larger source). I tried fitting the binned picture to the margin in the loader with Lanczos (one more step), and it measured no faster, so I didn't keep it. Real Z9 numbers need blwfish's set (
cargo xtask bench --only export45 --export-dir DIRonce #1554 is in).Merging
unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: none.Manual: output/export-size-sharpen.mdx. Release notes:
docs/whats-new/anddocs/changelog/unreleased/entries.Generated by Claude Code