Skip to content

fix: support the OL, OV and SV value representations - #653

Merged
wayfarer3130 merged 8 commits into
1.0-betafrom
fix/1.0-beta-other-long-vr
Nov 25, 2026
Merged

wayfarer3130 merged 8 commits into
1.0-betafrom
fix/1.0-beta-other-long-vr

Conversation

@wayfarer3130

@wayfarer3130 wayfarer3130 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR is the 1.0 port of #632 (commit 5b215ca). It adds the OL (Other Long) VR. The maintainer also asked for the SV (Signed 64-bit Very Long) and OV (Other 64-bit Very Long) VRs in this PR. SV and OV are new code, not a port. Before this PR, the 1.0 reader and writer used UN for an OL element. A rewrite of Long Triangle Point Index List (0066,0041) then came back as UL numbers.

Changes

  • packages/core/src/ValueRepresentation.js: the new class OtherLongString, the same as in 0.x. The class registers in the Vrs table from feat(core): extensible registries for VRs, SOP classes and character sets; options-object streams #650.
  • packages/core/src/constants/vrs.js: the seed gives OL the flags length32 single byteStream. The exported singleVRs list does not change.
  • packages/core/src/ValueRepresentation.js: the new class OtherVeryLongString (OV, raw bytes, the same as OL). The new class Signed64BitVeryLong (SV) reads and writes a signed BigInt. SV and UV share one class and one write conversion. A Number or a numeric string converts with BigInt().
  • BufferStream and SplitDataView: new readBigInt64 / writeBigInt64 and getBigInt64 / setBigInt64, the same as the BigUint64 methods.
  • constants/vrs.js: OV gets the flags length32 single byteStream, the same as OL. SV gets binary length32, the same as UV. The exported singleVRs list does not change.
  • The JSDoc of UV, SV, and OV cites PS3.5 Section 6.2, Table 6.2-1.
  • test/issues/issue457-vr-instances.test.js and test/core/registries.test.js: each standard VR now has a class. These tests now use codes that are not DICOM VRs (ZZ, QQ, XX).
  • docs/specs/registries-implementation.md (REG-I-5) and two code comments no longer say that OL has no class.
  • docs/MIGRATION.md: one line. Code that matched vr === "UN" for an OL, OV, or SV tag must match the new VR.
  • beta-1-release-notes.md: one bullet.
  • packages/generator/src/eventStream/DicomWebJsonWriter.js: an SV or UV value in DICOM JSON is a Number when the value is a safe integer, and a decimal string otherwise. PS3.18 Table F.2.3-1 allows a Number or a String. Before, an SV element was UN with InlineBinary. The release notes and docs/MIGRATION.md record the change.
  • test/bundle-size.test.js: the ceilings increase to 1.086 (dcmjs.js) and 1.067 (dcmjs.es.js), measured after the merge of 1.0-beta (×1.0851 and ×1.0666).

Review

An independent review compared the port with #632. The class is the same as in 0.x. The other VR lists of 1.x (VALID_VRS, BULKDATA_VRS, BINARY_VRS) already had OL. The parser package and the legacy package need no change. The review found a conflict with #650, which merged into 1.0-beta before this PR. The branch is rebased onto 1.0-beta, and the resolution follows the merge plan of the review.

An independent review of the SV and OV commit found no blocker. SV and OV use the 32-bit length field, as PS3.5 requires. UV does not change. The review found one problem: DicomWebJsonWriter wrote an SV value as a BigInt, and JSON.stringify cannot serialize a BigInt. The fix uses the option that the review recommended: a Number for a safe integer, and a string otherwise, the same rule as for DS and IS.

Tests

The 0.x test test/other-long.test.js moves to test/issues/pr632-other-long.test.js.

  • On 1.0-beta without the fix, 6 of the 7 tests fail. The test that writes OL through _vrMap passes with or without the fix.
  • After the fix, all tests pass, and the full suite passes.

The API must do this:

  • An OL element reads with vr: "OL", and the value is a binary value.
  • registerVr still adds an unknown VR.
  • An SV element reads and writes negative and large BigInt values, and a Number input. An OV element reads and writes its bytes. Both tests fail before the change.
  • DicomWebJsonWriter gives -2 as a Number and -9223372036854775808 as a string, and JSON.stringify succeeds. The test fails before the fix with TypeError: Do not know how to serialize a BigInt.

The user experience must have this:

  • An OL element writes as OL and reads back with the same bytes.

🤖 Generated with Claude Code

wayfarer3130 and others added 2 commits November 24, 2026 14:38
1.0 port of #632 (commit 5b215ca).

The Vrs registry in packages/core had no OL class, so
createByTypeString("OL") fell back to UN. Add OtherLongString, a
BinaryRepresentation like OF and OD, register it in Vrs, and give OL
the seed flags "length32 single byteStream" in constants/vrs.js. These
are the flags of 0.x: a 32 bit length, a single value, and not in the
read-side singleVRs list.

The 0.x test test/other-long.test.js moves to
test/issues/pr632-other-long.test.js. Six of its seven tests fail
without the change; the _vrMap test already passes.

Other changes for OL:
- The #457 contract test pinned OL as a UN fallback; it now pins only
  OV and SV.
- test/core/registries.test.js uses OV as its unknown VR for
  registerVr, because OL is now registered.
- The texts that said OL has no class change: the vrs.js comment, the
  registerVr example, REG-I-5 in docs/specs/registries-implementation.md,
  the createByTypeString comment, and the absentValues comment.
- The bundle-size ceilings move to 1.081 and 1.063 for the new class.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Maintainer decision Q2 of the review of the 1.0 port of #632: one line in docs/MIGRATION.md, and one bullet in beta-1-release-notes.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 and others added 2 commits November 24, 2026 15:21
…r-long-vr

# Conflicts:
#	beta-1-release-notes.md
Maintainer request on #653. Before, OV and SV fell back to UN, so an
element could not be written with its own VR.

- OV: OtherVeryLongString, a BinaryRepresentation with raw bytes, like
  OL. Seed flags "length32 single byteStream", the same as OL; OB, OW
  and OF also have readSingle, but OL and OV do not, so the exported
  singleVRs list does not change (REG-I-4).
- SV: Signed64BitVeryLong extends Unsigned64BitVeryLong, which now takes
  the type and the stream accessor (BigUint64 or BigInt64). SV reads a
  BigInt with readBigInt64 and writes with writeBigInt64, and coerces a
  Number or a numeric string with BigInt(), as UV does. Seed flags
  "binary length32", the same as UV.
- BufferStream.readBigInt64/writeBigInt64 and
  SplitDataView.getBigInt64/setBigInt64 mirror the BigUint64 methods.
- VALID_VRS, BULKDATA_VRS, BINARY_VRS and the schema rules already
  listed OV and SV. No other code special-cases UV.

Tests: test/issues/vr-sv-ov.test.js (OV bytes; SV negative, the 64 bit
limits and a Number input) fails before this change. The #457 test and
the registerVr test of test/core/registries.test.js now use codes that
are not DICOM VRs (ZZ, QQ, XX), and the #457 once-per-type test now
expects exactly one warning. test/core/absentValues.test.js no longer
filters the "Invalid vr type" warning.

Docs: the JSDoc of UV, SV and OV cites PS3.5 Section 6.2, Table 6.2-1.
REG-I-5, the docs/MIGRATION.md OL line and the beta 1 release notes
bullet now cover OV and SV. The bundle-size ceilings move to 1.083 and
1.065.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 24, 2026 20:42
@wayfarer3130 wayfarer3130 changed the title fix: support the OL (Other Long) value representation fix: support the OL, OV and SV value representations Nov 24, 2026
wayfarer3130 and others added 2 commits November 24, 2026 20:41
…r-long-vr

# Conflicts:
#	test/bundle-size.test.js
DicomWebJsonWriter put the BigInt value of an SV or UV element in Value,
and JSON.stringify threw. PS3.18 Table F.2.3-1 allows a Number or a
String, so a safe integer is a Number and a larger value is a decimal
string, as for DS and IS beyond 2^53.

Also: rewrap a long JSDoc line, rename the #457 describe title, and
raise the bundle ceilings to 1.086 and 1.067 after the merge of
1.0-beta (measured x1.0851 and x1.0666).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 and others added 2 commits November 25, 2026 09:24
…r-long-vr

test/bundle-size.test.js: took the 1.0-beta side and set the ceilings
by measurement after the merge: dcmjs.js 1.08615 -> 1.087, dcmjs.es.js
1.06767 -> 1.068.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-long-vr

Resolve the bundle-size ceilings against the merged build:
dcmjs.js x1.08975 -> 1.09, dcmjs.es.js x1.07144 -> 1.072.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 merged commit 573a702 into 1.0-beta Nov 25, 2026
4 checks passed
@wayfarer3130
wayfarer3130 deleted the fix/1.0-beta-other-long-vr branch November 25, 2026 18:07
@github-actions

Copy link
Copy Markdown

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

The release is available on:

Your semantic-release bot 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…OV, the same with every reader

With the OL and OV VR classes of #653, DicomMessage, fromPart10 and
AsyncDicomReader (normal and expectsRaw) give little endian words for
an explicit OL or OV value and for a UN value whose dictionary VR is
OV. Drop the stale "no OL VR class" sentence of the dataset comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…p docs

After #653, every key of WORD_WIDTHS has a built-in VR class, so the
Vrs check in BinaryRepresentation.wordWidth had no effect. NAT-I-BIN-4 now
says that a code not in WORD_WIDTHS, also one that registerVr adds, has a
width of 1. NAT-U-BIN-7, MIGRATION.md and the AsyncDicomReader skill doc
name OW, OF, OD, OL and OV for the swap and for the UN rule, and item 7 of
the skill doc lists SV and UV.

Tests: UN rows for OW (0028,1201) and OF (0066,0016), fromPart10Stream
in the every-reader check, SV in LENGTH_32_VRS, and a corrected comment
for (0066,0040).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…t of #622) (#663)

* fix: byte order of binary value fields in Explicit VR Big Endian (port of #622)

Explicit VR Big Endian stores the words of OW, OF and OD (and OL / OV)
value fields most significant byte first. dcmjs 1.0 gave them to the
caller, and wrote them, in the order of the caller's memory.

- core: swapBytes / swappedCopy (utilities/byteSwap.js, exported);
  BinaryRepresentation.wordWidth; swap on read, swap a copy on write;
  ParsedUnknownValue re-reads in the right byte order;
  BufferStream.readUint16Array off-by-one.
- legacy: AsyncDicomReader cuts fragments to whole words and swaps them,
  also on the bit-packed path; a UN "ox" pixel data uses the OW width.
- The event-stream parser and StreamingPart10Writer go through core.
- test/big-endian.test.js: independent encoder; every reader and the
  writer, plus the CT1_UNC big endian / little endian fixture pair.
- bundle-size ceilings 1.085 / 1.068.

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

* fix(async): swap Big Endian OW pixel data before it is cut into frames

When a frame of OW pixel data is not a whole number of words (8-bit data
stored as OW, odd samples per frame), a word spans two frames. The async
reader cut the value into frames first and swapped each frame alone, so it
mixed the bytes of the two frames. It now reads and swaps the whole value
first and then cuts it into frames, as the 1-bit path already does.

The big endian test now runs for Explicit VR Big Endian only, with one
little endian write test as a control, and checks the odd frame case on
DicomMessage, AsyncDicomReader, fromPart10 and fromPart10Stream.

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

* docs: little endian binary values in memory for every transfer syntax; bundle-size ceilings

Add NAT-U-BIN-7 and NAT-I-BIN-4 to the naturalized dataset spec, a
MIGRATION.md note for callers that swapped the bytes themselves, and the
raw byte order and maxFragmentSize rounding to the AsyncDicomReader doc.
Set the bundle-size ceilings to the measured ratios (x1.08949, x1.07200).

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

* fix(async): swap expectsRaw OW/OF/OD words to little endian in Big Endian

AsyncDicomReader.readRawBinary now passes the word width of the VR to
_emitSplitValues, so a listener that returns expectsRaw gets OW, OF, OL,
OD and OV words as little endian, the same as on the other read paths.
OB, UN and other VRs keep the byte order of the file.

Use one VR list in NAT-U-BIN-7, MIGRATION.md and the AsyncDicomReader
skill doc: OW, OF and OD, and OL and OV where the VR is supported.

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

* test(bundle-size): raise the ceilings to 1.091 and 1.073 after the merge of 1.0-beta

dcmjs.js is 1,509,340 bytes (ratio 1.09022) and dcmjs.es.js is
1,456,286 bytes (ratio 1.07284) after the merge of #654, #656 and #647.

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

* fix(VR): give a VR with no registered class a word width of 1

A UN element whose dictionary VR is OV (or OL) with no registered VR
class, for example (7FE0,0001), now reads the same with DicomMessage,
fromPart10 and AsyncDicomReader: BinaryRepresentation.wordWidth is 1
for a type that Vrs does not hold, so no reader swaps it.

Docs: NAT-I-BIN-4 states this rule; NAT-U-BIN-7, MIGRATION.md and the
AsyncDicomReader skill say that a UN element whose dictionary VR is
OW, OF or OD reads as that VR and gets the swap. Fix the readRawBinary
doc comment (fragments of maxFragmentSize, not 64KB chunks) and rewrap
a long MIGRATION.md line.

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

* test(big-endian): read explicit OL and OV, and UN with dictionary VR OV, the same with every reader

With the OL and OV VR classes of #653, DicomMessage, fromPart10 and
AsyncDicomReader (normal and expectsRaw) give little endian words for
an explicit OL or OV value and for a UN value whose dictionary VR is
OV. Drop the stale "no OL VR class" sentence of the dataset comment.

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

* fix(VR): drop the Vrs check from wordWidth; name OL and OV in the swap docs

After #653, every key of WORD_WIDTHS has a built-in VR class, so the
Vrs check in BinaryRepresentation.wordWidth had no effect. NAT-I-BIN-4 now
says that a code not in WORD_WIDTHS, also one that registerVr adds, has a
width of 1. NAT-U-BIN-7, MIGRATION.md and the AsyncDicomReader skill doc
name OW, OF, OD, OL and OV for the swap and for the UN rule, and item 7 of
the skill doc lists SV and UV.

Tests: UN rows for OW (0028,1201) and OF (0066,0016), fromPart10Stream
in the every-reader check, SV in LENGTH_32_VRS, and a corrected comment
for (0066,0040).

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

---------

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