summaryrefslogtreecommitdiff
path: root/shared-module/_pixelbuf
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-01-27 15:10:32 -0800
committerScott Shawcroft <scott@tannewt.org>2020-01-27 15:10:32 -0800
commit5e789b38504846982a8cd7fa447297a51efc8352 (patch)
treeb4d9c412f23b9485f5d3d5b4c63c2ab48ccc41b4 /shared-module/_pixelbuf
parentf6a635b102259c6bc7d0f163881eac5b5e50a117 (diff)
Don't allocate the pre brightness buffer if brightness is 1.0 still
Diffstat (limited to 'shared-module/_pixelbuf')
-rw-r--r--shared-module/_pixelbuf/PixelBuf.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/shared-module/_pixelbuf/PixelBuf.c b/shared-module/_pixelbuf/PixelBuf.c
index ab5bcb441..bad8539ea 100644
--- a/shared-module/_pixelbuf/PixelBuf.c
+++ b/shared-module/_pixelbuf/PixelBuf.c
@@ -68,6 +68,7 @@ void common_hal__pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *self, size
}
}
// Call set_brightness so that it can allocate a second buffer if needed.
+ self->brightness = 1.0;
common_hal__pixelbuf_pixelbuf_set_brightness(MP_OBJ_FROM_PTR(self), brightness);
// 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) {
void common_hal__pixelbuf_pixelbuf_set_brightness(mp_obj_t self_in, mp_float_t brightness) {
pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ // Skip out if the brightness is already set. The default of self->brightness is 1.0. So, this
+ // also prevents the pre_brightness_buffer allocation when brightness is set to 1.0 again.
+ mp_float_t change = brightness - self->brightness;
+ if (-0.001 < change && change < 0.001) {
+ return;
+ }
self->brightness = brightness;
size_t pixel_len = self->pixel_count * self->bytes_per_pixel;
if (self->pre_brightness_buffer == NULL) {