Heuristic:A9T9 RPA DPI Scaling Coordinate Normalization
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Computer_Vision, Desktop_Automation |
| Last Updated | 2026-10-22 17:48 GMT |
Overview
DPI scaling and coordinate normalization across screenshot capture, image search, and click dispatch using per-display device pixel ratio and window-anchored DIP-to-physical conversion.
Description
Ui.Vision must translate coordinates across three spaces: CSS DIP (device-independent pixels) used by the browser, physical screen pixels used by the OS, and the capture bitmap's own pixel dimensions. A single scaling factor cannot bridge them when displays run different scaling (e.g., 125% primary + 175% secondary). The solution is a window anchor: chrome.windows reports the focused browser window's top-left in DIP, the XModule2 host's GetWindowRect reports the same corner in physical pixels, and everything inside one window sits on one display where devicePixelRatio is the entire scale. This yields: phys = physWin + (dip − dipWin) × dpr and the inverse dip = dipWin + (phys − physWin) ÷ dpr. On uniform-scale setups this reduces exactly to the old single-factor math.
Usage
Use this heuristic whenever desktop-scope commands (XClick, XType, desktop image search, desktop OCR) are running on Windows with multi-display setups at different scaling percentages. Also relevant when AI vision (Anthropic Computer Use) returns coordinates that must be back-converted from scaled image space to original screen coordinates.
The Insight (Rule of Thumb)
- Action: Use a window anchor (DIP origin + physical origin + DPR) for coordinate conversion, not a single global scaling factor.
- Value:
phys = physWin + (dip − dipWin) × dpr;dip = dipWin + (phys − physWin) ÷ dpr - Trade-off: Requires an extra
chrome.windows.get+ hostGetWindowRectround-trip per anchor refresh (cached 300ms). - Compatibility: Anchor is null on macOS (points everywhere, no scaling needed) and when no browser window is foreground; callers fall back to old one-factor math then.
- AI Vision: When sending scaled images to Claude, back-convert coordinates with
coord / scaleFactor / window.devicePixelRatio.
Reasoning
Chrome re-packs DIP origins when displays have different scaling. A 2560px-wide 125% primary spans 2048 DIP, so a 175% display to its right starts at DIP 2048 but physical 2560. One-factor math (phys = dip × factor) overshot clicks on the second display by 1024px (measured live 2026-08-16). The window anchor ties the conversion to the actual display the content sits on, where devicePixelRatio is constant. This is a strict generalization — on uniform-scale setups, physWin = dipWin × factor and both formulas reduce to the old single-factor result.
The capture display hint extends this: the host's foreground-based display selection is wrong when a non-browser app is focused mid-run. The extension knows the play window's physical corner and passes the matching display's bounds as displayHint on every capture/search RPC, pinning capture to the correct display.