dcmjs 0.52.2 → 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 +263 -4
- package/build/dcmjs.es.js.map +1 -1
- package/build/dcmjs.js +263 -4
- 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.js
CHANGED
|
@@ -9697,8 +9697,8 @@
|
|
|
9697
9697
|
}
|
|
9698
9698
|
var DicomMessage$3, Tag$1, DicomMetaDictionary$1;
|
|
9699
9699
|
var binaryVRs = ["FL", "FD", "SL", "SS", "UL", "US", "AT", "UV"],
|
|
9700
|
-
length32VRs = ["OB", "OW", "OF", "SQ", "UC", "UR", "UT", "UN", "OD", "UV"],
|
|
9701
|
-
singleVRs$1 = ["SQ", "OF", "OW", "OB", "UN"];
|
|
9700
|
+
length32VRs = ["OB", "OW", "OF", "OL", "SQ", "UC", "UR", "UT", "UN", "OD", "UV"],
|
|
9701
|
+
singleVRs$1 = ["SQ", "OF", "OL", "OW", "OB", "UN"];
|
|
9702
9702
|
var ValueRepresentation = /*#__PURE__*/function () {
|
|
9703
9703
|
function ValueRepresentation(type) {
|
|
9704
9704
|
_classCallCheck(this, ValueRepresentation);
|
|
@@ -11278,6 +11278,22 @@
|
|
|
11278
11278
|
}
|
|
11279
11279
|
_inherits(OtherFloatString, _BinaryRepresentation6);
|
|
11280
11280
|
return _createClass(OtherFloatString);
|
|
11281
|
+
}(BinaryRepresentation); // A stream of 32 bit words. Used by the large mesh attributes of Surface
|
|
11282
|
+
// Segmentation - Long Triangle Point Index List (0066,0041) and its Edge and
|
|
11283
|
+
// Vertex counterparts - where the 16 bit indices of the OW forms cap a surface
|
|
11284
|
+
// at 65535 points.
|
|
11285
|
+
var OtherLongString = /*#__PURE__*/function (_BinaryRepresentation7) {
|
|
11286
|
+
function OtherLongString() {
|
|
11287
|
+
var _this34;
|
|
11288
|
+
_classCallCheck(this, OtherLongString);
|
|
11289
|
+
_this34 = _callSuper(this, OtherLongString, ["OL"]);
|
|
11290
|
+
_this34.maxLength = null;
|
|
11291
|
+
_this34.padByte = PADDING_NULL;
|
|
11292
|
+
_this34.noMultiple = true;
|
|
11293
|
+
return _this34;
|
|
11294
|
+
}
|
|
11295
|
+
_inherits(OtherLongString, _BinaryRepresentation7);
|
|
11296
|
+
return _createClass(OtherLongString);
|
|
11281
11297
|
}(BinaryRepresentation); // these VR instances are precreate and are reused for each requested vr/tag
|
|
11282
11298
|
var VRinstances = {
|
|
11283
11299
|
AE: new ApplicationEntity(),
|
|
@@ -11295,6 +11311,7 @@
|
|
|
11295
11311
|
OB: new OtherByteString(),
|
|
11296
11312
|
OD: new OtherDoubleString(),
|
|
11297
11313
|
OF: new OtherFloatString(),
|
|
11314
|
+
OL: new OtherLongString(),
|
|
11298
11315
|
OW: new OtherWordString(),
|
|
11299
11316
|
PN: new PersonName(),
|
|
11300
11317
|
SH: new ShortString(),
|
|
@@ -11313,6 +11330,208 @@
|
|
|
11313
11330
|
UV: new Unsigned64BitVeryLong()
|
|
11314
11331
|
};
|
|
11315
11332
|
|
|
11333
|
+
/**
|
|
11334
|
+
* Private block reservation, per PS3.5 Section 7.8.1.
|
|
11335
|
+
*
|
|
11336
|
+
* A private group is odd. Within it, a Private Creator Data Element at
|
|
11337
|
+
* (gggg,00xx) - where xx is 0x10 through 0xFF - identifies an implementer and
|
|
11338
|
+
* reserves the block of Data Elements (gggg,xx00) through (gggg,xxFF) for them.
|
|
11339
|
+
*
|
|
11340
|
+
* Which block a creator gets is decided by whoever wrote the file, so the
|
|
11341
|
+
* creator string is the identity and the block has to be looked up. A block
|
|
11342
|
+
* is named as in the 1.0 naturalized form: the block key "gggg:creator"
|
|
11343
|
+
* (for example "4D43:ACME 1.0"), or the pair (group, creator); an element of
|
|
11344
|
+
* the block is its number 0x00-0xFF, or the element key "xEE" (for example
|
|
11345
|
+
* "x01"):
|
|
11346
|
+
*
|
|
11347
|
+
* // writing
|
|
11348
|
+
* const block = dicomDict.privateBlock("4D43:ACME 1.0");
|
|
11349
|
+
* block.set("x01", "CS", ["HYBRID"]); // -> (4D43,1001), or wherever it landed
|
|
11350
|
+
*
|
|
11351
|
+
* // reading, from any parsed dict
|
|
11352
|
+
* const found = findPrivateBlock(dict, "4D43:ACME 1.0");
|
|
11353
|
+
* found && found.get("x01").Value;
|
|
11354
|
+
*/
|
|
11355
|
+
|
|
11356
|
+
var CREATOR_MIN = 0x10;
|
|
11357
|
+
var CREATOR_MAX = 0xff;
|
|
11358
|
+
var CREATOR_MAX_LENGTH = 64; // LO
|
|
11359
|
+
var BLOCK_KEY = /^([0-9A-Fa-f]{4}):([^]+)$/;
|
|
11360
|
+
var ELEMENT_KEY = /^x([0-9A-Fa-f]{2})$/;
|
|
11361
|
+
var hex2 = function hex2(n) {
|
|
11362
|
+
return n.toString(16).toUpperCase().padStart(2, "0");
|
|
11363
|
+
};
|
|
11364
|
+
var hex4 = function hex4(n) {
|
|
11365
|
+
return n.toString(16).toUpperCase().padStart(4, "0");
|
|
11366
|
+
};
|
|
11367
|
+
|
|
11368
|
+
/**
|
|
11369
|
+
* The block key "gggg:creator" of a group and creator. A line break in the
|
|
11370
|
+
* creator is written as the text `\n` (and `\r`); LO holds no backslash, so
|
|
11371
|
+
* the key reads back to the same creator.
|
|
11372
|
+
*/
|
|
11373
|
+
function privateBlockKey(group, creator) {
|
|
11374
|
+
var text = creator.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
11375
|
+
return "".concat(hex4(group), ":").concat(text);
|
|
11376
|
+
}
|
|
11377
|
+
|
|
11378
|
+
/** The creator of the creator part of a block key: `\n` and `\r` unescaped. */
|
|
11379
|
+
function keyCreator(text) {
|
|
11380
|
+
return text.replace(/\\r/g, "\r").replace(/\\n/g, "\n");
|
|
11381
|
+
}
|
|
11382
|
+
|
|
11383
|
+
/**
|
|
11384
|
+
* The creator text of a creator element value: no leading spaces, no
|
|
11385
|
+
* trailing spaces or NULs. A value in bytes (UN) is read as Latin-1.
|
|
11386
|
+
*/
|
|
11387
|
+
function creatorText(value) {
|
|
11388
|
+
var v = Array.isArray(value) ? value[0] : value;
|
|
11389
|
+
if (typeof v === "string") return v.replace(/^ +|[\0 ]+$/g, "");
|
|
11390
|
+
if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) {
|
|
11391
|
+
var bytes = ArrayBuffer.isView(v) ? new Uint8Array(v.buffer, v.byteOffset, v.byteLength) : new Uint8Array(v);
|
|
11392
|
+
return creatorText(String.fromCharCode.apply(String, _toConsumableArray(bytes.subarray(0, 64))));
|
|
11393
|
+
}
|
|
11394
|
+
return "";
|
|
11395
|
+
}
|
|
11396
|
+
|
|
11397
|
+
/** [group, creator] from (groupOrKey, creator), validated. */
|
|
11398
|
+
function blockArgs(groupOrKey, creator) {
|
|
11399
|
+
var group = groupOrKey;
|
|
11400
|
+
if (typeof groupOrKey === "string") {
|
|
11401
|
+
var match = BLOCK_KEY.exec(groupOrKey);
|
|
11402
|
+
if (!match) {
|
|
11403
|
+
throw new Error("Private block key must be \"gggg:creator\", got ".concat(groupOrKey));
|
|
11404
|
+
}
|
|
11405
|
+
group = parseInt(match[1], 16);
|
|
11406
|
+
creator = keyCreator(match[2]);
|
|
11407
|
+
}
|
|
11408
|
+
if (!Number.isInteger(group) || group < 0 || group > 0xffff) {
|
|
11409
|
+
throw new Error("Private group must be a 16 bit number, got ".concat(group));
|
|
11410
|
+
}
|
|
11411
|
+
if (group % 2 === 0) {
|
|
11412
|
+
throw new Error("Private group must be odd, got ".concat(hex4(group), " - an even group is standard, not private"));
|
|
11413
|
+
}
|
|
11414
|
+
if (typeof creator !== "string" || creatorText(creator).length === 0) {
|
|
11415
|
+
throw new Error("Private creator must be a non-empty string");
|
|
11416
|
+
}
|
|
11417
|
+
creator = creatorText(creator);
|
|
11418
|
+
if (creator.length > CREATOR_MAX_LENGTH) {
|
|
11419
|
+
throw new Error("Private creator must be at most ".concat(CREATOR_MAX_LENGTH, " characters (LO), got ").concat(creator.length));
|
|
11420
|
+
}
|
|
11421
|
+
return [group, creator];
|
|
11422
|
+
}
|
|
11423
|
+
|
|
11424
|
+
/** The element number of 0x00-0xFF or "xEE". */
|
|
11425
|
+
function elementNumber(element) {
|
|
11426
|
+
var match = typeof element === "string" && ELEMENT_KEY.exec(element);
|
|
11427
|
+
var n = match ? parseInt(match[1], 16) : element;
|
|
11428
|
+
if (!Number.isInteger(n) || n < 0x00 || n > 0xff) {
|
|
11429
|
+
throw new Error("Private element must be 0x00 to 0xFF or \"xEE\", got ".concat(element));
|
|
11430
|
+
}
|
|
11431
|
+
return n;
|
|
11432
|
+
}
|
|
11433
|
+
|
|
11434
|
+
/**
|
|
11435
|
+
* An accessor for one reserved block of a dict, keyed by 'GGGGEEEE'.
|
|
11436
|
+
* `reservedBlock` is the xx of the block in this dict.
|
|
11437
|
+
*/
|
|
11438
|
+
function blockAccessor(dict, group, creator, reservedBlock) {
|
|
11439
|
+
var tag = function tag(element) {
|
|
11440
|
+
return hex4(group) + hex2(reservedBlock) + hex2(elementNumber(element));
|
|
11441
|
+
};
|
|
11442
|
+
return {
|
|
11443
|
+
key: privateBlockKey(group, creator),
|
|
11444
|
+
group: group,
|
|
11445
|
+
creator: creator,
|
|
11446
|
+
reservedBlock: reservedBlock,
|
|
11447
|
+
/** The 'GGGGEEEE' key of an element of this block. */
|
|
11448
|
+
tag: tag,
|
|
11449
|
+
/** Whether this block holds that element. */
|
|
11450
|
+
has: function has(element) {
|
|
11451
|
+
return Object.prototype.hasOwnProperty.call(dict, tag(element));
|
|
11452
|
+
},
|
|
11453
|
+
/** The element object, or undefined. */
|
|
11454
|
+
get: function get(element) {
|
|
11455
|
+
return dict[tag(element)];
|
|
11456
|
+
},
|
|
11457
|
+
/**
|
|
11458
|
+
* Writes an element of this block, as DicomDict#upsertTag does.
|
|
11459
|
+
*
|
|
11460
|
+
* @param {number|string} element 0x00 to 0xFF, or "xEE"
|
|
11461
|
+
* @param {string} vr value representation
|
|
11462
|
+
* @param {*} values value, or array of values
|
|
11463
|
+
* @returns {string} the tag that was written
|
|
11464
|
+
*/
|
|
11465
|
+
set: function set(element, vr, values) {
|
|
11466
|
+
var key = tag(element);
|
|
11467
|
+
dict[key] = ValueRepresentation.addTagAccessors({
|
|
11468
|
+
vr: vr
|
|
11469
|
+
});
|
|
11470
|
+
dict[key].Value = Array.isArray(values) ? values : [values];
|
|
11471
|
+
return key;
|
|
11472
|
+
}
|
|
11473
|
+
};
|
|
11474
|
+
}
|
|
11475
|
+
|
|
11476
|
+
/**
|
|
11477
|
+
* Finds the block a creator has reserved in a dict.
|
|
11478
|
+
*
|
|
11479
|
+
* @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
|
|
11480
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11481
|
+
* @param {string} [creator] creator string, with a group number
|
|
11482
|
+
* @returns {object|null} a block accessor, or null when the creator is absent
|
|
11483
|
+
*/
|
|
11484
|
+
function findPrivateBlock(dict, groupOrKey, creator) {
|
|
11485
|
+
var _blockArgs = blockArgs(groupOrKey, creator),
|
|
11486
|
+
_blockArgs2 = _slicedToArray(_blockArgs, 2),
|
|
11487
|
+
group = _blockArgs2[0],
|
|
11488
|
+
wanted = _blockArgs2[1];
|
|
11489
|
+
for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
|
|
11490
|
+
var element = dict[hex4(group) + hex4(xx)];
|
|
11491
|
+
if (element && creatorText(element.Value) === wanted) {
|
|
11492
|
+
return blockAccessor(dict, group, wanted, xx);
|
|
11493
|
+
}
|
|
11494
|
+
}
|
|
11495
|
+
return null;
|
|
11496
|
+
}
|
|
11497
|
+
|
|
11498
|
+
/**
|
|
11499
|
+
* Finds the block a creator has reserved, or reserves the first free block
|
|
11500
|
+
* and writes the creator element. A block is free when the dict holds no
|
|
11501
|
+
* creator element for it and no element in its range.
|
|
11502
|
+
*
|
|
11503
|
+
* @param {object} dict parsed dataset, keyed by 'GGGGEEEE'
|
|
11504
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11505
|
+
* @param {string} [creator] creator string, with a group number
|
|
11506
|
+
* @returns {object} a block accessor
|
|
11507
|
+
*/
|
|
11508
|
+
function reservePrivateBlock(dict, groupOrKey, creator) {
|
|
11509
|
+
var existing = findPrivateBlock(dict, groupOrKey, creator);
|
|
11510
|
+
if (existing) return existing;
|
|
11511
|
+
var _blockArgs3 = blockArgs(groupOrKey, creator),
|
|
11512
|
+
_blockArgs4 = _slicedToArray(_blockArgs3, 2),
|
|
11513
|
+
group = _blockArgs4[0],
|
|
11514
|
+
wanted = _blockArgs4[1];
|
|
11515
|
+
var prefix = hex4(group);
|
|
11516
|
+
var used = new Set();
|
|
11517
|
+
for (var _i = 0, _Object$keys = Object.keys(dict); _i < _Object$keys.length; _i++) {
|
|
11518
|
+
var key = _Object$keys[_i];
|
|
11519
|
+
if (!key.startsWith(prefix) || key.length !== 8) continue;
|
|
11520
|
+
var element = parseInt(key.slice(4), 16);
|
|
11521
|
+
used.add(element <= 0xff ? element : element >> 8);
|
|
11522
|
+
}
|
|
11523
|
+
for (var xx = CREATOR_MIN; xx <= CREATOR_MAX; xx++) {
|
|
11524
|
+
if (!used.has(xx)) {
|
|
11525
|
+
dict[prefix + hex4(xx)] = ValueRepresentation.addTagAccessors({
|
|
11526
|
+
vr: "LO"
|
|
11527
|
+
});
|
|
11528
|
+
dict[prefix + hex4(xx)].Value = [wanted];
|
|
11529
|
+
return blockAccessor(dict, group, wanted, xx);
|
|
11530
|
+
}
|
|
11531
|
+
}
|
|
11532
|
+
throw new Error("No free private block in group ".concat(prefix, " - all of 0x10 to 0xFF are reserved"));
|
|
11533
|
+
}
|
|
11534
|
+
|
|
11316
11535
|
var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
|
|
11317
11536
|
var DicomMessage$2;
|
|
11318
11537
|
var DicomDict = /*#__PURE__*/function () {
|
|
@@ -11334,6 +11553,35 @@
|
|
|
11334
11553
|
this.dict[tag].Value = values;
|
|
11335
11554
|
}
|
|
11336
11555
|
}
|
|
11556
|
+
|
|
11557
|
+
/**
|
|
11558
|
+
* Reserves a private block for a creator, and writes its creator element
|
|
11559
|
+
* when the creator has no block yet; pass `{ create: false }` to only look
|
|
11560
|
+
* it up. See src/privateBlock.js: the block is found by creator, never
|
|
11561
|
+
* assumed.
|
|
11562
|
+
*
|
|
11563
|
+
* dicomDict.privateBlock("4D43:ACME 1.0").set("x01", "CS", ["HYBRID"]);
|
|
11564
|
+
*
|
|
11565
|
+
* @param {number|string} groupOrKey odd group number, or block key "gggg:creator"
|
|
11566
|
+
* @param {string} [creator] creator string, with a group number
|
|
11567
|
+
* @param {{create?: boolean}} [options] create defaults to true; false
|
|
11568
|
+
* returns null when the creator is absent
|
|
11569
|
+
* @returns {object|null} accessor with key, group, creator, reservedBlock,
|
|
11570
|
+
* tag, has, get and set
|
|
11571
|
+
*/
|
|
11572
|
+
}, {
|
|
11573
|
+
key: "privateBlock",
|
|
11574
|
+
value: function privateBlock(groupOrKey, creator) {
|
|
11575
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11576
|
+
if (typeof groupOrKey === "string" && _typeof(creator) === "object") {
|
|
11577
|
+
options = creator;
|
|
11578
|
+
creator = undefined;
|
|
11579
|
+
}
|
|
11580
|
+
var _ref = options || {},
|
|
11581
|
+
_ref$create = _ref.create,
|
|
11582
|
+
create = _ref$create === void 0 ? true : _ref$create;
|
|
11583
|
+
return create ? reservePrivateBlock(this.dict, groupOrKey, creator) : findPrivateBlock(this.dict, groupOrKey, creator);
|
|
11584
|
+
}
|
|
11337
11585
|
}, {
|
|
11338
11586
|
key: "write",
|
|
11339
11587
|
value: function write() {
|
|
@@ -12420,6 +12668,12 @@
|
|
|
12420
12668
|
}
|
|
12421
12669
|
}
|
|
12422
12670
|
var _vr = ValueRepresentation.createByTypeString(dataItem.vr);
|
|
12671
|
+
if (dataItem.vr === "DS" && Array.isArray(dataItem.Value)) {
|
|
12672
|
+
// Format numbers to fit 16 characters instead of truncating String(number) below
|
|
12673
|
+
dataItem.Value = dataItem.Value.map(function (value) {
|
|
12674
|
+
return typeof value === "number" ? _vr.convertToString(value) : value;
|
|
12675
|
+
});
|
|
12676
|
+
}
|
|
12423
12677
|
dataItem.Value = DicomMetaDictionary.denaturalizeValue(dataItem.Value);
|
|
12424
12678
|
if (entry.vr == "SQ") {
|
|
12425
12679
|
var unnaturalValues = [];
|
|
@@ -14342,7 +14596,7 @@
|
|
|
14342
14596
|
break;
|
|
14343
14597
|
}
|
|
14344
14598
|
// Group length
|
|
14345
|
-
stream.increment(
|
|
14599
|
+
stream.increment(length);
|
|
14346
14600
|
return _context5.abrupt("continue", 1);
|
|
14347
14601
|
case 5:
|
|
14348
14602
|
addTagResult = listener.addTag(tag, tagInfo);
|
|
@@ -28170,7 +28424,12 @@
|
|
|
28170
28424
|
Colors: Colors,
|
|
28171
28425
|
datasetToDict: datasetToDict,
|
|
28172
28426
|
datasetToBuffer: datasetToBuffer,
|
|
28173
|
-
datasetToBlob: datasetToBlob
|
|
28427
|
+
datasetToBlob: datasetToBlob,
|
|
28428
|
+
// Private block reservation, PS3.5 Section 7.8.1. findPrivateBlock() works
|
|
28429
|
+
// on any parsed dict; DicomDict#privateBlock() is the writing side.
|
|
28430
|
+
findPrivateBlock: findPrivateBlock,
|
|
28431
|
+
reservePrivateBlock: reservePrivateBlock,
|
|
28432
|
+
privateBlockKey: privateBlockKey
|
|
28174
28433
|
};
|
|
28175
28434
|
var async = {
|
|
28176
28435
|
AsyncDicomReader: AsyncDicomReader
|