WIP: refactor _pixelbuf to use strings instead of classes
This commit is contained in:
parent
db84445a62
commit
a62a1ae2bd
|
@ -42,7 +42,7 @@
|
|||
|
||||
extern const int32_t colorwheel(float pos);
|
||||
|
||||
int parse_byteorder_string(const char *byteorder, pixelbuf_byteorder_details_t details) {
|
||||
void parse_byteorder_string(const char *byteorder, pixelbuf_byteorder_details_t details) {
|
||||
details.bpp = strlen(byteorder);
|
||||
char *dotstar = strchr(byteorder, 'D');
|
||||
char *r = strchr(byteorder, 'R');
|
||||
|
|
|
@ -56,41 +56,6 @@
|
|||
//| PixelBuf
|
||||
|
||||
|
||||
STATIC void pixelbuf_byteorder_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &pixelbuf_byteorder_type));
|
||||
pixelbuf_byteorder_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (dest[0] == MP_OBJ_NULL) {
|
||||
// load attribute
|
||||
mp_obj_t val;
|
||||
if (attr == MP_QSTR_bpp) {
|
||||
val = MP_OBJ_NEW_SMALL_INT(self->bpp);
|
||||
} else if (attr == MP_QSTR_has_white) {
|
||||
val = mp_obj_new_bool(self->has_white);
|
||||
} else if (attr == MP_QSTR_has_luminosity) {
|
||||
val = mp_obj_new_bool(self->has_luminosity);
|
||||
} else if (attr == MP_QSTR_byteorder) {
|
||||
mp_obj_t items[4];
|
||||
uint8_t n = self->bpp;
|
||||
if (self->has_luminosity || self->has_white) {
|
||||
n = 4;
|
||||
}
|
||||
uint8_t *values = (uint8_t *)&(self->byteorder);
|
||||
for (uint8_t i=0; i<n; i++) {
|
||||
items[i] = MP_OBJ_NEW_SMALL_INT(values[i]);
|
||||
}
|
||||
val = mp_obj_new_tuple(n, items);
|
||||
} else {
|
||||
mp_raise_AttributeError(translate("no such attribute"));
|
||||
}
|
||||
dest[0] = val;
|
||||
} else {
|
||||
// delete/store attribute (ignored)
|
||||
dest[0] = MP_OBJ_NULL;
|
||||
mp_raise_AttributeError(translate("readonly attribute"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//| .. function:: wheel(n)
|
||||
//|
|
||||
//| C implementation of the common wheel() function found in many examples.
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "PixelBuf.h"
|
||||
#include <string.h>
|
||||
|
||||
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_obj_t *byteorder) {
|
||||
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_details_t *byteorder) {
|
||||
buf[byteorder->byteorder.r] = value >> 16 & 0xff;
|
||||
buf[byteorder->byteorder.g] = (value >> 8) & 0xff;
|
||||
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
|
|||
}
|
||||
}
|
||||
|
||||
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_obj_t *byteorder, bool dotstar) {
|
||||
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_details_t *byteorder, bool dotstar) {
|
||||
if (MP_OBJ_IS_INT(item)) {
|
||||
uint8_t *target = rawbuf ? rawbuf : buf;
|
||||
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_
|
|||
}
|
||||
}
|
||||
|
||||
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_obj_t *byteorder, uint8_t step, bool dotstar) {
|
||||
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_details_t *byteorder, uint8_t step, bool dotstar) {
|
||||
mp_obj_t elems[len];
|
||||
for (uint i = 0; i < len; i++) {
|
||||
elems[i] = pixelbuf_get_pixel(buf + (i * step), byteorder, dotstar);
|
||||
|
|
|
@ -42,9 +42,9 @@
|
|||
#define DOTSTAR_GET_BRIGHTNESS(value) ((value & 0b00011111) / 31.0)
|
||||
#define DOTSTAR_LED_START_FULL_BRIGHT 0xFF
|
||||
|
||||
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_obj_t *byteorder, bool dotstar);
|
||||
mp_obj_t *pixelbuf_get_pixel(uint8_t *buf, pixelbuf_byteorder_obj_t *byteorder, bool dotstar);
|
||||
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_obj_t *byteorder, uint8_t step, bool dotstar);
|
||||
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_obj_t *byteorder);
|
||||
void pixelbuf_set_pixel(uint8_t *buf, uint8_t *rawbuf, float brightness, mp_obj_t *item, pixelbuf_byteorder_details_t *byteorder, bool dotstar);
|
||||
mp_obj_t *pixelbuf_get_pixel(uint8_t *buf, pixelbuf_byteorder_details_t *byteorder, bool dotstar);
|
||||
mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_details_t *byteorder, uint8_t step, bool dotstar);
|
||||
void pixelbuf_set_pixel_int(uint8_t *buf, mp_int_t value, pixelbuf_byteorder_details_t *byteorder);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue