@dcmjs-org/dcmjs 1.0.0-beta.19 → 1.0.0-beta.21

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.
package/build/dcmjs.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dcmjs = require('./dcmjs.shared-L4OH_Ab_.cjs');
5
+ var dcmjs = require('./dcmjs.shared-C_SwQ4fu.cjs');
6
6
  var core = require('@dcmjs-org/core');
7
7
 
8
8
 
package/build/dcmjs.es.js CHANGED
@@ -1,3 +1,3 @@
1
- export { D as DICOMWEB, j as adapters, k as anonymizer, l as async, m as constants, n as data, o as default, p as derivations, q as normalizers, s as sr, u as utilities } from './dcmjs.shared-DnjtTwFB.js';
1
+ export { D as DICOMWEB, j as adapters, k as anonymizer, l as async, m as constants, n as data, o as default, p as derivations, q as normalizers, s as sr, u as utilities } from './dcmjs.shared-CMo1hh3U.js';
2
2
  export { log } from '@dcmjs-org/core';
3
3
  //# sourceMappingURL=dcmjs.es.js.map
package/build/dcmjs.js CHANGED
@@ -8906,10 +8906,9 @@
8906
8906
  }, {
8907
8907
  key: "readUint16Array",
8908
8908
  value: function readUint16Array(length) {
8909
- var sixlen = length / 2,
8910
- arr = new Uint16Array(sixlen),
8911
- i = 0;
8912
- while (i++ < sixlen) {
8909
+ var words = Math.floor(length / 2),
8910
+ arr = new Uint16Array(words);
8911
+ for (var i = 0; i < words; i++) {
8913
8912
  arr[i] = this.view.getUint16(this.offset, this.isLittleEndian);
8914
8913
  this.offset += 2;
8915
8914
  }
@@ -9915,6 +9914,50 @@
9915
9914
  pnAddValueAccessors: pnAddValueAccessors
9916
9915
  };
9917
9916
 
9917
+ /** A Uint8Array over the bytes of data, or undefined when data has no bytes. */
9918
+ function asBytes(data) {
9919
+ if (ArrayBuffer.isView(data)) {
9920
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
9921
+ }
9922
+ // not instanceof: a buffer from another realm (worker, jsdom) fails it
9923
+ if (data && typeof data.byteLength === "number") {
9924
+ return new Uint8Array(data);
9925
+ }
9926
+ return undefined;
9927
+ }
9928
+
9929
+ /**
9930
+ * Reverses the bytes of each word of data, in place: Explicit VR Big Endian
9931
+ * to the little endian in-memory form (PS3.5 Section 7.3), or back.
9932
+ * @param {ArrayBuffer|ArrayBufferView} data
9933
+ * @param {number} wordWidth bytes per word; 1 changes nothing
9934
+ * @returns data
9935
+ */
9936
+ function swapBytes(data, wordWidth) {
9937
+ var bytes = wordWidth > 1 ? asBytes(data) : undefined;
9938
+ if (!bytes) {
9939
+ return data;
9940
+ }
9941
+ var end = bytes.length - bytes.length % wordWidth;
9942
+ for (var start = 0; start < end; start += wordWidth) {
9943
+ for (var i = start, j = start + wordWidth - 1; i < j; i++, j--) {
9944
+ var b = bytes[i];
9945
+ bytes[i] = bytes[j];
9946
+ bytes[j] = b;
9947
+ }
9948
+ }
9949
+ return data;
9950
+ }
9951
+
9952
+ /**
9953
+ * {@link swapBytes} on a copy. Gives data itself when there is nothing to
9954
+ * swap, so the caller must not modify the result.
9955
+ */
9956
+ function swappedCopy(data, wordWidth) {
9957
+ var bytes = wordWidth > 1 ? asBytes(data) : undefined;
9958
+ return bytes ? swapBytes(bytes.slice(), wordWidth).buffer : data;
9959
+ }
9960
+
9918
9961
  function rtrim(str) {
9919
9962
  return str.replace(/\s*$/g, "");
9920
9963
  }
@@ -9951,6 +9994,15 @@
9951
9994
  vr._isLength32 = !!flags.length32;
9952
9995
  }
9953
9996
 
9997
+ // Bytes per word of a binary value field, for Explicit VR Big Endian (OB, UN: 1)
9998
+ var WORD_WIDTHS = {
9999
+ OD: 8,
10000
+ OF: 4,
10001
+ OL: 4,
10002
+ OV: 8,
10003
+ OW: 2
10004
+ };
10005
+
9954
10006
  // Unknown VR types already warned about by createByTypeString — the UN
9955
10007
  // fallback warns at most once per type (issue #457).
9956
10008
  var unknownVrTypesWarned = new Set();
@@ -10353,8 +10405,16 @@
10353
10405
  _this2._storeRaw = false;
10354
10406
  return _this2;
10355
10407
  }
10408
+
10409
+ /** Bytes per word of the value field; 1 for a byte stream. */
10356
10410
  _inherits(BinaryRepresentation, _ValueRepresentation3);
10357
10411
  return _createClass(BinaryRepresentation, [{
10412
+ key: "wordWidth",
10413
+ get: function get() {
10414
+ var _WORD_WIDTHS$this$typ;
10415
+ return (_WORD_WIDTHS$this$typ = WORD_WIDTHS[this.type]) !== null && _WORD_WIDTHS$this$typ !== void 0 ? _WORD_WIDTHS$this$typ : 1;
10416
+ }
10417
+ }, {
10358
10418
  key: "writeBytes",
10359
10419
  value: function writeBytes(stream, value, _syntax, isEncapsulated) {
10360
10420
  var writeOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
@@ -10427,6 +10487,9 @@
10427
10487
  return 0xffffffff;
10428
10488
  } else {
10429
10489
  var binaryData = value[0];
10490
+ if (!stream.isLittleEndian) {
10491
+ binaryData = swappedCopy(binaryData, this.wordWidth);
10492
+ }
10430
10493
  binaryStream = new ReadBufferStream(binaryData);
10431
10494
  stream.concat(binaryStream);
10432
10495
  return _get(_getPrototypeOf(BinaryRepresentation.prototype), "writeBytes", this).call(this, stream, binaryData, [binaryStream.size], writeOptions);
@@ -10539,12 +10602,6 @@
10539
10602
  }
10540
10603
  return frames;
10541
10604
  } else {
10542
- var bytes;
10543
- /*if (this.type == 'OW') {
10544
- bytes = stream.readUint16Array(length);
10545
- } else if (this.type == 'OB') {
10546
- bytes = stream.readUint8Array(length);
10547
- }*/
10548
10605
  // A declared length longer than the data present means a
10549
10606
  // truncated or malformed file: read the bytes that are present.
10550
10607
  // https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
@@ -10553,8 +10610,12 @@
10553
10610
  validationLog.warn("".concat(this.type, " value declares ").concat(length, " bytes but only ").concat(available, " are available - reading the available bytes"));
10554
10611
  length = available;
10555
10612
  }
10556
- bytes = stream.getBuffer(stream.offset, stream.offset + length);
10613
+ var bytes = stream.getBuffer(stream.offset, stream.offset + length);
10557
10614
  stream.increment(length);
10615
+ if (!stream.isLittleEndian) {
10616
+ // getBuffer gives a copy
10617
+ swapBytes(bytes, this.wordWidth);
10618
+ }
10558
10619
  return [bytes];
10559
10620
  }
10560
10621
  }
@@ -11558,12 +11619,15 @@
11558
11619
  _this30._storeRaw = true;
11559
11620
  return _this30;
11560
11621
  }
11622
+
11623
+ /** The second read swaps only what readBytes did not (scalar VRs, "ox"). */
11561
11624
  _inherits(ParsedUnknownValue, _BinaryRepresentation2);
11562
11625
  return _createClass(ParsedUnknownValue, [{
11563
11626
  key: "read",
11564
11627
  value: function read(stream, length, syntax, readOptions) {
11565
11628
  var arrayBuffer = this.readBytes(stream, length, syntax)[0];
11566
11629
  var streamFromBuffer = new ReadBufferStream(arrayBuffer, {
11630
+ littleEndian: stream.isLittleEndian || this.wordWidth > 1,
11567
11631
  decoder: stream.decoder
11568
11632
  });
11569
11633
  var vr = ValueRepresentation$1.createByTypeString(this.type);
@@ -16826,7 +16890,9 @@
16826
16890
  _classCallCheck(this, AsyncDicomReader);
16827
16891
  _defineProperty(this, "syntax", EXPLICIT_LITTLE_ENDIAN);
16828
16892
  this.isLittleEndian = options === null || options === void 0 ? void 0 : options.isLittleEndian;
16829
- // Default maxFragmentSize is 128 MB (128 * 1024 * 1024 bytes)
16893
+ // Number of sequence items being read, 0 at the top level
16894
+ this.sequenceDepth = 0;
16895
+ // Default maxFragmentSize is 128 MB; a Big Endian fragment is at least one word, so it can be larger
16830
16896
  this.maxFragmentSize = (_options$maxFragmentS = options === null || options === void 0 ? void 0 : options.maxFragmentSize) !== null && _options$maxFragmentS !== void 0 ? _options$maxFragmentS : 128 * 1024 * 1024;
16831
16897
  this.stream = new ReadBufferStream(null, _objectSpread2(_objectSpread2({
16832
16898
  clearBuffers: true
@@ -17287,16 +17353,24 @@
17287
17353
  * item boundary and returns control here for the next item. Without that
17288
17354
  * offset, read() skips the later Item tags as instructions, and all items
17289
17355
  * of a defined-length sequence merge into the first item.
17356
+ *
17357
+ * untilTag and includeUntilTagValue apply to the top-level data set only,
17358
+ * so the items are read without them: an Icon Image Sequence item has its
17359
+ * own Pixel Data, which must not stop a read with untilTag 7FE00010.
17290
17360
  */
17291
17361
  }, {
17292
17362
  key: "readSequence",
17293
17363
  value: (function () {
17294
17364
  var _readSequence = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(listener, sqTagInfo, options) {
17295
17365
  var _ref, _sqTagInfo$sequenceRe;
17296
- var length, stream, readSyntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, decoder, _t;
17366
+ var itemOptions, length, stream, readSyntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, decoder, _t;
17297
17367
  return _regeneratorRuntime().wrap(function (_context6) {
17298
17368
  while (1) switch (_context6.prev = _context6.next) {
17299
17369
  case 0:
17370
+ itemOptions = _objectSpread2(_objectSpread2({}, options), {}, {
17371
+ untilTag: null,
17372
+ includeUntilTagValue: false
17373
+ });
17300
17374
  length = sqTagInfo.length;
17301
17375
  stream = this.stream;
17302
17376
  readSyntax = (_ref = (_sqTagInfo$sequenceRe = sqTagInfo.sequenceReadSyntax) !== null && _sqTagInfo$sequenceRe !== void 0 ? _sqTagInfo$sequenceRe : options === null || options === void 0 ? void 0 : options.readSyntax) !== null && _ref !== void 0 ? _ref : this.syntax;
@@ -17313,16 +17387,16 @@
17313
17387
  _t = _context6.sent;
17314
17388
  case 3:
17315
17389
  if (!_t) {
17316
- _context6.next = 8;
17390
+ _context6.next = 10;
17317
17391
  break;
17318
17392
  }
17319
17393
  readLog.debug("readSequence loop", stream.offset, endOffset);
17320
- tagInfo = this.readTagHeader(_objectSpread2(_objectSpread2({}, options), {}, {
17394
+ tagInfo = this.readTagHeader(_objectSpread2(_objectSpread2({}, itemOptions), {}, {
17321
17395
  readSyntax: readSyntax
17322
17396
  }));
17323
17397
  tag = tagInfo.tag;
17324
17398
  if (!(tag === TagHex.Item)) {
17325
- _context6.next = 5;
17399
+ _context6.next = 7;
17326
17400
  break;
17327
17401
  }
17328
17402
  listener.startObject();
@@ -17332,38 +17406,59 @@
17332
17406
  // item (PS3.5 7.5.3), but the item is read on this stream:
17333
17407
  // put back the decoder the item started with.
17334
17408
  decoder = stream.decoder;
17335
- _context6.next = 4;
17336
- return this.read(listener, _objectSpread2(_objectSpread2({}, options), {}, {
17409
+ this.sequenceDepth++;
17410
+ _context6.prev = 4;
17411
+ _context6.next = 5;
17412
+ return this.read(listener, _objectSpread2(_objectSpread2({}, itemOptions), {}, {
17337
17413
  untilOffset: itemUntilOffset,
17338
17414
  readSyntax: readSyntax
17339
17415
  }));
17340
- case 4:
17416
+ case 5:
17417
+ _context6.prev = 5;
17418
+ this.sequenceDepth--;
17419
+ return _context6.finish(5);
17420
+ case 6:
17341
17421
  stream.setDecoder(decoder);
17342
- _context6.next = 7;
17422
+ _context6.next = 9;
17343
17423
  break;
17344
- case 5:
17424
+ case 7:
17345
17425
  if (!(tag === TagHex.SequenceDelimitationEnd)) {
17346
- _context6.next = 6;
17426
+ _context6.next = 8;
17347
17427
  break;
17348
17428
  }
17349
17429
  return _context6.abrupt("return");
17350
- case 6:
17430
+ case 8:
17351
17431
  console.warn("Unknown tag info", length, tagInfo);
17352
- throw new Error();
17353
- case 7:
17432
+ throw new Error("Expected an item or a sequence delimitation item in a sequence, found tag ".concat(tag));
17433
+ case 9:
17354
17434
  _context6.next = 1;
17355
17435
  break;
17356
- case 8:
17436
+ case 10:
17357
17437
  case "end":
17358
17438
  return _context6.stop();
17359
17439
  }
17360
- }, _callee6, this);
17440
+ }, _callee6, this, [[4,, 5, 6]]);
17361
17441
  }));
17362
17442
  function readSequence(_x3, _x4, _x5) {
17363
17443
  return _readSequence.apply(this, arguments);
17364
17444
  }
17365
17445
  return readSequence;
17366
- }())
17446
+ }()
17447
+ /**
17448
+ * The number of frames of the Pixel Data being read. NumberOfFrames is
17449
+ * tracked for the top-level data set only, so Pixel Data inside a sequence
17450
+ * item (an Icon Image Sequence item, for example) is a single frame.
17451
+ */
17452
+ )
17453
+ }, {
17454
+ key: "getNumberOfFrames",
17455
+ value: function getNumberOfFrames() {
17456
+ var _this$listener;
17457
+ if (this.sequenceDepth > 0) {
17458
+ return 1;
17459
+ }
17460
+ return parseInt(((_this$listener = this.listener) === null || _this$listener === void 0 || (_this$listener = _this$listener.information) === null || _this$listener === void 0 ? void 0 : _this$listener.numberOfFrames) || 1);
17461
+ }
17367
17462
  }, {
17368
17463
  key: "readPixelData",
17369
17464
  value: function readPixelData(tagInfo) {
@@ -17376,16 +17471,28 @@
17376
17471
  /**
17377
17472
  * Emits one or more listener.value() calls for a fragment, splitting if needed.
17378
17473
  * This does NOT start/pop any array contexts; callers control the surrounding structure.
17474
+ * In Explicit VR Big Endian, each fragment holds whole words of wordWidth
17475
+ * bytes, swapped to little endian.
17379
17476
  */
17380
17477
  }, {
17381
17478
  key: "_emitSplitValues",
17382
17479
  value: (function () {
17383
17480
  var _emitSplitValues2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(length) {
17384
17481
  var _listener$awaitDrain;
17385
- var stream, listener, maxFragmentSize, offset, chunkSize, buffer;
17482
+ var wordWidth,
17483
+ stream,
17484
+ listener,
17485
+ maxFragmentSize,
17486
+ swap,
17487
+ fragmentSize,
17488
+ offset,
17489
+ chunkSize,
17490
+ buffer,
17491
+ _args7 = arguments;
17386
17492
  return _regeneratorRuntime().wrap(function (_context7) {
17387
17493
  while (1) switch (_context7.prev = _context7.next) {
17388
17494
  case 0:
17495
+ wordWidth = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : 1;
17389
17496
  stream = this.stream, listener = this.listener;
17390
17497
  _context7.next = 1;
17391
17498
  return (_listener$awaitDrain = listener.awaitDrain) === null || _listener$awaitDrain === void 0 ? void 0 : _listener$awaitDrain.call(listener);
@@ -17397,6 +17504,8 @@
17397
17504
  }
17398
17505
  throw new Error("maxFragmentSize must be a positive number, got ".concat(maxFragmentSize));
17399
17506
  case 2:
17507
+ swap = this.syntax === EXPLICIT_BIG_ENDIAN && wordWidth > 1;
17508
+ fragmentSize = swap ? Math.max(wordWidth, maxFragmentSize - maxFragmentSize % wordWidth) : maxFragmentSize;
17400
17509
  offset = 0;
17401
17510
  case 3:
17402
17511
  if (!(offset < length)) {
@@ -17404,11 +17513,14 @@
17404
17513
  break;
17405
17514
  }
17406
17515
  readLog.trace("_emitSplitValues loop", offset, length);
17407
- chunkSize = Math.min(maxFragmentSize, length - offset);
17516
+ chunkSize = Math.min(fragmentSize, length - offset);
17408
17517
  _context7.next = 4;
17409
17518
  return stream.ensureAvailable(chunkSize);
17410
17519
  case 4:
17411
17520
  buffer = stream.readArrayBuffer(chunkSize);
17521
+ if (swap) {
17522
+ swapBytes(buffer, wordWidth);
17523
+ }
17412
17524
  listener.value(buffer);
17413
17525
  offset += chunkSize;
17414
17526
  stream.consume();
@@ -17433,8 +17545,7 @@
17433
17545
  key: "readCompressed",
17434
17546
  value: (function () {
17435
17547
  var _readCompressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_tagInfo) {
17436
- var _listener$information;
17437
- var stream, listener, transferSyntaxUid, isVideo, numberOfFrames, isSingleFrame, offsets, singleArray, startOffset, frameNumber, lastFrame, frameTag, length;
17548
+ var stream, listener, transferSyntaxUid, isVideo, isSingleFrame, offsets, singleArray, startOffset, frameNumber, lastFrame, frameTag, length;
17438
17549
  return _regeneratorRuntime().wrap(function (_context8) {
17439
17550
  while (1) switch (_context8.prev = _context8.next) {
17440
17551
  case 0:
@@ -17445,8 +17556,7 @@
17445
17556
  case 1:
17446
17557
  // Check if this is a video transfer syntax
17447
17558
  isVideo = isVideoTransferSyntax(transferSyntaxUid); // Check number of frames - only use video logic for single frame (or undefined)
17448
- numberOfFrames = (_listener$information = listener.information) === null || _listener$information === void 0 ? void 0 : _listener$information.numberOfFrames;
17449
- isSingleFrame = !numberOfFrames || parseInt(numberOfFrames) <= 1;
17559
+ isSingleFrame = this.getNumberOfFrames() <= 1;
17450
17560
  _context8.next = 2;
17451
17561
  return this.readOffsets();
17452
17562
  case 2:
@@ -17560,23 +17670,23 @@
17560
17670
  key: "readUncompressed",
17561
17671
  value: (function () {
17562
17672
  var _readUncompressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(tagInfo) {
17563
- var _listener$information2;
17564
- var length, listener, numberOfFrames, frameLength, _listener$information3, _listener$information4, _listener$information5, _listener$information6, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, frameNumber;
17673
+ var length, listener, wordWidth, numberOfFrames, frameLength, _listener$information, _listener$information2, _listener$information3, _listener$information4, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, allPixelData, offset, frameNumber;
17565
17674
  return _regeneratorRuntime().wrap(function (_context0) {
17566
17675
  while (1) switch (_context0.prev = _context0.next) {
17567
17676
  case 0:
17568
17677
  length = tagInfo.length;
17569
17678
  listener = this.listener;
17570
- numberOfFrames = parseInt(((_listener$information2 = listener.information) === null || _listener$information2 === void 0 ? void 0 : _listener$information2.numberOfFrames) || 1);
17679
+ wordWidth = this.wordWidth(tagInfo);
17680
+ numberOfFrames = this.getNumberOfFrames();
17571
17681
  frameLength = Math.floor(length / numberOfFrames);
17572
17682
  if (!(numberOfFrames > 1)) {
17573
17683
  _context0.next = 4;
17574
17684
  break;
17575
17685
  }
17576
- rows = (_listener$information3 = listener.information) === null || _listener$information3 === void 0 ? void 0 : _listener$information3.rows;
17577
- cols = (_listener$information4 = listener.information) === null || _listener$information4 === void 0 ? void 0 : _listener$information4.columns;
17578
- samplesPerPixel = (_listener$information5 = listener.information) === null || _listener$information5 === void 0 ? void 0 : _listener$information5.samplesPerPixel;
17579
- bitsAllocated = (_listener$information6 = listener.information) === null || _listener$information6 === void 0 ? void 0 : _listener$information6.bitsAllocated;
17686
+ rows = (_listener$information = listener.information) === null || _listener$information === void 0 ? void 0 : _listener$information.rows;
17687
+ cols = (_listener$information2 = listener.information) === null || _listener$information2 === void 0 ? void 0 : _listener$information2.columns;
17688
+ samplesPerPixel = (_listener$information3 = listener.information) === null || _listener$information3 === void 0 ? void 0 : _listener$information3.samplesPerPixel;
17689
+ bitsAllocated = (_listener$information4 = listener.information) === null || _listener$information4 === void 0 ? void 0 : _listener$information4.bitsAllocated;
17580
17690
  bitsPerFrame = rows * cols * samplesPerPixel * bitsAllocated;
17581
17691
  if (!(bitsPerFrame % 8 !== 0)) {
17582
17692
  _context0.next = 3;
@@ -17599,24 +17709,41 @@
17599
17709
  }
17600
17710
  throw new Error("Invalid frame length: ".concat(length, " for ").concat(numberOfFrames, " frames"));
17601
17711
  case 4:
17602
- frameNumber = 0;
17712
+ if (!(this.syntax === EXPLICIT_BIG_ENDIAN && frameLength % wordWidth !== 0)) {
17713
+ _context0.next = 6;
17714
+ break;
17715
+ }
17716
+ _context0.next = 5;
17717
+ return this.stream.ensureAvailable(length);
17603
17718
  case 5:
17719
+ allPixelData = this.stream.readArrayBuffer(length);
17720
+ this.stream.consume();
17721
+ swapBytes(allPixelData, wordWidth);
17722
+ for (offset = 0; offset < length; offset += frameLength) {
17723
+ listener.startObject([]);
17724
+ listener.value(allPixelData.slice(offset, offset + frameLength));
17725
+ listener.pop();
17726
+ }
17727
+ return _context0.abrupt("return");
17728
+ case 6:
17729
+ frameNumber = 0;
17730
+ case 7:
17604
17731
  if (!(frameNumber < numberOfFrames)) {
17605
- _context0.next = 8;
17732
+ _context0.next = 10;
17606
17733
  break;
17607
17734
  }
17608
17735
  readLog.trace("readUncompressed loop", frameNumber, numberOfFrames);
17609
17736
  listener.startObject([]);
17610
- _context0.next = 6;
17611
- return this._emitSplitValues(frameLength);
17612
- case 6:
17737
+ _context0.next = 8;
17738
+ return this._emitSplitValues(frameLength, wordWidth);
17739
+ case 8:
17613
17740
  listener.pop();
17614
17741
  // console.log(stream.getBufferMemoryInfo());
17615
- case 7:
17742
+ case 9:
17616
17743
  frameNumber++;
17617
- _context0.next = 5;
17744
+ _context0.next = 7;
17618
17745
  break;
17619
- case 8:
17746
+ case 10:
17620
17747
  case "end":
17621
17748
  return _context0.stop();
17622
17749
  }
@@ -17645,18 +17772,18 @@
17645
17772
  key: "readUncompressedBitFrame",
17646
17773
  value: (function () {
17647
17774
  var _readUncompressedBitFrame = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(tagInfo) {
17648
- var _listener$information7, _listener$information8, _listener$information9, _listener$information0, _listener$information1;
17775
+ var _listener$information5, _listener$information6, _listener$information7, _listener$information8;
17649
17776
  var length, listener, stream, numberOfFrames, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, bytesPerFrame, totalBits, totalBytes, allPixelData, frameNumber, bitOffset, frameBuffer, frameView, sourceView, bitIndex, globalBitIndex, sourceByteIndex, sourceBitIndex, targetByteIndex, targetBitIndex, sourceByte, bitValue;
17650
17777
  return _regeneratorRuntime().wrap(function (_context1) {
17651
17778
  while (1) switch (_context1.prev = _context1.next) {
17652
17779
  case 0:
17653
17780
  length = tagInfo.length;
17654
17781
  listener = this.listener, stream = this.stream;
17655
- numberOfFrames = parseInt(((_listener$information7 = listener.information) === null || _listener$information7 === void 0 ? void 0 : _listener$information7.numberOfFrames) || 1);
17656
- rows = (_listener$information8 = listener.information) === null || _listener$information8 === void 0 ? void 0 : _listener$information8.rows;
17657
- cols = (_listener$information9 = listener.information) === null || _listener$information9 === void 0 ? void 0 : _listener$information9.columns;
17658
- samplesPerPixel = ((_listener$information0 = listener.information) === null || _listener$information0 === void 0 ? void 0 : _listener$information0.samplesPerPixel) || 1;
17659
- bitsAllocated = (_listener$information1 = listener.information) === null || _listener$information1 === void 0 ? void 0 : _listener$information1.bitsAllocated;
17782
+ numberOfFrames = this.getNumberOfFrames();
17783
+ rows = (_listener$information5 = listener.information) === null || _listener$information5 === void 0 ? void 0 : _listener$information5.rows;
17784
+ cols = (_listener$information6 = listener.information) === null || _listener$information6 === void 0 ? void 0 : _listener$information6.columns;
17785
+ samplesPerPixel = ((_listener$information7 = listener.information) === null || _listener$information7 === void 0 ? void 0 : _listener$information7.samplesPerPixel) || 1;
17786
+ bitsAllocated = (_listener$information8 = listener.information) === null || _listener$information8 === void 0 ? void 0 : _listener$information8.bitsAllocated;
17660
17787
  if (!(!rows || !cols || !bitsAllocated)) {
17661
17788
  _context1.next = 1;
17662
17789
  break;
@@ -17684,6 +17811,10 @@
17684
17811
  case 4:
17685
17812
  allPixelData = stream.readArrayBuffer(totalBytes);
17686
17813
  stream.consume();
17814
+ if (this.syntax === EXPLICIT_BIG_ENDIAN) {
17815
+ // the bits of OW data are packed in big endian words
17816
+ swapBytes(allPixelData, this.wordWidth(tagInfo));
17817
+ }
17687
17818
 
17688
17819
  // Extract each frame, unpacking bits so each frame starts at byte 0
17689
17820
  for (frameNumber = 0; frameNumber < numberOfFrames; frameNumber++) {
@@ -17725,7 +17856,8 @@
17725
17856
  }()
17726
17857
  /**
17727
17858
  * Reads raw binary data in chunks and delivers it to the listener.
17728
- * This method reads data in 64KB chunks to manage memory efficiently.
17859
+ * Reads the value in fragments of `maxFragmentSize` bytes.
17860
+ * OW/OF/OL/OD/OV words come as little endian, as on the other read paths.
17729
17861
  */
17730
17862
  )
17731
17863
  }, {
@@ -17738,7 +17870,7 @@
17738
17870
  case 0:
17739
17871
  length = tagInfo.length;
17740
17872
  _context10.next = 1;
17741
- return this._emitSplitValues(length);
17873
+ return this._emitSplitValues(length, this.wordWidth(tagInfo));
17742
17874
  case 1:
17743
17875
  case "end":
17744
17876
  return _context10.stop();
@@ -17749,7 +17881,13 @@
17749
17881
  return _readRawBinary.apply(this, arguments);
17750
17882
  }
17751
17883
  return readRawBinary;
17752
- }())
17884
+ }() /** Bytes per word of the value field; "ox" (a UN pixel data) is OW. */)
17885
+ }, {
17886
+ key: "wordWidth",
17887
+ value: function wordWidth(tagInfo) {
17888
+ var _ValueRepresentation$;
17889
+ return (_ValueRepresentation$ = ValueRepresentation$1.createByTypeString(tagInfo.vr).wordWidth) !== null && _ValueRepresentation$ !== void 0 ? _ValueRepresentation$ : 1;
17890
+ }
17753
17891
  }, {
17754
17892
  key: "isSequence",
17755
17893
  value: function isSequence(tagInfo) {
@@ -17803,13 +17941,13 @@
17803
17941
  if (elementData) {
17804
17942
  vrType = elementData.vr;
17805
17943
  if (vrType === "xs") {
17806
- var _this$listener;
17944
+ var _this$listener2;
17807
17945
  // The dictionary meta-VR "xs" ("US or SS") resolves via
17808
17946
  // PixelRepresentation (PS3.5), exactly like the sync
17809
17947
  // reader (DicomMessage._readTag). The listener's
17810
17948
  // information filter tracks (0028,0103), which precedes
17811
17949
  // every xs tag in tag order.
17812
- vrType = DicomMessage.resolveXsVrType((_this$listener = this.listener) === null || _this$listener === void 0 || (_this$listener = _this$listener.information) === null || _this$listener === void 0 ? void 0 : _this$listener.pixelRepresentation);
17950
+ vrType = DicomMessage.resolveXsVrType((_this$listener2 = this.listener) === null || _this$listener2 === void 0 || (_this$listener2 = _this$listener2.information) === null || _this$listener2 === void 0 ? void 0 : _this$listener2.pixelRepresentation);
17813
17951
  }
17814
17952
  } else {
17815
17953
  //unknown tag
@@ -17831,10 +17969,10 @@
17831
17969
  if (vrType === "UN" && (_DicomMessage$lookupT = DicomMessage.lookupTag(tagObj)) !== null && _DicomMessage$lookupT !== void 0 && _DicomMessage$lookupT.vr) {
17832
17970
  vrType = DicomMessage.lookupTag(tagObj).vr;
17833
17971
  if (vrType === "xs") {
17834
- var _this$listener2;
17972
+ var _this$listener3;
17835
17973
  // Same PixelRepresentation-driven US/SS resolution for
17836
17974
  // explicit-VR UN elements whose dictionary VR is "xs".
17837
- vrType = DicomMessage.resolveXsVrType((_this$listener2 = this.listener) === null || _this$listener2 === void 0 || (_this$listener2 = _this$listener2.information) === null || _this$listener2 === void 0 ? void 0 : _this$listener2.pixelRepresentation);
17975
+ vrType = DicomMessage.resolveXsVrType((_this$listener3 = this.listener) === null || _this$listener3 === void 0 || (_this$listener3 = _this$listener3.information) === null || _this$listener3 === void 0 ? void 0 : _this$listener3.pixelRepresentation);
17838
17976
  }
17839
17977
  vr = ValueRepresentation$1.parseUnknownVr(vrType);
17840
17978
  } else {