From fb060e112a372dca511d5f0dd26841493e73dfe2 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Wed, 3 Apr 2024 11:59:20 -0400 Subject: [PATCH] Use `byte_offset` and `byte_offset_from` from the std library (#179) Closes #159 --- README.md | 14 ++++++++++---- src/runtime.rs | 16 +++------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0d5a83d..4f7a3bb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ python -m pip install acquire-imaging ``` -Acquire ([`acquire-imaging` on PyPI](https://pypi.org/project/acquire-imaging/)) provides high-speed, multi-camera, video streaming for up to **2** cameras and image acquisition with a programming interface for streaming video data directly to Python, cloud-friendly file formats, and visualization platforms, such as [napari](https://napari.org/stable/). +Acquire ([`acquire-imaging` on PyPI](https://pypi.org/project/acquire-imaging/)) provides high-speed, multi-camera, +video streaming for up to **2** cameras and image acquisition with a programming interface for streaming video data +directly to Python, cloud-friendly file formats, and visualization platforms, such +as [napari](https://napari.org/stable/). > **Note** This is an early stage project. If you find it interesting, please > reach out! @@ -33,9 +36,11 @@ For testing and demonstration purposes, Acquire provides a few simulated video s ## Usage -Check out our documentation [here](https://acquire-project.github.io/acquire-docs/). +Check out our documentation [here](https://acquire-project.github.io/acquire-docs/). -The provided [napari](https://napari.org/stable/) plugin ([code here](https://github.com/acquire-project/acquire-python/blob/main/python/acquire/__init__.py#L131)) is a good example of how to stream for visualization. +The provided [napari](https://napari.org/stable/) +plugin ([code here](https://github.com/acquire-project/acquire-python/blob/main/python/acquire/__init__.py#L131)) is a +good example of how to stream for visualization. ## Development @@ -50,7 +55,7 @@ Requires [chocolatey](https://community.chocolatey.org/packages/cmake)) - A C++20 compiler (Microsoft Visual Studio Community [download page](https://visualstudio.microsoft.com/downloads/), or clang) -- Rust (via rustup, see [install +- Rust >= 1.75 (via rustup, see [install page](https://www.rust-lang.org/tools/install)) - conda (optional; via [miniconda](https://docs.conda.io/en/latest/miniconda.html)) @@ -84,6 +89,7 @@ python -m build This package depends on a submodule ([acquire-common](https://github.com/acquire-project/acquire-common)) and binaries from the following Acquire drivers: + - [acquire-driver-hdcam](https://github.com/acquire-project/acquire-driver-hdcam) - [acquire-driver-egrabber](https://github.com/acquire-project/acquire-driver-egrabber) - [acquire-driver-zarr](https://github.com/acquire-project/acquire-driver-zarr) diff --git a/src/runtime.rs b/src/runtime.rs index 62a7ef5..c89802a 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -228,16 +228,6 @@ struct RawAvailableData { unsafe impl Send for RawAvailableData {} unsafe impl Sync for RawAvailableData {} -// Can replace this if `pointer_byte_offsets` gets stabilized. -unsafe fn byte_offset(origin: *mut T, count: isize) -> *mut T { - (origin as *const u8).offset(count) as *mut T -} - -// Can replace this if `pointer_byte_offsets` gets stabilized. -unsafe fn byte_offset_from(beg: *mut T, end: *mut T) -> isize { - (end as *const u8).offset_from(beg as *const u8) -} - impl RawAvailableData { fn get_frame_count(&self) -> usize { let mut count = 0; @@ -253,7 +243,7 @@ impl RawAvailableData { frame.bytes_of_frame ); assert!(frame.bytes_of_frame > 0); - cur = byte_offset(cur, frame.bytes_of_frame as _); + cur = cur.byte_offset(frame.bytes_of_frame as _); count += 1; } } @@ -265,7 +255,7 @@ impl Drop for RawAvailableData { fn drop(&mut self) { let consumed_bytes = self .consumed_bytes - .unwrap_or(unsafe { byte_offset_from(self.beg.as_ptr(), self.end.as_ptr()) } as usize); + .unwrap_or(unsafe { self.end.as_ptr().byte_offset_from(self.beg.as_ptr()) } as usize); log::debug!( "[stream {}] DROP read region: {:p}-{:p}:{}", self.stream_id, @@ -341,7 +331,7 @@ impl AvailableDataContext { let nbytes = if beg.is_null() || end.is_null() { 0 } else { - unsafe { byte_offset_from(beg, end) } + unsafe { end.byte_offset_from(beg) } }; log::trace!(