File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ void common_hal__pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *self, size
68
68
}
69
69
}
70
70
// Call set_brightness so that it can allocate a second buffer if needed.
71
+ self -> brightness = 1.0 ;
71
72
common_hal__pixelbuf_pixelbuf_set_brightness (MP_OBJ_FROM_PTR (self ), brightness );
72
73
73
74
// Turn on auto_write. We don't want to do it with the above brightness call.
@@ -106,6 +107,12 @@ mp_float_t common_hal__pixelbuf_pixelbuf_get_brightness(mp_obj_t self_in) {
106
107
107
108
void common_hal__pixelbuf_pixelbuf_set_brightness (mp_obj_t self_in , mp_float_t brightness ) {
108
109
pixelbuf_pixelbuf_obj_t * self = native_pixelbuf (self_in );
110
+ // Skip out if the brightness is already set. The default of self->brightness is 1.0. So, this
111
+ // also prevents the pre_brightness_buffer allocation when brightness is set to 1.0 again.
112
+ mp_float_t change = brightness - self -> brightness ;
113
+ if (-0.001 < change && change < 0.001 ) {
114
+ return ;
115
+ }
109
116
self -> brightness = brightness ;
110
117
size_t pixel_len = self -> pixel_count * self -> bytes_per_pixel ;
111
118
if (self -> pre_brightness_buffer == NULL ) {
You can’t perform that action at this time.
0 commit comments