@thi.ng/rasterize 1.0.62 → 1.0.64
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/CHANGELOG.md +1 -1
- package/api.js +0 -1
- package/checks.js +6 -2
- package/circle.js +8 -1
- package/draw.js +38 -32
- package/flood-fill.js +21 -22
- package/line.js +16 -8
- package/package.json +13 -11
- package/poly.js +51 -62
- package/polyline.js +12 -9
- package/rect.js +52 -36
- package/shader.js +42 -62
package/CHANGELOG.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/checks.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { isFunction } from "@thi.ng/checks/is-function";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const isInBounds2D = ({ size }, x, y) => x >= 0 && x < size[0] && y >= 0 && y < size[1];
|
|
3
|
+
const ensureShader2D = (val) => isFunction(val) ? val : () => val;
|
|
4
|
+
export {
|
|
5
|
+
ensureShader2D,
|
|
6
|
+
isInBounds2D
|
|
7
|
+
};
|
package/circle.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { circleClipped } from "@thi.ng/grid-iterators/circle";
|
|
2
2
|
import { __draw2D } from "./draw.js";
|
|
3
|
-
|
|
3
|
+
const drawCircle = (grid, x, y, r, val, fill = false) => __draw2D(
|
|
4
|
+
circleClipped(x, y, r, 0, 0, grid.size[0], grid.size[1], fill),
|
|
5
|
+
grid,
|
|
6
|
+
val
|
|
7
|
+
);
|
|
8
|
+
export {
|
|
9
|
+
drawCircle
|
|
10
|
+
};
|
package/draw.js
CHANGED
|
@@ -1,40 +1,46 @@
|
|
|
1
1
|
import { isFunction } from "@thi.ng/checks/is-function";
|
|
2
2
|
import { isPrimitive } from "@thi.ng/checks/is-primitive";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
3
|
+
const __draw2D = (pts, grid, val) => isFunction(val) ? __drawShader2D(pts, grid, val) : __drawSolid2D(pts, grid, val);
|
|
4
|
+
const __drawSolid2D = (pts, grid, val) => {
|
|
5
|
+
if (!pts)
|
|
6
|
+
return grid;
|
|
7
|
+
if (isPrimitive(val)) {
|
|
8
|
+
const {
|
|
9
|
+
data,
|
|
10
|
+
offset,
|
|
11
|
+
stride: [sx, sy]
|
|
12
|
+
} = grid;
|
|
13
|
+
for (let p of pts) {
|
|
14
|
+
data[offset + p[0] * sx + p[1] * sy] = val;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
16
|
+
} else {
|
|
17
|
+
for (let p of pts) {
|
|
18
|
+
grid.setAtUnsafe(p[0], p[1], val);
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
}
|
|
21
|
+
return grid;
|
|
23
22
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
const __drawShader2D = (pts, grid, shader) => {
|
|
24
|
+
if (!pts)
|
|
25
|
+
return grid;
|
|
26
|
+
if (isPrimitive(grid.getAtUnsafe(0, 0))) {
|
|
27
|
+
const {
|
|
28
|
+
data,
|
|
29
|
+
offset,
|
|
30
|
+
stride: [sx, sy]
|
|
31
|
+
} = grid;
|
|
32
|
+
for (let { 0: x, 1: y } of pts) {
|
|
33
|
+
data[offset + x * sx + y * sy] = shader(grid, x, y);
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
35
|
+
} else {
|
|
36
|
+
for (let { 0: x, 1: y } of pts) {
|
|
37
|
+
grid.setAtUnsafe(x, y, shader(grid, x, y));
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
}
|
|
40
|
+
return grid;
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
__draw2D,
|
|
44
|
+
__drawShader2D,
|
|
45
|
+
__drawSolid2D
|
|
40
46
|
};
|
package/flood-fill.js
CHANGED
|
@@ -4,27 +4,26 @@ import { equiv } from "@thi.ng/equiv";
|
|
|
4
4
|
import { floodFill as $fill } from "@thi.ng/grid-iterators/flood-fill";
|
|
5
5
|
import { isInBounds2D } from "./checks.js";
|
|
6
6
|
import { __draw2D } from "./draw.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @param grid -
|
|
13
|
-
* @param x -
|
|
14
|
-
* @param y -
|
|
15
|
-
* @param val -
|
|
16
|
-
*/
|
|
17
|
-
export const floodFill = (grid, x, y, val) => isInBounds2D(grid, x, y)
|
|
18
|
-
? __draw2D($fill(__pred(grid, x, y), x, y, grid.size[0], grid.size[1]), grid, val)
|
|
19
|
-
: grid;
|
|
7
|
+
const floodFill = (grid, x, y, val) => isInBounds2D(grid, x, y) ? __draw2D(
|
|
8
|
+
$fill(__pred(grid, x, y), x, y, grid.size[0], grid.size[1]),
|
|
9
|
+
grid,
|
|
10
|
+
val
|
|
11
|
+
) : grid;
|
|
20
12
|
const __pred = (img, x, y) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
const {
|
|
14
|
+
data,
|
|
15
|
+
offset,
|
|
16
|
+
stride: [stride, rowStride]
|
|
17
|
+
} = img;
|
|
18
|
+
let srcVal = img.getAtUnsafe(x, y);
|
|
19
|
+
if (isPrimitive(srcVal)) {
|
|
20
|
+
return (x2, y2) => data[offset + x2 * stride + y2 * rowStride] === srcVal;
|
|
21
|
+
}
|
|
22
|
+
if (isIterable(srcVal)) {
|
|
23
|
+
srcVal = [...srcVal];
|
|
24
|
+
}
|
|
25
|
+
return (x2, y2) => equiv(img.getAtUnsafe(x2, y2), srcVal);
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
floodFill
|
|
30
29
|
};
|
package/line.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { lineClipped } from "@thi.ng/grid-iterators/line";
|
|
2
2
|
import { __draw2D } from "./draw.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const drawLine = (grid, x1, y1, x2, y2, val) => __draw2D(
|
|
4
|
+
lineClipped(x1, y1, x2, y2, 0, 0, grid.size[0], grid.size[1]),
|
|
5
|
+
grid,
|
|
6
|
+
val
|
|
7
|
+
);
|
|
8
|
+
const traceLine = (grid, x1, y1, x2, y2, fn) => {
|
|
9
|
+
const pts = lineClipped(x1, y1, x2, y2, 0, 0, grid.size[0], grid.size[1]);
|
|
10
|
+
if (pts) {
|
|
11
|
+
for (let p of pts)
|
|
12
|
+
fn(p);
|
|
13
|
+
}
|
|
14
|
+
return grid;
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
drawLine,
|
|
18
|
+
traceLine
|
|
11
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rasterize",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.64",
|
|
4
4
|
"description": "2D shape drawing & rasterization",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,17 +35,17 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/equiv": "^2.1.
|
|
39
|
-
"@thi.ng/grid-iterators": "^4.0.
|
|
40
|
-
"@thi.ng/porter-duff": "^2.1.
|
|
41
|
-
"@thi.ng/random": "^3.6.
|
|
42
|
-
"@thi.ng/transducers": "^8.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/equiv": "^2.1.37",
|
|
41
|
+
"@thi.ng/grid-iterators": "^4.0.36",
|
|
42
|
+
"@thi.ng/porter-duff": "^2.1.52",
|
|
43
|
+
"@thi.ng/random": "^3.6.18",
|
|
44
|
+
"@thi.ng/transducers": "^8.8.15"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@microsoft/api-extractor": "^7.38.3",
|
|
46
|
-
"
|
|
48
|
+
"esbuild": "^0.19.8",
|
|
47
49
|
"rimraf": "^5.0.5",
|
|
48
50
|
"tools": "^0.0.1",
|
|
49
51
|
"typedoc": "^0.25.4",
|
|
@@ -118,5 +120,5 @@
|
|
|
118
120
|
"status": "alpha",
|
|
119
121
|
"year": 2021
|
|
120
122
|
},
|
|
121
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
122
124
|
}
|
package/poly.js
CHANGED
|
@@ -1,67 +1,56 @@
|
|
|
1
1
|
import { ensureShader2D } from "./checks.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
const fillPoly = (grid, pts, val) => {
|
|
3
|
+
const numP = pts.length;
|
|
4
|
+
const [width, height] = grid.size;
|
|
5
|
+
const shader = ensureShader2D(val);
|
|
6
|
+
let minX = Infinity;
|
|
7
|
+
let minY = Infinity;
|
|
8
|
+
let maxX = -Infinity;
|
|
9
|
+
let maxY = -Infinity;
|
|
10
|
+
for (let i2 = numP; i2-- > 0; ) {
|
|
11
|
+
const { 0: x, 1: y } = pts[i2];
|
|
12
|
+
minX = Math.min(minX, x);
|
|
13
|
+
maxX = Math.max(maxX, x);
|
|
14
|
+
minY = Math.min(minY, y);
|
|
15
|
+
maxY = Math.max(maxY, y);
|
|
16
|
+
}
|
|
17
|
+
minX = Math.max(minX | 0, 0);
|
|
18
|
+
maxX = Math.min(maxX | 0, width - 1);
|
|
19
|
+
minY = Math.max(minY | 0, 0);
|
|
20
|
+
maxY = Math.min(maxY | 0, height - 1);
|
|
21
|
+
if (minX >= width || maxX < 0 || minY >= height || maxY < 0)
|
|
22
|
+
return;
|
|
23
|
+
let i = 0;
|
|
24
|
+
let k = 0;
|
|
25
|
+
let j;
|
|
26
|
+
const isec = [];
|
|
27
|
+
for (let y = Math.max(0, minY); y <= maxY; y++) {
|
|
28
|
+
i = k = 0;
|
|
29
|
+
j = numP - 1;
|
|
30
|
+
isec.length = 0;
|
|
31
|
+
for (; i < numP; j = i, i++) {
|
|
32
|
+
const { 0: pix, 1: piy } = pts[i];
|
|
33
|
+
const { 0: pjx, 1: pjy } = pts[j];
|
|
34
|
+
if (piy < y && pjy >= y || pjy < y && piy >= y) {
|
|
35
|
+
isec[k++] = pix + (y - piy) / (pjy - piy) * (pjx - pix) | 0;
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
i = k = 0;
|
|
43
|
-
j = numP - 1;
|
|
44
|
-
isec.length = 0;
|
|
45
|
-
for (; i < numP; j = i, i++) {
|
|
46
|
-
const { 0: pix, 1: piy } = pts[i];
|
|
47
|
-
const { 0: pjx, 1: pjy } = pts[j];
|
|
48
|
-
if ((piy < y && pjy >= y) || (pjy < y && piy >= y)) {
|
|
49
|
-
isec[k++] = (pix + ((y - piy) / (pjy - piy)) * (pjx - pix)) | 0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
isec.sort((a, b) => a - b);
|
|
53
|
-
for (i = 0; i < k; i += 2) {
|
|
54
|
-
let x1 = isec[i];
|
|
55
|
-
if (x1 > maxX)
|
|
56
|
-
break;
|
|
57
|
-
let x2 = isec[i + 1];
|
|
58
|
-
if (x2 > minX) {
|
|
59
|
-
x1 < minX && (x1 = minX);
|
|
60
|
-
x2 > maxX && (x2 = maxX);
|
|
61
|
-
for (let x = x1; x <= x2; x++) {
|
|
62
|
-
grid.setAtUnsafe(x, y, shader(grid, x, y));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
38
|
+
isec.sort((a, b) => a - b);
|
|
39
|
+
for (i = 0; i < k; i += 2) {
|
|
40
|
+
let x1 = isec[i];
|
|
41
|
+
if (x1 > maxX)
|
|
42
|
+
break;
|
|
43
|
+
let x2 = isec[i + 1];
|
|
44
|
+
if (x2 > minX) {
|
|
45
|
+
x1 < minX && (x1 = minX);
|
|
46
|
+
x2 > maxX && (x2 = maxX);
|
|
47
|
+
for (let x = x1; x <= x2; x++) {
|
|
48
|
+
grid.setAtUnsafe(x, y, shader(grid, x, y));
|
|
65
49
|
}
|
|
50
|
+
}
|
|
66
51
|
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
fillPoly
|
|
67
56
|
};
|
package/polyline.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ensureShader2D } from "./checks.js";
|
|
2
2
|
import { drawLine } from "./line.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const drawPolyLine = (grid, pts, val, closed = false) => {
|
|
4
|
+
val = ensureShader2D(val);
|
|
5
|
+
const n = pts.length;
|
|
6
|
+
let [i, j] = closed ? [0, n - 1] : [1, 0];
|
|
7
|
+
for (; i < n; j = i, i++) {
|
|
8
|
+
const a = pts[j];
|
|
9
|
+
const b = pts[i];
|
|
10
|
+
drawLine(grid, a[0], a[1], b[0], b[1], val);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
drawPolyLine
|
|
12
15
|
};
|
package/rect.js
CHANGED
|
@@ -4,41 +4,57 @@ import { rows2d } from "@thi.ng/grid-iterators/rows";
|
|
|
4
4
|
import { concat } from "@thi.ng/transducers/concat";
|
|
5
5
|
import { ensureShader2D } from "./checks.js";
|
|
6
6
|
import { __draw2D } from "./draw.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const pts = rows2d({
|
|
23
|
-
cols: Math.min(w, width - x),
|
|
24
|
-
rows: Math.min(h, height - y),
|
|
25
|
-
});
|
|
26
|
-
const shader = ensureShader2D(val);
|
|
27
|
-
if (isPrimitive(val)) {
|
|
28
|
-
for (let { 0: xx, 1: yy } of pts) {
|
|
29
|
-
xx += x;
|
|
30
|
-
yy += y;
|
|
31
|
-
data[offset + xx * sx + yy * sy] = shader(grid, xx, yy);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
for (let { 0: xx, 1: yy } of pts) {
|
|
36
|
-
xx += x;
|
|
37
|
-
yy += y;
|
|
38
|
-
grid.setAtUnsafe(xx, yy, shader(grid, xx, yy));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return grid;
|
|
7
|
+
const drawRect = (grid, x, y, w, h, val, fill = false) => {
|
|
8
|
+
x |= 0;
|
|
9
|
+
y |= 0;
|
|
10
|
+
w |= 0;
|
|
11
|
+
h |= 0;
|
|
12
|
+
const {
|
|
13
|
+
data,
|
|
14
|
+
offset,
|
|
15
|
+
size: [width, height],
|
|
16
|
+
stride: [sx, sy]
|
|
17
|
+
} = grid;
|
|
18
|
+
if (fill) {
|
|
19
|
+
if (x < 0) {
|
|
20
|
+
w += x;
|
|
21
|
+
x = 0;
|
|
42
22
|
}
|
|
43
|
-
|
|
23
|
+
if (y < 0) {
|
|
24
|
+
h += y;
|
|
25
|
+
y = 0;
|
|
26
|
+
}
|
|
27
|
+
const pts = rows2d({
|
|
28
|
+
cols: Math.min(w, width - x),
|
|
29
|
+
rows: Math.min(h, height - y)
|
|
30
|
+
});
|
|
31
|
+
const shader = ensureShader2D(val);
|
|
32
|
+
if (isPrimitive(val)) {
|
|
33
|
+
for (let { 0: xx, 1: yy } of pts) {
|
|
34
|
+
xx += x;
|
|
35
|
+
yy += y;
|
|
36
|
+
data[offset + xx * sx + yy * sy] = shader(grid, xx, yy);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
for (let { 0: xx, 1: yy } of pts) {
|
|
40
|
+
xx += x;
|
|
41
|
+
yy += y;
|
|
42
|
+
grid.setAtUnsafe(xx, yy, shader(grid, xx, yy));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return grid;
|
|
46
|
+
}
|
|
47
|
+
return __draw2D(
|
|
48
|
+
concat(
|
|
49
|
+
hlineClipped(x, y, w, 0, 0, width, height),
|
|
50
|
+
vlineClipped(x, y + 1, h - 2, 0, 0, width, height),
|
|
51
|
+
hlineClipped(x, y + h - 1, w, 0, 0, width, height),
|
|
52
|
+
vlineClipped(x + w - 1, y + 1, h - 2, 0, 0, width, height)
|
|
53
|
+
),
|
|
54
|
+
grid,
|
|
55
|
+
val
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
drawRect
|
|
44
60
|
};
|
package/shader.js
CHANGED
|
@@ -1,68 +1,48 @@
|
|
|
1
1
|
import { isFunction } from "@thi.ng/checks/is-function";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
porterDuffP,
|
|
4
|
+
porterDuffPInt,
|
|
5
|
+
SRC_OVER_F,
|
|
6
|
+
SRC_OVER_I
|
|
7
|
+
} from "@thi.ng/porter-duff/porter-duff";
|
|
3
8
|
import { SYSTEM } from "@thi.ng/random/system";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
const defPattern = (pattern) => {
|
|
10
|
+
const [w, h] = pattern.size;
|
|
11
|
+
return (_, x, y) => pattern.getAtUnsafe(x % w, y % h);
|
|
7
12
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const defStripes = ({
|
|
14
|
+
dir,
|
|
15
|
+
size,
|
|
16
|
+
sizeA,
|
|
17
|
+
a,
|
|
18
|
+
b
|
|
19
|
+
}) => dir === "h" ? (_, x) => x % size < sizeA ? a : b : dir === "v" ? (_, __, y) => y % size < sizeA ? a : b : (_, x, y) => (x + y) % size < sizeA ? a : b;
|
|
20
|
+
const defNoise = (opts) => {
|
|
21
|
+
const { probability, rnd, a, b } = {
|
|
22
|
+
probability: 0.5,
|
|
23
|
+
rnd: SYSTEM,
|
|
24
|
+
...opts
|
|
25
|
+
};
|
|
26
|
+
return () => rnd.probability(probability) ? a : b;
|
|
20
27
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
* See {@link defBlendI} for integer based buffers.
|
|
32
|
-
*
|
|
33
|
-
* @param col
|
|
34
|
-
* @param blend
|
|
35
|
-
* @param isPremultiplied
|
|
36
|
-
*/
|
|
37
|
-
export const defBlendF = (col, blend = SRC_OVER_F, isPremultiplied = false) => {
|
|
38
|
-
blend = isPremultiplied ? blend : porterDuffP(blend);
|
|
39
|
-
return isFunction(col)
|
|
40
|
-
? (buf, x, y) => {
|
|
41
|
-
const dest = buf.getAtUnsafe(x, y);
|
|
42
|
-
return blend(dest, col(buf, x, y), dest);
|
|
43
|
-
}
|
|
44
|
-
: (buf, x, y) => {
|
|
45
|
-
const dest = buf.getAtUnsafe(x, y);
|
|
46
|
-
return blend(dest, col, dest);
|
|
47
|
-
};
|
|
28
|
+
const defBlendF = (col, blend = SRC_OVER_F, isPremultiplied = false) => {
|
|
29
|
+
blend = isPremultiplied ? blend : porterDuffP(blend);
|
|
30
|
+
return isFunction(col) ? (buf, x, y) => {
|
|
31
|
+
const dest = buf.getAtUnsafe(x, y);
|
|
32
|
+
return blend(dest, col(buf, x, y), dest);
|
|
33
|
+
} : (buf, x, y) => {
|
|
34
|
+
const dest = buf.getAtUnsafe(x, y);
|
|
35
|
+
return blend(dest, col, dest);
|
|
36
|
+
};
|
|
48
37
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @param col
|
|
60
|
-
* @param blend
|
|
61
|
-
* @param isPremultiplied
|
|
62
|
-
*/
|
|
63
|
-
export const defBlendI = (col, blend = SRC_OVER_I, isPremultiplied = false) => {
|
|
64
|
-
blend = isPremultiplied ? blend : porterDuffPInt(blend);
|
|
65
|
-
return isFunction(col)
|
|
66
|
-
? (buf, x, y) => blend(col(buf, x, y), buf.getAtUnsafe(x, y))
|
|
67
|
-
: (buf, x, y) => blend(col, buf.getAtUnsafe(x, y));
|
|
38
|
+
const defBlendI = (col, blend = SRC_OVER_I, isPremultiplied = false) => {
|
|
39
|
+
blend = isPremultiplied ? blend : porterDuffPInt(blend);
|
|
40
|
+
return isFunction(col) ? (buf, x, y) => blend(col(buf, x, y), buf.getAtUnsafe(x, y)) : (buf, x, y) => blend(col, buf.getAtUnsafe(x, y));
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
defBlendF,
|
|
44
|
+
defBlendI,
|
|
45
|
+
defNoise,
|
|
46
|
+
defPattern,
|
|
47
|
+
defStripes
|
|
68
48
|
};
|