@@ -240,30 +240,18 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
240
240
mp_raise_RuntimeError (translate ("Read-only object" ));
241
241
}
242
242
243
- // Ensure x1 < x2 and y1 < y2
244
- if (x1 > x2 ) {
245
- int16_t temp = x2 ;
246
- x2 = x1 ;
247
- x1 = temp ;
248
- }
249
- if (y1 > y2 ) {
250
- int16_t temp = y2 ;
251
- y2 = y1 ;
252
- y1 = temp ;
253
- }
243
+ displayio_area_t area = { x1 , y1 , x2 , y2 };
244
+ displayio_area_canon (& area );
254
245
255
- // constrain to bitmap dimensions
256
- x1 = constrain (x1 , 0 , destination -> width );
257
- x2 = constrain (x2 , 0 , destination -> width );
258
- y1 = constrain (y1 , 0 , destination -> height );
259
- y2 = constrain (y2 , 0 , destination -> height );
246
+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height };
247
+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
260
248
261
249
// update the dirty rectangle
262
- displayio_bitmap_set_dirty_area (destination , x1 , y1 , x2 , y2 );
250
+ displayio_bitmap_set_dirty_area (destination , & area );
263
251
264
252
int16_t x , y ;
265
- for (x = x1 ; x < x2 ; x ++ ) {
266
- for (y = y1 ; y < y2 ; y ++ ) {
253
+ for (x = area . x1 ; x < area . x2 ; x ++ ) {
254
+ for (y = area . y1 ; y < area . y2 ; y ++ ) {
267
255
displayio_bitmap_write_pixel (destination , x , y , value );
268
256
}
269
257
}
@@ -298,13 +286,11 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
298
286
ybb0 = y1 ;
299
287
ybb1 = y0 + 1 ;
300
288
}
289
+ displayio_area_t area = { xbb0 , ybb0 , xbb1 , ybb1 };
290
+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height };
291
+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
301
292
302
- xbb0 = constrain (xbb0 , 0 , destination -> width );
303
- xbb1 = constrain (xbb1 , 0 , destination -> width );
304
- ybb0 = constrain (ybb0 , 0 , destination -> height );
305
- ybb1 = constrain (ybb1 , 0 , destination -> height );
306
-
307
- displayio_bitmap_set_dirty_area (destination , xbb0 , ybb0 , xbb1 , ybb1 );
293
+ displayio_bitmap_set_dirty_area (destination , & area );
308
294
309
295
int16_t temp , x , y ;
310
296
@@ -401,7 +387,8 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
401
387
}
402
388
}
403
389
}
404
- displayio_bitmap_set_dirty_area (self , x1 , y1 , x2 , y2 );
390
+ displayio_area_t area = { x1 , y1 , x2 , y2 };
391
+ displayio_bitmap_set_dirty_area (self , & area );
405
392
}
406
393
407
394
void common_hal_bitmaptools_readinto (displayio_bitmap_t * self , pyb_file_obj_t * file , int element_size , int bits_per_pixel , bool reverse_pixels_in_element , bool swap_bytes ) {
@@ -486,5 +473,6 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *f
486
473
}
487
474
}
488
475
489
- displayio_bitmap_set_dirty_area (self , 0 , 0 , self -> width , self -> height );
476
+ displayio_area_t a = {0 , 0 , self -> width , self -> height };
477
+ displayio_bitmap_set_dirty_area (self , & a );
490
478
}
0 commit comments