summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorGeorge Waters <gwatersdev@gmail.com>2020-05-21 21:57:45 -0400
committerGeorge Waters <gwatersdev@gmail.com>2020-05-21 21:57:45 -0400
commit16ffc731f3c64b36a486a27d87b10742cf5bb4ba (patch)
treeb20a60a00ec230c74a99b923f4b86b4329138751 /shared-module
parenteea01c32b8c7727989774f0bb08a5efafc45911e (diff)
Implement negative step for pixelbuf slices
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/_pixelbuf/PixelBuf.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/shared-module/_pixelbuf/PixelBuf.c b/shared-module/_pixelbuf/PixelBuf.c
index 31350b875..c32544483 100644
--- a/shared-module/_pixelbuf/PixelBuf.c
+++ b/shared-module/_pixelbuf/PixelBuf.c
@@ -216,12 +216,19 @@ 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, size_t start, size_t stop, size_t step, mp_obj_t* values) {
+void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, size_t stop, mp_int_t step, mp_obj_t* values) {
pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
size_t source_i = 0;
- for (size_t target_i = start; target_i < stop; target_i += step) {
- _pixelbuf_set_pixel(self, target_i, values[source_i]);
- source_i++;
+ if (step > 0) {
+ for (size_t target_i = start; target_i < stop; target_i += step) {
+ _pixelbuf_set_pixel(self, target_i, values[source_i]);
+ source_i++;
+ }
+ }else{
+ for (size_t target_i = start; target_i >= stop; target_i += step) {
+ _pixelbuf_set_pixel(self, target_i, values[source_i]);
+ source_i++;
+ }
}
if (self->auto_write) {
common_hal__pixelbuf_pixelbuf_show(self_in);