Fix shift_pixel_window when shift_right_by > window_width

This commit is contained in:
kris 2021-11-03 15:19:29 +00:00
parent 34ae40ac2d
commit 1010b64272
1 changed files with 7 additions and 1 deletions

View File

@ -66,7 +66,13 @@ cdef inline unsigned char shift_pixel_window(
Returns: n-bit value representing shifted pixel window
"""
cdef unsigned char window_mask = 0xff >> (8 - window_width)
return ((last_pixels >> shift_right_by) | (next_pixels << (window_width - shift_right_by))) & window_mask
cdef unsigned int shifted_next_pixels
if window_width > shift_right_by:
shifted_next_pixels = next_pixels << (window_width - shift_right_by)
else:
shifted_next_pixels = next_pixels >> (shift_right_by - window_width)
return ((last_pixels >> shift_right_by) | shifted_next_pixels) & window_mask
# Look ahead a number of pixels and compute choice for next pixel with lowest total squared error after dithering.