Skip to content

Commit 153ff60

Browse files
authored
Merge pull request #5616 from jepler/bitmaptools-bugfixes
Bitmaptools bugfixes
2 parents b09c777 + ddf2477 commit 153ff60

File tree

11 files changed

+26
-39
lines changed

11 files changed

+26
-39
lines changed

shared-bindings/bitmaptools/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_readinto_obj, 0, bitmaptools_readinto);
664664
//| """The Floyd-Stenberg dither"""
665665
//|
666666
MAKE_ENUM_VALUE(bitmaptools_dither_algorithm_type, dither_algorithm, Atkinson, DITHER_ALGORITHM_ATKINSON);
667-
MAKE_ENUM_VALUE(bitmaptools_dither_algorithm_type, dither_algorithm, FloydStenberg, DITHER_ALGORITHM_ATKINSON);
667+
MAKE_ENUM_VALUE(bitmaptools_dither_algorithm_type, dither_algorithm, FloydStenberg, DITHER_ALGORITHM_FLOYD_STENBERG);
668668

669669
MAKE_ENUM_MAP(bitmaptools_dither_algorithm) {
670670
MAKE_ENUM_MAP_ENTRY(dither_algorithm, Atkinson),

shared-module/bitmaptools/__init__.c

Lines changed: 7 additions & 7 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

@@ -761,13 +761,13 @@ void common_hal_bitmaptools_dither(displayio_bitmap_t *dest_bitmap, displayio_bi
761761
rows[1] = rows[2];
762762
rows[2] = tmp;
763763

764-
fill_row(source_bitmap, swap, rows[2], y + 2, info->mx);
765-
766764
y++;
767765
if (y == height) {
768766
break;
769767
}
770768

769+
fill_row(source_bitmap, swap, rows[2], y + 2, info->mx);
770+
771771
// Serpentine dither. Going right-to-left...
772772
for (int x = width; x--;) {
773773
int16_t pixel_in = rows[0][x] + err;
@@ -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

@@ -790,7 +790,7 @@ void common_hal_bitmaptools_dither(displayio_bitmap_t *dest_bitmap, displayio_bi
790790
rows[1] = rows[2];
791791
rows[2] = tmp;
792792

793-
fill_row(source_bitmap, swap, rows[2], y + 2, info->mx);
793+
fill_row(source_bitmap, swap, rows[2], y + 3, info->mx);
794794
}
795795

796796
displayio_area_t a = { 0, 0, width, height, NULL };
Binary file not shown.
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import bitmaptools
2+
import displayio
3+
import _bmp16
4+
5+
if "/" in __file__:
6+
here = __file__.rsplit("/", 1)[0]
7+
else:
8+
here = "."
9+
10+
c = displayio.Colorspace.BGR565
11+
12+
b1 = _bmp16.loadbmp16(here + "/minerva16.bmp")
13+
b3 = displayio.Bitmap(320, 240, 65536)
14+
15+
bitmaptools.dither(b3, b1, c)
16+
_bmp16.writebmp16(f"dither-atkinson.bmp", b3)
17+
bitmaptools.dither(b3, b1, c, bitmaptools.DitherAlgorithm.FloydStenberg)
18+
_bmp16.writebmp16(f"dither-floydstenberg.bmp", b3)
Binary file not shown.

tests/circuitpython-manual/dither.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)