Repository navigation
fix(VR): format DS numbers to 16 characters instead of cutting off the exponent - #654
Merged
Merged
Conversation
…e exponent 1.0 port of #610 (commit aee06e4), with the round trip test of #624. denaturalizeDataset in packages/core now formats each number of a DS array with DecimalString.convertToString before denaturalizeValue, so 3.5163338899999997e-10 is written as 3.5163338900e-10 and not cut to 3.51633388999999. Both tests go in test/issues/issue531-ds-exponent.test.js (#610 fixes #531). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review items S1 and N1 of the 1.0 port of #610. The 1.x port now also formats the scalar case: a VM 1 DS attribute, for example SliceThickness or SliceLocation, is a single number in a 1.x naturalized dataset, and it went through String() and was cut to 16 characters. A Number object (new Number(...)) is formatted the same way. One formatDs function serves the scalar and the list form. master (0.x) has the same scalar gap after #610. The JSDoc of denaturalizeDataset cites PS3.5 Table 6.2-1. The bundle-size ceilings move to 1.081 and 1.063 for this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Maintainer decision Q2 of the review of the 1.0 port of #610: NAT-U-RT-8 in docs/specs/naturalized-dataset.md, with the PS3.5 Section 6.2, Table 6.2-1 reference and the test file, and one bullet in beta-1-release-notes.md. No NAT-I rule covers the DS write, so no NAT-I rule changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rebase onto 1.0-beta adds the declared length clamp of #652 to the DS formatting of this branch: dcmjs.es.js is x1.0632. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 24, 2026
wayfarer3130
marked this pull request as ready for review
November 24, 2026 20:18
…ormat # Conflicts: # beta-1-release-notes.md # test/bundle-size.test.js
…ormat test/bundle-size.test.js: kept the 1.0-beta ceilings. The measured ratios after the merge are dcmjs.js 1.08400 and dcmjs.es.js 1.06658, which fit under the 1.0-beta ceilings 1.085 and 1.067. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Nov 25, 2026
…rge 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]>
|
🎉 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
…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]>
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.
Summary
This PR is the 1.0 port of #610 (commit
aee06e4, fixes #531), with the round-trip test of #624.denaturalizeDatasetnow writes a DS number in 16 characters or less, and it keeps the exponent. Before,String(number)was cut to 16 characters:3.5163338899999997e-10became3.51633388999999.The 1.x port goes further than 0.x in two cases. Master still has the gap for both cases after #610.
SliceThicknesswith VM 1, is also formatted. In 1.x, a VM 1 attribute is a single number, not a list (NAT-U-VAL-1).Numberobject is also formatted.Changes
packages/core/src/DicomMetaDictionary.js: one formatting step for DS, withvr.convertToString. The step applies to a single number, to each number in a list, and to aNumberobject. The JSDoc cites PS3.5 Table 6.2-1.docs/specs/naturalized-dataset.md: new user requirement NAT-U-RT-8. A DS number, single or in a list, is written in 16 characters or less, and keeps the exponent. The rule cites PS3.5 Section 6.2, Table 6.2-1.beta-1-release-notes.md: one bullet.test/bundle-size.test.js: the ceilings increase to 1.084 (dcmjs.js) and 1.066 (dcmjs.es.js), measured after the merge of1.0-beta(×1.0830 and ×1.0655).Review
An independent review compared the port with #610 and #624.
fromNaturalizedcallsdenaturalizeDataset, so the fix also covers that path. A value that is read, edited, and written back already goes through the DS writer, which formats the number. The review found the single-number gap (S1) and theNumberobject gap (N1). This PR fixes both.Tests
test/issues/issue531-ds-exponent.test.jshas the #610 test, the #624 round trip, and one new test for the single number and theNumberobject.1.0-betawithout the fix, the tests fail. For example, the round trip gives_rawValue"3.51633388999999", not"3.5163338900e-10".The API must do this:
denaturalizeDatasetformats a DS number in a list, a single DS number, and aNumberobject to 16 characters or less.The user experience must have this:
3.5163338900e-10).🤖 Generated with Claude Code