Skip to content

Commit 4a30892

Browse files
author
evanwashere
committed
update wasm
1 parent f3839c3 commit 4a30892

13 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎ImageScript.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ export class Image {
12381238
max_width: Infinity === wrapWidth ? null : wrapWidth,
12391239
});
12401240

1241-
layout.append(font, text, scale);
1241+
layout.append(font, text, { scale });
12421242
const framebuffer = layout.rasterize(r, g, b);
12431243
const image = new this(framebuffer.width, framebuffer.height);
12441244

‎utils/wasm/font.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ let registry = null;
1010
}
1111

1212
class mem {
13+
static length() { return wasm.wlen(); }
1314
static alloc(size) { return wasm.walloc(size); }
1415
static free(ptr, size) { return wasm.wfree(ptr, size); }
1516
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
1617
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
17-
static length() { return new Uint32Array(wasm.memory.buffer, wasm.cur_len.value, 1)[0]; }
1818

1919
static copy_and_free(ptr, size) {
2020
let slice = mem.u8(ptr, size).slice();
@@ -109,12 +109,14 @@ export class Layout {
109109
wasm.layout_reset(this.ptr, ptr, options.length);
110110
}
111111

112-
append(font, text, scale) {
112+
append(font, text, init) {
113113
text = encode_utf8(text);
114+
const options = init || {};
114115
if (registry) this.refs.push(font);
115116
const ptr = mem.alloc(text.length);
116117
mem.u8(ptr, text.length).set(text);
117-
wasm.layout_append(this.ptr, font.ptr, ptr, text.length, scale ?? font.scale);
118+
const has_color = ('r' in options) || ('g' in options) || ('b' in options);
119+
wasm.layout_append(this.ptr, font.ptr, ptr, text.length, options.scale ?? font.scale, has_color, options.r, options.g, options.b);
118120
}
119121

120122
rasterize(r, g, b) {

‎utils/wasm/font.wasm‎

5.53 KB
Binary file not shown.

‎utils/wasm/gif.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ const streams = new Map;
1616
}
1717

1818
class mem {
19+
static length() { return wasm.wlen(); }
1920
static alloc(size) { return wasm.walloc(size); }
2021
static free(ptr, size) { return wasm.wfree(ptr, size); }
2122
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
2223
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
23-
static length() { return new Uint32Array(wasm.memory.buffer, wasm.cur_len.value, 1)[0]; }
2424

2525
static copy_and_free(ptr, size) {
2626
let slice = mem.u8(ptr, size).slice();

‎utils/wasm/gif.wasm‎

4.1 KB
Binary file not shown.

‎utils/wasm/jpeg.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ let wasm;
99
}
1010

1111
class mem {
12+
static length() { return wasm.wlen(); }
1213
static alloc(size) { return wasm.walloc(size); }
1314
static free(ptr, size) { return wasm.wfree(ptr, size); }
1415
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
1516
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
16-
static length() { return new Uint32Array(wasm.memory.buffer, wasm.cur_len.value, 1)[0]; }
1717

1818
static copy_and_free(ptr, size) {
1919
let slice = mem.u8(ptr, size).slice();

‎utils/wasm/jpeg.wasm‎

-1.17 KB
Binary file not shown.

‎utils/wasm/svg.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ let wasm;
99
}
1010

1111
class mem {
12+
static length() { return wasm.wlen(); }
1213
static alloc(size) { return wasm.walloc(size); }
1314
static free(ptr, size) { return wasm.wfree(ptr, size); }
1415
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
1516
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
16-
static length() { return new Uint32Array(wasm.memory.buffer, wasm.cur_len.value, 1)[0]; }
1717

1818
static copy_and_free(ptr, size) {
1919
let slice = mem.u8(ptr, size).slice();

‎utils/wasm/svg.wasm‎

16.9 KB
Binary file not shown.

‎utils/wasm/tiff.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ let wasm;
99
}
1010

1111
class mem {
12+
static length() { return wasm.wlen(); }
1213
static alloc(size) { return wasm.walloc(size); }
1314
static free(ptr, size) { return wasm.wfree(ptr, size); }
1415
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
1516
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
16-
static length() { return new Uint32Array(wasm.memory.buffer, wasm.cur_len.value, 1)[0]; }
1717

1818
static copy_and_free(ptr, size) {
1919
let slice = mem.u8(ptr, size).slice();

0 commit comments

Comments
 (0)