Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image decoding to CameraFrustumHandle when ._image is set via binary #368

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/viser/_scene_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def _encode_image_binary(
return media_type, binary


def _decode_image_binary(binary: bytes) -> np.ndarray:
with io.BytesIO(binary) as buf:
image = iio.imread(buf)
return image


TVector = TypeVar("TVector", bound=tuple)


Expand Down
5 changes: 5 additions & 0 deletions src/viser/_scene_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ class CameraFrustumHandle(
@property
def image(self) -> np.ndarray | None:
"""Current content of the image. Synchronized automatically when assigned."""
if self._image is None and self._image_data is not None:
from ._scene_api import _decode_image_binary

self._image = _decode_image_binary(self._image_data)

return self._image

@image.setter
Expand Down