imagescript 1.2.15 → 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.
Files changed (51) hide show
  1. package/ImageScript.d.ts +223 -223
  2. package/ImageScript.js +1646 -1646
  3. package/LICENSE +619 -619
  4. package/README.md +46 -46
  5. package/bench/_.mjs +165 -165
  6. package/bench/all.mjs +3 -3
  7. package/bench/blur.mjs +58 -58
  8. package/bench/flip.mjs +62 -62
  9. package/bench/overlay.mjs +34 -34
  10. package/bench/package.json +6 -6
  11. package/bench/readme.md +63 -63
  12. package/bench/resize.mjs +51 -51
  13. package/codecs/LICENSE +20 -20
  14. package/codecs/lib.d.ts +49 -49
  15. package/codecs/lib.js +5 -5
  16. package/codecs/node/index.js +2 -2
  17. package/codecs/node/index.mjs +5 -5
  18. package/codecs/package.json +13 -13
  19. package/codecs/readme.md +37 -37
  20. package/package.json +41 -41
  21. package/png/node.js +1137 -1137
  22. package/png/src/crc.mjs +48 -48
  23. package/png/src/mem.mjs +23 -23
  24. package/png/src/png.mjs +254 -254
  25. package/png/src/zlib.mjs +617 -617
  26. package/tsconfig.json +21 -21
  27. package/utils/mem.js +25 -25
  28. package/v2/codecs/magic.js +24 -24
  29. package/v2/framebuffer.d.ts +66 -66
  30. package/v2/framebuffer.js +2352 -2352
  31. package/v2/framebuffer.mjs +125 -125
  32. package/v2/framebuffer.rs +1263 -1263
  33. package/v2/index.d.ts +83 -83
  34. package/v2/index.js +260 -260
  35. package/v2/ops/blur.mjs +302 -302
  36. package/v2/ops/color.mjs +276 -276
  37. package/v2/ops/crop.mjs +63 -63
  38. package/v2/ops/fill.mjs +32 -32
  39. package/v2/ops/flip.mjs +32 -32
  40. package/v2/ops/index.mjs +8 -8
  41. package/v2/ops/iterator.mjs +33 -33
  42. package/v2/ops/overlay.mjs +62 -62
  43. package/v2/ops/resize.mjs +165 -165
  44. package/v2/ops/rotate.mjs +116 -116
  45. package/v2/util/mem.mjs +23 -23
  46. package/wasm/node/font.js +141 -141
  47. package/wasm/node/gif.js +76 -76
  48. package/wasm/node/jpeg.js +91 -91
  49. package/wasm/node/png.js +49 -49
  50. package/wasm/node/svg.js +55 -55
  51. package/wasm/node/tiff.js +46 -46
package/bench/flip.mjs CHANGED
@@ -1,63 +1,63 @@
1
- import { sync, async, format } from './_.mjs';
2
-
3
- import jimp from 'jimp';
4
- import sharp from 'sharp';
5
- import v2 from '../v2/framebuffer.mjs';
6
- import * as imagers from '@evan/wasm/target/image/node.mjs';
7
- import * as v2_wasm from '@evan/wasm/target/imagescript/node.mjs';
8
-
9
- {
10
- const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
11
-
12
- const images = {
13
- v2: new v2(256, 256, rgba),
14
- imagers: imagers.framebuffer.from(256, 256, rgba),
15
- v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
16
- sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
17
- jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
18
- };
19
-
20
- console.log(format({
21
- percentiles: false,
22
- title: 'flip horizontal (256)',
23
-
24
- results: {
25
- jimp: sync(1e4, () => images.jimp.flip(true, false)),
26
- imagescript: sync(1e4, () => images.v2.flip('horizontal')),
27
- sharp: await async(1e4, () => images.sharp.flip().toBuffer()),
28
- 'image-rs (wasm)': sync(1e4, () => images.imagers.flip_horizontal()),
29
- 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.flip_horizontal(images.v2_wasm)),
30
- },
31
- }));
32
-
33
- images.v2_wasm.drop();
34
- images.imagers.drop();
35
- }
36
-
37
- {
38
- const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
39
-
40
- const images = {
41
- v2: new v2(256, 256, rgba),
42
- imagers: imagers.framebuffer.from(256, 256, rgba),
43
- v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
44
- sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
45
- jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
46
- };
47
-
48
- console.log(format({
49
- percentiles: false,
50
- title: 'flip vertical (256)',
51
-
52
- results: {
53
- jimp: sync(1e4, () => images.jimp.flip(false, true)),
54
- imagescript: sync(1e4, () => images.v2.flip('vertical')),
55
- sharp: await async(1e4, () => images.sharp.flop().toBuffer()),
56
- 'image-rs (wasm)': sync(1e4, () => images.imagers.flip_vertical()),
57
- 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.flip_vertical(images.v2_wasm)),
58
- },
59
- }));
60
-
61
- images.v2_wasm.drop();
62
- images.imagers.drop();
1
+ import { sync, async, format } from './_.mjs';
2
+
3
+ import jimp from 'jimp';
4
+ import sharp from 'sharp';
5
+ import v2 from '../v2/framebuffer.mjs';
6
+ import * as imagers from '@evan/wasm/target/image/node.mjs';
7
+ import * as v2_wasm from '@evan/wasm/target/imagescript/node.mjs';
8
+
9
+ {
10
+ const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
11
+
12
+ const images = {
13
+ v2: new v2(256, 256, rgba),
14
+ imagers: imagers.framebuffer.from(256, 256, rgba),
15
+ v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
16
+ sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
17
+ jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
18
+ };
19
+
20
+ console.log(format({
21
+ percentiles: false,
22
+ title: 'flip horizontal (256)',
23
+
24
+ results: {
25
+ jimp: sync(1e4, () => images.jimp.flip(true, false)),
26
+ imagescript: sync(1e4, () => images.v2.flip('horizontal')),
27
+ sharp: await async(1e4, () => images.sharp.flip().toBuffer()),
28
+ 'image-rs (wasm)': sync(1e4, () => images.imagers.flip_horizontal()),
29
+ 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.flip_horizontal(images.v2_wasm)),
30
+ },
31
+ }));
32
+
33
+ images.v2_wasm.drop();
34
+ images.imagers.drop();
35
+ }
36
+
37
+ {
38
+ const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
39
+
40
+ const images = {
41
+ v2: new v2(256, 256, rgba),
42
+ imagers: imagers.framebuffer.from(256, 256, rgba),
43
+ v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
44
+ sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
45
+ jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
46
+ };
47
+
48
+ console.log(format({
49
+ percentiles: false,
50
+ title: 'flip vertical (256)',
51
+
52
+ results: {
53
+ jimp: sync(1e4, () => images.jimp.flip(false, true)),
54
+ imagescript: sync(1e4, () => images.v2.flip('vertical')),
55
+ sharp: await async(1e4, () => images.sharp.flop().toBuffer()),
56
+ 'image-rs (wasm)': sync(1e4, () => images.imagers.flip_vertical()),
57
+ 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.flip_vertical(images.v2_wasm)),
58
+ },
59
+ }));
60
+
61
+ images.v2_wasm.drop();
62
+ images.imagers.drop();
63
63
  }
package/bench/overlay.mjs CHANGED
@@ -1,35 +1,35 @@
1
- import { sync, async, format } from './_.mjs';
2
-
3
- import jimp from 'jimp';
4
- import sharp from 'sharp';
5
- import v2 from '../v2/framebuffer.mjs';
6
- import * as imagers from '@evan/wasm/target/image/node.mjs';
7
- import * as v2_wasm from '@evan/wasm/target/imagescript/node.mjs';
8
-
9
- {
10
- const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
11
-
12
- const images = {
13
- v2: new v2(256, 256, rgba),
14
- imagers: imagers.framebuffer.from(256, 256, rgba),
15
- v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
16
- sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
17
- jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
18
- };
19
-
20
- console.log(format({
21
- percentiles: false,
22
- title: 'overlay(256x256)',
23
-
24
- results: {
25
- jimp: sync(1e4, () => images.jimp.composite(images.jimp, 0, 0)),
26
- imagescript: sync(1e4, () => images.v2.overlay(images.v2, 0, 0)),
27
- 'image-rs (wasm)': sync(1e4, () => images.imagers.overlay(images.imagers, 0, 0)),
28
- 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.overlay(images.v2_wasm, images.v2_wasm, 0, 0)),
29
- sharp: await async(1e4, () => images.sharp.composite([{ input: rgba, raw: { width: 256, height: 256, channels: 4 } }]).toBuffer()),
30
- },
31
- }));
32
-
33
- images.v2_wasm.drop();
34
- images.imagers.drop();
1
+ import { sync, async, format } from './_.mjs';
2
+
3
+ import jimp from 'jimp';
4
+ import sharp from 'sharp';
5
+ import v2 from '../v2/framebuffer.mjs';
6
+ import * as imagers from '@evan/wasm/target/image/node.mjs';
7
+ import * as v2_wasm from '@evan/wasm/target/imagescript/node.mjs';
8
+
9
+ {
10
+ const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
11
+
12
+ const images = {
13
+ v2: new v2(256, 256, rgba),
14
+ imagers: imagers.framebuffer.from(256, 256, rgba),
15
+ v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
16
+ sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
17
+ jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
18
+ };
19
+
20
+ console.log(format({
21
+ percentiles: false,
22
+ title: 'overlay(256x256)',
23
+
24
+ results: {
25
+ jimp: sync(1e4, () => images.jimp.composite(images.jimp, 0, 0)),
26
+ imagescript: sync(1e4, () => images.v2.overlay(images.v2, 0, 0)),
27
+ 'image-rs (wasm)': sync(1e4, () => images.imagers.overlay(images.imagers, 0, 0)),
28
+ 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.overlay(images.v2_wasm, images.v2_wasm, 0, 0)),
29
+ sharp: await async(1e4, () => images.sharp.composite([{ input: rgba, raw: { width: 256, height: 256, channels: 4 } }]).toBuffer()),
30
+ },
31
+ }));
32
+
33
+ images.v2_wasm.drop();
34
+ images.imagers.drop();
35
35
  }
@@ -1,7 +1,7 @@
1
- {
2
- "dependencies": {
3
- "jimp": "^0.16.1",
4
- "sharp": "^0.29.2",
5
- "@evan/wasm": "^0.0.92"
6
- }
1
+ {
2
+ "dependencies": {
3
+ "jimp": "^0.16.1",
4
+ "sharp": "^0.29.2",
5
+ "@evan/wasm": "^0.0.92"
6
+ }
7
7
  }
package/bench/readme.md CHANGED
@@ -1,64 +1,64 @@
1
- these benchmarks are purely for v2 progress tracking
2
-
3
- `node all.mjs`
4
- ```js
5
- resize linear (256 -> 1024)
6
- ┌─────────────────────────────────────────────────────────────────────────────┐
7
- │ imagescript │ 19,503,902 ns/iter (18,861,626..27,912,168 ns/iter) │
8
- │ imagescript-rs (wasm) │ 17,713,101 ns/iter (17,476,625..23,760,793 ns/iter) │
9
- └─────────────────────────────────────────────────────────────────────────────┘
10
- resize cubic (256 -> 1024)
11
- ┌────────────────────────────────────────────────────────────────────────────────┐
12
- │ imagescript │ 235,246,467 ns/iter (229,790,251..354,907,209 ns/iter) │
13
- │ sharp │ 14,342,381 ns/iter (10,830,958..39,727,583 ns/iter) │
14
- │ imagescript-rs (wasm) │ 63,684,581 ns/iter (62,884,708..75,180,751 ns/iter) │
15
- └────────────────────────────────────────────────────────────────────────────────┘
16
- flip horizontal (256)
17
- ┌─────────────────────────────────────────────────────────────────────────────────┐
18
- │ jimp │ 1,259,846 ns/iter (1,209,542..2,151,208 ns/iter) │
19
- │ imagescript │ 26,333 ns/iter (24,626..93,501 ns/iter) │
20
- │ sharp │ 24,134,341 ns/iter (274,959..210,144,563,500 ns/iter) │
21
- │ image-rs (wasm) │ 43,797 ns/iter (43,501..74,293 ns/iter) │
22
- │ imagescript-rs (wasm) │ 14,309 ns/iter (13,959..49,333 ns/iter) │
23
- └─────────────────────────────────────────────────────────────────────────────────┘
24
- flip vertical (256)
25
- ┌───────────────────────────────────────────────────────────────────────────┐
26
- │ jimp │ 1,281,557 ns/iter (1,223,292..7,604,917 ns/iter) │
27
- │ imagescript │ 54,151 ns/iter (53,333..89,959 ns/iter) │
28
- │ sharp │ 2,552,946 ns/iter (513,959..10,188,876 ns/iter) │
29
- │ image-rs (wasm) │ 30,475 ns/iter (30,167..88,250 ns/iter) │
30
- │ imagescript-rs (wasm) │ 13,747 ns/iter (13,542..27,042 ns/iter) │
31
- └───────────────────────────────────────────────────────────────────────────┘
32
- overlay(256x256)
33
- ┌─────────────────────────────────────────────────────────────────────────────────┐
34
- │ jimp │ 3,428,386 ns/iter (3,372,335..5,125,459 ns/iter) │
35
- │ imagescript │ 259,099 ns/iter (256,583..310,334 ns/iter) │
36
- │ image-rs (wasm) │ 541,678 ns/iter (533,166..1,509,710 ns/iter) │
37
- │ imagescript-rs (wasm) │ 143,653 ns/iter (137,293..1,242,793 ns/iter) │
38
- │ sharp │ 28,689,423 ns/iter (1,837,000..210,144,590,042 ns/iter) │
39
- └─────────────────────────────────────────────────────────────────────────────────┘
40
- resize nearest (256 -> 1024)
41
- ┌───────────────────────────────────────────────────────────────────────────────┐
42
- │ imagescript │ 1,452,792 ns/iter (1,327,334..13,043,958 ns/iter) │
43
- │ jimp │ 6,053,008 ns/iter (5,835,042..9,540,835 ns/iter) │
44
- │ sharp │ 6,209,299 ns/iter (2,089,376..15,344,367,876 ns/iter) │
45
- │ image-rs (wasm) │ 4,823,582 ns/iter (4,809,042..7,176,000 ns/iter) │
46
- │ imagescript-rs (wasm) │ 600,103 ns/iter (597,042..802,751 ns/iter) │
47
- └───────────────────────────────────────────────────────────────────────────────┘
48
- blur (5.0f/256x256)
49
- ┌─────────────────────────────────────────────────────────────────────────────────┐
50
- │ jimp │ 3,752,613 ns/iter (3,338,751..17,802,125 ns/iter) │
51
- │ imagescript │ 1,982,010 ns/iter (1,935,459..2,907,833 ns/iter) │
52
- │ sharp │ 36,079,515 ns/iter (2,465,000..210,155,512,001 ns/iter) │
53
- │ image-rs (wasm) │ 6,050,020 ns/iter (6,037,125..8,032,876 ns/iter) │
54
- │ imagescript-rs (wasm) │ 1,288,080 ns/iter (1,263,834..1,699,542 ns/iter) │
55
- └─────────────────────────────────────────────────────────────────────────────────┘
56
- blur (5.0f/1024x1024)
57
- ┌───────────────────────────────────────────────────────────────────────────────┐
58
- │ jimp │ 105,250,057 ns/iter (89,942,042..302,817,625 ns/iter) │
59
- │ imagescript │ 31,996,324 ns/iter (31,372,417..101,801,209 ns/iter) │
60
- │ sharp │ 20,019,663 ns/iter (18,547,168..66,675,542 ns/iter) │
61
- │ image-rs (wasm) │ 97,924,025 ns/iter (96,879,584..158,598,250 ns/iter) │
62
- │ imagescript-rs (wasm) │ 20,960,014 ns/iter (20,533,709..104,136,960 ns/iter) │
63
- └───────────────────────────────────────────────────────────────────────────────┘
1
+ these benchmarks are purely for v2 progress tracking
2
+
3
+ `node all.mjs`
4
+ ```js
5
+ resize linear (256 -> 1024)
6
+ ┌─────────────────────────────────────────────────────────────────────────────┐
7
+ │ imagescript │ 19,503,902 ns/iter (18,861,626..27,912,168 ns/iter) │
8
+ │ imagescript-rs (wasm) │ 17,713,101 ns/iter (17,476,625..23,760,793 ns/iter) │
9
+ └─────────────────────────────────────────────────────────────────────────────┘
10
+ resize cubic (256 -> 1024)
11
+ ┌────────────────────────────────────────────────────────────────────────────────┐
12
+ │ imagescript │ 235,246,467 ns/iter (229,790,251..354,907,209 ns/iter) │
13
+ │ sharp │ 14,342,381 ns/iter (10,830,958..39,727,583 ns/iter) │
14
+ │ imagescript-rs (wasm) │ 63,684,581 ns/iter (62,884,708..75,180,751 ns/iter) │
15
+ └────────────────────────────────────────────────────────────────────────────────┘
16
+ flip horizontal (256)
17
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
18
+ │ jimp │ 1,259,846 ns/iter (1,209,542..2,151,208 ns/iter) │
19
+ │ imagescript │ 26,333 ns/iter (24,626..93,501 ns/iter) │
20
+ │ sharp │ 24,134,341 ns/iter (274,959..210,144,563,500 ns/iter) │
21
+ │ image-rs (wasm) │ 43,797 ns/iter (43,501..74,293 ns/iter) │
22
+ │ imagescript-rs (wasm) │ 14,309 ns/iter (13,959..49,333 ns/iter) │
23
+ └─────────────────────────────────────────────────────────────────────────────────┘
24
+ flip vertical (256)
25
+ ┌───────────────────────────────────────────────────────────────────────────┐
26
+ │ jimp │ 1,281,557 ns/iter (1,223,292..7,604,917 ns/iter) │
27
+ │ imagescript │ 54,151 ns/iter (53,333..89,959 ns/iter) │
28
+ │ sharp │ 2,552,946 ns/iter (513,959..10,188,876 ns/iter) │
29
+ │ image-rs (wasm) │ 30,475 ns/iter (30,167..88,250 ns/iter) │
30
+ │ imagescript-rs (wasm) │ 13,747 ns/iter (13,542..27,042 ns/iter) │
31
+ └───────────────────────────────────────────────────────────────────────────┘
32
+ overlay(256x256)
33
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
34
+ │ jimp │ 3,428,386 ns/iter (3,372,335..5,125,459 ns/iter) │
35
+ │ imagescript │ 259,099 ns/iter (256,583..310,334 ns/iter) │
36
+ │ image-rs (wasm) │ 541,678 ns/iter (533,166..1,509,710 ns/iter) │
37
+ │ imagescript-rs (wasm) │ 143,653 ns/iter (137,293..1,242,793 ns/iter) │
38
+ │ sharp │ 28,689,423 ns/iter (1,837,000..210,144,590,042 ns/iter) │
39
+ └─────────────────────────────────────────────────────────────────────────────────┘
40
+ resize nearest (256 -> 1024)
41
+ ┌───────────────────────────────────────────────────────────────────────────────┐
42
+ │ imagescript │ 1,452,792 ns/iter (1,327,334..13,043,958 ns/iter) │
43
+ │ jimp │ 6,053,008 ns/iter (5,835,042..9,540,835 ns/iter) │
44
+ │ sharp │ 6,209,299 ns/iter (2,089,376..15,344,367,876 ns/iter) │
45
+ │ image-rs (wasm) │ 4,823,582 ns/iter (4,809,042..7,176,000 ns/iter) │
46
+ │ imagescript-rs (wasm) │ 600,103 ns/iter (597,042..802,751 ns/iter) │
47
+ └───────────────────────────────────────────────────────────────────────────────┘
48
+ blur (5.0f/256x256)
49
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
50
+ │ jimp │ 3,752,613 ns/iter (3,338,751..17,802,125 ns/iter) │
51
+ │ imagescript │ 1,982,010 ns/iter (1,935,459..2,907,833 ns/iter) │
52
+ │ sharp │ 36,079,515 ns/iter (2,465,000..210,155,512,001 ns/iter) │
53
+ │ image-rs (wasm) │ 6,050,020 ns/iter (6,037,125..8,032,876 ns/iter) │
54
+ │ imagescript-rs (wasm) │ 1,288,080 ns/iter (1,263,834..1,699,542 ns/iter) │
55
+ └─────────────────────────────────────────────────────────────────────────────────┘
56
+ blur (5.0f/1024x1024)
57
+ ┌───────────────────────────────────────────────────────────────────────────────┐
58
+ │ jimp │ 105,250,057 ns/iter (89,942,042..302,817,625 ns/iter) │
59
+ │ imagescript │ 31,996,324 ns/iter (31,372,417..101,801,209 ns/iter) │
60
+ │ sharp │ 20,019,663 ns/iter (18,547,168..66,675,542 ns/iter) │
61
+ │ image-rs (wasm) │ 97,924,025 ns/iter (96,879,584..158,598,250 ns/iter) │
62
+ │ imagescript-rs (wasm) │ 20,960,014 ns/iter (20,533,709..104,136,960 ns/iter) │
63
+ └───────────────────────────────────────────────────────────────────────────────┘
64
64
  ```
package/bench/resize.mjs CHANGED
@@ -1,52 +1,52 @@
1
- import { sync, async, format } from './_.mjs';
2
-
3
- import jimp from 'jimp';
4
- import sharp from 'sharp';
5
- import v2 from '../v2/framebuffer.mjs';
6
- import * as imagers from '@evan/wasm/target/image/node.mjs';
7
- import * as v2_wasm from '@evan/wasm/target/imagescript/node.mjs';
8
- const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
9
-
10
- const images = {
11
- v2: () => new v2(256, 256, rgba),
12
- v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
13
- imagers: imagers.framebuffer.from(256, 256, rgba),
14
- sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
15
- jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
16
- };
17
-
18
- console.log(format({
19
- percentiles: false,
20
- title: 'resize linear (256 -> 1024)',
21
-
22
- results: {
23
- // others don't have linear
24
- imagescript: sync(1e3, () => images.v2().resize('linear', 1024, 1024)),
25
- 'imagescript-rs (wasm)': sync(1e3, () => v2_wasm.resize(images.v2_wasm, 'linear', 1024, 1024).drop()),
26
- },
27
- }));
28
-
29
- console.log(format({
30
- percentiles: false,
31
- title: 'resize cubic (256 -> 1024)',
32
-
33
- results: {
34
- // others don't have cubic
35
- imagescript: sync(1e3, () => images.v2().resize('cubic', 1024, 1024)),
36
- sharp: await async(1e3, () => images.sharp.resize(1024, 1024, { kernel: 'cubic' }).toBuffer()),
37
- 'imagescript-rs (wasm)': sync(1e3, () => v2_wasm.resize(images.v2_wasm, 'cubic', 1024, 1024).drop()),
38
- },
39
- }));
40
-
41
- console.log(format({
42
- percentiles: false,
43
- title: 'resize nearest (256 -> 1024)',
44
-
45
- results: {
46
- imagescript: sync(1e4, () => images.v2().resize('nearest', 1024, 1024)),
47
- jimp: sync(1e4, () => images.jimp.resize(1024, 1024, jimp.RESIZE_NEAREST_NEIGHBOR)),
48
- sharp: await async(1e4, () => images.sharp.resize(1024, 1024, { kernel: 'nearest' }).toBuffer()),
49
- 'image-rs (wasm)': sync(1e4, () => imagers.resize(images.imagers, 'nearest', 1024, 1024).drop()),
50
- 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.resize(images.v2_wasm, 'nearest', 1024, 1024).drop()),
51
- },
1
+ import { sync, async, format } from './_.mjs';
2
+
3
+ import jimp from 'jimp';
4
+ import sharp from 'sharp';
5
+ import v2 from '../v2/framebuffer.mjs';
6
+ import * as imagers from '@evan/wasm/target/image/node.mjs';
7
+ import * as v2_wasm from '@evan/wasm/target/imagescript/node.mjs';
8
+ const rgba = new Uint8Array(4 * 256 * 256).map((_, i) => i % 256);
9
+
10
+ const images = {
11
+ v2: () => new v2(256, 256, rgba),
12
+ v2_wasm: v2_wasm.framebuffer.from(256, 256, rgba),
13
+ imagers: imagers.framebuffer.from(256, 256, rgba),
14
+ sharp: sharp(rgba, { raw: { width: 256, height: 256, channels: 4 } }),
15
+ jimp: await new Promise(r => new jimp({ width: 256, height: 256, data: rgba }, (_, i) => r(i))),
16
+ };
17
+
18
+ console.log(format({
19
+ percentiles: false,
20
+ title: 'resize linear (256 -> 1024)',
21
+
22
+ results: {
23
+ // others don't have linear
24
+ imagescript: sync(1e3, () => images.v2().resize('linear', 1024, 1024)),
25
+ 'imagescript-rs (wasm)': sync(1e3, () => v2_wasm.resize(images.v2_wasm, 'linear', 1024, 1024).drop()),
26
+ },
27
+ }));
28
+
29
+ console.log(format({
30
+ percentiles: false,
31
+ title: 'resize cubic (256 -> 1024)',
32
+
33
+ results: {
34
+ // others don't have cubic
35
+ imagescript: sync(1e3, () => images.v2().resize('cubic', 1024, 1024)),
36
+ sharp: await async(1e3, () => images.sharp.resize(1024, 1024, { kernel: 'cubic' }).toBuffer()),
37
+ 'imagescript-rs (wasm)': sync(1e3, () => v2_wasm.resize(images.v2_wasm, 'cubic', 1024, 1024).drop()),
38
+ },
39
+ }));
40
+
41
+ console.log(format({
42
+ percentiles: false,
43
+ title: 'resize nearest (256 -> 1024)',
44
+
45
+ results: {
46
+ imagescript: sync(1e4, () => images.v2().resize('nearest', 1024, 1024)),
47
+ jimp: sync(1e4, () => images.jimp.resize(1024, 1024, jimp.RESIZE_NEAREST_NEIGHBOR)),
48
+ sharp: await async(1e4, () => images.sharp.resize(1024, 1024, { kernel: 'nearest' }).toBuffer()),
49
+ 'image-rs (wasm)': sync(1e4, () => imagers.resize(images.imagers, 'nearest', 1024, 1024).drop()),
50
+ 'imagescript-rs (wasm)': sync(1e4, () => v2_wasm.resize(images.v2_wasm, 'nearest', 1024, 1024).drop()),
51
+ },
52
52
  }));
package/codecs/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021-present matmen, evanwashere
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present matmen, evanwashere
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/codecs/lib.d.ts CHANGED
@@ -1,50 +1,50 @@
1
- declare module '@imagescript/codecs' {
2
- type wah = { width: number, height: number };
3
- type jpeg_encode_options = wah & { quality?: number };
4
- type webp_encode_options = wah & { quality?: number };
5
-
6
- type png_encode_options = wah & {
7
- compression?: 'fast' | 'best' | 'default',
8
- filter?: 'up' | 'sub' | 'none' | 'paeth' | 'average',
9
- };
10
-
11
- type gif_frame_options = wah & {
12
- x?: number,
13
- y?: number,
14
- delay?: number,
15
- speed?: number,
16
- colors?: number,
17
- quality?: number,
18
- dispose?: 'any' | 'keep' | 'previous' | 'background',
19
- }
20
-
21
-
22
- class gif_encoder {
23
- width: number;
24
- height: number;
25
-
26
- constructor(width: number, height: number): this;
27
- add(buffer: ArrayBufferView, options: gif_frame_options): void;
28
- finish(options: { repeat?: number, comment: string, application?: string }): Uint8Array;
29
- }
30
-
31
-
32
- export interface gif {
33
- encoder: gif_encoder,
34
- }
35
-
36
- export interface png {
37
- encode(buffer: ArrayBufferView, options: png_encode_options): Uint8Array,
38
- encode_async(buffer: ArrayBufferView, options: png_encode_options): Promise<Uint8Array>,
39
- }
40
-
41
- export interface jpeg {
42
- encode(buffer: ArrayBufferView, options: png_encode_options): Uint8Array,
43
- encode_async(buffer: ArrayBufferView, options: png_encode_options): Promise<Uint8Array>,
44
- }
45
-
46
- export interface webp {
47
- encode(buffer: ArrayBufferView, options: png_encode_options): Uint8Array,
48
- encode_async(buffer: ArrayBufferView, options: png_encode_options): Promise<Uint8Array>,
49
- }
1
+ declare module '@imagescript/codecs' {
2
+ type wah = { width: number, height: number };
3
+ type jpeg_encode_options = wah & { quality?: number };
4
+ type webp_encode_options = wah & { quality?: number };
5
+
6
+ type png_encode_options = wah & {
7
+ compression?: 'fast' | 'best' | 'default',
8
+ filter?: 'up' | 'sub' | 'none' | 'paeth' | 'average',
9
+ };
10
+
11
+ type gif_frame_options = wah & {
12
+ x?: number,
13
+ y?: number,
14
+ delay?: number,
15
+ speed?: number,
16
+ colors?: number,
17
+ quality?: number,
18
+ dispose?: 'any' | 'keep' | 'previous' | 'background',
19
+ }
20
+
21
+
22
+ class gif_encoder {
23
+ width: number;
24
+ height: number;
25
+
26
+ constructor(width: number, height: number): this;
27
+ add(buffer: ArrayBufferView, options: gif_frame_options): void;
28
+ finish(options: { repeat?: number, comment: string, application?: string }): Uint8Array;
29
+ }
30
+
31
+
32
+ export interface gif {
33
+ encoder: gif_encoder,
34
+ }
35
+
36
+ export interface png {
37
+ encode(buffer: ArrayBufferView, options: png_encode_options): Uint8Array,
38
+ encode_async(buffer: ArrayBufferView, options: png_encode_options): Promise<Uint8Array>,
39
+ }
40
+
41
+ export interface jpeg {
42
+ encode(buffer: ArrayBufferView, options: png_encode_options): Uint8Array,
43
+ encode_async(buffer: ArrayBufferView, options: png_encode_options): Promise<Uint8Array>,
44
+ }
45
+
46
+ export interface webp {
47
+ encode(buffer: ArrayBufferView, options: png_encode_options): Uint8Array,
48
+ encode_async(buffer: ArrayBufferView, options: png_encode_options): Promise<Uint8Array>,
49
+ }
50
50
  }
package/codecs/lib.js CHANGED
@@ -1,6 +1,6 @@
1
- let codecs;
2
-
3
- if (process.env.CODECS_FORCE_WASM) codecs = require('./wasm/index.js');
4
- else try { codecs = require('./node/index.js'); } catch { codecs = require('./wasm/index.js'); }
5
-
1
+ let codecs;
2
+
3
+ if (process.env.CODECS_FORCE_WASM) codecs = require('./wasm/index.js');
4
+ else try { codecs = require('./node/index.js'); } catch { codecs = require('./wasm/index.js'); }
5
+
6
6
  throw new Error('todo!');
@@ -1,3 +1,3 @@
1
- const { arch, platform } = require('os');
2
- try { module.exports = require(`./bin/${arch()}-${platform()}.node`); }
1
+ const { arch, platform } = require('os');
2
+ try { module.exports = require(`./bin/${arch()}-${platform()}.node`); }
3
3
  catch (err) { throw new Error('unsupported arch/platform: ' + err.message); }
@@ -1,6 +1,6 @@
1
- import lib from './index.js';
2
-
3
- export const png = lib.png;
4
- export const gif = lib.gif;
5
- export const jpeg = lib.jpeg;
1
+ import lib from './index.js';
2
+
3
+ export const png = lib.png;
4
+ export const gif = lib.gif;
5
+ export const jpeg = lib.jpeg;
6
6
  export const webp = lib.webp;