Skip to content

Commit 468c6f9

Browse files
peterhinchdpgeorge
authored andcommitted
extmod/modframebuf: Make monochrome bitmap formats start with MONO_.
MONO_xxx is much easier to read if you're not familiar with the code. MVLSB is deprecated but kept for backwards compatibility, for the time being. This patch also updates the associated docs and tests.
1 parent fc245d1 commit 468c6f9

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

docs/library/framebuf.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,32 @@ Other methods
116116
Constants
117117
---------
118118

119-
.. data:: framebuf.MVLSB
119+
.. data:: framebuf.MONO_VLSB
120120

121121
Monochrome (1-bit) color format
122+
This defines a mapping where the bits in a byte are vertically mapped with
123+
bit 0 being nearest the top of the screen. Consequently each byte occupies
124+
8 vertical pixels. Subsequent bytes appear at successive horizontal
125+
locations until the rightmost edge is reached. Further bytes are rendered
126+
at locations starting at the leftmost edge, 8 pixels lower.
127+
128+
.. data:: framebuf.MONO_HLSB
129+
130+
Monochrome (1-bit) color format
131+
This defines a mapping where the bits in a byte are horizontally mapped.
132+
Each byte occupies 8 horizontal pixels with bit 0 being the leftmost.
133+
Subsequent bytes appear at successive horizontal locations until the
134+
rightmost edge is reached. Further bytes are rendered on the next row, one
135+
pixel lower.
136+
137+
.. data:: framebuf.MONO_HMSB
138+
139+
Monochrome (1-bit) color format
140+
This defines a mapping where the bits in a byte are horizontally mapped.
141+
Each byte occupies 8 horizontal pixels with bit 7 being the leftmost.
142+
Subsequent bytes appear at successive horizontal locations until the
143+
rightmost edge is reached. Further bytes are rendered on the next row, one
144+
pixel lower.
122145

123146
.. data:: framebuf.RGB565
124147

extmod/modframebuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,11 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = {
579579
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) },
580580
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) },
581581
{ MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
582+
{ MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
582583
{ MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) },
583584
{ MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) },
584-
{ MP_ROM_QSTR(MP_QSTR_MHLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) },
585-
{ MP_ROM_QSTR(MP_QSTR_MHMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) },
585+
{ MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) },
586+
{ MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) },
586587
};
587588

588589
STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table);

tests/extmod/framebuf1.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
h = 16
1010
size = w * h // 8
1111
buf = bytearray(size)
12-
maps = {framebuf.MVLSB : 'MVLSB',
13-
framebuf.MHLSB : 'MHLSB',
14-
framebuf.MHMSB : 'MHMSB'}
12+
maps = {framebuf.MONO_VLSB : 'MONO_VLSB',
13+
framebuf.MONO_HLSB : 'MONO_HLSB',
14+
framebuf.MONO_HMSB : 'MONO_HMSB'}
1515

1616
for mapping in maps.keys():
1717
for x in range(size):
@@ -107,3 +107,4 @@
107107
# test legacy constructor
108108
fbuf = framebuf.FrameBuffer1(buf, w, h)
109109
fbuf = framebuf.FrameBuffer1(buf, w, h, w)
110+
print(framebuf.MVLSB == framebuf.MONO_VLSB)

tests/extmod/framebuf1.py.exp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MVLSB
1+
MONO_VLSB
22
0
33
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
44
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
@@ -20,7 +20,7 @@ bytearray(b'\x00\x7f\x7f\x04\x04\x00\x00\x00\x00\x00')
2020
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
2121
bytearray(b'\xaaU\xaaU\xaa\x00\x00\x00\x00\x00')
2222

23-
MHLSB
23+
MONO_HLSB
2424
0
2525
bytearray(b'\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8')
2626
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
@@ -42,7 +42,7 @@ bytearray(b'``x````\x00\x00\x00')
4242
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
4343
bytearray(b'P\xa8P\xa8P\xa8P\xa8\x00\x00')
4444

45-
MHMSB
45+
MONO_HMSB
4646
0
4747
bytearray(b'\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f')
4848
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
@@ -65,3 +65,4 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
6565
bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00')
6666

6767
ValueError
68+
True

0 commit comments

Comments
 (0)