Skip to content

Commit

Permalink
appease mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
mkst committed Mar 30, 2023
1 parent 158ff1e commit addc72b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions n64img/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from math import ceil


WORD_SIZE = 4 # bytes
BYTES_PER_WORD: int = 4


def iter_in_groups(iterable, n, fillvalue=None):
Expand All @@ -16,25 +16,24 @@ def iter_image_indexes(
bytes_per_pixel: float = 1,
flip_h: bool = False,
flip_v: bool = False,
swap_words : bool = False,
swap_words: bool = False,
):
w = int(width * bytes_per_pixel)
h = int(height * 1)

xrange = (
xrange = list(
range(w - ceil(bytes_per_pixel), -1, -ceil(bytes_per_pixel))
if flip_h
else range(0, w, ceil(bytes_per_pixel))
)

if swap_words:
xrange = list(xrange)
xrange_swapped = []
pixels_per_word = ceil(WORD_SIZE / bytes_per_pixel)
for i in range(0, len(xrange), pixels_per_word*2):
pixels_per_word = ceil(BYTES_PER_WORD / bytes_per_pixel)
for i in range(0, len(xrange), pixels_per_word * 2):
xrange_swapped += [
*xrange[i+pixels_per_word:i+pixels_per_word+pixels_per_word],
*xrange[i:i+pixels_per_word],
*xrange[i + pixels_per_word : i + pixels_per_word + pixels_per_word],
*xrange[i : i + pixels_per_word],
]

yrange = range(h - 1, -1, -1) if flip_v else range(0, h, 1)
Expand Down

0 comments on commit addc72b

Please sign in to comment.