From 165408f3c8e5f89f38fa0346e723ed21be555cd7 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Tue, 28 Dec 2021 19:04:38 -0800 Subject: [PATCH] Fix jpeg loading --- src/omv/imlib/imlib.c | 6 +++++- src/omv/imlib/jpeg.c | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/omv/imlib/imlib.c b/src/omv/imlib/imlib.c index 597e2f054..f3dcdb204 100644 --- a/src/omv/imlib/imlib.c +++ b/src/omv/imlib/imlib.c @@ -564,10 +564,14 @@ bool imlib_read_geometry(FIL *fp, image_t *img, const char *path, img_read_setti file_read_open(fp, path); file_buffer_on(fp); // REMEMBER TO TURN THIS OFF LATER! vflipped = bmp_read_geometry(fp, img, path, &rs->bmp_rs); - } else { + } else if ((magic[0]==0xFF) && (magic[1]==0xD8)) { // JPG rs->format = FORMAT_JPG; file_read_open(fp, path); + // Do not use file_buffer_on() here. jpeg_read_geometry(fp, img, path, &rs->jpg_rs); + file_buffer_on(fp); // REMEMBER TO TURN THIS OFF LATER! + } else { + ff_unsupported_format(NULL); } imblib_parse_extension(img, path); // Enforce extension! return vflipped; diff --git a/src/omv/imlib/jpeg.c b/src/omv/imlib/jpeg.c index 14518afe2..77327e560 100644 --- a/src/omv/imlib/jpeg.c +++ b/src/omv/imlib/jpeg.c @@ -2100,14 +2100,14 @@ void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settin || ((0xFFCD <= header) && (header <= 0xFFCF))) { read_byte_ignore(fp); - uint16_t width; - read_word(fp, &width); - width = __REV16(width); - uint16_t height; read_word(fp, &height); height = __REV16(height); + uint16_t width; + read_word(fp, &width); + width = __REV16(width); + rs->jpg_w = width; rs->jpg_h = height; rs->jpg_size = IMLIB_IMAGE_MAX_SIZE(f_size(fp));