@dcmjs-org/dcmjs 1.0.0-beta.20 → 1.0.0-beta.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { log, ValueRepresentation as ValueRepresentation$1, reservePrivateBlock, findPrivateBlock, writePart10, TagHex, resolveCharsetDecoder, normalizeSyntax, isEncapsulatedSyntax, EXPLICIT_LITTLE_ENDIAN, IMPLICIT_LITTLE_ENDIAN, VALID_VRS, ReadBufferStream, DEFLATED_EXPLICIT_LITTLE_ENDIAN, DeflatedReadBufferStream, writeTagObject, writeDataSet, getTagWriteValues, Tag, UNDEFINED_LENGTH, isUnSequenceValue, singleVRs, DicomMetaDictionary, VM_DELIMITER, UNDEFINED_LENGTH_FIX, EXPLICIT_BIG_ENDIAN, DicomMetadataListener, isVideoTransferSyntax, addAccessors, createInformationFilter, toInt, toFloat, dicomJson, BULKDATA_VRS, DEFAULT_INFORMATION_TAGS, ITEM_DELIMITATION_LENGTH, PADDING_NULL, PADDING_SPACE, PN_COMPONENT_DELIMITER, SEQUENCE_DELIMITATION_VALUE, SEQUENCE_DELIMITER_TAG, SEQUENCE_ITEM_TAG, TAG_NAME_MAP, encodingMapping, unencapsulatedTransferSyntaxes, videoTransferSyntaxUIDs, registerPrivatesModule, lookupPrivateTag, privateBlockKey, frameDataset, definePrivateAliases, setPersonName, setAttribute, setVr, WriteBufferStream } from '@dcmjs-org/core';
1
+ import { log, ValueRepresentation as ValueRepresentation$1, reservePrivateBlock, findPrivateBlock, writePart10, TagHex, resolveCharsetDecoder, normalizeSyntax, isEncapsulatedSyntax, EXPLICIT_LITTLE_ENDIAN, IMPLICIT_LITTLE_ENDIAN, VALID_VRS, ReadBufferStream, DEFLATED_EXPLICIT_LITTLE_ENDIAN, DeflatedReadBufferStream, writeTagObject, writeDataSet, getTagWriteValues, Tag, UNDEFINED_LENGTH, isUnSequenceValue, singleVRs, DicomMetaDictionary, VM_DELIMITER, UNDEFINED_LENGTH_FIX, EXPLICIT_BIG_ENDIAN, DicomMetadataListener, swapBytes, isVideoTransferSyntax, addAccessors, createInformationFilter, toInt, toFloat, dicomJson, BULKDATA_VRS, DEFAULT_INFORMATION_TAGS, ITEM_DELIMITATION_LENGTH, PADDING_NULL, PADDING_SPACE, PN_COMPONENT_DELIMITER, SEQUENCE_DELIMITATION_VALUE, SEQUENCE_DELIMITER_TAG, SEQUENCE_ITEM_TAG, TAG_NAME_MAP, encodingMapping, unencapsulatedTransferSyntaxes, videoTransferSyntaxUIDs, registerPrivatesModule, lookupPrivateTag, privateBlockKey, frameDataset, definePrivateAliases, setPersonName, setAttribute, setVr, WriteBufferStream } from '@dcmjs-org/core';
2
2
 
3
3
  /* eslint no-bitwise: 0 */
4
4
  var BitArray = {
@@ -1608,7 +1608,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
1608
1608
  this.isLittleEndian = options === null || options === void 0 ? void 0 : options.isLittleEndian;
1609
1609
  // Number of sequence items being read, 0 at the top level
1610
1610
  this.sequenceDepth = 0;
1611
- // Default maxFragmentSize is 128 MB (128 * 1024 * 1024 bytes)
1611
+ // Default maxFragmentSize is 128 MB; a Big Endian fragment is at least one word, so it can be larger
1612
1612
  this.maxFragmentSize = (_options$maxFragmentS = options === null || options === void 0 ? void 0 : options.maxFragmentSize) !== null && _options$maxFragmentS !== void 0 ? _options$maxFragmentS : 128 * 1024 * 1024;
1613
1613
  this.stream = new ReadBufferStream(null, _objectSpread2(_objectSpread2({
1614
1614
  clearBuffers: true
@@ -2187,16 +2187,28 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2187
2187
  /**
2188
2188
  * Emits one or more listener.value() calls for a fragment, splitting if needed.
2189
2189
  * This does NOT start/pop any array contexts; callers control the surrounding structure.
2190
+ * In Explicit VR Big Endian, each fragment holds whole words of wordWidth
2191
+ * bytes, swapped to little endian.
2190
2192
  */
2191
2193
  }, {
2192
2194
  key: "_emitSplitValues",
2193
2195
  value: (function () {
2194
2196
  var _emitSplitValues2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(length) {
2195
2197
  var _listener$awaitDrain;
2196
- var stream, listener, maxFragmentSize, offset, chunkSize, buffer;
2198
+ var wordWidth,
2199
+ stream,
2200
+ listener,
2201
+ maxFragmentSize,
2202
+ swap,
2203
+ fragmentSize,
2204
+ offset,
2205
+ chunkSize,
2206
+ buffer,
2207
+ _args7 = arguments;
2197
2208
  return _regeneratorRuntime().wrap(function (_context7) {
2198
2209
  while (1) switch (_context7.prev = _context7.next) {
2199
2210
  case 0:
2211
+ wordWidth = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : 1;
2200
2212
  stream = this.stream, listener = this.listener;
2201
2213
  _context7.next = 1;
2202
2214
  return (_listener$awaitDrain = listener.awaitDrain) === null || _listener$awaitDrain === void 0 ? void 0 : _listener$awaitDrain.call(listener);
@@ -2208,6 +2220,8 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2208
2220
  }
2209
2221
  throw new Error("maxFragmentSize must be a positive number, got ".concat(maxFragmentSize));
2210
2222
  case 2:
2223
+ swap = this.syntax === EXPLICIT_BIG_ENDIAN && wordWidth > 1;
2224
+ fragmentSize = swap ? Math.max(wordWidth, maxFragmentSize - maxFragmentSize % wordWidth) : maxFragmentSize;
2211
2225
  offset = 0;
2212
2226
  case 3:
2213
2227
  if (!(offset < length)) {
@@ -2215,11 +2229,14 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2215
2229
  break;
2216
2230
  }
2217
2231
  readLog.trace("_emitSplitValues loop", offset, length);
2218
- chunkSize = Math.min(maxFragmentSize, length - offset);
2232
+ chunkSize = Math.min(fragmentSize, length - offset);
2219
2233
  _context7.next = 4;
2220
2234
  return stream.ensureAvailable(chunkSize);
2221
2235
  case 4:
2222
2236
  buffer = stream.readArrayBuffer(chunkSize);
2237
+ if (swap) {
2238
+ swapBytes(buffer, wordWidth);
2239
+ }
2223
2240
  listener.value(buffer);
2224
2241
  offset += chunkSize;
2225
2242
  stream.consume();
@@ -2369,12 +2386,13 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2369
2386
  key: "readUncompressed",
2370
2387
  value: (function () {
2371
2388
  var _readUncompressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(tagInfo) {
2372
- var length, listener, numberOfFrames, frameLength, _listener$information, _listener$information2, _listener$information3, _listener$information4, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, frameNumber;
2389
+ var length, listener, wordWidth, numberOfFrames, frameLength, _listener$information, _listener$information2, _listener$information3, _listener$information4, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, allPixelData, offset, frameNumber;
2373
2390
  return _regeneratorRuntime().wrap(function (_context0) {
2374
2391
  while (1) switch (_context0.prev = _context0.next) {
2375
2392
  case 0:
2376
2393
  length = tagInfo.length;
2377
2394
  listener = this.listener;
2395
+ wordWidth = this.wordWidth(tagInfo);
2378
2396
  numberOfFrames = this.getNumberOfFrames();
2379
2397
  frameLength = Math.floor(length / numberOfFrames);
2380
2398
  if (!(numberOfFrames > 1)) {
@@ -2407,24 +2425,41 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2407
2425
  }
2408
2426
  throw new Error("Invalid frame length: ".concat(length, " for ").concat(numberOfFrames, " frames"));
2409
2427
  case 4:
2410
- frameNumber = 0;
2428
+ if (!(this.syntax === EXPLICIT_BIG_ENDIAN && frameLength % wordWidth !== 0)) {
2429
+ _context0.next = 6;
2430
+ break;
2431
+ }
2432
+ _context0.next = 5;
2433
+ return this.stream.ensureAvailable(length);
2411
2434
  case 5:
2435
+ allPixelData = this.stream.readArrayBuffer(length);
2436
+ this.stream.consume();
2437
+ swapBytes(allPixelData, wordWidth);
2438
+ for (offset = 0; offset < length; offset += frameLength) {
2439
+ listener.startObject([]);
2440
+ listener.value(allPixelData.slice(offset, offset + frameLength));
2441
+ listener.pop();
2442
+ }
2443
+ return _context0.abrupt("return");
2444
+ case 6:
2445
+ frameNumber = 0;
2446
+ case 7:
2412
2447
  if (!(frameNumber < numberOfFrames)) {
2413
- _context0.next = 8;
2448
+ _context0.next = 10;
2414
2449
  break;
2415
2450
  }
2416
2451
  readLog.trace("readUncompressed loop", frameNumber, numberOfFrames);
2417
2452
  listener.startObject([]);
2418
- _context0.next = 6;
2419
- return this._emitSplitValues(frameLength);
2420
- case 6:
2453
+ _context0.next = 8;
2454
+ return this._emitSplitValues(frameLength, wordWidth);
2455
+ case 8:
2421
2456
  listener.pop();
2422
2457
  // console.log(stream.getBufferMemoryInfo());
2423
- case 7:
2458
+ case 9:
2424
2459
  frameNumber++;
2425
- _context0.next = 5;
2460
+ _context0.next = 7;
2426
2461
  break;
2427
- case 8:
2462
+ case 10:
2428
2463
  case "end":
2429
2464
  return _context0.stop();
2430
2465
  }
@@ -2492,6 +2527,10 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2492
2527
  case 4:
2493
2528
  allPixelData = stream.readArrayBuffer(totalBytes);
2494
2529
  stream.consume();
2530
+ if (this.syntax === EXPLICIT_BIG_ENDIAN) {
2531
+ // the bits of OW data are packed in big endian words
2532
+ swapBytes(allPixelData, this.wordWidth(tagInfo));
2533
+ }
2495
2534
 
2496
2535
  // Extract each frame, unpacking bits so each frame starts at byte 0
2497
2536
  for (frameNumber = 0; frameNumber < numberOfFrames; frameNumber++) {
@@ -2533,7 +2572,8 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2533
2572
  }()
2534
2573
  /**
2535
2574
  * Reads raw binary data in chunks and delivers it to the listener.
2536
- * This method reads data in 64KB chunks to manage memory efficiently.
2575
+ * Reads the value in fragments of `maxFragmentSize` bytes.
2576
+ * OW/OF/OL/OD/OV words come as little endian, as on the other read paths.
2537
2577
  */
2538
2578
  )
2539
2579
  }, {
@@ -2546,7 +2586,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2546
2586
  case 0:
2547
2587
  length = tagInfo.length;
2548
2588
  _context10.next = 1;
2549
- return this._emitSplitValues(length);
2589
+ return this._emitSplitValues(length, this.wordWidth(tagInfo));
2550
2590
  case 1:
2551
2591
  case "end":
2552
2592
  return _context10.stop();
@@ -2557,7 +2597,13 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2557
2597
  return _readRawBinary.apply(this, arguments);
2558
2598
  }
2559
2599
  return readRawBinary;
2560
- }())
2600
+ }() /** Bytes per word of the value field; "ox" (a UN pixel data) is OW. */)
2601
+ }, {
2602
+ key: "wordWidth",
2603
+ value: function wordWidth(tagInfo) {
2604
+ var _ValueRepresentation$;
2605
+ return (_ValueRepresentation$ = ValueRepresentation$1.createByTypeString(tagInfo.vr).wordWidth) !== null && _ValueRepresentation$ !== void 0 ? _ValueRepresentation$ : 1;
2606
+ }
2561
2607
  }, {
2562
2608
  key: "isSequence",
2563
2609
  value: function isSequence(tagInfo) {
@@ -3522,6 +3568,22 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3522
3568
  DimensionDescriptionLabel: "ImagePositionPatient"
3523
3569
  }];
3524
3570
  }
3571
+
3572
+ /**
3573
+ * Fills in the functional groups of a multiframe dataset.
3574
+ *
3575
+ * A missing or empty SharedFunctionalGroupsSequence is built from the
3576
+ * top-level image plane attributes; a one-item array is used as its item.
3577
+ * The shared item gets the list accessors (addAccessors), so both
3578
+ * `SharedFunctionalGroupsSequence.X` and `SharedFunctionalGroupsSequence[0].X`
3579
+ * work.
3580
+ * The PerFrameFunctionalGroupsSequence is filled up to the declared
3581
+ * NumberOfFrames with items at the top-level position, existing items keep
3582
+ * their content, and each item without a FrameContentSequence gets one.
3583
+ * Added items share the position but get increasing InStackPositionNumber.
3584
+ * Items beyond NumberOfFrames are kept unchanged; a null item there is
3585
+ * skipped and does not throw.
3586
+ */
3525
3587
  }, {
3526
3588
  key: "normalizeMultiframe",
3527
3589
  value: function normalizeMultiframe() {
@@ -3545,6 +3607,10 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3545
3607
  if (!ds.PresentationLUTShape) {
3546
3608
  ds.PresentationLUTShape = "IDENTITY";
3547
3609
  }
3610
+ if (Array.isArray(ds.SharedFunctionalGroupsSequence)) {
3611
+ // The shared group has one item; an empty array counts as missing
3612
+ ds.SharedFunctionalGroupsSequence = ds.SharedFunctionalGroupsSequence[0];
3613
+ }
3548
3614
  if (!ds.SharedFunctionalGroupsSequence) {
3549
3615
  log.warn("Missing SharedFunctionalGroupsSequence; using the top-level image plane attributes");
3550
3616
  ds.SharedFunctionalGroupsSequence = ImageNormalizer.sharedImagePlaneGroups(ds, {
@@ -3552,6 +3618,7 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3552
3618
  SpacingBetweenSlices: ds.SpacingBetweenSlices
3553
3619
  });
3554
3620
  }
3621
+ ds.SharedFunctionalGroupsSequence = addAccessors(ds.SharedFunctionalGroupsSequence);
3555
3622
 
3556
3623
  // TODO: special case!
3557
3624
  if (ds.BodyPartExamined === "PROSTATE") {
@@ -3571,23 +3638,20 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3571
3638
  RescaleSlope: rescaleSlope,
3572
3639
  RescaleType: "US"
3573
3640
  };
3574
- var frameCount = this.datasets.length;
3575
- if (!ds.PerFrameFunctionalGroupsSequence) {
3576
- // One item per declared frame, all at the top-level position
3577
- frameCount = Math.max(frameCount, Number(ds.NumberOfFrames) || 0);
3578
- ds.PerFrameFunctionalGroupsSequence = Array.from({
3579
- length: frameCount
3580
- }, function () {
3581
- return ImageNormalizer.planePositionGroup(ds);
3582
- });
3583
- } else if (!Array.isArray(ds.PerFrameFunctionalGroupsSequence)) {
3584
- ds.PerFrameFunctionalGroupsSequence = [ds.PerFrameFunctionalGroupsSequence];
3641
+ var frameCount = Math.max(this.datasets.length, Number(ds.NumberOfFrames) || 0);
3642
+ var perFrame = ds.PerFrameFunctionalGroupsSequence || [];
3643
+ ds.PerFrameFunctionalGroupsSequence = Array.isArray(perFrame) ? perFrame : [perFrame];
3644
+ while (ds.PerFrameFunctionalGroupsSequence.length < frameCount) {
3645
+ ds.PerFrameFunctionalGroupsSequence.push(ImageNormalizer.planePositionGroup(ds));
3585
3646
  }
3586
3647
  for (var frameNumber = 1; frameNumber <= frameCount; frameNumber++) {
3587
3648
  var _ds$PerFrameFunctiona, _ref;
3649
+ var item = (_ds$PerFrameFunctiona = ds.PerFrameFunctionalGroupsSequence)[_ref = frameNumber - 1] || (_ds$PerFrameFunctiona[_ref] = {});
3650
+ if (item.FrameContentSequence) {
3651
+ continue;
3652
+ }
3588
3653
  var dataset = this.datasets[frameNumber - 1] || {};
3589
- (_ds$PerFrameFunctiona = ds.PerFrameFunctionalGroupsSequence)[_ref = frameNumber - 1] || (_ds$PerFrameFunctiona[_ref] = {});
3590
- ds.PerFrameFunctionalGroupsSequence[frameNumber - 1].FrameContentSequence = {
3654
+ item.FrameContentSequence = {
3591
3655
  FrameAcquisitionDuration: 0,
3592
3656
  StackID: 1,
3593
3657
  InStackPositionNumber: frameNumber,
@@ -3595,9 +3659,8 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3595
3659
  };
3596
3660
  var frameTime = dataset.AcquisitionDate + dataset.AcquisitionTime;
3597
3661
  if (!isNaN(frameTime)) {
3598
- var frameContentSequence = ds.PerFrameFunctionalGroupsSequence[frameNumber - 1].FrameContentSequence;
3599
- frameContentSequence.FrameAcquisitionDateTime = frameTime;
3600
- frameContentSequence.FrameReferenceDateTime = frameTime;
3662
+ item.FrameContentSequence.FrameAcquisitionDateTime = frameTime;
3663
+ item.FrameContentSequence.FrameReferenceDateTime = frameTime;
3601
3664
  }
3602
3665
  }
3603
3666
 
@@ -3625,7 +3688,7 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3625
3688
  count: 0
3626
3689
  };
3627
3690
  ds.PerFrameFunctionalGroupsSequence.forEach(function (functionalGroup) {
3628
- if (functionalGroup.FrameVOILUT) {
3691
+ if (functionalGroup !== null && functionalGroup !== void 0 && functionalGroup.FrameVOILUT) {
3629
3692
  var wc = functionalGroup.FrameVOILUTSequence.WindowCenter;
3630
3693
  var ww = functionalGroup.FrameVOILUTSequence.WindowWidth;
3631
3694
  if (functionalGroup.FrameVOILUTSequence && wc && ww) {
@@ -3699,9 +3762,11 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3699
3762
  }, {
3700
3763
  key: "planePositionGroup",
3701
3764
  value: function planePositionGroup(dataset) {
3765
+ var position = dataset.ImagePositionPatient;
3702
3766
  return {
3703
3767
  PlanePositionSequence: {
3704
- ImagePositionPatient: dataset.ImagePositionPatient
3768
+ // A copy, so that no two frames share one array
3769
+ ImagePositionPatient: Array.isArray(position) ? position.slice() : position
3705
3770
  }
3706
3771
  };
3707
3772
  }
@@ -15999,4 +16064,4 @@ ValueRepresentation.setTagClass(Tag);
15999
16064
  // entries (src/eventStream.js, ...): the default entry is the 0.52 surface.
16000
16065
 
16001
16066
  export { DICOMWEB as D, _inherits as _, _createClass as a, _objectSpread2 as b, _classCallCheck as c, _callSuper as d, _createForOfIteratorHelper as e, datasetToDict as f, _typeof as g, _asyncToGenerator as h, _regeneratorRuntime as i, adapters as j, anonymizer as k, async as l, constants as m, data as n, dcmjs as o, derivations as p, normalizers as q, sr as s, utilities as u };
16002
- //# sourceMappingURL=dcmjs.shared-RH-AbhO5.js.map
16067
+ //# sourceMappingURL=dcmjs.shared-DVqSe8G1.js.map