@cornerstonejs/core 1.74.2 → 1.74.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "1.74.2",
3
+ "version": "1.74.4",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "type": "individual",
48
48
  "url": "https://ohif.org/donate"
49
49
  },
50
- "gitHead": "1556e7f436257a38321b48c99f0682f82bb25ad0"
50
+ "gitHead": "2671f86e3ff632928128f490ca34dee71074f5ee"
51
51
  }
@@ -38,7 +38,7 @@ class Cache implements ICache {
38
38
  private _imageCacheSize = 0;
39
39
  private _volumeCacheSize = 0;
40
40
  private _maxCacheSize = 3 * ONE_GB;
41
- private _maxInstanceSize = 2 * ONE_GB - 8;
41
+ private _maxInstanceSize = 4 * ONE_GB - 8;
42
42
 
43
43
  constructor() {
44
44
  // used to store object data (contour, surface, etc.)
@@ -12,6 +12,9 @@ import triggerEvent from '../utilities/triggerEvent';
12
12
  import cloneDeep from 'lodash.clonedeep';
13
13
 
14
14
  import {
15
+ createUint16SharedArray,
16
+ createUint8SharedArray,
17
+ createFloat32SharedArray,
15
18
  generateVolumePropsFromImageIds,
16
19
  getBufferConfiguration,
17
20
  uuidv4,
@@ -641,8 +644,24 @@ function generateVolumeScalarData(
641
644
 
642
645
  let volumeScalarData;
643
646
  if (targetBuffer?.sharedArrayBuffer) {
644
- const buffer = new SharedArrayBuffer(numBytes);
645
- volumeScalarData = new TypedArrayConstructor(buffer);
647
+ switch (targetBuffer.type) {
648
+ case 'Float32Array':
649
+ volumeScalarData = createFloat32SharedArray(scalarLength);
650
+ break;
651
+ case 'Uint8Array':
652
+ volumeScalarData = createUint8SharedArray(scalarLength);
653
+ break;
654
+ case 'Uint16Array':
655
+ volumeScalarData = createUint16SharedArray(scalarLength);
656
+ break;
657
+ case 'Int16Array':
658
+ volumeScalarData = createUint16SharedArray(scalarLength);
659
+ break;
660
+ default:
661
+ throw new Error(
662
+ 'generateVolumeScalarData: SharedArrayBuffer is not supported for the specified target buffer type'
663
+ );
664
+ }
646
665
  } else {
647
666
  volumeScalarData = new TypedArrayConstructor(scalarLength);
648
667
  }
@@ -1,6 +1,10 @@
1
- import global from '../global';
2
1
  import { getShouldUseSharedArrayBuffer } from '../init';
3
2
 
3
+ const SMALL_MEMORY_LIMIT = 2 * 1024 * 1024 * 1024 - 2;
4
+ const BIG_MEMORY_LIMIT = SMALL_MEMORY_LIMIT * 2;
5
+ // Wasm page size
6
+ const PAGE_SIZE = 65536;
7
+
4
8
  /**
5
9
  * A helper function that creates a new Float32Array that utilized a shared
6
10
  * array buffer. This allows the array to be updated simultaneously in
@@ -37,9 +41,20 @@ function createFloat32SharedArray(length: number): Float32Array {
37
41
  );
38
42
  }
39
43
 
40
- const sharedArrayBuffer = new SharedArrayBuffer(length * 4);
44
+ const byteLength = length * 4;
41
45
 
42
- return new Float32Array(sharedArrayBuffer);
46
+ if (byteLength < SMALL_MEMORY_LIMIT) {
47
+ const sharedArrayBuffer = new SharedArrayBuffer(byteLength);
48
+ return new Float32Array(sharedArrayBuffer);
49
+ } else if (byteLength < BIG_MEMORY_LIMIT) {
50
+ const pages = Math.ceil(byteLength / PAGE_SIZE);
51
+ const memory = new WebAssembly.Memory({
52
+ initial: pages,
53
+ maximum: pages,
54
+ shared: true,
55
+ });
56
+ return new Float32Array(memory.buffer, 0, length);
57
+ }
43
58
  }
44
59
 
45
60
  export default createFloat32SharedArray;