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

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.
@@ -1606,6 +1606,8 @@ var AsyncDicomReader = /*#__PURE__*/function () {
1606
1606
  _classCallCheck(this, AsyncDicomReader);
1607
1607
  _defineProperty(this, "syntax", EXPLICIT_LITTLE_ENDIAN);
1608
1608
  this.isLittleEndian = options === null || options === void 0 ? void 0 : options.isLittleEndian;
1609
+ // Number of sequence items being read, 0 at the top level
1610
+ this.sequenceDepth = 0;
1609
1611
  // Default maxFragmentSize is 128 MB (128 * 1024 * 1024 bytes)
1610
1612
  this.maxFragmentSize = (_options$maxFragmentS = options === null || options === void 0 ? void 0 : options.maxFragmentSize) !== null && _options$maxFragmentS !== void 0 ? _options$maxFragmentS : 128 * 1024 * 1024;
1611
1613
  this.stream = new ReadBufferStream(null, _objectSpread2(_objectSpread2({
@@ -2067,16 +2069,24 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2067
2069
  * item boundary and returns control here for the next item. Without that
2068
2070
  * offset, read() skips the later Item tags as instructions, and all items
2069
2071
  * of a defined-length sequence merge into the first item.
2072
+ *
2073
+ * untilTag and includeUntilTagValue apply to the top-level data set only,
2074
+ * so the items are read without them: an Icon Image Sequence item has its
2075
+ * own Pixel Data, which must not stop a read with untilTag 7FE00010.
2070
2076
  */
2071
2077
  }, {
2072
2078
  key: "readSequence",
2073
2079
  value: (function () {
2074
2080
  var _readSequence = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(listener, sqTagInfo, options) {
2075
2081
  var _ref, _sqTagInfo$sequenceRe;
2076
- var length, stream, readSyntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, decoder, _t;
2082
+ var itemOptions, length, stream, readSyntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, decoder, _t;
2077
2083
  return _regeneratorRuntime().wrap(function (_context6) {
2078
2084
  while (1) switch (_context6.prev = _context6.next) {
2079
2085
  case 0:
2086
+ itemOptions = _objectSpread2(_objectSpread2({}, options), {}, {
2087
+ untilTag: null,
2088
+ includeUntilTagValue: false
2089
+ });
2080
2090
  length = sqTagInfo.length;
2081
2091
  stream = this.stream;
2082
2092
  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;
@@ -2093,16 +2103,16 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2093
2103
  _t = _context6.sent;
2094
2104
  case 3:
2095
2105
  if (!_t) {
2096
- _context6.next = 8;
2106
+ _context6.next = 10;
2097
2107
  break;
2098
2108
  }
2099
2109
  readLog.debug("readSequence loop", stream.offset, endOffset);
2100
- tagInfo = this.readTagHeader(_objectSpread2(_objectSpread2({}, options), {}, {
2110
+ tagInfo = this.readTagHeader(_objectSpread2(_objectSpread2({}, itemOptions), {}, {
2101
2111
  readSyntax: readSyntax
2102
2112
  }));
2103
2113
  tag = tagInfo.tag;
2104
2114
  if (!(tag === TagHex.Item)) {
2105
- _context6.next = 5;
2115
+ _context6.next = 7;
2106
2116
  break;
2107
2117
  }
2108
2118
  listener.startObject();
@@ -2112,38 +2122,59 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2112
2122
  // item (PS3.5 7.5.3), but the item is read on this stream:
2113
2123
  // put back the decoder the item started with.
2114
2124
  decoder = stream.decoder;
2115
- _context6.next = 4;
2116
- return this.read(listener, _objectSpread2(_objectSpread2({}, options), {}, {
2125
+ this.sequenceDepth++;
2126
+ _context6.prev = 4;
2127
+ _context6.next = 5;
2128
+ return this.read(listener, _objectSpread2(_objectSpread2({}, itemOptions), {}, {
2117
2129
  untilOffset: itemUntilOffset,
2118
2130
  readSyntax: readSyntax
2119
2131
  }));
2120
- case 4:
2132
+ case 5:
2133
+ _context6.prev = 5;
2134
+ this.sequenceDepth--;
2135
+ return _context6.finish(5);
2136
+ case 6:
2121
2137
  stream.setDecoder(decoder);
2122
- _context6.next = 7;
2138
+ _context6.next = 9;
2123
2139
  break;
2124
- case 5:
2140
+ case 7:
2125
2141
  if (!(tag === TagHex.SequenceDelimitationEnd)) {
2126
- _context6.next = 6;
2142
+ _context6.next = 8;
2127
2143
  break;
2128
2144
  }
2129
2145
  return _context6.abrupt("return");
2130
- case 6:
2146
+ case 8:
2131
2147
  console.warn("Unknown tag info", length, tagInfo);
2132
- throw new Error();
2133
- case 7:
2148
+ throw new Error("Expected an item or a sequence delimitation item in a sequence, found tag ".concat(tag));
2149
+ case 9:
2134
2150
  _context6.next = 1;
2135
2151
  break;
2136
- case 8:
2152
+ case 10:
2137
2153
  case "end":
2138
2154
  return _context6.stop();
2139
2155
  }
2140
- }, _callee6, this);
2156
+ }, _callee6, this, [[4,, 5, 6]]);
2141
2157
  }));
2142
2158
  function readSequence(_x3, _x4, _x5) {
2143
2159
  return _readSequence.apply(this, arguments);
2144
2160
  }
2145
2161
  return readSequence;
2146
- }())
2162
+ }()
2163
+ /**
2164
+ * The number of frames of the Pixel Data being read. NumberOfFrames is
2165
+ * tracked for the top-level data set only, so Pixel Data inside a sequence
2166
+ * item (an Icon Image Sequence item, for example) is a single frame.
2167
+ */
2168
+ )
2169
+ }, {
2170
+ key: "getNumberOfFrames",
2171
+ value: function getNumberOfFrames() {
2172
+ var _this$listener;
2173
+ if (this.sequenceDepth > 0) {
2174
+ return 1;
2175
+ }
2176
+ 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);
2177
+ }
2147
2178
  }, {
2148
2179
  key: "readPixelData",
2149
2180
  value: function readPixelData(tagInfo) {
@@ -2213,8 +2244,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2213
2244
  key: "readCompressed",
2214
2245
  value: (function () {
2215
2246
  var _readCompressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_tagInfo) {
2216
- var _listener$information;
2217
- var stream, listener, transferSyntaxUid, isVideo, numberOfFrames, isSingleFrame, offsets, singleArray, startOffset, frameNumber, lastFrame, frameTag, length;
2247
+ var stream, listener, transferSyntaxUid, isVideo, isSingleFrame, offsets, singleArray, startOffset, frameNumber, lastFrame, frameTag, length;
2218
2248
  return _regeneratorRuntime().wrap(function (_context8) {
2219
2249
  while (1) switch (_context8.prev = _context8.next) {
2220
2250
  case 0:
@@ -2225,8 +2255,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2225
2255
  case 1:
2226
2256
  // Check if this is a video transfer syntax
2227
2257
  isVideo = isVideoTransferSyntax(transferSyntaxUid); // Check number of frames - only use video logic for single frame (or undefined)
2228
- numberOfFrames = (_listener$information = listener.information) === null || _listener$information === void 0 ? void 0 : _listener$information.numberOfFrames;
2229
- isSingleFrame = !numberOfFrames || parseInt(numberOfFrames) <= 1;
2258
+ isSingleFrame = this.getNumberOfFrames() <= 1;
2230
2259
  _context8.next = 2;
2231
2260
  return this.readOffsets();
2232
2261
  case 2:
@@ -2340,23 +2369,22 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2340
2369
  key: "readUncompressed",
2341
2370
  value: (function () {
2342
2371
  var _readUncompressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(tagInfo) {
2343
- var _listener$information2;
2344
- var length, listener, numberOfFrames, frameLength, _listener$information3, _listener$information4, _listener$information5, _listener$information6, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, frameNumber;
2372
+ var length, listener, numberOfFrames, frameLength, _listener$information, _listener$information2, _listener$information3, _listener$information4, rows, cols, samplesPerPixel, bitsAllocated, bitsPerFrame, frameNumber;
2345
2373
  return _regeneratorRuntime().wrap(function (_context0) {
2346
2374
  while (1) switch (_context0.prev = _context0.next) {
2347
2375
  case 0:
2348
2376
  length = tagInfo.length;
2349
2377
  listener = this.listener;
2350
- numberOfFrames = parseInt(((_listener$information2 = listener.information) === null || _listener$information2 === void 0 ? void 0 : _listener$information2.numberOfFrames) || 1);
2378
+ numberOfFrames = this.getNumberOfFrames();
2351
2379
  frameLength = Math.floor(length / numberOfFrames);
2352
2380
  if (!(numberOfFrames > 1)) {
2353
2381
  _context0.next = 4;
2354
2382
  break;
2355
2383
  }
2356
- rows = (_listener$information3 = listener.information) === null || _listener$information3 === void 0 ? void 0 : _listener$information3.rows;
2357
- cols = (_listener$information4 = listener.information) === null || _listener$information4 === void 0 ? void 0 : _listener$information4.columns;
2358
- samplesPerPixel = (_listener$information5 = listener.information) === null || _listener$information5 === void 0 ? void 0 : _listener$information5.samplesPerPixel;
2359
- bitsAllocated = (_listener$information6 = listener.information) === null || _listener$information6 === void 0 ? void 0 : _listener$information6.bitsAllocated;
2384
+ rows = (_listener$information = listener.information) === null || _listener$information === void 0 ? void 0 : _listener$information.rows;
2385
+ cols = (_listener$information2 = listener.information) === null || _listener$information2 === void 0 ? void 0 : _listener$information2.columns;
2386
+ samplesPerPixel = (_listener$information3 = listener.information) === null || _listener$information3 === void 0 ? void 0 : _listener$information3.samplesPerPixel;
2387
+ bitsAllocated = (_listener$information4 = listener.information) === null || _listener$information4 === void 0 ? void 0 : _listener$information4.bitsAllocated;
2360
2388
  bitsPerFrame = rows * cols * samplesPerPixel * bitsAllocated;
2361
2389
  if (!(bitsPerFrame % 8 !== 0)) {
2362
2390
  _context0.next = 3;
@@ -2425,18 +2453,18 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2425
2453
  key: "readUncompressedBitFrame",
2426
2454
  value: (function () {
2427
2455
  var _readUncompressedBitFrame = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(tagInfo) {
2428
- var _listener$information7, _listener$information8, _listener$information9, _listener$information0, _listener$information1;
2456
+ var _listener$information5, _listener$information6, _listener$information7, _listener$information8;
2429
2457
  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;
2430
2458
  return _regeneratorRuntime().wrap(function (_context1) {
2431
2459
  while (1) switch (_context1.prev = _context1.next) {
2432
2460
  case 0:
2433
2461
  length = tagInfo.length;
2434
2462
  listener = this.listener, stream = this.stream;
2435
- numberOfFrames = parseInt(((_listener$information7 = listener.information) === null || _listener$information7 === void 0 ? void 0 : _listener$information7.numberOfFrames) || 1);
2436
- rows = (_listener$information8 = listener.information) === null || _listener$information8 === void 0 ? void 0 : _listener$information8.rows;
2437
- cols = (_listener$information9 = listener.information) === null || _listener$information9 === void 0 ? void 0 : _listener$information9.columns;
2438
- samplesPerPixel = ((_listener$information0 = listener.information) === null || _listener$information0 === void 0 ? void 0 : _listener$information0.samplesPerPixel) || 1;
2439
- bitsAllocated = (_listener$information1 = listener.information) === null || _listener$information1 === void 0 ? void 0 : _listener$information1.bitsAllocated;
2463
+ numberOfFrames = this.getNumberOfFrames();
2464
+ rows = (_listener$information5 = listener.information) === null || _listener$information5 === void 0 ? void 0 : _listener$information5.rows;
2465
+ cols = (_listener$information6 = listener.information) === null || _listener$information6 === void 0 ? void 0 : _listener$information6.columns;
2466
+ samplesPerPixel = ((_listener$information7 = listener.information) === null || _listener$information7 === void 0 ? void 0 : _listener$information7.samplesPerPixel) || 1;
2467
+ bitsAllocated = (_listener$information8 = listener.information) === null || _listener$information8 === void 0 ? void 0 : _listener$information8.bitsAllocated;
2440
2468
  if (!(!rows || !cols || !bitsAllocated)) {
2441
2469
  _context1.next = 1;
2442
2470
  break;
@@ -2583,13 +2611,13 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2583
2611
  if (elementData) {
2584
2612
  vrType = elementData.vr;
2585
2613
  if (vrType === "xs") {
2586
- var _this$listener;
2614
+ var _this$listener2;
2587
2615
  // The dictionary meta-VR "xs" ("US or SS") resolves via
2588
2616
  // PixelRepresentation (PS3.5), exactly like the sync
2589
2617
  // reader (DicomMessage._readTag). The listener's
2590
2618
  // information filter tracks (0028,0103), which precedes
2591
2619
  // every xs tag in tag order.
2592
- 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);
2620
+ 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);
2593
2621
  }
2594
2622
  } else {
2595
2623
  //unknown tag
@@ -2611,10 +2639,10 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2611
2639
  if (vrType === "UN" && (_DicomMessage$lookupT = DicomMessage.lookupTag(tagObj)) !== null && _DicomMessage$lookupT !== void 0 && _DicomMessage$lookupT.vr) {
2612
2640
  vrType = DicomMessage.lookupTag(tagObj).vr;
2613
2641
  if (vrType === "xs") {
2614
- var _this$listener2;
2642
+ var _this$listener3;
2615
2643
  // Same PixelRepresentation-driven US/SS resolution for
2616
2644
  // explicit-VR UN elements whose dictionary VR is "xs".
2617
- 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);
2645
+ 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);
2618
2646
  }
2619
2647
  vr = ValueRepresentation$1.parseUnknownVr(vrType);
2620
2648
  } else {
@@ -15971,4 +15999,4 @@ ValueRepresentation.setTagClass(Tag);
15971
15999
  // entries (src/eventStream.js, ...): the default entry is the 0.52 surface.
15972
16000
 
15973
16001
  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 };
15974
- //# sourceMappingURL=dcmjs.shared-DnjtTwFB.js.map
16002
+ //# sourceMappingURL=dcmjs.shared-RH-AbhO5.js.map