Skip to content

unienv_interface.remote.compression

Opt-in lossy compression of server-to-client image arrays.

A client asks for it in hello, e.g. RemoteClient.connect(address, compress={"image": "jpeg:90"}). The server then encodes the uint8 leaves of results whose space has metadata["kind"] == "image" (layout "HWC" or "CHW", 1 or 3 channels; leading dimensions are batch dimensions) with that codec. Depth maps, float arrays and everything the client sends stay raw.

Codecs are pluggable (:func:unienv_interface.remote.wire.register_codec); the built-in jpeg codec uses OpenCV when installed, otherwise Pillow.

KINDS module-attribute

KINDS = ('image',)

JpegCodec

Bases: ArrayCodec

JPEG per image. Options: quality (1-100), layout (HWC/CHW), format (rgb/bgr/gray).

encode

encode(array: ndarray, options: Dict[str, Any]) -> List[bytes]

decode

decode(blobs: Sequence[Any], dtype: dtype, shape: Tuple[int, ...], options: Dict[str, Any]) -> np.ndarray

parse_spec

parse_spec(spec: Any) -> Dict[str, Tuple[str, Dict[str, Any]]]

Validate {"image": "jpeg:90"} into {"image": ("jpeg", {"quality": 90})}.

compress_result

compress_result(value: Any, resource: _Resource, method: str, spec: Dict[str, Tuple[str, Dict[str, Any]]]) -> Any

Mark the image leaves of a call result for compression (others are returned as is).