@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
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
- export const isInBounds2D = ({ size }, x, y) => x >= 0 && x < size[0] && y >= 0 && y < size[1];
3
- export const ensureShader2D = (val) => isFunction(val) ? val : () => val;
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
- export const drawCircle = (grid, x, y, r, val, fill = false) => __draw2D(circleClipped(x, y, r, 0, 0, grid.size[0], grid.size[1], fill), grid, val);
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
- /** @internal */
4
- export const __draw2D = (pts, grid, val) => isFunction(val)
5
- ? __drawShader2D(pts, grid, val)
6
- : __drawSolid2D(pts, grid, val);
7
- /** @internal */
8
- export const __drawSolid2D = (pts, grid, val) => {
9
- if (!pts)
10
- return grid;
11
- if (isPrimitive(val)) {
12
- const { data, offset, stride: [sx, sy], } = grid;
13
- for (let p of pts) {
14
- data[offset + p[0] * sx + p[1] * sy] = val;
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
- else {
18
- for (let p of pts) {
19
- grid.setAtUnsafe(p[0], p[1], val);
20
- }
16
+ } else {
17
+ for (let p of pts) {
18
+ grid.setAtUnsafe(p[0], p[1], val);
21
19
  }
22
- return grid;
20
+ }
21
+ return grid;
23
22
  };
24
- /** @internal */
25
- export const __drawShader2D = (pts, grid, shader) => {
26
- if (!pts)
27
- return grid;
28
- if (isPrimitive(grid.getAtUnsafe(0, 0))) {
29
- const { data, offset, stride: [sx, sy], } = grid;
30
- for (let { 0: x, 1: y } of pts) {
31
- data[offset + x * sx + y * sy] = shader(grid, x, y);
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
- else {
35
- for (let { 0: x, 1: y } of pts) {
36
- grid.setAtUnsafe(x, y, shader(grid, x, y));
37
- }
35
+ } else {
36
+ for (let { 0: x, 1: y } of pts) {
37
+ grid.setAtUnsafe(x, y, shader(grid, x, y));
38
38
  }
39
- return grid;
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
- * Fills cells in the connected region around `x,y` with given value or shader
9
- * function. If the latter, the shader is called for each grid coordinate and
10
- * returns a fill value. Returns updated grid.
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
- const { data, offset, stride: [stride, rowStride], } = img;
22
- let srcVal = img.getAtUnsafe(x, y);
23
- if (isPrimitive(srcVal)) {
24
- return (x, y) => data[offset + x * stride + y * rowStride] === srcVal;
25
- }
26
- if (isIterable(srcVal)) {
27
- srcVal = [...srcVal];
28
- }
29
- return (x, y) => equiv(img.getAtUnsafe(x, y), srcVal);
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
- export const drawLine = (grid, x1, y1, x2, y2, val) => __draw2D(lineClipped(x1, y1, x2, y2, 0, 0, grid.size[0], grid.size[1]), grid, val);
4
- export const traceLine = (grid, x1, y1, x2, y2, fn) => {
5
- const pts = lineClipped(x1, y1, x2, y2, 0, 0, grid.size[0], grid.size[1]);
6
- if (pts) {
7
- for (let p of pts)
8
- fn(p);
9
- }
10
- return grid;
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.62",
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 clean && tsc --declaration",
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.10",
37
- "@thi.ng/checks": "^3.4.10",
38
- "@thi.ng/equiv": "^2.1.35",
39
- "@thi.ng/grid-iterators": "^4.0.34",
40
- "@thi.ng/porter-duff": "^2.1.50",
41
- "@thi.ng/random": "^3.6.16",
42
- "@thi.ng/transducers": "^8.8.13"
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
- "@thi.ng/testament": "^0.4.3",
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": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
123
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
122
124
  }
package/poly.js CHANGED
@@ -1,67 +1,56 @@
1
1
  import { ensureShader2D } from "./checks.js";
2
- /**
3
- * Draws a filled polygon (simple, no holes) into given grid. Each grid cell's
4
- * value is obtained from user supplied shader function which will be called
5
- * with the pixel's `x,y` coords.
6
- *
7
- * Based on Efficient Polygon Fill Algorithm by Darel Rex Finley
8
- * http://alienryderflex.com/polygon_fill/
9
- *
10
- * Bounds calculation and clipping added by Karsten Schmidt
11
- *
12
- * @param grid -
13
- * @param pts -
14
- * @param val -
15
- */
16
- export const fillPoly = (grid, pts, val) => {
17
- const numP = pts.length;
18
- const [width, height] = grid.size;
19
- const shader = ensureShader2D(val);
20
- let minX = Infinity;
21
- let minY = Infinity;
22
- let maxX = -Infinity;
23
- let maxY = -Infinity;
24
- for (let i = numP; i-- > 0;) {
25
- const { 0: x, 1: y } = pts[i];
26
- minX = Math.min(minX, x);
27
- maxX = Math.max(maxX, x);
28
- minY = Math.min(minY, y);
29
- maxY = Math.max(maxY, y);
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
- minX = Math.max(minX | 0, 0);
32
- maxX = Math.min(maxX | 0, width - 1);
33
- minY = Math.max(minY | 0, 0);
34
- maxY = Math.min(maxY | 0, height - 1);
35
- if (minX >= width || maxX < 0 || minY >= height || maxY < 0)
36
- return;
37
- let i = 0;
38
- let k = 0;
39
- let j;
40
- const isec = [];
41
- for (let y = Math.max(0, minY); y <= maxY; y++) {
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
- export 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
- }
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
- export const drawRect = (grid, x, y, w, h, val, fill = false) => {
8
- x |= 0;
9
- y |= 0;
10
- w |= 0;
11
- h |= 0;
12
- const { data, offset, size: [width, height], stride: [sx, sy], } = grid;
13
- if (fill) {
14
- if (x < 0) {
15
- w += x;
16
- x = 0;
17
- }
18
- if (y < 0) {
19
- h += y;
20
- y = 0;
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
- return __draw2D(concat(hlineClipped(x, y, w, 0, 0, width, height), vlineClipped(x, y + 1, h - 2, 0, 0, width, height), hlineClipped(x, y + h - 1, w, 0, 0, width, height), vlineClipped(x + w - 1, y + 1, h - 2, 0, 0, width, height)), grid, val);
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 { porterDuffP, porterDuffPInt, SRC_OVER_F, SRC_OVER_I, } from "@thi.ng/porter-duff/porter-duff";
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
- export const defPattern = (pattern) => {
5
- const [w, h] = pattern.size;
6
- return (_, x, y) => pattern.getAtUnsafe(x % w, y % h);
9
+ const defPattern = (pattern) => {
10
+ const [w, h] = pattern.size;
11
+ return (_, x, y) => pattern.getAtUnsafe(x % w, y % h);
7
12
  };
8
- export const defStripes = ({ dir, size, sizeA, a, b, }) => dir === "h"
9
- ? (_, x) => (x % size < sizeA ? a : b)
10
- : dir === "v"
11
- ? (_, __, y) => (y % size < sizeA ? a : b)
12
- : (_, x, y) => ((x + y) % size < sizeA ? a : b);
13
- export const defNoise = (opts) => {
14
- const { probability, rnd, a, b } = {
15
- probability: 0.5,
16
- rnd: SYSTEM,
17
- ...opts,
18
- };
19
- return () => (rnd.probability(probability) ? a : b);
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
- * Defines a shader (for floating point target buffers) which blends given color
23
- * (or another shader) with a Porter-Duff operator. Unless `isPremultiplied` is
24
- * true, both the given color and existing pixel values in the target buffer are
25
- * considered non-premultiplied.
26
- *
27
- * @remarks
28
- * The default PD blend op is `SRC_OVER_I`. See
29
- * [@thi.ng/porter-duff](https://thi.ng/porter-duff) for more info.
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
- * Similar to {@link defBlendF}, but for integer based target buffers. Defines a
51
- * shader which blends given color (or another shader) with a Porter-Duff
52
- * operator. Unless `isPremultiplied` is true, both the given color and existing
53
- * pixel values in the target buffer are considered non-premultiplied.
54
- *
55
- * @remarks
56
- * The default PD blend op is `SRC_OVER_I`. See
57
- * [@thi.ng/porter-duff](https://thi.ng/porter-duff) for more info.
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
  };