Skip to content

Commit a62a1ae

Browse files
committed
WIP: refactor _pixelbuf to use strings instead of classes
1 parent db84445 commit a62a1ae

4 files changed

Lines changed: 8 additions & 43 deletions

File tree

shared-bindings/_pixelbuf/PixelBuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
extern const int32_t colorwheel(float pos);
4444

45-
int parse_byteorder_string(const char *byteorder, pixelbuf_byteorder_details_t details) {
45+
void parse_byteorder_string(const char *byteorder, pixelbuf_byteorder_details_t details) {
4646
details.bpp = strlen(byteorder);
4747
char *dotstar = strchr(byteorder, 'D');
4848
char *r = strchr(byteorder, 'R');

shared-bindings/_pixelbuf/__init__.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,41 +56,6 @@
5656
//| PixelBuf
5757

5858

59-
STATIC void pixelbuf_byteorder_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
60-
mp_check_self(MP_OBJ_IS_TYPE(self_in, &pixelbuf_byteorder_type));
61-
pixelbuf_byteorder_obj_t *self = MP_OBJ_TO_PTR(self_in);
62-
if (dest[0] == MP_OBJ_NULL) {
63-
// load attribute
64-
mp_obj_t val;
65-
if (attr == MP_QSTR_bpp) {
66-
val = MP_OBJ_NEW_SMALL_INT(self->bpp);
67-
} else if (attr == MP_QSTR_has_white) {
68-
val = mp_obj_new_bool(self->has_white);
69-
} else if (attr == MP_QSTR_has_luminosity) {
70-
val = mp_obj_new_bool(self->has_luminosity);
71-
} else if (attr == MP_QSTR_byteorder) {
72-
mp_obj_t items[4];
73-
uint8_t n = self->bpp;
74-
if (self->has_luminosity || self->has_white) {
75-
n = 4;
76-
}
77-
uint8_t *values = (uint8_t *)&(self->byteorder);
78-
for (uint8_t i=0; i<n; i++) {
79-
items[i] = MP_OBJ_NEW_SMALL_INT(values[i]);
80-
}
81-
val = mp_obj_new_tuple(n, items);
82-
} else {
83-
mp_raise_AttributeError(translate("no such attribute"));
84-
}
85-
dest[0] = val;
86-
} else {
87-
// delete/store attribute (ignored)
88-
dest[0] = MP_OBJ_NULL;
89-
mp_raise_AttributeError(translate("readonly attribute"));
90-
}
91-
}
92-
93-
9459
//| .. function:: wheel(n)
9560
//|
9661
//| C implementation of the common wheel() function found in many examples.

shared-module/_pixelbuf/PixelBuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "PixelBuf.h"
3232
#include <string.h>
3333

34-
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_obj_t *byteorder) {
34+
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_details_t *byteorder) {
3535
buf[byteorder->byteorder.r] = value >> 16 & 0xff;
3636
buf[byteorder->byteorder.g] = (value >> 8) & 0xff;
3737
buf[byteorder->byteorder.b] = value & 0xff;
@@ -43,7 +43,7 @@ void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_obj
4343
}
4444
}
4545

46-
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_obj_t *byteorder, bool dotstar) {
46+
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_details_t *byteorder, bool dotstar) {
4747
if (MP_OBJ_IS_INT(item)) {
4848
uint8_t *target = rawbuf ? rawbuf : buf;
4949
pixelbuf_set_pixel_int(target, mp_obj_get_int_truncated(item), byteorder);
@@ -94,7 +94,7 @@ void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_
9494
}
9595
}
9696

97-
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_obj_t *byteorder, uint8_t step, bool dotstar) {
97+
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_details_t *byteorder, uint8_t step, bool dotstar) {
9898
mp_obj_t elems[len];
9999
for (uint i = 0; i < len; i++) {
100100
elems[i] = pixelbuf_get_pixel(buf + (i * step), byteorder, dotstar);

shared-module/_pixelbuf/PixelBuf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
#define DOTSTAR_GET_BRIGHTNESS(value) ((value & 0b00011111) / 31.0)
4343
#define DOTSTAR_LED_START_FULL_BRIGHT 0xFF
4444

45-
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_obj_t *byteorder, bool dotstar);
46-
mp_obj_t *pixelbuf_get_pixel(uint8_t *buf, pixelbuf_byteorder_obj_t *byteorder, bool dotstar);
47-
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_obj_t *byteorder, uint8_t step, bool dotstar);
48-
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_obj_t *byteorder);
45+
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_details_t *byteorder, bool dotstar);
46+
mp_obj_t *pixelbuf_get_pixel(uint8_t *buf, pixelbuf_byteorder_details_t *byteorder, bool dotstar);
47+
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_details_t *byteorder, uint8_t step, bool dotstar);
48+
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_details_t *byteorder);
4949

5050
#endif

0 commit comments

Comments
 (0)