imagescript 1.2.9 → 1.2.16
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 +223 -0
- package/ImageScript.js +1646 -1682
- package/LICENSE +619 -0
- package/README.md +46 -45
- package/bench/_.mjs +166 -0
- package/bench/all.mjs +4 -0
- package/bench/blur.mjs +59 -0
- package/bench/flip.mjs +63 -0
- package/bench/overlay.mjs +35 -0
- package/bench/package.json +7 -0
- package/bench/readme.md +64 -0
- package/bench/resize.mjs +52 -0
- package/codecs/LICENSE +21 -0
- package/codecs/lib.d.ts +50 -0
- package/codecs/lib.js +6 -0
- package/codecs/lib.mjs +1 -0
- package/codecs/node/bin/arm64-darwin.node +0 -0
- package/{node → codecs/node/bin}/arm64-linux.node +0 -0
- package/codecs/node/bin/x64-darwin.node +0 -0
- package/{node → codecs/node/bin}/x64-linux.node +0 -0
- package/{node → codecs/node/bin}/x64-win32.node +0 -0
- package/codecs/node/index.js +3 -0
- package/codecs/node/index.mjs +6 -0
- package/codecs/package.json +14 -0
- package/codecs/readme.md +38 -0
- package/{wasm/simd.wasm → codecs/tests/gif.js} +0 -0
- package/{wasm/unknown.wasm → codecs/tests/jpeg.js} +0 -0
- package/codecs/tests/png.js +0 -0
- package/codecs/tests/results/gif/1024.nis.gif +0 -0
- package/codecs/tests/results/gif/1024.skyra.gif +0 -0
- package/codecs/tests/results/gif/256.nis.gif +0 -0
- package/codecs/tests/results/gif/256.skyra.gif +0 -0
- package/codecs/tests/results/jpeg/256.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/256.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/256.sharp.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.sharp.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.sharp.jpeg +0 -0
- package/codecs/tests/results/png/256.jis.png +0 -0
- package/codecs/tests/results/png/256.nis.png +0 -0
- package/codecs/tests/results/png/256.sharp.png +0 -0
- package/codecs/tests/results/png/256.upng.png +0 -0
- package/codecs/tests/results/png/512.jis.png +0 -0
- package/codecs/tests/results/png/512.nis.png +0 -0
- package/codecs/tests/results/png/512.sharp.png +0 -0
- package/codecs/tests/results/png/512.upng.png +0 -0
- package/codecs/tests/results/png/64.jis.png +0 -0
- package/codecs/tests/results/png/64.nis.png +0 -0
- package/codecs/tests/results/png/64.sharp.png +0 -0
- package/codecs/tests/results/png/64.upng.png +0 -0
- package/codecs/tests/webp.js +0 -0
- package/codecs/wasm/bin/codecs.wasm +0 -0
- package/codecs/wasm/bin/simd.wasm +0 -0
- package/codecs/wasm/bundle/browser.js +1 -0
- package/codecs/wasm/index.js +1 -0
- package/codecs/wasm/index.mjs +1 -0
- package/package.json +41 -28
- package/png/node.js +1137 -1137
- package/png/src/{crc.js → crc.mjs} +48 -48
- package/png/src/{mem.js → mem.mjs} +23 -23
- package/png/src/{png.js → png.mjs} +254 -254
- package/png/src/{zlib.js → zlib.mjs} +617 -617
- package/tsconfig.json +21 -0
- 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 -2371
- package/v2/framebuffer.mjs +125 -125
- package/v2/framebuffer.rs +1264 -0
- package/v2/index.d.ts +83 -83
- package/v2/index.js +260 -260
- package/v2/ops/{blur.js → blur.mjs} +302 -302
- package/v2/ops/{color.js → color.mjs} +276 -276
- package/v2/ops/{crop.js → crop.mjs} +63 -63
- package/v2/ops/{fill.js → fill.mjs} +32 -32
- package/v2/ops/{flip.js → flip.mjs} +32 -32
- package/v2/ops/index.mjs +9 -0
- package/v2/ops/{iterator.js → iterator.mjs} +33 -33
- package/v2/ops/overlay.mjs +63 -0
- package/v2/ops/{resize.js → resize.mjs} +165 -165
- package/v2/ops/{rotate.js → rotate.mjs} +116 -117
- package/v2/util/{mem.js → mem.mjs} +24 -26
- package/wasm/any/font.wasm +0 -0
- package/wasm/any/png.wasm +0 -0
- 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 -0
- package/wasm/node/svg.js +55 -55
- package/wasm/node/tiff.js +46 -46
- package/node/arm64-darwin.node +0 -0
- package/node/index.js +0 -7
- package/node/x64-darwin.node +0 -0
- package/v2/ops/index.js +0 -9
- package/v2/ops/overlay.js +0 -56
- package/wasm/node.js +0 -23
- package/wasm/web.js +0 -10
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
|
}
|
package/node/arm64-darwin.node
DELETED
|
Binary file
|
package/node/index.js
DELETED
package/node/x64-darwin.node
DELETED
|
Binary file
|
package/v2/ops/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * as flip from './flip.js';
|
|
2
|
-
export * as fill from './fill.js';
|
|
3
|
-
export * as blur from './blur.js';
|
|
4
|
-
export * as crop from './crop.js';
|
|
5
|
-
export * as color from './color.js';
|
|
6
|
-
export * as resize from './resize.js';
|
|
7
|
-
export * as rotate from './rotate.js';
|
|
8
|
-
export * as overlay from './overlay.js';
|
|
9
|
-
export * as iterator from './iterator.js';
|
package/v2/ops/overlay.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { blend } from './color.js';
|
|
2
|
-
|
|
3
|
-
export function replace(bg, fg, x, y) {
|
|
4
|
-
const fwidth = fg.width | 0;
|
|
5
|
-
const bwidth = bg.width | 0;
|
|
6
|
-
const fheight = fg.height | 0;
|
|
7
|
-
const bheight = bg.height | 0;
|
|
8
|
-
let mw = Math.min(bwidth, fwidth) | 0;
|
|
9
|
-
let mh = Math.min(bheight, fheight) | 0;
|
|
10
|
-
|
|
11
|
-
const b32 = bg.u32;
|
|
12
|
-
const f32 = fg.u32;
|
|
13
|
-
|
|
14
|
-
// todo: range
|
|
15
|
-
// todo: negative speed
|
|
16
|
-
for (let yy = y | 0; yy < mh; yy++) {
|
|
17
|
-
const yoffset = yy * bwidth;
|
|
18
|
-
const yyoffset = fwidth * (yy - y);
|
|
19
|
-
|
|
20
|
-
for (let xx = x | 0; xx < mw; xx++) {
|
|
21
|
-
b32[xx + yoffset] = f32[xx - x + yyoffset];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function overlay(background, foreground, x, y) {
|
|
27
|
-
x = x | 0;
|
|
28
|
-
y = y | 0;
|
|
29
|
-
const fwidth = foreground.width | 0;
|
|
30
|
-
const bwidth = background.width | 0;
|
|
31
|
-
const fheight = foreground.height | 0;
|
|
32
|
-
const bheight = background.height | 0;
|
|
33
|
-
const mw = Math.min(bwidth, fwidth) | 0;
|
|
34
|
-
const mh = Math.min(bheight, fheight) | 0;
|
|
35
|
-
|
|
36
|
-
const fview = foreground.view;
|
|
37
|
-
const bview = background.view;
|
|
38
|
-
|
|
39
|
-
// todo: fix range
|
|
40
|
-
// todo: negative perf
|
|
41
|
-
for (let yy = y | 0; yy < mh; yy++) {
|
|
42
|
-
const yoffset = yy * bwidth;
|
|
43
|
-
const yyoffset = fwidth * (yy - y);
|
|
44
|
-
|
|
45
|
-
for (let xx = x | 0; xx < mw; xx++) {
|
|
46
|
-
const offset = 4 * (xx + yoffset);
|
|
47
|
-
const fg = fview.getUint32(4 * (xx - x + yyoffset), false);
|
|
48
|
-
|
|
49
|
-
const bg = bview.getUint32(offset, false);
|
|
50
|
-
if ((fg & 0xff) === 0xff) bview.setUint32(offset, fg, false);
|
|
51
|
-
else if ((fg & 0xff) === 0x00) bview.setUint32(offset, bg, false);
|
|
52
|
-
|
|
53
|
-
else bview.setUint32(offset, blend(fg, bg), false);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
package/wasm/node.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
let mod = async () => {
|
|
2
|
-
let t;
|
|
3
|
-
|
|
4
|
-
{
|
|
5
|
-
const simd = WebAssembly.validate(Uint8Array.of(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11));
|
|
6
|
-
t = new WebAssembly.Module(await require('fs').promises.readFile(require('path').join(__dirname, `${simd ? 'simd' : 'unknown'}.wasm`)));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return (mod = () => t)();
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
module.exports = async function codecs() {
|
|
13
|
-
const wasm = new WebAssembly.Instance(await mod(), {});
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
png: null,
|
|
17
|
-
gif: null,
|
|
18
|
-
svg: null,
|
|
19
|
-
webp: null,
|
|
20
|
-
jpeg: null,
|
|
21
|
-
tiff: null,
|
|
22
|
-
};
|
|
23
|
-
}
|