diff --git a/src/omv/img/bmp.c b/src/omv/img/bmp.c index 854e636f9..891014c0a 100644 --- a/src/omv/img/bmp.c +++ b/src/omv/img/bmp.c @@ -81,15 +81,13 @@ bool bmp_read_geometry(FIL *fp, image_t *img, const char *path, bmp_read_setting } // This function reads the pixel values of an image. -void bmp_read_pixels(FIL *fp, image_t *img, int line_start, int line_end, bmp_read_settings_t *rs) +void bmp_read_pixels(FIL *fp, image_t *img, int n_lines, bmp_read_settings_t *rs) { if (rs->bmp_bpp == 8) { if ((rs->bmp_h < 0) && (rs->bmp_w >= 0) && (img->w == rs->bmp_row_bytes)) { - read_data(fp, // Super Fast - Zoom, Zoom! - img->pixels + (line_start * img->w), - (line_end - line_start) * img->w); + read_data(fp, img->pixels, n_lines * img->w); } else { - for (int i = line_start; i < line_end; i++) { + for (int i = 0; i < n_lines; i++) { for (int j = 0; j < rs->bmp_row_bytes; j++) { uint8_t pixel; read_byte(fp, &pixel); @@ -112,7 +110,7 @@ void bmp_read_pixels(FIL *fp, image_t *img, int line_start, int line_end, bmp_re } } } else if (rs->bmp_bpp == 16) { - for (int i = line_start; i < line_end; i++) { + for (int i = 0; i < n_lines; i++) { for (int j = 0, jj = rs->bmp_row_bytes / 2; j < jj; j++) { uint16_t pixel; read_word(fp, &pixel); @@ -135,7 +133,7 @@ void bmp_read_pixels(FIL *fp, image_t *img, int line_start, int line_end, bmp_re } } } else if (rs->bmp_bpp == 24) { - for (int i = line_start; i < line_end; i++) { + for (int i = 0; i < n_lines; i++) { for (int j = 0, jj = rs->bmp_row_bytes / 3; j < jj; j++) { uint8_t r, g, b; read_byte(fp, &r); @@ -173,7 +171,7 @@ void bmp_read(image_t *img, const char *path) file_buffer_on(&fp); bmp_read_geometry(&fp, img, path, &rs); if (!img->pixels) img->pixels = xalloc(img->w * img->h * img->bpp); - bmp_read_pixels(&fp, img, 0, img->h, &rs); + bmp_read_pixels(&fp, img, img->h, &rs); file_buffer_off(&fp); file_close(&fp); } diff --git a/src/omv/img/imlib.c b/src/omv/img/imlib.c index bec71d29e..ac2a48522 100644 --- a/src/omv/img/imlib.c +++ b/src/omv/img/imlib.c @@ -559,14 +559,14 @@ bool imlib_read_geometry(FIL *fp, image_t *img, const char *path, img_read_setti return vflipped; } -static void imlib_read_pixels(FIL *fp, image_t *img, int line_start, int line_end, img_read_settings_t *rs) +static void imlib_read_pixels(FIL *fp, image_t *img, int n_lines, img_read_settings_t *rs) { switch (rs->format) { case FORMAT_BMP: - bmp_read_pixels(fp, img, line_start, line_end, &rs->bmp_rs); + bmp_read_pixels(fp, img, n_lines, &rs->bmp_rs); break; case FORMAT_PNM: - ppm_read_pixels(fp, img, line_start, line_end, &rs->ppm_rs); + ppm_read_pixels(fp, img, n_lines, &rs->ppm_rs); break; default: // won't happen break; @@ -603,7 +603,7 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s } for (int i=0; ih; i+=temp.h) { // goes past end int lines = IM_MIN(temp.h, img->h-i); - imlib_read_pixels(&fp, &temp, 0, lines, &rs); + imlib_read_pixels(&fp, &temp, lines, &rs); for (int j=0; jppm_fmt == '2') { - for (int i = line_start; i < line_end; i++) { + for (int i = 0; i < n_lines; i++) { for (int j = 0; j < img->w; j++) { uint32_t pixel; read_int(fp, &pixel, rs); @@ -80,7 +80,7 @@ void ppm_read_pixels(FIL *fp, image_t *img, int line_start, int line_end, ppm_re } } } else if (rs->ppm_fmt == '3') { - for (int i = line_start; i < line_end; i++) { + for (int i = 0; i < n_lines; i++) { for (int j = 0; j < img->w; j++) { uint32_t r, g, b; read_int(fp, &r, rs); @@ -92,11 +92,9 @@ void ppm_read_pixels(FIL *fp, image_t *img, int line_start, int line_end, ppm_re } } } else if (rs->ppm_fmt == '5') { - read_data(fp, // Super Fast - Zoom, Zoom! - img->pixels + (line_start * img->w), - (line_end - line_start) * img->w); + read_data(fp, img->pixels, n_lines * img->w); } else if (rs->ppm_fmt == '6') { - for (int i = line_start; i < line_end; i++) { + for (int i = 0; i < n_lines; i++) { for (int j = 0; j < img->w; j++) { uint8_t r, g, b; read_byte(fp, &r); @@ -118,7 +116,7 @@ void ppm_read(image_t *img, const char *path) file_buffer_on(&fp); ppm_read_geometry(&fp, img, path, &rs); if (!img->pixels) img->pixels = xalloc(img->w * img->h * img->bpp); - ppm_read_pixels(&fp, img, 0, img->h, &rs); + ppm_read_pixels(&fp, img, img->h, &rs); file_buffer_off(&fp); file_close(&fp); }