Skip to content

fix(legacy): keep untilTag and NumberOfFrames out of AsyncDicomReader sequence items (port of #657) - #666

Merged
wayfarer3130 merged 1 commit into
1.0-betafrom
fix/1.0-beta-port-657-async-sequence-state
Nov 25, 2026
Merged

wayfarer3130 merged 1 commit into
1.0-betafrom
fix/1.0-beta-port-657-async-sequence-state

Conversation

@wayfarer3130

@wayfarer3130 wayfarer3130 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Why

This PR ports #657 (commit d236313 on master) to 1.0-beta. The PR fixes #643 on 1.0-beta.

AsyncDicomReader (packages/legacy/src/AsyncDicomReader.js) applies the state of the top-level data set inside sequence items. An Icon Image Sequence (0088,0200) item has its own Pixel Data (PS3.3 C.7.6.1.1.6). The reader fails on such a file in two cases:

  • With untilTag: "7FE00010", the read stops at the Pixel Data of the icon. Then readSequence throws an Error with an empty message.
  • The reader uses the NumberOfFrames of the file to split the Pixel Data of the icon. With 2 frames, the reader gives two 2-byte frames for a 4-byte icon. With 3 frames, the reader throws Invalid frame length: 4 for 3 frames.

The sync reader (DicomMessage.readFile) reads these files correctly.

What changes

  • readSequence reads the items without untilTag and includeUntilTagValue. Thus untilTag stops the read at the top level only.
  • A sequenceDepth counter and the new getNumberOfFrames() method give 1 frame for Pixel Data inside a sequence item. readCompressed, readUncompressed and readUncompressedBitFrame use the method.
  • The error for a tag that is not an item and not a sequence delimitation item now names the tag.
  • docs/AsyncDicomReader-skill.md: untilTag applies to the top-level data set.

On 1.0-beta, readSequence already calls readTagHeader({ ...options, readSyntax }). The port replaces options with the item options in that call.

What stays

  • listener.information.rows, columns and bitsAllocated still come from the top level, as in fix: keep untilTag and NumberOfFrames out of AsyncDicomReader sequence items #657. The reader uses these values only for multi-frame or 1-bit Pixel Data. Inside an item, the reader does not use the 1-bit frame code, so these top-level values do not apply to an icon. The fix also corrects a 1-bit multi-frame image that has an 8-bit icon.
  • The includeUntilTagValue: true behaviour at the top level does not change. The review of fix: keep untilTag and NumberOfFrames out of AsyncDicomReader sequence items #657 found an older bug there. This PR does not fix that bug.
  • The event-stream reader (fromPart10, fromPart10Stream) is correct on the same file. I checked 2 and 3 frames, with one buffer and with 37-byte chunks. The reader gives the 4 icon bytes as one value. The event-stream reader has no untilTag option, and it does not split frames by NumberOfFrames.

Tests

The new test/async-sequence-item-state.test.js builds the file of #643 with createSampleDicom. The test checks two things:

  • untilTag: "7FE00010" reads the icon whole and stops before the Pixel Data of the data set. The sync reader gives the same icon.
  • The icon is one frame when NumberOfFrames is 1, 2 or 3. The Pixel Data of the data set still has 1, 2 or 3 frames.

Both tests fail on origin/1.0-beta: the first test gets the empty Error, and the second test gets more than one icon frame. Both tests pass with the change.

  • npx jest test/async-sequence-item-state.test.js: 2 passed.
  • npx jest: 123 suites passed, 2 skipped; 1426 tests passed, 11 skipped. Only test/bundle-size.test.js failed before the ceiling change below.
  • npx eslint and npx prettier --check on the changed source and test files: no errors. prettier --check also warns on docs/AsyncDicomReader-skill.md, but the warning is the same on 1.0-beta.

Bundle size

pnpm run build, then test/bundle-size.test.js:

Bundle Size (bytes) Ratio to 0.52 Old ceiling New ceiling
dcmjs.js 1509631 ×1.09044 ×1.09 ×1.091
dcmjs.es.js 1455302 ×1.07212 ×1.072 ×1.073

The new ceilings are the measured ratios, rounded up to 3 decimals. #663 also changes these lines. The second PR to merge must merge 1.0-beta into its branch, and then measure again.

Release note

AsyncDicomReader: untilTag applies to the top-level data set only. The reader no longer stops at a matching tag inside a sequence item. Pixel Data inside a sequence item is one frame. This is the behaviour of the sync reader and of 0.x after #657. I did not add a docs/MIGRATION.md note, because 0.x and 1.0 now behave the same.

Port of #657. Fixes #643 on 1.0-beta.

🤖 Generated with Claude Code

… sequence items (port of #657)

1.0 port of #657 (commit d236313), fixes #643.

AsyncDicomReader applied top-level state inside sequence items. With an
Icon Image Sequence (0088,0200), untilTag "7FE00010" stopped at the
icon's Pixel Data and readSequence threw an empty Error, and the
NumberOfFrames of the file split the icon's Pixel Data.

- readSequence reads the items without untilTag and includeUntilTagValue.
- A sequenceDepth counter and getNumberOfFrames() give 1 frame inside an
  item; readCompressed, readUncompressed and readUncompressedBitFrame use it.
- The error for an unexpected tag in a sequence names the tag.
- docs/AsyncDicomReader-skill.md: untilTag is for the top level.

Rows, Columns and BitsAllocated still come from the top level, as in #657.

test/async-sequence-item-state.test.js builds the file with
createSampleDicom; both tests fail on 1.0-beta and pass with the change.
The bundle-size ceilings rise to x1.091 and x1.073 (measured x1.09044,
x1.07212).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 25, 2026 19:13
@wayfarer3130
wayfarer3130 merged commit 0d0285d into 1.0-beta Nov 25, 2026
4 checks passed
@wayfarer3130
wayfarer3130 deleted the fix/1.0-beta-port-657-async-sequence-state branch November 25, 2026 19:13
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…-622-big-endian-swap

Brings in #666. Conflicts: the AsyncDicomReader constructor comments (keep both), and the bundle-size ceilings (measured after the build: x1.09355, x1.07519; ceilings 1.094, 1.076).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

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

The release is available on:

Your semantic-release bot 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 26, 2026
…#667)

Remove the normalizers from the untouched list, and add the three
visible changes. Name #666 in the bundle-size comment.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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