@@ -154,56 +154,55 @@ STATIC uint8_t _pixelbuf_get_as_uint8(mp_obj_t obj) {
154
154
translate ("can't convert %q to %q" ), mp_obj_get_type_qstr (obj ), MP_QSTR_int );
155
155
}
156
156
157
- STATIC color_u _pixelbuf_parse_color (pixelbuf_pixelbuf_obj_t * self , mp_obj_t color ) {
158
- color_u result ;
157
+ static void pixelbuf_parse_color (pixelbuf_pixelbuf_obj_t * self , mp_obj_t color , uint8_t * r , uint8_t * g , uint8_t * b , uint8_t * w ) {
159
158
pixelbuf_byteorder_details_t * byteorder = & self -> byteorder ;
160
159
// w is shared between white in NeoPixels and brightness in dotstars (so that DotStars can have
161
160
// per-pixel brightness). Set the defaults here in case it isn't set below.
162
161
if (byteorder -> is_dotstar ) {
163
- result . w = 255 ;
162
+ * w = 255 ;
164
163
} else {
165
- result . w = 0 ;
164
+ * w = 0 ;
166
165
}
167
166
168
167
if (mp_obj_is_int (color ) || mp_obj_is_float (color )) {
169
168
mp_int_t value = mp_obj_is_int (color ) ? mp_obj_get_int_truncated (color ) : (mp_int_t )mp_obj_get_float (color );
170
- result . r = value >> 16 & 0xff ;
171
- result . g = (value >> 8 ) & 0xff ;
172
- result . b = value & 0xff ;
169
+ * r = value >> 16 & 0xff ;
170
+ * g = (value >> 8 ) & 0xff ;
171
+ * b = value & 0xff ;
173
172
} else {
174
173
mp_obj_t * items ;
175
174
size_t len ;
176
175
mp_obj_get_array (color , & len , & items );
177
176
mp_arg_validate_length_range (len , 3 , 4 , MP_QSTR_color );
178
177
179
- result . r = _pixelbuf_get_as_uint8 (items [PIXEL_R ]);
180
- result . g = _pixelbuf_get_as_uint8 (items [PIXEL_G ]);
181
- result . b = _pixelbuf_get_as_uint8 (items [PIXEL_B ]);
178
+ * r = _pixelbuf_get_as_uint8 (items [PIXEL_R ]);
179
+ * g = _pixelbuf_get_as_uint8 (items [PIXEL_G ]);
180
+ * b = _pixelbuf_get_as_uint8 (items [PIXEL_B ]);
182
181
if (len > 3 ) {
183
182
if (mp_obj_is_float (items [PIXEL_W ])) {
184
- result . w = 255 * mp_obj_get_float (items [PIXEL_W ]);
183
+ * w = 255 * mp_obj_get_float (items [PIXEL_W ]);
185
184
} else {
186
- result . w = mp_obj_get_int_truncated (items [PIXEL_W ]);
185
+ * w = mp_obj_get_int_truncated (items [PIXEL_W ]);
187
186
}
188
- return result ;
187
+ return ;
189
188
}
190
189
}
191
190
// Int colors can't set white directly so convert to white when all components are equal.
192
191
// Also handles RGBW values assigned an RGB tuple.
193
- if (!byteorder -> is_dotstar && byteorder -> bpp == 4 && byteorder -> has_white && result . r == result . g && result . r == result . b ) {
194
- result . w = result . r ;
195
- result . r = 0 ;
196
- result . g = 0 ;
197
- result . b = 0 ;
192
+ if (!byteorder -> is_dotstar && byteorder -> bpp == 4 && byteorder -> has_white && * r == * g && * r == * b ) {
193
+ * w = * r ;
194
+ * r = 0 ;
195
+ * g = 0 ;
196
+ * b = 0 ;
198
197
}
199
- return result ;
200
198
}
201
199
202
- STATIC void _pixelbuf_set_pixel_color (pixelbuf_pixelbuf_obj_t * self , size_t index , color_u rgbw ) {
203
- uint8_t r = rgbw .r ;
204
- uint8_t g = rgbw .g ;
205
- uint8_t b = rgbw .b ;
206
- uint8_t w = rgbw .w ;
200
+ void common_hal_adafruit_pixelbuf_pixelbuf_parse_color (mp_obj_t self_in , mp_obj_t color , uint8_t * r , uint8_t * g , uint8_t * b , uint8_t * w ) {
201
+ pixelbuf_pixelbuf_obj_t * self = native_pixelbuf (self_in );
202
+ pixelbuf_parse_color (self , color , r , g , b , w );
203
+ }
204
+
205
+ static void pixelbuf_set_pixel_color (pixelbuf_pixelbuf_obj_t * self , size_t index , uint8_t r , uint8_t g , uint8_t b , uint8_t w ) {
207
206
// DotStars don't have white, instead they have 5 bit brightness so pack it into w. Shift right
208
207
// by three to leave the top five bits.
209
208
if (self -> bytes_per_pixel == 4 && self -> byteorder .is_dotstar ) {
@@ -240,10 +239,18 @@ STATIC void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t *self, size_t inde
240
239
scaled_buffer [rgbw_order -> b ] = (b * self -> scaled_brightness ) / 256 ;
241
240
}
242
241
}
242
+ void common_hal_adafruit_pixelbuf_pixelbuf_set_pixel_color (mp_obj_t self_in , size_t index , uint8_t r , uint8_t g , uint8_t b , uint8_t w ) {
243
+ pixelbuf_pixelbuf_obj_t * self = native_pixelbuf (self_in );
244
+ pixelbuf_set_pixel_color (self , index , r , g , b , w );
245
+ }
243
246
244
247
STATIC void _pixelbuf_set_pixel (pixelbuf_pixelbuf_obj_t * self , size_t index , mp_obj_t value ) {
245
- color_u rgbw = _pixelbuf_parse_color (self , value );
246
- _pixelbuf_set_pixel_color (self , index , rgbw );
248
+ uint8_t r ;
249
+ uint8_t g ;
250
+ uint8_t b ;
251
+ uint8_t w ;
252
+ common_hal_adafruit_pixelbuf_pixelbuf_parse_color (self , value , & r , & g , & b , & w );
253
+ common_hal_adafruit_pixelbuf_pixelbuf_set_pixel_color (self , index , r , g , b , w );
247
254
}
248
255
249
256
void common_hal_adafruit_pixelbuf_pixelbuf_set_pixels (mp_obj_t self_in , size_t start , mp_int_t step , size_t slice_len , mp_obj_t * values ,
@@ -322,10 +329,14 @@ void common_hal_adafruit_pixelbuf_pixelbuf_show(mp_obj_t self_in) {
322
329
void common_hal_adafruit_pixelbuf_pixelbuf_fill (mp_obj_t self_in , mp_obj_t fill_color ) {
323
330
pixelbuf_pixelbuf_obj_t * self = native_pixelbuf (self_in );
324
331
325
- color_u rgbw = _pixelbuf_parse_color (self , fill_color );
332
+ uint8_t r ;
333
+ uint8_t g ;
334
+ uint8_t b ;
335
+ uint8_t w ;
336
+ common_hal_adafruit_pixelbuf_pixelbuf_parse_color (self , fill_color , & r , & g , & b , & w );
326
337
327
338
for (size_t i = 0 ; i < self -> pixel_count ; i ++ ) {
328
- _pixelbuf_set_pixel_color (self , i , rgbw );
339
+ common_hal_adafruit_pixelbuf_pixelbuf_set_pixel_color (self , i , r , g , b , w );
329
340
}
330
341
if (self -> auto_write ) {
331
342
common_hal_adafruit_pixelbuf_pixelbuf_show (self_in );
0 commit comments