Skip to content

Commit

Permalink
feat(itkwasm-image-io-wasi): add bindgen output
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Nov 4, 2023
1 parent b69d683 commit 7fe693b
Show file tree
Hide file tree
Showing 46 changed files with 3,389 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/image-io/python/itkwasm-image-io-wasi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# itkwasm-image-io-wasi

[![PyPI version](https://badge.fury.io/py/itkwasm-image-io-wasi.svg)](https://badge.fury.io/py/itkwasm-image-io-wasi)

Input and output for scientific and medical image file formats. WASI implementation.

This package provides the WASI WebAssembly implementation. It is usually not called directly. Please use [`itkwasm-image-io`](https://pypi.org/project/itkwasm-image-io/) instead.


## Installation

```sh
pip install itkwasm-image-io-wasi
```

## Development

```sh
pip install pytest
pip install -e .
pytest

# or
pip install hatch
hatch run test
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated file. To retain edits, remove this comment.

"""itkwasm-image-io-wasi: Input and output for scientific and medical image file formats. WASI implementation."""

from .bio_rad_read_image import bio_rad_read_image
from .bio_rad_write_image import bio_rad_write_image
from .bmp_read_image import bmp_read_image
from .bmp_write_image import bmp_write_image
from .fdf_read_image import fdf_read_image
from .fdf_write_image import fdf_write_image
from .gdcm_read_image import gdcm_read_image
from .gdcm_write_image import gdcm_write_image
from .ge_adw_read_image import ge_adw_read_image
from .ge_adw_write_image import ge_adw_write_image
from .ge4_read_image import ge4_read_image
from .ge4_write_image import ge4_write_image
from .ge5_read_image import ge5_read_image
from .ge5_write_image import ge5_write_image
from .gipl_read_image import gipl_read_image
from .gipl_write_image import gipl_write_image
from .jpeg_read_image import jpeg_read_image
from .jpeg_write_image import jpeg_write_image
from .lsm_read_image import lsm_read_image
from .lsm_write_image import lsm_write_image
from .meta_read_image import meta_read_image
from .meta_write_image import meta_write_image
from .mgh_read_image import mgh_read_image
from .mgh_write_image import mgh_write_image
from .mrc_read_image import mrc_read_image
from .mrc_write_image import mrc_write_image
from .nifti_read_image import nifti_read_image
from .nifti_write_image import nifti_write_image
from .nrrd_read_image import nrrd_read_image
from .nrrd_write_image import nrrd_write_image
from .png_read_image import png_read_image
from .png_write_image import png_write_image
from .scanco_read_image import scanco_read_image
from .scanco_write_image import scanco_write_image
from .tiff_read_image import tiff_read_image
from .tiff_write_image import tiff_write_image
from .vtk_read_image import vtk_read_image
from .vtk_write_image import vtk_write_image
from .wasm_read_image import wasm_read_image
from .wasm_write_image import wasm_write_image
from .wasm_zstd_read_image import wasm_zstd_read_image
from .wasm_zstd_write_image import wasm_zstd_write_image

from ._version import __version__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.3.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path, PurePosixPath
import os
from typing import Dict, Tuple, Optional, List, Any

from importlib_resources import files as file_resources

_pipeline = None

from itkwasm import (
InterfaceTypes,
PipelineOutput,
PipelineInput,
Pipeline,
BinaryFile,
Image,
)

def bio_rad_read_image(
serialized_image: os.PathLike,
information_only: bool = False,
) -> Tuple[Any, Image]:
"""Read an image file format and convert it to the itk-wasm file format
:param serialized_image: Input image serialized in the file format
:type serialized_image: os.PathLike
:param information_only: Only read image metadata -- do not read pixel data.
:type information_only: bool
:return: Whether the input could be read. If false, the output image is not valid.
:rtype: Any
:return: Output image
:rtype: Image
"""
global _pipeline
if _pipeline is None:
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bio-rad-read-image.wasi.wasm')))

pipeline_outputs: List[PipelineOutput] = [
PipelineOutput(InterfaceTypes.JsonCompatible),
PipelineOutput(InterfaceTypes.Image),
]

pipeline_inputs: List[PipelineInput] = [
PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))),
]

args: List[str] = ['--memory-io',]
# Inputs
if not Path(serialized_image).exists():
raise FileNotFoundError("serialized_image does not exist")
args.append(str(PurePosixPath(serialized_image)))
# Outputs
could_read_name = '0'
args.append(could_read_name)

image_name = '1'
args.append(image_name)

# Options
input_count = len(pipeline_inputs)
if information_only:
args.append('--information-only')


outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)

result = (
outputs[0].data,
outputs[1].data,
)
return result

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path, PurePosixPath
import os
from typing import Dict, Tuple, Optional, List, Any

from importlib_resources import files as file_resources

_pipeline = None

from itkwasm import (
InterfaceTypes,
PipelineOutput,
PipelineInput,
Pipeline,
Image,
BinaryFile,
)

def bio_rad_write_image(
image: Image,
serialized_image: str,
information_only: bool = False,
use_compression: bool = False,
) -> Tuple[Any]:
"""Write an itk-wasm file format converted to an image file format
:param image: Input image
:type image: Image
:param serialized_image: Output image serialized in the file format.
:type serialized_image: str
:param information_only: Only write image metadata -- do not write pixel data.
:type information_only: bool
:param use_compression: Use compression in the written file
:type use_compression: bool
:return: Whether the input could be written. If false, the output image is not valid.
:rtype: Any
"""
global _pipeline
if _pipeline is None:
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bio-rad-write-image.wasi.wasm')))

pipeline_outputs: List[PipelineOutput] = [
PipelineOutput(InterfaceTypes.JsonCompatible),
PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))),
]

pipeline_inputs: List[PipelineInput] = [
PipelineInput(InterfaceTypes.Image, image),
]

args: List[str] = ['--memory-io',]
# Inputs
args.append('0')
# Outputs
could_write_name = '0'
args.append(could_write_name)

serialized_image_name = str(PurePosixPath(serialized_image))
args.append(serialized_image_name)

# Options
input_count = len(pipeline_inputs)
if information_only:
args.append('--information-only')

if use_compression:
args.append('--use-compression')


outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)

result = outputs[0].data
return result

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path, PurePosixPath
import os
from typing import Dict, Tuple, Optional, List, Any

from importlib_resources import files as file_resources

_pipeline = None

from itkwasm import (
InterfaceTypes,
PipelineOutput,
PipelineInput,
Pipeline,
BinaryFile,
Image,
)

def bmp_read_image(
serialized_image: os.PathLike,
information_only: bool = False,
) -> Tuple[Any, Image]:
"""Read an image file format and convert it to the itk-wasm file format
:param serialized_image: Input image serialized in the file format
:type serialized_image: os.PathLike
:param information_only: Only read image metadata -- do not read pixel data.
:type information_only: bool
:return: Whether the input could be read. If false, the output image is not valid.
:rtype: Any
:return: Output image
:rtype: Image
"""
global _pipeline
if _pipeline is None:
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bmp-read-image.wasi.wasm')))

pipeline_outputs: List[PipelineOutput] = [
PipelineOutput(InterfaceTypes.JsonCompatible),
PipelineOutput(InterfaceTypes.Image),
]

pipeline_inputs: List[PipelineInput] = [
PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))),
]

args: List[str] = ['--memory-io',]
# Inputs
if not Path(serialized_image).exists():
raise FileNotFoundError("serialized_image does not exist")
args.append(str(PurePosixPath(serialized_image)))
# Outputs
could_read_name = '0'
args.append(could_read_name)

image_name = '1'
args.append(image_name)

# Options
input_count = len(pipeline_inputs)
if information_only:
args.append('--information-only')


outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)

result = (
outputs[0].data,
outputs[1].data,
)
return result

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path, PurePosixPath
import os
from typing import Dict, Tuple, Optional, List, Any

from importlib_resources import files as file_resources

_pipeline = None

from itkwasm import (
InterfaceTypes,
PipelineOutput,
PipelineInput,
Pipeline,
Image,
BinaryFile,
)

def bmp_write_image(
image: Image,
serialized_image: str,
information_only: bool = False,
use_compression: bool = False,
) -> Tuple[Any]:
"""Write an itk-wasm file format converted to an image file format
:param image: Input image
:type image: Image
:param serialized_image: Output image serialized in the file format.
:type serialized_image: str
:param information_only: Only write image metadata -- do not write pixel data.
:type information_only: bool
:param use_compression: Use compression in the written file
:type use_compression: bool
:return: Whether the input could be written. If false, the output image is not valid.
:rtype: Any
"""
global _pipeline
if _pipeline is None:
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bmp-write-image.wasi.wasm')))

pipeline_outputs: List[PipelineOutput] = [
PipelineOutput(InterfaceTypes.JsonCompatible),
PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))),
]

pipeline_inputs: List[PipelineInput] = [
PipelineInput(InterfaceTypes.Image, image),
]

args: List[str] = ['--memory-io',]
# Inputs
args.append('0')
# Outputs
could_write_name = '0'
args.append(could_write_name)

serialized_image_name = str(PurePosixPath(serialized_image))
args.append(serialized_image_name)

# Options
input_count = len(pipeline_inputs)
if information_only:
args.append('--information-only')

if use_compression:
args.append('--use-compression')


outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)

result = outputs[0].data
return result

Loading

0 comments on commit 7fe693b

Please sign in to comment.