Simplify pixelbuf set_pixels function

This commit is contained in:
George Waters 2020-05-22 21:19:17 -04:00
parent f078055f59
commit c592a2b4db
No known key found for this signature in database
GPG Key ID: D993F8B1CC21DB25
3 changed files with 6 additions and 14 deletions

View File

@ -340,7 +340,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp
slice_len, num_items);
}
common_hal__pixelbuf_pixelbuf_set_pixels(self_in, slice.start, slice.stop, slice.step, src_objs);
common_hal__pixelbuf_pixelbuf_set_pixels(self_in, slice.start, slice.step, slice_len, src_objs);
return mp_const_none;
#else
return MP_OBJ_NULL; // op not supported

View File

@ -47,6 +47,6 @@ void common_hal__pixelbuf_pixelbuf_fill(mp_obj_t self, mp_obj_t item);
void common_hal__pixelbuf_pixelbuf_show(mp_obj_t self);
mp_obj_t common_hal__pixelbuf_pixelbuf_get_pixel(mp_obj_t self, size_t index);
void common_hal__pixelbuf_pixelbuf_set_pixel(mp_obj_t self, size_t index, mp_obj_t item);
void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, mp_int_t start, mp_int_t stop, mp_int_t step, mp_obj_t* values);
void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t* values);
#endif // CP_SHARED_BINDINGS_PIXELBUF_PIXELBUF_H

View File

@ -216,19 +216,11 @@ void _pixelbuf_set_pixel(pixelbuf_pixelbuf_obj_t* self, size_t index, mp_obj_t v
_pixelbuf_set_pixel_color(self, index, r, g, b, w);
}
void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, mp_int_t start, mp_int_t stop, mp_int_t step, mp_obj_t* values) {
void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t* values) {
pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
size_t source_i = 0;
if (step > 0) {
for (mp_int_t target_i = start; target_i < stop; target_i += step) {
_pixelbuf_set_pixel(self, target_i, values[source_i]);
source_i++;
}
} else {
for (mp_int_t target_i = start; target_i >= stop; target_i += step) {
_pixelbuf_set_pixel(self, target_i, values[source_i]);
source_i++;
}
for (size_t i = 0; i < slice_len; i++) {
_pixelbuf_set_pixel(self, start, values[i]);
start+=step;
}
if (self->auto_write) {
common_hal__pixelbuf_pixelbuf_show(self_in);