Skip to content

Commit 6074756

Browse files
committed
pybricks.common.LightMatrix: fix out of bound matrix scalar
Without this, large floating point values yield a non-maximum brightness, which is confuting.
1 parent 262a54d commit 6074756

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pybricks/common/pb_type_lightmatrix.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ static void common_Lightmatrix_image__extract(mp_obj_t image_in, size_t size, ui
7979
if (mp_obj_is_type(image_in, &pb_type_Matrix)) {
8080
for (size_t r = 0; r < size; r++) {
8181
for (size_t c = 0; c < size; c++) {
82-
data[r * size + c] = (uint8_t)pb_type_Matrix_get_scalar(image_in, r, c);
82+
float scalar = pb_type_Matrix_get_scalar(image_in, r, c);
83+
scalar = scalar > 100 ? 100 : (scalar < 0 ? 0: scalar);
84+
data[r * size + c] = (uint8_t)scalar;
8385
}
8486
}
8587
return;

0 commit comments

Comments
 (0)