Skip to content

Commit 9fdd804

Browse files
committed
enforce new bitmap same size as previous
1 parent 65f0857 commit 9fdd804

File tree

2 files changed

+19
-46
lines changed

2 files changed

+19
-46
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,10 @@ msgstr ""
15991599
msgid "Name too long"
16001600
msgstr ""
16011601

1602+
#: shared-bindings/displayio/TileGrid.c
1603+
msgid "New bitmap must be same size as old bitmap"
1604+
msgstr ""
1605+
16021606
#: ports/espressif/common-hal/_bleio/__init__.c
16031607
msgid "Nimble out of memory"
16041608
msgstr ""
@@ -3024,7 +3028,7 @@ msgstr ""
30243028
msgid "complex values not supported"
30253029
msgstr ""
30263030

3027-
#: extmod/moduzlib.c shared-module/zlib/DecompIO.c
3031+
#: extmod/moduzlib.c
30283032
msgid "compression header"
30293033
msgstr ""
30303034

shared-bindings/displayio/TileGrid.c

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -439,78 +439,47 @@ STATIC mp_obj_t displayio_tilegrid_obj_set_bitmap(mp_obj_t self_in, mp_obj_t bit
439439
mp_raise_TypeError(translate("bitmap must be displayio.Bitmap, displayio.Shape, or displayio.OnDiskBitmap"));
440440
}
441441

442-
/*if (bitmap->width % self->tile_width != 0) {
443-
mp_raise_ValueError(translate("Tile width must exactly divide bitmap width"));
444-
}
445-
if (bitmap->height % self->tile_height != 0) {
446-
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
447-
}*/
448-
// enforce_bitmap_size(self_in, bitmap);
449-
450-
uint16_t bitmap_width;
451-
uint16_t bitmap_height;
442+
uint16_t new_bitmap_width;
443+
uint16_t new_bitmap_height;
452444
mp_obj_t native = mp_obj_cast_to_native_base(bitmap, &displayio_shape_type);
453445
if (native != MP_OBJ_NULL) {
454446
displayio_shape_t *bmp = MP_OBJ_TO_PTR(native);
455-
bitmap_width = bmp->width;
456-
bitmap_height = bmp->height;
447+
new_bitmap_width = bmp->width;
448+
new_bitmap_height = bmp->height;
457449
} else if (mp_obj_is_type(bitmap, &displayio_bitmap_type)) {
458450
displayio_bitmap_t *bmp = MP_OBJ_TO_PTR(bitmap);
459451
native = bitmap;
460-
bitmap_width = bmp->width;
461-
bitmap_height = bmp->height;
452+
new_bitmap_width = bmp->width;
453+
new_bitmap_height = bmp->height;
462454
} else if (mp_obj_is_type(bitmap, &displayio_ondiskbitmap_type)) {
463455
displayio_ondiskbitmap_t *bmp = MP_OBJ_TO_PTR(bitmap);
464456
native = bitmap;
465-
bitmap_width = bmp->width;
466-
bitmap_height = bmp->height;
457+
new_bitmap_width = bmp->width;
458+
new_bitmap_height = bmp->height;
467459
} else {
468460
mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_bitmap);
469461
}
470462

471-
uint16_t tile_width = self->tile_width;
472-
uint16_t tile_height = self->tile_height;
473463
mp_obj_t old_native = mp_obj_cast_to_native_base(self->bitmap, &displayio_shape_type);
474464
if (old_native != MP_OBJ_NULL) {
475465
displayio_shape_t *old_bmp = MP_OBJ_TO_PTR(old_native);
476-
if (tile_width == old_bmp->width) {
477-
self->tile_width = bitmap_width;
478-
}
479-
if (tile_height == old_bmp->width) {
480-
self->tile_height = bitmap_height;
466+
if (old_bmp->width != new_bitmap_width || old_bmp->height != new_bitmap_height) {
467+
mp_raise_ValueError(translate("New bitmap must be same size as old bitmap"));
481468
}
482-
483469
} else if (mp_obj_is_type(self->bitmap, &displayio_bitmap_type)) {
484470
displayio_bitmap_t *old_bmp = MP_OBJ_TO_PTR(self->bitmap);
485471
old_native = self->bitmap;
486-
if (tile_width == old_bmp->width) {
487-
self->tile_width = bitmap_width;
488-
}
489-
if (tile_height == old_bmp->width) {
490-
self->tile_height = bitmap_height;
472+
if (old_bmp->width != new_bitmap_width || old_bmp->height != new_bitmap_height) {
473+
mp_raise_ValueError(translate("New bitmap must be same size as old bitmap"));
491474
}
492-
493475
} else if (mp_obj_is_type(self->bitmap, &displayio_ondiskbitmap_type)) {
494476
displayio_ondiskbitmap_t *old_bmp = MP_OBJ_TO_PTR(self->bitmap);
495477
old_native = self->bitmap;
496-
if (tile_width == old_bmp->width) {
497-
self->tile_width = bitmap_width;
498-
}
499-
if (tile_height == old_bmp->width) {
500-
self->tile_height = bitmap_height;
478+
if (old_bmp->width != new_bitmap_width || old_bmp->height != new_bitmap_height) {
479+
mp_raise_ValueError(translate("New bitmap must be same size as old bitmap"));
501480
}
502481
}
503482

504-
505-
506-
if (bitmap_width % tile_width != 0) {
507-
mp_raise_ValueError(translate("Tile width must exactly divide bitmap width"));
508-
}
509-
if (bitmap_height % tile_height != 0) {
510-
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
511-
}
512-
513-
514483
common_hal_displayio_tilegrid_set_bitmap(self, bitmap);
515484

516485
return mp_const_none;

0 commit comments

Comments
 (0)