Skip to content

Commit

Permalink
refactor: simplify strides (#194)
Browse files Browse the repository at this point in the history
* refactor: simplify strides

* comment

* fix walrus
  • Loading branch information
tlambert03 authored Nov 23, 2023
1 parent bdf0ecb commit eb4bf8f
Showing 1 changed file with 9 additions and 16 deletions.
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

0 comments on commit eb4bf8f

Please sign in to comment.