Skip to content

fix(wsi): correct point annotation placement on SM/WSI viewports at n…#2769

Merged
sedghi merged 3 commits into
cornerstonejs:mainfrom
katyayni1999000:fix/wsi-annotation-device-pixel-ratio
Jul 8, 2026
Merged

fix(wsi): correct point annotation placement on SM/WSI viewports at n…#2769
sedghi merged 3 commits into
cornerstonejs:mainfrom
katyayni1999000:fix/wsi-annotation-device-pixel-ratio

Conversation

@katyayni1999000

@katyayni1999000 katyayni1999000 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Context

Fixes WSIViewport annotation placement on HiDPI (Retina/high-DPI) displays.

WSIViewport sizes its canvas in CSS pixels and its internal transform (getTransform()) already operates in CSS-pixel space. The canvasToIndex method was pre-multiplying canvasPos by devicePixelRatio before transforming, and indexToCanvas was post-dividing by devicePixelRatio after transforming. On displays where devicePixelRatio > 1, this caused annotations to be placed at incorrect positions because the DPR scaling was applied twice.

Changes & Results

  • canvasToIndex: Removed canvasPos.map((it) => it * devicePixelRatio) — pass canvasPos directly to transformPoint.
  • indexToCanvas: Removed .map((it) => it / devicePixelRatio) — return transformPoint result directly.

Before: Annotations on WSI images are offset/misaligned on HiDPI screens (devicePixelRatio > 1).
After: Annotations render at the correct positions on all displays. No behavior change on standard displays where devicePixelRatio === 1.

Testing

  1. Open a WSI image in a viewer using WSIViewport.
  2. On a HiDPI/Retina display (or set browser zoom to simulate devicePixelRatio > 1), place an annotation (e.g. length or area tool).
  3. Verify the annotation anchor points land exactly where you clicked, rather than being scaled away from the origin.

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • "OS: Windows 11"
  • "Node version: 24.14.0"
  • "Browser: Chrome (HiDPI display, devicePixelRatio = 2)"

Summary by CodeRabbit

  • Bug Fixes
    • Improved coordinate conversion between canvas space and image index space for viewport interactions.
    • Fixed point/position mapping so interactions translate consistently on high-density displays.

…on-default devicePixelRatioPatch @cornerstonejs/core WSIViewport to stop scaling canvas coordinates bydevicePixelRatio in canvasToIndex/indexToCanvas. WSIViewport sizes its canvasin CSS pixels and its transform works in CSS-pixel space, so the extra DPR
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a7c64b13-7072-4f10-9ec8-3add90ed027b

📥 Commits

Reviewing files that changed from the base of the PR and between 3cc9ce9 and 3897eb1.

📒 Files selected for processing (1)
  • packages/core/src/RenderingEngine/WSIViewport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/RenderingEngine/WSIViewport.ts

📝 Walkthrough

Walkthrough

WSIViewport no longer applies devicePixelRatio scaling in either direction when converting between canvas and index coordinates. Raw canvas positions now flow directly through the inverse transform, and transformed index positions are returned directly.

Changes

WSIViewport Coordinate Conversion

Layer / File(s) Summary
Remove devicePixelRatio from canvas↔index transforms
packages/core/src/RenderingEngine/WSIViewport.ts
canvasToIndex drops the devicePixelRatio pre-scaling on input, and indexToCanvas drops the devicePixelRatio post-division on output.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required semantic-release style and matches the PR’s main fix for WSIViewport annotation placement.
Description check ✅ Passed The description includes context, changes, testing steps, and a completed checklist, so it mostly satisfies the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sedghi
sedghi merged commit a91cb5d into cornerstonejs:main Jul 8, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants