From 1f2a1a6e78f1a8d5b38a0cebad0f668217e3e93c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 22 Jun 2023 14:24:48 -0400 Subject: [PATCH] Improve OnDiskGif doc; check image width --- shared-bindings/gifio/OnDiskGif.c | 6 ++++++ shared-module/gifio/OnDiskGif.c | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/shared-bindings/gifio/OnDiskGif.c b/shared-bindings/gifio/OnDiskGif.c index e4335f9e44..8a7bba3a7f 100644 --- a/shared-bindings/gifio/OnDiskGif.c +++ b/shared-bindings/gifio/OnDiskGif.c @@ -114,6 +114,12 @@ //| `displayio` expects little-endian, so the example above uses `Colorspace.RGB565_SWAPPED`. //| //| :param file file: The name of the GIF file. +//| +//| If the image is too large it will be cropped at the bottom and right when displayed. +//| +//| **Limitations**: The image width is limited to 320 pixels at present. `ValueError` +//| will be raised if the image is too wide. The height +//| is not limited but images that are too large will cause a memory exception. //| """ //| ... STATIC mp_obj_t gifio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { diff --git a/shared-module/gifio/OnDiskGif.c b/shared-module/gifio/OnDiskGif.c index c1e6d1f2c2..039e77cf45 100644 --- a/shared-module/gifio/OnDiskGif.c +++ b/shared-module/gifio/OnDiskGif.c @@ -169,7 +169,14 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_ int result = GIF_init(&self->gif); if (result != 1) { - mp_arg_error_invalid(MP_QSTR_file); + switch (self->gif.iError) { + case GIF_TOO_WIDE: + mp_raise_ValueError_varg(translate("%q must be <= %d"), MP_QSTR_width, MAX_WIDTH); + break; + default: + mp_arg_error_invalid(MP_QSTR_file); + break; + } } int bpp = 16;