@dcmjs-org/dcmjs 1.0.0-beta.16 → 1.0.0-beta.17
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.cjs +1 -1
- package/build/dcmjs.es.js +1 -1
- package/build/dcmjs.js +130 -40
- package/build/dcmjs.js.map +1 -1
- package/build/dcmjs.min.js +1 -1
- package/build/dcmjs.min.js.map +1 -1
- package/build/{dcmjs.shared-D1MD8zKQ.cjs → dcmjs.shared---E7clvy.cjs} +117 -40
- package/build/dcmjs.shared---E7clvy.cjs.map +1 -0
- package/build/{dcmjs.shared-B2D8KPlB.js → dcmjs.shared-Cy_BdC0f.js} +117 -40
- package/build/dcmjs.shared-Cy_BdC0f.js.map +1 -0
- package/build/eventStream.cjs +1 -1
- package/build/eventStream.es.js +1 -1
- package/package.json +8 -8
- package/build/dcmjs.shared-B2D8KPlB.js.map +0 -1
- package/build/dcmjs.shared-D1MD8zKQ.cjs.map +0 -1
package/build/dcmjs.cjs
CHANGED
package/build/dcmjs.es.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { D as DICOMWEB, j as adapters, k as anonymizer, l as async, m as constants, n as data, o as default, p as derivations, q as normalizers, s as sr, u as utilities } from './dcmjs.shared-
|
|
1
|
+
export { D as DICOMWEB, j as adapters, k as anonymizer, l as async, m as constants, n as data, o as default, p as derivations, q as normalizers, s as sr, u as utilities } from './dcmjs.shared-Cy_BdC0f.js';
|
|
2
2
|
export { log } from '@dcmjs-org/core';
|
|
3
3
|
//# sourceMappingURL=dcmjs.es.js.map
|
package/build/dcmjs.js
CHANGED
|
@@ -7759,7 +7759,12 @@
|
|
|
7759
7759
|
value: function slice() {
|
|
7760
7760
|
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
7761
7761
|
var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size;
|
|
7762
|
-
|
|
7762
|
+
// Clamp to the data held, as ArrayBuffer.prototype.slice does.
|
|
7763
|
+
// https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
|
|
7764
|
+
if (end > this.byteLength) {
|
|
7765
|
+
end = this.byteLength;
|
|
7766
|
+
}
|
|
7767
|
+
if (end <= start) {
|
|
7763
7768
|
return new Uint8Array(0).buffer;
|
|
7764
7769
|
}
|
|
7765
7770
|
var index = this.findStart(start);
|
|
@@ -10495,6 +10500,14 @@
|
|
|
10495
10500
|
} else if (this.type == 'OB') {
|
|
10496
10501
|
bytes = stream.readUint8Array(length);
|
|
10497
10502
|
}*/
|
|
10503
|
+
// A declared length longer than the data present means a
|
|
10504
|
+
// truncated or malformed file: read the bytes that are present.
|
|
10505
|
+
// https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
|
|
10506
|
+
var available = stream.endOffset - stream.offset;
|
|
10507
|
+
if (length > available) {
|
|
10508
|
+
validationLog.warn("".concat(this.type, " value declares ").concat(length, " bytes but only ").concat(available, " are available - reading the available bytes"));
|
|
10509
|
+
length = available;
|
|
10510
|
+
}
|
|
10498
10511
|
bytes = stream.getBuffer(stream.offset, stream.offset + length);
|
|
10499
10512
|
stream.increment(length);
|
|
10500
10513
|
return [bytes];
|
|
@@ -16410,25 +16423,65 @@
|
|
|
16410
16423
|
//
|
|
16411
16424
|
// Handle DICOM and CIELAB colors
|
|
16412
16425
|
// based on:
|
|
16413
|
-
// https://github.com/
|
|
16426
|
+
// https://github.com/DCMTK/dcmtk/blob/88105877c3b610e23fc9422ba6a84af85552f5dd/dcmiod/libsrc/cielabutil.cc
|
|
16414
16427
|
//
|
|
16415
16428
|
// RGB here refers to sRGB 0-1 per component.
|
|
16416
16429
|
// dicomlab is CIELAB values as defined in the dicom standard
|
|
16417
|
-
// XYZ is CIEXYZ convention
|
|
16418
|
-
//
|
|
16419
|
-
// TODO: needs a test suite
|
|
16420
|
-
// TODO: only dicomlab2RGB tested on real data
|
|
16430
|
+
// XYZ is CIEXYZ convention, relative to the D50 white point (ICC PCS)
|
|
16421
16431
|
//
|
|
16432
|
+
// DICOM encodes CIELab values in the same way as the ICC Profile Connection
|
|
16433
|
+
// Space (PCS, see PS3.3 C.10.7.1.1), i.e. relative to the D50 illuminant,
|
|
16434
|
+
// whereas the native white point of sRGB is D65. The conversions below
|
|
16435
|
+
// therefore chromatically adapt between the two using the linear Bradford
|
|
16436
|
+
// transform. Matrices and constants are those of the CSS Color Module Level 4
|
|
16437
|
+
// sample code (https://www.w3.org/TR/css-color-4/#color-conversion-code).
|
|
16422
16438
|
//
|
|
16439
|
+
|
|
16440
|
+
// White points, defined by their 4-figure CIE x,y chromaticities.
|
|
16441
|
+
// D50 is intentionally [0.96430, 1, 0.82510] and not the ICC.1 PCS illuminant
|
|
16442
|
+
// [0.9642, 1, 0.8249]: this matches DCMTK, highdicom and CSS Color 4, and
|
|
16443
|
+
// encodes sRGB white as exactly 0x8080 in a* and b*.
|
|
16444
|
+
var D50_WHITEPOINT_XYZ = [0.3457 / 0.3585, 1.0, (1.0 - 0.3457 - 0.3585) / 0.3585];
|
|
16445
|
+
var D65_WHITEPOINT_XYZ = [0.3127 / 0.329, 1.0, (1.0 - 0.3127 - 0.329) / 0.329];
|
|
16446
|
+
function clamp01(n) {
|
|
16447
|
+
return Math.min(1.0, Math.max(0.0, n));
|
|
16448
|
+
}
|
|
16449
|
+
|
|
16450
|
+
// Rounds to the nearest integer in [0, max]; NaN (invalid input) gives 0
|
|
16451
|
+
function roundClamp(n, max) {
|
|
16452
|
+
if (!(n >= 0.0)) {
|
|
16453
|
+
return 0;
|
|
16454
|
+
}
|
|
16455
|
+
if (n > max) {
|
|
16456
|
+
return max;
|
|
16457
|
+
}
|
|
16458
|
+
return Math.floor(n + 0.5);
|
|
16459
|
+
}
|
|
16423
16460
|
var Colors = /*#__PURE__*/function () {
|
|
16424
16461
|
function Colors() {
|
|
16425
16462
|
_classCallCheck(this, Colors);
|
|
16426
16463
|
}
|
|
16427
16464
|
return _createClass(Colors, null, [{
|
|
16465
|
+
key: "d50WhitePointXYZ",
|
|
16466
|
+
value:
|
|
16467
|
+
/**
|
|
16468
|
+
* White point of the D50 illuminant (ICC PCS), the reference white of
|
|
16469
|
+
* DICOM CIELab. Use this white with the XYZ values of rgb2XYZ, xyz2RGB,
|
|
16470
|
+
* lab2XYZ and xyz2LAB.
|
|
16471
|
+
*/
|
|
16472
|
+
function d50WhitePointXYZ() {
|
|
16473
|
+
return [].concat(D50_WHITEPOINT_XYZ);
|
|
16474
|
+
}
|
|
16475
|
+
|
|
16476
|
+
/**
|
|
16477
|
+
* White point of the D65 illuminant, the native white of sRGB. No
|
|
16478
|
+
* conversion in this class uses it. Do not combine it with the XYZ
|
|
16479
|
+
* values of this class, which are relative to D50.
|
|
16480
|
+
*/
|
|
16481
|
+
}, {
|
|
16428
16482
|
key: "d65WhitePointXYZ",
|
|
16429
16483
|
value: function d65WhitePointXYZ() {
|
|
16430
|
-
|
|
16431
|
-
return [0.950456, 1.0, 1.088754];
|
|
16484
|
+
return [].concat(D65_WHITEPOINT_XYZ);
|
|
16432
16485
|
}
|
|
16433
16486
|
}, {
|
|
16434
16487
|
key: "dicomlab2RGB",
|
|
@@ -16440,6 +16493,26 @@
|
|
|
16440
16493
|
value: function rgb2DICOMLAB(rgb) {
|
|
16441
16494
|
return Colors.lab2DICOMLAB(Colors.rgb2LAB(rgb));
|
|
16442
16495
|
}
|
|
16496
|
+
|
|
16497
|
+
// 16 bit DICOM CIELab -> 8 bit sRGB, rounded and clamped
|
|
16498
|
+
}, {
|
|
16499
|
+
key: "dicomlab2RGB8",
|
|
16500
|
+
value: function dicomlab2RGB8(dicomlab) {
|
|
16501
|
+
return Colors.dicomlab2RGB(dicomlab).map(function (n) {
|
|
16502
|
+
return roundClamp(n * 255.0, 255);
|
|
16503
|
+
});
|
|
16504
|
+
}
|
|
16505
|
+
|
|
16506
|
+
// 8 bit sRGB (array or typed array) -> 16 bit DICOM CIELab, rounded and clamped
|
|
16507
|
+
}, {
|
|
16508
|
+
key: "rgb82DICOMLAB",
|
|
16509
|
+
value: function rgb82DICOMLAB(rgb) {
|
|
16510
|
+
return Colors.rgb2DICOMLAB(Array.from(rgb, function (n) {
|
|
16511
|
+
return n / 255.0;
|
|
16512
|
+
})).map(function (n) {
|
|
16513
|
+
return roundClamp(n, 65535);
|
|
16514
|
+
});
|
|
16515
|
+
}
|
|
16443
16516
|
}, {
|
|
16444
16517
|
key: "dicomlab2LAB",
|
|
16445
16518
|
value: function dicomlab2LAB(dicomlab) {
|
|
@@ -16468,7 +16541,8 @@
|
|
|
16468
16541
|
}, {
|
|
16469
16542
|
key: "gammaCorrection",
|
|
16470
16543
|
value: function gammaCorrection(n) {
|
|
16471
|
-
|
|
16544
|
+
// sRGB transfer function (IEC 61966-2-1), linear to gamma-encoded
|
|
16545
|
+
if (n <= 0.0031308) {
|
|
16472
16546
|
return 12.92 * n;
|
|
16473
16547
|
} else {
|
|
16474
16548
|
return 1.055 * Math.pow(n, 1 / 2.4) - 0.055;
|
|
@@ -16477,27 +16551,39 @@
|
|
|
16477
16551
|
}, {
|
|
16478
16552
|
key: "invGammaCorrection",
|
|
16479
16553
|
value: function invGammaCorrection(n) {
|
|
16480
|
-
|
|
16554
|
+
// sRGB transfer function (IEC 61966-2-1), gamma-encoded to linear
|
|
16555
|
+
if (n <= 0.04045) {
|
|
16481
16556
|
return n / 12.92;
|
|
16482
16557
|
} else {
|
|
16483
16558
|
return Math.pow((n + 0.055) / 1.055, 2.4);
|
|
16484
16559
|
}
|
|
16485
16560
|
}
|
|
16561
|
+
|
|
16562
|
+
// sRGB -> CIE XYZ relative to D50, as DICOM CIELab requires (not D65)
|
|
16486
16563
|
}, {
|
|
16487
16564
|
key: "rgb2XYZ",
|
|
16488
16565
|
value: function rgb2XYZ(rgb) {
|
|
16566
|
+
// sRGB to linear RGB
|
|
16489
16567
|
var R = Colors.invGammaCorrection(rgb[0]);
|
|
16490
16568
|
var G = Colors.invGammaCorrection(rgb[1]);
|
|
16491
16569
|
var B = Colors.invGammaCorrection(rgb[2]);
|
|
16492
|
-
|
|
16570
|
+
|
|
16571
|
+
// linear RGB to CIE XYZ (D65)
|
|
16572
|
+
var X65 = 506752.0 / 1228815.0 * R + 87881.0 / 245763.0 * G + 12673.0 / 70218.0 * B;
|
|
16573
|
+
var Y65 = 87098.0 / 409605.0 * R + 175762.0 / 245763.0 * G + 12673.0 / 175545.0 * B;
|
|
16574
|
+
var Z65 = 7918.0 / 409605.0 * R + 87881.0 / 737289.0 * G + 1001167.0 / 1053270.0 * B;
|
|
16575
|
+
|
|
16576
|
+
// chromatic adaptation D65 to D50 (linear Bradford)
|
|
16577
|
+
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];
|
|
16493
16578
|
}
|
|
16579
|
+
|
|
16580
|
+
// CIE XYZ relative to D50 -> CIELab
|
|
16494
16581
|
}, {
|
|
16495
16582
|
key: "xyz2LAB",
|
|
16496
16583
|
value: function xyz2LAB(xyz) {
|
|
16497
|
-
var
|
|
16498
|
-
var
|
|
16499
|
-
var
|
|
16500
|
-
var Z = xyz[2] / whitePoint[2];
|
|
16584
|
+
var X = xyz[0] / D50_WHITEPOINT_XYZ[0];
|
|
16585
|
+
var Y = xyz[1] / D50_WHITEPOINT_XYZ[1];
|
|
16586
|
+
var Z = xyz[2] / D50_WHITEPOINT_XYZ[2];
|
|
16501
16587
|
X = Colors.labf(X);
|
|
16502
16588
|
Y = Colors.labf(Y);
|
|
16503
16589
|
Z = Colors.labf(Z);
|
|
@@ -16508,50 +16594,58 @@
|
|
|
16508
16594
|
value: function lab2RGB(lab) {
|
|
16509
16595
|
return Colors.xyz2RGB(Colors.lab2XYZ(lab));
|
|
16510
16596
|
}
|
|
16597
|
+
|
|
16598
|
+
// CIELab -> CIE XYZ relative to D50
|
|
16511
16599
|
}, {
|
|
16512
16600
|
key: "lab2XYZ",
|
|
16513
16601
|
value: function lab2XYZ(lab) {
|
|
16514
16602
|
var L = (lab[0] + 16) / 116;
|
|
16515
16603
|
var a = L + lab[1] / 500;
|
|
16516
16604
|
var b = L - lab[2] / 200;
|
|
16517
|
-
|
|
16518
|
-
return [whitePoint[0] * Colors.labfInv(a), whitePoint[1] * Colors.labfInv(L), whitePoint[2] * Colors.labfInv(b)];
|
|
16605
|
+
return [D50_WHITEPOINT_XYZ[0] * Colors.labfInv(a), D50_WHITEPOINT_XYZ[1] * Colors.labfInv(L), D50_WHITEPOINT_XYZ[2] * Colors.labfInv(b)];
|
|
16519
16606
|
}
|
|
16607
|
+
|
|
16608
|
+
// CIE XYZ relative to D50 -> sRGB, clipped per channel to [0, 1]
|
|
16520
16609
|
}, {
|
|
16521
16610
|
key: "xyz2RGB",
|
|
16522
16611
|
value: function xyz2RGB(xyz) {
|
|
16523
|
-
var
|
|
16524
|
-
|
|
16525
|
-
|
|
16612
|
+
var _xyz = _slicedToArray(xyz, 3),
|
|
16613
|
+
X = _xyz[0],
|
|
16614
|
+
Y = _xyz[1],
|
|
16615
|
+
Z = _xyz[2];
|
|
16526
16616
|
|
|
16527
|
-
|
|
16528
|
-
var
|
|
16529
|
-
|
|
16530
|
-
|
|
16531
|
-
R1 -= minimumComponent;
|
|
16532
|
-
G1 -= minimumComponent;
|
|
16533
|
-
B1 -= minimumComponent;
|
|
16534
|
-
}
|
|
16617
|
+
// chromatic adaptation D50 to D65 (linear Bradford)
|
|
16618
|
+
var X65 = 0.955473421488075 * X - 0.02309845494876471 * Y + 0.06325924320057072 * Z;
|
|
16619
|
+
var Y65 = -0.0283697093338637 * X + 1.0099953980813041 * Y + 0.021041441191917323 * Z;
|
|
16620
|
+
var Z65 = 0.012314014864481998 * X - 0.020507649298898964 * Y + 1.330365926242124 * Z;
|
|
16535
16621
|
|
|
16536
|
-
|
|
16537
|
-
|
|
16622
|
+
// CIE XYZ (D65) to linear RGB
|
|
16623
|
+
var R1 = 12831.0 / 3959.0 * X65 - 329.0 / 214.0 * Y65 - 1974.0 / 3959.0 * Z65;
|
|
16624
|
+
var G1 = -851781 / 878810.0 * X65 + 1648619.0 / 878810.0 * Y65 + 36519.0 / 878810.0 * Z65;
|
|
16625
|
+
var B1 = 705.0 / 12673.0 * X65 - 2585.0 / 12673.0 * Y65 + 705.0 / 667.0 * Z65;
|
|
16626
|
+
|
|
16627
|
+
// Clip to the sRGB gamut (also makes sure that gamma encoding is
|
|
16628
|
+
// well-defined), then transform from linear RGB to sRGB
|
|
16629
|
+
return [Colors.gammaCorrection(clamp01(R1)), Colors.gammaCorrection(clamp01(G1)), Colors.gammaCorrection(clamp01(B1))];
|
|
16538
16630
|
}
|
|
16539
16631
|
}, {
|
|
16540
16632
|
key: "labf",
|
|
16541
16633
|
value: function labf(n) {
|
|
16542
|
-
|
|
16543
|
-
|
|
16634
|
+
// epsilon = (6/29)^3 = 216/24389, kappa = (29/3)^3 = 24389/27
|
|
16635
|
+
if (n > 216.0 / 24389.0) {
|
|
16636
|
+
return Math.cbrt(n);
|
|
16544
16637
|
} else {
|
|
16545
|
-
return
|
|
16638
|
+
return (24389.0 / 27.0 * n + 16.0) / 116.0;
|
|
16546
16639
|
}
|
|
16547
16640
|
}
|
|
16548
16641
|
}, {
|
|
16549
16642
|
key: "labfInv",
|
|
16550
16643
|
value: function labfInv(n) {
|
|
16551
|
-
|
|
16644
|
+
// n > 6/29 <=> n^3 > epsilon
|
|
16645
|
+
if (n > 6.0 / 29.0) {
|
|
16552
16646
|
return n * n * n;
|
|
16553
16647
|
} else {
|
|
16554
|
-
return
|
|
16648
|
+
return (116.0 * n - 16.0) / (24389.0 / 27.0);
|
|
16555
16649
|
}
|
|
16556
16650
|
}
|
|
16557
16651
|
}]);
|
|
@@ -27053,12 +27147,8 @@
|
|
|
27053
27147
|
CORNERSTONE_3D_TAG: CORNERSTONE_3D_TAG
|
|
27054
27148
|
};
|
|
27055
27149
|
|
|
27056
|
-
// TODO: Is there a better name for this? RGBAInt?
|
|
27057
|
-
// Should we move it to Colors.js
|
|
27058
27150
|
function dicomlab2RGBA(cielab) {
|
|
27059
|
-
var rgba = Colors.
|
|
27060
|
-
return Math.round(x * 255);
|
|
27061
|
-
});
|
|
27151
|
+
var rgba = Colors.dicomlab2RGB8(cielab);
|
|
27062
27152
|
rgba.push(255);
|
|
27063
27153
|
return rgba;
|
|
27064
27154
|
}
|