Skip to content

Commit e5ea1d2

Browse files
committed
try to revert pixelbuf merge brokenness. remove second color_u def.
1 parent 19f1119 commit e5ea1d2

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

shared-module/adafruit_pixelbuf/PixelBuf.c

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -154,56 +154,55 @@ STATIC uint8_t _pixelbuf_get_as_uint8(mp_obj_t obj) {
154154
translate("can't convert %q to %q"), mp_obj_get_type_qstr(obj), MP_QSTR_int);
155155
}
156156

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) {
159158
pixelbuf_byteorder_details_t *byteorder = &self->byteorder;
160159
// w is shared between white in NeoPixels and brightness in dotstars (so that DotStars can have
161160
// per-pixel brightness). Set the defaults here in case it isn't set below.
162161
if (byteorder->is_dotstar) {
163-
result.w = 255;
162+
*w = 255;
164163
} else {
165-
result.w = 0;
164+
*w = 0;
166165
}
167166

168167
if (mp_obj_is_int(color) || mp_obj_is_float(color)) {
169168
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;
173172
} else {
174173
mp_obj_t *items;
175174
size_t len;
176175
mp_obj_get_array(color, &len, &items);
177176
mp_arg_validate_length_range(len, 3, 4, MP_QSTR_color);
178177

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]);
182181
if (len > 3) {
183182
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]);
185184
} else {
186-
result.w = mp_obj_get_int_truncated(items[PIXEL_W]);
185+
*w = mp_obj_get_int_truncated(items[PIXEL_W]);
187186
}
188-
return result;
187+
return;
189188
}
190189
}
191190
// Int colors can't set white directly so convert to white when all components are equal.
192191
// 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;
198197
}
199-
return result;
200198
}
201199

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) {
207206
// DotStars don't have white, instead they have 5 bit brightness so pack it into w. Shift right
208207
// by three to leave the top five bits.
209208
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
240239
scaled_buffer[rgbw_order->b] = (b * self->scaled_brightness) / 256;
241240
}
242241
}
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+
}
243246

244247
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);
247254
}
248255

249256
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) {
322329
void common_hal_adafruit_pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t fill_color) {
323330
pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
324331

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);
326337

327338
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);
329340
}
330341
if (self->auto_write) {
331342
common_hal_adafruit_pixelbuf_pixelbuf_show(self_in);

shared-module/adafruit_pixelmap/PixelMap.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
#include "shared-bindings/adafruit_pixelbuf/PixelBuf.h"
3333
#include "shared-module/adafruit_pixelmap/PixelMap.h"
3434

35-
typedef union {
36-
uint32_t rgbw;
37-
struct {
38-
uint8_t r, g, b, w;
39-
};
40-
} color_u;
4135

4236
static void pixelmap_set_pixel_rgbw(pixelmap_pixelmap_obj_t *self, size_t i, color_u rgbw) {
4337
mp_arg_validate_index_range(i, 0, self->len, MP_QSTR_index);

0 commit comments

Comments
 (0)