dcmjs 0.52.3 → 0.53.1
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 +258 -7
- package/build/dcmjs.es.js.map +1 -1
- package/build/dcmjs.js +258 -7
- package/build/dcmjs.js.map +1 -1
- package/build/dcmjs.min.js +1 -1
- package/build/dcmjs.min.js.map +1 -1
- package/package.json +2 -2
package/build/dcmjs.es.js
CHANGED
|
@@ -9007,6 +9007,12 @@ var BufferStream = /*#__PURE__*/function () {
|
|
|
9007
9007
|
var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : start + 1;
|
|
9008
9008
|
return this.view.hasData(start, end);
|
|
9009
9009
|
}
|
|
9010
|
+
|
|
9011
|
+
/**
|
|
9012
|
+
* Returns a read stream over the next `length` bytes and moves past them.
|
|
9013
|
+
* The new stream decodes text with this stream's decoder, so sequence items
|
|
9014
|
+
* use the dataset's SpecificCharacterSet.
|
|
9015
|
+
*/
|
|
9010
9016
|
}, {
|
|
9011
9017
|
key: "more",
|
|
9012
9018
|
value: function more(length) {
|
|
@@ -9020,7 +9026,9 @@ var BufferStream = /*#__PURE__*/function () {
|
|
|
9020
9026
|
// start: this.offset,
|
|
9021
9027
|
// stop: this.offset + length
|
|
9022
9028
|
// });
|
|
9023
|
-
var newBuf = new ReadBufferStream(this.slice(this.offset, this.offset + length)
|
|
9029
|
+
var newBuf = new ReadBufferStream(this.slice(this.offset, this.offset + length), null, {
|
|
9030
|
+
decoder: this.decoder
|
|
9031
|
+
});
|
|
9024
9032
|
this.increment(length);
|
|
9025
9033
|
newBuf.setComplete();
|
|
9026
9034
|
return newBuf;
|
|
@@ -9071,7 +9079,8 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream2) {
|
|
|
9071
9079
|
littleEndian: littleEndian
|
|
9072
9080
|
})]);
|
|
9073
9081
|
_this2.noCopy = options.noCopy;
|
|
9074
|
-
|
|
9082
|
+
// A stream over part of a dataset gets the dataset's decoder in options
|
|
9083
|
+
_this2.decoder = options.decoder || new TextDecoder("latin1");
|
|
9075
9084
|
if (buffer instanceof BufferStream) {
|
|
9076
9085
|
_this2.view.from(buffer.view, options);
|
|
9077
9086
|
_this2.isComplete = true;
|
|
@@ -11197,7 +11206,9 @@ var ParsedUnknownValue = /*#__PURE__*/function (_BinaryRepresentation2) {
|
|
|
11197
11206
|
key: "read",
|
|
11198
11207
|
value: function read(stream, length, syntax, readOptions) {
|
|
11199
11208
|
var arrayBuffer = this.readBytes(stream, length, syntax)[0];
|
|
11200
|
-
var streamFromBuffer = new ReadBufferStream(arrayBuffer, true
|
|
11209
|
+
var streamFromBuffer = new ReadBufferStream(arrayBuffer, true, {
|
|
11210
|
+
decoder: stream.decoder
|
|
11211
|
+
});
|
|
11201
11212
|
var vr = ValueRepresentation.createByTypeString(this.type);
|
|
11202
11213
|
if (vr.isBinary() && length > vr.maxLength && !vr.noMultiple) {
|
|
11203
11214
|
var values = [];
|
|
@@ -11324,6 +11335,208 @@ var VRinstances = {
|
|
|
11324
11335
|
UV: new Unsigned64BitVeryLong()
|
|
11325
11336
|
};
|
|
11326
11337
|
|
|
11338
|
+
/**
|
|
11339
|
+
* Private block reservation, per PS3.5 Section 7.8.1.
|
|
11340
|
+
*
|
|
11341
|
+
* A private group is odd. Within it, a Private Creator Data Element at
|
|
11342
|
+
* (gggg,00xx) - where xx is 0x10 through 0xFF - identifies an implementer and
|
|
11343
|
+
* reserves the block of Data Elements (gggg,xx00) through (gggg,xxFF) for them.
|
|
11344
|
+
*
|
|
11345
|
+
* Which block a creator gets is decided by whoever wrote the file, so the
|
|
11346
|
+
* creator string is the identity and the block has to be looked up. A block
|
|
11347
|
+
* is named as in the 1.0 naturalized form: the block key "gggg:creator"
|
|
11348
|
+
* (for example "4D43:ACME 1.0"), or the pair (group, creator); an element of
|
|
11349
|
+
* the block is its number 0x00-0xFF, or the element key "xEE" (for example
|
|
11350
|
+
* "x01"):
|
|
11351
|
+
*
|
|
11352
|
+
* // writing
|
|
11353
|
+
* const block = dicomDict.privateBlock("4D43:ACME 1.0");
|
|
11354
|
+
* block.set("x01", "CS", ["HYBRID"]); // -> (4D43,1001), or wherever it landed
|
|
11355
|
+
*
|
|
11356
|
+
* // reading, from any parsed dict
|
|
11357
|
+
* const found = findPrivateBlock(dict, "4D43:ACME 1.0");
|
|
11358
|
+
* found && found.get("x01").Value;
|
|
11359
|
+
*/
|
|
11360
|
+
|
|
11361
|
+
var CREATOR_MIN = 0x10;
|
|
11362
|
+
var CREATOR_MAX = 0xff;
|
|
11363
|
+
var CREATOR_MAX_LENGTH = 64; // LO
|
|
11364
|
+
var BLOCK_KEY = /^([0-9A-Fa-f]{4}):([^]+)$/;
|
|
11365
|
+
var ELEMENT_KEY = /^x([0-9A-Fa-f]{2})$/;
|
|
11366
|
+
var hex2 = function hex2(n) {
|
|
11367
|
+
return n.toString(16).toUpperCase().padStart(2, "0");
|
|
11368
|
+
};
|
|
11369
|
+
var hex4 = function hex4(n) {
|
|
11370
|
+
return n.toString(16).toUpperCase().padStart(4, "0");
|
|
11371
|
+
};
|
|
11372
|
+
|
|
11373
|
+
/**
|
|
11374
|
+
* The block key "gggg:creator" of a group and creator. A line break in the
|
|
11375
|
+
* creator is written as the text `\n` (and `\r`); LO holds no backslash, so
|
|
11376
|
+
* the key reads back to the same creator.
|
|
11377
|
+
*/
|
|
11378
|
+
function privateBlockKey(group, creator) {
|
|
11379
|
+
var text = creator.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
11380
|
+
return "".concat(hex4(group), ":").concat(text);
|
|
11381
|
+
}
|
|
11382
|
+
|
|
11383
|
+
/** The creator of the creator part of a block key: `\n` and `\r` unescaped. */
|
|
11384
|
+
function keyCreator(text) {
|
|
11385
|
+
return text.replace(/\\r/g, "\r").replace(/\\n/g, "\n");
|
|
11386
|
+
}
|
|
11387
|
+
|
|
11388
|
+
/**
|
|
11389
|
+
* The creator text of a creator element value: no leading spaces, no
|
|
11390
|
+
* trailing spaces or NULs. A value in bytes (UN) is read as Latin-1.
|
|
11391
|
+
*/
|
|
11392
|
+
function creatorText(value) {
|
|
11393
|
+
var v = Array.isArray(value) ? value[0] : value;
|
|
11394
|
+
if (typeof v === "string") return v.replace(/^ +|[\0 ]+$/g, "");
|
|
11395
|
+
if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) {
|
|
11396
|
+
var bytes = ArrayBuffer.isView(v) ? new Uint8Array(v.buffer, v.byteOffset, v.byteLength) : new Uint8Array(v);
|
|
11397
|
+
return creatorText(String.fromCharCode.apply(String, _toConsumableArray(bytes.subarray(0, 64))));
|
|
11398
|
+
}
|
|
11399
|
+
return "";
|
|
11400
|
+
}
|
|
11401
|
+
|
|
11402
|
+
/** [group, creator] from (groupOrKey, creator), validated. */
|
|
11403
|
+
function blockArgs(groupOrKey, creator) {
|
|
11404
|
+
var group = groupOrKey;
|
|
11405
|
+
if (typeof groupOrKey === "string") {
|
|
11406
|
+
var match = BLOCK_KEY.exec(groupOrKey);
|
|
11407
|
+
if (!match) {
|
|
11408
|
+
throw new Error("Private block key must be \"gggg:creator\", got ".concat(groupOrKey));
|
|
11409
|
+
}
|
|
11410
|
+
group = parseInt(match[1], 16);
|
|
11411
|
+
creator = keyCreator(match[2]);
|
|
11412
|
+
}
|
|
11413
|
+
if (!Number.isInteger(group) || group < 0 || group > 0xffff) {
|
|
11414
|
+
throw new Error("Private group must be a 16 bit number, got ".concat(group));
|
|
11415
|
+
}
|
|
11416
|
+
if (group % 2 === 0) {
|
|
11417
|
+
throw new Error("Private group must be odd, got ".concat(hex4(group), " - an even group is standard, not private"));
|
|
11418
|
+
}
|
|
11419
|
+
if (typeof creator !== "string" || creatorText(creator).length === 0) {
|
|
11420
|
+
throw new Error("Private creator must be a non-empty string");
|
|
11421
|
+
}
|
|
11422
|
+
creator = creatorText(creator);
|
|
11423
|
+
if (creator.length > CREATOR_MAX_LENGTH) {
|
|
11424
|
+
throw new Error("Private creator must be at most ".concat(CREATOR_MAX_LENGTH, " characters (LO), got ").concat(creator.length));
|
|
11425
|
+
}
|
|
11426
|
+
return [group, creator];
|
|
11427
|
+
}
|
|
11428
|
+
|
|
11429
|
+
/** The element number of 0x00-0xFF or "xEE". */
|
|
11430
|
+
function elementNumber(element) {
|
|
11431
|
+
var match = typeof element === "string" && ELEMENT_KEY.exec(element);
|
|
11432
|
+
var n = match ? parseInt(match[1], 16) : element;
|
|
11433
|
+
if (!Number.isInteger(n) || n < 0x00 || n > 0xff) {
|
|
11434
|
+
throw new Error("Private element must be 0x00 to 0xFF or \"xEE\", got ".concat(element));
|
|
11435
|
+
}
|
|
11436
|
+
return n;
|
|
11437
|
+
}
|
|
11438
|
+
|
|
11439
|
+
/**
|
|
11440
|
+
* An accessor for one reserved block of a dict, keyed by 'GGGGEEEE'.
|
|
11441
|
+
* `reservedBlock` is the xx of the block in this dict.
|
|
11442
|
+
*/
|
|
11443
|
+
function blockAccessor(dict, group, creator, reservedBlock) {
|
|
11444
|
+
var tag = function tag(element) {
|
|
11445
|
+
return hex4(group) + hex2(reservedBlock) + hex2(elementNumber(element));
|
|
11446
|
+
};
|
|
11447
|
+
return {
|
|
11448
|
+
key: privateBlockKey(group, creator),
|
|
11449
|
+
group: group,
|
|
11450
|
+
creator: creator,
|
|
11451
|
+
reservedBlock: reservedBlock,
|
|
11452
|
+
/** The 'GGGGEEEE' key of an element of this block. */
|
|
11453
|
+
tag: tag,
|
|
11454
|
+
/** Whether this block holds that element. */
|
|
11455
|
+
has: function has(element) {
|
|
11456
|
+
return Object.prototype.hasOwnProperty.call(dict, tag(element));
|
|
11457
|
+
},
|
|
11458
|
+
/** The element object, or undefined. */
|
|
11459
|
+
get: function get(element) {
|
|
11460
|
+
return dict[tag(element)];
|
|
11461
|
+
},
|
|
11462
|
+
/**
|
|
11463
|
+
* Writes an element of this block, as DicomDict#upsertTag does.
|
|
11464
|
+
*
|
|
11465
|
+
* @param {number|string} element 0x00 to 0xFF, or "xEE"
|
|
11466
|
+
* @param {string} vr value representation
|
|
11467
|
+
* @param {*} values value, or array of values
|
|
11468
|
+
* @returns {string} the tag that was written
|
|
11469
|
+
*/
|
|
11470
|
+
set: function set(element, vr, values) {
|
|
11471
|
+
var key = tag(element);
|
|
11472
|
+
dict[key] = ValueRepresentation.addTagAccessors({
|
|
11473
|
+
vr: vr
|
|
11474
|
+
});
|
|
11475
|
+
dict[key].Value = Array.isArray(values) ? values : [values];
|
|
11476
|
+
return key;
|
|
11477
|
+
}
|
|
11478
|
+
};
|
|
11479
|
+
}
|
|
11480
|
+
|
|
11481
|
+
/**
|
|
11482
|
+
* Finds the block a creator has reserved in a dict.
|
|
11483
|
+
*
|
|
11484
|
+
* @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
|
|
11485
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11486
|
+
* @param {string} [creator] creator string, with a group number
|
|
11487
|
+
* @returns {object|null} a block accessor, or null when the creator is absent
|
|
11488
|
+
*/
|
|
11489
|
+
function findPrivateBlock(dict, groupOrKey, creator) {
|
|
11490
|
+
var _blockArgs = blockArgs(groupOrKey, creator),
|
|
11491
|
+
_blockArgs2 = _slicedToArray(_blockArgs, 2),
|
|
11492
|
+
group = _blockArgs2[0],
|
|
11493
|
+
wanted = _blockArgs2[1];
|
|
11494
|
+
for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
|
|
11495
|
+
var element = dict[hex4(group) + hex4(xx)];
|
|
11496
|
+
if (element && creatorText(element.Value) === wanted) {
|
|
11497
|
+
return blockAccessor(dict, group, wanted, xx);
|
|
11498
|
+
}
|
|
11499
|
+
}
|
|
11500
|
+
return null;
|
|
11501
|
+
}
|
|
11502
|
+
|
|
11503
|
+
/**
|
|
11504
|
+
* Finds the block a creator has reserved, or reserves the first free block
|
|
11505
|
+
* and writes the creator element. A block is free when the dict holds no
|
|
11506
|
+
* creator element for it and no element in its range.
|
|
11507
|
+
*
|
|
11508
|
+
* @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
|
|
11509
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11510
|
+
* @param {string} [creator] creator string, with a group number
|
|
11511
|
+
* @returns {object} a block accessor
|
|
11512
|
+
*/
|
|
11513
|
+
function reservePrivateBlock(dict, groupOrKey, creator) {
|
|
11514
|
+
var existing = findPrivateBlock(dict, groupOrKey, creator);
|
|
11515
|
+
if (existing) return existing;
|
|
11516
|
+
var _blockArgs3 = blockArgs(groupOrKey, creator),
|
|
11517
|
+
_blockArgs4 = _slicedToArray(_blockArgs3, 2),
|
|
11518
|
+
group = _blockArgs4[0],
|
|
11519
|
+
wanted = _blockArgs4[1];
|
|
11520
|
+
var prefix = hex4(group);
|
|
11521
|
+
var used = new Set();
|
|
11522
|
+
for (var _i = 0, _Object$keys = Object.keys(dict); _i < _Object$keys.length; _i++) {
|
|
11523
|
+
var key = _Object$keys[_i];
|
|
11524
|
+
if (!key.startsWith(prefix) || key.length !== 8) continue;
|
|
11525
|
+
var element = parseInt(key.slice(4), 16);
|
|
11526
|
+
used.add(element <= 0xff ? element : element >> 8);
|
|
11527
|
+
}
|
|
11528
|
+
for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
|
|
11529
|
+
if (!used.has(xx)) {
|
|
11530
|
+
dict[prefix + hex4(xx)] = ValueRepresentation.addTagAccessors({
|
|
11531
|
+
vr: "LO"
|
|
11532
|
+
});
|
|
11533
|
+
dict[prefix + hex4(xx)].Value = [wanted];
|
|
11534
|
+
return blockAccessor(dict, group, wanted, xx);
|
|
11535
|
+
}
|
|
11536
|
+
}
|
|
11537
|
+
throw new Error("No free private block in group ".concat(prefix, " - all of 0x10 to 0xFF are reserved"));
|
|
11538
|
+
}
|
|
11539
|
+
|
|
11327
11540
|
var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
|
|
11328
11541
|
var DicomMessage$2;
|
|
11329
11542
|
var DicomDict = /*#__PURE__*/function () {
|
|
@@ -11345,6 +11558,35 @@ var DicomDict = /*#__PURE__*/function () {
|
|
|
11345
11558
|
this.dict[tag].Value = values;
|
|
11346
11559
|
}
|
|
11347
11560
|
}
|
|
11561
|
+
|
|
11562
|
+
/**
|
|
11563
|
+
* Reserves a private block for a creator, and writes its creator element
|
|
11564
|
+
* when the creator has no block yet; pass `{ create: false }` to only look
|
|
11565
|
+
* it up. See src/privateBlock.js: the block is found by creator, never
|
|
11566
|
+
* assumed.
|
|
11567
|
+
*
|
|
11568
|
+
* dicomDict.privateBlock("4D43:ACME 1.0").set("x01", "CS", ["HYBRID"]);
|
|
11569
|
+
*
|
|
11570
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11571
|
+
* @param {string} [creator] creator string, with a group number
|
|
11572
|
+
* @param {{create?: boolean}} [options] create defaults to true; false
|
|
11573
|
+
* returns null when the creator is absent
|
|
11574
|
+
* @returns {object|null} accessor with key, group, creator, reservedBlock,
|
|
11575
|
+
* tag, has, get and set
|
|
11576
|
+
*/
|
|
11577
|
+
}, {
|
|
11578
|
+
key: "privateBlock",
|
|
11579
|
+
value: function privateBlock(groupOrKey, creator) {
|
|
11580
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11581
|
+
if (typeof groupOrKey === "string" && _typeof(creator) === "object") {
|
|
11582
|
+
options = creator;
|
|
11583
|
+
creator = undefined;
|
|
11584
|
+
}
|
|
11585
|
+
var _ref = options || {},
|
|
11586
|
+
_ref$create = _ref.create,
|
|
11587
|
+
create = _ref$create === void 0 ? true : _ref$create;
|
|
11588
|
+
return create ? reservePrivateBlock(this.dict, groupOrKey, creator) : findPrivateBlock(this.dict, groupOrKey, creator);
|
|
11589
|
+
}
|
|
11348
11590
|
}, {
|
|
11349
11591
|
key: "write",
|
|
11350
11592
|
value: function write() {
|
|
@@ -14359,7 +14601,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
|
|
|
14359
14601
|
break;
|
|
14360
14602
|
}
|
|
14361
14603
|
// Group length
|
|
14362
|
-
stream.increment(
|
|
14604
|
+
stream.increment(length);
|
|
14363
14605
|
return _context5.abrupt("continue", 1);
|
|
14364
14606
|
case 5:
|
|
14365
14607
|
addTagResult = listener.addTag(tag, tagInfo);
|
|
@@ -14425,7 +14667,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
|
|
|
14425
14667
|
key: "readSequence",
|
|
14426
14668
|
value: function () {
|
|
14427
14669
|
var _readSequence = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(listener, sqTagInfo, options) {
|
|
14428
|
-
var length, stream, syntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, _t;
|
|
14670
|
+
var length, stream, syntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, decoder, _t;
|
|
14429
14671
|
return _regeneratorRuntime().wrap(function (_context6) {
|
|
14430
14672
|
while (1) switch (_context6.prev = _context6.next) {
|
|
14431
14673
|
case 0:
|
|
@@ -14462,12 +14704,16 @@ var AsyncDicomReader = /*#__PURE__*/function () {
|
|
|
14462
14704
|
// first item because read() treats subsequent Item tags
|
|
14463
14705
|
// as instructions and skips them.
|
|
14464
14706
|
itemLength = tagInfo.length;
|
|
14465
|
-
itemUntilOffset = itemLength === UNDEFINED_LENGTH_FIX ? endOffset : Math.min(stream.offset + itemLength, endOffset);
|
|
14707
|
+
itemUntilOffset = itemLength === UNDEFINED_LENGTH_FIX ? endOffset : Math.min(stream.offset + itemLength, endOffset); // A SpecificCharacterSet in the item applies only to that
|
|
14708
|
+
// item (PS3.5 7.5.3), but the item is read on this stream:
|
|
14709
|
+
// put back the decoder the item started with.
|
|
14710
|
+
decoder = stream.decoder;
|
|
14466
14711
|
_context6.next = 4;
|
|
14467
14712
|
return this.read(listener, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
14468
14713
|
untilOffset: itemUntilOffset
|
|
14469
14714
|
}));
|
|
14470
14715
|
case 4:
|
|
14716
|
+
stream.setDecoder(decoder);
|
|
14471
14717
|
_context6.next = 7;
|
|
14472
14718
|
break;
|
|
14473
14719
|
case 5:
|
|
@@ -28187,7 +28433,12 @@ var data = {
|
|
|
28187
28433
|
Colors: Colors,
|
|
28188
28434
|
datasetToDict: datasetToDict,
|
|
28189
28435
|
datasetToBuffer: datasetToBuffer,
|
|
28190
|
-
datasetToBlob: datasetToBlob
|
|
28436
|
+
datasetToBlob: datasetToBlob,
|
|
28437
|
+
// Private block reservation, PS3.5 Section 7.8.1. findPrivateBlock() works
|
|
28438
|
+
// on any parsed dict; DicomDict#privateBlock() is the writing side.
|
|
28439
|
+
findPrivateBlock: findPrivateBlock,
|
|
28440
|
+
reservePrivateBlock: reservePrivateBlock,
|
|
28441
|
+
privateBlockKey: privateBlockKey
|
|
28191
28442
|
};
|
|
28192
28443
|
var async = {
|
|
28193
28444
|
AsyncDicomReader: AsyncDicomReader
|