dcmjs 0.52.0 → 0.52.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 +133 -40
- package/build/dcmjs.es.js.map +1 -1
- package/build/dcmjs.js +133 -40
- 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 +1 -1
package/build/dcmjs.es.js
CHANGED
|
@@ -8140,7 +8140,14 @@ var SplitDataView = /*#__PURE__*/function () {
|
|
|
8140
8140
|
value: function slice() {
|
|
8141
8141
|
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
8142
8142
|
var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size;
|
|
8143
|
-
|
|
8143
|
+
// Clamp to the data actually held, the way ArrayBuffer.prototype.slice
|
|
8144
|
+
// does. Otherwise a value length declared by a malformed file
|
|
8145
|
+
// allocates the declared size however few bytes are really present.
|
|
8146
|
+
// https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
|
|
8147
|
+
if (end > this.byteLength) {
|
|
8148
|
+
end = this.byteLength;
|
|
8149
|
+
}
|
|
8150
|
+
if (end <= start) {
|
|
8144
8151
|
return new Uint8Array(0).buffer;
|
|
8145
8152
|
}
|
|
8146
8153
|
var index = this.findStart(start);
|
|
@@ -10224,6 +10231,15 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation3) {
|
|
|
10224
10231
|
} else if (this.type == 'OB') {
|
|
10225
10232
|
bytes = stream.readUint8Array(length);
|
|
10226
10233
|
}*/
|
|
10234
|
+
// A declared value length longer than the data present means a
|
|
10235
|
+
// truncated or malformed file, so read what is there rather than
|
|
10236
|
+
// allocating the declared length, which the file controls.
|
|
10237
|
+
// https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
|
|
10238
|
+
var available = stream.endOffset - stream.offset;
|
|
10239
|
+
if (length > available) {
|
|
10240
|
+
validationLog.warn("".concat(this.type, " value declares ").concat(length, " bytes but only ").concat(available, " are available - reading the available bytes"));
|
|
10241
|
+
length = available;
|
|
10242
|
+
}
|
|
10227
10243
|
bytes = stream.getBuffer(stream.offset, stream.offset + length);
|
|
10228
10244
|
stream.increment(length);
|
|
10229
10245
|
return [bytes];
|
|
@@ -13338,25 +13354,65 @@ var DICOMWEB = /*#__PURE__*/function () {
|
|
|
13338
13354
|
//
|
|
13339
13355
|
// Handle DICOM and CIELAB colors
|
|
13340
13356
|
// based on:
|
|
13341
|
-
// https://github.com/
|
|
13357
|
+
// https://github.com/DCMTK/dcmtk/blob/88105877c3b610e23fc9422ba6a84af85552f5dd/dcmiod/libsrc/cielabutil.cc
|
|
13342
13358
|
//
|
|
13343
13359
|
// RGB here refers to sRGB 0-1 per component.
|
|
13344
13360
|
// dicomlab is CIELAB values as defined in the dicom standard
|
|
13345
|
-
// XYZ is CIEXYZ convention
|
|
13346
|
-
//
|
|
13347
|
-
// TODO: needs a test suite
|
|
13348
|
-
// TODO: only dicomlab2RGB tested on real data
|
|
13361
|
+
// XYZ is CIEXYZ convention, relative to the D50 white point (ICC PCS)
|
|
13349
13362
|
//
|
|
13363
|
+
// DICOM encodes CIELab values in the same way as the ICC Profile Connection
|
|
13364
|
+
// Space (PCS, see PS3.3 C.10.7.1.1), i.e. relative to the D50 illuminant,
|
|
13365
|
+
// whereas the native white point of sRGB is D65. The conversions below
|
|
13366
|
+
// therefore chromatically adapt between the two using the linear Bradford
|
|
13367
|
+
// transform. Matrices and constants are those of the CSS Color Module Level 4
|
|
13368
|
+
// sample code (https://www.w3.org/TR/css-color-4/#color-conversion-code).
|
|
13350
13369
|
//
|
|
13370
|
+
|
|
13371
|
+
// White points, defined by their 4-figure CIE x,y chromaticities.
|
|
13372
|
+
// D50 is intentionally [0.96430, 1, 0.82510] and not the ICC.1 PCS illuminant
|
|
13373
|
+
// [0.9642, 1, 0.8249]: this matches DCMTK, highdicom and CSS Color 4, and
|
|
13374
|
+
// encodes sRGB white as exactly 0x8080 in a* and b*.
|
|
13375
|
+
var D50_WHITEPOINT_XYZ = [0.3457 / 0.3585, 1.0, (1.0 - 0.3457 - 0.3585) / 0.3585];
|
|
13376
|
+
var D65_WHITEPOINT_XYZ = [0.3127 / 0.329, 1.0, (1.0 - 0.3127 - 0.329) / 0.329];
|
|
13377
|
+
function clamp01(n) {
|
|
13378
|
+
return Math.min(1.0, Math.max(0.0, n));
|
|
13379
|
+
}
|
|
13380
|
+
|
|
13381
|
+
// Rounds to the nearest integer in [0, max]; NaN (invalid input) gives 0
|
|
13382
|
+
function roundClamp(n, max) {
|
|
13383
|
+
if (!(n >= 0.0)) {
|
|
13384
|
+
return 0;
|
|
13385
|
+
}
|
|
13386
|
+
if (n > max) {
|
|
13387
|
+
return max;
|
|
13388
|
+
}
|
|
13389
|
+
return Math.floor(n + 0.5);
|
|
13390
|
+
}
|
|
13351
13391
|
var Colors = /*#__PURE__*/function () {
|
|
13352
13392
|
function Colors() {
|
|
13353
13393
|
_classCallCheck(this, Colors);
|
|
13354
13394
|
}
|
|
13355
13395
|
return _createClass(Colors, null, [{
|
|
13396
|
+
key: "d50WhitePointXYZ",
|
|
13397
|
+
value:
|
|
13398
|
+
/**
|
|
13399
|
+
* White point of the D50 illuminant (ICC PCS), the reference white of
|
|
13400
|
+
* DICOM CIELab. Use this white with the XYZ values of rgb2XYZ, xyz2RGB,
|
|
13401
|
+
* lab2XYZ and xyz2LAB.
|
|
13402
|
+
*/
|
|
13403
|
+
function d50WhitePointXYZ() {
|
|
13404
|
+
return [].concat(D50_WHITEPOINT_XYZ);
|
|
13405
|
+
}
|
|
13406
|
+
|
|
13407
|
+
/**
|
|
13408
|
+
* White point of the D65 illuminant, the native white of sRGB. No
|
|
13409
|
+
* conversion in this class uses it. Do not combine it with the XYZ
|
|
13410
|
+
* values of this class, which are relative to D50.
|
|
13411
|
+
*/
|
|
13412
|
+
}, {
|
|
13356
13413
|
key: "d65WhitePointXYZ",
|
|
13357
13414
|
value: function d65WhitePointXYZ() {
|
|
13358
|
-
|
|
13359
|
-
return [0.950456, 1.0, 1.088754];
|
|
13415
|
+
return [].concat(D65_WHITEPOINT_XYZ);
|
|
13360
13416
|
}
|
|
13361
13417
|
}, {
|
|
13362
13418
|
key: "dicomlab2RGB",
|
|
@@ -13368,6 +13424,26 @@ var Colors = /*#__PURE__*/function () {
|
|
|
13368
13424
|
value: function rgb2DICOMLAB(rgb) {
|
|
13369
13425
|
return Colors.lab2DICOMLAB(Colors.rgb2LAB(rgb));
|
|
13370
13426
|
}
|
|
13427
|
+
|
|
13428
|
+
// 16 bit DICOM CIELab -> 8 bit sRGB, rounded and clamped
|
|
13429
|
+
}, {
|
|
13430
|
+
key: "dicomlab2RGB8",
|
|
13431
|
+
value: function dicomlab2RGB8(dicomlab) {
|
|
13432
|
+
return Colors.dicomlab2RGB(dicomlab).map(function (n) {
|
|
13433
|
+
return roundClamp(n * 255.0, 255);
|
|
13434
|
+
});
|
|
13435
|
+
}
|
|
13436
|
+
|
|
13437
|
+
// 8 bit sRGB (array or typed array) -> 16 bit DICOM CIELab, rounded and clamped
|
|
13438
|
+
}, {
|
|
13439
|
+
key: "rgb82DICOMLAB",
|
|
13440
|
+
value: function rgb82DICOMLAB(rgb) {
|
|
13441
|
+
return Colors.rgb2DICOMLAB(Array.from(rgb, function (n) {
|
|
13442
|
+
return n / 255.0;
|
|
13443
|
+
})).map(function (n) {
|
|
13444
|
+
return roundClamp(n, 65535);
|
|
13445
|
+
});
|
|
13446
|
+
}
|
|
13371
13447
|
}, {
|
|
13372
13448
|
key: "dicomlab2LAB",
|
|
13373
13449
|
value: function dicomlab2LAB(dicomlab) {
|
|
@@ -13396,7 +13472,8 @@ var Colors = /*#__PURE__*/function () {
|
|
|
13396
13472
|
}, {
|
|
13397
13473
|
key: "gammaCorrection",
|
|
13398
13474
|
value: function gammaCorrection(n) {
|
|
13399
|
-
|
|
13475
|
+
// sRGB transfer function (IEC 61966-2-1), linear to gamma-encoded
|
|
13476
|
+
if (n <= 0.0031308) {
|
|
13400
13477
|
return 12.92 * n;
|
|
13401
13478
|
} else {
|
|
13402
13479
|
return 1.055 * Math.pow(n, 1 / 2.4) - 0.055;
|
|
@@ -13405,27 +13482,39 @@ var Colors = /*#__PURE__*/function () {
|
|
|
13405
13482
|
}, {
|
|
13406
13483
|
key: "invGammaCorrection",
|
|
13407
13484
|
value: function invGammaCorrection(n) {
|
|
13408
|
-
|
|
13485
|
+
// sRGB transfer function (IEC 61966-2-1), gamma-encoded to linear
|
|
13486
|
+
if (n <= 0.04045) {
|
|
13409
13487
|
return n / 12.92;
|
|
13410
13488
|
} else {
|
|
13411
13489
|
return Math.pow((n + 0.055) / 1.055, 2.4);
|
|
13412
13490
|
}
|
|
13413
13491
|
}
|
|
13492
|
+
|
|
13493
|
+
// sRGB -> CIE XYZ relative to D50, as DICOM CIELab requires (not D65)
|
|
13414
13494
|
}, {
|
|
13415
13495
|
key: "rgb2XYZ",
|
|
13416
13496
|
value: function rgb2XYZ(rgb) {
|
|
13497
|
+
// sRGB to linear RGB
|
|
13417
13498
|
var R = Colors.invGammaCorrection(rgb[0]);
|
|
13418
13499
|
var G = Colors.invGammaCorrection(rgb[1]);
|
|
13419
13500
|
var B = Colors.invGammaCorrection(rgb[2]);
|
|
13420
|
-
|
|
13501
|
+
|
|
13502
|
+
// linear RGB to CIE XYZ (D65)
|
|
13503
|
+
var X65 = 506752.0 / 1228815.0 * R + 87881.0 / 245763.0 * G + 12673.0 / 70218.0 * B;
|
|
13504
|
+
var Y65 = 87098.0 / 409605.0 * R + 175762.0 / 245763.0 * G + 12673.0 / 175545.0 * B;
|
|
13505
|
+
var Z65 = 7918.0 / 409605.0 * R + 87881.0 / 737289.0 * G + 1001167.0 / 1053270.0 * B;
|
|
13506
|
+
|
|
13507
|
+
// chromatic adaptation D65 to D50 (linear Bradford)
|
|
13508
|
+
return [1.0479297925449969 * X65 + 0.022946870601609652 * Y65 - 0.05019226628920524 * Z65, 0.02962780877005599 * X65 + 0.9904344267538799 * Y65 - 0.017073799063418826 * Z65, -0.009243040646204504 * X65 + 0.015055191490298152 * Y65 + 0.7518742814281371 * Z65];
|
|
13421
13509
|
}
|
|
13510
|
+
|
|
13511
|
+
// CIE XYZ relative to D50 -> CIELab
|
|
13422
13512
|
}, {
|
|
13423
13513
|
key: "xyz2LAB",
|
|
13424
13514
|
value: function xyz2LAB(xyz) {
|
|
13425
|
-
var
|
|
13426
|
-
var
|
|
13427
|
-
var
|
|
13428
|
-
var Z = xyz[2] / whitePoint[2];
|
|
13515
|
+
var X = xyz[0] / D50_WHITEPOINT_XYZ[0];
|
|
13516
|
+
var Y = xyz[1] / D50_WHITEPOINT_XYZ[1];
|
|
13517
|
+
var Z = xyz[2] / D50_WHITEPOINT_XYZ[2];
|
|
13429
13518
|
X = Colors.labf(X);
|
|
13430
13519
|
Y = Colors.labf(Y);
|
|
13431
13520
|
Z = Colors.labf(Z);
|
|
@@ -13436,50 +13525,58 @@ var Colors = /*#__PURE__*/function () {
|
|
|
13436
13525
|
value: function lab2RGB(lab) {
|
|
13437
13526
|
return Colors.xyz2RGB(Colors.lab2XYZ(lab));
|
|
13438
13527
|
}
|
|
13528
|
+
|
|
13529
|
+
// CIELab -> CIE XYZ relative to D50
|
|
13439
13530
|
}, {
|
|
13440
13531
|
key: "lab2XYZ",
|
|
13441
13532
|
value: function lab2XYZ(lab) {
|
|
13442
13533
|
var L = (lab[0] + 16) / 116;
|
|
13443
13534
|
var a = L + lab[1] / 500;
|
|
13444
13535
|
var b = L - lab[2] / 200;
|
|
13445
|
-
|
|
13446
|
-
return [whitePoint[0] * Colors.labfInv(a), whitePoint[1] * Colors.labfInv(L), whitePoint[2] * Colors.labfInv(b)];
|
|
13536
|
+
return [D50_WHITEPOINT_XYZ[0] * Colors.labfInv(a), D50_WHITEPOINT_XYZ[1] * Colors.labfInv(L), D50_WHITEPOINT_XYZ[2] * Colors.labfInv(b)];
|
|
13447
13537
|
}
|
|
13538
|
+
|
|
13539
|
+
// CIE XYZ relative to D50 -> sRGB, clipped per channel to [0, 1]
|
|
13448
13540
|
}, {
|
|
13449
13541
|
key: "xyz2RGB",
|
|
13450
13542
|
value: function xyz2RGB(xyz) {
|
|
13451
|
-
var
|
|
13452
|
-
|
|
13453
|
-
|
|
13543
|
+
var _xyz = _slicedToArray(xyz, 3),
|
|
13544
|
+
X = _xyz[0],
|
|
13545
|
+
Y = _xyz[1],
|
|
13546
|
+
Z = _xyz[2];
|
|
13454
13547
|
|
|
13455
|
-
|
|
13456
|
-
var
|
|
13457
|
-
|
|
13458
|
-
|
|
13459
|
-
R1 -= minimumComponent;
|
|
13460
|
-
G1 -= minimumComponent;
|
|
13461
|
-
B1 -= minimumComponent;
|
|
13462
|
-
}
|
|
13548
|
+
// chromatic adaptation D50 to D65 (linear Bradford)
|
|
13549
|
+
var X65 = 0.955473421488075 * X - 0.02309845494876471 * Y + 0.06325924320057072 * Z;
|
|
13550
|
+
var Y65 = -0.0283697093338637 * X + 1.0099953980813041 * Y + 0.021041441191917323 * Z;
|
|
13551
|
+
var Z65 = 0.012314014864481998 * X - 0.020507649298898964 * Y + 1.330365926242124 * Z;
|
|
13463
13552
|
|
|
13464
|
-
|
|
13465
|
-
|
|
13553
|
+
// CIE XYZ (D65) to linear RGB
|
|
13554
|
+
var R1 = 12831.0 / 3959.0 * X65 - 329.0 / 214.0 * Y65 - 1974.0 / 3959.0 * Z65;
|
|
13555
|
+
var G1 = -851781 / 878810.0 * X65 + 1648619.0 / 878810.0 * Y65 + 36519.0 / 878810.0 * Z65;
|
|
13556
|
+
var B1 = 705.0 / 12673.0 * X65 - 2585.0 / 12673.0 * Y65 + 705.0 / 667.0 * Z65;
|
|
13557
|
+
|
|
13558
|
+
// Clip to the sRGB gamut (also makes sure that gamma encoding is
|
|
13559
|
+
// well-defined), then transform from linear RGB to sRGB
|
|
13560
|
+
return [Colors.gammaCorrection(clamp01(R1)), Colors.gammaCorrection(clamp01(G1)), Colors.gammaCorrection(clamp01(B1))];
|
|
13466
13561
|
}
|
|
13467
13562
|
}, {
|
|
13468
13563
|
key: "labf",
|
|
13469
13564
|
value: function labf(n) {
|
|
13470
|
-
|
|
13471
|
-
|
|
13565
|
+
// epsilon = (6/29)^3 = 216/24389, kappa = (29/3)^3 = 24389/27
|
|
13566
|
+
if (n > 216.0 / 24389.0) {
|
|
13567
|
+
return Math.cbrt(n);
|
|
13472
13568
|
} else {
|
|
13473
|
-
return
|
|
13569
|
+
return (24389.0 / 27.0 * n + 16.0) / 116.0;
|
|
13474
13570
|
}
|
|
13475
13571
|
}
|
|
13476
13572
|
}, {
|
|
13477
13573
|
key: "labfInv",
|
|
13478
13574
|
value: function labfInv(n) {
|
|
13479
|
-
|
|
13575
|
+
// n > 6/29 <=> n^3 > epsilon
|
|
13576
|
+
if (n > 6.0 / 29.0) {
|
|
13480
13577
|
return n * n * n;
|
|
13481
13578
|
} else {
|
|
13482
|
-
return
|
|
13579
|
+
return (116.0 * n - 16.0) / (24389.0 / 27.0);
|
|
13483
13580
|
}
|
|
13484
13581
|
}
|
|
13485
13582
|
}]);
|
|
@@ -24340,12 +24437,8 @@ var Cornerstone3D = {
|
|
|
24340
24437
|
CORNERSTONE_3D_TAG: CORNERSTONE_3D_TAG
|
|
24341
24438
|
};
|
|
24342
24439
|
|
|
24343
|
-
// TODO: Is there a better name for this? RGBAInt?
|
|
24344
|
-
// Should we move it to Colors.js
|
|
24345
24440
|
function dicomlab2RGBA(cielab) {
|
|
24346
|
-
var rgba = Colors.
|
|
24347
|
-
return Math.round(x * 255);
|
|
24348
|
-
});
|
|
24441
|
+
var rgba = Colors.dicomlab2RGB8(cielab);
|
|
24349
24442
|
rgba.push(255);
|
|
24350
24443
|
return rgba;
|
|
24351
24444
|
}
|