From 11ca38afa2351c36cfb825210e5b11430c0f2cf6 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 16 Aug 2023 17:00:38 -0400 Subject: [PATCH] feat(image-io): Mark typescript couldRead and couldWrite as booleans Edit commands: ```sh cd packages/image-io/typescript git sed 's/couldRead: Object/couldRead: boolean/' git sed 's/couldWrite: Object/couldWrite: boolean/' for ff in src/*result*; do tail -n+3 $ff > "${ff}.new"; mv "${ff}.new" $ff ; done git sed 's/JsonObject).data/JsonObject).data as boolean/' ``` --- .../src/bio-rad-read-image-node-result.ts | 12 +++ .../typescript/src/bio-rad-read-image-node.ts | 78 +++++++++++++++++ .../src/bio-rad-read-image-result.ts | 15 ++++ .../typescript/src/bio-rad-read-image.ts | 86 +++++++++++++++++++ .../src/bio-rad-write-image-node-result.ts | 10 +++ .../src/bio-rad-write-image-node.ts | 82 ++++++++++++++++++ .../src/bio-rad-write-image-result.ts | 15 ++++ .../typescript/src/bio-rad-write-image.ts | 85 ++++++++++++++++++ .../src/bmp-read-image-node-result.ts | 12 +++ .../typescript/src/bmp-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/bmp-read-image-result.ts | 15 ++++ .../image-io/typescript/src/bmp-read-image.ts | 86 +++++++++++++++++++ .../src/bmp-write-image-node-result.ts | 10 +++ .../typescript/src/bmp-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/bmp-write-image-result.ts | 15 ++++ .../typescript/src/bmp-write-image.ts | 85 ++++++++++++++++++ .../src/fdf-read-image-node-result.ts | 12 +++ .../typescript/src/fdf-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/fdf-read-image-result.ts | 15 ++++ .../image-io/typescript/src/fdf-read-image.ts | 86 +++++++++++++++++++ .../src/fdf-write-image-node-result.ts | 10 +++ .../typescript/src/fdf-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/fdf-write-image-result.ts | 15 ++++ .../typescript/src/fdf-write-image.ts | 85 ++++++++++++++++++ .../src/gdcm-read-image-node-result.ts | 12 +++ .../typescript/src/gdcm-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/gdcm-read-image-result.ts | 15 ++++ .../typescript/src/gdcm-read-image.ts | 86 +++++++++++++++++++ .../src/gdcm-write-image-node-result.ts | 10 +++ .../typescript/src/gdcm-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/gdcm-write-image-result.ts | 15 ++++ .../typescript/src/gdcm-write-image.ts | 85 ++++++++++++++++++ .../src/ge-adw-read-image-node-result.ts | 12 +++ .../typescript/src/ge-adw-read-image-node.ts | 78 +++++++++++++++++ .../src/ge-adw-read-image-result.ts | 15 ++++ .../typescript/src/ge-adw-read-image.ts | 86 +++++++++++++++++++ .../src/ge-adw-write-image-node-result.ts | 10 +++ .../typescript/src/ge-adw-write-image-node.ts | 82 ++++++++++++++++++ .../src/ge-adw-write-image-result.ts | 15 ++++ .../typescript/src/ge-adw-write-image.ts | 85 ++++++++++++++++++ .../src/ge4-read-image-node-result.ts | 12 +++ .../typescript/src/ge4-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/ge4-read-image-result.ts | 15 ++++ .../image-io/typescript/src/ge4-read-image.ts | 86 +++++++++++++++++++ .../src/ge4-write-image-node-result.ts | 10 +++ .../typescript/src/ge4-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/ge4-write-image-result.ts | 15 ++++ .../typescript/src/ge4-write-image.ts | 85 ++++++++++++++++++ .../src/ge5-read-image-node-result.ts | 12 +++ .../typescript/src/ge5-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/ge5-read-image-result.ts | 15 ++++ .../image-io/typescript/src/ge5-read-image.ts | 86 +++++++++++++++++++ .../src/ge5-write-image-node-result.ts | 10 +++ .../typescript/src/ge5-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/ge5-write-image-result.ts | 15 ++++ .../typescript/src/ge5-write-image.ts | 85 ++++++++++++++++++ .../src/gipl-read-image-node-result.ts | 12 +++ .../typescript/src/gipl-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/gipl-read-image-result.ts | 15 ++++ .../typescript/src/gipl-read-image.ts | 86 +++++++++++++++++++ .../src/gipl-write-image-node-result.ts | 10 +++ .../typescript/src/gipl-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/gipl-write-image-result.ts | 15 ++++ .../typescript/src/gipl-write-image.ts | 85 ++++++++++++++++++ .../src/hdf5-read-image-node-result.ts | 12 +++ .../typescript/src/hdf5-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/hdf5-read-image-result.ts | 15 ++++ .../typescript/src/hdf5-read-image.ts | 86 +++++++++++++++++++ .../src/hdf5-write-image-node-result.ts | 10 +++ .../typescript/src/hdf5-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/hdf5-write-image-result.ts | 15 ++++ .../typescript/src/hdf5-write-image.ts | 85 ++++++++++++++++++ .../src/jpeg-read-image-node-result.ts | 12 +++ .../typescript/src/jpeg-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/jpeg-read-image-result.ts | 15 ++++ .../typescript/src/jpeg-read-image.ts | 86 +++++++++++++++++++ .../src/jpeg-write-image-node-result.ts | 10 +++ .../typescript/src/jpeg-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/jpeg-write-image-result.ts | 15 ++++ .../typescript/src/jpeg-write-image.ts | 85 ++++++++++++++++++ .../src/lsm-read-image-node-result.ts | 12 +++ .../typescript/src/lsm-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/lsm-read-image-result.ts | 15 ++++ .../image-io/typescript/src/lsm-read-image.ts | 86 +++++++++++++++++++ .../src/lsm-write-image-node-result.ts | 10 +++ .../typescript/src/lsm-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/lsm-write-image-result.ts | 15 ++++ .../typescript/src/lsm-write-image.ts | 85 ++++++++++++++++++ .../src/meta-read-image-node-result.ts | 12 +++ .../typescript/src/meta-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/meta-read-image-result.ts | 15 ++++ .../typescript/src/meta-read-image.ts | 86 +++++++++++++++++++ .../src/meta-write-image-node-result.ts | 10 +++ .../typescript/src/meta-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/meta-write-image-result.ts | 15 ++++ .../typescript/src/meta-write-image.ts | 85 ++++++++++++++++++ .../src/mgh-read-image-node-result.ts | 12 +++ .../typescript/src/mgh-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/mgh-read-image-result.ts | 15 ++++ .../image-io/typescript/src/mgh-read-image.ts | 86 +++++++++++++++++++ .../src/mgh-write-image-node-result.ts | 10 +++ .../typescript/src/mgh-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/mgh-write-image-result.ts | 15 ++++ .../typescript/src/mgh-write-image.ts | 85 ++++++++++++++++++ .../src/minc-read-image-node-result.ts | 12 +++ .../typescript/src/minc-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/minc-read-image-result.ts | 15 ++++ .../typescript/src/minc-read-image.ts | 86 +++++++++++++++++++ .../src/minc-write-image-node-result.ts | 10 +++ .../typescript/src/minc-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/minc-write-image-result.ts | 15 ++++ .../typescript/src/minc-write-image.ts | 85 ++++++++++++++++++ .../src/mrc-read-image-node-result.ts | 12 +++ .../typescript/src/mrc-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/mrc-read-image-result.ts | 15 ++++ .../image-io/typescript/src/mrc-read-image.ts | 86 +++++++++++++++++++ .../src/mrc-write-image-node-result.ts | 10 +++ .../typescript/src/mrc-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/mrc-write-image-result.ts | 15 ++++ .../typescript/src/mrc-write-image.ts | 85 ++++++++++++++++++ .../src/nifti-read-image-node-result.ts | 12 +++ .../typescript/src/nifti-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/nifti-read-image-result.ts | 15 ++++ .../typescript/src/nifti-read-image.ts | 86 +++++++++++++++++++ .../src/nifti-write-image-node-result.ts | 10 +++ .../typescript/src/nifti-write-image-node.ts | 82 ++++++++++++++++++ .../src/nifti-write-image-result.ts | 15 ++++ .../typescript/src/nifti-write-image.ts | 85 ++++++++++++++++++ .../src/nrrd-read-image-node-result.ts | 12 +++ .../typescript/src/nrrd-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/nrrd-read-image-result.ts | 15 ++++ .../typescript/src/nrrd-read-image.ts | 86 +++++++++++++++++++ .../src/nrrd-write-image-node-result.ts | 10 +++ .../typescript/src/nrrd-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/nrrd-write-image-result.ts | 15 ++++ .../typescript/src/nrrd-write-image.ts | 85 ++++++++++++++++++ .../src/png-read-image-node-result.ts | 12 +++ .../typescript/src/png-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/png-read-image-result.ts | 15 ++++ .../image-io/typescript/src/png-read-image.ts | 86 +++++++++++++++++++ .../src/png-write-image-node-result.ts | 10 +++ .../typescript/src/png-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/png-write-image-result.ts | 15 ++++ .../typescript/src/png-write-image.ts | 85 ++++++++++++++++++ .../src/scanco-read-image-node-result.ts | 12 +++ .../typescript/src/scanco-read-image-node.ts | 78 +++++++++++++++++ .../src/scanco-read-image-result.ts | 15 ++++ .../typescript/src/scanco-read-image.ts | 86 +++++++++++++++++++ .../src/scanco-write-image-node-result.ts | 10 +++ .../typescript/src/scanco-write-image-node.ts | 82 ++++++++++++++++++ .../src/scanco-write-image-result.ts | 15 ++++ .../typescript/src/scanco-write-image.ts | 85 ++++++++++++++++++ .../src/tiff-read-image-node-result.ts | 12 +++ .../typescript/src/tiff-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/tiff-read-image-result.ts | 15 ++++ .../typescript/src/tiff-read-image.ts | 86 +++++++++++++++++++ .../src/tiff-write-image-node-result.ts | 10 +++ .../typescript/src/tiff-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/tiff-write-image-result.ts | 15 ++++ .../typescript/src/tiff-write-image.ts | 85 ++++++++++++++++++ .../src/vtk-read-image-node-result.ts | 12 +++ .../typescript/src/vtk-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/vtk-read-image-result.ts | 15 ++++ .../image-io/typescript/src/vtk-read-image.ts | 86 +++++++++++++++++++ .../src/vtk-write-image-node-result.ts | 10 +++ .../typescript/src/vtk-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/vtk-write-image-result.ts | 15 ++++ .../typescript/src/vtk-write-image.ts | 85 ++++++++++++++++++ .../src/wasm-read-image-node-result.ts | 12 +++ .../typescript/src/wasm-read-image-node.ts | 78 +++++++++++++++++ .../typescript/src/wasm-read-image-result.ts | 15 ++++ .../typescript/src/wasm-read-image.ts | 86 +++++++++++++++++++ .../src/wasm-write-image-node-result.ts | 10 +++ .../typescript/src/wasm-write-image-node.ts | 82 ++++++++++++++++++ .../typescript/src/wasm-write-image-result.ts | 15 ++++ .../typescript/src/wasm-write-image.ts | 85 ++++++++++++++++++ .../src/wasm-zstd-read-image-node-result.ts | 12 +++ .../src/wasm-zstd-read-image-node.ts | 78 +++++++++++++++++ .../src/wasm-zstd-read-image-result.ts | 15 ++++ .../typescript/src/wasm-zstd-read-image.ts | 86 +++++++++++++++++++ .../src/wasm-zstd-write-image-node-result.ts | 10 +++ .../src/wasm-zstd-write-image-node.ts | 82 ++++++++++++++++++ .../src/wasm-zstd-write-image-result.ts | 15 ++++ .../typescript/src/wasm-zstd-write-image.ts | 85 ++++++++++++++++++ 184 files changed, 8809 insertions(+) create mode 100644 packages/image-io/typescript/src/bio-rad-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/bio-rad-read-image-node.ts create mode 100644 packages/image-io/typescript/src/bio-rad-read-image-result.ts create mode 100644 packages/image-io/typescript/src/bio-rad-read-image.ts create mode 100644 packages/image-io/typescript/src/bio-rad-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/bio-rad-write-image-node.ts create mode 100644 packages/image-io/typescript/src/bio-rad-write-image-result.ts create mode 100644 packages/image-io/typescript/src/bio-rad-write-image.ts create mode 100644 packages/image-io/typescript/src/bmp-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/bmp-read-image-node.ts create mode 100644 packages/image-io/typescript/src/bmp-read-image-result.ts create mode 100644 packages/image-io/typescript/src/bmp-read-image.ts create mode 100644 packages/image-io/typescript/src/bmp-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/bmp-write-image-node.ts create mode 100644 packages/image-io/typescript/src/bmp-write-image-result.ts create mode 100644 packages/image-io/typescript/src/bmp-write-image.ts create mode 100644 packages/image-io/typescript/src/fdf-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/fdf-read-image-node.ts create mode 100644 packages/image-io/typescript/src/fdf-read-image-result.ts create mode 100644 packages/image-io/typescript/src/fdf-read-image.ts create mode 100644 packages/image-io/typescript/src/fdf-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/fdf-write-image-node.ts create mode 100644 packages/image-io/typescript/src/fdf-write-image-result.ts create mode 100644 packages/image-io/typescript/src/fdf-write-image.ts create mode 100644 packages/image-io/typescript/src/gdcm-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/gdcm-read-image-node.ts create mode 100644 packages/image-io/typescript/src/gdcm-read-image-result.ts create mode 100644 packages/image-io/typescript/src/gdcm-read-image.ts create mode 100644 packages/image-io/typescript/src/gdcm-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/gdcm-write-image-node.ts create mode 100644 packages/image-io/typescript/src/gdcm-write-image-result.ts create mode 100644 packages/image-io/typescript/src/gdcm-write-image.ts create mode 100644 packages/image-io/typescript/src/ge-adw-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/ge-adw-read-image-node.ts create mode 100644 packages/image-io/typescript/src/ge-adw-read-image-result.ts create mode 100644 packages/image-io/typescript/src/ge-adw-read-image.ts create mode 100644 packages/image-io/typescript/src/ge-adw-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/ge-adw-write-image-node.ts create mode 100644 packages/image-io/typescript/src/ge-adw-write-image-result.ts create mode 100644 packages/image-io/typescript/src/ge-adw-write-image.ts create mode 100644 packages/image-io/typescript/src/ge4-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/ge4-read-image-node.ts create mode 100644 packages/image-io/typescript/src/ge4-read-image-result.ts create mode 100644 packages/image-io/typescript/src/ge4-read-image.ts create mode 100644 packages/image-io/typescript/src/ge4-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/ge4-write-image-node.ts create mode 100644 packages/image-io/typescript/src/ge4-write-image-result.ts create mode 100644 packages/image-io/typescript/src/ge4-write-image.ts create mode 100644 packages/image-io/typescript/src/ge5-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/ge5-read-image-node.ts create mode 100644 packages/image-io/typescript/src/ge5-read-image-result.ts create mode 100644 packages/image-io/typescript/src/ge5-read-image.ts create mode 100644 packages/image-io/typescript/src/ge5-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/ge5-write-image-node.ts create mode 100644 packages/image-io/typescript/src/ge5-write-image-result.ts create mode 100644 packages/image-io/typescript/src/ge5-write-image.ts create mode 100644 packages/image-io/typescript/src/gipl-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/gipl-read-image-node.ts create mode 100644 packages/image-io/typescript/src/gipl-read-image-result.ts create mode 100644 packages/image-io/typescript/src/gipl-read-image.ts create mode 100644 packages/image-io/typescript/src/gipl-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/gipl-write-image-node.ts create mode 100644 packages/image-io/typescript/src/gipl-write-image-result.ts create mode 100644 packages/image-io/typescript/src/gipl-write-image.ts create mode 100644 packages/image-io/typescript/src/hdf5-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/hdf5-read-image-node.ts create mode 100644 packages/image-io/typescript/src/hdf5-read-image-result.ts create mode 100644 packages/image-io/typescript/src/hdf5-read-image.ts create mode 100644 packages/image-io/typescript/src/hdf5-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/hdf5-write-image-node.ts create mode 100644 packages/image-io/typescript/src/hdf5-write-image-result.ts create mode 100644 packages/image-io/typescript/src/hdf5-write-image.ts create mode 100644 packages/image-io/typescript/src/jpeg-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/jpeg-read-image-node.ts create mode 100644 packages/image-io/typescript/src/jpeg-read-image-result.ts create mode 100644 packages/image-io/typescript/src/jpeg-read-image.ts create mode 100644 packages/image-io/typescript/src/jpeg-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/jpeg-write-image-node.ts create mode 100644 packages/image-io/typescript/src/jpeg-write-image-result.ts create mode 100644 packages/image-io/typescript/src/jpeg-write-image.ts create mode 100644 packages/image-io/typescript/src/lsm-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/lsm-read-image-node.ts create mode 100644 packages/image-io/typescript/src/lsm-read-image-result.ts create mode 100644 packages/image-io/typescript/src/lsm-read-image.ts create mode 100644 packages/image-io/typescript/src/lsm-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/lsm-write-image-node.ts create mode 100644 packages/image-io/typescript/src/lsm-write-image-result.ts create mode 100644 packages/image-io/typescript/src/lsm-write-image.ts create mode 100644 packages/image-io/typescript/src/meta-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/meta-read-image-node.ts create mode 100644 packages/image-io/typescript/src/meta-read-image-result.ts create mode 100644 packages/image-io/typescript/src/meta-read-image.ts create mode 100644 packages/image-io/typescript/src/meta-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/meta-write-image-node.ts create mode 100644 packages/image-io/typescript/src/meta-write-image-result.ts create mode 100644 packages/image-io/typescript/src/meta-write-image.ts create mode 100644 packages/image-io/typescript/src/mgh-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/mgh-read-image-node.ts create mode 100644 packages/image-io/typescript/src/mgh-read-image-result.ts create mode 100644 packages/image-io/typescript/src/mgh-read-image.ts create mode 100644 packages/image-io/typescript/src/mgh-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/mgh-write-image-node.ts create mode 100644 packages/image-io/typescript/src/mgh-write-image-result.ts create mode 100644 packages/image-io/typescript/src/mgh-write-image.ts create mode 100644 packages/image-io/typescript/src/minc-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/minc-read-image-node.ts create mode 100644 packages/image-io/typescript/src/minc-read-image-result.ts create mode 100644 packages/image-io/typescript/src/minc-read-image.ts create mode 100644 packages/image-io/typescript/src/minc-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/minc-write-image-node.ts create mode 100644 packages/image-io/typescript/src/minc-write-image-result.ts create mode 100644 packages/image-io/typescript/src/minc-write-image.ts create mode 100644 packages/image-io/typescript/src/mrc-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/mrc-read-image-node.ts create mode 100644 packages/image-io/typescript/src/mrc-read-image-result.ts create mode 100644 packages/image-io/typescript/src/mrc-read-image.ts create mode 100644 packages/image-io/typescript/src/mrc-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/mrc-write-image-node.ts create mode 100644 packages/image-io/typescript/src/mrc-write-image-result.ts create mode 100644 packages/image-io/typescript/src/mrc-write-image.ts create mode 100644 packages/image-io/typescript/src/nifti-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/nifti-read-image-node.ts create mode 100644 packages/image-io/typescript/src/nifti-read-image-result.ts create mode 100644 packages/image-io/typescript/src/nifti-read-image.ts create mode 100644 packages/image-io/typescript/src/nifti-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/nifti-write-image-node.ts create mode 100644 packages/image-io/typescript/src/nifti-write-image-result.ts create mode 100644 packages/image-io/typescript/src/nifti-write-image.ts create mode 100644 packages/image-io/typescript/src/nrrd-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/nrrd-read-image-node.ts create mode 100644 packages/image-io/typescript/src/nrrd-read-image-result.ts create mode 100644 packages/image-io/typescript/src/nrrd-read-image.ts create mode 100644 packages/image-io/typescript/src/nrrd-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/nrrd-write-image-node.ts create mode 100644 packages/image-io/typescript/src/nrrd-write-image-result.ts create mode 100644 packages/image-io/typescript/src/nrrd-write-image.ts create mode 100644 packages/image-io/typescript/src/png-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/png-read-image-node.ts create mode 100644 packages/image-io/typescript/src/png-read-image-result.ts create mode 100644 packages/image-io/typescript/src/png-read-image.ts create mode 100644 packages/image-io/typescript/src/png-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/png-write-image-node.ts create mode 100644 packages/image-io/typescript/src/png-write-image-result.ts create mode 100644 packages/image-io/typescript/src/png-write-image.ts create mode 100644 packages/image-io/typescript/src/scanco-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/scanco-read-image-node.ts create mode 100644 packages/image-io/typescript/src/scanco-read-image-result.ts create mode 100644 packages/image-io/typescript/src/scanco-read-image.ts create mode 100644 packages/image-io/typescript/src/scanco-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/scanco-write-image-node.ts create mode 100644 packages/image-io/typescript/src/scanco-write-image-result.ts create mode 100644 packages/image-io/typescript/src/scanco-write-image.ts create mode 100644 packages/image-io/typescript/src/tiff-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/tiff-read-image-node.ts create mode 100644 packages/image-io/typescript/src/tiff-read-image-result.ts create mode 100644 packages/image-io/typescript/src/tiff-read-image.ts create mode 100644 packages/image-io/typescript/src/tiff-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/tiff-write-image-node.ts create mode 100644 packages/image-io/typescript/src/tiff-write-image-result.ts create mode 100644 packages/image-io/typescript/src/tiff-write-image.ts create mode 100644 packages/image-io/typescript/src/vtk-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/vtk-read-image-node.ts create mode 100644 packages/image-io/typescript/src/vtk-read-image-result.ts create mode 100644 packages/image-io/typescript/src/vtk-read-image.ts create mode 100644 packages/image-io/typescript/src/vtk-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/vtk-write-image-node.ts create mode 100644 packages/image-io/typescript/src/vtk-write-image-result.ts create mode 100644 packages/image-io/typescript/src/vtk-write-image.ts create mode 100644 packages/image-io/typescript/src/wasm-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/wasm-read-image-node.ts create mode 100644 packages/image-io/typescript/src/wasm-read-image-result.ts create mode 100644 packages/image-io/typescript/src/wasm-read-image.ts create mode 100644 packages/image-io/typescript/src/wasm-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/wasm-write-image-node.ts create mode 100644 packages/image-io/typescript/src/wasm-write-image-result.ts create mode 100644 packages/image-io/typescript/src/wasm-write-image.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-read-image-node-result.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-read-image-node.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-read-image-result.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-read-image.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-write-image-node-result.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-write-image-node.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-write-image-result.ts create mode 100644 packages/image-io/typescript/src/wasm-zstd-write-image.ts diff --git a/packages/image-io/typescript/src/bio-rad-read-image-node-result.ts b/packages/image-io/typescript/src/bio-rad-read-image-node-result.ts new file mode 100644 index 000000000..7cc690056 --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface BioRadReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default BioRadReadImageNodeResult diff --git a/packages/image-io/typescript/src/bio-rad-read-image-node.ts b/packages/image-io/typescript/src/bio-rad-read-image-node.ts new file mode 100644 index 000000000..4ff8a6226 --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import BioRadReadImageOptions from './bio-rad-read-image-options.js' +import BioRadReadImageNodeResult from './bio-rad-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {BioRadReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bioRadReadImageNode( + serializedImage: string, + options: BioRadReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'bio-rad-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default bioRadReadImageNode diff --git a/packages/image-io/typescript/src/bio-rad-read-image-result.ts b/packages/image-io/typescript/src/bio-rad-read-image-result.ts new file mode 100644 index 000000000..2cd173ba8 --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface BioRadReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default BioRadReadImageResult diff --git a/packages/image-io/typescript/src/bio-rad-read-image.ts b/packages/image-io/typescript/src/bio-rad-read-image.ts new file mode 100644 index 000000000..0f1d37b7e --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import BioRadReadImageOptions from './bio-rad-read-image-options.js' +import BioRadReadImageResult from './bio-rad-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {BioRadReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bioRadReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: BioRadReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'bio-rad-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default bioRadReadImage diff --git a/packages/image-io/typescript/src/bio-rad-write-image-node-result.ts b/packages/image-io/typescript/src/bio-rad-write-image-node-result.ts new file mode 100644 index 000000000..468dfdb7b --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface BioRadWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default BioRadWriteImageNodeResult diff --git a/packages/image-io/typescript/src/bio-rad-write-image-node.ts b/packages/image-io/typescript/src/bio-rad-write-image-node.ts new file mode 100644 index 000000000..296f49a0f --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import BioRadWriteImageOptions from './bio-rad-write-image-options.js' +import BioRadWriteImageNodeResult from './bio-rad-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {BioRadWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bioRadWriteImageNode( + image: Image, + options: BioRadWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'bio-rad-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default bioRadWriteImageNode diff --git a/packages/image-io/typescript/src/bio-rad-write-image-result.ts b/packages/image-io/typescript/src/bio-rad-write-image-result.ts new file mode 100644 index 000000000..d0e62f2ee --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface BioRadWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default BioRadWriteImageResult diff --git a/packages/image-io/typescript/src/bio-rad-write-image.ts b/packages/image-io/typescript/src/bio-rad-write-image.ts new file mode 100644 index 000000000..616d72067 --- /dev/null +++ b/packages/image-io/typescript/src/bio-rad-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import BioRadWriteImageOptions from './bio-rad-write-image-options.js' +import BioRadWriteImageResult from './bio-rad-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {BioRadWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bioRadWriteImage( + webWorker: null | Worker, + image: Image, + options: BioRadWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'bio-rad-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default bioRadWriteImage diff --git a/packages/image-io/typescript/src/bmp-read-image-node-result.ts b/packages/image-io/typescript/src/bmp-read-image-node-result.ts new file mode 100644 index 000000000..6e4309b88 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface BmpReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default BmpReadImageNodeResult diff --git a/packages/image-io/typescript/src/bmp-read-image-node.ts b/packages/image-io/typescript/src/bmp-read-image-node.ts new file mode 100644 index 000000000..02f0ff161 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import BmpReadImageOptions from './bmp-read-image-options.js' +import BmpReadImageNodeResult from './bmp-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {BmpReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bmpReadImageNode( + serializedImage: string, + options: BmpReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'bmp-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default bmpReadImageNode diff --git a/packages/image-io/typescript/src/bmp-read-image-result.ts b/packages/image-io/typescript/src/bmp-read-image-result.ts new file mode 100644 index 000000000..2ba14f020 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface BmpReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default BmpReadImageResult diff --git a/packages/image-io/typescript/src/bmp-read-image.ts b/packages/image-io/typescript/src/bmp-read-image.ts new file mode 100644 index 000000000..f605ca216 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import BmpReadImageOptions from './bmp-read-image-options.js' +import BmpReadImageResult from './bmp-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {BmpReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bmpReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: BmpReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'bmp-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default bmpReadImage diff --git a/packages/image-io/typescript/src/bmp-write-image-node-result.ts b/packages/image-io/typescript/src/bmp-write-image-node-result.ts new file mode 100644 index 000000000..4d0a5f925 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface BmpWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default BmpWriteImageNodeResult diff --git a/packages/image-io/typescript/src/bmp-write-image-node.ts b/packages/image-io/typescript/src/bmp-write-image-node.ts new file mode 100644 index 000000000..b96cd569d --- /dev/null +++ b/packages/image-io/typescript/src/bmp-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import BmpWriteImageOptions from './bmp-write-image-options.js' +import BmpWriteImageNodeResult from './bmp-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {BmpWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bmpWriteImageNode( + image: Image, + options: BmpWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'bmp-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default bmpWriteImageNode diff --git a/packages/image-io/typescript/src/bmp-write-image-result.ts b/packages/image-io/typescript/src/bmp-write-image-result.ts new file mode 100644 index 000000000..ebb1f4f71 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface BmpWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default BmpWriteImageResult diff --git a/packages/image-io/typescript/src/bmp-write-image.ts b/packages/image-io/typescript/src/bmp-write-image.ts new file mode 100644 index 000000000..75a0448e2 --- /dev/null +++ b/packages/image-io/typescript/src/bmp-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import BmpWriteImageOptions from './bmp-write-image-options.js' +import BmpWriteImageResult from './bmp-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {BmpWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function bmpWriteImage( + webWorker: null | Worker, + image: Image, + options: BmpWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'bmp-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default bmpWriteImage diff --git a/packages/image-io/typescript/src/fdf-read-image-node-result.ts b/packages/image-io/typescript/src/fdf-read-image-node-result.ts new file mode 100644 index 000000000..024464772 --- /dev/null +++ b/packages/image-io/typescript/src/fdf-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface FdfReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default FdfReadImageNodeResult diff --git a/packages/image-io/typescript/src/fdf-read-image-node.ts b/packages/image-io/typescript/src/fdf-read-image-node.ts new file mode 100644 index 000000000..1ac843901 --- /dev/null +++ b/packages/image-io/typescript/src/fdf-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import FdfReadImageOptions from './fdf-read-image-options.js' +import FdfReadImageNodeResult from './fdf-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {FdfReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function fdfReadImageNode( + serializedImage: string, + options: FdfReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'fdf-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default fdfReadImageNode diff --git a/packages/image-io/typescript/src/fdf-read-image-result.ts b/packages/image-io/typescript/src/fdf-read-image-result.ts new file mode 100644 index 000000000..b48d6cc4b --- /dev/null +++ b/packages/image-io/typescript/src/fdf-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface FdfReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default FdfReadImageResult diff --git a/packages/image-io/typescript/src/fdf-read-image.ts b/packages/image-io/typescript/src/fdf-read-image.ts new file mode 100644 index 000000000..0cd5af58e --- /dev/null +++ b/packages/image-io/typescript/src/fdf-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import FdfReadImageOptions from './fdf-read-image-options.js' +import FdfReadImageResult from './fdf-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {FdfReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function fdfReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: FdfReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'fdf-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default fdfReadImage diff --git a/packages/image-io/typescript/src/fdf-write-image-node-result.ts b/packages/image-io/typescript/src/fdf-write-image-node-result.ts new file mode 100644 index 000000000..7a9714bf2 --- /dev/null +++ b/packages/image-io/typescript/src/fdf-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface FdfWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default FdfWriteImageNodeResult diff --git a/packages/image-io/typescript/src/fdf-write-image-node.ts b/packages/image-io/typescript/src/fdf-write-image-node.ts new file mode 100644 index 000000000..34e72b69e --- /dev/null +++ b/packages/image-io/typescript/src/fdf-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import FdfWriteImageOptions from './fdf-write-image-options.js' +import FdfWriteImageNodeResult from './fdf-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {FdfWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function fdfWriteImageNode( + image: Image, + options: FdfWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'fdf-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default fdfWriteImageNode diff --git a/packages/image-io/typescript/src/fdf-write-image-result.ts b/packages/image-io/typescript/src/fdf-write-image-result.ts new file mode 100644 index 000000000..b2d7602e4 --- /dev/null +++ b/packages/image-io/typescript/src/fdf-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface FdfWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default FdfWriteImageResult diff --git a/packages/image-io/typescript/src/fdf-write-image.ts b/packages/image-io/typescript/src/fdf-write-image.ts new file mode 100644 index 000000000..67e7dc0df --- /dev/null +++ b/packages/image-io/typescript/src/fdf-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import FdfWriteImageOptions from './fdf-write-image-options.js' +import FdfWriteImageResult from './fdf-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {FdfWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function fdfWriteImage( + webWorker: null | Worker, + image: Image, + options: FdfWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'fdf-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default fdfWriteImage diff --git a/packages/image-io/typescript/src/gdcm-read-image-node-result.ts b/packages/image-io/typescript/src/gdcm-read-image-node-result.ts new file mode 100644 index 000000000..4b93a14e0 --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface GdcmReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default GdcmReadImageNodeResult diff --git a/packages/image-io/typescript/src/gdcm-read-image-node.ts b/packages/image-io/typescript/src/gdcm-read-image-node.ts new file mode 100644 index 000000000..43ddab27f --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import GdcmReadImageOptions from './gdcm-read-image-options.js' +import GdcmReadImageNodeResult from './gdcm-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {GdcmReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function gdcmReadImageNode( + serializedImage: string, + options: GdcmReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'gdcm-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default gdcmReadImageNode diff --git a/packages/image-io/typescript/src/gdcm-read-image-result.ts b/packages/image-io/typescript/src/gdcm-read-image-result.ts new file mode 100644 index 000000000..712c244d1 --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface GdcmReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default GdcmReadImageResult diff --git a/packages/image-io/typescript/src/gdcm-read-image.ts b/packages/image-io/typescript/src/gdcm-read-image.ts new file mode 100644 index 000000000..cff5dc3d4 --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import GdcmReadImageOptions from './gdcm-read-image-options.js' +import GdcmReadImageResult from './gdcm-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {GdcmReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function gdcmReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: GdcmReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'gdcm-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default gdcmReadImage diff --git a/packages/image-io/typescript/src/gdcm-write-image-node-result.ts b/packages/image-io/typescript/src/gdcm-write-image-node-result.ts new file mode 100644 index 000000000..cfdd0a090 --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface GdcmWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default GdcmWriteImageNodeResult diff --git a/packages/image-io/typescript/src/gdcm-write-image-node.ts b/packages/image-io/typescript/src/gdcm-write-image-node.ts new file mode 100644 index 000000000..ea78da6ad --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import GdcmWriteImageOptions from './gdcm-write-image-options.js' +import GdcmWriteImageNodeResult from './gdcm-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {GdcmWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function gdcmWriteImageNode( + image: Image, + options: GdcmWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'gdcm-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default gdcmWriteImageNode diff --git a/packages/image-io/typescript/src/gdcm-write-image-result.ts b/packages/image-io/typescript/src/gdcm-write-image-result.ts new file mode 100644 index 000000000..ccf21e8d3 --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface GdcmWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default GdcmWriteImageResult diff --git a/packages/image-io/typescript/src/gdcm-write-image.ts b/packages/image-io/typescript/src/gdcm-write-image.ts new file mode 100644 index 000000000..1f7c2f157 --- /dev/null +++ b/packages/image-io/typescript/src/gdcm-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import GdcmWriteImageOptions from './gdcm-write-image-options.js' +import GdcmWriteImageResult from './gdcm-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {GdcmWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function gdcmWriteImage( + webWorker: null | Worker, + image: Image, + options: GdcmWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'gdcm-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default gdcmWriteImage diff --git a/packages/image-io/typescript/src/ge-adw-read-image-node-result.ts b/packages/image-io/typescript/src/ge-adw-read-image-node-result.ts new file mode 100644 index 000000000..7326fc8d5 --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface GeAdwReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default GeAdwReadImageNodeResult diff --git a/packages/image-io/typescript/src/ge-adw-read-image-node.ts b/packages/image-io/typescript/src/ge-adw-read-image-node.ts new file mode 100644 index 000000000..ddcf8d83f --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import GeAdwReadImageOptions from './ge-adw-read-image-options.js' +import GeAdwReadImageNodeResult from './ge-adw-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {GeAdwReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function geAdwReadImageNode( + serializedImage: string, + options: GeAdwReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'ge-adw-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default geAdwReadImageNode diff --git a/packages/image-io/typescript/src/ge-adw-read-image-result.ts b/packages/image-io/typescript/src/ge-adw-read-image-result.ts new file mode 100644 index 000000000..ad7e615f1 --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface GeAdwReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default GeAdwReadImageResult diff --git a/packages/image-io/typescript/src/ge-adw-read-image.ts b/packages/image-io/typescript/src/ge-adw-read-image.ts new file mode 100644 index 000000000..58edbe8fc --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import GeAdwReadImageOptions from './ge-adw-read-image-options.js' +import GeAdwReadImageResult from './ge-adw-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {GeAdwReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function geAdwReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: GeAdwReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'ge-adw-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default geAdwReadImage diff --git a/packages/image-io/typescript/src/ge-adw-write-image-node-result.ts b/packages/image-io/typescript/src/ge-adw-write-image-node-result.ts new file mode 100644 index 000000000..f09c9e41f --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface GeAdwWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default GeAdwWriteImageNodeResult diff --git a/packages/image-io/typescript/src/ge-adw-write-image-node.ts b/packages/image-io/typescript/src/ge-adw-write-image-node.ts new file mode 100644 index 000000000..f79ae9db2 --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import GeAdwWriteImageOptions from './ge-adw-write-image-options.js' +import GeAdwWriteImageNodeResult from './ge-adw-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {GeAdwWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function geAdwWriteImageNode( + image: Image, + options: GeAdwWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'ge-adw-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default geAdwWriteImageNode diff --git a/packages/image-io/typescript/src/ge-adw-write-image-result.ts b/packages/image-io/typescript/src/ge-adw-write-image-result.ts new file mode 100644 index 000000000..542d40432 --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface GeAdwWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default GeAdwWriteImageResult diff --git a/packages/image-io/typescript/src/ge-adw-write-image.ts b/packages/image-io/typescript/src/ge-adw-write-image.ts new file mode 100644 index 000000000..dd3fff546 --- /dev/null +++ b/packages/image-io/typescript/src/ge-adw-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import GeAdwWriteImageOptions from './ge-adw-write-image-options.js' +import GeAdwWriteImageResult from './ge-adw-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {GeAdwWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function geAdwWriteImage( + webWorker: null | Worker, + image: Image, + options: GeAdwWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'ge-adw-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default geAdwWriteImage diff --git a/packages/image-io/typescript/src/ge4-read-image-node-result.ts b/packages/image-io/typescript/src/ge4-read-image-node-result.ts new file mode 100644 index 000000000..ef2fdd9df --- /dev/null +++ b/packages/image-io/typescript/src/ge4-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface Ge4ReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default Ge4ReadImageNodeResult diff --git a/packages/image-io/typescript/src/ge4-read-image-node.ts b/packages/image-io/typescript/src/ge4-read-image-node.ts new file mode 100644 index 000000000..bed5a3559 --- /dev/null +++ b/packages/image-io/typescript/src/ge4-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import Ge4ReadImageOptions from './ge4-read-image-options.js' +import Ge4ReadImageNodeResult from './ge4-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {Ge4ReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge4ReadImageNode( + serializedImage: string, + options: Ge4ReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'ge4-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default ge4ReadImageNode diff --git a/packages/image-io/typescript/src/ge4-read-image-result.ts b/packages/image-io/typescript/src/ge4-read-image-result.ts new file mode 100644 index 000000000..6b4599edb --- /dev/null +++ b/packages/image-io/typescript/src/ge4-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface Ge4ReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default Ge4ReadImageResult diff --git a/packages/image-io/typescript/src/ge4-read-image.ts b/packages/image-io/typescript/src/ge4-read-image.ts new file mode 100644 index 000000000..9ba2c92c8 --- /dev/null +++ b/packages/image-io/typescript/src/ge4-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import Ge4ReadImageOptions from './ge4-read-image-options.js' +import Ge4ReadImageResult from './ge4-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {Ge4ReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge4ReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: Ge4ReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'ge4-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default ge4ReadImage diff --git a/packages/image-io/typescript/src/ge4-write-image-node-result.ts b/packages/image-io/typescript/src/ge4-write-image-node-result.ts new file mode 100644 index 000000000..d49329c96 --- /dev/null +++ b/packages/image-io/typescript/src/ge4-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface Ge4WriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default Ge4WriteImageNodeResult diff --git a/packages/image-io/typescript/src/ge4-write-image-node.ts b/packages/image-io/typescript/src/ge4-write-image-node.ts new file mode 100644 index 000000000..88f9a58e9 --- /dev/null +++ b/packages/image-io/typescript/src/ge4-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import Ge4WriteImageOptions from './ge4-write-image-options.js' +import Ge4WriteImageNodeResult from './ge4-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {Ge4WriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge4WriteImageNode( + image: Image, + options: Ge4WriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'ge4-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default ge4WriteImageNode diff --git a/packages/image-io/typescript/src/ge4-write-image-result.ts b/packages/image-io/typescript/src/ge4-write-image-result.ts new file mode 100644 index 000000000..3c28529c0 --- /dev/null +++ b/packages/image-io/typescript/src/ge4-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface Ge4WriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default Ge4WriteImageResult diff --git a/packages/image-io/typescript/src/ge4-write-image.ts b/packages/image-io/typescript/src/ge4-write-image.ts new file mode 100644 index 000000000..79f4f7c2d --- /dev/null +++ b/packages/image-io/typescript/src/ge4-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import Ge4WriteImageOptions from './ge4-write-image-options.js' +import Ge4WriteImageResult from './ge4-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {Ge4WriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge4WriteImage( + webWorker: null | Worker, + image: Image, + options: Ge4WriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'ge4-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default ge4WriteImage diff --git a/packages/image-io/typescript/src/ge5-read-image-node-result.ts b/packages/image-io/typescript/src/ge5-read-image-node-result.ts new file mode 100644 index 000000000..4814e3aa7 --- /dev/null +++ b/packages/image-io/typescript/src/ge5-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface Ge5ReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default Ge5ReadImageNodeResult diff --git a/packages/image-io/typescript/src/ge5-read-image-node.ts b/packages/image-io/typescript/src/ge5-read-image-node.ts new file mode 100644 index 000000000..b50865a92 --- /dev/null +++ b/packages/image-io/typescript/src/ge5-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import Ge5ReadImageOptions from './ge5-read-image-options.js' +import Ge5ReadImageNodeResult from './ge5-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {Ge5ReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge5ReadImageNode( + serializedImage: string, + options: Ge5ReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'ge5-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default ge5ReadImageNode diff --git a/packages/image-io/typescript/src/ge5-read-image-result.ts b/packages/image-io/typescript/src/ge5-read-image-result.ts new file mode 100644 index 000000000..1d130408b --- /dev/null +++ b/packages/image-io/typescript/src/ge5-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface Ge5ReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default Ge5ReadImageResult diff --git a/packages/image-io/typescript/src/ge5-read-image.ts b/packages/image-io/typescript/src/ge5-read-image.ts new file mode 100644 index 000000000..503f4440e --- /dev/null +++ b/packages/image-io/typescript/src/ge5-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import Ge5ReadImageOptions from './ge5-read-image-options.js' +import Ge5ReadImageResult from './ge5-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {Ge5ReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge5ReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: Ge5ReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'ge5-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default ge5ReadImage diff --git a/packages/image-io/typescript/src/ge5-write-image-node-result.ts b/packages/image-io/typescript/src/ge5-write-image-node-result.ts new file mode 100644 index 000000000..9a80571f2 --- /dev/null +++ b/packages/image-io/typescript/src/ge5-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface Ge5WriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default Ge5WriteImageNodeResult diff --git a/packages/image-io/typescript/src/ge5-write-image-node.ts b/packages/image-io/typescript/src/ge5-write-image-node.ts new file mode 100644 index 000000000..19740dacc --- /dev/null +++ b/packages/image-io/typescript/src/ge5-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import Ge5WriteImageOptions from './ge5-write-image-options.js' +import Ge5WriteImageNodeResult from './ge5-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {Ge5WriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge5WriteImageNode( + image: Image, + options: Ge5WriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'ge5-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default ge5WriteImageNode diff --git a/packages/image-io/typescript/src/ge5-write-image-result.ts b/packages/image-io/typescript/src/ge5-write-image-result.ts new file mode 100644 index 000000000..e82123fe7 --- /dev/null +++ b/packages/image-io/typescript/src/ge5-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface Ge5WriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default Ge5WriteImageResult diff --git a/packages/image-io/typescript/src/ge5-write-image.ts b/packages/image-io/typescript/src/ge5-write-image.ts new file mode 100644 index 000000000..1e19c02b4 --- /dev/null +++ b/packages/image-io/typescript/src/ge5-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import Ge5WriteImageOptions from './ge5-write-image-options.js' +import Ge5WriteImageResult from './ge5-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {Ge5WriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function ge5WriteImage( + webWorker: null | Worker, + image: Image, + options: Ge5WriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'ge5-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default ge5WriteImage diff --git a/packages/image-io/typescript/src/gipl-read-image-node-result.ts b/packages/image-io/typescript/src/gipl-read-image-node-result.ts new file mode 100644 index 000000000..babd52b4b --- /dev/null +++ b/packages/image-io/typescript/src/gipl-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface GiplReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default GiplReadImageNodeResult diff --git a/packages/image-io/typescript/src/gipl-read-image-node.ts b/packages/image-io/typescript/src/gipl-read-image-node.ts new file mode 100644 index 000000000..efaee89b0 --- /dev/null +++ b/packages/image-io/typescript/src/gipl-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import GiplReadImageOptions from './gipl-read-image-options.js' +import GiplReadImageNodeResult from './gipl-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {GiplReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function giplReadImageNode( + serializedImage: string, + options: GiplReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'gipl-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default giplReadImageNode diff --git a/packages/image-io/typescript/src/gipl-read-image-result.ts b/packages/image-io/typescript/src/gipl-read-image-result.ts new file mode 100644 index 000000000..e8dc01764 --- /dev/null +++ b/packages/image-io/typescript/src/gipl-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface GiplReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default GiplReadImageResult diff --git a/packages/image-io/typescript/src/gipl-read-image.ts b/packages/image-io/typescript/src/gipl-read-image.ts new file mode 100644 index 000000000..57a33a77f --- /dev/null +++ b/packages/image-io/typescript/src/gipl-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import GiplReadImageOptions from './gipl-read-image-options.js' +import GiplReadImageResult from './gipl-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {GiplReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function giplReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: GiplReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'gipl-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default giplReadImage diff --git a/packages/image-io/typescript/src/gipl-write-image-node-result.ts b/packages/image-io/typescript/src/gipl-write-image-node-result.ts new file mode 100644 index 000000000..49d84ceb4 --- /dev/null +++ b/packages/image-io/typescript/src/gipl-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface GiplWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default GiplWriteImageNodeResult diff --git a/packages/image-io/typescript/src/gipl-write-image-node.ts b/packages/image-io/typescript/src/gipl-write-image-node.ts new file mode 100644 index 000000000..cc9dfae0b --- /dev/null +++ b/packages/image-io/typescript/src/gipl-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import GiplWriteImageOptions from './gipl-write-image-options.js' +import GiplWriteImageNodeResult from './gipl-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {GiplWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function giplWriteImageNode( + image: Image, + options: GiplWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'gipl-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default giplWriteImageNode diff --git a/packages/image-io/typescript/src/gipl-write-image-result.ts b/packages/image-io/typescript/src/gipl-write-image-result.ts new file mode 100644 index 000000000..999dabad1 --- /dev/null +++ b/packages/image-io/typescript/src/gipl-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface GiplWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default GiplWriteImageResult diff --git a/packages/image-io/typescript/src/gipl-write-image.ts b/packages/image-io/typescript/src/gipl-write-image.ts new file mode 100644 index 000000000..cec21f8e3 --- /dev/null +++ b/packages/image-io/typescript/src/gipl-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import GiplWriteImageOptions from './gipl-write-image-options.js' +import GiplWriteImageResult from './gipl-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {GiplWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function giplWriteImage( + webWorker: null | Worker, + image: Image, + options: GiplWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'gipl-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default giplWriteImage diff --git a/packages/image-io/typescript/src/hdf5-read-image-node-result.ts b/packages/image-io/typescript/src/hdf5-read-image-node-result.ts new file mode 100644 index 000000000..47e508880 --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface Hdf5ReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default Hdf5ReadImageNodeResult diff --git a/packages/image-io/typescript/src/hdf5-read-image-node.ts b/packages/image-io/typescript/src/hdf5-read-image-node.ts new file mode 100644 index 000000000..12f6e6b47 --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import Hdf5ReadImageOptions from './hdf5-read-image-options.js' +import Hdf5ReadImageNodeResult from './hdf5-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {Hdf5ReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function hdf5ReadImageNode( + serializedImage: string, + options: Hdf5ReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'hdf5-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default hdf5ReadImageNode diff --git a/packages/image-io/typescript/src/hdf5-read-image-result.ts b/packages/image-io/typescript/src/hdf5-read-image-result.ts new file mode 100644 index 000000000..8218aefcf --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface Hdf5ReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default Hdf5ReadImageResult diff --git a/packages/image-io/typescript/src/hdf5-read-image.ts b/packages/image-io/typescript/src/hdf5-read-image.ts new file mode 100644 index 000000000..038107cd1 --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import Hdf5ReadImageOptions from './hdf5-read-image-options.js' +import Hdf5ReadImageResult from './hdf5-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {Hdf5ReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function hdf5ReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: Hdf5ReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'hdf5-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default hdf5ReadImage diff --git a/packages/image-io/typescript/src/hdf5-write-image-node-result.ts b/packages/image-io/typescript/src/hdf5-write-image-node-result.ts new file mode 100644 index 000000000..2d953b80b --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface Hdf5WriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default Hdf5WriteImageNodeResult diff --git a/packages/image-io/typescript/src/hdf5-write-image-node.ts b/packages/image-io/typescript/src/hdf5-write-image-node.ts new file mode 100644 index 000000000..20f6b96b0 --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import Hdf5WriteImageOptions from './hdf5-write-image-options.js' +import Hdf5WriteImageNodeResult from './hdf5-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {Hdf5WriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function hdf5WriteImageNode( + image: Image, + options: Hdf5WriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'hdf5-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default hdf5WriteImageNode diff --git a/packages/image-io/typescript/src/hdf5-write-image-result.ts b/packages/image-io/typescript/src/hdf5-write-image-result.ts new file mode 100644 index 000000000..4ca612c15 --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface Hdf5WriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default Hdf5WriteImageResult diff --git a/packages/image-io/typescript/src/hdf5-write-image.ts b/packages/image-io/typescript/src/hdf5-write-image.ts new file mode 100644 index 000000000..99cb37b08 --- /dev/null +++ b/packages/image-io/typescript/src/hdf5-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import Hdf5WriteImageOptions from './hdf5-write-image-options.js' +import Hdf5WriteImageResult from './hdf5-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {Hdf5WriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function hdf5WriteImage( + webWorker: null | Worker, + image: Image, + options: Hdf5WriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'hdf5-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default hdf5WriteImage diff --git a/packages/image-io/typescript/src/jpeg-read-image-node-result.ts b/packages/image-io/typescript/src/jpeg-read-image-node-result.ts new file mode 100644 index 000000000..32d411452 --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface JpegReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default JpegReadImageNodeResult diff --git a/packages/image-io/typescript/src/jpeg-read-image-node.ts b/packages/image-io/typescript/src/jpeg-read-image-node.ts new file mode 100644 index 000000000..3dd686010 --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import JpegReadImageOptions from './jpeg-read-image-options.js' +import JpegReadImageNodeResult from './jpeg-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {JpegReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function jpegReadImageNode( + serializedImage: string, + options: JpegReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'jpeg-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default jpegReadImageNode diff --git a/packages/image-io/typescript/src/jpeg-read-image-result.ts b/packages/image-io/typescript/src/jpeg-read-image-result.ts new file mode 100644 index 000000000..1c859336b --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface JpegReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default JpegReadImageResult diff --git a/packages/image-io/typescript/src/jpeg-read-image.ts b/packages/image-io/typescript/src/jpeg-read-image.ts new file mode 100644 index 000000000..a3023d2ed --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import JpegReadImageOptions from './jpeg-read-image-options.js' +import JpegReadImageResult from './jpeg-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {JpegReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function jpegReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: JpegReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'jpeg-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default jpegReadImage diff --git a/packages/image-io/typescript/src/jpeg-write-image-node-result.ts b/packages/image-io/typescript/src/jpeg-write-image-node-result.ts new file mode 100644 index 000000000..9ac85cf13 --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface JpegWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default JpegWriteImageNodeResult diff --git a/packages/image-io/typescript/src/jpeg-write-image-node.ts b/packages/image-io/typescript/src/jpeg-write-image-node.ts new file mode 100644 index 000000000..f702743f9 --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import JpegWriteImageOptions from './jpeg-write-image-options.js' +import JpegWriteImageNodeResult from './jpeg-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {JpegWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function jpegWriteImageNode( + image: Image, + options: JpegWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'jpeg-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default jpegWriteImageNode diff --git a/packages/image-io/typescript/src/jpeg-write-image-result.ts b/packages/image-io/typescript/src/jpeg-write-image-result.ts new file mode 100644 index 000000000..54bf5aa66 --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface JpegWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default JpegWriteImageResult diff --git a/packages/image-io/typescript/src/jpeg-write-image.ts b/packages/image-io/typescript/src/jpeg-write-image.ts new file mode 100644 index 000000000..075e62c33 --- /dev/null +++ b/packages/image-io/typescript/src/jpeg-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import JpegWriteImageOptions from './jpeg-write-image-options.js' +import JpegWriteImageResult from './jpeg-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {JpegWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function jpegWriteImage( + webWorker: null | Worker, + image: Image, + options: JpegWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'jpeg-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default jpegWriteImage diff --git a/packages/image-io/typescript/src/lsm-read-image-node-result.ts b/packages/image-io/typescript/src/lsm-read-image-node-result.ts new file mode 100644 index 000000000..f2e33e033 --- /dev/null +++ b/packages/image-io/typescript/src/lsm-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface LsmReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default LsmReadImageNodeResult diff --git a/packages/image-io/typescript/src/lsm-read-image-node.ts b/packages/image-io/typescript/src/lsm-read-image-node.ts new file mode 100644 index 000000000..1b1767125 --- /dev/null +++ b/packages/image-io/typescript/src/lsm-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import LsmReadImageOptions from './lsm-read-image-options.js' +import LsmReadImageNodeResult from './lsm-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {LsmReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function lsmReadImageNode( + serializedImage: string, + options: LsmReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'lsm-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default lsmReadImageNode diff --git a/packages/image-io/typescript/src/lsm-read-image-result.ts b/packages/image-io/typescript/src/lsm-read-image-result.ts new file mode 100644 index 000000000..d22190a82 --- /dev/null +++ b/packages/image-io/typescript/src/lsm-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface LsmReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default LsmReadImageResult diff --git a/packages/image-io/typescript/src/lsm-read-image.ts b/packages/image-io/typescript/src/lsm-read-image.ts new file mode 100644 index 000000000..12217349d --- /dev/null +++ b/packages/image-io/typescript/src/lsm-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import LsmReadImageOptions from './lsm-read-image-options.js' +import LsmReadImageResult from './lsm-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {LsmReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function lsmReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: LsmReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'lsm-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default lsmReadImage diff --git a/packages/image-io/typescript/src/lsm-write-image-node-result.ts b/packages/image-io/typescript/src/lsm-write-image-node-result.ts new file mode 100644 index 000000000..d147bbb97 --- /dev/null +++ b/packages/image-io/typescript/src/lsm-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface LsmWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default LsmWriteImageNodeResult diff --git a/packages/image-io/typescript/src/lsm-write-image-node.ts b/packages/image-io/typescript/src/lsm-write-image-node.ts new file mode 100644 index 000000000..be23a436e --- /dev/null +++ b/packages/image-io/typescript/src/lsm-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import LsmWriteImageOptions from './lsm-write-image-options.js' +import LsmWriteImageNodeResult from './lsm-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {LsmWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function lsmWriteImageNode( + image: Image, + options: LsmWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'lsm-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default lsmWriteImageNode diff --git a/packages/image-io/typescript/src/lsm-write-image-result.ts b/packages/image-io/typescript/src/lsm-write-image-result.ts new file mode 100644 index 000000000..8c39f21ef --- /dev/null +++ b/packages/image-io/typescript/src/lsm-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface LsmWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default LsmWriteImageResult diff --git a/packages/image-io/typescript/src/lsm-write-image.ts b/packages/image-io/typescript/src/lsm-write-image.ts new file mode 100644 index 000000000..6d280d304 --- /dev/null +++ b/packages/image-io/typescript/src/lsm-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import LsmWriteImageOptions from './lsm-write-image-options.js' +import LsmWriteImageResult from './lsm-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {LsmWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function lsmWriteImage( + webWorker: null | Worker, + image: Image, + options: LsmWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'lsm-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default lsmWriteImage diff --git a/packages/image-io/typescript/src/meta-read-image-node-result.ts b/packages/image-io/typescript/src/meta-read-image-node-result.ts new file mode 100644 index 000000000..01eef6fee --- /dev/null +++ b/packages/image-io/typescript/src/meta-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface MetaReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MetaReadImageNodeResult diff --git a/packages/image-io/typescript/src/meta-read-image-node.ts b/packages/image-io/typescript/src/meta-read-image-node.ts new file mode 100644 index 000000000..5d5869d3a --- /dev/null +++ b/packages/image-io/typescript/src/meta-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MetaReadImageOptions from './meta-read-image-options.js' +import MetaReadImageNodeResult from './meta-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {MetaReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function metaReadImageNode( + serializedImage: string, + options: MetaReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'meta-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default metaReadImageNode diff --git a/packages/image-io/typescript/src/meta-read-image-result.ts b/packages/image-io/typescript/src/meta-read-image-result.ts new file mode 100644 index 000000000..cf16c9eb4 --- /dev/null +++ b/packages/image-io/typescript/src/meta-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface MetaReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MetaReadImageResult diff --git a/packages/image-io/typescript/src/meta-read-image.ts b/packages/image-io/typescript/src/meta-read-image.ts new file mode 100644 index 000000000..096266701 --- /dev/null +++ b/packages/image-io/typescript/src/meta-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MetaReadImageOptions from './meta-read-image-options.js' +import MetaReadImageResult from './meta-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {MetaReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function metaReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: MetaReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'meta-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default metaReadImage diff --git a/packages/image-io/typescript/src/meta-write-image-node-result.ts b/packages/image-io/typescript/src/meta-write-image-node-result.ts new file mode 100644 index 000000000..e3d903cd7 --- /dev/null +++ b/packages/image-io/typescript/src/meta-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface MetaWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default MetaWriteImageNodeResult diff --git a/packages/image-io/typescript/src/meta-write-image-node.ts b/packages/image-io/typescript/src/meta-write-image-node.ts new file mode 100644 index 000000000..bd51b159e --- /dev/null +++ b/packages/image-io/typescript/src/meta-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MetaWriteImageOptions from './meta-write-image-options.js' +import MetaWriteImageNodeResult from './meta-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MetaWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function metaWriteImageNode( + image: Image, + options: MetaWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'meta-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default metaWriteImageNode diff --git a/packages/image-io/typescript/src/meta-write-image-result.ts b/packages/image-io/typescript/src/meta-write-image-result.ts new file mode 100644 index 000000000..7d77a8407 --- /dev/null +++ b/packages/image-io/typescript/src/meta-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface MetaWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default MetaWriteImageResult diff --git a/packages/image-io/typescript/src/meta-write-image.ts b/packages/image-io/typescript/src/meta-write-image.ts new file mode 100644 index 000000000..5c8f06440 --- /dev/null +++ b/packages/image-io/typescript/src/meta-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MetaWriteImageOptions from './meta-write-image-options.js' +import MetaWriteImageResult from './meta-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MetaWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function metaWriteImage( + webWorker: null | Worker, + image: Image, + options: MetaWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'meta-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default metaWriteImage diff --git a/packages/image-io/typescript/src/mgh-read-image-node-result.ts b/packages/image-io/typescript/src/mgh-read-image-node-result.ts new file mode 100644 index 000000000..59f34e5fb --- /dev/null +++ b/packages/image-io/typescript/src/mgh-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface MghReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MghReadImageNodeResult diff --git a/packages/image-io/typescript/src/mgh-read-image-node.ts b/packages/image-io/typescript/src/mgh-read-image-node.ts new file mode 100644 index 000000000..76bc4f917 --- /dev/null +++ b/packages/image-io/typescript/src/mgh-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MghReadImageOptions from './mgh-read-image-options.js' +import MghReadImageNodeResult from './mgh-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {MghReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mghReadImageNode( + serializedImage: string, + options: MghReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'mgh-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default mghReadImageNode diff --git a/packages/image-io/typescript/src/mgh-read-image-result.ts b/packages/image-io/typescript/src/mgh-read-image-result.ts new file mode 100644 index 000000000..8d648bfb8 --- /dev/null +++ b/packages/image-io/typescript/src/mgh-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface MghReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MghReadImageResult diff --git a/packages/image-io/typescript/src/mgh-read-image.ts b/packages/image-io/typescript/src/mgh-read-image.ts new file mode 100644 index 000000000..976e5e25d --- /dev/null +++ b/packages/image-io/typescript/src/mgh-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MghReadImageOptions from './mgh-read-image-options.js' +import MghReadImageResult from './mgh-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {MghReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mghReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: MghReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'mgh-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default mghReadImage diff --git a/packages/image-io/typescript/src/mgh-write-image-node-result.ts b/packages/image-io/typescript/src/mgh-write-image-node-result.ts new file mode 100644 index 000000000..5961d5d72 --- /dev/null +++ b/packages/image-io/typescript/src/mgh-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface MghWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default MghWriteImageNodeResult diff --git a/packages/image-io/typescript/src/mgh-write-image-node.ts b/packages/image-io/typescript/src/mgh-write-image-node.ts new file mode 100644 index 000000000..0632f1ec0 --- /dev/null +++ b/packages/image-io/typescript/src/mgh-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MghWriteImageOptions from './mgh-write-image-options.js' +import MghWriteImageNodeResult from './mgh-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MghWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mghWriteImageNode( + image: Image, + options: MghWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'mgh-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default mghWriteImageNode diff --git a/packages/image-io/typescript/src/mgh-write-image-result.ts b/packages/image-io/typescript/src/mgh-write-image-result.ts new file mode 100644 index 000000000..7f16b24bb --- /dev/null +++ b/packages/image-io/typescript/src/mgh-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface MghWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default MghWriteImageResult diff --git a/packages/image-io/typescript/src/mgh-write-image.ts b/packages/image-io/typescript/src/mgh-write-image.ts new file mode 100644 index 000000000..189ef6a91 --- /dev/null +++ b/packages/image-io/typescript/src/mgh-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MghWriteImageOptions from './mgh-write-image-options.js' +import MghWriteImageResult from './mgh-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MghWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mghWriteImage( + webWorker: null | Worker, + image: Image, + options: MghWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'mgh-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default mghWriteImage diff --git a/packages/image-io/typescript/src/minc-read-image-node-result.ts b/packages/image-io/typescript/src/minc-read-image-node-result.ts new file mode 100644 index 000000000..eb69efa77 --- /dev/null +++ b/packages/image-io/typescript/src/minc-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface MincReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MincReadImageNodeResult diff --git a/packages/image-io/typescript/src/minc-read-image-node.ts b/packages/image-io/typescript/src/minc-read-image-node.ts new file mode 100644 index 000000000..c86e22222 --- /dev/null +++ b/packages/image-io/typescript/src/minc-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MincReadImageOptions from './minc-read-image-options.js' +import MincReadImageNodeResult from './minc-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {MincReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mincReadImageNode( + serializedImage: string, + options: MincReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'minc-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default mincReadImageNode diff --git a/packages/image-io/typescript/src/minc-read-image-result.ts b/packages/image-io/typescript/src/minc-read-image-result.ts new file mode 100644 index 000000000..f845ceb6e --- /dev/null +++ b/packages/image-io/typescript/src/minc-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface MincReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MincReadImageResult diff --git a/packages/image-io/typescript/src/minc-read-image.ts b/packages/image-io/typescript/src/minc-read-image.ts new file mode 100644 index 000000000..b4b4db7f9 --- /dev/null +++ b/packages/image-io/typescript/src/minc-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MincReadImageOptions from './minc-read-image-options.js' +import MincReadImageResult from './minc-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {MincReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mincReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: MincReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'minc-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default mincReadImage diff --git a/packages/image-io/typescript/src/minc-write-image-node-result.ts b/packages/image-io/typescript/src/minc-write-image-node-result.ts new file mode 100644 index 000000000..ed4bc2e8d --- /dev/null +++ b/packages/image-io/typescript/src/minc-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface MincWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default MincWriteImageNodeResult diff --git a/packages/image-io/typescript/src/minc-write-image-node.ts b/packages/image-io/typescript/src/minc-write-image-node.ts new file mode 100644 index 000000000..60234aec0 --- /dev/null +++ b/packages/image-io/typescript/src/minc-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MincWriteImageOptions from './minc-write-image-options.js' +import MincWriteImageNodeResult from './minc-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MincWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mincWriteImageNode( + image: Image, + options: MincWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'minc-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default mincWriteImageNode diff --git a/packages/image-io/typescript/src/minc-write-image-result.ts b/packages/image-io/typescript/src/minc-write-image-result.ts new file mode 100644 index 000000000..9d9c4be84 --- /dev/null +++ b/packages/image-io/typescript/src/minc-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface MincWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default MincWriteImageResult diff --git a/packages/image-io/typescript/src/minc-write-image.ts b/packages/image-io/typescript/src/minc-write-image.ts new file mode 100644 index 000000000..53b28d391 --- /dev/null +++ b/packages/image-io/typescript/src/minc-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MincWriteImageOptions from './minc-write-image-options.js' +import MincWriteImageResult from './minc-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MincWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mincWriteImage( + webWorker: null | Worker, + image: Image, + options: MincWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'minc-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default mincWriteImage diff --git a/packages/image-io/typescript/src/mrc-read-image-node-result.ts b/packages/image-io/typescript/src/mrc-read-image-node-result.ts new file mode 100644 index 000000000..f69a5ea9a --- /dev/null +++ b/packages/image-io/typescript/src/mrc-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface MrcReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MrcReadImageNodeResult diff --git a/packages/image-io/typescript/src/mrc-read-image-node.ts b/packages/image-io/typescript/src/mrc-read-image-node.ts new file mode 100644 index 000000000..ab0a526a5 --- /dev/null +++ b/packages/image-io/typescript/src/mrc-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MrcReadImageOptions from './mrc-read-image-options.js' +import MrcReadImageNodeResult from './mrc-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {MrcReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mrcReadImageNode( + serializedImage: string, + options: MrcReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'mrc-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default mrcReadImageNode diff --git a/packages/image-io/typescript/src/mrc-read-image-result.ts b/packages/image-io/typescript/src/mrc-read-image-result.ts new file mode 100644 index 000000000..cda534264 --- /dev/null +++ b/packages/image-io/typescript/src/mrc-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface MrcReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default MrcReadImageResult diff --git a/packages/image-io/typescript/src/mrc-read-image.ts b/packages/image-io/typescript/src/mrc-read-image.ts new file mode 100644 index 000000000..bddca60ad --- /dev/null +++ b/packages/image-io/typescript/src/mrc-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MrcReadImageOptions from './mrc-read-image-options.js' +import MrcReadImageResult from './mrc-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {MrcReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mrcReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: MrcReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'mrc-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default mrcReadImage diff --git a/packages/image-io/typescript/src/mrc-write-image-node-result.ts b/packages/image-io/typescript/src/mrc-write-image-node-result.ts new file mode 100644 index 000000000..793c5f8f6 --- /dev/null +++ b/packages/image-io/typescript/src/mrc-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface MrcWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default MrcWriteImageNodeResult diff --git a/packages/image-io/typescript/src/mrc-write-image-node.ts b/packages/image-io/typescript/src/mrc-write-image-node.ts new file mode 100644 index 000000000..7e9baa927 --- /dev/null +++ b/packages/image-io/typescript/src/mrc-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import MrcWriteImageOptions from './mrc-write-image-options.js' +import MrcWriteImageNodeResult from './mrc-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MrcWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mrcWriteImageNode( + image: Image, + options: MrcWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'mrc-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default mrcWriteImageNode diff --git a/packages/image-io/typescript/src/mrc-write-image-result.ts b/packages/image-io/typescript/src/mrc-write-image-result.ts new file mode 100644 index 000000000..f28157b1a --- /dev/null +++ b/packages/image-io/typescript/src/mrc-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface MrcWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default MrcWriteImageResult diff --git a/packages/image-io/typescript/src/mrc-write-image.ts b/packages/image-io/typescript/src/mrc-write-image.ts new file mode 100644 index 000000000..ef46bf78b --- /dev/null +++ b/packages/image-io/typescript/src/mrc-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import MrcWriteImageOptions from './mrc-write-image-options.js' +import MrcWriteImageResult from './mrc-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {MrcWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function mrcWriteImage( + webWorker: null | Worker, + image: Image, + options: MrcWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'mrc-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default mrcWriteImage diff --git a/packages/image-io/typescript/src/nifti-read-image-node-result.ts b/packages/image-io/typescript/src/nifti-read-image-node-result.ts new file mode 100644 index 000000000..8ab207037 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface NiftiReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default NiftiReadImageNodeResult diff --git a/packages/image-io/typescript/src/nifti-read-image-node.ts b/packages/image-io/typescript/src/nifti-read-image-node.ts new file mode 100644 index 000000000..815b68561 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import NiftiReadImageOptions from './nifti-read-image-options.js' +import NiftiReadImageNodeResult from './nifti-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {NiftiReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function niftiReadImageNode( + serializedImage: string, + options: NiftiReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'nifti-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default niftiReadImageNode diff --git a/packages/image-io/typescript/src/nifti-read-image-result.ts b/packages/image-io/typescript/src/nifti-read-image-result.ts new file mode 100644 index 000000000..8057eda53 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface NiftiReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default NiftiReadImageResult diff --git a/packages/image-io/typescript/src/nifti-read-image.ts b/packages/image-io/typescript/src/nifti-read-image.ts new file mode 100644 index 000000000..b5de43b0a --- /dev/null +++ b/packages/image-io/typescript/src/nifti-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import NiftiReadImageOptions from './nifti-read-image-options.js' +import NiftiReadImageResult from './nifti-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {NiftiReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function niftiReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: NiftiReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'nifti-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default niftiReadImage diff --git a/packages/image-io/typescript/src/nifti-write-image-node-result.ts b/packages/image-io/typescript/src/nifti-write-image-node-result.ts new file mode 100644 index 000000000..71b36eb25 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface NiftiWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default NiftiWriteImageNodeResult diff --git a/packages/image-io/typescript/src/nifti-write-image-node.ts b/packages/image-io/typescript/src/nifti-write-image-node.ts new file mode 100644 index 000000000..35f4d01f6 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import NiftiWriteImageOptions from './nifti-write-image-options.js' +import NiftiWriteImageNodeResult from './nifti-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {NiftiWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function niftiWriteImageNode( + image: Image, + options: NiftiWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'nifti-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default niftiWriteImageNode diff --git a/packages/image-io/typescript/src/nifti-write-image-result.ts b/packages/image-io/typescript/src/nifti-write-image-result.ts new file mode 100644 index 000000000..9c6aee4c1 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface NiftiWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default NiftiWriteImageResult diff --git a/packages/image-io/typescript/src/nifti-write-image.ts b/packages/image-io/typescript/src/nifti-write-image.ts new file mode 100644 index 000000000..b6bda3e35 --- /dev/null +++ b/packages/image-io/typescript/src/nifti-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import NiftiWriteImageOptions from './nifti-write-image-options.js' +import NiftiWriteImageResult from './nifti-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {NiftiWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function niftiWriteImage( + webWorker: null | Worker, + image: Image, + options: NiftiWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'nifti-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default niftiWriteImage diff --git a/packages/image-io/typescript/src/nrrd-read-image-node-result.ts b/packages/image-io/typescript/src/nrrd-read-image-node-result.ts new file mode 100644 index 000000000..fe732c217 --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface NrrdReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default NrrdReadImageNodeResult diff --git a/packages/image-io/typescript/src/nrrd-read-image-node.ts b/packages/image-io/typescript/src/nrrd-read-image-node.ts new file mode 100644 index 000000000..f14649baf --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import NrrdReadImageOptions from './nrrd-read-image-options.js' +import NrrdReadImageNodeResult from './nrrd-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {NrrdReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function nrrdReadImageNode( + serializedImage: string, + options: NrrdReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'nrrd-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default nrrdReadImageNode diff --git a/packages/image-io/typescript/src/nrrd-read-image-result.ts b/packages/image-io/typescript/src/nrrd-read-image-result.ts new file mode 100644 index 000000000..493feee43 --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface NrrdReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default NrrdReadImageResult diff --git a/packages/image-io/typescript/src/nrrd-read-image.ts b/packages/image-io/typescript/src/nrrd-read-image.ts new file mode 100644 index 000000000..b60fb6a48 --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import NrrdReadImageOptions from './nrrd-read-image-options.js' +import NrrdReadImageResult from './nrrd-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {NrrdReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function nrrdReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: NrrdReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'nrrd-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default nrrdReadImage diff --git a/packages/image-io/typescript/src/nrrd-write-image-node-result.ts b/packages/image-io/typescript/src/nrrd-write-image-node-result.ts new file mode 100644 index 000000000..347510fc7 --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface NrrdWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default NrrdWriteImageNodeResult diff --git a/packages/image-io/typescript/src/nrrd-write-image-node.ts b/packages/image-io/typescript/src/nrrd-write-image-node.ts new file mode 100644 index 000000000..0d48f5d38 --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import NrrdWriteImageOptions from './nrrd-write-image-options.js' +import NrrdWriteImageNodeResult from './nrrd-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {NrrdWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function nrrdWriteImageNode( + image: Image, + options: NrrdWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'nrrd-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default nrrdWriteImageNode diff --git a/packages/image-io/typescript/src/nrrd-write-image-result.ts b/packages/image-io/typescript/src/nrrd-write-image-result.ts new file mode 100644 index 000000000..7f66a4129 --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface NrrdWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default NrrdWriteImageResult diff --git a/packages/image-io/typescript/src/nrrd-write-image.ts b/packages/image-io/typescript/src/nrrd-write-image.ts new file mode 100644 index 000000000..0f135d2da --- /dev/null +++ b/packages/image-io/typescript/src/nrrd-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import NrrdWriteImageOptions from './nrrd-write-image-options.js' +import NrrdWriteImageResult from './nrrd-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {NrrdWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function nrrdWriteImage( + webWorker: null | Worker, + image: Image, + options: NrrdWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'nrrd-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default nrrdWriteImage diff --git a/packages/image-io/typescript/src/png-read-image-node-result.ts b/packages/image-io/typescript/src/png-read-image-node-result.ts new file mode 100644 index 000000000..0abc4ad05 --- /dev/null +++ b/packages/image-io/typescript/src/png-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface PngReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default PngReadImageNodeResult diff --git a/packages/image-io/typescript/src/png-read-image-node.ts b/packages/image-io/typescript/src/png-read-image-node.ts new file mode 100644 index 000000000..f3bc3daa7 --- /dev/null +++ b/packages/image-io/typescript/src/png-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import PngReadImageOptions from './png-read-image-options.js' +import PngReadImageNodeResult from './png-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {PngReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function pngReadImageNode( + serializedImage: string, + options: PngReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'png-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default pngReadImageNode diff --git a/packages/image-io/typescript/src/png-read-image-result.ts b/packages/image-io/typescript/src/png-read-image-result.ts new file mode 100644 index 000000000..8f6b6b036 --- /dev/null +++ b/packages/image-io/typescript/src/png-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface PngReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default PngReadImageResult diff --git a/packages/image-io/typescript/src/png-read-image.ts b/packages/image-io/typescript/src/png-read-image.ts new file mode 100644 index 000000000..d8731fdd3 --- /dev/null +++ b/packages/image-io/typescript/src/png-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import PngReadImageOptions from './png-read-image-options.js' +import PngReadImageResult from './png-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {PngReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function pngReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: PngReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'png-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default pngReadImage diff --git a/packages/image-io/typescript/src/png-write-image-node-result.ts b/packages/image-io/typescript/src/png-write-image-node-result.ts new file mode 100644 index 000000000..7c3fa771f --- /dev/null +++ b/packages/image-io/typescript/src/png-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface PngWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default PngWriteImageNodeResult diff --git a/packages/image-io/typescript/src/png-write-image-node.ts b/packages/image-io/typescript/src/png-write-image-node.ts new file mode 100644 index 000000000..76f8f9409 --- /dev/null +++ b/packages/image-io/typescript/src/png-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import PngWriteImageOptions from './png-write-image-options.js' +import PngWriteImageNodeResult from './png-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {PngWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function pngWriteImageNode( + image: Image, + options: PngWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'png-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default pngWriteImageNode diff --git a/packages/image-io/typescript/src/png-write-image-result.ts b/packages/image-io/typescript/src/png-write-image-result.ts new file mode 100644 index 000000000..5cc072e7c --- /dev/null +++ b/packages/image-io/typescript/src/png-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface PngWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default PngWriteImageResult diff --git a/packages/image-io/typescript/src/png-write-image.ts b/packages/image-io/typescript/src/png-write-image.ts new file mode 100644 index 000000000..0ee4dbda2 --- /dev/null +++ b/packages/image-io/typescript/src/png-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import PngWriteImageOptions from './png-write-image-options.js' +import PngWriteImageResult from './png-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {PngWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function pngWriteImage( + webWorker: null | Worker, + image: Image, + options: PngWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'png-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default pngWriteImage diff --git a/packages/image-io/typescript/src/scanco-read-image-node-result.ts b/packages/image-io/typescript/src/scanco-read-image-node-result.ts new file mode 100644 index 000000000..f0a11d2d1 --- /dev/null +++ b/packages/image-io/typescript/src/scanco-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface ScancoReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default ScancoReadImageNodeResult diff --git a/packages/image-io/typescript/src/scanco-read-image-node.ts b/packages/image-io/typescript/src/scanco-read-image-node.ts new file mode 100644 index 000000000..58224d17f --- /dev/null +++ b/packages/image-io/typescript/src/scanco-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import ScancoReadImageOptions from './scanco-read-image-options.js' +import ScancoReadImageNodeResult from './scanco-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {ScancoReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function scancoReadImageNode( + serializedImage: string, + options: ScancoReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'scanco-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default scancoReadImageNode diff --git a/packages/image-io/typescript/src/scanco-read-image-result.ts b/packages/image-io/typescript/src/scanco-read-image-result.ts new file mode 100644 index 000000000..9da366b48 --- /dev/null +++ b/packages/image-io/typescript/src/scanco-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface ScancoReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default ScancoReadImageResult diff --git a/packages/image-io/typescript/src/scanco-read-image.ts b/packages/image-io/typescript/src/scanco-read-image.ts new file mode 100644 index 000000000..02e041f9c --- /dev/null +++ b/packages/image-io/typescript/src/scanco-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import ScancoReadImageOptions from './scanco-read-image-options.js' +import ScancoReadImageResult from './scanco-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {ScancoReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function scancoReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: ScancoReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'scanco-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default scancoReadImage diff --git a/packages/image-io/typescript/src/scanco-write-image-node-result.ts b/packages/image-io/typescript/src/scanco-write-image-node-result.ts new file mode 100644 index 000000000..6f626ba34 --- /dev/null +++ b/packages/image-io/typescript/src/scanco-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface ScancoWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default ScancoWriteImageNodeResult diff --git a/packages/image-io/typescript/src/scanco-write-image-node.ts b/packages/image-io/typescript/src/scanco-write-image-node.ts new file mode 100644 index 000000000..9df04d0e2 --- /dev/null +++ b/packages/image-io/typescript/src/scanco-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import ScancoWriteImageOptions from './scanco-write-image-options.js' +import ScancoWriteImageNodeResult from './scanco-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {ScancoWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function scancoWriteImageNode( + image: Image, + options: ScancoWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'scanco-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default scancoWriteImageNode diff --git a/packages/image-io/typescript/src/scanco-write-image-result.ts b/packages/image-io/typescript/src/scanco-write-image-result.ts new file mode 100644 index 000000000..2f20924c0 --- /dev/null +++ b/packages/image-io/typescript/src/scanco-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface ScancoWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default ScancoWriteImageResult diff --git a/packages/image-io/typescript/src/scanco-write-image.ts b/packages/image-io/typescript/src/scanco-write-image.ts new file mode 100644 index 000000000..45bad5935 --- /dev/null +++ b/packages/image-io/typescript/src/scanco-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import ScancoWriteImageOptions from './scanco-write-image-options.js' +import ScancoWriteImageResult from './scanco-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {ScancoWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function scancoWriteImage( + webWorker: null | Worker, + image: Image, + options: ScancoWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'scanco-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default scancoWriteImage diff --git a/packages/image-io/typescript/src/tiff-read-image-node-result.ts b/packages/image-io/typescript/src/tiff-read-image-node-result.ts new file mode 100644 index 000000000..94f5a5ba3 --- /dev/null +++ b/packages/image-io/typescript/src/tiff-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface TiffReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default TiffReadImageNodeResult diff --git a/packages/image-io/typescript/src/tiff-read-image-node.ts b/packages/image-io/typescript/src/tiff-read-image-node.ts new file mode 100644 index 000000000..3d601d87f --- /dev/null +++ b/packages/image-io/typescript/src/tiff-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import TiffReadImageOptions from './tiff-read-image-options.js' +import TiffReadImageNodeResult from './tiff-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {TiffReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function tiffReadImageNode( + serializedImage: string, + options: TiffReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'tiff-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default tiffReadImageNode diff --git a/packages/image-io/typescript/src/tiff-read-image-result.ts b/packages/image-io/typescript/src/tiff-read-image-result.ts new file mode 100644 index 000000000..b7be7b1da --- /dev/null +++ b/packages/image-io/typescript/src/tiff-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface TiffReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default TiffReadImageResult diff --git a/packages/image-io/typescript/src/tiff-read-image.ts b/packages/image-io/typescript/src/tiff-read-image.ts new file mode 100644 index 000000000..00c807be8 --- /dev/null +++ b/packages/image-io/typescript/src/tiff-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import TiffReadImageOptions from './tiff-read-image-options.js' +import TiffReadImageResult from './tiff-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {TiffReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function tiffReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: TiffReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'tiff-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default tiffReadImage diff --git a/packages/image-io/typescript/src/tiff-write-image-node-result.ts b/packages/image-io/typescript/src/tiff-write-image-node-result.ts new file mode 100644 index 000000000..9f70b9aa8 --- /dev/null +++ b/packages/image-io/typescript/src/tiff-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface TiffWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default TiffWriteImageNodeResult diff --git a/packages/image-io/typescript/src/tiff-write-image-node.ts b/packages/image-io/typescript/src/tiff-write-image-node.ts new file mode 100644 index 000000000..b9c66505e --- /dev/null +++ b/packages/image-io/typescript/src/tiff-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import TiffWriteImageOptions from './tiff-write-image-options.js' +import TiffWriteImageNodeResult from './tiff-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {TiffWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function tiffWriteImageNode( + image: Image, + options: TiffWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'tiff-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default tiffWriteImageNode diff --git a/packages/image-io/typescript/src/tiff-write-image-result.ts b/packages/image-io/typescript/src/tiff-write-image-result.ts new file mode 100644 index 000000000..321ea5409 --- /dev/null +++ b/packages/image-io/typescript/src/tiff-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface TiffWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default TiffWriteImageResult diff --git a/packages/image-io/typescript/src/tiff-write-image.ts b/packages/image-io/typescript/src/tiff-write-image.ts new file mode 100644 index 000000000..ce47d3dd2 --- /dev/null +++ b/packages/image-io/typescript/src/tiff-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import TiffWriteImageOptions from './tiff-write-image-options.js' +import TiffWriteImageResult from './tiff-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {TiffWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function tiffWriteImage( + webWorker: null | Worker, + image: Image, + options: TiffWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'tiff-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default tiffWriteImage diff --git a/packages/image-io/typescript/src/vtk-read-image-node-result.ts b/packages/image-io/typescript/src/vtk-read-image-node-result.ts new file mode 100644 index 000000000..05e6ee6e6 --- /dev/null +++ b/packages/image-io/typescript/src/vtk-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface VtkReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default VtkReadImageNodeResult diff --git a/packages/image-io/typescript/src/vtk-read-image-node.ts b/packages/image-io/typescript/src/vtk-read-image-node.ts new file mode 100644 index 000000000..60d34dd0f --- /dev/null +++ b/packages/image-io/typescript/src/vtk-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import VtkReadImageOptions from './vtk-read-image-options.js' +import VtkReadImageNodeResult from './vtk-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {VtkReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function vtkReadImageNode( + serializedImage: string, + options: VtkReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'vtk-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default vtkReadImageNode diff --git a/packages/image-io/typescript/src/vtk-read-image-result.ts b/packages/image-io/typescript/src/vtk-read-image-result.ts new file mode 100644 index 000000000..498907f09 --- /dev/null +++ b/packages/image-io/typescript/src/vtk-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface VtkReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default VtkReadImageResult diff --git a/packages/image-io/typescript/src/vtk-read-image.ts b/packages/image-io/typescript/src/vtk-read-image.ts new file mode 100644 index 000000000..2daabbdae --- /dev/null +++ b/packages/image-io/typescript/src/vtk-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import VtkReadImageOptions from './vtk-read-image-options.js' +import VtkReadImageResult from './vtk-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {VtkReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function vtkReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: VtkReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'vtk-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default vtkReadImage diff --git a/packages/image-io/typescript/src/vtk-write-image-node-result.ts b/packages/image-io/typescript/src/vtk-write-image-node-result.ts new file mode 100644 index 000000000..dc44f0270 --- /dev/null +++ b/packages/image-io/typescript/src/vtk-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface VtkWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default VtkWriteImageNodeResult diff --git a/packages/image-io/typescript/src/vtk-write-image-node.ts b/packages/image-io/typescript/src/vtk-write-image-node.ts new file mode 100644 index 000000000..a50357d56 --- /dev/null +++ b/packages/image-io/typescript/src/vtk-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import VtkWriteImageOptions from './vtk-write-image-options.js' +import VtkWriteImageNodeResult from './vtk-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {VtkWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function vtkWriteImageNode( + image: Image, + options: VtkWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'vtk-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default vtkWriteImageNode diff --git a/packages/image-io/typescript/src/vtk-write-image-result.ts b/packages/image-io/typescript/src/vtk-write-image-result.ts new file mode 100644 index 000000000..e2784a81d --- /dev/null +++ b/packages/image-io/typescript/src/vtk-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface VtkWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default VtkWriteImageResult diff --git a/packages/image-io/typescript/src/vtk-write-image.ts b/packages/image-io/typescript/src/vtk-write-image.ts new file mode 100644 index 000000000..29250cefc --- /dev/null +++ b/packages/image-io/typescript/src/vtk-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import VtkWriteImageOptions from './vtk-write-image-options.js' +import VtkWriteImageResult from './vtk-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {VtkWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function vtkWriteImage( + webWorker: null | Worker, + image: Image, + options: VtkWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'vtk-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default vtkWriteImage diff --git a/packages/image-io/typescript/src/wasm-read-image-node-result.ts b/packages/image-io/typescript/src/wasm-read-image-node-result.ts new file mode 100644 index 000000000..d1ade3298 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface WasmReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default WasmReadImageNodeResult diff --git a/packages/image-io/typescript/src/wasm-read-image-node.ts b/packages/image-io/typescript/src/wasm-read-image-node.ts new file mode 100644 index 000000000..b6c63c40f --- /dev/null +++ b/packages/image-io/typescript/src/wasm-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import WasmReadImageOptions from './wasm-read-image-options.js' +import WasmReadImageNodeResult from './wasm-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {WasmReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmReadImageNode( + serializedImage: string, + options: WasmReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'wasm-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default wasmReadImageNode diff --git a/packages/image-io/typescript/src/wasm-read-image-result.ts b/packages/image-io/typescript/src/wasm-read-image-result.ts new file mode 100644 index 000000000..aea8fdbac --- /dev/null +++ b/packages/image-io/typescript/src/wasm-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface WasmReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default WasmReadImageResult diff --git a/packages/image-io/typescript/src/wasm-read-image.ts b/packages/image-io/typescript/src/wasm-read-image.ts new file mode 100644 index 000000000..dc5038654 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import WasmReadImageOptions from './wasm-read-image-options.js' +import WasmReadImageResult from './wasm-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {WasmReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: WasmReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'wasm-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default wasmReadImage diff --git a/packages/image-io/typescript/src/wasm-write-image-node-result.ts b/packages/image-io/typescript/src/wasm-write-image-node-result.ts new file mode 100644 index 000000000..fe7a5125f --- /dev/null +++ b/packages/image-io/typescript/src/wasm-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface WasmWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default WasmWriteImageNodeResult diff --git a/packages/image-io/typescript/src/wasm-write-image-node.ts b/packages/image-io/typescript/src/wasm-write-image-node.ts new file mode 100644 index 000000000..c67d1c55d --- /dev/null +++ b/packages/image-io/typescript/src/wasm-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import WasmWriteImageOptions from './wasm-write-image-options.js' +import WasmWriteImageNodeResult from './wasm-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {WasmWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmWriteImageNode( + image: Image, + options: WasmWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'wasm-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default wasmWriteImageNode diff --git a/packages/image-io/typescript/src/wasm-write-image-result.ts b/packages/image-io/typescript/src/wasm-write-image-result.ts new file mode 100644 index 000000000..a69b7b14a --- /dev/null +++ b/packages/image-io/typescript/src/wasm-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface WasmWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default WasmWriteImageResult diff --git a/packages/image-io/typescript/src/wasm-write-image.ts b/packages/image-io/typescript/src/wasm-write-image.ts new file mode 100644 index 000000000..926b8e679 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import WasmWriteImageOptions from './wasm-write-image-options.js' +import WasmWriteImageResult from './wasm-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {WasmWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmWriteImage( + webWorker: null | Worker, + image: Image, + options: WasmWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'wasm-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default wasmWriteImage diff --git a/packages/image-io/typescript/src/wasm-zstd-read-image-node-result.ts b/packages/image-io/typescript/src/wasm-zstd-read-image-node-result.ts new file mode 100644 index 000000000..c5251b65a --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-read-image-node-result.ts @@ -0,0 +1,12 @@ +import { Image } from 'itk-wasm' + +interface WasmZstdReadImageNodeResult { + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default WasmZstdReadImageNodeResult diff --git a/packages/image-io/typescript/src/wasm-zstd-read-image-node.ts b/packages/image-io/typescript/src/wasm-zstd-read-image-node.ts new file mode 100644 index 000000000..b7993b251 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-read-image-node.ts @@ -0,0 +1,78 @@ +// Generated file. To retain edits, remove this comment. + +import { + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import WasmZstdReadImageOptions from './wasm-zstd-read-image-options.js' +import WasmZstdReadImageNodeResult from './wasm-zstd-read-image-node-result.js' + + +import path from 'path' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {string} serializedImage - Input image serialized in the file format + * @param {WasmZstdReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmZstdReadImageNode( + serializedImage: string, + options: WasmZstdReadImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + mountDirs.add(path.dirname(serializedImage as string)) + const inputs: Array = [ + ] + + const args = [] + // Inputs + const serializedImageName = serializedImage + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'wasm-zstd-read-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default wasmZstdReadImageNode diff --git a/packages/image-io/typescript/src/wasm-zstd-read-image-result.ts b/packages/image-io/typescript/src/wasm-zstd-read-image-result.ts new file mode 100644 index 000000000..a268bc665 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-read-image-result.ts @@ -0,0 +1,15 @@ +import { Image } from 'itk-wasm' + +interface WasmZstdReadImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be read. If false, the output image is not valid. */ + couldRead: boolean + + /** Output image */ + image: Image + +} + +export default WasmZstdReadImageResult diff --git a/packages/image-io/typescript/src/wasm-zstd-read-image.ts b/packages/image-io/typescript/src/wasm-zstd-read-image.ts new file mode 100644 index 000000000..39f083233 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-read-image.ts @@ -0,0 +1,86 @@ +// Generated file. To retain edits, remove this comment. + +import { + BinaryFile, + JsonObject, + Image, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import WasmZstdReadImageOptions from './wasm-zstd-read-image-options.js' +import WasmZstdReadImageResult from './wasm-zstd-read-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {WasmZstdReadImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmZstdReadImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: WasmZstdReadImageOptions = {} +) : Promise { + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.Image }, + ] + + let serializedImageFile = serializedImage + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + const inputs: Array = [ + { type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, + ] + + const args = [] + // Inputs + const serializedImageName = (serializedImageFile as BinaryFile).path + args.push(serializedImageName as string) + + // Outputs + const couldReadName = '0' + args.push(couldReadName) + + const imageName = '1' + args.push(imageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + + const pipelinePath = 'wasm-zstd-read-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldRead: (outputs[0].data as JsonObject).data, + image: outputs[1].data as Image, + } + return result +} + +export default wasmZstdReadImage diff --git a/packages/image-io/typescript/src/wasm-zstd-write-image-node-result.ts b/packages/image-io/typescript/src/wasm-zstd-write-image-node-result.ts new file mode 100644 index 000000000..d1478e164 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-write-image-node-result.ts @@ -0,0 +1,10 @@ +interface WasmZstdWriteImageNodeResult { + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: string + +} + +export default WasmZstdWriteImageNodeResult diff --git a/packages/image-io/typescript/src/wasm-zstd-write-image-node.ts b/packages/image-io/typescript/src/wasm-zstd-write-image-node.ts new file mode 100644 index 000000000..83698dbba --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-write-image-node.ts @@ -0,0 +1,82 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipelineNode +} from 'itk-wasm' + +import WasmZstdWriteImageOptions from './wasm-zstd-write-image-options.js' +import WasmZstdWriteImageNodeResult from './wasm-zstd-write-image-node-result.js' + + +import path from 'path' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {WasmZstdWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmZstdWriteImageNode( + image: Image, + options: WasmZstdWriteImageOptions = {} +) : Promise { + + const mountDirs: Set = new Set() + + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile }, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + args.push(serializedImageName) + mountDirs.add(path.dirname(serializedImageName)) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'wasm-zstd-write-image') + + const { + returnValue, + stderr, + outputs + } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as string, + } + return result +} + +export default wasmZstdWriteImageNode diff --git a/packages/image-io/typescript/src/wasm-zstd-write-image-result.ts b/packages/image-io/typescript/src/wasm-zstd-write-image-result.ts new file mode 100644 index 000000000..0133b9019 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-write-image-result.ts @@ -0,0 +1,15 @@ +import { BinaryFile } from 'itk-wasm' + +interface WasmZstdWriteImageResult { + /** WebWorker used for computation */ + webWorker: Worker | null + + /** Whether the input could be written. If false, the output image is not valid. */ + couldWrite: boolean + + /** Output image serialized in the file format. */ + serializedImage: BinaryFile + +} + +export default WasmZstdWriteImageResult diff --git a/packages/image-io/typescript/src/wasm-zstd-write-image.ts b/packages/image-io/typescript/src/wasm-zstd-write-image.ts new file mode 100644 index 000000000..ae8f28ca1 --- /dev/null +++ b/packages/image-io/typescript/src/wasm-zstd-write-image.ts @@ -0,0 +1,85 @@ +// Generated file. To retain edits, remove this comment. + +import { + Image, + JsonObject, + BinaryFile, + InterfaceTypes, + PipelineOutput, + PipelineInput, + runPipeline +} from 'itk-wasm' + +import WasmZstdWriteImageOptions from './wasm-zstd-write-image-options.js' +import WasmZstdWriteImageResult from './wasm-zstd-write-image-result.js' + + +import { getPipelinesBaseUrl } from './pipelines-base-url.js' +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + +/** + * Write an itk-wasm file format converted to an image file format + * + * @param {Image} image - Input image + * @param {WasmZstdWriteImageOptions} options - options object + * + * @returns {Promise} - result object + */ +async function wasmZstdWriteImage( + webWorker: null | Worker, + image: Image, + options: WasmZstdWriteImageOptions = {} +) : Promise { + + const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath + const desiredOutputs: Array = [ + { type: InterfaceTypes.JsonObject }, + { type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, + ] + + const inputs: Array = [ + { type: InterfaceTypes.Image, data: image }, + ] + + const args = [] + // Inputs + const imageName = '0' + args.push(imageName as string) + + // Outputs + const couldWriteName = '0' + args.push(couldWriteName) + + const serializedImageName = serializedImagePath + args.push(serializedImageName) + + // Options + args.push('--memory-io') + if (typeof options.informationOnly !== "undefined") { + options.informationOnly && args.push('--information-only') + } + if (typeof options.useCompression !== "undefined") { + options.useCompression && args.push('--use-compression') + } + + const pipelinePath = 'wasm-zstd-write-image' + + const { + webWorker: usedWebWorker, + returnValue, + stderr, + outputs + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) + if (returnValue !== 0) { + throw new Error(stderr) + } + + const result = { + webWorker: usedWebWorker as Worker, + couldWrite: (outputs[0].data as JsonObject).data, + serializedImage: outputs[1].data as BinaryFile, + } + return result +} + +export default wasmZstdWriteImage