From 968f29d65bcafd9b09f71569e2713f1bf659fe71 Mon Sep 17 00:00:00 2001 From: Taylor Hanayik Date: Wed, 15 Jan 2025 12:49:00 +0000 Subject: [PATCH] add zlib support and jpegls support --- .gitignore | 4 +- console/makefile | 6 +- js/esbuild.config.jpegls.js | 24 +++ js/index.html | 2 + js/package.json | 12 +- js/src/index.jpegls.js | 315 ++++++++++++++++++++++++++++++++++++ js/src/worker.jpegls.js | 163 +++++++++++++++++++ 7 files changed, 520 insertions(+), 6 deletions(-) create mode 100644 js/esbuild.config.jpegls.js create mode 100644 js/src/index.jpegls.js create mode 100644 js/src/worker.jpegls.js diff --git a/.gitignore b/.gitignore index 9e350170..e0e75098 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,5 @@ __pycache__/ dist node_modules -dcm2niix.js -dcm2niix.wasm +dcm2niix*.js +dcm2niix*.wasm diff --git a/console/makefile b/console/makefile index c2ab23f2..c3282a3a 100644 --- a/console/makefile +++ b/console/makefile @@ -69,6 +69,10 @@ noroi: g++ $(CFLAGS) -I. $(JSFLAGS) $(JFLAGS) $(LFLAGS) $(UFILES) -DmyNoRois wasm: - emcc -O3 $(UFILES) -s DEMANGLE_SUPPORT=1 -s EXPORTED_RUNTIME_METHODS='["callMain", "ccall", "cwrap", "FS", "FS_createDataFile", "FS_readFile", "FS_unlink", "allocateUTF8", "getValue", "stringToUTF8", "setValue"]' -s STACK_OVERFLOW_CHECK=2 -s STACK_SIZE=16MB -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORTED_FUNCTIONS='["_main", "_malloc", "_free"]' -s FORCE_FILESYSTEM=1 -s INVOKE_RUN=0 -o ../js/src/dcm2niix.js + emcc -O3 $(UFILES) -lz -s USE_ZLIB -s DEMANGLE_SUPPORT=1 -s EXPORTED_RUNTIME_METHODS='["callMain", "ccall", "cwrap", "FS", "FS_createDataFile", "FS_readFile", "FS_unlink", "allocateUTF8", "getValue", "stringToUTF8", "setValue"]' -s STACK_OVERFLOW_CHECK=2 -s STACK_SIZE=16MB -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORTED_FUNCTIONS='["_main", "_malloc", "_free"]' -s FORCE_FILESYSTEM=1 -s INVOKE_RUN=0 -o ../js/src/dcm2niix.js + # STACK_SIZE=16MB is the minimum value found to work with the current codebase when targeting WASM + +wasm-jpegls: + emcc -O3 $(JFLAGS) $(UFILES) -lz -s USE_ZLIB -s DEMANGLE_SUPPORT=1 -s EXPORTED_RUNTIME_METHODS='["callMain", "ccall", "cwrap", "FS", "FS_createDataFile", "FS_readFile", "FS_unlink", "allocateUTF8", "getValue", "stringToUTF8", "setValue"]' -s STACK_OVERFLOW_CHECK=2 -s STACK_SIZE=16MB -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORTED_FUNCTIONS='["_main", "_malloc", "_free"]' -s FORCE_FILESYSTEM=1 -s INVOKE_RUN=0 -o ../js/src/dcm2niix.jpegls.js # STACK_SIZE=16MB is the minimum value found to work with the current codebase when targeting WASM diff --git a/js/esbuild.config.jpegls.js b/js/esbuild.config.jpegls.js new file mode 100644 index 00000000..c2d34a58 --- /dev/null +++ b/js/esbuild.config.jpegls.js @@ -0,0 +1,24 @@ +const esbuild = require('esbuild'); +const fs = require('fs'); + +esbuild.build({ + entryPoints: ['./src/index.jpegls.js'], + outfile: './dist/index.jpegls.js', + bundle: true, + format: 'esm', + target: ['es2020'], + minify: false, + define: { + 'process.env.NODE_ENV': '"production"', + }, +}).then(() => { + // copy worker.js, dcm2niix.wasm, dcm2niix.js to dist folder + // (they do not require any processing by esbuild). + // Technically, none of the files in the src folder require processing by esbuild, + // but it does allow minification (optional), and ES version target specification if needed. + // In the future, if we use Typescript, we can use esbuild to transpile the Typescript to JS. + fs.copyFileSync('./src/worker.jpegls.js', './dist/worker.jpegls.js'); + fs.copyFileSync('./src/dcm2niix.jpegls.wasm', './dist/dcm2niix.jpegls.wasm'); + fs.copyFileSync('./src/dcm2niix.jpegls.js', './dist/dcm2niix.jpegls.js'); + console.log('Build completed!'); +}).catch(() => process.exit(1)); \ No newline at end of file diff --git a/js/index.html b/js/index.html index 467bf204..ddea3a6e 100644 --- a/js/index.html +++ b/js/index.html @@ -19,6 +19,8 @@

dcm2niix WASM Demo