dcmjs 0.52.3 → 0.53.0
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 +238 -2
- package/build/dcmjs.es.js.map +1 -1
- package/build/dcmjs.js +238 -2
- 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
|
@@ -11324,6 +11324,208 @@ var VRinstances = {
|
|
|
11324
11324
|
UV: new Unsigned64BitVeryLong()
|
|
11325
11325
|
};
|
|
11326
11326
|
|
|
11327
|
+
/**
|
|
11328
|
+
* Private block reservation, per PS3.5 Section 7.8.1.
|
|
11329
|
+
*
|
|
11330
|
+
* A private group is odd. Within it, a Private Creator Data Element at
|
|
11331
|
+
* (gggg,00xx) - where xx is 0x10 through 0xFF - identifies an implementer and
|
|
11332
|
+
* reserves the block of Data Elements (gggg,xx00) through (gggg,xxFF) for them.
|
|
11333
|
+
*
|
|
11334
|
+
* Which block a creator gets is decided by whoever wrote the file, so the
|
|
11335
|
+
* creator string is the identity and the block has to be looked up. A block
|
|
11336
|
+
* is named as in the 1.0 naturalized form: the block key "gggg:creator"
|
|
11337
|
+
* (for example "4D43:ACME 1.0"), or the pair (group, creator); an element of
|
|
11338
|
+
* the block is its number 0x00-0xFF, or the element key "xEE" (for example
|
|
11339
|
+
* "x01"):
|
|
11340
|
+
*
|
|
11341
|
+
* // writing
|
|
11342
|
+
* const block = dicomDict.privateBlock("4D43:ACME 1.0");
|
|
11343
|
+
* block.set("x01", "CS", ["HYBRID"]); // -> (4D43,1001), or wherever it landed
|
|
11344
|
+
*
|
|
11345
|
+
* // reading, from any parsed dict
|
|
11346
|
+
* const found = findPrivateBlock(dict, "4D43:ACME 1.0");
|
|
11347
|
+
* found && found.get("x01").Value;
|
|
11348
|
+
*/
|
|
11349
|
+
|
|
11350
|
+
var CREATOR_MIN = 0x10;
|
|
11351
|
+
var CREATOR_MAX = 0xff;
|
|
11352
|
+
var CREATOR_MAX_LENGTH = 64; // LO
|
|
11353
|
+
var BLOCK_KEY = /^([0-9A-Fa-f]{4}):([^]+)$/;
|
|
11354
|
+
var ELEMENT_KEY = /^x([0-9A-Fa-f]{2})$/;
|
|
11355
|
+
var hex2 = function hex2(n) {
|
|
11356
|
+
return n.toString(16).toUpperCase().padStart(2, "0");
|
|
11357
|
+
};
|
|
11358
|
+
var hex4 = function hex4(n) {
|
|
11359
|
+
return n.toString(16).toUpperCase().padStart(4, "0");
|
|
11360
|
+
};
|
|
11361
|
+
|
|
11362
|
+
/**
|
|
11363
|
+
* The block key "gggg:creator" of a group and creator. A line break in the
|
|
11364
|
+
* creator is written as the text `\n` (and `\r`); LO holds no backslash, so
|
|
11365
|
+
* the key reads back to the same creator.
|
|
11366
|
+
*/
|
|
11367
|
+
function privateBlockKey(group, creator) {
|
|
11368
|
+
var text = creator.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
11369
|
+
return "".concat(hex4(group), ":").concat(text);
|
|
11370
|
+
}
|
|
11371
|
+
|
|
11372
|
+
/** The creator of the creator part of a block key: `\n` and `\r` unescaped. */
|
|
11373
|
+
function keyCreator(text) {
|
|
11374
|
+
return text.replace(/\\r/g, "\r").replace(/\\n/g, "\n");
|
|
11375
|
+
}
|
|
11376
|
+
|
|
11377
|
+
/**
|
|
11378
|
+
* The creator text of a creator element value: no leading spaces, no
|
|
11379
|
+
* trailing spaces or NULs. A value in bytes (UN) is read as Latin-1.
|
|
11380
|
+
*/
|
|
11381
|
+
function creatorText(value) {
|
|
11382
|
+
var v = Array.isArray(value) ? value[0] : value;
|
|
11383
|
+
if (typeof v === "string") return v.replace(/^ +|[\0 ]+$/g, "");
|
|
11384
|
+
if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) {
|
|
11385
|
+
var bytes = ArrayBuffer.isView(v) ? new Uint8Array(v.buffer, v.byteOffset, v.byteLength) : new Uint8Array(v);
|
|
11386
|
+
return creatorText(String.fromCharCode.apply(String, _toConsumableArray(bytes.subarray(0, 64))));
|
|
11387
|
+
}
|
|
11388
|
+
return "";
|
|
11389
|
+
}
|
|
11390
|
+
|
|
11391
|
+
/** [group, creator] from (groupOrKey, creator), validated. */
|
|
11392
|
+
function blockArgs(groupOrKey, creator) {
|
|
11393
|
+
var group = groupOrKey;
|
|
11394
|
+
if (typeof groupOrKey === "string") {
|
|
11395
|
+
var match = BLOCK_KEY.exec(groupOrKey);
|
|
11396
|
+
if (!match) {
|
|
11397
|
+
throw new Error("Private block key must be \"gggg:creator\", got ".concat(groupOrKey));
|
|
11398
|
+
}
|
|
11399
|
+
group = parseInt(match[1], 16);
|
|
11400
|
+
creator = keyCreator(match[2]);
|
|
11401
|
+
}
|
|
11402
|
+
if (!Number.isInteger(group) || group < 0 || group > 0xffff) {
|
|
11403
|
+
throw new Error("Private group must be a 16 bit number, got ".concat(group));
|
|
11404
|
+
}
|
|
11405
|
+
if (group % 2 === 0) {
|
|
11406
|
+
throw new Error("Private group must be odd, got ".concat(hex4(group), " - an even group is standard, not private"));
|
|
11407
|
+
}
|
|
11408
|
+
if (typeof creator !== "string" || creatorText(creator).length === 0) {
|
|
11409
|
+
throw new Error("Private creator must be a non-empty string");
|
|
11410
|
+
}
|
|
11411
|
+
creator = creatorText(creator);
|
|
11412
|
+
if (creator.length > CREATOR_MAX_LENGTH) {
|
|
11413
|
+
throw new Error("Private creator must be at most ".concat(CREATOR_MAX_LENGTH, " characters (LO), got ").concat(creator.length));
|
|
11414
|
+
}
|
|
11415
|
+
return [group, creator];
|
|
11416
|
+
}
|
|
11417
|
+
|
|
11418
|
+
/** The element number of 0x00-0xFF or "xEE". */
|
|
11419
|
+
function elementNumber(element) {
|
|
11420
|
+
var match = typeof element === "string" && ELEMENT_KEY.exec(element);
|
|
11421
|
+
var n = match ? parseInt(match[1], 16) : element;
|
|
11422
|
+
if (!Number.isInteger(n) || n < 0x00 || n > 0xff) {
|
|
11423
|
+
throw new Error("Private element must be 0x00 to 0xFF or \"xEE\", got ".concat(element));
|
|
11424
|
+
}
|
|
11425
|
+
return n;
|
|
11426
|
+
}
|
|
11427
|
+
|
|
11428
|
+
/**
|
|
11429
|
+
* An accessor for one reserved block of a dict, keyed by 'GGGGEEEE'.
|
|
11430
|
+
* `reservedBlock` is the xx of the block in this dict.
|
|
11431
|
+
*/
|
|
11432
|
+
function blockAccessor(dict, group, creator, reservedBlock) {
|
|
11433
|
+
var tag = function tag(element) {
|
|
11434
|
+
return hex4(group) + hex2(reservedBlock) + hex2(elementNumber(element));
|
|
11435
|
+
};
|
|
11436
|
+
return {
|
|
11437
|
+
key: privateBlockKey(group, creator),
|
|
11438
|
+
group: group,
|
|
11439
|
+
creator: creator,
|
|
11440
|
+
reservedBlock: reservedBlock,
|
|
11441
|
+
/** The 'GGGGEEEE' key of an element of this block. */
|
|
11442
|
+
tag: tag,
|
|
11443
|
+
/** Whether this block holds that element. */
|
|
11444
|
+
has: function has(element) {
|
|
11445
|
+
return Object.prototype.hasOwnProperty.call(dict, tag(element));
|
|
11446
|
+
},
|
|
11447
|
+
/** The element object, or undefined. */
|
|
11448
|
+
get: function get(element) {
|
|
11449
|
+
return dict[tag(element)];
|
|
11450
|
+
},
|
|
11451
|
+
/**
|
|
11452
|
+
* Writes an element of this block, as DicomDict#upsertTag does.
|
|
11453
|
+
*
|
|
11454
|
+
* @param {number|string} element 0x00 to 0xFF, or "xEE"
|
|
11455
|
+
* @param {string} vr value representation
|
|
11456
|
+
* @param {*} values value, or array of values
|
|
11457
|
+
* @returns {string} the tag that was written
|
|
11458
|
+
*/
|
|
11459
|
+
set: function set(element, vr, values) {
|
|
11460
|
+
var key = tag(element);
|
|
11461
|
+
dict[key] = ValueRepresentation.addTagAccessors({
|
|
11462
|
+
vr: vr
|
|
11463
|
+
});
|
|
11464
|
+
dict[key].Value = Array.isArray(values) ? values : [values];
|
|
11465
|
+
return key;
|
|
11466
|
+
}
|
|
11467
|
+
};
|
|
11468
|
+
}
|
|
11469
|
+
|
|
11470
|
+
/**
|
|
11471
|
+
* Finds the block a creator has reserved in a dict.
|
|
11472
|
+
*
|
|
11473
|
+
* @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
|
|
11474
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11475
|
+
* @param {string} [creator] creator string, with a group number
|
|
11476
|
+
* @returns {object|null} a block accessor, or null when the creator is absent
|
|
11477
|
+
*/
|
|
11478
|
+
function findPrivateBlock(dict, groupOrKey, creator) {
|
|
11479
|
+
var _blockArgs = blockArgs(groupOrKey, creator),
|
|
11480
|
+
_blockArgs2 = _slicedToArray(_blockArgs, 2),
|
|
11481
|
+
group = _blockArgs2[0],
|
|
11482
|
+
wanted = _blockArgs2[1];
|
|
11483
|
+
for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
|
|
11484
|
+
var element = dict[hex4(group) + hex4(xx)];
|
|
11485
|
+
if (element && creatorText(element.Value) === wanted) {
|
|
11486
|
+
return blockAccessor(dict, group, wanted, xx);
|
|
11487
|
+
}
|
|
11488
|
+
}
|
|
11489
|
+
return null;
|
|
11490
|
+
}
|
|
11491
|
+
|
|
11492
|
+
/**
|
|
11493
|
+
* Finds the block a creator has reserved, or reserves the first free block
|
|
11494
|
+
* and writes the creator element. A block is free when the dict holds no
|
|
11495
|
+
* creator element for it and no element in its range.
|
|
11496
|
+
*
|
|
11497
|
+
* @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
|
|
11498
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11499
|
+
* @param {string} [creator] creator string, with a group number
|
|
11500
|
+
* @returns {object} a block accessor
|
|
11501
|
+
*/
|
|
11502
|
+
function reservePrivateBlock(dict, groupOrKey, creator) {
|
|
11503
|
+
var existing = findPrivateBlock(dict, groupOrKey, creator);
|
|
11504
|
+
if (existing) return existing;
|
|
11505
|
+
var _blockArgs3 = blockArgs(groupOrKey, creator),
|
|
11506
|
+
_blockArgs4 = _slicedToArray(_blockArgs3, 2),
|
|
11507
|
+
group = _blockArgs4[0],
|
|
11508
|
+
wanted = _blockArgs4[1];
|
|
11509
|
+
var prefix = hex4(group);
|
|
11510
|
+
var used = new Set();
|
|
11511
|
+
for (var _i = 0, _Object$keys = Object.keys(dict); _i < _Object$keys.length; _i++) {
|
|
11512
|
+
var key = _Object$keys[_i];
|
|
11513
|
+
if (!key.startsWith(prefix) || key.length !== 8) continue;
|
|
11514
|
+
var element = parseInt(key.slice(4), 16);
|
|
11515
|
+
used.add(element <= 0xff ? element : element >> 8);
|
|
11516
|
+
}
|
|
11517
|
+
for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
|
|
11518
|
+
if (!used.has(xx)) {
|
|
11519
|
+
dict[prefix + hex4(xx)] = ValueRepresentation.addTagAccessors({
|
|
11520
|
+
vr: "LO"
|
|
11521
|
+
});
|
|
11522
|
+
dict[prefix + hex4(xx)].Value = [wanted];
|
|
11523
|
+
return blockAccessor(dict, group, wanted, xx);
|
|
11524
|
+
}
|
|
11525
|
+
}
|
|
11526
|
+
throw new Error("No free private block in group ".concat(prefix, " - all of 0x10 to 0xFF are reserved"));
|
|
11527
|
+
}
|
|
11528
|
+
|
|
11327
11529
|
var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
|
|
11328
11530
|
var DicomMessage$2;
|
|
11329
11531
|
var DicomDict = /*#__PURE__*/function () {
|
|
@@ -11345,6 +11547,35 @@ var DicomDict = /*#__PURE__*/function () {
|
|
|
11345
11547
|
this.dict[tag].Value = values;
|
|
11346
11548
|
}
|
|
11347
11549
|
}
|
|
11550
|
+
|
|
11551
|
+
/**
|
|
11552
|
+
* Reserves a private block for a creator, and writes its creator element
|
|
11553
|
+
* when the creator has no block yet; pass `{ create: false }` to only look
|
|
11554
|
+
* it up. See src/privateBlock.js: the block is found by creator, never
|
|
11555
|
+
* assumed.
|
|
11556
|
+
*
|
|
11557
|
+
* dicomDict.privateBlock("4D43:ACME 1.0").set("x01", "CS", ["HYBRID"]);
|
|
11558
|
+
*
|
|
11559
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11560
|
+
* @param {string} [creator] creator string, with a group number
|
|
11561
|
+
* @param {{create?: boolean}} [options] create defaults to true; false
|
|
11562
|
+
* returns null when the creator is absent
|
|
11563
|
+
* @returns {object|null} accessor with key, group, creator, reservedBlock,
|
|
11564
|
+
* tag, has, get and set
|
|
11565
|
+
*/
|
|
11566
|
+
}, {
|
|
11567
|
+
key: "privateBlock",
|
|
11568
|
+
value: function privateBlock(groupOrKey, creator) {
|
|
11569
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11570
|
+
if (typeof groupOrKey === "string" && _typeof(creator) === "object") {
|
|
11571
|
+
options = creator;
|
|
11572
|
+
creator = undefined;
|
|
11573
|
+
}
|
|
11574
|
+
var _ref = options || {},
|
|
11575
|
+
_ref$create = _ref.create,
|
|
11576
|
+
create = _ref$create === void 0 ? true : _ref$create;
|
|
11577
|
+
return create ? reservePrivateBlock(this.dict, groupOrKey, creator) : findPrivateBlock(this.dict, groupOrKey, creator);
|
|
11578
|
+
}
|
|
11348
11579
|
}, {
|
|
11349
11580
|
key: "write",
|
|
11350
11581
|
value: function write() {
|
|
@@ -14359,7 +14590,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
|
|
|
14359
14590
|
break;
|
|
14360
14591
|
}
|
|
14361
14592
|
// Group length
|
|
14362
|
-
stream.increment(
|
|
14593
|
+
stream.increment(length);
|
|
14363
14594
|
return _context5.abrupt("continue", 1);
|
|
14364
14595
|
case 5:
|
|
14365
14596
|
addTagResult = listener.addTag(tag, tagInfo);
|
|
@@ -28187,7 +28418,12 @@ var data = {
|
|
|
28187
28418
|
Colors: Colors,
|
|
28188
28419
|
datasetToDict: datasetToDict,
|
|
28189
28420
|
datasetToBuffer: datasetToBuffer,
|
|
28190
|
-
datasetToBlob: datasetToBlob
|
|
28421
|
+
datasetToBlob: datasetToBlob,
|
|
28422
|
+
// Private block reservation, PS3.5 Section 7.8.1. findPrivateBlock() works
|
|
28423
|
+
// on any parsed dict; DicomDict#privateBlock() is the writing side.
|
|
28424
|
+
findPrivateBlock: findPrivateBlock,
|
|
28425
|
+
reservePrivateBlock: reservePrivateBlock,
|
|
28426
|
+
privateBlockKey: privateBlockKey
|
|
28191
28427
|
};
|
|
28192
28428
|
var async = {
|
|
28193
28429
|
AsyncDicomReader: AsyncDicomReader
|