Skip to content

Commit c7c5d60

Browse files
authored
Merge pull request #8102 from dhalbert/OnDiskGif-width-and-doc
Improve OnDiskGif doc; check image width
2 parents 0da6241 + 1f2a1a6 commit c7c5d60

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

shared-bindings/gifio/OnDiskGif.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
//| `displayio` expects little-endian, so the example above uses `Colorspace.RGB565_SWAPPED`.
115115
//|
116116
//| :param file file: The name of the GIF file.
117+
//|
118+
//| If the image is too large it will be cropped at the bottom and right when displayed.
119+
//|
120+
//| **Limitations**: The image width is limited to 320 pixels at present. `ValueError`
121+
//| will be raised if the image is too wide. The height
122+
//| is not limited but images that are too large will cause a memory exception.
117123
//| """
118124
//| ...
119125
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) {

shared-module/gifio/OnDiskGif.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_
169169

170170
int result = GIF_init(&self->gif);
171171
if (result != 1) {
172-
mp_arg_error_invalid(MP_QSTR_file);
172+
switch (self->gif.iError) {
173+
case GIF_TOO_WIDE:
174+
mp_raise_ValueError_varg(translate("%q must be <= %d"), MP_QSTR_width, MAX_WIDTH);
175+
break;
176+
default:
177+
mp_arg_error_invalid(MP_QSTR_file);
178+
break;
179+
}
173180
}
174181

175182
int bpp = 16;

0 commit comments

Comments
 (0)