Repository navigation
Detail: snap the 100% view to whole screen pixels - #1831
Merged
Merged
Conversation
At 100% the photo's corner could sit half a physical pixel off, for example in a 1279.5 pt canvas on a 2x display. The GPU then resampled the photo with its bilinear filter and blurred it. On a 5152x7728 JPEG the 100% view kept 68% of the fine detail. fit_rect now rounds the corner to a whole physical pixel when the photo is 1:1 with the screen. Other zooms resample anyway, and a pinch must not jump, so they stay as they were. With the fix the same view matches the original (71.4 dB PSNR, 100% of the detail). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
|
Thank you @john01px2022! This landed on main in integration batch 36 (#1843). If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there. |
Contributor
Author
|
I also checked the new test against main by removing the snap and re-running it. It fails there with "-1936.25 pt is not a whole pixel at 1x", and passes with the snap in place. |
aiongg
pushed a commit
to aiongg/lightcraft
that referenced
this pull request
Oct 21, 2026
…Lanczos decode) At Fit the loupe was softer than a good downscale of the same file. Four resamples stacked up between the source and the screen: - the render edge is rounded up to a 64 px step, so the texture was drawn up to ~6 % smaller than its size and the GPU shrank it with 2-tap bilinear sampling; - the fitted texture sat on a fractional pixel position, so even at the right size every screen pixel was averaged with its neighbour (storytold#1831 fixed the same for 100 %); - the render box truncated its short side (2560 x 1706 for a 2560 x 1707 source), a slightly anisotropic resample that blurred one axis only; - the codec's decode-time shrink at 2:1 and more, and SourceRef::Fit, used a box filter, which halves the contrast of detail near the output's limit. RenderJob::display_fit shrinks a full-quality render that is larger than its drawn size to exactly that size with Lanczos-3 on the worker (after the caches have the full render; drafts untouched; part of the key). The Detail view sets it for the After and Before renders at rest, and snap_fit_rect draws a texture that is its drawn size on whole physical pixels. The render boxes round their short side, and the 2:1-and-more shrinks use Lanczos-3. Refs storytold#1472, storytold#1042. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1683. A full-size JPEG looked soft in the editor at 100%, even though import, decode, render and export all keep its detail.
Cause
At 100% the photo should map one texel to one screen pixel.
fit_rect(inpanels/detail.rs) centres the photo on the canvas and does not snap its corner to the physical pixel grid. When the canvas has an odd width, the corner lands between two pixels. In the file from the issue, on a 2x display, the canvas is 1279.5 pt wide, so the photo's left edge sat at x = -648.25 pt. That is -1296.5 physical pixels, half a pixel off. The GPU then drew every texel with its bilinear filter, which averages neighbouring pixels. That blurred the whole view.The pipeline was not at fault. I checked each stage with the file from the issue (
2268623-qr6i.jpg, 5152x7728, progressive, ICC profile, 4:2:0):lightcraft-cli render, no edits, full sizeui.inspectreportsregion.full5152x7728 and the full source held in memory, so the sharp render was already being usedWhat changed
fit_rectnow rounds the photo's top-left corner to a whole physical pixel when the photo is 1:1 with the screen. The rule is aZoom::Percentzoom and(w * ppp - img_px[0]).abs() < 0.5. The size is unchanged. Only the position moves, by at most half a physical pixel.trackpad_pinch_anchors_fractional_zoom_and_scroll_panspinches by 0.1% and requires the point under the cursor to stay put within 1e-5. My first version snapped at every percentage and failed that test, so I narrowed the rule to 1:1.fit_rectis shared, so the Compare view gets the same fix. One function, one place to read the rule.panels/detail.rschanges (+26, -1).Before and after
Crops of the plush eye from the original post. These are the reporter's screenshots, not output from this branch.
Measured against the original file, headless at 2x:
The last row is how I found the cause. The same render, shifted by half a pixel, goes from 71.4 dB to 39.5 dB.
How I measured it:
lightcraft-cli snapshot --size 1600x1000 --scale 2with a script that runsview.detail,view.navigate {zoom: {percent: 100}, pan: [0.5, 0.5]}andui.settle, thenui.screenshot.The offset in this file was in x only (y already sat on a whole pixel), so the detail figure uses the x direction.
Tests
panels::detail::preview_geometry_tests::percent_zoom_lands_on_whole_physical_pixels. It uses the 1279.5 pt canvas from the issue and asserts the corner is a whole physical pixel and the size is still the photo's own pixels, at ppp 1, 1.25, 2 and 3, with three pans each. I checked it against main by removing the snap and re-running: it fails with "-1936.25 pt is not a whole pixel at 1x".trackpad_pinch_anchors_fractional_zoom_and_scroll_pansand the rest oflightcraft-ui-eguipass.A note for anyone running the crate's tests alone:
cargo test -p lightcraft-ui-eguifails 6tests_model_setuptests with "this build cannot run denoise models". Thedenoisefeature reacheslightcraft-enginethrough thelightcraftapp crate's defaults, so a single-crate run has it off.cargo test --workspaceunifies the feature and they pass. This happens on main too.CI
cargo xtask ciis green on this branch, all eight steps:-D warnings)cargo test --workspace)wasm32-unknown-unknownThe
wasmstep neededrustup target add wasm32-unknown-unknownon my machine first. Worth knowing for anyone whose firstcargo xtask cifails there with "thewasm32-unknown-unknowntarget may not be installed".No workflow runs on this PR:
freebsd.ymlneeds aCargo.tomlor lockfile change,packaging-lint.ymlneeds.github/,packaging/or app-icon changes, andrelease.ymlis release-branch only. This change touches onlycrates/ui-egui/src/panels/detail.rs.Not done
docs/parity-checklist.md. This is a bug fix, not a new feature, and the LR-DEV-LOUPE behaviour it belongs to is already listed.🤖 Generated with Claude Code