Repository navigation
fix: decode text in sequence items with the right SpecificCharacterSet (port of #609) - #659
Merged
Merged
Conversation
…t (port of #609) PS3.5 7.5.3: items use the character set of the data set that contains them, and a character set declared in an item applies only to that item and the items nested in it. - ReadBufferStream takes a `decoder` option; BufferStream.more() and ParsedUnknownValue.read() pass the decoder of the parent stream, so the sync reader and the UN re-read decode items with the data set charset. - AsyncDicomReader.readSequence restores the decoder after each item. - The event-stream reader already scopes the charset per item; it had only the UN re-read bug, which the ParsedUnknownValue change fixes. - Tests run the sync, async and event-stream readers on Explicit and Implicit VR, with undefined and defined lengths. - bundle-size ceilings 1.084 and 1.066 for the added source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Nov 25, 2026
…662 The combined build measures x1.0841 (dcmjs.js) and x1.0665 (dcmjs.es.js). The ceiling comment is now one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Nov 25, 2026
…oups (port of #603) (#662) * fix(normalizers): normalize multiframe datasets missing functional groups (port of #603) normalizeMultiframe dereferenced a missing SharedFunctionalGroupsSequence and threw a TypeError. When the groups are missing, fill the shared PlaneOrientationSequence / PixelMeasuresSequence and the per-frame PlanePositionSequence from the top-level attributes, through the static ImageNormalizer.sharedImagePlaneGroups and planePositionGroup that convertToMultiframe now also uses. Lower NumberOfFrames to the whole frames PixelData holds (never raise it), with a warning. A per-frame sequence that is already an array is no longer wrapped again, so a one-frame item is an object and not [[item]]. log.error becomes log.warn. Raise the bundle-size ceilings to 1.084 and 1.067 for the ~1.7 KB added. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(normalizers): keep the declared NumberOfFrames when functional groups are missing The normalizer no longer lowers NumberOfFrames to the frames that PixelData appears to hold. Encapsulated PixelData can have more or fewer fragments than frames, so a byte count says nothing about the frame count. framesInPixelData is removed. A dataset with no PerFrameFunctionalGroupsSequence now gets one per-frame item for each declared frame, each with PlanePositionSequence from the top-level ImagePositionPatient and its own FrameContentSequence. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(bundle-size): set the ceilings from a build with #660, #659 and #662 The combined build measures x1.0841 (dcmjs.js) and x1.0665 (dcmjs.es.js). The ceiling comment is now one line. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
wayfarer3130
marked this pull request as ready for review
November 25, 2026 14:08
…-609-item-charset test/bundle-size.test.js: kept the 1.0-beta ceilings. The measured ratios after the merge are dcmjs.js 1.08412 and dcmjs.es.js 1.06656, which round up to the 1.0-beta ceilings 1.085 and 1.067. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.19 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
This PR is the 1.0 port of #609 from 0.x (which contains #520).
Summary
PS3.5 7.5.3 says that a Specific Character Set applies to the data set and to the items nested in it. A Specific Character Set in a sequence item applies only to that item and to the items nested in it.
origin/1.0-betahad the two bugs that #609 fixed in 0.x:DicomMessage.readFile). WithSpecificCharacterSet=ISO_IR 192, text in sequence items came back as windows-1252."lesione – café 肝"came back as"lesione – café è‚".AsyncDicomReader). The reader kept the character set of an item after the item ended. The next items and the elements after the sequence decoded with the character set of the item.Cause
ReadBufferStreamstarts withnew TextDecoder("latin1").BufferStream.more()makes a new stream for each item, and that new stream started again with the default decoder.ParsedUnknownValue.read()reads aUNelement again from a new stream, and had the same problem.AsyncDicomReaderreads items on the stream of the parent. When the reader reads (0008,0005) in an item, it changes the decoder of that stream. Nothing set the decoder back when the item ended.fromPart10Streamgives the decoder to each item as a value (parseSqItems,parseItemElements). Thus the event-stream reader already used the correct character set for items, and an item charset did not go out of the item. The event-stream reader had only theUNbug, because it usesParsedUnknownValue.read()for aUNelement with a known dictionary VR.Changes
packages/core/src/BufferStream.js:ReadBufferStreamaccepts adecoderoption. The default islatin1, as before.BufferStream.more()gives its decoder to the new stream. Items at all depths get the decoder.packages/core/src/ValueRepresentation.js:ParsedUnknownValue.read()gives the decoder of the stream to the new stream. This change fixes the sync reader and the event-stream reader.packages/legacy/src/AsyncDicomReader.js:readSequencesaves the decoder of the stream before each item, and sets the decoder again after the item. A nested item still gets the character set of its parent item.test/data-encoding.test.js: the tests of fix: decode text in sequence items with the right SpecificCharacterSet (sync and async readers) #609, adapted to 1.x. Each test runs on three readers:DicomMessage.readFile,AsyncDicomReader, andfromPart10withNaturalizedListener. The depth test and the worklist test read four encodings: Explicit VR and Implicit VR Little Endian, each with undefined lengths and with defined lengths. TheUNtest reads Explicit VR with undefined lengths.UN-encodedLO.ISO_IR 192whose firstScheduledProcedureStepSequenceitem declaresISO_IR 144. The test checks the text before the sequence, in the first item, in its nested item, in the second item, and after the sequence.test/async-sequence-charset.test.js: the async test of fix: decode text in sequence items with the right SpecificCharacterSet (sync and async readers) #609, without changes. The test reads the worklist data set from one buffer and from 7-byte pieces throughfromAsyncStream.test/bundle-size.test.js: the ceilings change from 1.083 to 1.084 (dcmjs.js) and from 1.065 to 1.066 (dcmjs.es.js). The fix adds about 0.5 KB of documented source. The ratios were 1.0831 and 1.0656, so the old ceilings failed.Verified
DicomMessage.readFile: the depth test, theUNtest and the worklist test failed in all encodings (Received: "lesione – café è‚").AsyncDicomReader: the worklist test failed in all four encodings, and the test oftest/async-sequence-charset.test.jsfailed in all four cases.fromPart10event stream: only theUNtest failed. The depth test and the worklist test passed.npx jest --runInBandpassed on these files:test/data-encoding.test.js,test/async-sequence-charset.test.js,test/readBufferStream.test.js,test/SequenceOfItems.test.js(64 tests). It also passed ontest/charset,test/sync-async-parser-equivalency.test.js,test/defined-length-sequence.test.js,test/eventStream/fromPart10Stream.test.js,test/eventStream/NaturalizedListener.test.jsandtest/writeBufferStream.test.js(144 passed, 1 skipped).test/bundle-size.test.jspassed with the new ceilings (7 tests).pnpm run build, eslint andprettier --checkpassed on the changed files.Release note
A file that declares UTF-8 but stores windows-1252 bytes in its sequence items now shows replacement characters (U+FFFD) in those items. Before this change, the sync reader decoded these bytes correctly by accident.
Not ported, and why
fromPart10Stream. The event-stream reader already gives the decoder to each item, and the new tests show the correct result for items. TheParsedUnknownValuechange fixes itsUNbug.Fixeslink. Sequence-nested string content decoded with Latin-1 instead of SpecificCharacterSet (UTF-8 mojibake) #503 and Nested sequence items are decoded as cp1252, ignoring SpecificCharacterSet (ISO_IR 192) #508 are closed.🤖 Generated with Claude Code