@cornerstonejs/core 2.18.7 → 2.18.9

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.
@@ -7,6 +7,7 @@ import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
7
7
  import { Representation } from '@kitware/vtk.js/Rendering/Core/Property/Constants';
8
8
  import vtkOpenGLTexture from '@kitware/vtk.js/Rendering/OpenGL/Texture';
9
9
  import { getConstructorFromType } from '../../utilities/getBufferConfiguration';
10
+ import { getCanUseNorm16Texture } from '../../init';
10
11
  function vtkStreamingOpenGLVolumeMapper(publicAPI, model) {
11
12
  model.classHierarchy.push('vtkStreamingOpenGLVolumeMapper');
12
13
  publicAPI.buildBufferObjects = (ren, actor) => {
@@ -132,7 +133,7 @@ function vtkStreamingOpenGLVolumeMapper(publicAPI, model) {
132
133
  }
133
134
  if (shouldReset) {
134
135
  const norm16Ext = model.context.getExtension('EXT_texture_norm16');
135
- model.scalarTexture.setOglNorm16Ext(norm16Ext);
136
+ model.scalarTexture.setOglNorm16Ext(getCanUseNorm16Texture() ? norm16Ext : null);
136
137
  model.scalarTexture.resetFormatAndType();
137
138
  model.scalarTexture.setTextureParameters({
138
139
  width: dims[0],
@@ -1,5 +1,6 @@
1
1
  import type { Cornerstone3DConfig } from './types';
2
2
  declare function init(configuration?: Cornerstone3DConfig): boolean;
3
+ declare function getCanUseNorm16Texture(): boolean;
3
4
  declare function setUseCPURendering(status: boolean, updateViewports?: boolean): void;
4
5
  declare function setPreferSizeOverAccuracy(status: boolean): void;
5
6
  declare function canRenderFloatTextures(): boolean;
@@ -11,4 +12,4 @@ declare function getConfiguration(): Cornerstone3DConfig;
11
12
  declare function setConfiguration(c: Cornerstone3DConfig): void;
12
13
  declare function getWebWorkerManager(): any;
13
14
  declare function peerImport(moduleId: string): Promise<any>;
14
- export { init, getShouldUseCPURendering, isCornerstoneInitialized, setUseCPURendering, setPreferSizeOverAccuracy, resetUseCPURendering, getConfiguration, setConfiguration, getWebWorkerManager, canRenderFloatTextures, peerImport, resetInitialization, };
15
+ export { init, getShouldUseCPURendering, isCornerstoneInitialized, setUseCPURendering, setPreferSizeOverAccuracy, resetUseCPURendering, getConfiguration, setConfiguration, getWebWorkerManager, canRenderFloatTextures, peerImport, resetInitialization, getCanUseNorm16Texture, };
package/dist/esm/init.js CHANGED
@@ -2,6 +2,7 @@ import { getRenderingEngines } from './RenderingEngine/getRenderingEngine';
2
2
  let csRenderInitialized = false;
3
3
  import deepMerge from './utilities/deepMerge';
4
4
  import CentralizedWebWorkerManager from './webWorkerManager/webWorkerManager';
5
+ import { getSupportedTextureFormats } from './utilities/textureSupport';
5
6
  const defaultConfig = {
6
7
  gpuTier: { tier: 2 },
7
8
  isMobile: false,
@@ -17,6 +18,7 @@ let config = {
17
18
  rendering: { ...defaultConfig.rendering },
18
19
  };
19
20
  let webWorkerManager = null;
21
+ let canUseNorm16Texture = false;
20
22
  function _getGLContext() {
21
23
  const canvas = document.createElement('canvas');
22
24
  const gl = canvas.getContext('webgl2') ||
@@ -29,14 +31,8 @@ function _hasActiveWebGLContext() {
29
31
  return (gl instanceof WebGLRenderingContext || gl instanceof WebGL2RenderingContext);
30
32
  }
31
33
  function _hasNorm16TextureSupport() {
32
- const gl = _getGLContext();
33
- if (gl) {
34
- const ext = gl.getExtension('EXT_texture_norm16');
35
- if (ext) {
36
- return true;
37
- }
38
- }
39
- return false;
34
+ const supportedTextureFormats = getSupportedTextureFormats();
35
+ return supportedTextureFormats.norm16 && supportedTextureFormats.norm16Linear;
40
36
  }
41
37
  function isIOS() {
42
38
  if (/iPad|iPhone|iPod/.test(navigator.platform)) {
@@ -52,6 +48,7 @@ function init(configuration = config) {
52
48
  if (csRenderInitialized) {
53
49
  return csRenderInitialized;
54
50
  }
51
+ canUseNorm16Texture = _hasNorm16TextureSupport();
55
52
  config = deepMerge(defaultConfig, configuration);
56
53
  if (isIOS()) {
57
54
  if (configuration.rendering?.preferSizeOverAccuracy) {
@@ -75,6 +72,9 @@ function init(configuration = config) {
75
72
  }
76
73
  return csRenderInitialized;
77
74
  }
75
+ function getCanUseNorm16Texture() {
76
+ return canUseNorm16Texture;
77
+ }
78
78
  function setUseCPURendering(status, updateViewports = true) {
79
79
  config.rendering.useCPURendering = status;
80
80
  csRenderInitialized = true;
@@ -129,4 +129,4 @@ function getWebWorkerManager() {
129
129
  async function peerImport(moduleId) {
130
130
  return config.peerImport(moduleId);
131
131
  }
132
- export { init, getShouldUseCPURendering, isCornerstoneInitialized, setUseCPURendering, setPreferSizeOverAccuracy, resetUseCPURendering, getConfiguration, setConfiguration, getWebWorkerManager, canRenderFloatTextures, peerImport, resetInitialization, };
132
+ export { init, getShouldUseCPURendering, isCornerstoneInitialized, setUseCPURendering, setPreferSizeOverAccuracy, resetUseCPURendering, getConfiguration, setConfiguration, getWebWorkerManager, canRenderFloatTextures, peerImport, resetInitialization, getCanUseNorm16Texture, };
@@ -0,0 +1,4 @@
1
+ export declare function getSupportedTextureFormats(): {
2
+ norm16: boolean;
3
+ norm16Linear: boolean;
4
+ };
@@ -0,0 +1,101 @@
1
+ const canvasSize = 4;
2
+ const texWidth = 5;
3
+ const texHeight = 1;
4
+ const pixelToCheck = [1, 1];
5
+ function main({ ext, filterType, texData, internalFormat, glDataType }) {
6
+ try {
7
+ const canvas = document.createElement('canvas');
8
+ canvas.width = canvasSize;
9
+ canvas.height = canvasSize;
10
+ const gl = canvas.getContext('webgl2');
11
+ if (!gl) {
12
+ return false;
13
+ }
14
+ const vs = `#version 300 es
15
+ void main() {
16
+ gl_PointSize = ${canvasSize.toFixed(1)};
17
+ gl_Position = vec4(0, 0, 0, 1);
18
+ }
19
+ `;
20
+ const fs = `#version 300 es
21
+ precision highp float;
22
+ precision highp int;
23
+ precision highp sampler2D;
24
+
25
+ uniform sampler2D u_image;
26
+
27
+ out vec4 color;
28
+
29
+ void main() {
30
+ vec4 intColor = texture(u_image, gl_PointCoord.xy);
31
+ color = vec4(vec3(intColor.rrr), 1);
32
+ }
33
+ `;
34
+ let extToUse;
35
+ if (ext) {
36
+ extToUse = gl.getExtension(ext);
37
+ if (!extToUse) {
38
+ return false;
39
+ }
40
+ }
41
+ const vertexShader = gl.createShader(gl.VERTEX_SHADER);
42
+ gl.shaderSource(vertexShader, vs);
43
+ gl.compileShader(vertexShader);
44
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
45
+ return false;
46
+ }
47
+ const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
48
+ gl.shaderSource(fragmentShader, fs);
49
+ gl.compileShader(fragmentShader);
50
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
51
+ return false;
52
+ }
53
+ const program = gl.createProgram();
54
+ gl.attachShader(program, vertexShader);
55
+ gl.attachShader(program, fragmentShader);
56
+ gl.linkProgram(program);
57
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
58
+ return false;
59
+ }
60
+ const tex = gl.createTexture();
61
+ gl.bindTexture(gl.TEXTURE_2D, tex);
62
+ gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat(gl, extToUse), texWidth, texHeight, 0, gl.RED, glDataType(gl, extToUse), texData);
63
+ const filter = filterType === 'LINEAR' ? gl.LINEAR : gl.NEAREST;
64
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
65
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
66
+ gl.useProgram(program);
67
+ gl.drawArrays(gl.POINTS, 0, 1);
68
+ const pixel = new Uint8Array(4);
69
+ gl.readPixels(pixelToCheck[0], pixelToCheck[1], 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
70
+ const [r, g, b] = pixel;
71
+ const webglLoseContext = gl.getExtension('WEBGL_lose_context');
72
+ if (webglLoseContext) {
73
+ webglLoseContext.loseContext();
74
+ }
75
+ return r === g && g === b && r !== 0;
76
+ }
77
+ catch (e) {
78
+ return false;
79
+ }
80
+ }
81
+ export function getSupportedTextureFormats() {
82
+ const norm16TexData = new Int16Array([
83
+ 32767, 2000, 3000, 4000, 5000, 16784, 7000, 8000, 9000, 32767,
84
+ ]);
85
+ return {
86
+ norm16: main({
87
+ ext: 'EXT_texture_norm16',
88
+ filterType: 'NEAREST',
89
+ texData: norm16TexData,
90
+ internalFormat: (gl, ext) => ext.R16_SNORM_EXT,
91
+ glDataType: (gl) => gl.SHORT,
92
+ }),
93
+ norm16Linear: main({
94
+ ext: 'EXT_texture_norm16',
95
+ filterType: 'LINEAR',
96
+ texData: norm16TexData,
97
+ internalFormat: (gl, ext) => ext.R16_SNORM_EXT,
98
+ glDataType: (gl) => gl.SHORT,
99
+ }),
100
+ };
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "2.18.7",
3
+ "version": "2.18.9",
4
4
  "description": "Cornerstone3D Core",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -82,5 +82,5 @@
82
82
  "type": "individual",
83
83
  "url": "https://ohif.org/donate"
84
84
  },
85
- "gitHead": "313a569eec20e132ea5f0929e10b34bd5ea63ba2"
85
+ "gitHead": "e3ff43396e9170f4350143ed1f48218c8afb90de"
86
86
  }