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

refactor: simplify strides #194

Merged
merged 3 commits into from
Nov 23, 2023
Merged
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
25 changes: 9 additions & 16 deletions src/nd2/readers/_modern/modern_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,28 +382,21 @@ def _strides(self) -> tuple[int, ...] | None:
if not (widthP and widthB):
self._strides_ = None
else:
bypc = self._bytes_per_pixel()
compCount = a.componentCount
array_stride = widthB - (bypc * widthP * compCount)
if array_stride == 0:
n_components = a.componentCount
bypc = a.bitsPerComponentInMemory // 8
if widthB == (widthP * bypc * n_components):
self._strides_ = None
else:
self._strides_ = (
array_stride + widthP * bypc * compCount,
compCount * bypc,
compCount // (a.channelCount or 1) * bypc,
bypc,
)
# the extra bypc is because we shape this as
# (width, height, channels, RGBcompents)
# see _actual_frame_shape() below
self._strides_ = (widthB, n_components * bypc, bypc, bypc)
return self._strides_

def _actual_frame_shape(self) -> tuple[int, ...]:
attr = self.attributes()
return (
attr.heightPx,
attr.widthPx or 1,
attr.channelCount or 1,
attr.componentCount // (attr.channelCount or 1),
)
nC = attr.channelCount or 1
return (attr.heightPx, attr.widthPx or 1, nC, attr.componentCount // nC)

def custom_data(self) -> dict[str, Any]:
return {
Expand Down