Repository navigation
feat: add the element-decode primitives and character-set decoders - #535
Merged
Merged
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 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 lands the element-decode primitives and the character-set decoders. It's the half of the decode core that doesn't depend on the vendored tokenizer, and it's what the streaming reader (arriving in a later PR) builds on.
A quick gloss for anyone who hasn't been following this branch. Every DICOM element carries a VR — a value representation, the two-letter code (CS, LO, SQ, ...) that says how the element's bytes should be interpreted. In "implicit VR" transfer syntaxes the file doesn't store that code at all. The reader has to resolve it from the data dictionary. Separately, a dataset can declare its text encoding through SpecificCharacterSet (0008,0005). That's what the character-set modules here handle.
What's actually in the PR:
src/core/decodeCore.js— pure decode functions extracted from the lazy reader. They take read-onlywindowandpolicyinputs instead of the lazy reader's mutable context. The centerpiece isresolveVrInstance, which is now the single canonical implicit-VR contract for every read path. It follows the classic eager rules: a dictionary miss with a defined length resolves to UN and is never promoted to SQ by peeking at the data; pixel data falls back to OW; private creators fall back to LO. Around it sitshapeReadValues(string multiplicity splitting and the raw-value quirks, replicated verbatim fromDicomMessage._readTag),retainRaw,buildElementStream,decodeElementValues,decodeWithEagerReadTag(a narrow fallback that hands rare shapes to the exact eager code), andclassifyElement, which routes each element to one of four decode strategies: sequence, encapsulated pixel data, eager fallback, or plain value.src/core/normalizeSyntax.js— transfer-syntax normalization as a standalone module.src/charset/latin1.jsandsrc/charset/iso2022.js— the Latin-1 and ISO 2022 decoders, plusresolveCharsetDecoder, which turns a SpecificCharacterSet value into a decoder. It keeps the eager reader's exact error policy.Here's the charset resolver in use:
One thing did NOT come along, and that's deliberate. The lazy reader's
seedReadContext, its pako inflater shim, and itsparseDicomimport existed only to drive the vendored tokenizer. The release plan removes that tokenizer from 1.0, so this module arrives already free of the dependency.For testing:
test/core/decodeCore.test.jsexercises the pure primitives with synthetic elements, andtest/charset/resolveCharsetDecoder.test.jsdrives the charset resolver directly. Corpus-level coverage of these same functions arrives with the streaming reader's suite — the streaming reader is what produces elements once the tokenizer is gone.🤖 Generated with Claude Code