diff --git a/src/omv/img/imlib.c b/src/omv/img/imlib.c index 0331a910f..bec71d29e 100644 --- a/src/omv/img/imlib.c +++ b/src/omv/img/imlib.c @@ -594,20 +594,21 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s // window is equal to an image in size. However, since this is not the // case we shrink the window size to how many lines we're buffering. temp.pixels = alloc; - temp.h = (size / (temp.w * temp.bpp)); // round down + // Set the max buffer height to image height. + temp.h = IM_MIN(img->h, (size / (temp.w * temp.bpp))); // This should never happen unless someone forgot to free. if ((!temp.pixels) || (!temp.h)) { nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "Not enough memory available!")); } for (int i=0; ih; i+=temp.h) { // goes past end - int can_do = IM_MIN(temp.h, img->h-i); - imlib_read_pixels(&fp, &temp, 0, can_do, &rs); - for (int j=0; jh-i); + imlib_read_pixels(&fp, &temp, 0, lines, &rs); + for (int j=0; jh-i-can_do)+j, temp.pixels+(temp.w*temp.bpp*j), data, true); + op(img, (img->h-i-lines)+j, temp.pixels+(temp.w*temp.bpp*j), data, true); } } }