Skip to content

Commit 20c9f25

Browse files
committed
rgbmatrix: Eliminate some duplicated height-calculating code
This was hard to write, so let's have it written in 2 places instead of 4.
1 parent 368977f commit 20c9f25

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
219219
translate("tile must be greater than or equal to zero"));
220220
}
221221

222+
int computed_height = (rgb_count / 3) * (1 << (addr_count)) * tile;
222223
if (args[ARG_height].u_int != 0) {
223-
int computed_height = (rgb_count / 3) * (1 << (addr_count)) * tile;
224224
if (computed_height != args[ARG_height].u_int) {
225225
mp_raise_ValueError_varg(
226226
translate("%d address pins, %d rgb pins and %d tiles indicate a height of %d, not %d"), addr_count, rgb_count, tile, computed_height, args[ARG_height].u_int);
@@ -236,7 +236,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
236236
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
237237
if (framebuffer == mp_const_none) {
238238
int width = args[ARG_width].u_int;
239-
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count) * tile;
239+
int bufsize = 2 * width * computed_height;
240240
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
241241
}
242242

shared-module/rgbmatrix/RGBMatrix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
6262
}
6363

6464
self->width = width;
65-
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count) * tile;
65+
self->bufsize = 2 * width * common_hal_rgbmatrix_rgbmatrix_get_height(self);
6666

6767
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
6868
}

0 commit comments

Comments
 (0)