-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(image-io): Mark typescript couldRead and couldWrite as booleans
Edit commands: ```sh cd packages/image-io/typescript git sed 's/couldRead: Object/couldRead: boolean/' git sed 's/couldWrite: Object/couldWrite: boolean/' for ff in src/*result*; do tail -n+3 $ff > "${ff}.new"; mv "${ff}.new" $ff ; done git sed 's/JsonObject).data/JsonObject).data as boolean/' ```
- Loading branch information
Showing
184 changed files
with
8,809 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/image-io/typescript/src/bio-rad-read-image-node-result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Image } from 'itk-wasm' | ||
|
||
interface BioRadReadImageNodeResult { | ||
/** Whether the input could be read. If false, the output image is not valid. */ | ||
couldRead: boolean | ||
|
||
/** Output image */ | ||
image: Image | ||
|
||
} | ||
|
||
export default BioRadReadImageNodeResult |
78 changes: 78 additions & 0 deletions
78
packages/image-io/typescript/src/bio-rad-read-image-node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
JsonObject, | ||
Image, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import BioRadReadImageOptions from './bio-rad-read-image-options.js' | ||
import BioRadReadImageNodeResult from './bio-rad-read-image-node-result.js' | ||
|
||
|
||
import path from 'path' | ||
|
||
/** | ||
* Read an image file format and convert it to the itk-wasm file format | ||
* | ||
* @param {string} serializedImage - Input image serialized in the file format | ||
* @param {BioRadReadImageOptions} options - options object | ||
* | ||
* @returns {Promise<BioRadReadImageNodeResult>} - result object | ||
*/ | ||
async function bioRadReadImageNode( | ||
serializedImage: string, | ||
options: BioRadReadImageOptions = {} | ||
) : Promise<BioRadReadImageNodeResult> { | ||
|
||
const mountDirs: Set<string> = new Set() | ||
|
||
const desiredOutputs: Array<PipelineOutput> = [ | ||
{ type: InterfaceTypes.JsonObject }, | ||
{ type: InterfaceTypes.Image }, | ||
] | ||
|
||
mountDirs.add(path.dirname(serializedImage as string)) | ||
const inputs: Array<PipelineInput> = [ | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
const serializedImageName = serializedImage | ||
args.push(serializedImageName as string) | ||
|
||
// Outputs | ||
const couldReadName = '0' | ||
args.push(couldReadName) | ||
|
||
const imageName = '1' | ||
args.push(imageName) | ||
|
||
// Options | ||
args.push('--memory-io') | ||
if (typeof options.informationOnly !== "undefined") { | ||
options.informationOnly && args.push('--information-only') | ||
} | ||
|
||
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'bio-rad-read-image') | ||
|
||
const { | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
couldRead: (outputs[0].data as JsonObject).data, | ||
image: outputs[1].data as Image, | ||
} | ||
return result | ||
} | ||
|
||
export default bioRadReadImageNode |
15 changes: 15 additions & 0 deletions
15
packages/image-io/typescript/src/bio-rad-read-image-result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Image } from 'itk-wasm' | ||
|
||
interface BioRadReadImageResult { | ||
/** WebWorker used for computation */ | ||
webWorker: Worker | null | ||
|
||
/** Whether the input could be read. If false, the output image is not valid. */ | ||
couldRead: boolean | ||
|
||
/** Output image */ | ||
image: Image | ||
|
||
} | ||
|
||
export default BioRadReadImageResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
BinaryFile, | ||
JsonObject, | ||
Image, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipeline | ||
} from 'itk-wasm' | ||
|
||
import BioRadReadImageOptions from './bio-rad-read-image-options.js' | ||
import BioRadReadImageResult from './bio-rad-read-image-result.js' | ||
|
||
|
||
import { getPipelinesBaseUrl } from './pipelines-base-url.js' | ||
import { getPipelineWorkerUrl } from './pipeline-worker-url.js' | ||
|
||
/** | ||
* Read an image file format and convert it to the itk-wasm file format | ||
* | ||
* @param {File | BinaryFile} serializedImage - Input image serialized in the file format | ||
* @param {BioRadReadImageOptions} options - options object | ||
* | ||
* @returns {Promise<BioRadReadImageResult>} - result object | ||
*/ | ||
async function bioRadReadImage( | ||
webWorker: null | Worker, | ||
serializedImage: File | BinaryFile, | ||
options: BioRadReadImageOptions = {} | ||
) : Promise<BioRadReadImageResult> { | ||
|
||
const desiredOutputs: Array<PipelineOutput> = [ | ||
{ type: InterfaceTypes.JsonObject }, | ||
{ type: InterfaceTypes.Image }, | ||
] | ||
|
||
let serializedImageFile = serializedImage | ||
if (serializedImage instanceof File) { | ||
const serializedImageBuffer = await serializedImage.arrayBuffer() | ||
serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) } | ||
} | ||
const inputs: Array<PipelineInput> = [ | ||
{ type: InterfaceTypes.BinaryFile, data: serializedImageFile as BinaryFile }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
const serializedImageName = (serializedImageFile as BinaryFile).path | ||
args.push(serializedImageName as string) | ||
|
||
// Outputs | ||
const couldReadName = '0' | ||
args.push(couldReadName) | ||
|
||
const imageName = '1' | ||
args.push(imageName) | ||
|
||
// Options | ||
args.push('--memory-io') | ||
if (typeof options.informationOnly !== "undefined") { | ||
options.informationOnly && args.push('--information-only') | ||
} | ||
|
||
const pipelinePath = 'bio-rad-read-image' | ||
|
||
const { | ||
webWorker: usedWebWorker, | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
webWorker: usedWebWorker as Worker, | ||
couldRead: (outputs[0].data as JsonObject).data, | ||
image: outputs[1].data as Image, | ||
} | ||
return result | ||
} | ||
|
||
export default bioRadReadImage |
10 changes: 10 additions & 0 deletions
10
packages/image-io/typescript/src/bio-rad-write-image-node-result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
interface BioRadWriteImageNodeResult { | ||
/** Whether the input could be written. If false, the output image is not valid. */ | ||
couldWrite: boolean | ||
|
||
/** Output image serialized in the file format. */ | ||
serializedImage: string | ||
|
||
} | ||
|
||
export default BioRadWriteImageNodeResult |
82 changes: 82 additions & 0 deletions
82
packages/image-io/typescript/src/bio-rad-write-image-node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
Image, | ||
JsonObject, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import BioRadWriteImageOptions from './bio-rad-write-image-options.js' | ||
import BioRadWriteImageNodeResult from './bio-rad-write-image-node-result.js' | ||
|
||
|
||
import path from 'path' | ||
|
||
/** | ||
* Write an itk-wasm file format converted to an image file format | ||
* | ||
* @param {Image} image - Input image | ||
* @param {BioRadWriteImageOptions} options - options object | ||
* | ||
* @returns {Promise<BioRadWriteImageNodeResult>} - result object | ||
*/ | ||
async function bioRadWriteImageNode( | ||
image: Image, | ||
options: BioRadWriteImageOptions = {} | ||
) : Promise<BioRadWriteImageNodeResult> { | ||
|
||
const mountDirs: Set<string> = new Set() | ||
|
||
const desiredOutputs: Array<PipelineOutput> = [ | ||
{ type: InterfaceTypes.JsonObject }, | ||
{ type: InterfaceTypes.BinaryFile }, | ||
] | ||
|
||
const inputs: Array<PipelineInput> = [ | ||
{ type: InterfaceTypes.Image, data: image }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
const imageName = '0' | ||
args.push(imageName as string) | ||
|
||
// Outputs | ||
const couldWriteName = '0' | ||
args.push(couldWriteName) | ||
|
||
const serializedImageName = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath | ||
args.push(serializedImageName) | ||
mountDirs.add(path.dirname(serializedImageName)) | ||
|
||
// Options | ||
args.push('--memory-io') | ||
if (typeof options.informationOnly !== "undefined") { | ||
options.informationOnly && args.push('--information-only') | ||
} | ||
if (typeof options.useCompression !== "undefined") { | ||
options.useCompression && args.push('--use-compression') | ||
} | ||
|
||
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'bio-rad-write-image') | ||
|
||
const { | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
couldWrite: (outputs[0].data as JsonObject).data, | ||
serializedImage: outputs[1].data as string, | ||
} | ||
return result | ||
} | ||
|
||
export default bioRadWriteImageNode |
15 changes: 15 additions & 0 deletions
15
packages/image-io/typescript/src/bio-rad-write-image-result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BinaryFile } from 'itk-wasm' | ||
|
||
interface BioRadWriteImageResult { | ||
/** WebWorker used for computation */ | ||
webWorker: Worker | null | ||
|
||
/** Whether the input could be written. If false, the output image is not valid. */ | ||
couldWrite: boolean | ||
|
||
/** Output image serialized in the file format. */ | ||
serializedImage: BinaryFile | ||
|
||
} | ||
|
||
export default BioRadWriteImageResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
Image, | ||
JsonObject, | ||
BinaryFile, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipeline | ||
} from 'itk-wasm' | ||
|
||
import BioRadWriteImageOptions from './bio-rad-write-image-options.js' | ||
import BioRadWriteImageResult from './bio-rad-write-image-result.js' | ||
|
||
|
||
import { getPipelinesBaseUrl } from './pipelines-base-url.js' | ||
import { getPipelineWorkerUrl } from './pipeline-worker-url.js' | ||
|
||
/** | ||
* Write an itk-wasm file format converted to an image file format | ||
* | ||
* @param {Image} image - Input image | ||
* @param {BioRadWriteImageOptions} options - options object | ||
* | ||
* @returns {Promise<BioRadWriteImageResult>} - result object | ||
*/ | ||
async function bioRadWriteImage( | ||
webWorker: null | Worker, | ||
image: Image, | ||
options: BioRadWriteImageOptions = {} | ||
) : Promise<BioRadWriteImageResult> { | ||
|
||
const serializedImagePath = typeof options.serializedImagePath === 'undefined' ? 'serializedImage' : options.serializedImagePath | ||
const desiredOutputs: Array<PipelineOutput> = [ | ||
{ type: InterfaceTypes.JsonObject }, | ||
{ type: InterfaceTypes.BinaryFile, data: { path: serializedImagePath, data: new Uint8Array() }}, | ||
] | ||
|
||
const inputs: Array<PipelineInput> = [ | ||
{ type: InterfaceTypes.Image, data: image }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
const imageName = '0' | ||
args.push(imageName as string) | ||
|
||
// Outputs | ||
const couldWriteName = '0' | ||
args.push(couldWriteName) | ||
|
||
const serializedImageName = serializedImagePath | ||
args.push(serializedImageName) | ||
|
||
// Options | ||
args.push('--memory-io') | ||
if (typeof options.informationOnly !== "undefined") { | ||
options.informationOnly && args.push('--information-only') | ||
} | ||
if (typeof options.useCompression !== "undefined") { | ||
options.useCompression && args.push('--use-compression') | ||
} | ||
|
||
const pipelinePath = 'bio-rad-write-image' | ||
|
||
const { | ||
webWorker: usedWebWorker, | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
webWorker: usedWebWorker as Worker, | ||
couldWrite: (outputs[0].data as JsonObject).data, | ||
serializedImage: outputs[1].data as BinaryFile, | ||
} | ||
return result | ||
} | ||
|
||
export default bioRadWriteImage |
Oops, something went wrong.