Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ports/wasm/js/display.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export class Display {
? this._ctx.createImageData(this._fbWidth, this._fbHeight)
: null;

// Scale canvas to match displayio
// Match the canvas to the framebuffer. The backing-store resolution
// (width/height attributes) MUST equal the framebuffer, else
// putImageData() of a fbWidth×fbHeight ImageData is clipped to the
// canvas default (300×150). CSS width/height then scale it for display.
if (canvas) {
canvas.width = this._fbWidth;
canvas.height = this._fbHeight;
canvas.style.width = this._fbWidth + 'px';
canvas.style.height = this._fbHeight + 'px';
}
Expand Down
4 changes: 4 additions & 0 deletions py/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ static const emit_method_table_t *emit_native_table[] = {
&emit_native_xtensa_method_table,
&emit_native_xtensawin_method_table,
&emit_native_rv32_method_table,
#if MICROPY_EMIT_WASM
&emit_native_wasm_method_table,
#else
NULL, // wasm native emitter is a PORT feature (needs mp_wasm_compile_native); absent in host mpy-cross
#endif
&emit_native_debug_method_table,
};

Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ cryptography
minify_html
jsmin

# for the wasm port's display-resource generation (tools/gen_display_resources.py)
huffman
adafruit-circuitpython-bitmap-font

# for Silicon Labs Configurator (SLC)
websockets
colorama
Expand Down
32 changes: 24 additions & 8 deletions tools/gen_display_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,26 @@
class BitmapStub:
def __init__(self, width, height, color_depth):
self.width = width
self.rows = [b""] * height
self.height = height
self._stride = (width + 7) // 8 # bytes per row, MSB-first byte-packed
self._buf = bytearray(self._stride * height)

def _load_row(self, y, row):
self.rows[y] = bytes(row)
def _load_row(self, y, row): # old bitmap_font API (row = packed bytes)
b = bytes(row)
self._buf[y * self._stride:y * self._stride + self._stride] = b[:self._stride]

def __setitem__(self, index, value): # new bitmap_font API: flat y*width+x -> 0/1
y, x = divmod(index, self.width)
off = y * self._stride + (x >> 3)
if value:
self._buf[off] |= 1 << (7 - (x & 7))
else:
self._buf[off] &= ~(1 << (7 - (x & 7))) & 0xFF

@property
def rows(self):
s = self._stride
return [bytes(self._buf[y * s:y * s + s]) for y in range(self.height)]


f = bitmap_font.load_font(args.font, BitmapStub)
Expand Down Expand Up @@ -69,7 +85,7 @@ def _load_row(self, y, row):
filtered_characters = filtered_characters.replace(c, "")
continue
g = f.get_glyph(ord(c))
if g["shift"][1] != 0:
if g.shift_y != 0:
raise RuntimeError("y shift")

if missing > 0:
Expand All @@ -83,10 +99,10 @@ def _load_row(self, y, row):

for x, c in enumerate(filtered_characters):
g = f.get_glyph(ord(c))
start_bit = x * tile_x + g["bounds"][2]
start_y = (tile_y - 2) - (g["bounds"][1] + g["bounds"][3])
for y, row in enumerate(g["bitmap"].rows):
for i in range(g["bounds"][0]):
start_bit = x * tile_x + g.dx
start_y = (tile_y - 2) - (g.height + g.dy)
for y, row in enumerate(g.bitmap.rows):
for i in range(g.width):
byte = i // 8
bit = i % 8
if row[byte] & (1 << (7 - bit)) != 0:
Expand Down