@pixerate/editor 0.112.0 → 0.114.0
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/THIRD_PARTY_NOTICES.md +11 -0
- package/dist/animation-editor/index.cjs +60 -54
- package/dist/animation-editor/index.cjs.map +1 -1
- package/dist/animation-editor/index.d.cts +3 -3
- package/dist/animation-editor/index.d.ts +3 -3
- package/dist/animation-editor/index.js +14 -8
- package/dist/animation-editor/index.js.map +1 -1
- package/dist/builtin-CY97ppKM.d.cts +354 -0
- package/dist/builtin-CY97ppKM.d.ts +354 -0
- package/dist/canvas/index.cjs +3 -3
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.js +9 -9
- package/dist/chunk-26PGXHY7.cjs +753 -0
- package/dist/chunk-26PGXHY7.cjs.map +1 -0
- package/dist/chunk-2OJACTPR.cjs +929 -0
- package/dist/chunk-2OJACTPR.cjs.map +1 -0
- package/dist/chunk-3UFGNHSP.js +929 -0
- package/dist/chunk-3UFGNHSP.js.map +1 -0
- package/dist/{chunk-YGIMK4NX.cjs → chunk-5OVJHMZQ.cjs} +757 -825
- package/dist/chunk-5OVJHMZQ.cjs.map +1 -0
- package/dist/chunk-643B2HKC.cjs +534 -0
- package/dist/chunk-643B2HKC.cjs.map +1 -0
- package/dist/chunk-6FCKOS2B.js +534 -0
- package/dist/chunk-6FCKOS2B.js.map +1 -0
- package/dist/chunk-BRLYOPLT.js +2574 -0
- package/dist/chunk-BRLYOPLT.js.map +1 -0
- package/dist/{chunk-LQEEDHOP.js → chunk-C6C5PDKU.js} +759 -761
- package/dist/chunk-C6C5PDKU.js.map +1 -0
- package/dist/chunk-DFQEX3AM.cjs +781 -0
- package/dist/chunk-DFQEX3AM.cjs.map +1 -0
- package/dist/{chunk-CZOXTEMN.js → chunk-EUVSQ25B.js} +336 -404
- package/dist/chunk-EUVSQ25B.js.map +1 -0
- package/dist/chunk-G5NMLUVF.cjs +2574 -0
- package/dist/chunk-G5NMLUVF.cjs.map +1 -0
- package/dist/chunk-LKCYANMW.js +781 -0
- package/dist/chunk-LKCYANMW.js.map +1 -0
- package/dist/{chunk-W3GXSUSQ.cjs → chunk-LPLCWZTM.cjs} +5087 -1283
- package/dist/chunk-LPLCWZTM.cjs.map +1 -0
- package/dist/chunk-MMVHBKMM.js +753 -0
- package/dist/chunk-MMVHBKMM.js.map +1 -0
- package/dist/{chunk-POGBUYWE.cjs → chunk-ST7E3NEE.cjs} +857 -859
- package/dist/chunk-ST7E3NEE.cjs.map +1 -0
- package/dist/{chunk-7VOHOPLW.cjs → chunk-TCKIXI46.cjs} +59 -59
- package/dist/{chunk-7VOHOPLW.cjs.map → chunk-TCKIXI46.cjs.map} +1 -1
- package/dist/{chunk-XIOMMGPD.cjs → chunk-TFOPHZ3U.cjs} +1 -1
- package/dist/chunk-TFOPHZ3U.cjs.map +1 -0
- package/dist/{chunk-Z4BC6M74.js → chunk-UBIXVXPR.js} +2 -2
- package/dist/{chunk-BLWCAQCW.js → chunk-VXR7XWMF.js} +4574 -770
- package/dist/chunk-VXR7XWMF.js.map +1 -0
- package/dist/{chunk-HNS7UHCM.js → chunk-XK5LZKBD.js} +1 -1
- package/dist/chunk-XK5LZKBD.js.map +1 -0
- package/dist/cms/index.cjs +146 -0
- package/dist/cms/index.cjs.map +1 -0
- package/dist/cms/index.d.cts +51 -0
- package/dist/cms/index.d.ts +51 -0
- package/dist/cms/index.js +146 -0
- package/dist/{export-DNu_Jr8p.d.ts → export-_1dUKwpF.d.ts} +326 -195
- package/dist/{export-DBba-buV.d.cts → export-b6NjCZ5-.d.cts} +326 -195
- package/dist/image-editor/index.cjs +2377 -1291
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +149 -97
- package/dist/image-editor/index.d.ts +149 -97
- package/dist/image-editor/index.js +1343 -257
- package/dist/image-editor/index.js.map +1 -1
- package/dist/opentype-BZEOSOX3.d.ts +188 -0
- package/dist/opentype-Dpe75vL5.d.cts +188 -0
- package/dist/paint/index.cjs +63 -4
- package/dist/paint/index.cjs.map +1 -1
- package/dist/paint/index.d.cts +30 -3
- package/dist/paint/index.d.ts +30 -3
- package/dist/paint/index.js +62 -3
- package/dist/paint-editor/index.cjs +146 -145
- package/dist/paint-editor/index.cjs.map +1 -1
- package/dist/paint-editor/index.d.cts +9 -8
- package/dist/paint-editor/index.d.ts +9 -8
- package/dist/paint-editor/index.js +6 -5
- package/dist/paint-editor/index.js.map +1 -1
- package/dist/raster/index.cjs +53 -3
- package/dist/raster/index.cjs.map +1 -1
- package/dist/raster/index.d.cts +62 -91
- package/dist/raster/index.d.ts +62 -91
- package/dist/raster/index.js +59 -9
- package/dist/{render-BEriFuqK.d.cts → render-B1K_OoLy.d.cts} +87 -2
- package/dist/{render-tjzKaik-.d.ts → render-CrmHOgpo.d.ts} +87 -2
- package/dist/{blending-aOE6Y3UE.d.cts → retouch-Bxkuc0KH.d.cts} +219 -2
- package/dist/{blending-DXl06NSx.d.ts → retouch-Do6tBs2H.d.ts} +219 -2
- package/dist/{surface-C8RRg_Bh.d.ts → surface-Cn30xIV6.d.cts} +6 -1
- package/dist/{surface-C8RRg_Bh.d.cts → surface-Cn30xIV6.d.ts} +6 -1
- package/dist/{svg-D_cfkhlB.d.cts → svg-BnRj0q8i.d.cts} +16 -4
- package/dist/{svg-wIaKLrU0.d.ts → svg-CmmBFfGT.d.ts} +16 -4
- package/dist/{types-DtL_qLFz.d.ts → types-1SUQKDAw.d.ts} +273 -4
- package/dist/{types-DyQq-WPY.d.cts → types-yINF17Ta.d.cts} +273 -4
- package/dist/vector/index.cjs +12170 -7343
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.cts +1579 -16
- package/dist/vector/index.d.ts +1579 -16
- package/dist/vector/index.js +6303 -1476
- package/dist/vector/index.js.map +1 -1
- package/dist/warp-B39VsOtd.d.cts +348 -0
- package/dist/warp-DMN30aY6.d.ts +348 -0
- package/dist/zlib-dxQdgHyN.d.cts +95 -0
- package/dist/zlib-dxQdgHyN.d.ts +95 -0
- package/package.json +6 -1
- package/skills/pixerate-image-editor/SKILL.md +34 -34
- package/skills/pixerate-image-editor/references/color-management.md +37 -0
- package/skills/pixerate-image-editor/references/photoshop-files.md +39 -0
- package/skills/pixerate-image-editor/references/retouching.md +36 -0
- package/skills/pixerate-vector/SKILL.md +154 -5
- package/dist/chunk-BLWCAQCW.js.map +0 -1
- package/dist/chunk-CZOXTEMN.js.map +0 -1
- package/dist/chunk-FTBZPI77.cjs +0 -1
- package/dist/chunk-FTBZPI77.cjs.map +0 -1
- package/dist/chunk-HNS7UHCM.js.map +0 -1
- package/dist/chunk-JLYX4V57.cjs +0 -2001
- package/dist/chunk-JLYX4V57.cjs.map +0 -1
- package/dist/chunk-KB2YBCVS.js +0 -2001
- package/dist/chunk-KB2YBCVS.js.map +0 -1
- package/dist/chunk-LQEEDHOP.js.map +0 -1
- package/dist/chunk-POGBUYWE.cjs.map +0 -1
- package/dist/chunk-VKK5VS2T.js +0 -1
- package/dist/chunk-W3GXSUSQ.cjs.map +0 -1
- package/dist/chunk-XIOMMGPD.cjs.map +0 -1
- package/dist/chunk-YGIMK4NX.cjs.map +0 -1
- package/dist/homography-CZ-tFjay.d.cts +0 -50
- package/dist/homography-Ctfjoc1b.d.ts +0 -50
- package/dist/warp-CWHZzE3x.d.ts +0 -118
- package/dist/warp-D5jz_tN7.d.cts +0 -118
- /package/dist/{chunk-Z4BC6M74.js.map → chunk-UBIXVXPR.js.map} +0 -0
- /package/dist/{chunk-VKK5VS2T.js.map → cms/index.js.map} +0 -0
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkTCKIXI46cjs = require('./chunk-TCKIXI46.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkTFOPHZ3Ucjs = require('./chunk-TFOPHZ3U.cjs');
|
|
13
|
+
|
|
14
|
+
// src/paint/heal.ts
|
|
15
|
+
var TOL = 2e-3;
|
|
16
|
+
var FINE_ITERS = 30;
|
|
17
|
+
var FINE_OMEGA = 1.7;
|
|
18
|
+
function solveMembrane(w, h, unknown, v) {
|
|
19
|
+
if (unknown.length !== w * h || v.length !== w * h) throw new RangeError(`solveMembrane: expected ${w * h} cells, got ${unknown.length} and ${v.length}.`);
|
|
20
|
+
const u = new Uint8Array(w * h);
|
|
21
|
+
for (let i = 0; i < u.length; i++) u[i] = unknown[i] ? 1 : 0;
|
|
22
|
+
solveLevel(w, h, u, v, 0);
|
|
23
|
+
}
|
|
24
|
+
function solveLevel(w, h, unknown, v, depth) {
|
|
25
|
+
let nUnknown = 0;
|
|
26
|
+
let knownSum = 0;
|
|
27
|
+
let nKnown = 0;
|
|
28
|
+
for (let i = 0; i < unknown.length; i++) {
|
|
29
|
+
if (unknown[i]) nUnknown++;
|
|
30
|
+
else {
|
|
31
|
+
knownSum += v[i];
|
|
32
|
+
nKnown++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (nUnknown === 0 || nKnown === 0) return;
|
|
36
|
+
if (w >= 8 && h >= 8 && nUnknown > 64 && depth < 16) {
|
|
37
|
+
const cw = Math.ceil(w / 2);
|
|
38
|
+
const chh = Math.ceil(h / 2);
|
|
39
|
+
const cu = new Uint8Array(cw * chh).fill(1);
|
|
40
|
+
const cv = new Float32Array(cw * chh);
|
|
41
|
+
for (let cy = 0; cy < chh; cy++) {
|
|
42
|
+
for (let cx = 0; cx < cw; cx++) {
|
|
43
|
+
let s = 0;
|
|
44
|
+
let n = 0;
|
|
45
|
+
for (let k = 0; k < 4; k++) {
|
|
46
|
+
const x = cx * 2 + (k & 1);
|
|
47
|
+
const y = cy * 2 + (k >> 1);
|
|
48
|
+
if (x < w && y < h && !unknown[y * w + x]) {
|
|
49
|
+
s += v[y * w + x];
|
|
50
|
+
n++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (n > 0) {
|
|
54
|
+
cu[cy * cw + cx] = 0;
|
|
55
|
+
cv[cy * cw + cx] = s / n;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
solveLevel(cw, chh, cu, cv, depth + 1);
|
|
60
|
+
for (let y = 0; y < h; y++) {
|
|
61
|
+
const fy = Math.min(chh - 1, Math.max(0, (y + 0.5) / 2 - 0.5));
|
|
62
|
+
const y0 = Math.floor(fy);
|
|
63
|
+
const y1 = Math.min(chh - 1, y0 + 1);
|
|
64
|
+
const ty = fy - y0;
|
|
65
|
+
for (let x = 0; x < w; x++) {
|
|
66
|
+
if (!unknown[y * w + x]) continue;
|
|
67
|
+
const fx = Math.min(cw - 1, Math.max(0, (x + 0.5) / 2 - 0.5));
|
|
68
|
+
const x0 = Math.floor(fx);
|
|
69
|
+
const x1 = Math.min(cw - 1, x0 + 1);
|
|
70
|
+
const tx = fx - x0;
|
|
71
|
+
const a = cv[y0 * cw + x0] + (cv[y0 * cw + x1] - cv[y0 * cw + x0]) * tx;
|
|
72
|
+
const b = cv[y1 * cw + x0] + (cv[y1 * cw + x1] - cv[y1 * cw + x0]) * tx;
|
|
73
|
+
v[y * w + x] = a + (b - a) * ty;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
sor(w, h, unknown, v, FINE_ITERS, FINE_OMEGA);
|
|
77
|
+
} else {
|
|
78
|
+
const mean = knownSum / nKnown;
|
|
79
|
+
for (let i = 0; i < v.length; i++) if (unknown[i]) v[i] = mean;
|
|
80
|
+
sor(w, h, unknown, v, 2e3, 1.85);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function sor(w, h, unknown, v, maxIter, omega) {
|
|
84
|
+
let n = 0;
|
|
85
|
+
for (let i = 0; i < unknown.length; i++) if (unknown[i]) n++;
|
|
86
|
+
const cells = new Uint32Array(n);
|
|
87
|
+
const masks = new Uint8Array(n);
|
|
88
|
+
for (let i = 0, k = 0; i < unknown.length; i++) {
|
|
89
|
+
if (!unknown[i]) continue;
|
|
90
|
+
const x = i % w;
|
|
91
|
+
const y = (i - x) / w;
|
|
92
|
+
cells[k] = i;
|
|
93
|
+
masks[k++] = (x > 0 ? 1 : 0) | (x + 1 < w ? 2 : 0) | (y > 0 ? 4 : 0) | (y + 1 < h ? 8 : 0);
|
|
94
|
+
}
|
|
95
|
+
for (let it = 0; it < maxIter; it++) {
|
|
96
|
+
let maxD = 0;
|
|
97
|
+
for (let k = 0; k < n; k++) {
|
|
98
|
+
const i = cells[k];
|
|
99
|
+
const m = masks[k];
|
|
100
|
+
let s;
|
|
101
|
+
let c;
|
|
102
|
+
if (m === 15) {
|
|
103
|
+
s = v[i - 1] + v[i + 1] + v[i - w] + v[i + w];
|
|
104
|
+
c = 4;
|
|
105
|
+
} else {
|
|
106
|
+
s = 0;
|
|
107
|
+
c = 0;
|
|
108
|
+
if (m & 1) s += v[i - 1], c++;
|
|
109
|
+
if (m & 2) s += v[i + 1], c++;
|
|
110
|
+
if (m & 4) s += v[i - w], c++;
|
|
111
|
+
if (m & 8) s += v[i + w], c++;
|
|
112
|
+
if (c === 0) continue;
|
|
113
|
+
}
|
|
114
|
+
const d = omega * (s / c - v[i]);
|
|
115
|
+
v[i] += d;
|
|
116
|
+
const ad = d < 0 ? -d : d;
|
|
117
|
+
if (ad > maxD) maxD = ad;
|
|
118
|
+
}
|
|
119
|
+
if (maxD < TOL) break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function seamlessClone(w, h, ch, src, dst, mask) {
|
|
123
|
+
const n = w * h;
|
|
124
|
+
if (src.length !== n * ch || dst.length !== n * ch || mask.length !== n) throw new RangeError("seamlessClone: src, dst and mask must cover w \xD7 h pixels.");
|
|
125
|
+
const out = new Float32Array(n * ch);
|
|
126
|
+
const hv = new Float32Array(n);
|
|
127
|
+
for (let c = 0; c < ch; c++) {
|
|
128
|
+
for (let i = 0; i < n; i++) hv[i] = mask[i] ? 0 : dst[i * ch + c] - src[i * ch + c];
|
|
129
|
+
solveMembrane(w, h, mask, hv);
|
|
130
|
+
for (let i = 0; i < n; i++) out[i * ch + c] = mask[i] ? src[i * ch + c] + hv[i] : dst[i * ch + c];
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
function membraneFill(w, h, ch, img, hole) {
|
|
135
|
+
const n = w * h;
|
|
136
|
+
const out = new Float32Array(n * ch);
|
|
137
|
+
const v = new Float32Array(n);
|
|
138
|
+
for (let c = 0; c < ch; c++) {
|
|
139
|
+
for (let i = 0; i < n; i++) v[i] = hole[i] ? 0 : img[i * ch + c];
|
|
140
|
+
solveMembrane(w, h, hole, v);
|
|
141
|
+
for (let i = 0; i < n; i++) out[i * ch + c] = v[i];
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
function dilateMask(w, h, mask, r) {
|
|
146
|
+
const tmp = new Uint8Array(w * h);
|
|
147
|
+
for (let y = 0; y < h; y++) {
|
|
148
|
+
for (let x = 0; x < w; x++) {
|
|
149
|
+
if (!mask[y * w + x]) continue;
|
|
150
|
+
for (let xx = Math.max(0, x - r); xx <= Math.min(w - 1, x + r); xx++) tmp[y * w + xx] = 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const out = new Uint8Array(w * h);
|
|
154
|
+
for (let y = 0; y < h; y++) {
|
|
155
|
+
for (let x = 0; x < w; x++) {
|
|
156
|
+
if (!tmp[y * w + x]) continue;
|
|
157
|
+
for (let yy = Math.max(0, y - r); yy <= Math.min(h - 1, y + r); yy++) out[yy * w + x] = 1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
var MaskIntegral = class {
|
|
163
|
+
constructor(w, h, mask) {
|
|
164
|
+
this.w = w;
|
|
165
|
+
this.h = h;
|
|
166
|
+
const W = w + 1;
|
|
167
|
+
this.s = new Uint32Array(W * (h + 1));
|
|
168
|
+
for (let y = 0; y < h; y++) {
|
|
169
|
+
let row = 0;
|
|
170
|
+
for (let x = 0; x < w; x++) {
|
|
171
|
+
row += mask[y * w + x] ? 1 : 0;
|
|
172
|
+
this.s[(y + 1) * W + x + 1] = this.s[y * W + x + 1] + row;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
/** Masked cells in [x0, x1) × [y0, y1) (clipped to the grid). */
|
|
180
|
+
count(x0, y0, x1, y1) {
|
|
181
|
+
const W = this.w + 1;
|
|
182
|
+
const a = Math.max(0, Math.min(this.w, x0));
|
|
183
|
+
const b = Math.max(0, Math.min(this.h, y0));
|
|
184
|
+
const c = Math.max(0, Math.min(this.w, x1));
|
|
185
|
+
const d = Math.max(0, Math.min(this.h, y1));
|
|
186
|
+
if (c <= a || d <= b) return 0;
|
|
187
|
+
return this.s[d * W + c] - this.s[b * W + c] - this.s[d * W + a] + this.s[b * W + a];
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function maskBounds(w, h, mask) {
|
|
191
|
+
let x0 = w;
|
|
192
|
+
let y0 = h;
|
|
193
|
+
let x1 = -1;
|
|
194
|
+
let y1 = -1;
|
|
195
|
+
for (let y = 0; y < h; y++) {
|
|
196
|
+
for (let x = 0; x < w; x++) {
|
|
197
|
+
if (!mask[y * w + x]) continue;
|
|
198
|
+
if (x < x0) x0 = x;
|
|
199
|
+
if (x > x1) x1 = x;
|
|
200
|
+
if (y < y0) y0 = y;
|
|
201
|
+
if (y > y1) y1 = y;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return x1 < 0 ? null : [x0, y0, x1 + 1, y1 + 1];
|
|
205
|
+
}
|
|
206
|
+
function bestOffset(w, h, ch, img, hole, ring, maxRadius) {
|
|
207
|
+
const bb = maskBounds(w, h, hole);
|
|
208
|
+
if (!bb) return null;
|
|
209
|
+
const extent = Math.max(w, h);
|
|
210
|
+
const R = Math.max(0, Math.min(extent, Math.floor(maxRadius)));
|
|
211
|
+
if (R === 0) return null;
|
|
212
|
+
const rg = Math.max(1, Math.min(extent, Math.floor(ring)));
|
|
213
|
+
const hs = new MaskIntegral(w, h, hole);
|
|
214
|
+
const x0 = bb[0] - rg;
|
|
215
|
+
const y0 = bb[1] - rg;
|
|
216
|
+
const x1 = bb[2] + rg;
|
|
217
|
+
const y1 = bb[3] + rg;
|
|
218
|
+
const pts = [];
|
|
219
|
+
for (let y = Math.max(0, y0); y < Math.min(h, y1); y++) {
|
|
220
|
+
for (let x = Math.max(0, x0); x < Math.min(w, x1); x++) {
|
|
221
|
+
if (hole[y * w + x]) continue;
|
|
222
|
+
if (hs.count(x - rg, y - rg, x + rg + 1, y + rg + 1) > 0) pts.push(x, y);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const stride = Math.max(1, Math.floor(pts.length / 2 / 2e3));
|
|
226
|
+
const sx = [];
|
|
227
|
+
const sy = [];
|
|
228
|
+
for (let i = 0; i < pts.length; i += 2 * stride) {
|
|
229
|
+
sx.push(pts[i]);
|
|
230
|
+
sy.push(pts[i + 1]);
|
|
231
|
+
}
|
|
232
|
+
const n = Math.max(1, sx.length);
|
|
233
|
+
const evalAt = (dx, dy, cutoff) => {
|
|
234
|
+
if (dx === 0 && dy === 0) return null;
|
|
235
|
+
const hx0 = x0 + dx;
|
|
236
|
+
const hy0 = y0 + dy;
|
|
237
|
+
const hx1 = x1 + dx;
|
|
238
|
+
const hy1 = y1 + dy;
|
|
239
|
+
if (hx0 < 0 || hy0 < 0 || hx1 > w || hy1 > h) return null;
|
|
240
|
+
if (hs.count(hx0, hy0, hx1, hy1) !== 0) return null;
|
|
241
|
+
const penalty = 1 + 1e-3 * (Math.hypot(dx, dy) / R);
|
|
242
|
+
let e = 0;
|
|
243
|
+
for (let i = 0; i < sx.length; i++) {
|
|
244
|
+
const a = (sy[i] * w + sx[i]) * ch;
|
|
245
|
+
const b = ((sy[i] + dy) * w + sx[i] + dx) * ch;
|
|
246
|
+
for (let c = 0; c < ch; c++) {
|
|
247
|
+
const d = img[a + c] - img[b + c];
|
|
248
|
+
e += d * d;
|
|
249
|
+
}
|
|
250
|
+
if ((i & 31) === 31 && e / n * penalty >= cutoff) return null;
|
|
251
|
+
}
|
|
252
|
+
return e / n * penalty;
|
|
253
|
+
};
|
|
254
|
+
const found = { best: null, e: Infinity };
|
|
255
|
+
const consider = (dx, dy) => {
|
|
256
|
+
const e = evalAt(dx, dy, found.e);
|
|
257
|
+
if (e !== null && e < found.e) {
|
|
258
|
+
found.e = e;
|
|
259
|
+
found.best = [dx, dy];
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const step = Math.max(1, Math.floor(R / 24));
|
|
263
|
+
for (let dy = -R; dy <= R; dy += step) for (let dx = -R; dx <= R; dx += step) consider(dx, dy);
|
|
264
|
+
if (step > 1 && found.best) {
|
|
265
|
+
const [bx, by] = found.best;
|
|
266
|
+
for (let dy = by - step; dy <= by + step; dy++) for (let dx = bx - step; dx <= bx + step; dx++) consider(dx, dy);
|
|
267
|
+
}
|
|
268
|
+
return found.best;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/paint/retouch.ts
|
|
272
|
+
var TONE_RANGES = ["shadows", "midtones", "highlights"];
|
|
273
|
+
function luma(r, g, b) {
|
|
274
|
+
return 0.299 * r + 0.587 * g + 0.114 * b;
|
|
275
|
+
}
|
|
276
|
+
function dodgeBurnCurve(v, e, range, burn) {
|
|
277
|
+
const x = Math.max(0, v);
|
|
278
|
+
const k = Math.min(1, Math.max(0, e));
|
|
279
|
+
const c = Math.min(1, x);
|
|
280
|
+
if (range === "midtones") {
|
|
281
|
+
const w2 = Math.min(1, Math.max(0, 4 * x * (1 - x)));
|
|
282
|
+
return x + w2 * (Math.pow(c, burn ? 1 + k : 1 / (1 + k)) - x);
|
|
283
|
+
}
|
|
284
|
+
const w = range === "shadows" ? (1 - c) * (1 - c) : c * c;
|
|
285
|
+
return burn ? x - k * w * x : x + k * w * (1 - c);
|
|
286
|
+
}
|
|
287
|
+
function compressGamut(c, l) {
|
|
288
|
+
const L = Math.min(1, Math.max(0, l));
|
|
289
|
+
const lo = Math.min(c[0], c[1], c[2]);
|
|
290
|
+
const hi = Math.max(c[0], c[1], c[2]);
|
|
291
|
+
let t = 1;
|
|
292
|
+
if (hi > 1 && hi - L > 1e-9) t = Math.min(t, (1 - L) / (hi - L));
|
|
293
|
+
if (lo < 0 && L - lo > 1e-9) t = Math.min(t, L / (L - lo));
|
|
294
|
+
for (let i = 0; i < 3; i++) c[i] = L + (c[i] - L) * t;
|
|
295
|
+
}
|
|
296
|
+
function dodgeBurn(c, e, range, burn, protectTones) {
|
|
297
|
+
if (!(e > 0)) return c;
|
|
298
|
+
if (protectTones) {
|
|
299
|
+
const l = luma(c[0], c[1], c[2]);
|
|
300
|
+
const nl = dodgeBurnCurve(l, e, range, burn);
|
|
301
|
+
if (l > 1e-6) for (let i = 0; i < 3; i++) c[i] *= nl / l;
|
|
302
|
+
else c[0] = c[1] = c[2] = nl;
|
|
303
|
+
compressGamut(c, nl);
|
|
304
|
+
} else for (let i = 0; i < 3; i++) c[i] = dodgeBurnCurve(c[i], e, range, burn);
|
|
305
|
+
return c;
|
|
306
|
+
}
|
|
307
|
+
function saturationOf(r, g, b) {
|
|
308
|
+
const lo = Math.min(r, g, b);
|
|
309
|
+
const hi = Math.max(r, g, b);
|
|
310
|
+
return hi <= 1e-6 ? 0 : Math.min(1, Math.max(0, (hi - lo) / hi));
|
|
311
|
+
}
|
|
312
|
+
function sponge(c, amount, saturate, vibrance) {
|
|
313
|
+
let a = Math.min(1, Math.max(0, amount));
|
|
314
|
+
if (!(a > 0)) return c;
|
|
315
|
+
if (vibrance) {
|
|
316
|
+
const s = saturationOf(c[0], c[1], c[2]);
|
|
317
|
+
a *= saturate ? 1 - s : 0.25 + 0.75 * s;
|
|
318
|
+
}
|
|
319
|
+
const l = luma(c[0], c[1], c[2]);
|
|
320
|
+
const k = saturate ? 1 + a : 1 - a;
|
|
321
|
+
for (let i = 0; i < 3; i++) c[i] = l + (c[i] - l) * k;
|
|
322
|
+
compressGamut(c, l);
|
|
323
|
+
return c;
|
|
324
|
+
}
|
|
325
|
+
function perDabStrength(e, spacing) {
|
|
326
|
+
return 1 - Math.pow(1 - Math.min(1, Math.max(0, e)), Math.min(1, Math.max(0.01, spacing)));
|
|
327
|
+
}
|
|
328
|
+
var RETOUCH_SAMPLES = ["current", "current-below", "all"];
|
|
329
|
+
var SPOT_HEAL_TYPES = ["proximity-match", "smooth"];
|
|
330
|
+
var DEFAULT_RETOUCH = {
|
|
331
|
+
aligned: true,
|
|
332
|
+
sample: "current",
|
|
333
|
+
spotType: "proximity-match",
|
|
334
|
+
range: "midtones",
|
|
335
|
+
exposure: 0.5,
|
|
336
|
+
protectTones: true,
|
|
337
|
+
spongeMode: "desaturate",
|
|
338
|
+
vibrance: true,
|
|
339
|
+
strength: 0.5
|
|
340
|
+
};
|
|
341
|
+
function normalizeRetouch(raw = {}, base = DEFAULT_RETOUCH) {
|
|
342
|
+
const unit = (v, d) => typeof v === "number" && Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : d;
|
|
343
|
+
const bool = (v, d) => typeof v === "boolean" ? v : d;
|
|
344
|
+
const pick = (v, all, d) => all.includes(v) ? v : d;
|
|
345
|
+
return {
|
|
346
|
+
aligned: bool(raw.aligned, base.aligned),
|
|
347
|
+
sample: pick(raw.sample, RETOUCH_SAMPLES, base.sample),
|
|
348
|
+
spotType: pick(raw.spotType, SPOT_HEAL_TYPES, base.spotType),
|
|
349
|
+
range: pick(raw.range, TONE_RANGES, base.range),
|
|
350
|
+
exposure: unit(raw.exposure, base.exposure),
|
|
351
|
+
protectTones: bool(raw.protectTones, base.protectTones),
|
|
352
|
+
spongeMode: pick(raw.spongeMode, ["desaturate", "saturate"], base.spongeMode),
|
|
353
|
+
vibrance: bool(raw.vibrance, base.vibrance),
|
|
354
|
+
strength: unit(raw.strength, base.strength)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
var TilePixelSource = (_class = class {
|
|
358
|
+
constructor(readTile, channels, offset = { x: 0, y: 0 }) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
359
|
+
this.readTile = readTile;
|
|
360
|
+
this.channels = channels;
|
|
361
|
+
this.offset = offset;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
__init() {this.cache = /* @__PURE__ */ new Map()}
|
|
367
|
+
__init2() {this.lastKey = NaN}
|
|
368
|
+
__init3() {this.last = null}
|
|
369
|
+
sample(x, y, out) {
|
|
370
|
+
const lx = x - this.offset.x;
|
|
371
|
+
const ly = y - this.offset.y;
|
|
372
|
+
const tx = Math.floor(lx / _chunkTFOPHZ3Ucjs.TILE);
|
|
373
|
+
const ty = Math.floor(ly / _chunkTFOPHZ3Ucjs.TILE);
|
|
374
|
+
const key = _chunkTFOPHZ3Ucjs.tileKey.call(void 0, tx, ty);
|
|
375
|
+
if (key !== this.lastKey) {
|
|
376
|
+
let t2 = this.cache.get(key);
|
|
377
|
+
if (t2 === void 0) {
|
|
378
|
+
t2 = this.readTile(tx, ty);
|
|
379
|
+
this.cache.set(key, t2);
|
|
380
|
+
}
|
|
381
|
+
this.last = t2;
|
|
382
|
+
this.lastKey = key;
|
|
383
|
+
}
|
|
384
|
+
const t = this.last;
|
|
385
|
+
if (!t) {
|
|
386
|
+
out[0] = out[1] = out[2] = out[3] = 0;
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
const p = (ly - ty * _chunkTFOPHZ3Ucjs.TILE) * _chunkTFOPHZ3Ucjs.TILE + (lx - tx * _chunkTFOPHZ3Ucjs.TILE);
|
|
390
|
+
if (this.channels === 1) {
|
|
391
|
+
out[0] = out[1] = out[2] = t[p];
|
|
392
|
+
out[3] = 255;
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
const i = p * 4;
|
|
396
|
+
out[0] = t[i];
|
|
397
|
+
out[1] = t[i + 1];
|
|
398
|
+
out[2] = t[i + 2];
|
|
399
|
+
out[3] = t[i + 3];
|
|
400
|
+
return out[3] > 0;
|
|
401
|
+
}
|
|
402
|
+
}, _class);
|
|
403
|
+
var RegionPixelSource = class {
|
|
404
|
+
constructor(rect, data) {
|
|
405
|
+
this.rect = rect;
|
|
406
|
+
this.data = data;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
sample(x, y, out) {
|
|
411
|
+
const r = this.rect;
|
|
412
|
+
const lx = x - r.x;
|
|
413
|
+
const ly = y - r.y;
|
|
414
|
+
if (lx < 0 || ly < 0 || lx >= r.width || ly >= r.height) {
|
|
415
|
+
out[0] = out[1] = out[2] = out[3] = 0;
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
const i = (ly * r.width + lx) * 4;
|
|
419
|
+
out[0] = this.data[i];
|
|
420
|
+
out[1] = this.data[i + 1];
|
|
421
|
+
out[2] = this.data[i + 2];
|
|
422
|
+
out[3] = this.data[i + 3];
|
|
423
|
+
return out[3] > 0;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
function readSourceRegion(source, rect, dx = 0, dy = 0) {
|
|
427
|
+
const out = new Float32Array(rect.width * rect.height * 4);
|
|
428
|
+
const px = [0, 0, 0, 0];
|
|
429
|
+
for (let y = 0; y < rect.height; y++) {
|
|
430
|
+
for (let x = 0; x < rect.width; x++) {
|
|
431
|
+
source.sample(rect.x + x + dx, rect.y + y + dy, px);
|
|
432
|
+
const i = (y * rect.width + x) * 4;
|
|
433
|
+
out[i] = px[0];
|
|
434
|
+
out[i + 1] = px[1];
|
|
435
|
+
out[i + 2] = px[2];
|
|
436
|
+
out[i + 3] = px[3];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return out;
|
|
440
|
+
}
|
|
441
|
+
function applyRetouchToTile(coverage, tileData, channels, tx, ty, paint, s, options = {}) {
|
|
442
|
+
const out = options.into ? new Uint8ClampedArray(options.into) : new Uint8ClampedArray(tileData);
|
|
443
|
+
const ox = tx * _chunkTFOPHZ3Ucjs.TILE + s.offset.x;
|
|
444
|
+
const oy = ty * _chunkTFOPHZ3Ucjs.TILE + s.offset.y;
|
|
445
|
+
let x0 = 0;
|
|
446
|
+
let y0 = 0;
|
|
447
|
+
let x1 = _chunkTFOPHZ3Ucjs.TILE;
|
|
448
|
+
let y1 = _chunkTFOPHZ3Ucjs.TILE;
|
|
449
|
+
if (options.region) {
|
|
450
|
+
const r = options.region;
|
|
451
|
+
x0 = Math.max(0, Math.floor(r.x) - ox);
|
|
452
|
+
y0 = Math.max(0, Math.floor(r.y) - oy);
|
|
453
|
+
x1 = Math.min(_chunkTFOPHZ3Ucjs.TILE, Math.ceil(r.x + r.width) - ox);
|
|
454
|
+
y1 = Math.min(_chunkTFOPHZ3Ucjs.TILE, Math.ceil(r.y + r.height) - oy);
|
|
455
|
+
if (x1 <= x0 || y1 <= y0) return out;
|
|
456
|
+
if (options.into) {
|
|
457
|
+
for (let y = y0; y < y1; y++) out.set(tileData.subarray((y * _chunkTFOPHZ3Ucjs.TILE + x0) * channels, (y * _chunkTFOPHZ3Ucjs.TILE + x1) * channels), (y * _chunkTFOPHZ3Ucjs.TILE + x0) * channels);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const sel = s.selection;
|
|
461
|
+
const blend = _nullishCoalesce(s.blend, () => ( "normal"));
|
|
462
|
+
const src = [0, 0, 0, 0];
|
|
463
|
+
const rgb = [0, 0, 0];
|
|
464
|
+
const cb = [0, 0, 0, 0];
|
|
465
|
+
const cs = [0, 0, 0, 0];
|
|
466
|
+
let covKey = NaN;
|
|
467
|
+
let covTile;
|
|
468
|
+
for (let y = y0; y < y1; y++) {
|
|
469
|
+
const dy = oy + y;
|
|
470
|
+
const cty = Math.floor(dy / _chunkTFOPHZ3Ucjs.TILE);
|
|
471
|
+
for (let x = x0; x < x1; x++) {
|
|
472
|
+
const dx = ox + x;
|
|
473
|
+
const ctx = Math.floor(dx / _chunkTFOPHZ3Ucjs.TILE);
|
|
474
|
+
const key = _chunkTFOPHZ3Ucjs.tileKey.call(void 0, ctx, cty);
|
|
475
|
+
if (key !== covKey) {
|
|
476
|
+
covKey = key;
|
|
477
|
+
covTile = coverage.tiles.get(key);
|
|
478
|
+
}
|
|
479
|
+
if (!covTile) continue;
|
|
480
|
+
const c = covTile[(dy - cty * _chunkTFOPHZ3Ucjs.TILE) * _chunkTFOPHZ3Ucjs.TILE + (dx - ctx * _chunkTFOPHZ3Ucjs.TILE)];
|
|
481
|
+
if (c <= 0) continue;
|
|
482
|
+
let k = c * s.opacity;
|
|
483
|
+
if (sel) {
|
|
484
|
+
if (dx < 0 || dy < 0 || dx >= sel.width || dy >= sel.height) continue;
|
|
485
|
+
k *= sel.data[dy * sel.width + dx] / 255;
|
|
486
|
+
}
|
|
487
|
+
if (k > 1) k = 1;
|
|
488
|
+
if (k <= 0) continue;
|
|
489
|
+
const p = y * _chunkTFOPHZ3Ucjs.TILE + x;
|
|
490
|
+
if (channels === 1) {
|
|
491
|
+
const g = out[p];
|
|
492
|
+
let t;
|
|
493
|
+
if (paint.kind === "tone") {
|
|
494
|
+
rgb[0] = rgb[1] = rgb[2] = g / 255;
|
|
495
|
+
paint.tone(rgb);
|
|
496
|
+
t = luma(rgb[0], rgb[1], rgb[2]) * 255;
|
|
497
|
+
} else if (paint.kind === "color") t = paint.color[0];
|
|
498
|
+
else {
|
|
499
|
+
if (!paint.source.sample(dx + paint.dx, dy + paint.dy, src)) continue;
|
|
500
|
+
t = src[0];
|
|
501
|
+
k *= src[3] / 255;
|
|
502
|
+
}
|
|
503
|
+
out[p] = Math.round(g + (t - g) * k);
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const i = p * 4;
|
|
507
|
+
const a = out[i + 3];
|
|
508
|
+
if (paint.kind === "tone") {
|
|
509
|
+
if (a === 0) continue;
|
|
510
|
+
rgb[0] = out[i] / 255;
|
|
511
|
+
rgb[1] = out[i + 1] / 255;
|
|
512
|
+
rgb[2] = out[i + 2] / 255;
|
|
513
|
+
const r0 = rgb[0];
|
|
514
|
+
const g0 = rgb[1];
|
|
515
|
+
const b0 = rgb[2];
|
|
516
|
+
paint.tone(rgb);
|
|
517
|
+
out[i] = Math.round((r0 + (rgb[0] - r0) * k) * 255);
|
|
518
|
+
out[i + 1] = Math.round((g0 + (rgb[1] - g0) * k) * 255);
|
|
519
|
+
out[i + 2] = Math.round((b0 + (rgb[2] - b0) * k) * 255);
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
if (s.lockTransparency && a === 0) continue;
|
|
523
|
+
if (paint.kind === "color") {
|
|
524
|
+
src[0] = paint.color[0];
|
|
525
|
+
src[1] = paint.color[1];
|
|
526
|
+
src[2] = paint.color[2];
|
|
527
|
+
src[3] = paint.color[3];
|
|
528
|
+
} else if (!paint.source.sample(dx + paint.dx, dy + paint.dy, src)) continue;
|
|
529
|
+
for (let ch = 0; ch < 4; ch++) {
|
|
530
|
+
cb[ch] = out[i + ch] / 255;
|
|
531
|
+
cs[ch] = src[ch] / 255;
|
|
532
|
+
}
|
|
533
|
+
const o = _chunkTFOPHZ3Ucjs.blendPixel.call(void 0, blend, cb, cs, k);
|
|
534
|
+
out[i] = Math.round(o[0] * 255);
|
|
535
|
+
out[i + 1] = Math.round(o[1] * 255);
|
|
536
|
+
out[i + 2] = Math.round(o[2] * 255);
|
|
537
|
+
if (!s.lockTransparency) out[i + 3] = Math.round(o[3] * 255);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return out;
|
|
541
|
+
}
|
|
542
|
+
function toneOf(tool, settings) {
|
|
543
|
+
const burn = tool === "burn";
|
|
544
|
+
return (rgb) => {
|
|
545
|
+
dodgeBurn(rgb, settings.exposure, settings.range, burn, settings.protectTones);
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function healPixels(w, h, src, dst, mask) {
|
|
549
|
+
const out = new Float32Array(dst);
|
|
550
|
+
const bb = maskBounds(w, h, mask);
|
|
551
|
+
if (!bb) return out;
|
|
552
|
+
const x0 = Math.max(0, bb[0] - 1);
|
|
553
|
+
const y0 = Math.max(0, bb[1] - 1);
|
|
554
|
+
const x1 = Math.min(w, bb[2] + 1);
|
|
555
|
+
const y1 = Math.min(h, bb[3] + 1);
|
|
556
|
+
const rw = x1 - x0;
|
|
557
|
+
const rh = y1 - y0;
|
|
558
|
+
const s = new Float32Array(rw * rh * 4);
|
|
559
|
+
const d = new Float32Array(rw * rh * 4);
|
|
560
|
+
const m = new Uint8Array(rw * rh);
|
|
561
|
+
for (let y = 0; y < rh; y++) {
|
|
562
|
+
for (let x = 0; x < rw; x++) {
|
|
563
|
+
const gi = (y + y0) * w + x + x0;
|
|
564
|
+
const li = y * rw + x;
|
|
565
|
+
m[li] = mask[gi] ? 1 : 0;
|
|
566
|
+
for (let c = 0; c < 4; c++) {
|
|
567
|
+
s[li * 4 + c] = src[gi * 4 + c];
|
|
568
|
+
d[li * 4 + c] = dst[gi * 4 + c];
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const healed = seamlessClone(rw, rh, 4, s, d, m);
|
|
573
|
+
for (let y = 0; y < rh; y++) {
|
|
574
|
+
for (let x = 0; x < rw; x++) {
|
|
575
|
+
const gi = ((y + y0) * w + x + x0) * 4;
|
|
576
|
+
const li = (y * rw + x) * 4;
|
|
577
|
+
for (let c = 0; c < 4; c++) out[gi + c] = Math.min(255, Math.max(0, healed[li + c]));
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return out;
|
|
581
|
+
}
|
|
582
|
+
function spotHealPixels(w, h, img, hole, size, type, onOffset) {
|
|
583
|
+
const domain = dilateMask(w, h, hole, 2);
|
|
584
|
+
const healMask = dilateMask(w, h, hole, 1);
|
|
585
|
+
let filled = null;
|
|
586
|
+
let bestFound = null;
|
|
587
|
+
if (type === "proximity-match") {
|
|
588
|
+
const ring = Math.min(16, Math.max(3, Math.floor(size / 8)));
|
|
589
|
+
const off = bestOffset(w, h, 4, img, domain, ring, Math.floor(Math.max(w, h) / 2));
|
|
590
|
+
if (off) {
|
|
591
|
+
bestFound = off;
|
|
592
|
+
filled = new Float32Array(img);
|
|
593
|
+
const [ddx, ddy] = off;
|
|
594
|
+
for (let i = 0; i < w * h; i++) {
|
|
595
|
+
if (!domain[i]) continue;
|
|
596
|
+
const x = i % w + ddx;
|
|
597
|
+
const y = Math.floor(i / w) + ddy;
|
|
598
|
+
const j = (y * w + x) * 4;
|
|
599
|
+
for (let c = 0; c < 4; c++) filled[i * 4 + c] = img[j + c];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
_optionalChain([onOffset, 'optionalCall', _ => _(filled ? bestFound : null)]);
|
|
604
|
+
if (!filled) filled = membraneFill(w, h, 4, img, domain);
|
|
605
|
+
return healPixels(w, h, filled, img, healMask);
|
|
606
|
+
}
|
|
607
|
+
function spotHealWindow(bounds, canvas) {
|
|
608
|
+
const g = Math.max(8, Math.ceil(Math.max(bounds.width, bounds.height)));
|
|
609
|
+
const x0 = Math.max(0, bounds.x - g);
|
|
610
|
+
const y0 = Math.max(0, bounds.y - g);
|
|
611
|
+
const x1 = Math.min(canvas.width, bounds.x + bounds.width + g);
|
|
612
|
+
const y1 = Math.min(canvas.height, bounds.y + bounds.height + g);
|
|
613
|
+
return { x: x0, y: y0, width: Math.max(0, x1 - x0), height: Math.max(0, y1 - y0) };
|
|
614
|
+
}
|
|
615
|
+
var RetouchDabStroke = (_class2 = class {
|
|
616
|
+
constructor(brush, target, effect) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);
|
|
617
|
+
this.brush = brush;
|
|
618
|
+
this.effect = effect;
|
|
619
|
+
this.walker = new (0, _chunkTCKIXI46cjs.DabWalker)(brush);
|
|
620
|
+
this.medium = new (0, _chunkTCKIXI46cjs.TileMedium)(target);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
__init4() {this.dabCount = 0}
|
|
625
|
+
__init5() {this.bounds = null}
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
__init6() {this.smoothPos = null}
|
|
629
|
+
__init7() {this.buf = new Float32Array(0)}
|
|
630
|
+
push(points) {
|
|
631
|
+
const dabs = [];
|
|
632
|
+
for (const p of points) this.walker.push(this.smooth(p), dabs);
|
|
633
|
+
return this.paint(dabs);
|
|
634
|
+
}
|
|
635
|
+
finish(last) {
|
|
636
|
+
const dabs = [];
|
|
637
|
+
if (last && this.smoothPos && (this.smoothPos.x !== last.x || this.smoothPos.y !== last.y)) this.walker.push(last, dabs);
|
|
638
|
+
this.walker.finish(dabs);
|
|
639
|
+
return this.paint(dabs);
|
|
640
|
+
}
|
|
641
|
+
smooth(p) {
|
|
642
|
+
const a = 1 - Math.min(0.95, Math.max(0, this.brush.smoothing));
|
|
643
|
+
const cur = this.smoothPos;
|
|
644
|
+
const n = cur && a < 1 ? { ...p, x: cur.x + (p.x - cur.x) * a, y: cur.y + (p.y - cur.y) * a } : p;
|
|
645
|
+
this.smoothPos = n;
|
|
646
|
+
return n;
|
|
647
|
+
}
|
|
648
|
+
paint(dabs) {
|
|
649
|
+
const rects = [];
|
|
650
|
+
for (const d of dabs) {
|
|
651
|
+
const rect = _chunkTCKIXI46cjs.dabRect.call(void 0, d, this.brush.hardness);
|
|
652
|
+
const n = rect.width * rect.height;
|
|
653
|
+
if (this.buf.length < n) this.buf = new Float32Array(n);
|
|
654
|
+
const cov = this.buf.subarray(0, n);
|
|
655
|
+
_chunkTCKIXI46cjs.rasterizeDab.call(void 0, { ...d, alpha: 1 }, this.brush.hardness, rect, cov);
|
|
656
|
+
this.medium.reset();
|
|
657
|
+
this.effect(this.medium, d, rect, cov);
|
|
658
|
+
rects.push(rect);
|
|
659
|
+
this.bounds = unionRect(this.bounds, rect);
|
|
660
|
+
this.dabCount++;
|
|
661
|
+
}
|
|
662
|
+
return rects;
|
|
663
|
+
}
|
|
664
|
+
}, _class2);
|
|
665
|
+
function smudgeEffect(brush, strength, mixing = "rgb") {
|
|
666
|
+
const s = Math.min(1, Math.max(0, strength));
|
|
667
|
+
const tip = new (0, _chunkTCKIXI46cjs.SmudgeTip)({ strength: s, length: s, mixing }, brush.size);
|
|
668
|
+
return (medium, d, rect, cov) => tip.dab(medium, { x: d.x, y: d.y, radius: d.radius, opacity: d.opacity * d.alpha }, rect, cov);
|
|
669
|
+
}
|
|
670
|
+
function spongeEffect(brush, saturate, vibrance) {
|
|
671
|
+
const rgb = [0, 0, 0];
|
|
672
|
+
return (medium, d, rect, cov) => {
|
|
673
|
+
const w = rect.width;
|
|
674
|
+
for (let yy = 0; yy < rect.height; yy++) {
|
|
675
|
+
for (let xx = 0; xx < w; xx++) {
|
|
676
|
+
const cv = cov[yy * w + xx];
|
|
677
|
+
if (cv <= 0) continue;
|
|
678
|
+
const dx = rect.x + xx;
|
|
679
|
+
const dy = rect.y + yy;
|
|
680
|
+
const k = perDabStrength(cv * d.alpha * d.opacity * 0.5, brush.spacing) * medium.selectionAt(dx, dy);
|
|
681
|
+
if (k <= 0) continue;
|
|
682
|
+
const ri = medium.locate(dx, dy, false);
|
|
683
|
+
if (ri < 0 || medium.pixels[ri + 3] === 0) continue;
|
|
684
|
+
const i = medium.locate(dx, dy, true);
|
|
685
|
+
const px = medium.pixels;
|
|
686
|
+
rgb[0] = px[i] / 255;
|
|
687
|
+
rgb[1] = px[i + 1] / 255;
|
|
688
|
+
rgb[2] = px[i + 2] / 255;
|
|
689
|
+
sponge(rgb, k, saturate, vibrance);
|
|
690
|
+
px[i] = Math.round(rgb[0] * 255);
|
|
691
|
+
px[i + 1] = Math.round(rgb[1] * 255);
|
|
692
|
+
px[i + 2] = Math.round(rgb[2] * 255);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function rgbaViewOfGrey(target) {
|
|
698
|
+
const views = /* @__PURE__ */ new Map();
|
|
699
|
+
const dirty = /* @__PURE__ */ new Map();
|
|
700
|
+
const expand = (g) => {
|
|
701
|
+
const out = new Uint8ClampedArray(g.length * 4);
|
|
702
|
+
for (let i = 0; i < g.length; i++) {
|
|
703
|
+
out[i * 4] = out[i * 4 + 1] = out[i * 4 + 2] = g[i];
|
|
704
|
+
out[i * 4 + 3] = 255;
|
|
705
|
+
}
|
|
706
|
+
return out;
|
|
707
|
+
};
|
|
708
|
+
const view = {
|
|
709
|
+
offset: target.offset,
|
|
710
|
+
lockTransparency: true,
|
|
711
|
+
selection: target.selection,
|
|
712
|
+
readTile: (tx, ty) => {
|
|
713
|
+
const key = _chunkTFOPHZ3Ucjs.tileKey.call(void 0, tx, ty);
|
|
714
|
+
let v = views.get(key);
|
|
715
|
+
if (!v) {
|
|
716
|
+
v = expand(_nullishCoalesce(target.readTile(tx, ty), () => ( new Uint8ClampedArray(_chunkTFOPHZ3Ucjs.TILE * _chunkTFOPHZ3Ucjs.TILE))));
|
|
717
|
+
views.set(key, v);
|
|
718
|
+
}
|
|
719
|
+
return v;
|
|
720
|
+
},
|
|
721
|
+
writeTile: (tx, ty) => {
|
|
722
|
+
const key = _chunkTFOPHZ3Ucjs.tileKey.call(void 0, tx, ty);
|
|
723
|
+
let v = views.get(key);
|
|
724
|
+
if (!v) {
|
|
725
|
+
v = expand(_nullishCoalesce(target.readTile(tx, ty), () => ( new Uint8ClampedArray(_chunkTFOPHZ3Ucjs.TILE * _chunkTFOPHZ3Ucjs.TILE))));
|
|
726
|
+
views.set(key, v);
|
|
727
|
+
}
|
|
728
|
+
dirty.set(key, { tx, ty, data: v });
|
|
729
|
+
return v;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
return {
|
|
733
|
+
target: view,
|
|
734
|
+
flush: () => {
|
|
735
|
+
for (const { tx, ty, data } of dirty.values()) {
|
|
736
|
+
const g = target.writeTile(tx, ty);
|
|
737
|
+
for (let i = 0; i < g.length; i++) g[i] = data[i * 4];
|
|
738
|
+
}
|
|
739
|
+
dirty.clear();
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function unionRect(a, b) {
|
|
744
|
+
if (!a) return { ...b };
|
|
745
|
+
const x = Math.min(a.x, b.x);
|
|
746
|
+
const y = Math.min(a.y, b.y);
|
|
747
|
+
return { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
exports.solveMembrane = solveMembrane; exports.seamlessClone = seamlessClone; exports.membraneFill = membraneFill; exports.dilateMask = dilateMask; exports.maskBounds = maskBounds; exports.bestOffset = bestOffset; exports.TONE_RANGES = TONE_RANGES; exports.luma = luma; exports.dodgeBurnCurve = dodgeBurnCurve; exports.dodgeBurn = dodgeBurn; exports.saturationOf = saturationOf; exports.sponge = sponge; exports.perDabStrength = perDabStrength; exports.RETOUCH_SAMPLES = RETOUCH_SAMPLES; exports.SPOT_HEAL_TYPES = SPOT_HEAL_TYPES; exports.DEFAULT_RETOUCH = DEFAULT_RETOUCH; exports.normalizeRetouch = normalizeRetouch; exports.TilePixelSource = TilePixelSource; exports.RegionPixelSource = RegionPixelSource; exports.readSourceRegion = readSourceRegion; exports.applyRetouchToTile = applyRetouchToTile; exports.toneOf = toneOf; exports.healPixels = healPixels; exports.spotHealPixels = spotHealPixels; exports.spotHealWindow = spotHealWindow; exports.RetouchDabStroke = RetouchDabStroke; exports.smudgeEffect = smudgeEffect; exports.spongeEffect = spongeEffect; exports.rgbaViewOfGrey = rgbaViewOfGrey;
|
|
781
|
+
//# sourceMappingURL=chunk-DFQEX3AM.cjs.map
|