3
3
*
4
4
* The MIT License (MIT)
5
5
*
6
- * Copyright (c) 2021 Kevin Matocha
6
+ * Copyright (c) 2021 Kevin Matocha, Jose David Montoya
7
7
*
8
8
* Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
* of this software and associated documentation files (the "Software"), to deal
40
40
#include <stdio.h>
41
41
#include <string.h>
42
42
43
+ #define BITMAP_DEBUG (...) (void)0
44
+ // #define BITMAP_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
45
+
43
46
void common_hal_bitmaptools_rotozoom (displayio_bitmap_t * self , int16_t ox , int16_t oy ,
44
47
int16_t dest_clip0_x , int16_t dest_clip0_y ,
45
48
int16_t dest_clip1_x , int16_t dest_clip1_y ,
@@ -918,3 +921,59 @@ void common_hal_bitmaptools_alphablend(displayio_bitmap_t *dest, displayio_bitma
918
921
}
919
922
}
920
923
}
924
+
925
+ STATIC void draw_circle (displayio_bitmap_t * destination ,
926
+ int16_t x0 , int16_t y0 ,
927
+ int16_t radius , uint32_t value ) {
928
+
929
+ int16_t d , y ;
930
+
931
+ mp_arg_validate_int_range (x0 , SHRT_MIN , SHRT_MAX , MP_QSTR_x0 );
932
+ mp_arg_validate_int_range (y0 , SHRT_MIN , SHRT_MAX , MP_QSTR_y0 );
933
+
934
+ BITMAP_DEBUG ("x, y, radius (%4d, %4d, %4d)\n" , x0 , y0 , radius );
935
+
936
+ y = radius ;
937
+ d = 3 - 2 * radius ;
938
+
939
+ // Bresenham's circle algorithm
940
+ for (int x = 0 ; x <= y ; x ++ ) {
941
+ displayio_bitmap_write_pixel (destination , x + x0 , y + y0 , value );
942
+ displayio_bitmap_write_pixel (destination , - x + x0 , - y + y0 , value );
943
+ displayio_bitmap_write_pixel (destination , - x + x0 , y + y0 , value );
944
+ displayio_bitmap_write_pixel (destination , x + x0 , - y + y0 , value );
945
+ displayio_bitmap_write_pixel (destination , y + x0 , x + y0 , value );
946
+ displayio_bitmap_write_pixel (destination , - y + x0 , x + y0 , value );
947
+ displayio_bitmap_write_pixel (destination , - y + x0 , - x + y0 , value );
948
+ displayio_bitmap_write_pixel (destination , y + x0 , - x + y0 , value );
949
+ if (d <= 0 ) {
950
+ d = d + (4 * x ) + 6 ;
951
+ } else {
952
+ d = d + 4 * (x - y ) + 10 ;
953
+ y = y - 1 ;
954
+ }
955
+ }
956
+ }
957
+
958
+ void common_hal_bitmaptools_draw_circle (displayio_bitmap_t * destination ,
959
+ int16_t x0 , int16_t y0 ,
960
+ int16_t radius ,
961
+ uint32_t value ) {
962
+
963
+
964
+ // update the dirty area
965
+ int16_t xbb0 , xbb1 , ybb0 , ybb1 ;
966
+
967
+ xbb0 = x0 - radius ;
968
+ xbb1 = x0 + radius ;
969
+ ybb0 = y0 - radius ;
970
+ ybb1 = y0 + radius ;
971
+
972
+ displayio_area_t area = { xbb0 , ybb0 , xbb1 , ybb1 , NULL };
973
+ displayio_area_t bitmap_area = { 0 , 0 , destination -> width , destination -> height , NULL };
974
+ displayio_area_compute_overlap (& area , & bitmap_area , & area );
975
+
976
+ displayio_bitmap_set_dirty_area (destination , & area );
977
+
978
+ draw_circle (destination , x0 , y0 , radius , value );
979
+ }
0 commit comments