From b80fd47593f1ed8da76d7d97233579e5b27117c7 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 8 Oct 2023 21:35:28 -0400 Subject: [PATCH] feat(image-io): add readImage --- package.json | 2 +- .../compare-double-images.wasi.wasm | Bin 1591412 -> 1591348 bytes .../wasm_modules/vector-magnitude.wasi.wasm | Bin 1441632 -> 1441568 bytes .../typescript/src/vector-magnitude-node.ts | 4 +- .../typescript/src/vector-magnitude.ts | 4 +- .../typescript/src/compress-stringify-node.ts | 4 +- .../typescript/src/compress-stringify.ts | 4 +- .../src/parse-string-decompress-node.ts | 4 +- .../typescript/src/parse-string-decompress.ts | 4 +- ...pply-presentation-state-to-image.wasi.wasm | Bin 5231236 -> 5231172 bytes .../read-image-dicom-file-series.wasi.wasm | Bin 6070364 -> 6070300 bytes .../apply-presentation-state-to-image-node.ts | 6 +- .../src/apply-presentation-state-to-image.ts | 6 +- .../src/read-dicom-encapsulated-pdf-node.ts | 4 +- .../src/read-dicom-encapsulated-pdf.ts | 4 +- .../src/read-image-dicom-file-series-node.ts | 6 +- .../src/structured-report-to-html-node.ts | 4 +- .../src/structured-report-to-html.ts | 4 +- .../src/structured-report-to-text-node.ts | 4 +- .../src/structured-report-to-text.ts | 4 +- packages/image-io/CMakeLists.txt | 6 +- packages/image-io/image-io-index.ts.in | 3 - .../typescript/cypress/e2e/read-image.cy.ts | 59 +++++++ .../typescript/src/bio-rad-read-image-node.ts | 6 +- .../typescript/src/bio-rad-read-image.ts | 6 +- .../src/bio-rad-write-image-node.ts | 4 +- .../typescript/src/bio-rad-write-image.ts | 6 +- .../typescript/src/bmp-read-image-node.ts | 6 +- .../image-io/typescript/src/bmp-read-image.ts | 6 +- .../typescript/src/bmp-write-image-node.ts | 4 +- .../typescript/src/bmp-write-image.ts | 6 +- .../typescript/src/fdf-read-image-node.ts | 6 +- .../image-io/typescript/src/fdf-read-image.ts | 6 +- .../typescript/src/fdf-write-image-node.ts | 4 +- .../typescript/src/fdf-write-image.ts | 6 +- .../typescript/src/gdcm-read-image-node.ts | 6 +- .../typescript/src/gdcm-read-image.ts | 6 +- .../typescript/src/gdcm-write-image-node.ts | 4 +- .../typescript/src/gdcm-write-image.ts | 6 +- .../typescript/src/ge-adw-read-image-node.ts | 6 +- .../typescript/src/ge-adw-read-image.ts | 6 +- .../typescript/src/ge-adw-write-image-node.ts | 4 +- .../typescript/src/ge-adw-write-image.ts | 6 +- .../typescript/src/ge4-read-image-node.ts | 6 +- .../image-io/typescript/src/ge4-read-image.ts | 6 +- .../typescript/src/ge4-write-image-node.ts | 4 +- .../typescript/src/ge4-write-image.ts | 6 +- .../typescript/src/ge5-read-image-node.ts | 6 +- .../image-io/typescript/src/ge5-read-image.ts | 6 +- .../typescript/src/ge5-write-image-node.ts | 4 +- .../typescript/src/ge5-write-image.ts | 6 +- .../typescript/src/gipl-read-image-node.ts | 6 +- .../typescript/src/gipl-read-image.ts | 6 +- .../typescript/src/gipl-write-image-node.ts | 4 +- .../typescript/src/gipl-write-image.ts | 6 +- .../typescript/src/hdf5-read-image-node.ts | 6 +- .../typescript/src/hdf5-read-image.ts | 6 +- .../typescript/src/hdf5-write-image-node.ts | 4 +- .../typescript/src/hdf5-write-image.ts | 6 +- packages/image-io/typescript/src/index.ts | 9 +- .../typescript/src/jpeg-read-image-node.ts | 6 +- .../typescript/src/jpeg-read-image.ts | 6 +- .../typescript/src/jpeg-write-image-node.ts | 4 +- .../typescript/src/jpeg-write-image.ts | 6 +- .../typescript/src/lsm-read-image-node.ts | 6 +- .../image-io/typescript/src/lsm-read-image.ts | 6 +- .../typescript/src/lsm-write-image-node.ts | 4 +- .../typescript/src/lsm-write-image.ts | 6 +- .../typescript/src/meta-read-image-node.ts | 6 +- .../typescript/src/meta-read-image.ts | 6 +- .../typescript/src/meta-write-image-node.ts | 4 +- .../typescript/src/meta-write-image.ts | 6 +- .../typescript/src/mgh-read-image-node.ts | 6 +- .../image-io/typescript/src/mgh-read-image.ts | 6 +- .../typescript/src/mgh-write-image-node.ts | 4 +- .../typescript/src/mgh-write-image.ts | 6 +- .../typescript/src/minc-read-image-node.ts | 6 +- .../typescript/src/minc-read-image.ts | 6 +- .../typescript/src/minc-write-image-node.ts | 4 +- .../typescript/src/minc-write-image.ts | 6 +- .../typescript/src/mrc-read-image-node.ts | 6 +- .../image-io/typescript/src/mrc-read-image.ts | 6 +- .../typescript/src/mrc-write-image-node.ts | 4 +- .../typescript/src/mrc-write-image.ts | 6 +- .../typescript/src/nifti-read-image-node.ts | 6 +- .../typescript/src/nifti-read-image.ts | 6 +- .../typescript/src/nifti-write-image-node.ts | 4 +- .../typescript/src/nifti-write-image.ts | 6 +- .../typescript/src/nrrd-read-image-node.ts | 6 +- .../typescript/src/nrrd-read-image.ts | 6 +- .../typescript/src/nrrd-write-image-node.ts | 4 +- .../typescript/src/nrrd-write-image.ts | 6 +- .../typescript/src/png-read-image-node.ts | 6 +- .../image-io/typescript/src/png-read-image.ts | 6 +- .../typescript/src/png-write-image-node.ts | 4 +- .../typescript/src/png-write-image.ts | 6 +- .../typescript/src/read-image-file-series.ts | 91 +++++++++++ .../typescript/src/read-image-node.ts | 14 +- .../typescript/src/read-image-options.ts | 3 + .../typescript/src/read-image-result.ts | 17 +- .../image-io/typescript/src/read-image.ts | 90 ++++++++++ .../typescript/src/scanco-read-image-node.ts | 6 +- .../typescript/src/scanco-read-image.ts | 6 +- .../typescript/src/scanco-write-image-node.ts | 4 +- .../typescript/src/scanco-write-image.ts | 6 +- .../typescript/src/tiff-read-image-node.ts | 6 +- .../typescript/src/tiff-read-image.ts | 6 +- .../typescript/src/tiff-write-image-node.ts | 4 +- .../typescript/src/tiff-write-image.ts | 6 +- .../typescript/src/vtk-read-image-node.ts | 6 +- .../image-io/typescript/src/vtk-read-image.ts | 6 +- .../typescript/src/vtk-write-image-node.ts | 4 +- .../typescript/src/vtk-write-image.ts | 6 +- .../typescript/src/wasm-read-image-node.ts | 6 +- .../typescript/src/wasm-read-image.ts | 6 +- .../typescript/src/wasm-write-image-node.ts | 4 +- .../typescript/src/wasm-write-image.ts | 6 +- .../src/wasm-zstd-read-image-node.ts | 6 +- .../typescript/src/wasm-zstd-read-image.ts | 6 +- .../src/wasm-zstd-write-image-node.ts | 4 +- .../typescript/src/wasm-zstd-write-image.ts | 6 +- .../test/browser/demo-app/index.html | 57 ++++++- .../typescript/test/browser/demo-app/index.ts | 10 +- .../browser/demo-app/read-image-controller.ts | 154 ++++++++++++++++++ .../demo-app/read-image-load-sample-inputs.ts | 20 +++ src/bindgen/typescript/function-module.js | 15 +- 126 files changed, 794 insertions(+), 328 deletions(-) delete mode 100644 packages/image-io/image-io-index.ts.in create mode 100644 packages/image-io/typescript/cypress/e2e/read-image.cy.ts create mode 100644 packages/image-io/typescript/src/read-image-file-series.ts create mode 100644 packages/image-io/typescript/src/read-image.ts create mode 100644 packages/image-io/typescript/test/browser/demo-app/read-image-controller.ts create mode 100644 packages/image-io/typescript/test/browser/demo-app/read-image-load-sample-inputs.ts diff --git a/package.json b/package.json index 0c018e55b..cb1b204f1 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "build": "npm run build:testData && npm run build:emscripten && npm run build:tsc && npm run build:tscWorkersModuleLoader && npm run build:tscWebWorkers && npm run build:workerBundles && npm run build:workerMinBundles && npm run build:webpack && node ./src/io/internal/packages/package-json-gen.cjs && npm run build:emscripten:packages", "build:testData": "npm run build:testData:dicom && npm run build:testData:image-io", "build:testData:dicom": "dam download packages/dicom/test/data packages/dicom/test/data.tar.gz bafybeicskxufnvuem6342pkfwgeo3siiozgzmfo5f34woge6aptuzuwzzu https://github.com/InsightSoftwareConsortium/itk-wasm/releases/download/itk-wasm-v1.0.0-b.119/dicom-test-data.tar.gz https://w3s.link/ipfs/bafybeiby67winzvozowf4moqthwunuxxscssitnb6wahxv4ugvfxhu2vki/data.tar.gz", - "build:testData:image-io": "dam download packages/image-io/test/data packages/image-io/test/data.tar.gz bafybeidehh27iwse4s5ybxlhg63e46n5osff4rmbc5wqczeuto56phofxu https://w3s.link/ipfs/bafybeievzv4yo7nrhrwt27x6nkyvlo4gznz6o2igaihywbjw7qwqje6q3q", + "build:testData:image-io": "dam download packages/image-io/test/data packages/image-io/test/data.tar.gz bafybeibyjhkcrinl2lotw5g2vngjs23aaenv3tjzxssm35jxaci5ylsqia https://w3s.link/ipfs/bafybeiewe4rankwwe7nw7qm2g3qclflhci2e53wthn3gukdlhbff64pua4/data.tar.gz", "build:debug": "npm run build:emscripten -- --debug && npm run build:tsc && npm run build:tscWorkersModuleLoader && npm run build:tscWebWorkers && npm run build:workerBundles && npm run build:workerMinBundles && npm run build:webpack -- --mode development", "build:tsc": "tsc --pretty", "build:tscWorkersModuleLoader": "tsc --types --lib es2017,webworker --rootDir ./src/ --outDir ./dist/ --moduleResolution node --target es2017 --module es2020 --strict --forceConsistentCasingInFileNames --declaration ./src/core/internal/loadEmscriptenModuleWebWorker.ts", diff --git a/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm b/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm index faa55383de40b943b507e6d247fd8d18fb80775c..39a37bb426d8e2bb346a46ae651dcb810a8e13a3 100755 GIT binary patch delta 1123 zcmbu8KW`H;7>DiGKHn85?X{($q64o_9mr7FG8Be*AmIyu5JRP|mx-{j9ipl_u$1Y< zf~dq==zvt%VCo28phL#aR6=5bpYPHtjmiR%ev0Ei?>+ZE>&v$KB0?Zaew*`oV|R zyBkS4T8dj+8||HqwnPX~h(;pBATg34GsqRhA`PU8%p!A#8}0P*Q}t5U)ylV{`KWB( znO`m?Mm!COW{S}C*wlPO zXDo;A>Mkeg`xqL1ny(5rhod*?-d)<#<=4_KmItq9qjLMj!g8URf^O|Z&`o3ACg{eC zvYF7WSp?lUQRxo8DCnkIH$3a$S)Y53K{B?Cm2k42F`@Bn@+@)%O?6UTbgj-jN7J6w z1<#7H0rzLpb2T&R8S>9PQ{BWOsyut)6z(rh;CitcyAGWAAN)Jvq~}ROc&;=@y+?q) z1hMiwMyv@dx-+(+Q?}|QJcrI!s&%be%~@eT-!At)&0a6R_Y=Kybetmd$O5v6Tt$|U L*5T3dwf+1LLI}R2 delta 1179 zcmcIiF^dyH6rOoA+1*%`QEDEyfa%o+KiDLCO37oo;s8*scR~7q`-%7mLAl*x|M8(#0**HpL&1PMxn5au# z#I(~xTqE~G-*o5uRXoS0SH-)aIJ=yX+gJT6I*{85vFhO-p^W>AIQFb1q8&*s?aYuZ zYdPOny;hvr3ZZQ_C?Cqg_CV6IH*}e-JiJpdoUxJAIl~$2C5Cv8igx4&qUZoQAo{%^ zDoJyqnK1b>Won!`j7#`n7Pj;7v>v7eg3}g1OAE6O^kE0T_>bap$TEG~Wj}i1LuMDH zXB3xfp$fm9ThZC%{iEo?C3<4>cX`+-d|{q7*7A>^>dnj(8;IiGk`1801ntxY7%*G0 zfh}x6zv=ITK`T+BzE}jAMMOM+38#OwK(^q4|D^wt{0_=4S|B@;2WAY9rvG2%zaa)T z?jQ7rw`JDQUnak30TK(mxsX48y>cr5&=2f*yc+>^;5g6#P5`Swb28pNxt;z5rPaqv diff --git a/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm b/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm index d514fc75e2e96676e871435ff63654d990c6b24f..2d7e6ac0c621fa57325bb2f22b38a34acc1b7836 100755 GIT binary patch delta 1093 zcmbV~y=xRf7>D0^XLk1D$`H z1!1dzb`}xR$YCe=7YMe3mZ=pKh3IeYBi;oA;=+%eozG|AXFeUQJwI66YuDB8)_Q$= zy{-^OG-8khu}F$kkSXK@;*e>i+FP&JireZ@x$-odEuUPpY594zHdp@aWm8?AR!(%t zIzhDx%6C)Gk_d$dcfVWWq}?vT?$qMCT7HqFaHM2m_axe1#jaVI)}~SCG)# zVk*$Bg60c#vq}=TL0fx@%UgxxK?xlimODZak?^AQ$r_=1>w#(hBa!!n- zO+coi+o2mnSfeKD2k(c9c~HLu7s$ClUgPFs0WOx)9FoGfgG521*rX7POkwV>(DrPuvP;rjD#2m}g=?chQ$ zW3S&(5JMU=Pzeg45Q?BOv;xIY1*(qvjhfw3&x+ND$y)K?ToC3e-H$A}kK^$;+%j!$ z3%Ql+rY$9*D-=s94FmOD=Q5W$akR#f}|MCDXexKY_d{ECgSl*;6&yvpu0kWd&K zn=Q4Fo{m_di5)F}g250Qjf%!bpV>ReL9o$Fe!0Eb+1Y33*_)kTqW7tYEhcj+GJa@^UrOCQwD(hss8>=oi8e6{(0ZY2`Ggk^L`r8uvG5fWA72}8O zc2^fUlmD4PjW%EI73?p*dXZbbOEWrox~|%ih0eT|GWqhnxvQ#~T;bXXS2)!R_g&$5 zRQ4MR*DPG&xFRjwHAb#*suhl=wQE{$HXR^Ky=Ru1upbVd&cS)O03&b_F2Q9Og)u0Cg)49suE99OP=X1#4wG;LZo;j_<<;A7KK%jq C(@A6i delta 1413 zcmcK3JyR1w9LMq9z0DIxLX-!U_^@}P;zK|bQ4uk#ay%$HmUhyHN-Dd+$P5JyV_{x^ zTG`MsR#^BF@Es@)W8?TdHu1YjKo}VY3p4YX-2HEN@4uU0-aKDcvoDs_;)6)Oe>@S* zO+*q39yDTzBY`ARXn>DKq?ab5Oxu`zS)RF@ZGE~jm?+8Y=Ts={r%I)g7}W(;Fv2#B z>w<|H(Jy=x3sj@@DK<@6SqydddooZw)OMQBqp3cX<{YP8%d?aW91f; z)|)iiNH<_jM7cmWDzT# zJII%WpwnNqPTj06oqnly>RE4V`D?wbH_FxZI3*gaZt>lw9mqdBSnq!-Nco1-AJN%@ zNo0Q}`JHXH*da`6Y5GZK^`3gB%QN4-=JLWqCe^Dq$3w5jL)YRVTs(9=9&r~BmxOrP z+|RU>r{4}HOVVhU23<>o`YQ$r8p(yiWxyqc*|myG0tdaTBKs$0ch(kDxBQOXM;wU6*+&ef06~vEsR#f}|Q4|$XZ&dE^8&UDIqgyJkvRe}pDQt|* zH5M8ROYLYZFwuX&%0ft#idIcbZ1kDEgB%1Kz2ukMo1L9~cAmY@GvDYLy!jf-*OT+{ z)O;*~K!FAid~DGB_LTED&AODw zeG#!fIU>6t%6UA2n;nsxAepd?{fTjxF&&YX+*;DA2@Y7g^9!QXVUi$6p<5TrhaqbY zN(dRSny`sGayhl}k>)=V{`yP8@1i`mdPKh#@rR4(uSn>Z*stZQ7(ZmUySm7k!iNAg z+CtnZ*q@#&^vsRWq^^GHYHF$WKFVn+tMA@=ZHZ=bg=-^R;Z!f&cZK6o*>5OZvv7su zinMUo7`ei!Rydm0u4%p0bbu`No^i%qSsU@)*0Uc+o=IrMUaIA7tHq|hl})QutN7_$T~(!p5c>6Qb#~Xssr}rYIeK__CqfmfP>Hnhu|>u!x1fHqL$_2=*{z8Qw8rKd zO-yJ^Z0zU^h5iFJS{M_>h6QHLznU@hv=fOTlZdNg4JHX?^+Y{F)2fkA)}Td@t> zu>(8Nf?e2+J=i-r9ksrhP|tPg?xT)|(!+NtKbF~N$xzrY<#O5Y(*;#9!dCa|f~hj1 zQ>0B*plW2A#=21}qflpG`GMl4w)gqm8_laEzf@icHzKce+9)H9$UaRP5n1NoMT-)F z&(u6DC=`MA3dXZ43Z(H`g$R_QKH8*} z!}Ls?6-muX| zx(+jGV^lwh4oh4a<8k&6}1SG}x4mQ$7OxGxH22d%LX zRQj`0sT;Md(rde&Rs{C&PzFE-E3$0gH+mZ`n@_^Fn;#6 zPtGdaF@#-SBr1$SJ$8)z+E!@HtGyb0u z=PS2##f-VX?yTK^nUi0dvKoIf)P{C+U?2A501o01@;HnmIEqdjLl=(Y1Wuv=i&Hp_ tGw4PUJ?KRr&f*--qaPP=5d#>+C0xc8T*Wn9#|_-XE!>`bGIS^I`UN--OUVEL diff --git a/packages/dicom/typescript/src/apply-presentation-state-to-image-node.ts b/packages/dicom/typescript/src/apply-presentation-state-to-image-node.ts index c00f4cf35..7b3c58479 100644 --- a/packages/dicom/typescript/src/apply-presentation-state-to-image-node.ts +++ b/packages/dicom/typescript/src/apply-presentation-state-to-image-node.ts @@ -86,13 +86,13 @@ async function applyPresentationStateToImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - presentationStateOutStream: outputs[0].data as JsonCompatible, - outputImage: outputs[1].data as Image, + presentationStateOutStream: outputs[0]?.data as JsonCompatible, + outputImage: outputs[1]?.data as Image, } return result } diff --git a/packages/dicom/typescript/src/apply-presentation-state-to-image.ts b/packages/dicom/typescript/src/apply-presentation-state-to-image.ts index 5c28165c7..0af6d61b5 100644 --- a/packages/dicom/typescript/src/apply-presentation-state-to-image.ts +++ b/packages/dicom/typescript/src/apply-presentation-state-to-image.ts @@ -96,14 +96,14 @@ async function applyPresentationStateToImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - presentationStateOutStream: outputs[0].data as JsonCompatible, - outputImage: outputs[1].data as Image, + presentationStateOutStream: outputs[0]?.data as JsonCompatible, + outputImage: outputs[1]?.data as Image, } return result } diff --git a/packages/dicom/typescript/src/read-dicom-encapsulated-pdf-node.ts b/packages/dicom/typescript/src/read-dicom-encapsulated-pdf-node.ts index e60ec3145..466314556 100644 --- a/packages/dicom/typescript/src/read-dicom-encapsulated-pdf-node.ts +++ b/packages/dicom/typescript/src/read-dicom-encapsulated-pdf-node.ts @@ -102,12 +102,12 @@ async function readDicomEncapsulatedPdfNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - pdfBinaryOutput: (outputs[0].data as BinaryStream).data, + pdfBinaryOutput: (outputs[0]?.data as BinaryStream).data, } return result } diff --git a/packages/dicom/typescript/src/read-dicom-encapsulated-pdf.ts b/packages/dicom/typescript/src/read-dicom-encapsulated-pdf.ts index d16ed44a0..de43f1dbd 100644 --- a/packages/dicom/typescript/src/read-dicom-encapsulated-pdf.ts +++ b/packages/dicom/typescript/src/read-dicom-encapsulated-pdf.ts @@ -108,13 +108,13 @@ async function readDicomEncapsulatedPdf( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - pdfBinaryOutput: (outputs[0].data as BinaryStream).data, + pdfBinaryOutput: (outputs[0]?.data as BinaryStream).data, } return result } diff --git a/packages/dicom/typescript/src/read-image-dicom-file-series-node.ts b/packages/dicom/typescript/src/read-image-dicom-file-series-node.ts index 29974fe86..b038dfc01 100644 --- a/packages/dicom/typescript/src/read-image-dicom-file-series-node.ts +++ b/packages/dicom/typescript/src/read-image-dicom-file-series-node.ts @@ -69,13 +69,13 @@ async function readImageDicomFileSeriesNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - outputImage: outputs[0].data as Image, - sortedFilenames: outputs[1].data as JsonCompatible, + outputImage: outputs[0]?.data as Image, + sortedFilenames: outputs[1]?.data as JsonCompatible, } return result } diff --git a/packages/dicom/typescript/src/structured-report-to-html-node.ts b/packages/dicom/typescript/src/structured-report-to-html-node.ts index 63975ae07..bc5c2f309 100644 --- a/packages/dicom/typescript/src/structured-report-to-html-node.ts +++ b/packages/dicom/typescript/src/structured-report-to-html-node.ts @@ -188,12 +188,12 @@ async function structuredReportToHtmlNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - outputText: (outputs[0].data as TextStream).data, + outputText: (outputs[0]?.data as TextStream).data, } return result } diff --git a/packages/dicom/typescript/src/structured-report-to-html.ts b/packages/dicom/typescript/src/structured-report-to-html.ts index e4c57f609..9ef684a2b 100644 --- a/packages/dicom/typescript/src/structured-report-to-html.ts +++ b/packages/dicom/typescript/src/structured-report-to-html.ts @@ -200,13 +200,13 @@ async function structuredReportToHtml( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - outputText: (outputs[0].data as TextStream).data, + outputText: (outputs[0]?.data as TextStream).data, } return result } diff --git a/packages/dicom/typescript/src/structured-report-to-text-node.ts b/packages/dicom/typescript/src/structured-report-to-text-node.ts index 956a28008..bab2b3ec8 100644 --- a/packages/dicom/typescript/src/structured-report-to-text-node.ts +++ b/packages/dicom/typescript/src/structured-report-to-text-node.ts @@ -108,12 +108,12 @@ async function structuredReportToTextNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - outputText: (outputs[0].data as TextStream).data, + outputText: (outputs[0]?.data as TextStream).data, } return result } diff --git a/packages/dicom/typescript/src/structured-report-to-text.ts b/packages/dicom/typescript/src/structured-report-to-text.ts index 3ede8e2db..b01801138 100644 --- a/packages/dicom/typescript/src/structured-report-to-text.ts +++ b/packages/dicom/typescript/src/structured-report-to-text.ts @@ -114,13 +114,13 @@ async function structuredReportToText( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - outputText: (outputs[0].data as TextStream).data, + outputText: (outputs[0]?.data as TextStream).data, } return result } diff --git a/packages/image-io/CMakeLists.txt b/packages/image-io/CMakeLists.txt index cfab993a5..cb3f26495 100644 --- a/packages/image-io/CMakeLists.txt +++ b/packages/image-io/CMakeLists.txt @@ -210,10 +210,6 @@ foreach(io_module ${WebAssemblyInterface_ImageIOModules} WebAssemblyInterface) endif() endforeach() endforeach() -if(EMSCRIPTEN) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/image-io-index.ts.in - ${CMAKE_CURRENT_SOURCE_DIR}/typescript/src/image-io-index.ts @ONLY) -endif() enable_testing() @@ -231,4 +227,4 @@ add_test(NAME bio-rad-write-image-test COMMAND bio-rad-write-image ${baseline_dir}/bio-rad-read-image-test.iwi.cbor ${output_dir}/bio-rad-write-image-test.could-write.json - ${output_dir}/bio-rad-write-image-test.pic) \ No newline at end of file + ${output_dir}/bio-rad-write-image-test.pic) diff --git a/packages/image-io/image-io-index.ts.in b/packages/image-io/image-io-index.ts.in deleted file mode 100644 index f7daad830..000000000 --- a/packages/image-io/image-io-index.ts.in +++ /dev/null @@ -1,3 +0,0 @@ -const ImageIOIndex = [@ImageIOIndex_ARRAY@] - -export default ImageIOIndex diff --git a/packages/image-io/typescript/cypress/e2e/read-image.cy.ts b/packages/image-io/typescript/cypress/e2e/read-image.cy.ts new file mode 100644 index 000000000..9363c355b --- /dev/null +++ b/packages/image-io/typescript/cypress/e2e/read-image.cy.ts @@ -0,0 +1,59 @@ +import { demoServer } from './common.ts' + +// const cthead1SmallBase64DataURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfhBQYVKw8AZTNIAAADdklEQVQ4y2WTa2wUVRiGp6W7O3POnLmc2VrstokJlrBIUBJigjfSICVCCAo/QKM/FFNRIESJQKAws3M7M2f20t3GthRKQQq0kkoXMIq9oFwCXkg0UpMakGLgR9EmJF4TNOvZhRBb31+TvM955/vO+T6Ou69pAgSwKCCAEPc/lYUhFEUkMgH2ESmbYocEEUmKLIQqBKmEgUlERQhAPhyJiDMXPFZZDmRGoP8Q5TwC4ciMpatfXE9zmT2NVRVIQiLi76cDUVRDT/m72zLUc/Srv+gNCi8jhCrupvMAQIWf1zJx58pRj7g7h/sduunhiIIkUAJ4AUBZ0LZev3TondmeS42TuaYms6kOapJUalYQAAKxt+j4qD3yxvMZ0z47NLi/ydhWA7GMinWyAH6G1Wwe/OdUz6dz33T35dPdIxdIYrPGK0qxTnYrobVtjm+3pNvPxGu9/dTRgw8/e89et0AKF1uFItS2u7ZP7fr4K3H19VbP94me/T6fXRifM6+a/QKC6N5+PWGYZhVeNn9pzvUoTVnt3/QEz81dUTONgwjis4UzvS2Z5JbY9JlPdxmEuFZzX9va0yu5WlXmRAlWd3Tmjg980vXBprJZbYPtza0dXw40ZleeP1ZbrWKOXXpsu7Grb3gnsY/27B46+e3ElVuF3w+sm7Pki2VAUxkAo1t0a7TL8YnVPZxy6KG9fX/+2qu/+9DARoAVBiDYaHjnfc/3nHOdicA1Em6WpnOdG/I6zwCA5PCzrn6uw6VO99gBnRBKGUyIMfz3BgmrHHta8cEdu04dN6wjPwy6FinaTNT8emKNzGrgBEmJLLf7T6Tf/60wpFP2oKToB/bNr+pVTWHjghQxZuTzW51C4aIZENdj8gMv+1f3I7iYwPEqrFu+z1/zzI3vHN/ziEd9P0haV39aXxXFRaBMRrCu9Vjj5o/S5C4QBCnjws+pJ9SoqpZmRlqyeNWlPa922El22PMCl5if38q9FGV+CeAaFuK4OZY5nLRoksnsPX19nL5do2GsREoAlCtr68lo4VoXNROWdXD8j7GUNV96AMPye5MtYgU/ujF/887tHy+PXLt9o9/asUipvDfWpc1QNFWKPfla8PHI5Ysnsua2l2dH1Un7WS6rKlamxx9f/MKKhkX1syoxmLqcUMVRDTNMlZGkilPsUrOsJ6wxRSel/wuAkzbenLRf4gAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wNS0wNlQxNzoyNjozNC0wNDowMORO/MMAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDUtMDZUMTc6MjY6MzQtMDQ6MDCVE0R/AAAAAElFTkSuQmCC' +// const byteString = window.atob(cthead1SmallBase64DataURI.split(',')[1]) +// const mimeString = cthead1SmallBase64DataURI.split(',')[0].split(':')[1].split(';')[0] +// const intArray = new Uint8Array(byteString.length) +// for (let ii = 0; ii < byteString.length; ++ii) { +// intArray[ii] = byteString.charCodeAt(ii) +// } + +// const cthead1SmallBlob = new window.Blob([intArray], { type: mimeString }) +// const cthead1SmallFile = new window.File([cthead1SmallBlob], 'cthead1Small.png') + +function verifyImage (t, image, componentType, pixelType) { + t.is(image.imageType.dimension, 2, 'dimension') + t.is(image.imageType.componentType, componentType) + t.is(image.imageType.pixelType, pixelType) + t.is(image.imageType.components, 1, 'components') + t.is(image.origin[0], 0.0, 'origin[0]') + t.is(image.origin[1], 0.0, 'origin[1]') + t.is(image.spacing[0], 1.0, 'spacing[0]') + t.is(image.spacing[1], 1.0, 'spacing[1]') + t.is(getMatrixElement(image.direction, 2, 0, 0), 1.0, 'direction (0, 0)') + t.is(getMatrixElement(image.direction, 2, 0, 1), 0.0, 'direction (0, 1)') + t.is(getMatrixElement(image.direction, 2, 1, 0), 0.0, 'direction (1, 0)') + t.is(getMatrixElement(image.direction, 2, 1, 1), 1.0, 'direction (1, 1)') + t.is(image.size[0], 32, 'size[0]') + t.is(image.size[1], 32, 'size[1]') + t.is(image.data.length, 1024, 'data.length') + t.is(image.data[512], 12, 'data[512]') + t.end() +} + +describe('read-image', () => { + beforeEach(function() { + cy.visit(demoServer) + + const testPathPrefix = '../test/data/input/' + + const testImageFiles = [ + 'cthead1.png' + ] + testImageFiles.forEach((fileName) => { + cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName) + }) + }) + + it('Reads a image', function () { + cy.get('sl-tab[panel="readImage-panel"]').click() + + const testFile = { contents: new Uint8Array(this['cthead1.png']), fileName: 'cthead1.png' } + cy.get('#readImageInputs input[name="serialized-image-file"]').selectFile([testFile,], { force: true }) + cy.get('#readImage-serialized-image-details').should('contain', '137,80') + + cy.get('#readImageInputs sl-button[name="run"]').click() + + cy.get('#readImage-image-details').should('contain', 'imageType') + }) +}) 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 index 388f61ed5..881e833dc 100644 --- a/packages/image-io/typescript/src/bio-rad-read-image-node.ts +++ b/packages/image-io/typescript/src/bio-rad-read-image-node.ts @@ -65,13 +65,13 @@ async function bioRadReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/bio-rad-read-image.ts b/packages/image-io/typescript/src/bio-rad-read-image.ts index 48c89dbbf..6177af870 100644 --- a/packages/image-io/typescript/src/bio-rad-read-image.ts +++ b/packages/image-io/typescript/src/bio-rad-read-image.ts @@ -71,14 +71,14 @@ async function bioRadReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } 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 index dc1e3eacf..9a69f2c07 100644 --- a/packages/image-io/typescript/src/bio-rad-write-image-node.ts +++ b/packages/image-io/typescript/src/bio-rad-write-image-node.ts @@ -69,12 +69,12 @@ async function bioRadWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/bio-rad-write-image.ts b/packages/image-io/typescript/src/bio-rad-write-image.ts index d3b328503..ec0722a82 100644 --- a/packages/image-io/typescript/src/bio-rad-write-image.ts +++ b/packages/image-io/typescript/src/bio-rad-write-image.ts @@ -71,14 +71,14 @@ async function bioRadWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/bmp-read-image-node.ts b/packages/image-io/typescript/src/bmp-read-image-node.ts index 58b1058a1..308849204 100644 --- a/packages/image-io/typescript/src/bmp-read-image-node.ts +++ b/packages/image-io/typescript/src/bmp-read-image-node.ts @@ -65,13 +65,13 @@ async function bmpReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/bmp-read-image.ts b/packages/image-io/typescript/src/bmp-read-image.ts index 5f12d3acd..e9f30c637 100644 --- a/packages/image-io/typescript/src/bmp-read-image.ts +++ b/packages/image-io/typescript/src/bmp-read-image.ts @@ -71,14 +71,14 @@ async function bmpReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/bmp-write-image-node.ts b/packages/image-io/typescript/src/bmp-write-image-node.ts index 97e3a2ed8..872e93234 100644 --- a/packages/image-io/typescript/src/bmp-write-image-node.ts +++ b/packages/image-io/typescript/src/bmp-write-image-node.ts @@ -69,12 +69,12 @@ async function bmpWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/bmp-write-image.ts b/packages/image-io/typescript/src/bmp-write-image.ts index cad094398..92c25ea23 100644 --- a/packages/image-io/typescript/src/bmp-write-image.ts +++ b/packages/image-io/typescript/src/bmp-write-image.ts @@ -71,14 +71,14 @@ async function bmpWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/fdf-read-image-node.ts b/packages/image-io/typescript/src/fdf-read-image-node.ts index b0e29c264..31bc33d8b 100644 --- a/packages/image-io/typescript/src/fdf-read-image-node.ts +++ b/packages/image-io/typescript/src/fdf-read-image-node.ts @@ -65,13 +65,13 @@ async function fdfReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/fdf-read-image.ts b/packages/image-io/typescript/src/fdf-read-image.ts index b24f05b92..d77ed48fe 100644 --- a/packages/image-io/typescript/src/fdf-read-image.ts +++ b/packages/image-io/typescript/src/fdf-read-image.ts @@ -71,14 +71,14 @@ async function fdfReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/fdf-write-image-node.ts b/packages/image-io/typescript/src/fdf-write-image-node.ts index 2b3e29e2b..7a2ba3c7b 100644 --- a/packages/image-io/typescript/src/fdf-write-image-node.ts +++ b/packages/image-io/typescript/src/fdf-write-image-node.ts @@ -69,12 +69,12 @@ async function fdfWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/fdf-write-image.ts b/packages/image-io/typescript/src/fdf-write-image.ts index 6a8c26761..613c829a1 100644 --- a/packages/image-io/typescript/src/fdf-write-image.ts +++ b/packages/image-io/typescript/src/fdf-write-image.ts @@ -71,14 +71,14 @@ async function fdfWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/gdcm-read-image-node.ts b/packages/image-io/typescript/src/gdcm-read-image-node.ts index 9bae10958..233101e79 100644 --- a/packages/image-io/typescript/src/gdcm-read-image-node.ts +++ b/packages/image-io/typescript/src/gdcm-read-image-node.ts @@ -65,13 +65,13 @@ async function gdcmReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/gdcm-read-image.ts b/packages/image-io/typescript/src/gdcm-read-image.ts index 02f612760..a8c88fc1a 100644 --- a/packages/image-io/typescript/src/gdcm-read-image.ts +++ b/packages/image-io/typescript/src/gdcm-read-image.ts @@ -71,14 +71,14 @@ async function gdcmReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/gdcm-write-image-node.ts b/packages/image-io/typescript/src/gdcm-write-image-node.ts index 66e4ed0aa..5fbd56db1 100644 --- a/packages/image-io/typescript/src/gdcm-write-image-node.ts +++ b/packages/image-io/typescript/src/gdcm-write-image-node.ts @@ -69,12 +69,12 @@ async function gdcmWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/gdcm-write-image.ts b/packages/image-io/typescript/src/gdcm-write-image.ts index d80db8210..1259a77ce 100644 --- a/packages/image-io/typescript/src/gdcm-write-image.ts +++ b/packages/image-io/typescript/src/gdcm-write-image.ts @@ -71,14 +71,14 @@ async function gdcmWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } 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 index ac902d8fd..49cf0d5fa 100644 --- a/packages/image-io/typescript/src/ge-adw-read-image-node.ts +++ b/packages/image-io/typescript/src/ge-adw-read-image-node.ts @@ -65,13 +65,13 @@ async function geAdwReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/ge-adw-read-image.ts b/packages/image-io/typescript/src/ge-adw-read-image.ts index 0db9a1b7d..c892a4397 100644 --- a/packages/image-io/typescript/src/ge-adw-read-image.ts +++ b/packages/image-io/typescript/src/ge-adw-read-image.ts @@ -71,14 +71,14 @@ async function geAdwReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } 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 index b00648fa8..77dc9a250 100644 --- a/packages/image-io/typescript/src/ge-adw-write-image-node.ts +++ b/packages/image-io/typescript/src/ge-adw-write-image-node.ts @@ -69,12 +69,12 @@ async function geAdwWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/ge-adw-write-image.ts b/packages/image-io/typescript/src/ge-adw-write-image.ts index f7fab252e..5012e75e6 100644 --- a/packages/image-io/typescript/src/ge-adw-write-image.ts +++ b/packages/image-io/typescript/src/ge-adw-write-image.ts @@ -71,14 +71,14 @@ async function geAdwWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/ge4-read-image-node.ts b/packages/image-io/typescript/src/ge4-read-image-node.ts index 792c3901a..ac7c5b75b 100644 --- a/packages/image-io/typescript/src/ge4-read-image-node.ts +++ b/packages/image-io/typescript/src/ge4-read-image-node.ts @@ -65,13 +65,13 @@ async function ge4ReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/ge4-read-image.ts b/packages/image-io/typescript/src/ge4-read-image.ts index 47bde3542..7c6b0a985 100644 --- a/packages/image-io/typescript/src/ge4-read-image.ts +++ b/packages/image-io/typescript/src/ge4-read-image.ts @@ -71,14 +71,14 @@ async function ge4ReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/ge4-write-image-node.ts b/packages/image-io/typescript/src/ge4-write-image-node.ts index df6243e7c..01e1cd308 100644 --- a/packages/image-io/typescript/src/ge4-write-image-node.ts +++ b/packages/image-io/typescript/src/ge4-write-image-node.ts @@ -69,12 +69,12 @@ async function ge4WriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/ge4-write-image.ts b/packages/image-io/typescript/src/ge4-write-image.ts index ebff80ed1..a9b49f9f6 100644 --- a/packages/image-io/typescript/src/ge4-write-image.ts +++ b/packages/image-io/typescript/src/ge4-write-image.ts @@ -71,14 +71,14 @@ async function ge4WriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/ge5-read-image-node.ts b/packages/image-io/typescript/src/ge5-read-image-node.ts index e8697ebf8..515fa3d82 100644 --- a/packages/image-io/typescript/src/ge5-read-image-node.ts +++ b/packages/image-io/typescript/src/ge5-read-image-node.ts @@ -65,13 +65,13 @@ async function ge5ReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/ge5-read-image.ts b/packages/image-io/typescript/src/ge5-read-image.ts index d4c9cb04e..b1c0b295a 100644 --- a/packages/image-io/typescript/src/ge5-read-image.ts +++ b/packages/image-io/typescript/src/ge5-read-image.ts @@ -71,14 +71,14 @@ async function ge5ReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/ge5-write-image-node.ts b/packages/image-io/typescript/src/ge5-write-image-node.ts index 0427c740d..e4fb8d3f9 100644 --- a/packages/image-io/typescript/src/ge5-write-image-node.ts +++ b/packages/image-io/typescript/src/ge5-write-image-node.ts @@ -69,12 +69,12 @@ async function ge5WriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/ge5-write-image.ts b/packages/image-io/typescript/src/ge5-write-image.ts index bd8e52215..0188d9dcb 100644 --- a/packages/image-io/typescript/src/ge5-write-image.ts +++ b/packages/image-io/typescript/src/ge5-write-image.ts @@ -71,14 +71,14 @@ async function ge5WriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/gipl-read-image-node.ts b/packages/image-io/typescript/src/gipl-read-image-node.ts index 38b312794..9b5c9727f 100644 --- a/packages/image-io/typescript/src/gipl-read-image-node.ts +++ b/packages/image-io/typescript/src/gipl-read-image-node.ts @@ -65,13 +65,13 @@ async function giplReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/gipl-read-image.ts b/packages/image-io/typescript/src/gipl-read-image.ts index 5bc245d5b..499f98860 100644 --- a/packages/image-io/typescript/src/gipl-read-image.ts +++ b/packages/image-io/typescript/src/gipl-read-image.ts @@ -71,14 +71,14 @@ async function giplReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/gipl-write-image-node.ts b/packages/image-io/typescript/src/gipl-write-image-node.ts index 202c6b35b..248d54096 100644 --- a/packages/image-io/typescript/src/gipl-write-image-node.ts +++ b/packages/image-io/typescript/src/gipl-write-image-node.ts @@ -69,12 +69,12 @@ async function giplWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/gipl-write-image.ts b/packages/image-io/typescript/src/gipl-write-image.ts index d6ee8f4b8..5c41bbd22 100644 --- a/packages/image-io/typescript/src/gipl-write-image.ts +++ b/packages/image-io/typescript/src/gipl-write-image.ts @@ -71,14 +71,14 @@ async function giplWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/hdf5-read-image-node.ts b/packages/image-io/typescript/src/hdf5-read-image-node.ts index 8428ea621..6c781b8e4 100644 --- a/packages/image-io/typescript/src/hdf5-read-image-node.ts +++ b/packages/image-io/typescript/src/hdf5-read-image-node.ts @@ -65,13 +65,13 @@ async function hdf5ReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/hdf5-read-image.ts b/packages/image-io/typescript/src/hdf5-read-image.ts index c9b59d051..2f563d69d 100644 --- a/packages/image-io/typescript/src/hdf5-read-image.ts +++ b/packages/image-io/typescript/src/hdf5-read-image.ts @@ -71,14 +71,14 @@ async function hdf5ReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/hdf5-write-image-node.ts b/packages/image-io/typescript/src/hdf5-write-image-node.ts index 281ecfbd4..5228d231a 100644 --- a/packages/image-io/typescript/src/hdf5-write-image-node.ts +++ b/packages/image-io/typescript/src/hdf5-write-image-node.ts @@ -69,12 +69,12 @@ async function hdf5WriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/hdf5-write-image.ts b/packages/image-io/typescript/src/hdf5-write-image.ts index ee22d384a..8ef0fa145 100644 --- a/packages/image-io/typescript/src/hdf5-write-image.ts +++ b/packages/image-io/typescript/src/hdf5-write-image.ts @@ -71,14 +71,14 @@ async function hdf5WriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/index.ts b/packages/image-io/typescript/src/index.ts index 4bc4e1ed1..cae480510 100644 --- a/packages/image-io/typescript/src/index.ts +++ b/packages/image-io/typescript/src/index.ts @@ -1,8 +1,15 @@ -// Generated file. To retain edits, remove this comment. export * from './pipelines-base-url.js' export * from './pipeline-worker-url.js' +import ReadImageOptions from './read-image-options.js' +export type { ReadImageOptions } + +import ReadImageResult from './read-image-result.js' +export type { ReadImageResult } + +import readImage from './read-image.js' +export { readImage } import BioRadReadImageResult from './bio-rad-read-image-result.js' export type { BioRadReadImageResult } diff --git a/packages/image-io/typescript/src/jpeg-read-image-node.ts b/packages/image-io/typescript/src/jpeg-read-image-node.ts index c7151468c..ec5d44d49 100644 --- a/packages/image-io/typescript/src/jpeg-read-image-node.ts +++ b/packages/image-io/typescript/src/jpeg-read-image-node.ts @@ -65,13 +65,13 @@ async function jpegReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/jpeg-read-image.ts b/packages/image-io/typescript/src/jpeg-read-image.ts index 278d8dfc2..ed917708d 100644 --- a/packages/image-io/typescript/src/jpeg-read-image.ts +++ b/packages/image-io/typescript/src/jpeg-read-image.ts @@ -71,14 +71,14 @@ async function jpegReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/jpeg-write-image-node.ts b/packages/image-io/typescript/src/jpeg-write-image-node.ts index 03d7caca7..546f45a99 100644 --- a/packages/image-io/typescript/src/jpeg-write-image-node.ts +++ b/packages/image-io/typescript/src/jpeg-write-image-node.ts @@ -69,12 +69,12 @@ async function jpegWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/jpeg-write-image.ts b/packages/image-io/typescript/src/jpeg-write-image.ts index aac5972e1..de607d954 100644 --- a/packages/image-io/typescript/src/jpeg-write-image.ts +++ b/packages/image-io/typescript/src/jpeg-write-image.ts @@ -71,14 +71,14 @@ async function jpegWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/lsm-read-image-node.ts b/packages/image-io/typescript/src/lsm-read-image-node.ts index 67fbb20b5..13c1d5932 100644 --- a/packages/image-io/typescript/src/lsm-read-image-node.ts +++ b/packages/image-io/typescript/src/lsm-read-image-node.ts @@ -65,13 +65,13 @@ async function lsmReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/lsm-read-image.ts b/packages/image-io/typescript/src/lsm-read-image.ts index 40aff0f25..9493aa57e 100644 --- a/packages/image-io/typescript/src/lsm-read-image.ts +++ b/packages/image-io/typescript/src/lsm-read-image.ts @@ -71,14 +71,14 @@ async function lsmReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/lsm-write-image-node.ts b/packages/image-io/typescript/src/lsm-write-image-node.ts index 42c0e672d..4f7a7e276 100644 --- a/packages/image-io/typescript/src/lsm-write-image-node.ts +++ b/packages/image-io/typescript/src/lsm-write-image-node.ts @@ -69,12 +69,12 @@ async function lsmWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/lsm-write-image.ts b/packages/image-io/typescript/src/lsm-write-image.ts index 9af55ce25..b80040875 100644 --- a/packages/image-io/typescript/src/lsm-write-image.ts +++ b/packages/image-io/typescript/src/lsm-write-image.ts @@ -71,14 +71,14 @@ async function lsmWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/meta-read-image-node.ts b/packages/image-io/typescript/src/meta-read-image-node.ts index 4af379a34..e3b544832 100644 --- a/packages/image-io/typescript/src/meta-read-image-node.ts +++ b/packages/image-io/typescript/src/meta-read-image-node.ts @@ -65,13 +65,13 @@ async function metaReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/meta-read-image.ts b/packages/image-io/typescript/src/meta-read-image.ts index d7f675839..997f3560b 100644 --- a/packages/image-io/typescript/src/meta-read-image.ts +++ b/packages/image-io/typescript/src/meta-read-image.ts @@ -71,14 +71,14 @@ async function metaReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/meta-write-image-node.ts b/packages/image-io/typescript/src/meta-write-image-node.ts index 2f5bafe1d..7e265ee11 100644 --- a/packages/image-io/typescript/src/meta-write-image-node.ts +++ b/packages/image-io/typescript/src/meta-write-image-node.ts @@ -69,12 +69,12 @@ async function metaWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/meta-write-image.ts b/packages/image-io/typescript/src/meta-write-image.ts index f94ee14e8..2896bc969 100644 --- a/packages/image-io/typescript/src/meta-write-image.ts +++ b/packages/image-io/typescript/src/meta-write-image.ts @@ -71,14 +71,14 @@ async function metaWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/mgh-read-image-node.ts b/packages/image-io/typescript/src/mgh-read-image-node.ts index dc3e25742..e54b31eef 100644 --- a/packages/image-io/typescript/src/mgh-read-image-node.ts +++ b/packages/image-io/typescript/src/mgh-read-image-node.ts @@ -65,13 +65,13 @@ async function mghReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/mgh-read-image.ts b/packages/image-io/typescript/src/mgh-read-image.ts index 658819b3c..3424fd816 100644 --- a/packages/image-io/typescript/src/mgh-read-image.ts +++ b/packages/image-io/typescript/src/mgh-read-image.ts @@ -71,14 +71,14 @@ async function mghReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/mgh-write-image-node.ts b/packages/image-io/typescript/src/mgh-write-image-node.ts index 3c9c4b64d..a3c9f916c 100644 --- a/packages/image-io/typescript/src/mgh-write-image-node.ts +++ b/packages/image-io/typescript/src/mgh-write-image-node.ts @@ -69,12 +69,12 @@ async function mghWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/mgh-write-image.ts b/packages/image-io/typescript/src/mgh-write-image.ts index d2767d011..ded3e724c 100644 --- a/packages/image-io/typescript/src/mgh-write-image.ts +++ b/packages/image-io/typescript/src/mgh-write-image.ts @@ -71,14 +71,14 @@ async function mghWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/minc-read-image-node.ts b/packages/image-io/typescript/src/minc-read-image-node.ts index 238f78448..cfbf0e4f5 100644 --- a/packages/image-io/typescript/src/minc-read-image-node.ts +++ b/packages/image-io/typescript/src/minc-read-image-node.ts @@ -65,13 +65,13 @@ async function mincReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/minc-read-image.ts b/packages/image-io/typescript/src/minc-read-image.ts index 71c735909..b13d3997f 100644 --- a/packages/image-io/typescript/src/minc-read-image.ts +++ b/packages/image-io/typescript/src/minc-read-image.ts @@ -71,14 +71,14 @@ async function mincReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/minc-write-image-node.ts b/packages/image-io/typescript/src/minc-write-image-node.ts index 564dceba8..716725ddd 100644 --- a/packages/image-io/typescript/src/minc-write-image-node.ts +++ b/packages/image-io/typescript/src/minc-write-image-node.ts @@ -69,12 +69,12 @@ async function mincWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/minc-write-image.ts b/packages/image-io/typescript/src/minc-write-image.ts index df58d9ec3..b4cc378f5 100644 --- a/packages/image-io/typescript/src/minc-write-image.ts +++ b/packages/image-io/typescript/src/minc-write-image.ts @@ -71,14 +71,14 @@ async function mincWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/mrc-read-image-node.ts b/packages/image-io/typescript/src/mrc-read-image-node.ts index 55cefcae7..f58d7494e 100644 --- a/packages/image-io/typescript/src/mrc-read-image-node.ts +++ b/packages/image-io/typescript/src/mrc-read-image-node.ts @@ -65,13 +65,13 @@ async function mrcReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/mrc-read-image.ts b/packages/image-io/typescript/src/mrc-read-image.ts index feea33246..172abccdc 100644 --- a/packages/image-io/typescript/src/mrc-read-image.ts +++ b/packages/image-io/typescript/src/mrc-read-image.ts @@ -71,14 +71,14 @@ async function mrcReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/mrc-write-image-node.ts b/packages/image-io/typescript/src/mrc-write-image-node.ts index e39ddf454..f90fb6462 100644 --- a/packages/image-io/typescript/src/mrc-write-image-node.ts +++ b/packages/image-io/typescript/src/mrc-write-image-node.ts @@ -69,12 +69,12 @@ async function mrcWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/mrc-write-image.ts b/packages/image-io/typescript/src/mrc-write-image.ts index 0f9693383..da2cdba21 100644 --- a/packages/image-io/typescript/src/mrc-write-image.ts +++ b/packages/image-io/typescript/src/mrc-write-image.ts @@ -71,14 +71,14 @@ async function mrcWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/nifti-read-image-node.ts b/packages/image-io/typescript/src/nifti-read-image-node.ts index ca17a0b99..9beb6225f 100644 --- a/packages/image-io/typescript/src/nifti-read-image-node.ts +++ b/packages/image-io/typescript/src/nifti-read-image-node.ts @@ -65,13 +65,13 @@ async function niftiReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/nifti-read-image.ts b/packages/image-io/typescript/src/nifti-read-image.ts index 6df831400..28f68743c 100644 --- a/packages/image-io/typescript/src/nifti-read-image.ts +++ b/packages/image-io/typescript/src/nifti-read-image.ts @@ -71,14 +71,14 @@ async function niftiReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/nifti-write-image-node.ts b/packages/image-io/typescript/src/nifti-write-image-node.ts index bc0a5a7a4..793fc64b7 100644 --- a/packages/image-io/typescript/src/nifti-write-image-node.ts +++ b/packages/image-io/typescript/src/nifti-write-image-node.ts @@ -69,12 +69,12 @@ async function niftiWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/nifti-write-image.ts b/packages/image-io/typescript/src/nifti-write-image.ts index 7a7e6e262..242c3879c 100644 --- a/packages/image-io/typescript/src/nifti-write-image.ts +++ b/packages/image-io/typescript/src/nifti-write-image.ts @@ -71,14 +71,14 @@ async function niftiWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/nrrd-read-image-node.ts b/packages/image-io/typescript/src/nrrd-read-image-node.ts index f22c3f36e..8fbbc174e 100644 --- a/packages/image-io/typescript/src/nrrd-read-image-node.ts +++ b/packages/image-io/typescript/src/nrrd-read-image-node.ts @@ -65,13 +65,13 @@ async function nrrdReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/nrrd-read-image.ts b/packages/image-io/typescript/src/nrrd-read-image.ts index 177ff7b3f..e8e0fc265 100644 --- a/packages/image-io/typescript/src/nrrd-read-image.ts +++ b/packages/image-io/typescript/src/nrrd-read-image.ts @@ -71,14 +71,14 @@ async function nrrdReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/nrrd-write-image-node.ts b/packages/image-io/typescript/src/nrrd-write-image-node.ts index dfdb38379..2c4758285 100644 --- a/packages/image-io/typescript/src/nrrd-write-image-node.ts +++ b/packages/image-io/typescript/src/nrrd-write-image-node.ts @@ -69,12 +69,12 @@ async function nrrdWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/nrrd-write-image.ts b/packages/image-io/typescript/src/nrrd-write-image.ts index 7e40d90b3..5416d2e59 100644 --- a/packages/image-io/typescript/src/nrrd-write-image.ts +++ b/packages/image-io/typescript/src/nrrd-write-image.ts @@ -71,14 +71,14 @@ async function nrrdWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/png-read-image-node.ts b/packages/image-io/typescript/src/png-read-image-node.ts index 0af7b2b8f..e622252dd 100644 --- a/packages/image-io/typescript/src/png-read-image-node.ts +++ b/packages/image-io/typescript/src/png-read-image-node.ts @@ -65,13 +65,13 @@ async function pngReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/png-read-image.ts b/packages/image-io/typescript/src/png-read-image.ts index c36041950..2ecd998e8 100644 --- a/packages/image-io/typescript/src/png-read-image.ts +++ b/packages/image-io/typescript/src/png-read-image.ts @@ -71,14 +71,14 @@ async function pngReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/png-write-image-node.ts b/packages/image-io/typescript/src/png-write-image-node.ts index 80c927f43..9dcc1e00a 100644 --- a/packages/image-io/typescript/src/png-write-image-node.ts +++ b/packages/image-io/typescript/src/png-write-image-node.ts @@ -69,12 +69,12 @@ async function pngWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/png-write-image.ts b/packages/image-io/typescript/src/png-write-image.ts index f7d94d681..54654fe06 100644 --- a/packages/image-io/typescript/src/png-write-image.ts +++ b/packages/image-io/typescript/src/png-write-image.ts @@ -71,14 +71,14 @@ async function pngWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/read-image-file-series.ts b/packages/image-io/typescript/src/read-image-file-series.ts new file mode 100644 index 000000000..e24726f14 --- /dev/null +++ b/packages/image-io/typescript/src/read-image-file-series.ts @@ -0,0 +1,91 @@ +// import { stackImages, WorkerPool, castImage } from 'itk-wasm' + +// import { readImage } from './read-image.js' + +// import ReadImageFileSeriesResult from './ReadImageFileSeriesResult.js' +// import ReadImageFileSeriesOptions from './ReadImageFileSeriesOptions.js' + +// const numberOfWorkers = typeof globalThis.navigator?.hardwareConcurrency === 'number' ? globalThis.navigator.hardwareConcurrency : 6 +// const workerPool = new WorkerPool(numberOfWorkers, readImageArrayBuffer) + +// async function readImageFileSeries ( +// fileList: File[] | FileList, +// options?: ReadImageFileSeriesOptions | number, +// zOriginBackwardsCompatibility?: number, +// sortedSeriesBackwardsCompatibility?: boolean +// ): Promise { +// let zSpacing = 1.0 +// let zOrigin = 0.0 +// let sortedSeries = false +// if (typeof options === 'number') { +// // Backwards compatibility +// zSpacing = options +// } +// if (typeof zOriginBackwardsCompatibility !== 'undefined') { +// zOrigin = zOriginBackwardsCompatibility +// } +// if (typeof sortedSeriesBackwardsCompatibility !== 'undefined') { +// sortedSeries = sortedSeriesBackwardsCompatibility +// } +// if (typeof options === 'object') { +// if (typeof options.zSpacing !== 'undefined') { +// zSpacing = options.zSpacing +// } +// if (typeof options.zOrigin !== 'undefined') { +// zOrigin = options.zOrigin +// } +// if (typeof options.sortedSeries !== 'undefined') { +// sortedSeries = options.sortedSeries +// } +// } +// const fetchFileDescriptions = Array.from(fileList, async function (file) { +// return await file.arrayBuffer().then(function ( +// arrayBuffer +// ) { +// const fileDescription = { +// name: file.name, +// type: file.type, +// data: arrayBuffer +// } +// return fileDescription +// }) +// }) + +// const fileDescriptions = await Promise.all(fetchFileDescriptions) +// if (!sortedSeries) { +// fileDescriptions.sort((a, b) => { +// if (a.name < b.name) { +// return -1 +// } +// if (a.name > b.name) { +// return 1 +// } +// return 0 +// }) +// } +// const taskArgsArray = [] +// for (let index = 0; index < fileDescriptions.length; index++) { +// taskArgsArray.push([fileDescriptions[index].data, fileDescriptions[index].name]) +// } +// const results = await workerPool.runTasks(taskArgsArray).promise +// const images = results.map((result) => { +// const image = result.image +// image.imageType.dimension = 3 +// image.size.push(1) +// image.spacing.push(zSpacing) +// image.origin.push(zOrigin) +// image.direction = new Float64Array(9) +// image.direction.fill(0.0) +// image.direction[0] = 1.0 +// image.direction[4] = 1.0 +// image.direction[8] = 1.0 +// return image +// }) +// let stacked = stackImages(images) +// if (typeof options === 'object' && (typeof options.componentType !== 'undefined' || typeof options.pixelType !== 'undefined')) { +// stacked = castImage(stacked, options) +// } +// return { image: stacked, webWorkerPool: workerPool } +// } + +// export default readImageFileSeries diff --git a/packages/image-io/typescript/src/read-image-node.ts b/packages/image-io/typescript/src/read-image-node.ts index 307bdac55..b63d021d4 100644 --- a/packages/image-io/typescript/src/read-image-node.ts +++ b/packages/image-io/typescript/src/read-image-node.ts @@ -17,14 +17,18 @@ interface ReaderResult { couldRead: boolean, image: Image } -type Reader = (serializedImage: string) => Promise +interface ReaderOptions { + /** Only read image metadata -- do not read pixel data. */ + informationOnly?: boolean +} +type Reader = (serializedImage: string, options: ReaderOptions) => Promise /** * Read an image file format and convert it to the itk-wasm file format * * @param {string} serializedImage - Path to input image serialized in the file format - * @param {ReadImageOptions} options - options to cast resulting image type + * @param {ReadImageOptions} options - options to cast resulting image type or to only read image metadata * * @returns {Promise} - Image result */ @@ -38,14 +42,14 @@ async function readImageNode( const extension = getFileExtension(absoluteFilePath) let io = null - if (mimeType !== false && mimeToImageIo.has(mimeType)) { + if (mimeType && mimeToImageIo.has(mimeType)) { io = mimeToImageIo.get(mimeType) } else if (extensionToImageIo.has(extension)) { io = extensionToImageIo.get(extension) } else { for (const readerWriter of imageIoIndexNode.values()) { if (readerWriter[0] !== null) { - let { couldRead, image } = await (readerWriter[0] as Reader)(absoluteFilePath) + let { couldRead, image } = await (readerWriter[0] as Reader)(absoluteFilePath, { informationOnly: options.informationOnly }) if (couldRead) { if (typeof options !== 'undefined') { image = castImage(image, options) @@ -61,7 +65,7 @@ async function readImageNode( const readerWriter = imageIoIndexNode.get(io as string) const reader = (readerWriter as Array)[0] - let { couldRead, image } = await reader(absoluteFilePath) + let { couldRead, image } = await reader(absoluteFilePath, { informationOnly: options.informationOnly }) if (!couldRead) { throw Error('Could not read: ' + absoluteFilePath) } diff --git a/packages/image-io/typescript/src/read-image-options.ts b/packages/image-io/typescript/src/read-image-options.ts index 6bd079aaa..05cbe57cf 100644 --- a/packages/image-io/typescript/src/read-image-options.ts +++ b/packages/image-io/typescript/src/read-image-options.ts @@ -6,6 +6,9 @@ interface ReadImageOptions { /** Pixel type, from itk-wasm PixelTypes, for the output pixels. Defaults to the input pixel type. */ pixelType?: typeof PixelTypes[keyof typeof PixelTypes] + + /** Only read image metadata -- do not read pixel data. */ + informationOnly?: boolean } export default ReadImageOptions diff --git a/packages/image-io/typescript/src/read-image-result.ts b/packages/image-io/typescript/src/read-image-result.ts index 0a18e4b70..e2f74fcf4 100644 --- a/packages/image-io/typescript/src/read-image-result.ts +++ b/packages/image-io/typescript/src/read-image-result.ts @@ -1,17 +1,8 @@ -// Generated file. To retain edits, remove this comment. +import { Image } from 'itk-wasm' -import { JsonCompatible, 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: JsonCompatible - - /** Output image */ +interface ReadImageResult { image: Image - + webWorker: Worker } -export default MetaReadImageResult +export default ReadImageResult diff --git a/packages/image-io/typescript/src/read-image.ts b/packages/image-io/typescript/src/read-image.ts new file mode 100644 index 000000000..ce30effe6 --- /dev/null +++ b/packages/image-io/typescript/src/read-image.ts @@ -0,0 +1,90 @@ +import { + BinaryFile, + Image, + castImage, + getFileExtension, +} from 'itk-wasm' + +import mimeToImageIo from './mime-to-image-io.js' +import extensionToImageIo from './extension-to-image-io.js' +import imageIoIndex from './image-io-index.js' + +import ReadImageOptions from './read-image-options.js' +import ReadImageResult from './read-image-result.js' + +interface ReaderResult { + webWorker: Worker, + couldRead: boolean, + image: Image +} +interface ReaderOptions { + /** Only read image metadata -- do not read pixel data. */ + informationOnly?: boolean +} +type Reader = (webWorker: null | Worker, serializedImage: File | BinaryFile, options: ReaderOptions) => Promise + +/** + * Read an image file format and convert it to the itk-wasm file format + * + * @param {webWorker} null | webWorker - Web worker to run the pipeline or null to run it in a new worker + * @param {File | BinaryFile} serializedImage - Input image serialized in the file format + * @param {ReadImageOptions} options - options to cast the resulting image type or to only read image metadata + * + * @returns {Promise} - result object with the image and the web worker used + */ +async function readImage( + webWorker: null | Worker, + serializedImage: File | BinaryFile, + options: ReadImageOptions = {} +) : Promise { + + const mimeType = (serializedImage as File).type ?? '' + const fileName = (serializedImage as File).name ?? (serializedImage as BinaryFile).path + const extension = getFileExtension(fileName) + let usedWebWorker = webWorker + + let serializedImageFile = serializedImage as BinaryFile + if (serializedImage instanceof File) { + const serializedImageBuffer = await serializedImage.arrayBuffer() + serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } + } + + let io = null + if (mimeType && mimeToImageIo.has(mimeType)) { + io = mimeToImageIo.get(mimeType) + } else if (!extensionToImageIo.has(extension)) { + io = extensionToImageIo.get(extension) + } else { + for (const readerWriter of imageIoIndex.values()) { + if (readerWriter[0] !== null) { + let { webWorker: testWebWorker, couldRead, image } = await (readerWriter[0] as unknown as Reader)(usedWebWorker, { path: serializedImageFile.path, data: serializedImageFile.data.slice() }, { informationOnly: options.informationOnly }) + usedWebWorker = testWebWorker + if (couldRead) { + if (typeof options !== 'undefined') { + image = castImage(image, options) + } + return { webWorker: usedWebWorker, image } + } + } + } + } + if (io === null ) { + throw Error('Could not find IO for: ' + fileName) + } + const readerWriter = imageIoIndex.get(io as string) + + const reader = (readerWriter as Array)[0] + let { webWorker: testWebWorker, couldRead, image } = await reader(usedWebWorker, serializedImageFile, { informationOnly: options.informationOnly }) + usedWebWorker = testWebWorker + if (!couldRead) { + throw Error('Could not read: ' + fileName) + } + + if (typeof options !== 'undefined') { + image = castImage(image, options) + } + + return { webWorker: usedWebWorker, image } +} + +export default readImage diff --git a/packages/image-io/typescript/src/scanco-read-image-node.ts b/packages/image-io/typescript/src/scanco-read-image-node.ts index fa8f46504..4474feab8 100644 --- a/packages/image-io/typescript/src/scanco-read-image-node.ts +++ b/packages/image-io/typescript/src/scanco-read-image-node.ts @@ -65,13 +65,13 @@ async function scancoReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/scanco-read-image.ts b/packages/image-io/typescript/src/scanco-read-image.ts index cfec7d768..ba6255dda 100644 --- a/packages/image-io/typescript/src/scanco-read-image.ts +++ b/packages/image-io/typescript/src/scanco-read-image.ts @@ -71,14 +71,14 @@ async function scancoReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/scanco-write-image-node.ts b/packages/image-io/typescript/src/scanco-write-image-node.ts index 45b3f7604..b26e9e03d 100644 --- a/packages/image-io/typescript/src/scanco-write-image-node.ts +++ b/packages/image-io/typescript/src/scanco-write-image-node.ts @@ -69,12 +69,12 @@ async function scancoWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/scanco-write-image.ts b/packages/image-io/typescript/src/scanco-write-image.ts index bb11b89dd..2830881ca 100644 --- a/packages/image-io/typescript/src/scanco-write-image.ts +++ b/packages/image-io/typescript/src/scanco-write-image.ts @@ -71,14 +71,14 @@ async function scancoWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/tiff-read-image-node.ts b/packages/image-io/typescript/src/tiff-read-image-node.ts index 44265070c..201e6d178 100644 --- a/packages/image-io/typescript/src/tiff-read-image-node.ts +++ b/packages/image-io/typescript/src/tiff-read-image-node.ts @@ -65,13 +65,13 @@ async function tiffReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/tiff-read-image.ts b/packages/image-io/typescript/src/tiff-read-image.ts index edca84e53..f06ea20aa 100644 --- a/packages/image-io/typescript/src/tiff-read-image.ts +++ b/packages/image-io/typescript/src/tiff-read-image.ts @@ -71,14 +71,14 @@ async function tiffReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/tiff-write-image-node.ts b/packages/image-io/typescript/src/tiff-write-image-node.ts index 8052dd793..0ebdc8071 100644 --- a/packages/image-io/typescript/src/tiff-write-image-node.ts +++ b/packages/image-io/typescript/src/tiff-write-image-node.ts @@ -69,12 +69,12 @@ async function tiffWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/tiff-write-image.ts b/packages/image-io/typescript/src/tiff-write-image.ts index 0be270dcf..5cf8922f7 100644 --- a/packages/image-io/typescript/src/tiff-write-image.ts +++ b/packages/image-io/typescript/src/tiff-write-image.ts @@ -71,14 +71,14 @@ async function tiffWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/vtk-read-image-node.ts b/packages/image-io/typescript/src/vtk-read-image-node.ts index fa1c1cf1d..73bb349b4 100644 --- a/packages/image-io/typescript/src/vtk-read-image-node.ts +++ b/packages/image-io/typescript/src/vtk-read-image-node.ts @@ -65,13 +65,13 @@ async function vtkReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/vtk-read-image.ts b/packages/image-io/typescript/src/vtk-read-image.ts index dff00aa08..795570241 100644 --- a/packages/image-io/typescript/src/vtk-read-image.ts +++ b/packages/image-io/typescript/src/vtk-read-image.ts @@ -71,14 +71,14 @@ async function vtkReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/vtk-write-image-node.ts b/packages/image-io/typescript/src/vtk-write-image-node.ts index 633753104..c89d142ad 100644 --- a/packages/image-io/typescript/src/vtk-write-image-node.ts +++ b/packages/image-io/typescript/src/vtk-write-image-node.ts @@ -69,12 +69,12 @@ async function vtkWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/vtk-write-image.ts b/packages/image-io/typescript/src/vtk-write-image.ts index f29a24e38..4a179c471 100644 --- a/packages/image-io/typescript/src/vtk-write-image.ts +++ b/packages/image-io/typescript/src/vtk-write-image.ts @@ -71,14 +71,14 @@ async function vtkWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/src/wasm-read-image-node.ts b/packages/image-io/typescript/src/wasm-read-image-node.ts index 09cc7cc42..a16cf49e2 100644 --- a/packages/image-io/typescript/src/wasm-read-image-node.ts +++ b/packages/image-io/typescript/src/wasm-read-image-node.ts @@ -65,13 +65,13 @@ async function wasmReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/wasm-read-image.ts b/packages/image-io/typescript/src/wasm-read-image.ts index 8f3e201bb..0e57b01be 100644 --- a/packages/image-io/typescript/src/wasm-read-image.ts +++ b/packages/image-io/typescript/src/wasm-read-image.ts @@ -71,14 +71,14 @@ async function wasmReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/wasm-write-image-node.ts b/packages/image-io/typescript/src/wasm-write-image-node.ts index 38719bdc8..2c6b0e039 100644 --- a/packages/image-io/typescript/src/wasm-write-image-node.ts +++ b/packages/image-io/typescript/src/wasm-write-image-node.ts @@ -69,12 +69,12 @@ async function wasmWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/wasm-write-image.ts b/packages/image-io/typescript/src/wasm-write-image.ts index 381554fe9..7d7674cee 100644 --- a/packages/image-io/typescript/src/wasm-write-image.ts +++ b/packages/image-io/typescript/src/wasm-write-image.ts @@ -71,14 +71,14 @@ async function wasmWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } 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 index 3f2e2ab94..7097b513e 100644 --- a/packages/image-io/typescript/src/wasm-zstd-read-image-node.ts +++ b/packages/image-io/typescript/src/wasm-zstd-read-image-node.ts @@ -65,13 +65,13 @@ async function wasmZstdReadImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } diff --git a/packages/image-io/typescript/src/wasm-zstd-read-image.ts b/packages/image-io/typescript/src/wasm-zstd-read-image.ts index 46480a0b7..c15d4b20f 100644 --- a/packages/image-io/typescript/src/wasm-zstd-read-image.ts +++ b/packages/image-io/typescript/src/wasm-zstd-read-image.ts @@ -71,14 +71,14 @@ async function wasmZstdReadImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldRead: outputs[0].data as JsonCompatible, - image: outputs[1].data as Image, + couldRead: outputs[0]?.data as JsonCompatible, + image: outputs[1]?.data as Image, } return result } 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 index 9cec6bee4..a36184c36 100644 --- a/packages/image-io/typescript/src/wasm-zstd-write-image-node.ts +++ b/packages/image-io/typescript/src/wasm-zstd-write-image-node.ts @@ -69,12 +69,12 @@ async function wasmZstdWriteImageNode( stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { - couldWrite: outputs[0].data as JsonCompatible, + couldWrite: outputs[0]?.data as JsonCompatible, } return result } diff --git a/packages/image-io/typescript/src/wasm-zstd-write-image.ts b/packages/image-io/typescript/src/wasm-zstd-write-image.ts index 16ec2130f..b1489b6f0 100644 --- a/packages/image-io/typescript/src/wasm-zstd-write-image.ts +++ b/packages/image-io/typescript/src/wasm-zstd-write-image.ts @@ -71,14 +71,14 @@ async function wasmZstdWriteImage( stderr, outputs } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) - if (returnValue !== 0) { + if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, - couldWrite: outputs[0].data as JsonCompatible, - serializedImage: outputs[1].data as BinaryFile, + couldWrite: outputs[0]?.data as JsonCompatible, + serializedImage: outputs[1]?.data as BinaryFile, } return result } diff --git a/packages/image-io/typescript/test/browser/demo-app/index.html b/packages/image-io/typescript/test/browser/demo-app/index.html index 630d4ecb4..1750d461e 100644 --- a/packages/image-io/typescript/test/browser/demo-app/index.html +++ b/packages/image-io/typescript/test/browser/demo-app/index.html @@ -1,5 +1,3 @@ - - @@ -58,6 +56,10 @@

👨‍💻 Live API Demo ✨



+ + readImage + + bioRadReadImage bioRadWriteImage bmpReadImage @@ -106,6 +108,57 @@

👨‍💻 Live API Demo ✨

wasmZstdWriteImage + + + + Read an image file.

+ +
+ + +

+ informationOnly - Only read image metadata -- do not read pixel data. +

+ +
Load sample inputs + Run

+ +
+ + +
+ + + bmp + dcm + gipl + hdf5 + jpg + lsm + mnc + mnc.gz + mgh + mha + mrc + nii + nii.gz + png + nrrd + png + pic + tif + isq + fdf + vtk + + Download +

+
+ +
+ + + Read an image file format and convert it to the itk-wasm file format

diff --git a/packages/image-io/typescript/test/browser/demo-app/index.ts b/packages/image-io/typescript/test/browser/demo-app/index.ts index 7fb013194..fe44d1a7c 100644 --- a/packages/image-io/typescript/test/browser/demo-app/index.ts +++ b/packages/image-io/typescript/test/browser/demo-app/index.ts @@ -1,5 +1,3 @@ -// Generated file. To retain edits, remove this comment. - import * as imageIo from '../../../dist/bundles/image-io.js' // Use local, vendored WebAssembly module assets @@ -11,11 +9,15 @@ imageIo.setPipelineWorkerUrl(pipelineWorkerUrl) const params = new URLSearchParams(window.location.search) if (!params.has('functionName')) { - params.set('functionName', 'bioRadReadImage') +// Begin added content + params.set('functionName', 'readImage') const url = new URL(document.location) url.search = params - window.history.replaceState({ functionName: 'bioRadReadImage' }, '', url) + window.history.replaceState({ functionName: 'readImage' }, '', url) } + +import './read-image-controller.js' +// End added content import './bio-rad-read-image-controller.js' import './bio-rad-write-image-controller.js' import './bmp-read-image-controller.js' diff --git a/packages/image-io/typescript/test/browser/demo-app/read-image-controller.ts b/packages/image-io/typescript/test/browser/demo-app/read-image-controller.ts new file mode 100644 index 000000000..8408f6f30 --- /dev/null +++ b/packages/image-io/typescript/test/browser/demo-app/read-image-controller.ts @@ -0,0 +1,154 @@ +import { writeImageArrayBuffer } from 'itk-wasm' +import { copyImage } from 'itk-wasm' +import * as imageIo from '../../../dist/bundles/image-io.js' +import readImageLoadSampleInputs, { usePreRun } from "./read-image-load-sample-inputs.js" + +class ReadImageModel { + + inputs: Map + options: Map + outputs: Map + + constructor() { + this.inputs = new Map() + this.options = new Map() + this.outputs = new Map() + } + } + + +class ReadImageController { + + constructor(loadSampleInputs) { + this.loadSampleInputs = loadSampleInputs + + this.model = new ReadImageModel() + const model = this.model + + this.webWorker = null + + if (loadSampleInputs) { + const loadSampleInputsButton = document.querySelector("#readImageInputs [name=loadSampleInputs]") + loadSampleInputsButton.setAttribute('style', 'display: block-inline;') + loadSampleInputsButton.addEventListener('click', async (event) => { + loadSampleInputsButton.loading = true + await loadSampleInputs(model) + loadSampleInputsButton.loading = false + }) + } + + // ---------------------------------------------- + // Inputs + const serializedImageElement = document.querySelector('#readImageInputs input[name=serialized-image-file]') + serializedImageElement.addEventListener('change', async (event) => { + const dataTransfer = event.dataTransfer + const files = event.target.files || dataTransfer.files + + const arrayBuffer = await files[0].arrayBuffer() + model.inputs.set("serializedImage", { data: new Uint8Array(arrayBuffer), path: files[0].name }) + const details = document.getElementById("readImage-serialized-image-details") + details.innerHTML = `
${globalThis.escapeHtml(model.inputs.get("serializedImage").data.subarray(0, 50).toString() + ' ...')}
` + details.disabled = false + }) + + // ---------------------------------------------- + // Options + const informationOnlyElement = document.querySelector('#readImageInputs sl-checkbox[name=information-only]') + informationOnlyElement.addEventListener('sl-change', (event) => { + model.options.set("informationOnly", informationOnlyElement.checked) + }) + + // ---------------------------------------------- + // Outputs + const imageOutputDownload = document.querySelector('#readImageOutputs sl-button[name=image-download]') + imageOutputDownload.addEventListener('click', async (event) => { + event.preventDefault() + event.stopPropagation() + if (model.outputs.has("image")) { + const imageDownloadFormat = document.getElementById('image-output-format') + const downloadFormat = imageDownloadFormat.value || 'nrrd' + const fileName = `image.${downloadFormat}` + const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, copyImage(model.outputs.get("image")), fileName) + + webWorker.terminate() + globalThis.downloadFile(arrayBuffer, fileName) + } + }) + + const preRun = async () => { + if (!this.webWorker && loadSampleInputs && usePreRun) { + await loadSampleInputs(model, true) + await this.run() + } + } + + const onSelectTab = async (event) => { + if (event.detail.name === 'readImage-panel') { + const params = new URLSearchParams(window.location.search) + if (!params.has('functionName') || params.get('functionName') !== 'readImage') { + params.set('functionName', 'readImage') + const url = new URL(document.location) + url.search = params + window.history.replaceState({ functionName: 'readImage' }, '', url) + await preRun() + } + } + } + + const tabGroup = document.querySelector('sl-tab-group') + tabGroup.addEventListener('sl-tab-show', onSelectTab) + function onInit() { + const params = new URLSearchParams(window.location.search) + if (params.has('functionName') && params.get('functionName') === 'readImage') { + tabGroup.show('readImage-panel') + preRun() + } + } + onInit() + + const runButton = document.querySelector('#readImageInputs sl-button[name="run"]') + runButton.addEventListener('click', async (event) => { + event.preventDefault() + + if(!model.inputs.has('serializedImage')) { + globalThis.notify("Required input not provided", "serializedImage", "danger", "exclamation-octagon") + return + } + + + try { + runButton.loading = true + + const t0 = performance.now() + const { couldRead, image, } = await this.run() + const t1 = performance.now() + globalThis.notify("readImage successfully completed", `in ${t1 - t0} milliseconds.`, "success", "rocket-fill") + + model.outputs.set("image", image) + imageOutputDownload.variant = "success" + imageOutputDownload.disabled = false + const imageDetails = document.getElementById("readImage-image-details") + imageDetails.innerHTML = `
${globalThis.escapeHtml(JSON.stringify(image, globalThis.interfaceTypeJsonReplacer, 2))}
` + imageDetails.disabled = false + const imageOutput = document.getElementById('readImage-image-details') + } catch (error) { + globalThis.notify("Error while running pipeline", error.toString(), "danger", "exclamation-octagon") + throw error + } finally { + runButton.loading = false + } + }) + } + + async run() { + const { webWorker, image, } = await imageIo.readImage(this.webWorker, + { data: this.model.inputs.get('serializedImage').data.slice(), path: this.model.inputs.get('serializedImage').path }, + Object.fromEntries(this.model.options.entries()) + ) + this.webWorker = webWorker + + return { image, } + } +} + +const readImageController = new ReadImageController(readImageLoadSampleInputs) diff --git a/packages/image-io/typescript/test/browser/demo-app/read-image-load-sample-inputs.ts b/packages/image-io/typescript/test/browser/demo-app/read-image-load-sample-inputs.ts new file mode 100644 index 000000000..e32b848f7 --- /dev/null +++ b/packages/image-io/typescript/test/browser/demo-app/read-image-load-sample-inputs.ts @@ -0,0 +1,20 @@ +export default async function readImageLoadSampleInputs (model, preRun=false) { + const inputButton = document.querySelector('#readImageInputs sl-button[name=serialized-image-file-button]') + if (!preRun) { + inputButton.loading = true + } + const fileName = 'cthead1.png' + const inputResponse = await fetch(`https://bafybeigrnfohpfr2kqooyjsozsva6jh2663riwrxsum5x3ltow42r6j2o4.ipfs.w3s.link/ipfs/bafybeigrnfohpfr2kqooyjsozsva6jh2663riwrxsum5x3ltow42r6j2o4/data/input/${fileName}`) + const inputData = new Uint8Array(await inputResponse.arrayBuffer()) + model.inputs.set('serializedImage', { data: inputData, path: fileName }) + if (!preRun) { + const inputElement = document.getElementById('readImage-serialized-image-details') + inputElement.innerHTML = `
${globalThis.escapeHtml(inputData.subarray(0, 50).toString())}
` + inputElement.disabled = false + inputButton.loading = false + } + + return model +} + +export const usePreRun = true diff --git a/src/bindgen/typescript/function-module.js b/src/bindgen/typescript/function-module.js index 0d5b53eda..40103a1f7 100644 --- a/src/bindgen/typescript/function-module.js +++ b/src/bindgen/typescript/function-module.js @@ -14,7 +14,6 @@ function readFileIfNotInterfaceType(forNode, interfaceType, varName, indent, isA } else { return `${indent}mountDirs.add(path.dirname(${varName} as string))\n` } - } else { if (interfaceType === 'TextFile') { if (isArray) { @@ -456,7 +455,7 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase, functionContent += ` const {\n webWorker: usedWebWorker,\n returnValue,\n stderr,\n${outputsVar} } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() })\n` } - functionContent += ' if (returnValue !== 0) {\n throw new Error(stderr)\n }\n\n' + functionContent += ' if (returnValue !== 0 && stderr !== "") {\n throw new Error(stderr)\n }\n\n' functionContent += ' const result = {\n' if (!forNode) { @@ -471,12 +470,12 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase, if (haveArray) { const isArray = output.itemsExpectedMax > 1 if (isArray) { - functionContent += ` ${camel}: (outputs.slice(${camel}Start, ${camel}End).map(o => (o.data as ${interfaceType}).data)),\n` + functionContent += ` ${camel}: (outputs.slice(${camel}Start, ${camel}End).map(o => (o?.data as ${interfaceType})?.data)),\n` } else { - functionContent += ` ${camel}: (outputs[${camel}Index].data as ${interfaceType}).data),\n` + functionContent += ` ${camel}: (outputs[${camel}Index]?.data as ${interfaceType}).data),\n` } } else { - functionContent += ` ${camel}: (outputs[${outputIndex}].data as ${interfaceType}).data,\n` + functionContent += ` ${camel}: (outputs[${outputIndex}]?.data as ${interfaceType}).data,\n` } } else if (forNode && interfaceType.includes('File')) { // Written to disk @@ -484,12 +483,12 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase, if (haveArray) { const isArray = output.itemsExpectedMax > 1 if (isArray) { - functionContent += ` ${camel}: outputs.slice(${camel}Start, ${camel}End).map(o => (o.data as ${interfaceType})),\n` + functionContent += ` ${camel}: outputs.slice(${camel}Start, ${camel}End).map(o => (o?.data as ${interfaceType})),\n` } else { - functionContent += ` ${camel}: outputs[${camel}Index].data as ${interfaceType},\n` + functionContent += ` ${camel}: outputs[${camel}Index]?.data as ${interfaceType},\n` } } else { - functionContent += ` ${camel}: outputs[${outputIndex}].data as ${interfaceType},\n` + functionContent += ` ${camel}: outputs[${outputIndex}]?.data as ${interfaceType},\n` } } if (!(forNode && interfaceType.includes('File'))) {