Skip to content

Commit

Permalink
Use byte_offset and byte_offset_from from the std library (#179)
Browse files Browse the repository at this point in the history
Closes #159
  • Loading branch information
aliddell authored Apr 3, 2024
1 parent 5c1d9c3 commit fb060e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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

Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 3 additions & 13 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<T>(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;
Expand All @@ -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;
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit fb060e1

Please sign in to comment.