@@ -439,78 +439,47 @@ STATIC mp_obj_t displayio_tilegrid_obj_set_bitmap(mp_obj_t self_in, mp_obj_t bit
439
439
mp_raise_TypeError (translate ("bitmap must be displayio.Bitmap, displayio.Shape, or displayio.OnDiskBitmap" ));
440
440
}
441
441
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 ;
452
444
mp_obj_t native = mp_obj_cast_to_native_base (bitmap , & displayio_shape_type );
453
445
if (native != MP_OBJ_NULL ) {
454
446
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 ;
457
449
} else if (mp_obj_is_type (bitmap , & displayio_bitmap_type )) {
458
450
displayio_bitmap_t * bmp = MP_OBJ_TO_PTR (bitmap );
459
451
native = bitmap ;
460
- bitmap_width = bmp -> width ;
461
- bitmap_height = bmp -> height ;
452
+ new_bitmap_width = bmp -> width ;
453
+ new_bitmap_height = bmp -> height ;
462
454
} else if (mp_obj_is_type (bitmap , & displayio_ondiskbitmap_type )) {
463
455
displayio_ondiskbitmap_t * bmp = MP_OBJ_TO_PTR (bitmap );
464
456
native = bitmap ;
465
- bitmap_width = bmp -> width ;
466
- bitmap_height = bmp -> height ;
457
+ new_bitmap_width = bmp -> width ;
458
+ new_bitmap_height = bmp -> height ;
467
459
} else {
468
460
mp_raise_TypeError_varg (translate ("unsupported %q type" ), MP_QSTR_bitmap );
469
461
}
470
462
471
- uint16_t tile_width = self -> tile_width ;
472
- uint16_t tile_height = self -> tile_height ;
473
463
mp_obj_t old_native = mp_obj_cast_to_native_base (self -> bitmap , & displayio_shape_type );
474
464
if (old_native != MP_OBJ_NULL ) {
475
465
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" ));
481
468
}
482
-
483
469
} else if (mp_obj_is_type (self -> bitmap , & displayio_bitmap_type )) {
484
470
displayio_bitmap_t * old_bmp = MP_OBJ_TO_PTR (self -> bitmap );
485
471
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" ));
491
474
}
492
-
493
475
} else if (mp_obj_is_type (self -> bitmap , & displayio_ondiskbitmap_type )) {
494
476
displayio_ondiskbitmap_t * old_bmp = MP_OBJ_TO_PTR (self -> bitmap );
495
477
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" ));
501
480
}
502
481
}
503
482
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
-
514
483
common_hal_displayio_tilegrid_set_bitmap (self , bitmap );
515
484
516
485
return mp_const_none ;
0 commit comments