summaryrefslogtreecommitdiff
path: root/shared-bindings/_pixelbuf
diff options
context:
space:
mode:
authorRoy Hooper <rhooper@toybox.ca>2019-08-03 13:35:11 -0400
committerRoy Hooper <rhooper@toybox.ca>2019-08-03 13:35:11 -0400
commit5c08182c731a0f341b6ee61b2433f91063552464 (patch)
treed0bc0fd95ef64055e1a4936401eed581c805faac /shared-bindings/_pixelbuf
parentcff9c9bc950a3d374babfb3c7388f179c3577e51 (diff)
fix fix the byte order property.
Diffstat (limited to 'shared-bindings/_pixelbuf')
-rw-r--r--shared-bindings/_pixelbuf/PixelBuf.c16
-rw-r--r--shared-bindings/_pixelbuf/types.h1
2 files changed, 11 insertions, 6 deletions
diff --git a/shared-bindings/_pixelbuf/PixelBuf.c b/shared-bindings/_pixelbuf/PixelBuf.c
index f4f6c83b2..90210d4f3 100644
--- a/shared-bindings/_pixelbuf/PixelBuf.c
+++ b/shared-bindings/_pixelbuf/PixelBuf.c
@@ -101,7 +101,11 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
else
byteorder = mp_obj_str_get_data(args[ARG_byteorder].u_obj, &bo_len);
- byteorder_details.bpp = strlen(byteorder);
+ if (bo_len < 3 || bo_len > 4)
+ mp_raise_ValueError(translate("Invalid byteorder string"));
+ strncpy(byteorder_details.order, byteorder, sizeof(byteorder_details.order));
+
+ byteorder_details.bpp = bo_len;
char *dotstar = strchr(byteorder, 'D');
char *r = strchr(byteorder, 'R');
char *g = strchr(byteorder, 'G');
@@ -344,13 +348,13 @@ const mp_obj_property_t pixelbuf_pixelbuf_buf_obj = {
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_byteorder(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_TYPE(self_in, &pixelbuf_pixelbuf_type));
pixelbuf_pixelbuf_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return &self->byteorder;
+ return mp_obj_new_str(self->byteorder.order, strlen(self->byteorder.order));
}
-MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_get_byteorder_obj, pixelbuf_pixelbuf_obj_get_byteorder);
+MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_get_byteorder_str, pixelbuf_pixelbuf_obj_get_byteorder);
-const mp_obj_property_t pixelbuf_pixelbuf_byteorder_obj = {
+const mp_obj_property_t pixelbuf_pixelbuf_byteorder_str = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&pixelbuf_pixelbuf_get_byteorder_obj,
+ .proxy = {(mp_obj_t)&pixelbuf_pixelbuf_get_byteorder_str,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
@@ -479,7 +483,7 @@ STATIC const mp_rom_map_elem_t pixelbuf_pixelbuf_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_bpp), MP_ROM_PTR(&pixelbuf_pixelbuf_bpp_obj)},
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&pixelbuf_pixelbuf_brightness_obj)},
{ MP_ROM_QSTR(MP_QSTR_buf), MP_ROM_PTR(&pixelbuf_pixelbuf_buf_obj)},
- { MP_ROM_QSTR(MP_QSTR_byteorder), MP_ROM_PTR(&pixelbuf_pixelbuf_byteorder_obj)},
+ { MP_ROM_QSTR(MP_QSTR_byteorder), MP_ROM_PTR(&pixelbuf_pixelbuf_byteorder_str)},
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&pixelbuf_pixelbuf_show_obj)},
};
diff --git a/shared-bindings/_pixelbuf/types.h b/shared-bindings/_pixelbuf/types.h
index 7d772dbf5..39e49935f 100644
--- a/shared-bindings/_pixelbuf/types.h
+++ b/shared-bindings/_pixelbuf/types.h
@@ -41,6 +41,7 @@ typedef struct {
pixelbuf_rgbw_t byteorder;
bool has_white;
bool is_dotstar;
+ char order[5];
} pixelbuf_byteorder_details_t;
#endif // CIRCUITPYTHON_PIXELBUF_TYPES_H