Skip to content

Commit 30c07a7

Browse files
committed
bitmaptools: dither: get rid of shifts
this happens to make the occasional FS dither artifact disappear. I guess `a * b >> 8` and `(a * b) / 256` are not identical. I'm not sure if it was just the parens or not, but write the clearer code and rely on the compiler to substitute an appropriate shift if possible.
1 parent 9af76a2 commit 30c07a7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

shared-module/bitmaptools/__init__.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ void common_hal_bitmaptools_dither(displayio_bitmap_t *dest_bitmap, displayio_bi
749749
int x1 = x + info->terms[i].dx;
750750
int dy = info->terms[i].dy;
751751

752-
rows[dy][x1] = ((info->terms[i].dl * err) >> 8) + rows[dy][x1];
752+
rows[dy][x1] = ((info->terms[i].dl * err) / 256) + rows[dy][x1];
753753
}
754-
err = err * info->dl >> 8;
754+
err = (err * info->dl) / 256;
755755
}
756756
write_pixels(dest_bitmap, y, out);
757757

@@ -779,9 +779,9 @@ void common_hal_bitmaptools_dither(displayio_bitmap_t *dest_bitmap, displayio_bi
779779
int x1 = x - info->terms[i].dx;
780780
int dy = info->terms[i].dy;
781781

782-
rows[dy][x1] = ((info->terms[i].dl * err) >> 8) + rows[dy][x1];
782+
rows[dy][x1] = ((info->terms[i].dl * err) / 256) + rows[dy][x1];
783783
}
784-
err = err * info->dl >> 8;
784+
err = (err * info->dl) / 256;
785785
}
786786
write_pixels(dest_bitmap, y, out);
787787

0 commit comments

Comments
 (0)