dcmjs 0.24.1 → 0.24.2
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.es.js +94 -47
- package/build/dcmjs.es.js.map +1 -1
- package/build/dcmjs.js +94 -47
- package/build/dcmjs.js.map +1 -1
- package/package.json +1 -1
- package/test/data-options.test.js +237 -0
- package/test/data.test.js +22 -50
- package/test/untilTag.test.js +0 -44
package/build/dcmjs.js
CHANGED
|
@@ -1182,7 +1182,8 @@
|
|
|
1182
1182
|
|
|
1183
1183
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
1184
1184
|
start: null,
|
|
1185
|
-
stop: null
|
|
1185
|
+
stop: null,
|
|
1186
|
+
noCopy: false
|
|
1186
1187
|
};
|
|
1187
1188
|
|
|
1188
1189
|
_classCallCheck(this, ReadBufferStream);
|
|
@@ -1190,12 +1191,27 @@
|
|
|
1190
1191
|
_this = _super.call(this, buffer, littleEndian);
|
|
1191
1192
|
_this.offset = options.start || 0;
|
|
1192
1193
|
_this.size = options.stop || _this.buffer.byteLength;
|
|
1194
|
+
_this.noCopy = options.noCopy;
|
|
1193
1195
|
_this.startOffset = _this.offset;
|
|
1194
1196
|
_this.endOffset = _this.size;
|
|
1195
1197
|
return _this;
|
|
1196
1198
|
}
|
|
1197
1199
|
|
|
1198
1200
|
_createClass(ReadBufferStream, [{
|
|
1201
|
+
key: "getBuffer",
|
|
1202
|
+
value: function getBuffer(start, end) {
|
|
1203
|
+
if (this.noCopy) {
|
|
1204
|
+
return new Uint8Array(this.buffer, start, end - start);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
if (!start && !end) {
|
|
1208
|
+
start = 0;
|
|
1209
|
+
end = this.size;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
return this.buffer.slice(start, end);
|
|
1213
|
+
}
|
|
1214
|
+
}, {
|
|
1199
1215
|
key: "readString",
|
|
1200
1216
|
value: function readString(length) {
|
|
1201
1217
|
var chars = [];
|
|
@@ -1317,25 +1333,10 @@
|
|
|
1317
1333
|
return _createClass(WriteBufferStream);
|
|
1318
1334
|
}(BufferStream);
|
|
1319
1335
|
|
|
1320
|
-
function paddingLeft(paddingValue, string) {
|
|
1321
|
-
return String(paddingValue + string).slice(-paddingValue.length);
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
1336
|
function rtrim(str) {
|
|
1325
1337
|
return str.replace(/\s*$/g, "");
|
|
1326
1338
|
}
|
|
1327
1339
|
|
|
1328
|
-
function tagFromNumbers(group, element) {
|
|
1329
|
-
return new Tag((group << 16 | element) >>> 0);
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
function readTag(stream) {
|
|
1333
|
-
var group = stream.readUint16(),
|
|
1334
|
-
element = stream.readUint16();
|
|
1335
|
-
var tag = tagFromNumbers(group, element);
|
|
1336
|
-
return tag;
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
1340
|
function toWindows(inputArray, size) {
|
|
1340
1341
|
return Array.from({
|
|
1341
1342
|
length: inputArray.length - (size - 1)
|
|
@@ -1722,7 +1723,8 @@
|
|
|
1722
1723
|
|
|
1723
1724
|
var rangeStream = new ReadBufferStream(stream.buffer, stream.isLittleEndian, {
|
|
1724
1725
|
start: start,
|
|
1725
|
-
stop: stop
|
|
1726
|
+
stop: stop,
|
|
1727
|
+
noCopy: stream.noCopy
|
|
1726
1728
|
});
|
|
1727
1729
|
var frameSize = 0;
|
|
1728
1730
|
|
|
@@ -1742,16 +1744,21 @@
|
|
|
1742
1744
|
|
|
1743
1745
|
if (fragments.length === 1) {
|
|
1744
1746
|
return fragments[0];
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
+
}
|
|
1747
1748
|
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1749
|
+
if (rangeStream.noCopy) {
|
|
1750
|
+
// return the fragments for downstream application to process
|
|
1751
|
+
return fragments;
|
|
1752
|
+
} else {
|
|
1753
|
+
// Allocate a final ArrayBuffer and concat all buffers into it
|
|
1754
|
+
var mergedFrame = new ArrayBuffer(frameSize);
|
|
1755
|
+
var u8Data = new Uint8Array(mergedFrame);
|
|
1756
|
+
fragments.reduce(function (offset, buffer) {
|
|
1757
|
+
u8Data.set(new Uint8Array(buffer), offset);
|
|
1758
|
+
return offset + buffer.byteLength;
|
|
1759
|
+
}, 0);
|
|
1760
|
+
return mergedFrame;
|
|
1761
|
+
}
|
|
1755
1762
|
});
|
|
1756
1763
|
} // If no offset table, loop through remainder of stream looking for termination tag
|
|
1757
1764
|
else {
|
|
@@ -1884,9 +1891,7 @@
|
|
|
1884
1891
|
_createClass(AttributeTag, [{
|
|
1885
1892
|
key: "readBytes",
|
|
1886
1893
|
value: function readBytes(stream) {
|
|
1887
|
-
|
|
1888
|
-
element = stream.readUint16();
|
|
1889
|
-
return tagFromNumbers(group, element).value;
|
|
1894
|
+
return Tag.readTag(stream).value;
|
|
1890
1895
|
}
|
|
1891
1896
|
}, {
|
|
1892
1897
|
key: "writeBytes",
|
|
@@ -2323,7 +2328,7 @@
|
|
|
2323
2328
|
/* eslint-disable-next-line no-constant-condition */
|
|
2324
2329
|
|
|
2325
2330
|
while (true) {
|
|
2326
|
-
var tag = readTag(stream),
|
|
2331
|
+
var tag = Tag.readTag(stream),
|
|
2327
2332
|
length = null;
|
|
2328
2333
|
read += 4;
|
|
2329
2334
|
|
|
@@ -2394,7 +2399,9 @@
|
|
|
2394
2399
|
|
|
2395
2400
|
read += toRead;
|
|
2396
2401
|
if (undef) stream.increment(8);
|
|
2397
|
-
|
|
2402
|
+
|
|
2403
|
+
var items = DicomMessage._read(itemStream, syntax);
|
|
2404
|
+
|
|
2398
2405
|
elements.push(items);
|
|
2399
2406
|
}
|
|
2400
2407
|
|
|
@@ -2826,6 +2833,10 @@
|
|
|
2826
2833
|
var IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
|
|
2827
2834
|
var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
|
|
2828
2835
|
|
|
2836
|
+
function paddingLeft(paddingValue, string) {
|
|
2837
|
+
return String(paddingValue + string).slice(-paddingValue.length);
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2829
2840
|
var Tag = /*#__PURE__*/function () {
|
|
2830
2841
|
function Tag(value) {
|
|
2831
2842
|
_classCallCheck(this, Tag);
|
|
@@ -3395,11 +3406,40 @@
|
|
|
3395
3406
|
value: function read(bufferStream, syntax, ignoreErrors) {
|
|
3396
3407
|
var untilTag = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
3397
3408
|
var includeUntilTagValue = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
3409
|
+
console.warn("DicomMessage.read to be deprecated after dcmjs 0.24.x");
|
|
3410
|
+
return this._read(bufferStream, syntax, {
|
|
3411
|
+
ignoreErrors: ignoreErrors,
|
|
3412
|
+
untilTag: untilTag,
|
|
3413
|
+
includeUntilTagValue: includeUntilTagValue
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
}, {
|
|
3417
|
+
key: "readTag",
|
|
3418
|
+
value: function readTag(bufferStream, syntax) {
|
|
3419
|
+
var untilTag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
3420
|
+
var includeUntilTagValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
3421
|
+
console.warn("DicomMessage.readTag to be deprecated after dcmjs 0.24.x");
|
|
3422
|
+
return this._readTag(bufferStream, syntax, {
|
|
3423
|
+
untilTag: untilTag,
|
|
3424
|
+
includeUntilTagValue: includeUntilTagValue
|
|
3425
|
+
});
|
|
3426
|
+
}
|
|
3427
|
+
}, {
|
|
3428
|
+
key: "_read",
|
|
3429
|
+
value: function _read(bufferStream, syntax) {
|
|
3430
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
3431
|
+
ignoreErrors: false,
|
|
3432
|
+
untilTag: null,
|
|
3433
|
+
includeUntilTagValue: false
|
|
3434
|
+
};
|
|
3435
|
+
var ignoreErrors = options.ignoreErrors,
|
|
3436
|
+
untilTag = options.untilTag;
|
|
3398
3437
|
var dict = {};
|
|
3399
3438
|
|
|
3400
3439
|
try {
|
|
3401
3440
|
while (!bufferStream.end()) {
|
|
3402
|
-
var readInfo = DicomMessage.
|
|
3441
|
+
var readInfo = DicomMessage._readTag(bufferStream, syntax, options);
|
|
3442
|
+
|
|
3403
3443
|
var cleanTagString = readInfo.tag.toCleanString();
|
|
3404
3444
|
dict[cleanTagString] = {
|
|
3405
3445
|
vr: readInfo.vr.type,
|
|
@@ -3441,12 +3481,12 @@
|
|
|
3441
3481
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
3442
3482
|
ignoreErrors: false,
|
|
3443
3483
|
untilTag: null,
|
|
3444
|
-
includeUntilTagValue: false
|
|
3484
|
+
includeUntilTagValue: false,
|
|
3485
|
+
noCopy: false
|
|
3445
3486
|
};
|
|
3446
|
-
var
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
var stream = new ReadBufferStream(buffer),
|
|
3487
|
+
var stream = new ReadBufferStream(buffer, null, {
|
|
3488
|
+
noCopy: options.noCopy
|
|
3489
|
+
}),
|
|
3450
3490
|
useSyntax = EXPLICIT_LITTLE_ENDIAN$1;
|
|
3451
3491
|
stream.reset();
|
|
3452
3492
|
stream.increment(128);
|
|
@@ -3455,15 +3495,20 @@
|
|
|
3455
3495
|
throw new Error("Invalid a dicom file");
|
|
3456
3496
|
}
|
|
3457
3497
|
|
|
3458
|
-
var el = DicomMessage.
|
|
3498
|
+
var el = DicomMessage._readTag(stream, useSyntax),
|
|
3459
3499
|
metaLength = el.values[0]; //read header buffer
|
|
3460
3500
|
|
|
3501
|
+
|
|
3461
3502
|
var metaStream = stream.more(metaLength);
|
|
3462
|
-
|
|
3503
|
+
|
|
3504
|
+
var metaHeader = DicomMessage._read(metaStream, useSyntax, options); //get the syntax
|
|
3505
|
+
|
|
3463
3506
|
|
|
3464
3507
|
var mainSyntax = metaHeader["00020010"].Value[0];
|
|
3465
3508
|
mainSyntax = DicomMessage._normalizeSyntax(mainSyntax);
|
|
3466
|
-
|
|
3509
|
+
|
|
3510
|
+
var objects = DicomMessage._read(stream, mainSyntax, options);
|
|
3511
|
+
|
|
3467
3512
|
var dicomDict = new DicomDict(metaHeader);
|
|
3468
3513
|
dicomDict.dict = objects;
|
|
3469
3514
|
return dicomDict;
|
|
@@ -3489,17 +3534,19 @@
|
|
|
3489
3534
|
return written;
|
|
3490
3535
|
}
|
|
3491
3536
|
}, {
|
|
3492
|
-
key: "
|
|
3493
|
-
value: function
|
|
3494
|
-
var
|
|
3495
|
-
|
|
3537
|
+
key: "_readTag",
|
|
3538
|
+
value: function _readTag(stream, syntax) {
|
|
3539
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
3540
|
+
untilTag: null,
|
|
3541
|
+
includeUntilTagValue: false
|
|
3542
|
+
};
|
|
3543
|
+
var untilTag = options.untilTag,
|
|
3544
|
+
includeUntilTagValue = options.includeUntilTagValue;
|
|
3496
3545
|
var implicit = syntax == IMPLICIT_LITTLE_ENDIAN$1 ? true : false,
|
|
3497
3546
|
isLittleEndian = syntax == IMPLICIT_LITTLE_ENDIAN$1 || syntax == EXPLICIT_LITTLE_ENDIAN$1 ? true : false;
|
|
3498
3547
|
var oldEndian = stream.isLittleEndian;
|
|
3499
3548
|
stream.setEndian(isLittleEndian);
|
|
3500
|
-
var
|
|
3501
|
-
element = stream.readUint16(),
|
|
3502
|
-
tag = tagFromNumbers(group, element);
|
|
3549
|
+
var tag = Tag.readTag(stream);
|
|
3503
3550
|
|
|
3504
3551
|
if (untilTag === tag.toCleanString() && untilTag !== null) {
|
|
3505
3552
|
if (!includeUntilTagValue) {
|