imagescript 1.2.8 → 1.2.15

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 (91) hide show
  1. package/ImageScript.d.ts +223 -0
  2. package/ImageScript.js +60 -192
  3. package/LICENSE +619 -0
  4. package/README.md +17 -16
  5. package/bench/_.mjs +166 -0
  6. package/bench/all.mjs +4 -0
  7. package/bench/blur.mjs +59 -0
  8. package/bench/flip.mjs +63 -0
  9. package/bench/overlay.mjs +35 -0
  10. package/bench/package.json +7 -0
  11. package/bench/readme.md +64 -0
  12. package/bench/resize.mjs +52 -0
  13. package/codecs/LICENSE +21 -0
  14. package/codecs/lib.d.ts +50 -0
  15. package/codecs/lib.js +6 -0
  16. package/codecs/lib.mjs +1 -0
  17. package/codecs/node/bin/arm64-darwin.node +0 -0
  18. package/{node → codecs/node/bin}/arm64-linux.node +0 -0
  19. package/codecs/node/bin/x64-darwin.node +0 -0
  20. package/{node → codecs/node/bin}/x64-linux.node +0 -0
  21. package/{node → codecs/node/bin}/x64-win32.node +0 -0
  22. package/codecs/node/index.js +3 -0
  23. package/codecs/node/index.mjs +6 -0
  24. package/codecs/package.json +14 -0
  25. package/codecs/readme.md +38 -0
  26. package/{wasm/simd.wasm → codecs/tests/gif.js} +0 -0
  27. package/{wasm/unknown.wasm → codecs/tests/jpeg.js} +0 -0
  28. package/codecs/tests/png.js +0 -0
  29. package/codecs/tests/results/gif/1024.nis.gif +0 -0
  30. package/codecs/tests/results/gif/1024.skyra.gif +0 -0
  31. package/codecs/tests/results/gif/256.nis.gif +0 -0
  32. package/codecs/tests/results/gif/256.skyra.gif +0 -0
  33. package/codecs/tests/results/jpeg/256.jpegjs.jpeg +0 -0
  34. package/codecs/tests/results/jpeg/256.nis.jpeg +0 -0
  35. package/codecs/tests/results/jpeg/256.sharp.jpeg +0 -0
  36. package/codecs/tests/results/jpeg/512.jpegjs.jpeg +0 -0
  37. package/codecs/tests/results/jpeg/512.nis.jpeg +0 -0
  38. package/codecs/tests/results/jpeg/512.sharp.jpeg +0 -0
  39. package/codecs/tests/results/jpeg/64.jpegjs.jpeg +0 -0
  40. package/codecs/tests/results/jpeg/64.nis.jpeg +0 -0
  41. package/codecs/tests/results/jpeg/64.sharp.jpeg +0 -0
  42. package/codecs/tests/results/png/256.jis.png +0 -0
  43. package/codecs/tests/results/png/256.nis.png +0 -0
  44. package/codecs/tests/results/png/256.sharp.png +0 -0
  45. package/codecs/tests/results/png/256.upng.png +0 -0
  46. package/codecs/tests/results/png/512.jis.png +0 -0
  47. package/codecs/tests/results/png/512.nis.png +0 -0
  48. package/codecs/tests/results/png/512.sharp.png +0 -0
  49. package/codecs/tests/results/png/512.upng.png +0 -0
  50. package/codecs/tests/results/png/64.jis.png +0 -0
  51. package/codecs/tests/results/png/64.nis.png +0 -0
  52. package/codecs/tests/results/png/64.sharp.png +0 -0
  53. package/codecs/tests/results/png/64.upng.png +0 -0
  54. package/codecs/tests/webp.js +0 -0
  55. package/codecs/wasm/bin/codecs.wasm +0 -0
  56. package/codecs/wasm/bin/simd.wasm +0 -0
  57. package/codecs/wasm/bundle/browser.js +1 -0
  58. package/codecs/wasm/index.js +1 -0
  59. package/codecs/wasm/index.mjs +1 -0
  60. package/package.json +17 -4
  61. package/png/README.md +1 -0
  62. package/png/src/{crc.js → crc.mjs} +0 -0
  63. package/png/src/{mem.js → mem.mjs} +0 -0
  64. package/png/src/{png.js → png.mjs} +3 -3
  65. package/png/src/{zlib.js → zlib.mjs} +0 -0
  66. package/tsconfig.json +21 -0
  67. package/v2/framebuffer.js +94 -115
  68. package/v2/framebuffer.mjs +9 -10
  69. package/v2/framebuffer.rs +1264 -0
  70. package/v2/index.js +1 -1
  71. package/v2/ops/{blur.js → blur.mjs} +0 -0
  72. package/v2/ops/{color.js → color.mjs} +0 -0
  73. package/v2/ops/{crop.js → crop.mjs} +0 -0
  74. package/v2/ops/{fill.js → fill.mjs} +0 -0
  75. package/v2/ops/{flip.js → flip.mjs} +0 -0
  76. package/v2/ops/index.mjs +9 -0
  77. package/v2/ops/{iterator.js → iterator.mjs} +6 -6
  78. package/v2/ops/overlay.mjs +63 -0
  79. package/v2/ops/{resize.js → resize.mjs} +3 -3
  80. package/v2/ops/{rotate.js → rotate.mjs} +8 -9
  81. package/v2/util/{mem.js → mem.mjs} +3 -5
  82. package/wasm/any/font.wasm +0 -0
  83. package/wasm/any/png.wasm +0 -0
  84. package/wasm/node/png.js +49 -0
  85. package/node/arm64-darwin.node +0 -0
  86. package/node/index.js +0 -7
  87. package/node/x64-darwin.node +0 -0
  88. package/v2/ops/index.js +0 -9
  89. package/v2/ops/overlay.js +0 -55
  90. package/wasm/node.js +0 -23
  91. package/wasm/web.js +0 -10
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ throw new Error('todo!');
@@ -0,0 +1 @@
1
+ throw new Error('todo!');
@@ -0,0 +1 @@
1
+ import lib from './index.js';
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "imagescript",
3
- "version": "1.2.8",
3
+ "version": "1.2.15",
4
4
  "description": "zero-dependency javascript image manipulation",
5
5
  "main": "ImageScript.js",
6
+ "types": "ImageScript.d.ts",
6
7
  "scripts": {
7
8
  "test": "node ./tests/run.js",
8
9
  "coverage": "nyc --reporter=html npm test"
@@ -14,10 +15,22 @@
14
15
  "keywords": [
15
16
  "image",
16
17
  "image processing",
17
- "image manipulation"
18
+ "image manipulation",
19
+ "png",
20
+ "jpeg",
21
+ "jpg",
22
+ "scale",
23
+ "resize",
24
+ "crop",
25
+ "webp",
26
+ "svg",
27
+ "bitmap",
28
+ "gif",
29
+ "picture",
30
+ "thumbnail"
18
31
  ],
19
- "author": "matmen <matmen@dreadful.tech>",
20
- "license": "GPL-3.0-or-later",
32
+ "author": "Mathis Mensing <mathis@matmen.dev>",
33
+ "license": "AGPL-3.0-or-later",
21
34
  "bugs": {
22
35
  "url": "https://github.com/matmen/ImageScript/issues"
23
36
  },
package/png/README.md CHANGED
@@ -0,0 +1 @@
1
+ TBD
File without changes
File without changes
@@ -1,6 +1,6 @@
1
- import { crc32 } from './crc.js';
2
- import { from_parts } from './mem.js';
3
- import { compress, decompress } from './zlib.js';
1
+ import { crc32 } from './crc.mjs';
2
+ import { from_parts } from './mem.mjs';
3
+ import { compress, decompress } from './zlib.mjs';
4
4
 
5
5
  const __IHDR__ = new Uint8Array([73, 72, 68, 82]);
6
6
  const __IDAT__ = new Uint8Array([73, 68, 65, 84]);
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es6",
4
+ "module": "commonjs",
5
+ "strict": true,
6
+ "noImplicitAny": true,
7
+ "strictNullChecks": true,
8
+ "noImplicitThis": true,
9
+ "alwaysStrict": true,
10
+ "noUnusedLocals": true,
11
+ "noUnusedParameters": true,
12
+ "noImplicitReturns": true,
13
+ "noFallthroughCasesInSwitch": true,
14
+ "moduleResolution": "node",
15
+ "allowJs": true,
16
+ "allowSyntheticDefaultImports": true,
17
+ "skipLibCheck": true,
18
+ "lib": ["es6"]
19
+ },
20
+ "files": ["ImageScript.d.ts"]
21
+ }
package/v2/framebuffer.js CHANGED
@@ -1,57 +1,10 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
2
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
3
  var __export = (target, all) => {
12
4
  __markAsModule(target);
13
5
  for (var name in all)
14
6
  __defProp(target, name, { get: all[name], enumerable: true });
15
7
  };
16
- var __reExport = (target, module2, desc) => {
17
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
18
- for (let key of __getOwnPropNames(module2))
19
- if (!__hasOwnProp.call(target, key) && key !== "default")
20
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
21
- }
22
- return target;
23
- };
24
- var __toModule = (module2) => {
25
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
26
- };
27
-
28
- // v2/util/mem.js
29
- var require_mem = __commonJS({
30
- "v2/util/mem.js"(exports, module2) {
31
- function view3(buffer, shared = false) {
32
- if (buffer instanceof ArrayBuffer)
33
- return new Uint8Array(buffer);
34
- if (shared && buffer instanceof SharedArrayBuffer)
35
- return new Uint8Array(buffer);
36
- if (ArrayBuffer.isView(buffer))
37
- return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
38
- throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
39
- }
40
- function from_parts2(buffers, shared = false) {
41
- let length = 0;
42
- let offset = 0;
43
- buffers.forEach((buffer) => length += buffer.byteLength == null ? buffer.length : buffer.byteLength);
44
- const u82 = new Uint8Array(shared ? new SharedArrayBuffer(length) : length);
45
- buffers.forEach((buffer) => {
46
- const ref = Array.isArray(buffer) ? buffer : view3(buffer, true);
47
- u82.set(ref, offset);
48
- offset += ref.length;
49
- });
50
- return u82;
51
- }
52
- module2.exports = { view: view3, from_parts: from_parts2 };
53
- }
54
- });
55
8
 
56
9
  // v2/framebuffer.mjs
57
10
  __export(exports, {
@@ -340,8 +293,16 @@ var colors = new Map([
340
293
  ["yellowgreen", 2597139199]
341
294
  ]);
342
295
 
343
- // v2/framebuffer.mjs
344
- var import_mem2 = __toModule(require_mem());
296
+ // v2/util/mem.js
297
+ function view(buffer, shared = false) {
298
+ if (buffer instanceof ArrayBuffer)
299
+ return new Uint8Array(buffer);
300
+ if (shared && buffer instanceof SharedArrayBuffer)
301
+ return new Uint8Array(buffer);
302
+ if (ArrayBuffer.isView(buffer))
303
+ return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
304
+ throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
305
+ }
345
306
 
346
307
  // v2/ops/flip.js
347
308
  var flip_exports = {};
@@ -773,9 +734,9 @@ function clamped(x2, y, width, height) {
773
734
  return 4 * (clamp3(0, x2, width - 1) + clamp3(0, y, height - 1) * width);
774
735
  }
775
736
  function hermite(A, B, C, D, t) {
776
- const c = C / 2 + -A / 2;
777
- const b = A + 2 * C - D / 2 - 5 * B / 2;
778
- const a = D / 2 + -A / 2 + 3 * B / 2 - 3 * C / 2;
737
+ const c = C / 2 + A / -2;
738
+ const b = A + C * 2 - D / 2 - B * 2.5;
739
+ const a = D / 2 + A / -2 + B * 1.5 - C * 1.5;
779
740
  const t2 = t * t;
780
741
  return B + c * t + b * t2 + a * t * t2;
781
742
  }
@@ -998,50 +959,64 @@ function pawn(point0, point1, weight, ref, inn) {
998
959
  // v2/ops/overlay.js
999
960
  var overlay_exports = {};
1000
961
  __export(overlay_exports, {
1001
- overlay: () => overlay,
962
+ blend: () => blend2,
1002
963
  replace: () => replace
1003
964
  });
1004
965
  function replace(bg, fg, x2, y) {
1005
- const fwidth = fg.width | 0;
1006
- const bwidth = bg.width | 0;
1007
- const fheight = fg.height | 0;
1008
- const bheight = bg.height | 0;
1009
- let mw = Math.min(bwidth, fwidth) | 0;
1010
- let mh = Math.min(bheight, fheight) | 0;
1011
966
  const b32 = bg.u32;
1012
967
  const f32 = fg.u32;
1013
- for (let yy = y | 0; yy < mh; yy++) {
1014
- const yoffset = yy * bwidth;
1015
- const yyoffset = fwidth * (yy - y);
1016
- for (let xx = x2 | 0; xx < mw; xx++) {
1017
- b32[xx + yoffset] = f32[xx - x2 + yyoffset];
1018
- }
968
+ const fw = fg.width | 0;
969
+ const bw = bg.width | 0;
970
+ const fh = fg.height | 0;
971
+ const bh = bg.height | 0;
972
+ const ox = (x2 > 0 ? 0 : -x2) | 0;
973
+ const oy = (y > 0 ? 0 : -y) | 0;
974
+ const top = (y > 0 ? y : 0) | 0;
975
+ const left = (x2 > 0 ? x2 : 0) | 0;
976
+ const width = Math.min(bw, x2 + fw) - left | 0;
977
+ const height = Math.min(bh, y + fh) - top | 0;
978
+ if (0 >= width || 0 >= height)
979
+ return;
980
+ for (let yy = 0 | 0; yy < height; yy++) {
981
+ const yyoffset = ox + fw * (yy + oy);
982
+ const yoffset = left + bw * (yy + top);
983
+ b32.subarray(yoffset, width + yoffset).set(f32.subarray(yyoffset, width + yyoffset));
1019
984
  }
1020
985
  }
1021
- function overlay(background, foreground, x2, y) {
1022
- x2 = x2 | 0;
1023
- y = y | 0;
1024
- const fwidth = foreground.width | 0;
1025
- const bwidth = background.width | 0;
1026
- const fheight = foreground.height | 0;
1027
- const bheight = background.height | 0;
1028
- const mw = Math.min(bwidth, fwidth) | 0;
1029
- const mh = Math.min(bheight, fheight) | 0;
1030
- const fview = foreground.view;
1031
- const bview = background.view;
1032
- for (let yy = y | 0; yy < mh; yy++) {
1033
- const yoffset = yy * bwidth;
1034
- const yyoffset = fwidth * (yy - y);
1035
- for (let xx = x2 | 0; xx < mw; xx++) {
1036
- const offset = 4 * (xx + yoffset);
1037
- const fg = fview.getUint32(4 * (xx - x2 + yyoffset), false);
1038
- const bg = bview.getUint32(offset, false);
1039
- if ((fg & 255) === 255)
1040
- bview.setUint32(offset, fg, false);
1041
- else if ((fg & 255) === 0)
1042
- bview.setUint32(offset, bg, false);
1043
- else
1044
- bview.setUint32(offset, blend(fg, bg), false);
986
+ function blend2(bg, fg, x2, y) {
987
+ const b32 = bg.u32;
988
+ const f32 = fg.u32;
989
+ const fw = fg.width | 0;
990
+ const bw = bg.width | 0;
991
+ const fh = fg.height | 0;
992
+ const bh = bg.height | 0;
993
+ const ox = (x2 > 0 ? 0 : -x2) | 0;
994
+ const oy = (y > 0 ? 0 : -y) | 0;
995
+ const top = (y > 0 ? y : 0) | 0;
996
+ const left = (x2 > 0 ? x2 : 0) | 0;
997
+ const width = Math.min(bw, x2 + fw) - left | 0;
998
+ const height = Math.min(bh, y + fh) - top | 0;
999
+ if (0 >= width || 0 >= height)
1000
+ return;
1001
+ for (let yy = 0 | 0; yy < height; yy++) {
1002
+ const yyoffset = ox + fw * (yy + oy);
1003
+ const yoffset = left + bw * (yy + top);
1004
+ for (let xx = 0 | 0; xx < width; xx++) {
1005
+ const F = f32[xx + yyoffset];
1006
+ const fa = F >> 24 & 255;
1007
+ if (fa === 0)
1008
+ continue;
1009
+ else if (fa === 255)
1010
+ b32[xx + yoffset] = F;
1011
+ else {
1012
+ const alpha = 1 + fa;
1013
+ const inv_alpha = 256 - fa;
1014
+ const B = b32[xx + yoffset];
1015
+ const r = alpha * (F & 255) + inv_alpha * (B & 255) >> 8;
1016
+ const g = alpha * (F >> 8 & 255) + inv_alpha * (B >> 8 & 255) >> 8;
1017
+ const b = alpha * (F >> 16 & 255) + inv_alpha * (B >> 16 & 255) >> 8;
1018
+ b32[xx + yoffset] = Math.max(fa, B >> 24 & 255) << 24 | (b & 255) << 16 | (g & 255) << 8 | r;
1019
+ }
1045
1020
  }
1046
1021
  }
1047
1022
  }
@@ -1056,8 +1031,8 @@ __export(iterator_exports, {
1056
1031
  function* cords(framebuffer2) {
1057
1032
  const width = framebuffer2.width | 0;
1058
1033
  const height = framebuffer2.height | 0;
1059
- for (let y = 1 | 0; y <= height; y++) {
1060
- for (let x2 = 1 | 0; x2 <= width; x2++)
1034
+ for (let y = 0 | 0; y < height; y++) {
1035
+ for (let x2 = 0 | 0; x2 < width; x2++)
1061
1036
  yield [x2, y];
1062
1037
  }
1063
1038
  }
@@ -1066,8 +1041,8 @@ function* rgba(framebuffer2) {
1066
1041
  const u82 = framebuffer2.u8;
1067
1042
  const width = framebuffer2.width | 0;
1068
1043
  const height = framebuffer2.height | 0;
1069
- for (let y = 1 | 0; y <= height; y++) {
1070
- for (let x2 = 1 | 0; x2 <= width; x2++) {
1044
+ for (let y = 0 | 0; y < height; y++) {
1045
+ for (let x2 = 0 | 0; x2 < width; x2++) {
1071
1046
  yield [x2, y, u82.subarray(offset, offset += 4)];
1072
1047
  }
1073
1048
  }
@@ -1077,8 +1052,8 @@ function* u32(framebuffer2) {
1077
1052
  const view3 = framebuffer2.view;
1078
1053
  const width = framebuffer2.width | 0;
1079
1054
  const height = framebuffer2.height | 0;
1080
- for (let y = 1 | 0; y <= height; y++) {
1081
- for (let x2 = 1 | 0; x2 <= width; x2++) {
1055
+ for (let y = 0 | 0; y < height; y++) {
1056
+ for (let x2 = 0 | 0; x2 < width; x2++) {
1082
1057
  yield [x2, y, view3.getUint32(offset, false)];
1083
1058
  offset += 4;
1084
1059
  }
@@ -1361,7 +1336,7 @@ function crc32(buffer) {
1361
1336
  }
1362
1337
 
1363
1338
  // png/src/mem.js
1364
- function view(buffer, shared = false) {
1339
+ function view2(buffer, shared = false) {
1365
1340
  if (buffer instanceof ArrayBuffer)
1366
1341
  return new Uint8Array(buffer);
1367
1342
  if (shared && buffer instanceof SharedArrayBuffer)
@@ -1376,7 +1351,7 @@ function from_parts(buffers, shared = false) {
1376
1351
  buffers.forEach((buffer) => length += buffer.byteLength == null ? buffer.length : buffer.byteLength);
1377
1352
  const u82 = new Uint8Array(shared ? new SharedArrayBuffer(length) : length);
1378
1353
  buffers.forEach((buffer) => {
1379
- const ref = Array.isArray(buffer) ? buffer : view(buffer, true);
1354
+ const ref = Array.isArray(buffer) ? buffer : view2(buffer, true);
1380
1355
  u82.set(ref, offset);
1381
1356
  offset += ref.length;
1382
1357
  });
@@ -1411,12 +1386,13 @@ var _b = freb(fdeb, 0);
1411
1386
  var fd = _b[0];
1412
1387
  var revfd = _b[1];
1413
1388
  var rev = new u16(32768);
1414
- for (var i = 0; i < 32768; ++i) {
1389
+ for (i = 0; i < 32768; ++i) {
1415
1390
  x = (i & 43690) >>> 1 | (i & 21845) << 1;
1416
1391
  x = (x & 52428) >>> 2 | (x & 13107) << 2;
1417
1392
  x = (x & 61680) >>> 4 | (x & 3855) << 4;
1418
1393
  rev[i] = ((x & 65280) >>> 8 | (x & 255) << 8) >>> 1;
1419
1394
  }
1395
+ var i;
1420
1396
  var x;
1421
1397
  var hMap = function(cd, mb, r) {
1422
1398
  var s = cd.length;
@@ -1453,17 +1429,22 @@ var hMap = function(cd, mb, r) {
1453
1429
  return co;
1454
1430
  };
1455
1431
  var flt = new u8(288);
1456
- for (var i = 0; i < 144; ++i)
1432
+ for (i = 0; i < 144; ++i)
1457
1433
  flt[i] = 8;
1458
- for (var i = 144; i < 256; ++i)
1434
+ var i;
1435
+ for (i = 144; i < 256; ++i)
1459
1436
  flt[i] = 9;
1460
- for (var i = 256; i < 280; ++i)
1437
+ var i;
1438
+ for (i = 256; i < 280; ++i)
1461
1439
  flt[i] = 7;
1462
- for (var i = 280; i < 288; ++i)
1440
+ var i;
1441
+ for (i = 280; i < 288; ++i)
1463
1442
  flt[i] = 8;
1443
+ var i;
1464
1444
  var fdt = new u8(32);
1465
- for (var i = 0; i < 32; ++i)
1445
+ for (i = 0; i < 32; ++i)
1466
1446
  fdt[i] = 5;
1447
+ var i;
1467
1448
  var flm = hMap(flt, 9, 0);
1468
1449
  var flrm = hMap(flt, 9, 1);
1469
1450
  var fdm = hMap(fdt, 5, 0);
@@ -2214,7 +2195,7 @@ var framebuffer = class {
2214
2195
  constructor(width, height, buffer) {
2215
2196
  this.width = width | 0;
2216
2197
  this.height = height | 0;
2217
- this.u8 = buffer ? (0, import_mem2.view)(buffer) : new Uint8Array(4 * this.width * this.height);
2198
+ this.u8 = buffer ? view(buffer) : new Uint8Array(4 * this.width * this.height);
2218
2199
  this.view = new DataView(this.u8.buffer, this.u8.byteOffset, this.u8.byteLength);
2219
2200
  this.u32 = new Uint32Array(this.u8.buffer, this.u8.byteOffset, this.u8.byteLength / 4);
2220
2201
  if (this.u8.length !== 4 * this.width * this.height)
@@ -2226,29 +2207,29 @@ var framebuffer = class {
2226
2207
  toString() {
2227
2208
  return `framebuffer<${this.width}x${this.height}>`;
2228
2209
  }
2210
+ get(x2, y) {
2211
+ return this.view.getUint32((x2 | 0) + (y | 0) * this.width, false);
2212
+ }
2229
2213
  clone() {
2230
2214
  return new this.constructor(this.width, this.height, this.u8.slice());
2231
2215
  }
2216
+ set(x2, y, color3) {
2217
+ this.view.setUint32((x2 | 0) + (y | 0) * this.width, color3, false);
2218
+ }
2232
2219
  toJSON() {
2233
2220
  return { width: this.width, height: this.height, buffer: Array.from(this.u8) };
2234
2221
  }
2235
- get(x2, y) {
2236
- return this.view.getUint32((x2 | 0) - 1 + ((y | 0) - 1) * this.width, false);
2237
- }
2238
2222
  scale(type, factor) {
2239
2223
  return this.resize(type, factor * this.width, factor * this.height);
2240
2224
  }
2241
2225
  overlay(frame, x2 = 0, y = 0) {
2242
- return overlay_exports.overlay(this, frame, x2 | 0, y | 0), this;
2226
+ return overlay_exports.blend(this, frame, x2 | 0, y | 0), this;
2243
2227
  }
2244
2228
  replace(frame, x2 = 0, y = 0) {
2245
2229
  return overlay_exports.replace(this, frame, x2 | 0, y | 0), this;
2246
2230
  }
2247
- set(x2, y, color3) {
2248
- this.view.setUint32((x2 | 0) - 1 + ((y | 0) - 1) * this.width, color3, false);
2249
- }
2250
2231
  at(x2, y) {
2251
- const offset = 4 * ((x2 | 0) - 1 + ((y | 0) - 1) * this.width);
2232
+ const offset = 4 * ((x2 | 0) + (y | 0) * this.width);
2252
2233
  return this.u8.subarray(offset, 4 + offset);
2253
2234
  }
2254
2235
  static from(framebuffer2) {
@@ -2294,7 +2275,7 @@ var framebuffer = class {
2294
2275
  }
2295
2276
  cut(type, arg0, arg1, arg2, arg3) {
2296
2277
  if (type === "circle")
2297
- return crop_exports.circle(arg0 || 0, this);
2278
+ return crop_exports.circle(arg0 || 0, this.clone());
2298
2279
  else if (type === "box")
2299
2280
  return crop_exports.cut(arg0 | 0, arg1 | 0, arg2 | 0, arg3 | 0, this);
2300
2281
  else
@@ -2358,8 +2339,6 @@ var framebuffer = class {
2358
2339
  resize_exports.cubic(width, height, this);
2359
2340
  else if (type === "linear")
2360
2341
  resize_exports.linear(width, height, this);
2361
- else if (type === "liquid")
2362
- resize_exports.liquid(width, height, this);
2363
2342
  else if (type === "nearest")
2364
2343
  resize_exports.nearest(width, height, this);
2365
2344
  else
@@ -1,7 +1,7 @@
1
- import Color from './ops/color.js';
2
- import { view } from './util/mem.js';
3
- import * as ops from './ops/index.js';
4
- import * as png from '../png/src/png.js';
1
+ import Color from './ops/color.mjs';
2
+ import { view } from './util/mem.mjs';
3
+ import * as ops from './ops/index.mjs';
4
+ import * as png from '../png/src/png.mjs';
5
5
 
6
6
  export { Color };
7
7
 
@@ -20,14 +20,14 @@ export default class framebuffer {
20
20
 
21
21
  [Symbol.iterator]() { return ops.iterator.cords(this); }
22
22
  toString() { return `framebuffer<${this.width}x${this.height}>`; }
23
+ get(x, y) { return this.view.getUint32((x | 0) + (y | 0) * this.width, false); }
23
24
  clone() { return new this.constructor(this.width, this.height, this.u8.slice()); }
25
+ set(x, y, color) { this.view.setUint32((x | 0) + (y | 0) * this.width, color, false); }
24
26
  toJSON() { return { width: this.width, height: this.height, buffer: Array.from(this.u8) } }
25
- get(x, y) { return this.view.getUint32(((x | 0) - 1) + ((y | 0) - 1) * this.width, false); }
26
27
  scale(type, factor) { return this.resize(type, factor * this.width, factor * this.height); }
27
- overlay(frame, x = 0, y = 0) { return (ops.overlay.overlay(this, frame, x | 0, y | 0), this); }
28
+ overlay(frame, x = 0, y = 0) { return (ops.overlay.blend(this, frame, x | 0, y | 0), this); }
28
29
  replace(frame, x = 0, y = 0) { return (ops.overlay.replace(this, frame, x | 0, y | 0), this); }
29
- set(x, y, color) { this.view.setUint32(((x | 0) - 1) + ((y | 0) - 1) * this.width, color, false); }
30
- at(x, y) { const offset = 4 * (((x | 0) - 1) + ((y | 0) - 1) * this.width); return this.u8.subarray(offset, 4 + offset); }
30
+ at(x, y) { const offset = 4 * ((x | 0) + (y | 0) * this.width); return this.u8.subarray(offset, 4 + offset); }
31
31
  static from(framebuffer) { return new this(framebuffer.width, framebuffer.height, framebuffer.u8 || framebuffer.buffer); }
32
32
  static decode(format, buffer) { if (format !== 'png') throw new RangeError('invalid image format'); else return framebuffer.from(png.decode(buffer)); }
33
33
 
@@ -62,7 +62,7 @@ export default class framebuffer {
62
62
  }
63
63
 
64
64
  cut(type, arg0, arg1, arg2, arg3) {
65
- if (type === 'circle') return ops.crop.circle(arg0 || 0, this);
65
+ if (type === 'circle') return ops.crop.circle(arg0 || 0, this.clone());
66
66
  else if (type === 'box') return ops.crop.cut(arg0 | 0, arg1 | 0, arg2 | 0, arg3 | 0, this);
67
67
 
68
68
  else throw new RangeError('invalid cut type');
@@ -117,7 +117,6 @@ export default class framebuffer {
117
117
  if (width === this.width && height === this.height) return this;
118
118
  else if (type === 'cubic') ops.resize.cubic(width, height, this);
119
119
  else if (type === 'linear') ops.resize.linear(width, height, this);
120
- else if (type === 'liquid') ops.resize.liquid(width, height, this);
121
120
  else if (type === 'nearest') ops.resize.nearest(width, height, this);
122
121
 
123
122
  else throw new RangeError('invalid resize type');