30
30
31
31
#include "py/runtime.h"
32
32
33
- void common_hal_displayio_bitmap_construct (displayio_bitmap_t * self , uint32_t width ,
34
- uint32_t height , uint32_t bits_per_value ) {
33
+ enum { align_bits = 8 * sizeof (uint32_t ) };
34
+
35
+ static int stride (uint32_t width , uint32_t bits_per_value ) {
35
36
uint32_t row_width = width * bits_per_value ;
36
37
// align to uint32_t
37
- uint8_t align_bits = 8 * sizeof (uint32_t );
38
- if (row_width % align_bits != 0 ) {
39
- self -> stride = (row_width / align_bits + 1 );
40
- } else {
41
- self -> stride = row_width / align_bits ;
42
- }
38
+ return (row_width + align_bits - 1 ) / align_bits ;
39
+ }
40
+
41
+ void common_hal_displayio_bitmap_construct (displayio_bitmap_t * self , uint32_t width ,
42
+ uint32_t height , uint32_t bits_per_value ) {
43
+ common_hal_displayio_bitmap_construct_from_buffer (self , width , height , bits_per_value , NULL , false);
44
+ }
45
+
46
+ void common_hal_displayio_bitmap_construct_from_buffer (displayio_bitmap_t * self , uint32_t width ,
47
+ uint32_t height , uint32_t bits_per_value , uint32_t * data , bool read_only ) {
43
48
self -> width = width ;
44
49
self -> height = height ;
45
- self -> data = m_malloc (self -> stride * height * sizeof (uint32_t ), false);
46
- self -> read_only = false;
50
+ self -> stride = stride (width , bits_per_value );
51
+ if (!data ) {
52
+ data = m_malloc (self -> stride * height * sizeof (uint32_t ), false);
53
+ }
54
+ self -> data = data ;
55
+ self -> read_only = read_only ;
47
56
self -> bits_per_value = bits_per_value ;
48
57
49
58
if (bits_per_value > 8 && bits_per_value != 16 && bits_per_value != 32 ) {
@@ -70,6 +79,7 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi
70
79
self -> dirty_area .y2 = height ;
71
80
}
72
81
82
+
73
83
uint16_t common_hal_displayio_bitmap_get_height (displayio_bitmap_t * self ) {
74
84
return self -> height ;
75
85
}
0 commit comments