Skip to content

Commit afae397

Browse files
committed
PR review fixups
1 parent 403ea89 commit afae397

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

shared-bindings/gifio/OnDiskGif.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,18 @@ STATIC mp_obj_t gifio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n_arg
126126
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
127127
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
128128

129-
mp_obj_t arg = all_args[0];
130-
if (mp_obj_is_str(arg)) {
131-
arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb));
129+
mp_obj_t filename = all_args[0];
130+
if (mp_obj_is_str(filename)) {
131+
filename = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), filename, MP_ROM_QSTR(MP_QSTR_rb));
132132
}
133133

134-
if (!mp_obj_is_type(arg, &mp_type_fileio)) {
134+
if (!mp_obj_is_type(filename, &mp_type_fileio)) {
135135
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
136136
}
137137

138138
gifio_ondiskgif_t *self = m_new_obj(gifio_ondiskgif_t);
139139
self->base.type = &gifio_ondiskgif_type;
140-
common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(arg), args[ARG_use_palette].u_bool);
140+
common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(filename), args[ARG_use_palette].u_bool);
141141

142142
return MP_OBJ_FROM_PTR(self);
143143
}
@@ -207,7 +207,7 @@ MP_PROPERTY_GETTER(gifio_ondiskgif_bitmap_obj,
207207
(mp_obj_t)&gifio_ondiskgif_get_bitmap_obj);
208208

209209
//| palette: displayio.Palette
210-
//| """The palette for the current frame."""
210+
//| """The palette for the current frame if it exists."""
211211
STATIC mp_obj_t gifio_ondiskgif_obj_get_palette(mp_obj_t self_in) {
212212
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
213213

shared-module/gifio/OnDiskGif.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ static void GIFDraw(GIFDRAW *pDraw) {
6868
// The palette is either RGB565 or the original 24-bit RGB values
6969
// depending on the pixel type selected with gif.begin()
7070

71-
gifio_ondiskgif_displayio_objs_t *displayio_objs = (gifio_ondiskgif_displayio_objs_t *)pDraw->pUser;
72-
displayio_bitmap_t *bitmap = displayio_objs->bitmap;
73-
displayio_palette_t *palette = displayio_objs->palette;
71+
gifio_ondiskgif_t *ondiskgif = (gifio_ondiskgif_t *)pDraw->pUser;
72+
displayio_bitmap_t *bitmap = ondiskgif->bitmap;
73+
displayio_palette_t *palette = ondiskgif->palette;
7474

7575
// Update the palette if we have one in RGB888
7676
if (palette != NULL) {
@@ -174,20 +174,19 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_
174174

175175
int bpp = 16;
176176
if (use_palette == true) {
177-
mp_printf(&mp_plat_print, "Using palette\n");
178177
displayio_palette_t *palette = m_new_obj(displayio_palette_t);
179178
palette->base.type = &displayio_palette_type;
180179
common_hal_displayio_palette_construct(palette, 256, false);
181-
self->displayio_objs.palette = palette;
180+
self->palette = palette;
182181
bpp = 8;
183182
} else {
184-
self->displayio_objs.palette = NULL;
183+
self->palette = NULL;
185184
}
186185

187186
displayio_bitmap_t *bitmap = m_new_obj(displayio_bitmap_t);
188187
bitmap->base.type = &displayio_bitmap_type;
189188
common_hal_displayio_bitmap_construct(bitmap, self->gif.iCanvasWidth, self->gif.iCanvasHeight, bpp);
190-
self->displayio_objs.bitmap = bitmap;
189+
self->bitmap = bitmap;
191190

192191
GIFINFO info;
193192
GIF_getInfo(&self->gif, &info);
@@ -199,13 +198,13 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_
199198

200199
void common_hal_gifio_ondiskgif_deinit(gifio_ondiskgif_t *self) {
201200
self->file = NULL;
202-
common_hal_displayio_bitmap_deinit(self->displayio_objs.bitmap);
203-
self->displayio_objs.bitmap = NULL;
204-
self->displayio_objs.palette = NULL;
201+
common_hal_displayio_bitmap_deinit(self->bitmap);
202+
self->bitmap = NULL;
203+
self->palette = NULL;
205204
}
206205

207206
bool common_hal_gifio_ondiskgif_deinited(gifio_ondiskgif_t *self) {
208-
return self->displayio_objs.bitmap == NULL;
207+
return self->bitmap == NULL;
209208
}
210209

211210
uint16_t common_hal_gifio_ondiskgif_get_height(gifio_ondiskgif_t *self) {
@@ -217,11 +216,14 @@ uint16_t common_hal_gifio_ondiskgif_get_width(gifio_ondiskgif_t *self) {
217216
}
218217

219218
mp_obj_t common_hal_gifio_ondiskgif_get_bitmap(gifio_ondiskgif_t *self) {
220-
return MP_OBJ_FROM_PTR(self->displayio_objs.bitmap);
219+
return MP_OBJ_FROM_PTR(self->bitmap);
221220
}
222221

223222
mp_obj_t common_hal_gifio_ondiskgif_get_palette(gifio_ondiskgif_t *self) {
224-
return MP_OBJ_FROM_PTR(self->displayio_objs.palette);
223+
if (self->palette == NULL) {
224+
return mp_const_none;
225+
}
226+
return MP_OBJ_FROM_PTR(self->palette);
225227
}
226228

227229
int32_t common_hal_gifio_ondiskgif_get_duration(gifio_ondiskgif_t *self) {
@@ -243,17 +245,17 @@ int32_t common_hal_gifio_ondiskgif_get_max_delay(gifio_ondiskgif_t *self) {
243245
uint32_t common_hal_gifio_ondiskgif_next_frame(gifio_ondiskgif_t *self, bool setDirty) {
244246
int nextDelay = 0;
245247
int result = 0;
246-
result = GIF_playFrame(&self->gif, &nextDelay, &self->displayio_objs);
248+
result = GIF_playFrame(&self->gif, &nextDelay, self);
247249

248250
if ((result >= 0) && (setDirty)) {
249251
displayio_area_t dirty_area = {
250252
.x1 = 0,
251253
.y1 = 0,
252-
.x2 = self->displayio_objs.bitmap->width,
253-
.y2 = self->displayio_objs.bitmap->height,
254+
.x2 = self->bitmap->width,
255+
.y2 = self->bitmap->height,
254256
};
255257

256-
displayio_bitmap_set_dirty_area(self->displayio_objs.bitmap, &dirty_area);
258+
displayio_bitmap_set_dirty_area(self->bitmap, &dirty_area);
257259
}
258260

259261
return nextDelay;

shared-module/gifio/OnDiskGif.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,12 @@
3838

3939
#include "extmod/vfs_fat.h"
4040

41-
typedef struct {
42-
displayio_bitmap_t *bitmap;
43-
displayio_palette_t *palette;
44-
} gifio_ondiskgif_displayio_objs_t;
45-
4641
typedef struct {
4742
mp_obj_base_t base;
4843
GIFIMAGE gif;
4944
pyb_file_obj_t *file;
50-
gifio_ondiskgif_displayio_objs_t displayio_objs;
45+
displayio_bitmap_t *bitmap;
46+
displayio_palette_t *palette;
5147
int32_t duration;
5248
int32_t frame_count;
5349
int32_t min_delay;

0 commit comments

Comments
 (0)