Skip to content

fix(orientation): allocate matrix transform output with the input type (port of #602) - #661

Merged
wayfarer3130 merged 1 commit into
1.0-betafrom
fix/1.0-beta-port-602-typed-matrix
Nov 25, 2026
Merged

wayfarer3130 merged 1 commit into
1.0-betafrom
fix/1.0-beta-port-602-typed-matrix

Conversation

@wayfarer3130

Copy link
Copy Markdown
Contributor

This PR is the 1.0 port of #602 from 0.x.

Summary

The 2D matrix transforms of src/utilities/orientation/ now keep the type of the input data. Before this fix, a 16-bit labelmap lost its high byte: [300, 513] became [44, 1] (cornerstone3D#2961).

Cause

flipMatrix2D.h, flipMatrix2D.v and rotateMatrix902D always allocated the output with new Uint8Array(rows * cols). The functions then wrote each input value into that Uint8Array, and JavaScript kept only the low 8 bits of each value.

Changes

  • src/utilities/orientation/flipMatrix2D.js: h and v allocate the output with new matrix.data.constructor(rows * cols).
  • src/utilities/orientation/rotateMatrix902D.js: the function allocates the output with new matrix.data.constructor(rows * cols).
  • test/orientationMatrix2D.test.js (new): 4 tests, the same tests as fix(orientation): allocate matrix transform output with the input typed array type #602. Three tests check that h, v and rotateMatrix902D keep Uint16Array data and values. One control test checks that Uint8Array input still gives a Uint8Array result.

Callers

  • The library exports the functions as utilities.orientation.flipMatrix2D and utilities.orientation.rotateMatrix902D. An external caller, for example Cornerstone3D, can give 16-bit data. The fix is for that caller.
  • The in-repo callers are alignPixelDataWithSourceData in src/adapters/Cornerstone/Segmentation_3X.js and src/adapters/Cornerstone/Segmentation_4X.js. Each in-repo caller gives an ndarray on a Uint8Array view of the SEG pixel data. Thus the in-repo callers get a Uint8Array result, as before. No in-repo caller gives 16-bit data, and no behavior changes for these callers.
  • No caller depends on a Uint8Array result for non-Uint8Array input.

Verified

  • Before the fix, npx jest --runInBand test/orientationMatrix2D.test.js gave Tests: 3 failed, 1 passed, 4 total. Each failure was Expected: [Function Uint16Array], Received: [Function Uint8Array].
  • After the fix, npx jest --runInBand test/orientationMatrix2D.test.js test/adapters.test.js test/compat-052.test.js gave Test Suites: 3 passed, 3 total.
  • pnpm run build passed. After the build, test/bundle-size.test.js passed (7 of 7 tests). The PR did not change the bundle-size limits.
  • eslint and prettier --check passed on the changed files.
  • I ran only the tests above on my local system. CI runs the full test suite.

Not ported and why

🤖 Generated with Claude Code

…e (port of #602)

flipMatrix2D.h, flipMatrix2D.v and rotateMatrix902D always allocated a
Uint8Array, so 16-bit input lost its high byte ([300, 513] -> [44, 1]).
Allocate the output with the constructor of the input data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 25, 2026 14:06
@wayfarer3130
wayfarer3130 merged commit c4f3cfd into 1.0-beta Nov 25, 2026
4 checks passed
@wayfarer3130
wayfarer3130 deleted the fix/1.0-beta-port-602-typed-matrix branch November 25, 2026 14:06
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant