Skip to content

Commit c6dbc7d

Browse files
committed
Add displayio bitmaps to unix build
1 parent a1069eb commit c6dbc7d

File tree

9 files changed

+216
-146
lines changed

9 files changed

+216
-146
lines changed

ports/unix/displayio_colorspace_only.c renamed to ports/unix/displayio_min.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "py/runtime.h"
3030

3131
#include "shared-bindings/displayio/__init__.h"
32+
#include "shared-bindings/displayio/Bitmap.h"
3233

3334
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB888, DISPLAYIO_COLORSPACE_RGB888);
3435
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB565, DISPLAYIO_COLORSPACE_RGB565);
@@ -78,6 +79,7 @@ MAKE_ENUM_TYPE(displayio, ColorSpace, displayio_colorspace);
7879

7980
STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
8081
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_displayio) },
82+
{ MP_ROM_QSTR(MP_QSTR_Bitmap), MP_ROM_PTR(&displayio_bitmap_type) },
8183
{ MP_ROM_QSTR(MP_QSTR_Colorspace), MP_ROM_PTR(&displayio_colorspace_type) },
8284
};
8385
STATIC MP_DEFINE_CONST_DICT(displayio_module_globals, displayio_module_globals_table);
@@ -87,4 +89,4 @@ const mp_obj_module_t displayio_module = {
8789
.globals = (mp_obj_dict_t *)&displayio_module_globals,
8890
};
8991

90-
MP_REGISTER_MODULE(MP_QSTR_displayio, displayio_module, CIRCUITPY_DISPLAYIO_COLORSPACE_ONLY);
92+
MP_REGISTER_MODULE(MP_QSTR_displayio, displayio_module, CIRCUITPY_DISPLAYIO_UNIX);

ports/unix/variants/coverage/mpconfigvariant.mk

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,20 @@ SRC_C += $(SRC_QRIO)
2727
CFLAGS += -DCIRCUITPY_QRIO=1
2828
$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h
2929

30-
SRC_GIFIO := $(patsubst ../../%,%,$(wildcard ../../shared-bindings/gifio/*.c ../../shared-module/gifio/*.c)) shared/runtime/context_manager_helpers.c displayio_colorspace_only.c shared-module/displayio/ColorConverter.c shared-bindings/util.c
31-
SRC_C += $(SRC_GIFIO)
32-
33-
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_COLORSPACE_ONLY=1
30+
SRC_BITMAP := \
31+
$(patsubst ../../%,%,$(wildcard ../../shared-bindings/gifio/*.c ../../shared-module/gifio/*.c)) \
32+
shared/runtime/context_manager_helpers.c \
33+
displayio_min.c \
34+
shared-bindings/displayio/Bitmap.c \
35+
shared-module/displayio/area.c \
36+
shared-module/displayio/Bitmap.c \
37+
shared-module/displayio/ColorConverter.c \
38+
shared-bindings/util.c \
39+
40+
$(info $(SRC_BITMAP))
41+
SRC_C += $(SRC_BITMAP)
42+
43+
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_UNIX=1
3444

3545
SRC_C += coverage.c
3646
SRC_CXX += coveragecpp.cpp

py/circuitpy_defns.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ SRC_SHARED_MODULE_ALL = \
534534
displayio/Palette.c \
535535
displayio/Shape.c \
536536
displayio/TileGrid.c \
537+
displayio/area.c \
537538
displayio/__init__.c \
538539
fontio/BuiltinFont.c \
539540
fontio/__init__.c \

shared-bindings/displayio/Bitmap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "py/binary.h"
3434
#include "py/objproperty.h"
3535
#include "py/runtime.h"
36-
#include "shared-bindings/microcontroller/Pin.h"
3736
#include "shared-bindings/util.h"
3837
#include "supervisor/shared/translate.h"
3938

@@ -206,9 +205,9 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
206205
STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
207206
enum {ARG_x, ARG_y, ARG_source, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_skip_index};
208207
static const mp_arg_t allowed_args[] = {
209-
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT},
210-
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT},
211-
{MP_QSTR_source_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ},
208+
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = 0} },
209+
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = 0} },
210+
{MP_QSTR_source_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = 0} },
212211
{MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
213212
{MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
214213
{MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width

shared-bindings/displayio/area.c

Whitespace-only changes.

shared-module/displayio/Bitmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, const displayio_a
113113
displayio_area_t area = *dirty_area;
114114
displayio_area_canon(&area);
115115
displayio_area_union(&area, &self->dirty_area, &area);
116-
displayio_area_t bitmap_area = {0, 0, self->width, self->height};
116+
displayio_area_t bitmap_area = {0, 0, self->width, self->height, NULL};
117117
displayio_area_compute_overlap(&area, &bitmap_area, &self->dirty_area);
118118
}
119119

@@ -160,7 +160,7 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
160160
dirty_y_max = self->height;
161161
}
162162

163-
displayio_area_t a = { x, y, dirty_x_max, dirty_y_max};
163+
displayio_area_t a = { x, y, dirty_x_max, dirty_y_max, NULL};
164164
displayio_bitmap_set_dirty_area(self, &a);
165165

166166
bool x_reverse = false;
@@ -199,7 +199,7 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
199199

200200
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) {
201201
// update the dirty region
202-
displayio_area_t a = {x, y, x + 1, y + 1};
202+
displayio_area_t a = {x, y, x + 1, y + 1, NULL};
203203
displayio_bitmap_set_dirty_area(self, &a);
204204

205205
// write the pixel
@@ -221,7 +221,7 @@ void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) {
221221
}
222222

223223
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value) {
224-
displayio_area_t a = {0, 0, self->width, self->height};
224+
displayio_area_t a = {0, 0, self->width, self->height, NULL};
225225
displayio_bitmap_set_dirty_area(self, &a);
226226

227227
// build the packed word

shared-module/displayio/__init__.c

Lines changed: 26 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
127

228
#include <string.h>
329

@@ -249,138 +275,6 @@ void displayio_gc_collect(void) {
249275
}
250276
}
251277

252-
void displayio_area_copy(const displayio_area_t *src, displayio_area_t *dst) {
253-
dst->x1 = src->x1;
254-
dst->y1 = src->y1;
255-
dst->x2 = src->x2;
256-
dst->y2 = src->y2;
257-
}
258-
259-
void displayio_area_scale(displayio_area_t *area, uint16_t scale) {
260-
area->x1 *= scale;
261-
area->y1 *= scale;
262-
area->x2 *= scale;
263-
area->y2 *= scale;
264-
}
265-
266-
void displayio_area_shift(displayio_area_t *area, int16_t dx, int16_t dy) {
267-
area->x1 += dx;
268-
area->y1 += dy;
269-
area->x2 += dx;
270-
area->y2 += dy;
271-
}
272-
273-
bool displayio_area_compute_overlap(const displayio_area_t *a,
274-
const displayio_area_t *b,
275-
displayio_area_t *overlap) {
276-
overlap->x1 = a->x1;
277-
if (b->x1 > overlap->x1) {
278-
overlap->x1 = b->x1;
279-
}
280-
overlap->x2 = a->x2;
281-
if (b->x2 < overlap->x2) {
282-
overlap->x2 = b->x2;
283-
}
284-
if (overlap->x1 >= overlap->x2) {
285-
return false;
286-
}
287-
overlap->y1 = a->y1;
288-
if (b->y1 > overlap->y1) {
289-
overlap->y1 = b->y1;
290-
}
291-
overlap->y2 = a->y2;
292-
if (b->y2 < overlap->y2) {
293-
overlap->y2 = b->y2;
294-
}
295-
if (overlap->y1 >= overlap->y2) {
296-
return false;
297-
}
298-
return true;
299-
}
300-
301-
bool displayio_area_empty(const displayio_area_t *a) {
302-
return (a->x1 == a->x2) || (a->y1 == a->y2);
303-
}
304-
305-
void displayio_area_canon(displayio_area_t *a) {
306-
if (a->x1 > a->x2) {
307-
int16_t t = a->x1;
308-
a->x1 = a->x2;
309-
a->x2 = t;
310-
}
311-
if (a->y1 > a->y2) {
312-
int16_t t = a->y1;
313-
a->y1 = a->y2;
314-
a->y2 = t;
315-
}
316-
}
317-
318-
void displayio_area_union(const displayio_area_t *a,
319-
const displayio_area_t *b,
320-
displayio_area_t *u) {
321-
322-
if (displayio_area_empty(a)) {
323-
displayio_area_copy(b, u);
324-
return;
325-
}
326-
if (displayio_area_empty(b)) {
327-
displayio_area_copy(a, u);
328-
return;
329-
}
330-
u->x1 = MIN(a->x1, b->x1);
331-
u->y1 = MIN(a->y1, b->y1);
332-
u->x2 = MAX(a->x2, b->x2);
333-
u->y2 = MAX(a->y2, b->y2);
334-
}
335-
336-
uint16_t displayio_area_width(const displayio_area_t *area) {
337-
return area->x2 - area->x1;
338-
}
339-
340-
uint16_t displayio_area_height(const displayio_area_t *area) {
341-
return area->y2 - area->y1;
342-
}
343-
344-
uint32_t displayio_area_size(const displayio_area_t *area) {
345-
return displayio_area_width(area) * displayio_area_height(area);
346-
}
347-
348-
bool displayio_area_equal(const displayio_area_t *a, const displayio_area_t *b) {
349-
return a->x1 == b->x1 &&
350-
a->y1 == b->y1 &&
351-
a->x2 == b->x2 &&
352-
a->y2 == b->y2;
353-
}
354-
355-
// Original and whole must be in the same coordinate space.
356-
void displayio_area_transform_within(bool mirror_x, bool mirror_y, bool transpose_xy,
357-
const displayio_area_t *original,
358-
const displayio_area_t *whole,
359-
displayio_area_t *transformed) {
360-
if (mirror_x) {
361-
transformed->x1 = whole->x1 + (whole->x2 - original->x2);
362-
transformed->x2 = whole->x2 - (original->x1 - whole->x1);
363-
} else {
364-
transformed->x1 = original->x1;
365-
transformed->x2 = original->x2;
366-
}
367-
if (mirror_y) {
368-
transformed->y1 = whole->y1 + (whole->y2 - original->y2);
369-
transformed->y2 = whole->y2 - (original->y1 - whole->y1);
370-
} else {
371-
transformed->y1 = original->y1;
372-
transformed->y2 = original->y2;
373-
}
374-
if (transpose_xy) {
375-
int16_t y1 = transformed->y1;
376-
int16_t y2 = transformed->y2;
377-
transformed->y1 = whole->y1 + (transformed->x1 - whole->x1);
378-
transformed->y2 = whole->y1 + (transformed->x2 - whole->x1);
379-
transformed->x2 = whole->x1 + (y2 - whole->y1);
380-
transformed->x1 = whole->x1 + (y1 - whole->y1);
381-
}
382-
}
383-
384278
primary_display_t *allocate_display(void) {
385279
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
386280
mp_const_obj_t display_type = displays[i].display.base.type;

0 commit comments

Comments
 (0)