diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-10-04 22:33:14 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-10-16 12:18:08 +1100 |
commit | 03a9fa227d323da7b239a1ef3fa84b0ef45a1621 (patch) | |
tree | eed9378d0c534e6c0dcf65c094cf0809ba2fe69f | |
parent | d040478d8aad7a05aac98651ec6ac5c2e9265a22 (diff) |
extmod/modframebuf: Fix FrameBuffer get-buffer implementation.
This wasn't correctly accounting for the bits-per-pixel and was returning a
bufinfo struct with the incorrect length. Instead, just forward directly
to the underlying buffer object.
Fixes issue #12563.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r-- | extmod/modframebuf.c | 6 | ||||
-rw-r--r-- | tests/extmod/framebuf1.py | 6 | ||||
-rw-r--r-- | tests/extmod/framebuf1.py.exp | 1 |
3 files changed, 8 insertions, 5 deletions
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index eabe81997..c62ac4fe3 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -336,12 +336,8 @@ STATIC void framebuf_args(const mp_obj_t *args_in, mp_int_t *args_out, int n) { } STATIC mp_int_t framebuf_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { - (void)flags; mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in); - bufinfo->buf = self->buf; - bufinfo->len = self->stride * self->height * (self->format == FRAMEBUF_RGB565 ? 2 : 1); - bufinfo->typecode = 'B'; // view framebuf as bytes - return 0; + return mp_get_buffer(self->buf_obj, bufinfo, flags) ? 0 : 1; } STATIC mp_obj_t framebuf_fill(mp_obj_t self_in, mp_obj_t col_in) { diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index d35674a70..b1173d536 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -109,3 +109,9 @@ except ValueError: fbuf = framebuf.FrameBuffer1(buf, w, h) fbuf = framebuf.FrameBuffer1(buf, w, h, w) print(framebuf.MVLSB == framebuf.MONO_VLSB) + +# test get-buffer (returns the original buffer) +fbuf = framebuf.FrameBuffer(bytearray(2), 8, 1, framebuf.MONO_HLSB) +fbuf.pixel(0, 0, 1) +fbuf.pixel(4, 0, 1) +print(bytearray(fbuf)) diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp index b9cd97835..4f18e48ec 100644 --- a/tests/extmod/framebuf1.py.exp +++ b/tests/extmod/framebuf1.py.exp @@ -66,3 +66,4 @@ bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00\x00\x00\x00\x00\x00\x00') ValueError True +bytearray(b'\x88\x00') |