@@ -384,37 +384,11 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
384
384
385
385
}
386
386
387
- void common_hal_bitmaptools_draw_line (displayio_bitmap_t * destination ,
387
+ STATIC void draw_line (displayio_bitmap_t * destination ,
388
388
int16_t x0 , int16_t y0 ,
389
389
int16_t x1 , int16_t y1 ,
390
390
uint32_t value ) {
391
391
392
- //
393
- // adapted from Adafruit_CircuitPython_Display_Shapes.Polygon._line
394
- //
395
-
396
- // update the dirty rectangle
397
- int16_t xbb0 , xbb1 , ybb0 , ybb1 ;
398
- if (x0 < x1 ) {
399
- xbb0 = x0 ;
400
- xbb1 = x1 + 1 ;
401
- } else {
402
- xbb0 = x1 ;
403
- xbb1 = x0 + 1 ;
404
- }
405
- if (y0 < y1 ) {
406
- ybb0 = y0 ;
407
- ybb1 = y1 + 1 ;
408
- } else {
409
- ybb0 = y1 ;
410
- ybb1 = y0 + 1 ;
411
- }
412
- displayio_area_t area = { xbb0 , ybb0 , xbb1 , ybb1 , NULL };
413
- displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height , NULL };
414
- displayio_area_compute_overlap (& area , & bitmap_area , & area );
415
-
416
- displayio_bitmap_set_dirty_area (destination , & area );
417
-
418
392
int16_t temp , x , y ;
419
393
420
394
if (x0 == x1 ) { // vertical line
@@ -488,6 +462,84 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
488
462
}
489
463
}
490
464
465
+ void common_hal_bitmaptools_draw_line (displayio_bitmap_t * destination ,
466
+ int16_t x0 , int16_t y0 ,
467
+ int16_t x1 , int16_t y1 ,
468
+ uint32_t value ) {
469
+
470
+ //
471
+ // adapted from Adafruit_CircuitPython_Display_Shapes.Polygon._line
472
+ //
473
+
474
+ // update the dirty rectangle
475
+ int16_t xbb0 , xbb1 , ybb0 , ybb1 ;
476
+ if (x0 < x1 ) {
477
+ xbb0 = x0 ;
478
+ xbb1 = x1 + 1 ;
479
+ } else {
480
+ xbb0 = x1 ;
481
+ xbb1 = x0 + 1 ;
482
+ }
483
+ if (y0 < y1 ) {
484
+ ybb0 = y0 ;
485
+ ybb1 = y1 + 1 ;
486
+ } else {
487
+ ybb0 = y1 ;
488
+ ybb1 = y0 + 1 ;
489
+ }
490
+ displayio_area_t area = { xbb0 , ybb0 , xbb1 , ybb1 , NULL };
491
+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height , NULL };
492
+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
493
+
494
+ displayio_bitmap_set_dirty_area (destination , & area );
495
+
496
+ draw_line (destination , x0 , y0 , x1 , y1 , value );
497
+ }
498
+
499
+ STATIC int32_t ith (void * data , size_t i , int element_size ) {
500
+ switch (element_size ) {
501
+ default :
502
+ case 1 :
503
+ return * ((int8_t * )data + i );
504
+ case 2 :
505
+ return * ((int16_t * )data + i );
506
+ case 4 :
507
+ return * ((int32_t * )data + i );
508
+ }
509
+ }
510
+
511
+ void common_hal_bitmaptools_draw_polygon (displayio_bitmap_t * destination , void * xs , void * ys , size_t points_len , int point_size , uint32_t value , bool close ) {
512
+ int16_t x0 , y0 , xmin , xmax , ymin , ymax , xprev , yprev , x , y ;
513
+ x0 = ith (xs , 0 , point_size );
514
+ xmin = x0 ;
515
+ xmax = x0 ;
516
+ xprev = x0 ;
517
+ y0 = ith (ys , 0 , point_size );
518
+ ymin = y0 ;
519
+ ymax = y0 ;
520
+ yprev = y0 ;
521
+
522
+ for (size_t i = 1 ; i < points_len ; i ++ ) {
523
+ x = ith (xs , i , point_size );
524
+ y = ith (ys , i , point_size );
525
+ draw_line (destination , xprev , yprev , x , y , value );
526
+ xprev = x ;
527
+ yprev = y ;
528
+ xmin = MIN (xmin , x );
529
+ xmax = MAX (xmax , x );
530
+ ymin = MIN (ymin , y );
531
+ ymax = MAX (ymax , y );
532
+ }
533
+ if (close ) {
534
+ draw_line (destination , xprev , yprev , x0 , y0 , value );
535
+ }
536
+
537
+ displayio_area_t area = { xmin , ymin , xmax , ymax , NULL };
538
+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height , NULL };
539
+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
540
+ displayio_bitmap_set_dirty_area (destination , & area );
541
+ }
542
+
491
543
void common_hal_bitmaptools_arrayblit (displayio_bitmap_t * self , void * data , int element_size , int x1 , int y1 , int x2 , int y2 , bool skip_specified , uint32_t skip_value ) {
492
544
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value (self )) - 1 ;
493
545
0 commit comments