diff --git a/packages/dicomImageLoader/package.json b/packages/dicomImageLoader/package.json index bc0e6ce8d4..3bd6d3b162 100644 --- a/packages/dicomImageLoader/package.json +++ b/packages/dicomImageLoader/package.json @@ -58,6 +58,7 @@ "devDependencies": { "@babel/plugin-proposal-object-rest-spread": "^7.14.7", "@babel/runtime-corejs3": "^7.15.4", + "@types/emscripten": "^1.39.6", "@types/jasmine": "^4.3.1", "@types/karma": "^6.3.3", "chai": "^4.3.4", diff --git a/packages/dicomImageLoader/src/shared/decoders/decodeJPEG2000.ts b/packages/dicomImageLoader/src/shared/decoders/decodeJPEG2000.ts index 64fb8bbd2c..7423071cd1 100644 --- a/packages/dicomImageLoader/src/shared/decoders/decodeJPEG2000.ts +++ b/packages/dicomImageLoader/src/shared/decoders/decodeJPEG2000.ts @@ -1,4 +1,8 @@ // https://emscripten.org/docs/api_reference/module.html +import type { + J2KDecoder, + OpenJpegModule, +} from '@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode'; import openJpegFactory from '@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode'; const openjpegWasm = new URL( @@ -8,7 +12,11 @@ const openjpegWasm = new URL( import { ImageFrame, WebWorkerDecodeConfig } from '../../types'; -const local = { +const local: { + codec: OpenJpegModule; + decoder: J2KDecoder; + decodeConfig: WebWorkerDecodeConfig; +} = { codec: undefined, decoder: undefined, decodeConfig: {} as WebWorkerDecodeConfig, @@ -26,7 +34,7 @@ export function initialize( const openJpegModule = openJpegFactory({ locateFile: (f) => { if (f.endsWith('.wasm')) { - return openjpegWasm; + return openjpegWasm.toString(); } return f; diff --git a/packages/dicomImageLoader/src/shared/decoders/decodeJPEGBaseline8Bit.ts b/packages/dicomImageLoader/src/shared/decoders/decodeJPEGBaseline8Bit.ts index 76715e7720..aff5618cba 100644 --- a/packages/dicomImageLoader/src/shared/decoders/decodeJPEGBaseline8Bit.ts +++ b/packages/dicomImageLoader/src/shared/decoders/decodeJPEGBaseline8Bit.ts @@ -1,6 +1,9 @@ -import { ByteArray } from 'dicom-parser'; - +import type { + LibJpegTurbo8Bit, + OpenJpegModule, +} from '@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode'; import libjpegTurboFactory from '@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode'; +import { ByteArray } from 'dicom-parser'; const libjpegTurboWasm = new URL( '@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.wasm', @@ -9,7 +12,10 @@ const libjpegTurboWasm = new URL( import { ImageFrame } from '../../types'; -const local = { +const local: { + codec: OpenJpegModule; + decoder: LibJpegTurbo8Bit; +} = { codec: undefined, decoder: undefined, }; @@ -22,7 +28,7 @@ function initLibjpegTurbo(): Promise { const libjpegTurboModule = libjpegTurboFactory({ locateFile: (f) => { if (f.endsWith('.wasm')) { - return libjpegTurboWasm; + return libjpegTurboWasm.toString(); } return f; diff --git a/packages/dicomImageLoader/src/shared/decoders/decodeJPEGLS.ts b/packages/dicomImageLoader/src/shared/decoders/decodeJPEGLS.ts index 9db9712453..514b66ce0a 100644 --- a/packages/dicomImageLoader/src/shared/decoders/decodeJPEGLS.ts +++ b/packages/dicomImageLoader/src/shared/decoders/decodeJPEGLS.ts @@ -1,3 +1,7 @@ +import type { + CharlsModule, + JpegLSDecoder, +} from '@cornerstonejs/codec-charls/dist/charlswasm_decode'; import charlsFactory from '@cornerstonejs/codec-charls/dist/charlswasm_decode'; const charlsWasm = new URL( @@ -8,7 +12,11 @@ const charlsWasm = new URL( import { ByteArray } from 'dicom-parser'; import { ImageFrame, WebWorkerDecodeConfig } from '../../types'; -const local = { +const local: { + codec: CharlsModule; + decoder: JpegLSDecoder; + decodeConfig: WebWorkerDecodeConfig; +} = { codec: undefined, decoder: undefined, decodeConfig: {} as WebWorkerDecodeConfig, @@ -32,7 +40,7 @@ export function initialize( const charlsModule = charlsFactory({ locateFile: (f) => { if (f.endsWith('.wasm')) { - return charlsWasm; + return charlsWasm.toString(); } return f; diff --git a/packages/dicomImageLoader/src/types/codec-charls.d.ts b/packages/dicomImageLoader/src/types/codec-charls.d.ts new file mode 100644 index 0000000000..a565e418d7 --- /dev/null +++ b/packages/dicomImageLoader/src/types/codec-charls.d.ts @@ -0,0 +1,18 @@ +/// + +declare module '@cornerstonejs/codec-charls/dist/charlswasm_decode' { + export class JpegLSDecoder { + decode: () => any; + getDecodedBuffer: () => any; + getEncodedBuffer: (length: number) => any; + getFrameInfo: () => any; + getInterleaveMode: () => any; + getNearLossless: () => any; + } + export interface CharlsModule extends EmscriptenModule { + JpegLSDecoder: typeof JpegLSDecoder; + getExceptionMessage: (exception: number) => any; + } + declare const Module: EmscriptenModuleFactory; + export default Module; +} diff --git a/packages/dicomImageLoader/src/types/codec-libjpeg-turbo-8bit.d.ts b/packages/dicomImageLoader/src/types/codec-libjpeg-turbo-8bit.d.ts new file mode 100644 index 0000000000..2ceebc888e --- /dev/null +++ b/packages/dicomImageLoader/src/types/codec-libjpeg-turbo-8bit.d.ts @@ -0,0 +1,15 @@ +/// + +declare module '@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode' { + export class LibJpegTurbo8Bit { + decode: () => any; + getDecodedBuffer: () => any; + getEncodedBuffer: (length: number) => any; + getFrameInfo: () => any; + } + export interface OpenJpegModule extends EmscriptenModule { + JPEGDecoder: typeof LibJpegTurbo8Bit; + } + declare const Module: EmscriptenModuleFactory; + export default Module; +} diff --git a/packages/dicomImageLoader/src/types/codec-openjpeg.d.ts b/packages/dicomImageLoader/src/types/codec-openjpeg.d.ts new file mode 100644 index 0000000000..10467e472f --- /dev/null +++ b/packages/dicomImageLoader/src/types/codec-openjpeg.d.ts @@ -0,0 +1,24 @@ +/// + +declare module '@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode' { + export class J2KDecoder { + decode: () => any; + getBlockDimensions: () => any; + getColorSpace: () => any; + getDecodedBuffer: () => any; + getEncodedBuffer: (length: number) => any; + getFrameInfo: () => any; + getImageOffset: () => any; + getIsReversible: () => any; + getNumDecompositions: () => any; + getNumLayers: () => any; + getProgressionOrder: () => number; + getTileOffset: () => any; + getTileSize: () => any; + } + export interface OpenJpegModule extends EmscriptenModule { + J2KDecoder: typeof J2KDecoder; + } + declare const Module: EmscriptenModuleFactory; + export default Module; +} diff --git a/yarn.lock b/yarn.lock index 66b09117f5..392311a790 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5520,6 +5520,11 @@ "@types/got" "^8" "@types/node" "*" +"@types/emscripten@^1.39.6": + version "1.39.6" + resolved "https://registry.yarnpkg.com/@types/emscripten/-/emscripten-1.39.6.tgz#698b90fe60d44acf93c31064218fbea93fbfd85a" + integrity sha512-H90aoynNhhkQP6DRweEjJp5vfUVdIj7tdPLsu7pq89vODD/lcugKfZOsfgwpvM6XUewEp2N5dCg1Uf3Qe55Dcg== + "@types/eslint-scope@^3.7.0", "@types/eslint-scope@^3.7.3": version "3.7.3" resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224"