@@ -303,7 +303,8 @@ STATIC mp_obj_t microbit_image_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_u
303
303
mp_int_t i = 0 ;
304
304
for (mp_int_t y = 0 ; y < h; y++) {
305
305
for (mp_int_t x = 0 ; x < w; ++x) {
306
- image->setPixelValue (x,y, ((const uint8_t *)bufinfo.buf )[i]);
306
+ uint8_t val = min (((const uint8_t *)bufinfo.buf )[i], MAX_BRIGHTNESS);
307
+ image->setPixelValue (x, y, val);
307
308
++i;
308
309
}
309
310
}
@@ -649,11 +650,13 @@ STATIC mp_obj_t microbit_image_slice_iter_next(mp_obj_t o_in) {
649
650
image_slice_iterator_t *iter = (image_slice_iterator_t *)o_in;
650
651
mp_obj_t result;
651
652
microbit_image_obj_t *img = iter->slice ->img ;
652
- if (iter->next_start <= img->width ()-iter->slice ->width ) {
653
- result = image_crop (img, iter->next_start , 0 , iter->next_start + iter->slice ->width , img->height ());
654
- } else {
655
- result = MP_OBJ_STOP_ITERATION;
653
+ if (iter->slice ->stride > 0 && iter->next_start >= img->width ()) {
654
+ return MP_OBJ_STOP_ITERATION;
655
+ }
656
+ if (iter->slice ->stride < 0 && iter->next_start <= -iter->slice ->width ) {
657
+ return MP_OBJ_STOP_ITERATION;
656
658
}
659
+ result = image_crop (img, iter->next_start , 0 , iter->slice ->width , img->height ());
657
660
iter->next_start += iter->slice ->stride ;
658
661
return result;
659
662
}
0 commit comments