@@ -38,20 +38,20 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt
38
38
self -> width = width ;
39
39
if (self -> mirror_x ) {
40
40
width /= 2 ;
41
- width += self -> width % 2 - 1 ;
41
+ width += self -> width % 2 ;
42
42
}
43
43
self -> half_width = width ;
44
44
45
45
self -> height = height ;
46
46
if (self -> mirror_y ) {
47
47
height /= 2 ;
48
- height += self -> height % 2 - 1 ;
48
+ height += self -> height % 2 ;
49
49
}
50
50
self -> half_height = height ;
51
51
52
52
self -> data = m_malloc (height * sizeof (uint32_t ), false);
53
53
54
- for (uint16_t i = 0 ; i <= height ; i ++ ) {
54
+ for (uint16_t i = 0 ; i < height ; i ++ ) {
55
55
self -> data [2 * i ] = 0 ;
56
56
self -> data [2 * i + 1 ] = width ;
57
57
}
@@ -63,69 +63,63 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt
63
63
}
64
64
65
65
void common_hal_displayio_shape_set_boundary (displayio_shape_t * self , uint16_t y , uint16_t start_x , uint16_t end_x ) {
66
- if (y < 0 || y >= self -> height || (self -> mirror_y && y > self -> half_height )) {
66
+ if (y < 0 || y >= self -> height || (self -> mirror_y && y >= self -> half_height )) {
67
67
mp_raise_ValueError (translate ("y value out of bounds" ));
68
68
}
69
- if (start_x < 0 || start_x > self -> width || end_x < 0 || end_x > self -> width ) {
69
+ if (start_x < 0 || start_x >= self -> width || end_x < 0 || end_x >= self -> width ) {
70
70
mp_raise_ValueError (translate ("x value out of bounds" ));
71
71
}
72
- uint16_t half_width = self -> width / 2 - 1 + self -> width % 2 ;
73
- if (self -> mirror_x && (start_x > half_width || end_x > half_width )) {
74
- mp_raise_ValueError_varg (translate ("Maximum x value when mirrored is %d" ), half_width );
72
+ if (self -> mirror_x && (start_x >= self -> half_width || end_x >= self -> half_width )) {
73
+ mp_raise_ValueError_varg (translate ("Maximum x value when mirrored is %d" ), self -> half_width );
75
74
}
76
75
77
- uint16_t lower_x , upper_x ;
76
+ uint16_t lower_x , upper_x , lower_y , upper_y ;
78
77
79
- // find x-boundaries for updating based on current data and start_x, end_x
78
+ // find x-boundaries for updating based on current data and start_x, end_x, and mirror_x
80
79
lower_x = MIN (start_x , self -> data [2 * y ]);
81
80
82
81
if (self -> mirror_x ) {
83
- upper_x = self -> width - lower_x ;
82
+ upper_x = self -> width - lower_x + 1 ; // dirty rectangles are treated with max value exclusive
84
83
} else {
85
- upper_x = 1 + MAX (end_x , self -> data [2 * y + 1 ]);
84
+ upper_x = MAX (end_x , self -> data [2 * y + 1 ]) + 1 ; // dirty rectangles are treated with max value exclusive
86
85
}
87
86
88
- self -> data [2 * y ] = start_x ;
87
+ // find y-boundaries based on y and mirror_y
88
+ lower_y = y ;
89
+
90
+ if (self -> mirror_y ) {
91
+ upper_y = self -> height - lower_y + 1 ; // dirty rectangles are treated with max value exclusive
92
+ } else {
93
+ upper_y = y + 1 ; // dirty rectangles are treated with max value exclusive
94
+ }
95
+
96
+ self -> data [2 * y ] = start_x ; // update the data array with the new boundaries
89
97
self -> data [2 * y + 1 ] = end_x ;
90
98
91
99
if (self -> dirty_area .x1 == self -> dirty_area .x2 ) { // Dirty region is empty
92
- self -> dirty_area .x1 = lower_x ;
93
- self -> dirty_area .x2 = upper_x ;
94
- self -> dirty_area .y1 = y ;
95
- if (self -> mirror_y ) {
96
- self -> dirty_area .y2 = self -> height - y ;
97
- } else {
98
- self -> dirty_area .y2 = y + 1 ;
99
- }
100
- } else { // Dirty region is not empty
100
+ self -> dirty_area .x1 = lower_x ;
101
+ self -> dirty_area .x2 = upper_x ;
102
+ self -> dirty_area .y1 = lower_y ;
103
+ self -> dirty_area .y2 = upper_y ;
101
104
105
+ } else { // Dirty region is not empty
102
106
self -> dirty_area .x1 = MIN (lower_x , self -> dirty_area .x1 );
103
107
self -> dirty_area .x2 = MAX (upper_x , self -> dirty_area .x2 );
104
108
105
- if (y < self -> dirty_area .y1 ) {
106
- self -> dirty_area .y1 = y ;
107
- if (self -> mirror_y ) { // if y is mirrored and the lower y was updated, the upper y must be updated too
108
- self -> dirty_area .y2 = self -> height - y ;
109
- }
110
- }
111
- else {
112
- if ( !self -> mirror_y && (y >= self -> dirty_area .y2 ) ) { // y is not mirrored
113
- self -> dirty_area .y2 = y + 1 ;
114
- }
115
- }
109
+ self -> dirty_area .y1 = MIN (lower_y , self -> dirty_area .y1 );
110
+ self -> dirty_area .y2 = MAX (upper_y , self -> dirty_area .y2 );
116
111
}
117
-
118
112
}
119
113
120
114
uint32_t common_hal_displayio_shape_get_pixel (void * obj , int16_t x , int16_t y ) {
121
115
displayio_shape_t * self = obj ;
122
116
if (x >= self -> width || x < 0 || y >= self -> height || y < 0 ) {
123
117
return 0 ;
124
118
}
125
- if (self -> mirror_x && x > self -> half_width ) {
126
- x = self -> width - 1 - x ;
119
+ if (self -> mirror_x && x >= self -> half_width ) {
120
+ x = self -> width - x - 1 ;
127
121
}
128
- if (self -> mirror_y && y > self -> half_height ) {
122
+ if (self -> mirror_y && y >= self -> half_height ) {
129
123
y = self -> height - y - 1 ;
130
124
}
131
125
uint16_t start_x = self -> data [2 * y ];
0 commit comments