perf(screenshot): Phase D — native server-side region crop - #3
Merged
Conversation
…to JS) The in-tool region flow captured the frozen full-res screen, shipped the whole PNG to JS (10-30MB on a 5K display), base64'd it, decoded it, and cropped in a canvas — even for a tiny region. Now: capture_hold captures the frozen full frame once (while the main window is hidden) and keeps it in Rust; after selection, crop_held crops server-side with HiDPI scaling and returns only the small region as raw PNG bytes. release_held frees it on cancel. Memory is bounded to one held frame (cleared on next capture). physical_crop_rect (logical→physical, clamped) is a pure fn with 6 unit tests. Screenshot.tsx loads the crop via createImageBitmap — no base64, no full-res decode. Region button is Tauri-only so there's no browser path to preserve. cargo test: 19 passed; JS: 385 passed. Manual test: crop is pixel-accurate on HiDPI and correct on a secondary display. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dqouzFP8vy9jaKhTDFj5H
This was referenced Jul 21, 2026
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.
Summary
Completes the screenshot optimization plan. The in-tool region flow no longer ships a full-res PNG to JS to crop in canvas — it holds the frozen full frame in Rust and crops server-side, so only the small region crosses IPC.
Before → after
<img>decode → canvas crop.capture_holdkeeps the frozen frame in Rust; after selectioncrop_heldcrops with HiDPI scaling and returns just the region as PNG;release_heldfrees it on cancel. Memory bounded to one held frame.Details
physical_crop_rect(logical→physical, clamped) is a pure fn with 6 unit tests (identity, 2× retina, edge-clamp, negative-origin, zero-dims, zero-logical fallback).Screenshot.tsxloads the crop viacreateImageBitmap— no base64, no full-res decode.Testing
cargo test→ 19 passed (incl. the 6 new crop tests); JS → 385 passed.Note
capture_hold/crop_heldare macOS-only, consistent with the rest of desktop capture (Windows/Linux capture is still unimplemented).🤖 Generated with Claude Code