@cornerstonejs/dicom-image-loader 5.7.3 → 5.8.1

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.
@@ -11,6 +11,7 @@ import decodeJPEGLS from './shared/decoders/decodeJPEGLS.js';
11
11
  import decodeJPEG2000 from './shared/decoders/decodeJPEG2000.js';
12
12
  import decodeHTJ2K from './shared/decoders/decodeHTJ2K.js';
13
13
  import applyModalityLUT from './shared/scaling/scaleArray.js';
14
+ import { setWasmBasePathFromConfig } from './shared/wasmBasePath.js';
14
15
  import getMinMax from './shared/getMinMax.js';
15
16
  import getPixelDataTypeFromMinMax, { validatePixelDataType, } from './shared/getPixelDataTypeFromMinMax.js';
16
17
  import isColorImage from './shared/isColorImage.js';
@@ -203,6 +204,7 @@ function scaleImageFrame(imageFrame, targetBuffer, TypedArrayConstructor) {
203
204
  }
204
205
  export async function decodeImageFrame(imageFrame, transferSyntax, pixelData, decodeConfig, options, callbackFn) {
205
206
  const start = new Date().getTime();
207
+ setWasmBasePathFromConfig(decodeConfig);
206
208
  let decodePromise = null;
207
209
  let opts;
208
210
  switch (transferSyntax) {
@@ -54,14 +54,17 @@ async function createImage(imageId, pixelData, transferSyntax, options = {}) {
54
54
  options.preScale.enabled = false;
55
55
  }
56
56
  }
57
- const { decodeConfig } = getOptions();
57
+ const { decodeConfig, wasmBasePath } = getOptions();
58
+ const taskDecodeConfig = wasmBasePath === undefined
59
+ ? decodeConfig
60
+ : { ...decodeConfig, wasmBasePath };
58
61
  Object.keys(imageFrame).forEach((key) => {
59
62
  if (typeof imageFrame[key] === 'function' ||
60
63
  imageFrame[key] instanceof Promise) {
61
64
  delete imageFrame[key];
62
65
  }
63
66
  });
64
- const decodePromise = decodeImageFrame(imageFrame, transferSyntax, pixelData, canvas, options, decodeConfig);
67
+ const decodePromise = decodeImageFrame(imageFrame, transferSyntax, pixelData, canvas, options, taskDecodeConfig);
65
68
  const isColorImage = isColorImageFn(imageFrame.photometricInterpretation);
66
69
  return new Promise((resolve, reject) => {
67
70
  decodePromise.then(function (imageFrame) {
@@ -103,7 +103,7 @@ declare const cornerstoneDICOMImageLoader: {
103
103
  JPEGLS: typeof import("./shared/decoders/decodeJPEGLS.js").initialize;
104
104
  JPEGBaseline12Bit: typeof import("./shared/decoders/decodeJPEGBaseline12Bit-js.js").initialize;
105
105
  JPEGLossless: typeof import("./shared/decoders/decodeJPEGLossless.js").initialize;
106
- JPEGBaseline8Bit: () => Promise<void>;
106
+ JPEGBaseline8Bit: (decodeConfig?: Types.LoaderDecodeOptions) => Promise<void>;
107
107
  };
108
108
  decoders: {
109
109
  HTJ2K: typeof import("./shared/decoders/decodeHTJ2K.js").default;
@@ -1,5 +1,6 @@
1
1
  import openJphFactory, {} from '@cornerstonejs/codec-openjph/wasmjs';
2
2
  const openjphWasm = new URL('@cornerstonejs/codec-openjph/wasm', import.meta.url);
3
+ import { resolveWasmUrl, setWasmBasePathFromConfig } from '../wasmBasePath.js';
3
4
  const local = {
4
5
  codec: undefined,
5
6
  decoder: undefined,
@@ -16,13 +17,14 @@ function calculateSizeAtDecompositionLevel(decompositionLevel, frameWidth, frame
16
17
  }
17
18
  export function initialize(decodeConfig) {
18
19
  local.decodeConfig = decodeConfig;
20
+ setWasmBasePathFromConfig(decodeConfig);
19
21
  if (local.codec) {
20
22
  return Promise.resolve();
21
23
  }
22
24
  const openJphModule = openJphFactory({
23
25
  locateFile: (f) => {
24
26
  if (f.endsWith('.wasm')) {
25
- return openjphWasm.toString();
27
+ return resolveWasmUrl('openjphjs.wasm', openjphWasm);
26
28
  }
27
29
  return f;
28
30
  },
@@ -1,5 +1,6 @@
1
1
  import openJpegFactory from '@cornerstonejs/codec-openjpeg/decodewasmjs';
2
2
  const openjpegWasm = new URL('@cornerstonejs/codec-openjpeg/decodewasm', import.meta.url);
3
+ import { resolveWasmUrl, setWasmBasePathFromConfig } from '../wasmBasePath.js';
3
4
  const local = {
4
5
  codec: undefined,
5
6
  decoder: undefined,
@@ -7,13 +8,14 @@ const local = {
7
8
  };
8
9
  export function initialize(decodeConfig) {
9
10
  local.decodeConfig = decodeConfig;
11
+ setWasmBasePathFromConfig(decodeConfig);
10
12
  if (local.codec) {
11
13
  return Promise.resolve();
12
14
  }
13
15
  const openJpegModule = openJpegFactory({
14
16
  locateFile: (f) => {
15
17
  if (f.endsWith('.wasm')) {
16
- return openjpegWasm.toString();
18
+ return resolveWasmUrl('openjpegwasm_decode.wasm', openjpegWasm);
17
19
  }
18
20
  return f;
19
21
  },
@@ -1,5 +1,6 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
- declare function initLibjpegTurbo(): Promise<void>;
2
+ import type { LoaderDecodeOptions } from '../../types/index.js';
3
+ declare function initLibjpegTurbo(decodeConfig?: LoaderDecodeOptions): Promise<void>;
3
4
  declare function decodeAsync(compressedImageFrame: any, imageInfo: any): Promise<Types.IImageFrame>;
4
5
  declare const initialize: typeof initLibjpegTurbo;
5
6
  export { initialize };
@@ -1,17 +1,19 @@
1
1
  import libjpegTurboFactory from '@cornerstonejs/codec-libjpeg-turbo-8bit/decodewasmjs';
2
2
  const libjpegTurboWasm = new URL('@cornerstonejs/codec-libjpeg-turbo-8bit/decodewasm', import.meta.url);
3
+ import { resolveWasmUrl, setWasmBasePathFromConfig } from '../wasmBasePath.js';
3
4
  const local = {
4
5
  codec: undefined,
5
6
  decoder: undefined,
6
7
  };
7
- function initLibjpegTurbo() {
8
+ function initLibjpegTurbo(decodeConfig) {
9
+ setWasmBasePathFromConfig(decodeConfig);
8
10
  if (local.codec) {
9
11
  return Promise.resolve();
10
12
  }
11
13
  const libjpegTurboModule = libjpegTurboFactory({
12
14
  locateFile: (f) => {
13
15
  if (f.endsWith('.wasm')) {
14
- return libjpegTurboWasm.toString();
16
+ return resolveWasmUrl('libjpegturbowasm_decode.wasm', libjpegTurboWasm);
15
17
  }
16
18
  return f;
17
19
  },
@@ -1,5 +1,6 @@
1
1
  import charlsFactory from '@cornerstonejs/codec-charls/decodewasmjs';
2
2
  const charlsWasm = new URL('@cornerstonejs/codec-charls/decodewasm', import.meta.url);
3
+ import { resolveWasmUrl, setWasmBasePathFromConfig } from '../wasmBasePath.js';
3
4
  const local = {
4
5
  codec: undefined,
5
6
  decoder: undefined,
@@ -12,13 +13,14 @@ function getExceptionMessage(exception) {
12
13
  }
13
14
  export function initialize(decodeConfig) {
14
15
  local.decodeConfig = decodeConfig;
16
+ setWasmBasePathFromConfig(decodeConfig);
15
17
  if (local.codec) {
16
18
  return Promise.resolve();
17
19
  }
18
20
  const charlsModule = charlsFactory({
19
21
  locateFile: (f) => {
20
22
  if (f.endsWith('.wasm')) {
21
- return charlsWasm.toString();
23
+ return resolveWasmUrl('charlswasm_decode.wasm', charlsWasm);
22
24
  }
23
25
  return f;
24
26
  },
@@ -18,7 +18,7 @@ declare const initializers: {
18
18
  JPEGLS: typeof initializeJPEGLS;
19
19
  JPEGBaseline12Bit: typeof initializeJPEGBaseline12Bit;
20
20
  JPEGLossless: typeof initializeJPEGLossless;
21
- JPEGBaseline8Bit: () => Promise<void>;
21
+ JPEGBaseline8Bit: (decodeConfig?: import("../../types/index.js").LoaderDecodeOptions) => Promise<void>;
22
22
  };
23
23
  declare const decoders: {
24
24
  HTJ2K: typeof decodeHTJ2K;
@@ -0,0 +1,6 @@
1
+ export declare function setWasmBasePath(basePath?: string): void;
2
+ export declare function getWasmBasePath(): string | undefined;
3
+ export declare function setWasmBasePathFromConfig(decodeConfig?: {
4
+ wasmBasePath?: string;
5
+ } | undefined): void;
6
+ export declare function resolveWasmUrl(fileName: string, defaultUrl: URL | string): string;
@@ -0,0 +1,29 @@
1
+ let wasmBasePath;
2
+ export function setWasmBasePath(basePath) {
3
+ wasmBasePath = basePath || undefined;
4
+ }
5
+ export function getWasmBasePath() {
6
+ return wasmBasePath;
7
+ }
8
+ export function setWasmBasePathFromConfig(decodeConfig) {
9
+ if (decodeConfig?.wasmBasePath !== undefined) {
10
+ setWasmBasePath(decodeConfig.wasmBasePath);
11
+ }
12
+ }
13
+ export function resolveWasmUrl(fileName, defaultUrl) {
14
+ if (!wasmBasePath) {
15
+ return defaultUrl.toString();
16
+ }
17
+ const base = wasmBasePath.endsWith('/') ? wasmBasePath : `${wasmBasePath}/`;
18
+ const path = `${base}${fileName}`;
19
+ const href = typeof self !== 'undefined' ? self.location?.href : undefined;
20
+ if (!href) {
21
+ return path;
22
+ }
23
+ try {
24
+ return new URL(path, href).toString();
25
+ }
26
+ catch {
27
+ return path;
28
+ }
29
+ }
@@ -1,2 +1,3 @@
1
1
  export interface LoaderDecodeOptions {
2
+ wasmBasePath?: string;
2
3
  }
@@ -12,6 +12,7 @@ export interface LoaderOptions {
12
12
  onprogress?: (event: ProgressEvent<EventTarget>, params: unknown) => void;
13
13
  errorInterceptor?: (error: LoaderXhrRequestError) => void;
14
14
  strict?: boolean;
15
+ wasmBasePath?: string;
15
16
  decodeConfig?: LoaderDecodeOptions;
16
17
  useLegacyMetadataProvider?: boolean;
17
18
  }
@@ -11,6 +11,7 @@ export interface WebWorkerOptions {
11
11
  export interface WebWorkerDecodeConfig {
12
12
  initializeCodecsOnStartup: boolean;
13
13
  strict?: boolean;
14
+ wasmBasePath?: string;
14
15
  }
15
16
  export interface WebWorkerTaskOptions {
16
17
  decodeTask: WebWorkerDecodeConfig;
@@ -1 +1 @@
1
- export declare const version = "5.7.3";
1
+ export declare const version = "5.8.1";
@@ -1 +1 @@
1
- export const version = '5.7.3';
1
+ export const version = '5.8.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/dicom-image-loader",
3
- "version": "5.7.3",
3
+ "version": "5.8.1",
4
4
  "description": "Cornerstone Image Loader for DICOM WADO-URI and WADO-RS and Local file",
5
5
  "keywords": [
6
6
  "DICOM",
@@ -111,10 +111,10 @@
111
111
  "prepublishOnly": "pnpm run build:loader"
112
112
  },
113
113
  "dependencies": {
114
- "@cornerstonejs/codec-charls": "1.2.3",
115
- "@cornerstonejs/codec-libjpeg-turbo-8bit": "1.2.2",
116
- "@cornerstonejs/codec-openjpeg": "1.3.0",
117
- "@cornerstonejs/codec-openjph": "2.4.7",
114
+ "@cornerstonejs/codec-charls": "1.2.5",
115
+ "@cornerstonejs/codec-libjpeg-turbo-8bit": "1.2.4",
116
+ "@cornerstonejs/codec-openjpeg": "1.3.2",
117
+ "@cornerstonejs/codec-openjph": "2.4.9",
118
118
  "comlink": "4.4.2",
119
119
  "dicom-parser": "1.8.21",
120
120
  "jpeg-lossless-decoder-js": "2.1.2",
@@ -122,12 +122,12 @@
122
122
  "uuid": "9.0.1"
123
123
  },
124
124
  "devDependencies": {
125
- "@cornerstonejs/core": "5.7.3",
126
- "@cornerstonejs/metadata": "5.7.3"
125
+ "@cornerstonejs/core": "5.8.1",
126
+ "@cornerstonejs/metadata": "5.8.1"
127
127
  },
128
128
  "peerDependencies": {
129
- "@cornerstonejs/core": "5.7.3",
130
- "@cornerstonejs/metadata": "5.7.3",
129
+ "@cornerstonejs/core": "5.8.1",
130
+ "@cornerstonejs/metadata": "5.8.1",
131
131
  "dicom-parser": "1.8.21"
132
132
  },
133
133
  "config": {
@@ -135,5 +135,5 @@
135
135
  "path": "./node_modules/cz-conventional-changelog"
136
136
  }
137
137
  },
138
- "gitHead": "32815247b0972b0cd0074a60b58f0103274659ea"
138
+ "gitHead": "b0e07ac229d4118fa46350210a0ed6ce2cd24a25"
139
139
  }