@dcmjs-org/dcmjs 1.0.0-beta.20 → 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.
@@ -1610,7 +1610,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
1610
1610
  this.isLittleEndian = options === null || options === void 0 ? void 0 : options.isLittleEndian;
1611
1611
  // Number of sequence items being read, 0 at the top level
1612
1612
  this.sequenceDepth = 0;
1613
- // Default maxFragmentSize is 128 MB (128 * 1024 * 1024 bytes)
1613
+ // Default maxFragmentSize is 128 MB; a Big Endian fragment is at least one word, so it can be larger
1614
1614
  this.maxFragmentSize = (_options$maxFragmentS = options === null || options === void 0 ? void 0 : options.maxFragmentSize) !== null && _options$maxFragmentS !== void 0 ? _options$maxFragmentS : 128 * 1024 * 1024;
1615
1615
  this.stream = new core.ReadBufferStream(null, _objectSpread2(_objectSpread2({
1616
1616
  clearBuffers: true
@@ -2189,16 +2189,28 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2189
2189
  /**
2190
2190
  * Emits one or more listener.value() calls for a fragment, splitting if needed.
2191
2191
  * This does NOT start/pop any array contexts; callers control the surrounding structure.
2192
+ * In Explicit VR Big Endian, each fragment holds whole words of wordWidth
2193
+ * bytes, swapped to little endian.
2192
2194
  */
2193
2195
  }, {
2194
2196
  key: "_emitSplitValues",
2195
2197
  value: (function () {
2196
2198
  var _emitSplitValues2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(length) {
2197
2199
  var _listener$awaitDrain;
2198
- var stream, listener, maxFragmentSize, offset, chunkSize, buffer;
2200
+ var wordWidth,
2201
+ stream,
2202
+ listener,
2203
+ maxFragmentSize,
2204
+ swap,
2205
+ fragmentSize,
2206
+ offset,
2207
+ chunkSize,
2208
+ buffer,
2209
+ _args7 = arguments;
2199
2210
  return _regeneratorRuntime().wrap(function (_context7) {
2200
2211
  while (1) switch (_context7.prev = _context7.next) {
2201
2212
  case 0:
2213
+ wordWidth = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : 1;
2202
2214
  stream = this.stream, listener = this.listener;
2203
2215
  _context7.next = 1;
2204
2216
  return (_listener$awaitDrain = listener.awaitDrain) === null || _listener$awaitDrain === void 0 ? void 0 : _listener$awaitDrain.call(listener);
@@ -2210,6 +2222,8 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2210
2222
  }
2211
2223
  throw new Error("maxFragmentSize must be a positive number, got ".concat(maxFragmentSize));
2212
2224
  case 2:
2225
+ swap = this.syntax === core.EXPLICIT_BIG_ENDIAN && wordWidth > 1;
2226
+ fragmentSize = swap ? Math.max(wordWidth, maxFragmentSize - maxFragmentSize % wordWidth) : maxFragmentSize;
2213
2227
  offset = 0;
2214
2228
  case 3:
2215
2229
  if (!(offset < length)) {
@@ -2217,11 +2231,14 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2217
2231
  break;
2218
2232
  }
2219
2233
  readLog.trace("_emitSplitValues loop", offset, length);
2220
- chunkSize = Math.min(maxFragmentSize, length - offset);
2234
+ chunkSize = Math.min(fragmentSize, length - offset);
2221
2235
  _context7.next = 4;
2222
2236
  return stream.ensureAvailable(chunkSize);
2223
2237
  case 4:
2224
2238
  buffer = stream.readArrayBuffer(chunkSize);
2239
+ if (swap) {
2240
+ core.swapBytes(buffer, wordWidth);
2241
+ }
2225
2242
  listener.value(buffer);
2226
2243
  offset += chunkSize;
2227
2244
  stream.consume();
@@ -2371,12 +2388,13 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2371
2388
  key: "readUncompressed",
2372
2389
  value: (function () {
2373
2390
  var _readUncompressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(tagInfo) {
2374
- var length, listener, numberOfFrames, frameLength, _listener$information, _listener$information2, _listener$information3, _listener$information4, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, frameNumber;
2391
+ var length, listener, wordWidth, numberOfFrames, frameLength, _listener$information, _listener$information2, _listener$information3, _listener$information4, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, allPixelData, offset, frameNumber;
2375
2392
  return _regeneratorRuntime().wrap(function (_context0) {
2376
2393
  while (1) switch (_context0.prev = _context0.next) {
2377
2394
  case 0:
2378
2395
  length = tagInfo.length;
2379
2396
  listener = this.listener;
2397
+ wordWidth = this.wordWidth(tagInfo);
2380
2398
  numberOfFrames = this.getNumberOfFrames();
2381
2399
  frameLength = Math.floor(length / numberOfFrames);
2382
2400
  if (!(numberOfFrames > 1)) {
@@ -2409,24 +2427,41 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2409
2427
  }
2410
2428
  throw new Error("Invalid frame length: ".concat(length, " for ").concat(numberOfFrames, " frames"));
2411
2429
  case 4:
2412
- frameNumber = 0;
2430
+ if (!(this.syntax === core.EXPLICIT_BIG_ENDIAN && frameLength % wordWidth !== 0)) {
2431
+ _context0.next = 6;
2432
+ break;
2433
+ }
2434
+ _context0.next = 5;
2435
+ return this.stream.ensureAvailable(length);
2413
2436
  case 5:
2437
+ allPixelData = this.stream.readArrayBuffer(length);
2438
+ this.stream.consume();
2439
+ core.swapBytes(allPixelData, wordWidth);
2440
+ for (offset = 0; offset < length; offset += frameLength) {
2441
+ listener.startObject([]);
2442
+ listener.value(allPixelData.slice(offset, offset + frameLength));
2443
+ listener.pop();
2444
+ }
2445
+ return _context0.abrupt("return");
2446
+ case 6:
2447
+ frameNumber = 0;
2448
+ case 7:
2414
2449
  if (!(frameNumber < numberOfFrames)) {
2415
- _context0.next = 8;
2450
+ _context0.next = 10;
2416
2451
  break;
2417
2452
  }
2418
2453
  readLog.trace("readUncompressed loop", frameNumber, numberOfFrames);
2419
2454
  listener.startObject([]);
2420
- _context0.next = 6;
2421
- return this._emitSplitValues(frameLength);
2422
- case 6:
2455
+ _context0.next = 8;
2456
+ return this._emitSplitValues(frameLength, wordWidth);
2457
+ case 8:
2423
2458
  listener.pop();
2424
2459
  // console.log(stream.getBufferMemoryInfo());
2425
- case 7:
2460
+ case 9:
2426
2461
  frameNumber++;
2427
- _context0.next = 5;
2462
+ _context0.next = 7;
2428
2463
  break;
2429
- case 8:
2464
+ case 10:
2430
2465
  case "end":
2431
2466
  return _context0.stop();
2432
2467
  }
@@ -2494,6 +2529,10 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2494
2529
  case 4:
2495
2530
  allPixelData = stream.readArrayBuffer(totalBytes);
2496
2531
  stream.consume();
2532
+ if (this.syntax === core.EXPLICIT_BIG_ENDIAN) {
2533
+ // the bits of OW data are packed in big endian words
2534
+ core.swapBytes(allPixelData, this.wordWidth(tagInfo));
2535
+ }
2497
2536
 
2498
2537
  // Extract each frame, unpacking bits so each frame starts at byte 0
2499
2538
  for (frameNumber = 0; frameNumber < numberOfFrames; frameNumber++) {
@@ -2535,7 +2574,8 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2535
2574
  }()
2536
2575
  /**
2537
2576
  * Reads raw binary data in chunks and delivers it to the listener.
2538
- * This method reads data in 64KB chunks to manage memory efficiently.
2577
+ * Reads the value in fragments of `maxFragmentSize` bytes.
2578
+ * OW/OF/OL/OD/OV words come as little endian, as on the other read paths.
2539
2579
  */
2540
2580
  )
2541
2581
  }, {
@@ -2548,7 +2588,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2548
2588
  case 0:
2549
2589
  length = tagInfo.length;
2550
2590
  _context10.next = 1;
2551
- return this._emitSplitValues(length);
2591
+ return this._emitSplitValues(length, this.wordWidth(tagInfo));
2552
2592
  case 1:
2553
2593
  case "end":
2554
2594
  return _context10.stop();
@@ -2559,7 +2599,13 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2559
2599
  return _readRawBinary.apply(this, arguments);
2560
2600
  }
2561
2601
  return readRawBinary;
2562
- }())
2602
+ }() /** Bytes per word of the value field; "ox" (a UN pixel data) is OW. */)
2603
+ }, {
2604
+ key: "wordWidth",
2605
+ value: function wordWidth(tagInfo) {
2606
+ var _ValueRepresentation$;
2607
+ return (_ValueRepresentation$ = core.ValueRepresentation.createByTypeString(tagInfo.vr).wordWidth) !== null && _ValueRepresentation$ !== void 0 ? _ValueRepresentation$ : 1;
2608
+ }
2563
2609
  }, {
2564
2610
  key: "isSequence",
2565
2611
  value: function isSequence(tagInfo) {
@@ -16021,4 +16067,4 @@ exports.derivations = derivations;
16021
16067
  exports.normalizers = normalizers;
16022
16068
  exports.sr = sr;
16023
16069
  exports.utilities = utilities;
16024
- //# sourceMappingURL=dcmjs.shared-Cmkm67T1.cjs.map
16070
+ //# sourceMappingURL=dcmjs.shared-C_SwQ4fu.cjs.map