Skip to content

Commit ba47aa2

Browse files
authored
Merge pull request #2550 from tannewt/tweak_pixelbuf
Encapsulate the buffers within PixelBuf
2 parents d22e95e + 55eb173 commit ba47aa2

File tree

26 files changed

+639
-911
lines changed

26 files changed

+639
-911
lines changed

extmod/modframebuf.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string.h>
2929

3030
#include "py/runtime.h"
31+
#include "py/objtype.h"
3132
#include "py/proto.h"
3233

3334
#if MICROPY_PY_FRAMEBUF
@@ -304,17 +305,26 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, cons
304305
return MP_OBJ_FROM_PTR(o);
305306
}
306307

308+
STATIC const mp_obj_type_t mp_type_framebuf;
309+
310+
// Helper to ensure we have the native super class instead of a subclass.
311+
static mp_obj_framebuf_t* native_framebuf(mp_obj_t framebuf_obj) {
312+
mp_obj_t native_framebuf = mp_instance_cast_to_native_base(framebuf_obj, &mp_type_framebuf);
313+
mp_obj_assert_native_inited(native_framebuf);
314+
return MP_OBJ_TO_PTR(native_framebuf);
315+
}
316+
307317
STATIC mp_int_t framebuf_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
308318
(void)flags;
309-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
319+
mp_obj_framebuf_t *self = native_framebuf(self_in);
310320
bufinfo->buf = self->buf;
311321
bufinfo->len = self->stride * self->height * (self->format == FRAMEBUF_RGB565 ? 2 : 1);
312322
bufinfo->typecode = 'B'; // view framebuf as bytes
313323
return 0;
314324
}
315325

316326
STATIC mp_obj_t framebuf_fill(mp_obj_t self_in, mp_obj_t col_in) {
317-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
327+
mp_obj_framebuf_t *self = native_framebuf(self_in);
318328
mp_int_t col = mp_obj_get_int(col_in);
319329
formats[self->format].fill_rect(self, 0, 0, self->width, self->height, col);
320330
return mp_const_none;
@@ -324,7 +334,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(framebuf_fill_obj, framebuf_fill);
324334
STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) {
325335
(void)n_args;
326336

327-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
337+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
328338
mp_int_t x = mp_obj_get_int(args[1]);
329339
mp_int_t y = mp_obj_get_int(args[2]);
330340
mp_int_t width = mp_obj_get_int(args[3]);
@@ -338,7 +348,7 @@ STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) {
338348
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_fill_rect_obj, 6, 6, framebuf_fill_rect);
339349

340350
STATIC mp_obj_t framebuf_pixel(size_t n_args, const mp_obj_t *args) {
341-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
351+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
342352
mp_int_t x = mp_obj_get_int(args[1]);
343353
mp_int_t y = mp_obj_get_int(args[2]);
344354
if (0 <= x && x < self->width && 0 <= y && y < self->height) {
@@ -357,7 +367,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_pixel_obj, 3, 4, framebuf_pi
357367
STATIC mp_obj_t framebuf_hline(size_t n_args, const mp_obj_t *args) {
358368
(void)n_args;
359369

360-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
370+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
361371
mp_int_t x = mp_obj_get_int(args[1]);
362372
mp_int_t y = mp_obj_get_int(args[2]);
363373
mp_int_t w = mp_obj_get_int(args[3]);
@@ -372,7 +382,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_hline_obj, 5, 5, framebuf_hl
372382
STATIC mp_obj_t framebuf_vline(size_t n_args, const mp_obj_t *args) {
373383
(void)n_args;
374384

375-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
385+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
376386
mp_int_t x = mp_obj_get_int(args[1]);
377387
mp_int_t y = mp_obj_get_int(args[2]);
378388
mp_int_t h = mp_obj_get_int(args[3]);
@@ -387,7 +397,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_vline_obj, 5, 5, framebuf_vl
387397
STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args) {
388398
(void)n_args;
389399

390-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
400+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
391401
mp_int_t x = mp_obj_get_int(args[1]);
392402
mp_int_t y = mp_obj_get_int(args[2]);
393403
mp_int_t w = mp_obj_get_int(args[3]);
@@ -406,7 +416,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 6, framebuf_rec
406416
STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
407417
(void)n_args;
408418

409-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
419+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
410420
mp_int_t x1 = mp_obj_get_int(args[1]);
411421
mp_int_t y1 = mp_obj_get_int(args[2]);
412422
mp_int_t x2 = mp_obj_get_int(args[3]);
@@ -470,8 +480,8 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
470480
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_line_obj, 6, 6, framebuf_line);
471481

472482
STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
473-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
474-
mp_obj_framebuf_t *source = MP_OBJ_TO_PTR(args[1]);
483+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
484+
mp_obj_framebuf_t *source = native_framebuf(args[1]);
475485
mp_int_t x = mp_obj_get_int(args[2]);
476486
mp_int_t y = mp_obj_get_int(args[3]);
477487
mp_int_t key = -1;
@@ -513,7 +523,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
513523
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 5, framebuf_blit);
514524

515525
STATIC mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) {
516-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
526+
mp_obj_framebuf_t *self = native_framebuf(self_in);
517527
mp_int_t xstep = mp_obj_get_int(xstep_in);
518528
mp_int_t ystep = mp_obj_get_int(ystep_in);
519529
int sx, y, xend, yend, dx, dy;
@@ -546,7 +556,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(framebuf_scroll_obj, framebuf_scroll);
546556

547557
STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args) {
548558
// extract arguments
549-
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
559+
mp_obj_framebuf_t *self = native_framebuf(args[0]);
550560
const char *str = mp_obj_str_get_str(args[1]);
551561
mp_int_t x0 = mp_obj_get_int(args[2]);
552562
mp_int_t y0 = mp_obj_get_int(args[3]);

locale/ID.po

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-01-18 11:56-0800\n"
11+
"POT-Creation-Date: 2020-01-29 17:27-0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -512,11 +512,8 @@ msgstr "Clock unit sedang digunakan"
512512
msgid "Column entry must be digitalio.DigitalInOut"
513513
msgstr ""
514514

515-
#: shared-bindings/displayio/I2CDisplay.c
516-
msgid "Command must be 0-255"
517-
msgstr ""
518-
519-
#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c
515+
#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c
516+
#: shared-bindings/displayio/ParallelBus.c
520517
msgid "Command must be an int between 0 and 255"
521518
msgstr ""
522519

@@ -661,10 +658,6 @@ msgstr ""
661658
msgid "Expected a Characteristic"
662659
msgstr ""
663660

664-
#: shared-bindings/_pixelbuf/__init__.c
665-
msgid "Expected a PixelBuf instance"
666-
msgstr ""
667-
668661
#: shared-bindings/_bleio/Characteristic.c
669662
msgid "Expected a Service"
670663
msgstr ""
@@ -692,11 +685,11 @@ msgstr ""
692685
msgid "Failed to acquire mutex, err 0x%04x"
693686
msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX"
694687

695-
#: ports/atmel-samd/common-hal/busio/UART.c
696688
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
697689
msgid "Failed to allocate RX buffer"
698690
msgstr "Gagal untuk mengalokasikan buffer RX"
699691

692+
#: ports/atmel-samd/common-hal/busio/UART.c
700693
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
701694
#: ports/cxd56/common-hal/pulseio/PulseIn.c
702695
#: ports/nrf/common-hal/pulseio/PulseIn.c
@@ -1148,10 +1141,6 @@ msgstr ""
11481141
msgid "Pin does not have ADC capabilities"
11491142
msgstr "Pin tidak mempunya kemampuan untuk ADC (Analog Digital Converter)"
11501143

1151-
#: shared-bindings/_pixelbuf/PixelBuf.c
1152-
msgid "Pixel beyond bounds of buffer"
1153-
msgstr ""
1154-
11551144
#: py/builtinhelp.c
11561145
msgid "Plus any modules on the filesystem\n"
11571146
msgstr "Tambahkan module apapun pada filesystem\n"
@@ -1203,10 +1192,6 @@ msgstr ""
12031192
msgid "Random number generation error"
12041193
msgstr ""
12051194

1206-
#: shared-bindings/_pixelbuf/PixelBuf.c
1207-
msgid "Range out of bounds"
1208-
msgstr ""
1209-
12101195
#: shared-bindings/pulseio/PulseIn.c
12111196
msgid "Read-only"
12121197
msgstr ""
@@ -1632,11 +1617,6 @@ msgstr ""
16321617
msgid "branch not in range"
16331618
msgstr ""
16341619

1635-
#: shared-bindings/_pixelbuf/PixelBuf.c
1636-
#, c-format
1637-
msgid "buf is too small. need %d bytes"
1638-
msgstr ""
1639-
16401620
#: shared-bindings/audiocore/RawSample.c
16411621
msgid "buffer must be a bytes-like object"
16421622
msgstr ""
@@ -2528,10 +2508,6 @@ msgstr ""
25282508
msgid "queue overflow"
25292509
msgstr "antrian meluap (overflow)"
25302510

2531-
#: shared-bindings/_pixelbuf/PixelBuf.c
2532-
msgid "rawbuf is not the same size as buf"
2533-
msgstr ""
2534-
25352511
#: py/builtinimport.c
25362512
msgid "relative import"
25372513
msgstr "relative import"
@@ -2765,16 +2741,6 @@ msgstr ""
27652741
msgid "unknown format code '%c' for object of type '%s'"
27662742
msgstr ""
27672743

2768-
#: py/objstr.c
2769-
#, c-format
2770-
msgid "unknown format code '%c' for object of type 'float'"
2771-
msgstr ""
2772-
2773-
#: py/objstr.c
2774-
#, c-format
2775-
msgid "unknown format code '%c' for object of type 'str'"
2776-
msgstr ""
2777-
27782744
#: py/compile.c
27792745
msgid "unknown type"
27802746
msgstr "tipe tidak diketahui"

locale/circuitpython.pot

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-01-18 11:56-0800\n"
11+
"POT-Creation-Date: 2020-01-29 17:27-0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -502,11 +502,8 @@ msgstr ""
502502
msgid "Column entry must be digitalio.DigitalInOut"
503503
msgstr ""
504504

505-
#: shared-bindings/displayio/I2CDisplay.c
506-
msgid "Command must be 0-255"
507-
msgstr ""
508-
509-
#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c
505+
#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c
506+
#: shared-bindings/displayio/ParallelBus.c
510507
msgid "Command must be an int between 0 and 255"
511508
msgstr ""
512509

@@ -650,10 +647,6 @@ msgstr ""
650647
msgid "Expected a Characteristic"
651648
msgstr ""
652649

653-
#: shared-bindings/_pixelbuf/__init__.c
654-
msgid "Expected a PixelBuf instance"
655-
msgstr ""
656-
657650
#: shared-bindings/_bleio/Characteristic.c
658651
msgid "Expected a Service"
659652
msgstr ""
@@ -681,11 +674,11 @@ msgstr ""
681674
msgid "Failed to acquire mutex, err 0x%04x"
682675
msgstr ""
683676

684-
#: ports/atmel-samd/common-hal/busio/UART.c
685677
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
686678
msgid "Failed to allocate RX buffer"
687679
msgstr ""
688680

681+
#: ports/atmel-samd/common-hal/busio/UART.c
689682
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
690683
#: ports/cxd56/common-hal/pulseio/PulseIn.c
691684
#: ports/nrf/common-hal/pulseio/PulseIn.c
@@ -1136,10 +1129,6 @@ msgstr ""
11361129
msgid "Pin does not have ADC capabilities"
11371130
msgstr ""
11381131

1139-
#: shared-bindings/_pixelbuf/PixelBuf.c
1140-
msgid "Pixel beyond bounds of buffer"
1141-
msgstr ""
1142-
11431132
#: py/builtinhelp.c
11441133
msgid "Plus any modules on the filesystem\n"
11451134
msgstr ""
@@ -1189,10 +1178,6 @@ msgstr ""
11891178
msgid "Random number generation error"
11901179
msgstr ""
11911180

1192-
#: shared-bindings/_pixelbuf/PixelBuf.c
1193-
msgid "Range out of bounds"
1194-
msgstr ""
1195-
11961181
#: shared-bindings/pulseio/PulseIn.c
11971182
msgid "Read-only"
11981183
msgstr ""
@@ -1609,11 +1594,6 @@ msgstr ""
16091594
msgid "branch not in range"
16101595
msgstr ""
16111596

1612-
#: shared-bindings/_pixelbuf/PixelBuf.c
1613-
#, c-format
1614-
msgid "buf is too small. need %d bytes"
1615-
msgstr ""
1616-
16171597
#: shared-bindings/audiocore/RawSample.c
16181598
msgid "buffer must be a bytes-like object"
16191599
msgstr ""
@@ -2503,10 +2483,6 @@ msgstr ""
25032483
msgid "queue overflow"
25042484
msgstr ""
25052485

2506-
#: shared-bindings/_pixelbuf/PixelBuf.c
2507-
msgid "rawbuf is not the same size as buf"
2508-
msgstr ""
2509-
25102486
#: py/builtinimport.c
25112487
msgid "relative import"
25122488
msgstr ""
@@ -2739,16 +2715,6 @@ msgstr ""
27392715
msgid "unknown format code '%c' for object of type '%s'"
27402716
msgstr ""
27412717

2742-
#: py/objstr.c
2743-
#, c-format
2744-
msgid "unknown format code '%c' for object of type 'float'"
2745-
msgstr ""
2746-
2747-
#: py/objstr.c
2748-
#, c-format
2749-
msgid "unknown format code '%c' for object of type 'str'"
2750-
msgstr ""
2751-
27522718
#: py/compile.c
27532719
msgid "unknown type"
27542720
msgstr ""

0 commit comments

Comments
 (0)