Skip to content

Commit

Permalink
fix(bindgen): copy image for repeated downloads in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Aug 4, 2023
1 parent 2f24d40 commit de7b098
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated file. To retain edits, remove this comment.

import { writeImageArrayBuffer } from 'itk-wasm'
import { writeImageArrayBuffer, copyImage } from 'itk-wasm'
import * as dicom from '../../../dist/bundles/dicom.js'
import applyPresentationStateToImageLoadSampleInputs from "./apply-presentation-state-to-image-load-sample-inputs.js"

Expand Down Expand Up @@ -107,7 +107,7 @@ class ApplyPresentationStateToImageController {
const outputImageDownloadFormat = document.getElementById('output-image-output-format')
const downloadFormat = outputImageDownloadFormat.value || 'nrrd'
const fileName = `outputImage.${downloadFormat}`
const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, model.outputs.get("outputImage"), fileName)
const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, copyImage(model.outputs.get("outputImage")), fileName)

webWorker.terminate()
globalThis.downloadFile(arrayBuffer, fileName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated file. To retain edits, remove this comment.

import { writeImageArrayBuffer } from 'itk-wasm'
import { writeImageArrayBuffer, copyImage } from 'itk-wasm'
import * as dicom from '../../../dist/bundles/dicom.js'
import readImageDicomFileSeriesLoadSampleInputs from "./read-image-dicom-file-series-load-sample-inputs.js"

Expand Down Expand Up @@ -66,7 +66,7 @@ class ReadImageDicomFileSeriesController {
const outputImageDownloadFormat = document.getElementById('output-image-output-format')
const downloadFormat = outputImageDownloadFormat.value || 'nrrd'
const fileName = `outputImage.${downloadFormat}`
const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, model.outputs.get("outputImage"), fileName)
const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, copyImage(model.outputs.get("outputImage")), fileName)

webWorker.terminate()
globalThis.downloadFile(arrayBuffer, fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function interfaceFunctionsDemoTypeScript(packageName, interfaceJson, outputPath
}
const needWriteImage = interfaceJson.outputs.filter((value) => interfaceJsonTypeToInterfaceType.get(value.type) === 'Image').length > 0
if (needWriteImage) {
result += `import { writeImageArrayBuffer } from 'itk-wasm'\n`
result += `import { writeImageArrayBuffer, copyImage } from 'itk-wasm'\n`
}

result += `import * as ${camelCase(bundleName)} from '../../../dist/bundles/${bundleName}.js'\n`
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/typescript/demo/output-demo-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function outputDemoTypeScript(functionName, prefix, indent, parameter) {
result += `${prefix}${indent}${indent}${indent}const ${parameterName}DownloadFormat = document.getElementById('${parameter.name}-output-format')\n`
result += `${prefix}${indent}${indent}${indent}const downloadFormat = ${parameterName}DownloadFormat.value || 'nrrd'\n`
result += `${prefix}${indent}${indent}${indent}const fileName = \`${parameterName}.\${downloadFormat}\`\n`
result += `${prefix}${indent}${indent}${indent}const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, model.outputs.get("${parameterName}"), fileName)\n\n`
result += `${prefix}${indent}${indent}${indent}const { webWorker, arrayBuffer } = await writeImageArrayBuffer(null, copyImage(model.outputs.get("${parameterName}")), fileName)\n\n`
result += `${prefix}${indent}${indent}${indent}webWorker.terminate()\n`
result += `${prefix}${indent}${indent}${indent}globalThis.downloadFile(arrayBuffer, fileName)\n`
result += `${prefix}${indent}${indent}}\n`
Expand Down

0 comments on commit de7b098

Please sign in to comment.