Skip to content

Commit 31e4591

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

3 files changed

Lines changed: 3 additions & 123 deletions

File tree

shared-bindings/_pixelbuf/PixelBuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
133133
if (args[ARG_byteorder].u_obj == NULL)
134134
byteorder_str = "BGR";
135135
else
136-
byteorder_str = mp_obj_str_get_data(byteorder_str, bo_len);
136+
byteorder_str = mp_obj_str_get_data(args[ARG_byteorder].u_obj, &bo_len);
137137

138138
parse_byteorder_string(byteorder_str, byteorder_details);
139139

shared-bindings/_pixelbuf/__init__.c

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -82,126 +82,6 @@ const int32_t colorwheel(float pos) {
8282
}
8383
}
8484

85-
86-
/// RGB
87-
//| .. data:: RGB
88-
//|
89-
//| * **order** Red, Green, Blue
90-
//| * **bpp** 3
91-
PIXELBUF_BYTEORDER(RGB, 3, 0, 1, 2, 3, false, false)
92-
//| .. data:: RBG
93-
//|
94-
//| * **order** Red, Blue, Green
95-
//| * **bpp** 3
96-
PIXELBUF_BYTEORDER(RBG, 3, 0, 2, 1, 3, false, false)
97-
//| .. data:: GRB
98-
//|
99-
//| * **order** Green, Red, Blue
100-
//| * **bpp** 3
101-
//|
102-
//| Commonly used by NeoPixel.
103-
PIXELBUF_BYTEORDER(GRB, 3, 1, 0, 2, 3, false, false)
104-
//| .. data:: GBR
105-
//|
106-
//| * **order** Green, Blue, Red
107-
//| * **bpp** 3
108-
PIXELBUF_BYTEORDER(GBR, 3, 1, 2, 0, 3, false, false)
109-
//| .. data:: BRG
110-
//|
111-
//| * **order** Blue, Red, Green
112-
//| * **bpp** 3
113-
PIXELBUF_BYTEORDER(BRG, 3, 2, 0, 1, 3, false, false)
114-
//| .. data:: BGR
115-
//|
116-
//| * **order** Blue, Green, Red
117-
//| * **bpp** 3
118-
//|
119-
//| Commonly used by Dotstar.
120-
PIXELBUF_BYTEORDER(BGR, 3, 2, 1, 0, 3, false, false)
121-
122-
// RGBW
123-
//| .. data:: RGBW
124-
//|
125-
//| * **order** Red, Green, Blue, White
126-
//| * **bpp** 4
127-
//| * **has_white** True
128-
PIXELBUF_BYTEORDER(RGBW, 4, 0, 1, 2, 3, true, false)
129-
//| .. data:: RBGW
130-
//|
131-
//| * **order** Red, Blue, Green, White
132-
//| * **bpp** 4
133-
//| * **has_white** True
134-
PIXELBUF_BYTEORDER(RBGW, 4, 0, 2, 1, 3, true, false)
135-
//| .. data:: GRBW
136-
//|
137-
//| * **order** Green, Red, Blue, White
138-
//| * **bpp** 4
139-
//| * **has_white** True
140-
//|
141-
//| Commonly used by RGBW NeoPixels.
142-
PIXELBUF_BYTEORDER(GRBW, 4, 1, 0, 2, 3, true, false)
143-
//| .. data:: GBRW
144-
//|
145-
//| * **order** Green, Blue, Red, White
146-
//| * **bpp** 4
147-
//| * **has_white** True
148-
PIXELBUF_BYTEORDER(GBRW, 4, 1, 2, 0, 3, true, false)
149-
//| .. data:: BRGW
150-
//|
151-
//| * **order** Blue, Red, Green, White
152-
//| * **bpp** 4
153-
//| * **has_white** True
154-
PIXELBUF_BYTEORDER(BRGW, 4, 2, 0, 1, 3, true, false)
155-
//| .. data:: BGRW
156-
//|
157-
//| * **order** Blue, Green, Red, White
158-
//| * **bpp** 4
159-
//| * **has_white** True
160-
PIXELBUF_BYTEORDER(BGRW, 4, 2, 1, 0, 3, true, false)
161-
162-
// Luminosity + RGB (eg for Dotstar)
163-
// Luminosity chosen because the luminosity of a Dotstar at full bright
164-
// burns the eyes like looking at the Sun.
165-
// https://www.thesaurus.com/browse/luminosity?s=t
166-
//| .. data:: LRGB
167-
//|
168-
//| * **order** *Luminosity*, Red, Green, Blue
169-
//| * **bpp** 4
170-
//| * **has_luminosity** True
171-
PIXELBUF_BYTEORDER(LRGB, 4, 1, 2, 3, 0, false, true)
172-
//| .. data:: LRBG
173-
//|
174-
//| * **order** *Luminosity*, Red, Blue, Green
175-
//| * **bpp** 4
176-
//| * **has_luminosity** True
177-
PIXELBUF_BYTEORDER(LRBG, 4, 1, 3, 2, 0, false, true)
178-
//| .. data:: LGRB
179-
//|
180-
//| * **order** *Luminosity*, Green, Red, Blue
181-
//| * **bpp** 4
182-
//| * **has_luminosity** True
183-
PIXELBUF_BYTEORDER(LGRB, 4, 2, 1, 3, 0, false, true)
184-
//| .. data:: LGBR
185-
//|
186-
//| * **order** *Luminosity*, Green, Blue, Red
187-
//| * **bpp** 4
188-
//| * **has_luminosity** True
189-
PIXELBUF_BYTEORDER(LGBR, 4, 2, 3, 1, 0, false, true)
190-
//| .. data:: LBRG
191-
//|
192-
//| * **order** *Luminosity*, Blue, Red, Green
193-
//| * **bpp** 4
194-
//| * **has_luminosity** True
195-
PIXELBUF_BYTEORDER(LBRG, 4, 3, 1, 2, 0, false, true)
196-
//| .. data:: LBGR
197-
//|
198-
//| * **order** *Luminosity*, Blue, Green, Red
199-
//| * **bpp** 4
200-
//| * **has_luminosity** True
201-
//|
202-
//| Actual format commonly used by DotStar (5 bit luninance value)
203-
PIXELBUF_BYTEORDER(LBGR, 4, 3, 2, 1, 0, false, true)
204-
20585
STATIC const mp_rom_map_elem_t pixelbuf_module_globals_table[] = {
20686
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pixelbuf) },
20787
{ MP_ROM_QSTR(MP_QSTR_PixelBuf), MP_ROM_PTR(&pixelbuf_pixelbuf_type) },
@@ -223,7 +103,7 @@ STATIC const mp_rom_map_elem_t pixelbuf_module_globals_table[] = {
223103
{ MP_ROM_QSTR(MP_QSTR_GBRD), MP_ROM_QSTR(MP_QSTR_GBRD) },
224104
{ MP_ROM_QSTR(MP_QSTR_BRGD), MP_ROM_QSTR(MP_QSTR_BRGD) },
225105
{ MP_ROM_QSTR(MP_QSTR_BGRD), MP_ROM_QSTR(MP_QSTR_BGRD) },
226-
{ MP_ROM_QSTR(MP_QSTR_wheel), MP_ROM_QSTR(&pixelbuf_wheel_obj) },
106+
{ MP_ROM_QSTR(MP_QSTR_wheel), MP_ROM_PTR(&pixelbuf_wheel_obj) },
227107
};
228108

229109
STATIC MP_DEFINE_CONST_DICT(pixelbuf_module_globals, pixelbuf_module_globals_table);

shared-module/_pixelbuf/PixelBuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ mp_obj_t *pixelbuf_get_pixel_array(uint8_t *buf, uint len, pixelbuf_byteorder_de
102102
return mp_obj_new_tuple(len, elems);
103103
}
104104

105-
mp_obj_t *pixelbuf_get_pixel(uint8_t *buf, pixelbuf_byteorder_obj_t *byteorder, bool dotstar) {
105+
mp_obj_t *pixelbuf_get_pixel(uint8_t *buf, pixelbuf_byteorder_details_t *byteorder, bool dotstar) {
106106
mp_obj_t elems[byteorder->bpp];
107107

108108
elems[0] = mp_obj_new_int(buf[byteorder->byteorder.r]);

0 commit comments

Comments
 (0)