imagescript 1.2.15 → 1.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ImageScript.d.ts +233 -223
- package/ImageScript.js +1658 -1646
- package/LICENSE +12 -619
- package/LICENSE.AGPL-3.0 +619 -0
- package/LICENSE.MIT +19 -0
- package/README.md +51 -46
- package/bench/_.mjs +165 -165
- package/bench/all.mjs +3 -3
- package/bench/blur.mjs +58 -58
- package/bench/flip.mjs +62 -62
- package/bench/overlay.mjs +34 -34
- package/bench/package.json +6 -6
- package/bench/readme.md +63 -63
- package/bench/resize.mjs +51 -51
- package/codecs/LICENSE +20 -20
- package/codecs/lib.d.ts +49 -49
- package/codecs/lib.js +5 -5
- package/codecs/node/index.js +2 -2
- package/codecs/node/index.mjs +5 -5
- package/codecs/package.json +13 -13
- package/codecs/readme.md +37 -37
- package/package.json +41 -41
- package/png/node.js +1137 -1137
- package/png/src/crc.mjs +48 -48
- package/png/src/mem.mjs +23 -23
- package/png/src/png.mjs +254 -254
- package/png/src/zlib.mjs +617 -617
- package/tsconfig.json +21 -21
- package/utils/mem.js +25 -25
- package/v2/codecs/magic.js +24 -24
- package/v2/framebuffer.d.ts +66 -66
- package/v2/framebuffer.js +2352 -2352
- package/v2/framebuffer.mjs +125 -125
- package/v2/framebuffer.rs +1263 -1263
- package/v2/index.d.ts +83 -83
- package/v2/index.js +260 -260
- package/v2/ops/blur.mjs +302 -302
- package/v2/ops/color.mjs +276 -276
- package/v2/ops/crop.mjs +63 -63
- package/v2/ops/fill.mjs +32 -32
- package/v2/ops/flip.mjs +32 -32
- package/v2/ops/index.mjs +8 -8
- package/v2/ops/iterator.mjs +33 -33
- package/v2/ops/overlay.mjs +62 -62
- package/v2/ops/resize.mjs +165 -165
- package/v2/ops/rotate.mjs +116 -116
- package/v2/util/mem.mjs +23 -23
- package/wasm/node/font.js +141 -141
- package/wasm/node/gif.js +76 -76
- package/wasm/node/jpeg.js +91 -91
- package/wasm/node/png.js +49 -49
- package/wasm/node/svg.js +55 -55
- package/wasm/node/tiff.js +46 -46
package/wasm/node/png.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
const wasm_name = 'png';
|
|
2
|
-
const { join } = require('path');
|
|
3
|
-
const { promises: { readFile } } = require('fs');
|
|
4
|
-
const wasm_path = process.env.IMAGESCRIPT_WASM_SIMD ? 'simd' : 'any';
|
|
5
|
-
|
|
6
|
-
let mod = null;
|
|
7
|
-
module.exports = {
|
|
8
|
-
async init() {
|
|
9
|
-
if (!mod) mod = new WebAssembly.Module(await readFile(join(__dirname, `../${wasm_path}/${wasm_name}.wasm`)));
|
|
10
|
-
|
|
11
|
-
return this.new();
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
new() {
|
|
15
|
-
let u8;
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
wfree, walloc, decode, memory,
|
|
19
|
-
width: wwidth, height: wheight,
|
|
20
|
-
} = new WebAssembly.Instance(mod, {
|
|
21
|
-
env: {
|
|
22
|
-
emscripten_notify_memory_growth() {
|
|
23
|
-
u8 = new Uint8Array(memory.buffer);
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
}).exports;
|
|
27
|
-
|
|
28
|
-
u8 = new Uint8Array(memory.buffer);
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
decode(buffer) {
|
|
32
|
-
const ptr = walloc(buffer.length);
|
|
33
|
-
|
|
34
|
-
u8.set(buffer, ptr);
|
|
35
|
-
const status = decode(ptr, buffer.length);
|
|
36
|
-
|
|
37
|
-
wfree(ptr);
|
|
38
|
-
if (0 > status) throw new Error(`png: failed to decode (${status})`);
|
|
39
|
-
|
|
40
|
-
const width = wwidth();
|
|
41
|
-
const height = wheight();
|
|
42
|
-
const framebuffer = u8.slice(status, status + 4 * width * height);
|
|
43
|
-
|
|
44
|
-
wfree(status);
|
|
45
|
-
return { width, height, framebuffer };
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
const wasm_name = 'png';
|
|
2
|
+
const { join } = require('path');
|
|
3
|
+
const { promises: { readFile } } = require('fs');
|
|
4
|
+
const wasm_path = process.env.IMAGESCRIPT_WASM_SIMD ? 'simd' : 'any';
|
|
5
|
+
|
|
6
|
+
let mod = null;
|
|
7
|
+
module.exports = {
|
|
8
|
+
async init() {
|
|
9
|
+
if (!mod) mod = new WebAssembly.Module(await readFile(join(__dirname, `../${wasm_path}/${wasm_name}.wasm`)));
|
|
10
|
+
|
|
11
|
+
return this.new();
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
new() {
|
|
15
|
+
let u8;
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
wfree, walloc, decode, memory,
|
|
19
|
+
width: wwidth, height: wheight,
|
|
20
|
+
} = new WebAssembly.Instance(mod, {
|
|
21
|
+
env: {
|
|
22
|
+
emscripten_notify_memory_growth() {
|
|
23
|
+
u8 = new Uint8Array(memory.buffer);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}).exports;
|
|
27
|
+
|
|
28
|
+
u8 = new Uint8Array(memory.buffer);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
decode(buffer) {
|
|
32
|
+
const ptr = walloc(buffer.length);
|
|
33
|
+
|
|
34
|
+
u8.set(buffer, ptr);
|
|
35
|
+
const status = decode(ptr, buffer.length);
|
|
36
|
+
|
|
37
|
+
wfree(ptr);
|
|
38
|
+
if (0 > status) throw new Error(`png: failed to decode (${status})`);
|
|
39
|
+
|
|
40
|
+
const width = wwidth();
|
|
41
|
+
const height = wheight();
|
|
42
|
+
const framebuffer = u8.slice(status, status + 4 * width * height);
|
|
43
|
+
|
|
44
|
+
wfree(status);
|
|
45
|
+
return { width, height, framebuffer };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
package/wasm/node/svg.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
const wasm_name = 'svg';
|
|
2
|
-
const { join } = require('path');
|
|
3
|
-
const { promises: { readFile } } = require('fs');
|
|
4
|
-
const wasm_path = process.env.IMAGESCRIPT_WASM_SIMD ? 'simd' : 'any';
|
|
5
|
-
|
|
6
|
-
let mod = null;
|
|
7
|
-
module.exports = {
|
|
8
|
-
async init() {
|
|
9
|
-
if (!mod) mod = new WebAssembly.Module(await readFile(join(__dirname, `../${wasm_path}/${wasm_name}.wasm`)));
|
|
10
|
-
|
|
11
|
-
return this.new();
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
new() {
|
|
15
|
-
const wasm = new WebAssembly.Instance(mod).exports;
|
|
16
|
-
|
|
17
|
-
class mem {
|
|
18
|
-
static length() { return wasm.wlen(); }
|
|
19
|
-
static alloc(size) { return wasm.walloc(size); }
|
|
20
|
-
static free(ptr, size) { return wasm.wfree(ptr, size); }
|
|
21
|
-
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
|
|
22
|
-
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
|
|
23
|
-
|
|
24
|
-
static copy_and_free(ptr, size) {
|
|
25
|
-
let slice = mem.u8(ptr, size).slice();
|
|
26
|
-
return (wasm.wfree(ptr, size), slice);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function load(buffer, fit) {
|
|
31
|
-
if (!fit) return rasterize(buffer, 0, 0);
|
|
32
|
-
if (fit.zoom) return rasterize(buffer, 1, fit.zoom);
|
|
33
|
-
if (fit.width) return rasterize(buffer, 2, fit.width);
|
|
34
|
-
if (fit.height) return rasterize(buffer, 3, fit.height);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function rasterize(buffer, fit, scale) {
|
|
38
|
-
const bptr = mem.alloc(buffer.length);
|
|
39
|
-
mem.u8(bptr, buffer.length).set(buffer);
|
|
40
|
-
const ptr = wasm.rasterize(bptr, buffer.length, fit, scale);
|
|
41
|
-
|
|
42
|
-
if (0 === ptr) throw new Error('svg: failed to parse');
|
|
43
|
-
if (1 === ptr) throw new Error('svg: failed to rasterize');
|
|
44
|
-
|
|
45
|
-
const framebuffer = {
|
|
46
|
-
width: wasm.rasterize_width(ptr),
|
|
47
|
-
height: wasm.rasterize_height(ptr),
|
|
48
|
-
buffer: mem.u8(wasm.rasterize_buffer(ptr), mem.length()).slice(),
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return (wasm.rasterize_free(ptr), framebuffer);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return { load, rasterize };
|
|
55
|
-
}
|
|
1
|
+
const wasm_name = 'svg';
|
|
2
|
+
const { join } = require('path');
|
|
3
|
+
const { promises: { readFile } } = require('fs');
|
|
4
|
+
const wasm_path = process.env.IMAGESCRIPT_WASM_SIMD ? 'simd' : 'any';
|
|
5
|
+
|
|
6
|
+
let mod = null;
|
|
7
|
+
module.exports = {
|
|
8
|
+
async init() {
|
|
9
|
+
if (!mod) mod = new WebAssembly.Module(await readFile(join(__dirname, `../${wasm_path}/${wasm_name}.wasm`)));
|
|
10
|
+
|
|
11
|
+
return this.new();
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
new() {
|
|
15
|
+
const wasm = new WebAssembly.Instance(mod).exports;
|
|
16
|
+
|
|
17
|
+
class mem {
|
|
18
|
+
static length() { return wasm.wlen(); }
|
|
19
|
+
static alloc(size) { return wasm.walloc(size); }
|
|
20
|
+
static free(ptr, size) { return wasm.wfree(ptr, size); }
|
|
21
|
+
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
|
|
22
|
+
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
|
|
23
|
+
|
|
24
|
+
static copy_and_free(ptr, size) {
|
|
25
|
+
let slice = mem.u8(ptr, size).slice();
|
|
26
|
+
return (wasm.wfree(ptr, size), slice);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function load(buffer, fit) {
|
|
31
|
+
if (!fit) return rasterize(buffer, 0, 0);
|
|
32
|
+
if (fit.zoom) return rasterize(buffer, 1, fit.zoom);
|
|
33
|
+
if (fit.width) return rasterize(buffer, 2, fit.width);
|
|
34
|
+
if (fit.height) return rasterize(buffer, 3, fit.height);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function rasterize(buffer, fit, scale) {
|
|
38
|
+
const bptr = mem.alloc(buffer.length);
|
|
39
|
+
mem.u8(bptr, buffer.length).set(buffer);
|
|
40
|
+
const ptr = wasm.rasterize(bptr, buffer.length, fit, scale);
|
|
41
|
+
|
|
42
|
+
if (0 === ptr) throw new Error('svg: failed to parse');
|
|
43
|
+
if (1 === ptr) throw new Error('svg: failed to rasterize');
|
|
44
|
+
|
|
45
|
+
const framebuffer = {
|
|
46
|
+
width: wasm.rasterize_width(ptr),
|
|
47
|
+
height: wasm.rasterize_height(ptr),
|
|
48
|
+
buffer: mem.u8(wasm.rasterize_buffer(ptr), mem.length()).slice(),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (wasm.rasterize_free(ptr), framebuffer);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { load, rasterize };
|
|
55
|
+
}
|
|
56
56
|
}
|
package/wasm/node/tiff.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
const wasm_name = 'tiff';
|
|
2
|
-
const { join } = require('path');
|
|
3
|
-
const { promises: { readFile } } = require('fs');
|
|
4
|
-
const wasm_path = process.env.IMAGESCRIPT_WASM_SIMD ? 'simd' : 'any';
|
|
5
|
-
|
|
6
|
-
let mod = null;
|
|
7
|
-
module.exports = {
|
|
8
|
-
async init() {
|
|
9
|
-
if (!mod) mod = new WebAssembly.Module(await readFile(join(__dirname, `../${wasm_path}/${wasm_name}.wasm`)));
|
|
10
|
-
|
|
11
|
-
return this.new();
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
new() {
|
|
15
|
-
const wasm = new WebAssembly.Instance(mod).exports;
|
|
16
|
-
|
|
17
|
-
class mem {
|
|
18
|
-
static length() { return wasm.wlen(); }
|
|
19
|
-
static alloc(size) { return wasm.walloc(size); }
|
|
20
|
-
static free(ptr, size) { return wasm.wfree(ptr, size); }
|
|
21
|
-
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
|
|
22
|
-
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
|
|
23
|
-
|
|
24
|
-
static copy_and_free(ptr, size) {
|
|
25
|
-
let slice = mem.u8(ptr, size).slice();
|
|
26
|
-
return (wasm.wfree(ptr, size), slice);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function decode(buffer) {
|
|
31
|
-
const bptr = mem.alloc(buffer.length);
|
|
32
|
-
mem.u8(bptr, buffer.length).set(buffer);
|
|
33
|
-
const ptr = wasm.decode(bptr, buffer.length);
|
|
34
|
-
if (0 === ptr) throw new Error('tiff: failed to decode');
|
|
35
|
-
|
|
36
|
-
const framebuffer = {
|
|
37
|
-
width: wasm.decode_width(ptr),
|
|
38
|
-
height: wasm.decode_height(ptr),
|
|
39
|
-
buffer: mem.u8(wasm.decode_buffer(ptr), mem.length()).slice(),
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return (wasm.decode_free(ptr), framebuffer);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return { decode, load: decode };
|
|
46
|
-
}
|
|
1
|
+
const wasm_name = 'tiff';
|
|
2
|
+
const { join } = require('path');
|
|
3
|
+
const { promises: { readFile } } = require('fs');
|
|
4
|
+
const wasm_path = process.env.IMAGESCRIPT_WASM_SIMD ? 'simd' : 'any';
|
|
5
|
+
|
|
6
|
+
let mod = null;
|
|
7
|
+
module.exports = {
|
|
8
|
+
async init() {
|
|
9
|
+
if (!mod) mod = new WebAssembly.Module(await readFile(join(__dirname, `../${wasm_path}/${wasm_name}.wasm`)));
|
|
10
|
+
|
|
11
|
+
return this.new();
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
new() {
|
|
15
|
+
const wasm = new WebAssembly.Instance(mod).exports;
|
|
16
|
+
|
|
17
|
+
class mem {
|
|
18
|
+
static length() { return wasm.wlen(); }
|
|
19
|
+
static alloc(size) { return wasm.walloc(size); }
|
|
20
|
+
static free(ptr, size) { return wasm.wfree(ptr, size); }
|
|
21
|
+
static u8(ptr, size) { return new Uint8Array(wasm.memory.buffer, ptr, size); }
|
|
22
|
+
static u32(ptr, size) { return new Uint32Array(wasm.memory.buffer, ptr, size); }
|
|
23
|
+
|
|
24
|
+
static copy_and_free(ptr, size) {
|
|
25
|
+
let slice = mem.u8(ptr, size).slice();
|
|
26
|
+
return (wasm.wfree(ptr, size), slice);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function decode(buffer) {
|
|
31
|
+
const bptr = mem.alloc(buffer.length);
|
|
32
|
+
mem.u8(bptr, buffer.length).set(buffer);
|
|
33
|
+
const ptr = wasm.decode(bptr, buffer.length);
|
|
34
|
+
if (0 === ptr) throw new Error('tiff: failed to decode');
|
|
35
|
+
|
|
36
|
+
const framebuffer = {
|
|
37
|
+
width: wasm.decode_width(ptr),
|
|
38
|
+
height: wasm.decode_height(ptr),
|
|
39
|
+
buffer: mem.u8(wasm.decode_buffer(ptr), mem.length()).slice(),
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (wasm.decode_free(ptr), framebuffer);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { decode, load: decode };
|
|
46
|
+
}
|
|
47
47
|
}
|