Skip to content

fix: resolve the xs meta-VR via PixelRepresentation and quiet the unknown-VR fallback - #537

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/xs-and-vr-log-fixes
Sep 29, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/xs-and-vr-log-fixes

Conversation

@awatson1978

@awatson1978 awatson1978 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Two fixes to the eager reader, both taken from the review map's regression list: correct signed-vs-unsigned resolution for the "xs" meta-VR, and much quieter logging in the unknown-VR fallback.

First, some vocabulary. A VR (value representation) is the two-letter code that says how an element's bytes are interpreted. A few DICOM dictionary entries don't pin down a single VR — the entry "xs" means "US or SS", i.e. unsigned or signed 16-bit. Per the standard (PS3.5), the right choice depends on PixelRepresentation (0028,0103), a flag that says whether the image's pixel values are signed (1) or unsigned (0).

The first fix: dcmjs used to give up on "xs" and always read those elements as unsigned. A stored value of -2000 came back as 63536. Now DicomMessage._read remembers the PixelRepresentation value as it walks the dataset and threads it through to _readTag, which resolves "xs" to SS when PixelRepresentation is 1 and US otherwise. This works because (0028,0103) precedes every "xs"-typed tag in tag order, so the flag is always parsed before it's needed. The streaming reader's equivalence gate is what exposed this — it compares the new reader's output element-for-element against the eager reader's, so the eager reader had to be right first. Here's the before/after, straight from the regression test:

// A file with PixelRepresentation = 1 (signed) and
// SmallestImagePixelValue = -2, whose dictionary VR is "xs".
const { dict } = DicomMessage.readFile(buffer);

// before: "xs" always resolved to US, so the signed value came back
// as its unsigned reinterpretation
dict["00280106"].vr;    // "US"
dict["00280106"].Value; // [65534]

// after: resolved via PixelRepresentation, per PS3.5
dict["00280106"].vr;    // "SS"
dict["00280106"].Value; // [-2]

The second fix is about log noise. ValueRepresentation.createByTypeString used to log an error for every element whose VR type wasn't in its instance table. But "xs" and "ox" ("OB or OW") are expected dictionary meta-VRs, not errors — that's the literal complaint in issue #368, where OHIF consoles filled with "Invalid vr type xs - using US" (and the log-spam half of issue #437 is the same thing for "ox"). Issue #457 adds the other case: files carrying many elements of a genuinely unregistered VR (OL/OV/SV) produced one log line per element. Now the xs/ox fallbacks log at debug level, and genuinely unknown types warn once per type instead of once per element.

The two issue suites the test bank had to leave out land here as the regression tests: test/issues/issue368-xs-ox-vr-resolution.test.js and test/issues/issue457-vr-instances.test.js, with their known-gap skips now green and unskipped. Both fixes look applicable to master as 0.52.x hotfixes.

🤖 Generated with Claude Code

@awatson1978
awatson1978 merged commit 548b1b6 into release/1.0-beta-core Sep 29, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

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

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