@@ -95,10 +95,6 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
9595 // # */
9696
9797
98- if (self -> read_only ) {
99- mp_raise_RuntimeError (translate ("Read-only object" ));
100- }
101-
10298 int16_t x ,y ;
10399
104100 int16_t minx = dest_clip1_x ;
@@ -199,14 +195,17 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
199195 float rowu = startu + miny * duCol ;
200196 float rowv = startv + miny * dvCol ;
201197
198+ displayio_area_t dirty_area = {minx , miny , maxx + 1 , maxy + 1 };
199+ displayio_bitmap_set_dirty_area (self , & dirty_area );
200+
202201 for (y = miny ; y <= maxy ; y ++ ) {
203202 float u = rowu + minx * duRow ;
204203 float v = rowv + minx * dvRow ;
205204 for (x = minx ; x <= maxx ; x ++ ) {
206205 if (u >= source_clip0_x && u < source_clip1_x && v >= source_clip0_y && v < source_clip1_y ) {
207206 uint32_t c = common_hal_displayio_bitmap_get_pixel (source , u , v );
208207 if ((skip_index_none ) || (c != skip_index )) {
209- common_hal_displayio_bitmap_set_pixel (self , x , y , c );
208+ displayio_bitmap_write_pixel (self , x , y , c );
210209 }
211210 }
212211 u += duRow ;
@@ -236,34 +235,18 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
236235 //
237236 // input checks should ensure that x1 < x2 and y1 < y2 and are within the bitmap region
238237
239- if (destination -> read_only ) {
240- mp_raise_RuntimeError (translate ("Read-only object" ));
241- }
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- }
238+ displayio_area_t area = { x1 , y1 , x2 , y2 };
239+ displayio_area_canon (& area );
254240
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 );
241+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height };
242+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
260243
261244 // update the dirty rectangle
262- displayio_bitmap_set_dirty_area (destination , x1 , y1 , x2 , y2 );
245+ displayio_bitmap_set_dirty_area (destination , & area );
263246
264247 int16_t x , y ;
265- for (x = x1 ; x < x2 ; x ++ ) {
266- for (y = y1 ; y < y2 ; y ++ ) {
248+ for (x = area . x1 ; x < area . x2 ; x ++ ) {
249+ for (y = area . y1 ; y < area . y2 ; y ++ ) {
267250 displayio_bitmap_write_pixel (destination , x , y , value );
268251 }
269252 }
@@ -274,10 +257,6 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
274257 int16_t x1 , int16_t y1 ,
275258 uint32_t value ) {
276259
277- if (destination -> read_only ) {
278- mp_raise_RuntimeError (translate ("Read-only object" ));
279- }
280-
281260 //
282261 // adapted from Adafruit_CircuitPython_Display_Shapes.Polygon._line
283262 //
@@ -298,13 +277,11 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
298277 ybb0 = y1 ;
299278 ybb1 = y0 + 1 ;
300279 }
280+ displayio_area_t area = { xbb0 , ybb0 , xbb1 , ybb1 };
281+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height };
282+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
301283
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 );
284+ displayio_bitmap_set_dirty_area (destination , & area );
308285
309286 int16_t temp , x , y ;
310287
@@ -401,15 +378,15 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
401378 }
402379 }
403380 }
404- displayio_bitmap_set_dirty_area (self , x1 , y1 , x2 , y2 );
381+ displayio_area_t area = { x1 , y1 , x2 , y2 };
382+ displayio_bitmap_set_dirty_area (self , & area );
405383}
406384
407385void 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 , bool reverse_rows ) {
408386 uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value (self )) - 1 ;
409387
410- if (self -> read_only ) {
411- mp_raise_RuntimeError (translate ("Read-only object" ));
412- }
388+ displayio_area_t a = {0 , 0 , self -> width , self -> height };
389+ displayio_bitmap_set_dirty_area (self , & a );
413390
414391 size_t elements_per_row = (self -> width * bits_per_pixel + element_size * 8 - 1 ) / (element_size * 8 );
415392 size_t rowsize = element_size * elements_per_row ;
@@ -486,6 +463,4 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *f
486463 displayio_bitmap_write_pixel (self , x , y_draw , value & mask );
487464 }
488465 }
489-
490- displayio_bitmap_set_dirty_area (self , 0 , 0 , self -> width , self -> height );
491466}
0 commit comments