@pixerate/editor 0.259.0 → 0.260.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/dist/agent/index.cjs +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/animation-editor/index.cjs +61 -59
- package/dist/animation-editor/index.js +5 -3
- package/dist/brushes/index.cjs +52 -52
- package/dist/brushes/index.js +6 -6
- package/dist/{brushstrokeRender-JI4W6F2G.js → brushstrokeRender-25Q5BEY6.js} +17 -7
- package/dist/{brushstrokeRender-MQ6PSDM5.cjs → brushstrokeRender-N6UPZSQS.cjs} +31 -21
- package/dist/canvas/brushTypes.d.cts +5 -0
- package/dist/canvas/brushTypes.d.ts +5 -0
- package/dist/canvas/drawController.d.cts +15 -1
- package/dist/canvas/drawController.d.ts +15 -1
- package/dist/canvas/index.cjs +136 -102
- package/dist/canvas/index.js +35 -1
- package/dist/{chunk-3PPJRMIG.js → chunk-3O47TPGX.js} +197 -18
- package/dist/{chunk-5Q5MLXAD.cjs → chunk-3TQW5MPW.cjs} +23 -23
- package/dist/{chunk-JBBJE76O.cjs → chunk-3ZRNK3RO.cjs} +1138 -85
- package/dist/{chunk-YSGW7VV4.cjs → chunk-43NT242D.cjs} +1401 -228
- package/dist/{chunk-SMTUQWGY.js → chunk-5IW65VQ6.js} +1 -1
- package/dist/{chunk-YQ4PQTBB.js → chunk-6NZL24W4.js} +9 -1
- package/dist/{chunk-O3ZVZSNJ.cjs → chunk-7AUQ2UJ3.cjs} +137 -129
- package/dist/{chunk-4M4E3N6X.js → chunk-CQVTGBQI.js} +1 -1
- package/dist/{chunk-SSFMWJDK.js → chunk-D4TE5JNW.js} +1192 -19
- package/dist/{chunk-AORZ5M5C.js → chunk-EHALWBBD.js} +1 -1
- package/dist/{chunk-6WCQ35GI.cjs → chunk-NHA26O5X.cjs} +2 -2
- package/dist/{chunk-DPYAO5U6.cjs → chunk-PVJMTLPJ.cjs} +197 -18
- package/dist/{chunk-MQGQTKVW.cjs → chunk-PYTJBVW5.cjs} +29 -29
- package/dist/{chunk-IXQZHCOF.js → chunk-QAR2N7HZ.js} +1 -1
- package/dist/{chunk-5P4JEOIV.js → chunk-TMDDMJCR.js} +2 -2
- package/dist/{chunk-RSIKDWOP.cjs → chunk-TZOX7KWV.cjs} +15 -15
- package/dist/{chunk-IPUTIUGQ.cjs → chunk-UVZ7RQOE.cjs} +1 -1
- package/dist/{chunk-A7GJ6BXI.js → chunk-WJ4WQJCC.js} +1062 -9
- package/dist/{chunk-ICTPLVSR.js → chunk-X2EXYY4J.js} +1 -1
- package/dist/{chunk-WQCNC4DK.js → chunk-XC6DPRYI.js} +695 -4
- package/dist/{chunk-KBYB7OWB.cjs → chunk-YHDHFJUC.cjs} +776 -85
- package/dist/{chunk-P3PZ63M3.cjs → chunk-YLUIFXSL.cjs} +35 -35
- package/dist/commands/index.cjs +2 -2
- package/dist/commands/index.js +1 -1
- package/dist/image-editor/index.cjs +1385 -2484
- package/dist/image-editor/index.js +139 -1238
- package/dist/image-editor/selection-worker.cjs +3 -4
- package/dist/image-editor/selection-worker.js +1 -2
- package/dist/paint/index.cjs +3 -5
- package/dist/paint/index.js +40 -42
- package/dist/paint-editor/contract.d.cts +29 -0
- package/dist/paint-editor/contract.d.ts +29 -0
- package/dist/paint-editor/dab-stroke.d.cts +5 -0
- package/dist/paint-editor/dab-stroke.d.ts +5 -0
- package/dist/paint-editor/index.cjs +402 -258
- package/dist/paint-editor/index.d.cts +1 -0
- package/dist/paint-editor/index.d.ts +1 -0
- package/dist/paint-editor/index.js +197 -53
- package/dist/paint-editor/stamp-tip.d.cts +17 -0
- package/dist/paint-editor/stamp-tip.d.ts +17 -0
- package/dist/paint-editor/ui.d.cts +21 -1
- package/dist/paint-editor/ui.d.ts +21 -1
- package/dist/raster/index.cjs +2 -4
- package/dist/raster/index.js +6 -8
- package/dist/vector/brushstroke.d.cts +6 -0
- package/dist/vector/brushstroke.d.ts +6 -0
- package/dist/vector/controller.d.cts +11 -2
- package/dist/vector/controller.d.ts +11 -2
- package/dist/vector/index.cjs +990 -973
- package/dist/vector/index.js +28 -11
- package/package.json +1 -1
- package/skills/pixerate-brushes/SKILL.md +1 -1
- package/skills/pixerate-canvas/SKILL.md +3 -1
- package/skills/pixerate-vector/SKILL.md +2 -2
- package/dist/chunk-2VJAVXLI.js +0 -192
- package/dist/chunk-62Z5WLRA.js +0 -700
- package/dist/chunk-BOHDJJ2O.cjs +0 -192
- package/dist/chunk-NKGB64CW.cjs +0 -700
- package/dist/chunk-SS53NNZO.cjs +0 -1066
- package/dist/chunk-ZNA3IQZF.js +0 -1066
package/dist/chunk-62Z5WLRA.js
DELETED
|
@@ -1,700 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
bestOffset,
|
|
3
|
-
contentAwareFill,
|
|
4
|
-
dilateMask,
|
|
5
|
-
maskBounds,
|
|
6
|
-
membraneFill,
|
|
7
|
-
seamlessClone
|
|
8
|
-
} from "./chunk-VWEWY4FY.js";
|
|
9
|
-
import {
|
|
10
|
-
DabWalker,
|
|
11
|
-
SmudgeTip,
|
|
12
|
-
TileMedium,
|
|
13
|
-
dabRect,
|
|
14
|
-
put255,
|
|
15
|
-
rasterizeDab
|
|
16
|
-
} from "./chunk-GCVFEPJG.js";
|
|
17
|
-
import {
|
|
18
|
-
blendPixel,
|
|
19
|
-
srgbDecode,
|
|
20
|
-
srgbEncode
|
|
21
|
-
} from "./chunk-IRSTHLQQ.js";
|
|
22
|
-
import {
|
|
23
|
-
TILE,
|
|
24
|
-
tileKey
|
|
25
|
-
} from "./chunk-HVVR5PZW.js";
|
|
26
|
-
|
|
27
|
-
// src/paint/retouch.ts
|
|
28
|
-
var TONE_RANGES = ["shadows", "midtones", "highlights"];
|
|
29
|
-
function luma(r, g, b) {
|
|
30
|
-
return 0.299 * r + 0.587 * g + 0.114 * b;
|
|
31
|
-
}
|
|
32
|
-
function dodgeBurnCurve(v, e, range, burn) {
|
|
33
|
-
const x = Math.max(0, v);
|
|
34
|
-
const k = Math.min(1, Math.max(0, e));
|
|
35
|
-
const c = Math.min(1, x);
|
|
36
|
-
if (range === "midtones") {
|
|
37
|
-
const w2 = Math.min(1, Math.max(0, 4 * x * (1 - x)));
|
|
38
|
-
return x + w2 * (Math.pow(c, burn ? 1 + k : 1 / (1 + k)) - x);
|
|
39
|
-
}
|
|
40
|
-
const w = range === "shadows" ? (1 - c) * (1 - c) : c * c;
|
|
41
|
-
return burn ? x - k * w * x : x + k * w * (1 - c);
|
|
42
|
-
}
|
|
43
|
-
function compressGamut(c, l) {
|
|
44
|
-
const L = Math.min(1, Math.max(0, l));
|
|
45
|
-
const lo = Math.min(c[0], c[1], c[2]);
|
|
46
|
-
const hi = Math.max(c[0], c[1], c[2]);
|
|
47
|
-
let t = 1;
|
|
48
|
-
if (hi > 1 && hi - L > 1e-9) t = Math.min(t, (1 - L) / (hi - L));
|
|
49
|
-
if (lo < 0 && L - lo > 1e-9) t = Math.min(t, L / (L - lo));
|
|
50
|
-
for (let i = 0; i < 3; i++) c[i] = L + (c[i] - L) * t;
|
|
51
|
-
}
|
|
52
|
-
function dodgeBurn(c, e, range, burn, protectTones) {
|
|
53
|
-
if (!(e > 0)) return c;
|
|
54
|
-
if (protectTones) {
|
|
55
|
-
const l = luma(c[0], c[1], c[2]);
|
|
56
|
-
const nl = dodgeBurnCurve(l, e, range, burn);
|
|
57
|
-
if (l > 1e-6) for (let i = 0; i < 3; i++) c[i] *= nl / l;
|
|
58
|
-
else c[0] = c[1] = c[2] = nl;
|
|
59
|
-
compressGamut(c, nl);
|
|
60
|
-
} else for (let i = 0; i < 3; i++) c[i] = dodgeBurnCurve(c[i], e, range, burn);
|
|
61
|
-
return c;
|
|
62
|
-
}
|
|
63
|
-
function saturationOf(r, g, b) {
|
|
64
|
-
const lo = Math.min(r, g, b);
|
|
65
|
-
const hi = Math.max(r, g, b);
|
|
66
|
-
return hi <= 1e-6 ? 0 : Math.min(1, Math.max(0, (hi - lo) / hi));
|
|
67
|
-
}
|
|
68
|
-
function sponge(c, amount, saturate, vibrance) {
|
|
69
|
-
let a = Math.min(1, Math.max(0, amount));
|
|
70
|
-
if (!(a > 0)) return c;
|
|
71
|
-
if (vibrance) {
|
|
72
|
-
const s = saturationOf(c[0], c[1], c[2]);
|
|
73
|
-
a *= saturate ? 1 - s : 0.25 + 0.75 * s;
|
|
74
|
-
}
|
|
75
|
-
const l = luma(c[0], c[1], c[2]);
|
|
76
|
-
const k = saturate ? 1 + a : 1 - a;
|
|
77
|
-
for (let i = 0; i < 3; i++) c[i] = l + (c[i] - l) * k;
|
|
78
|
-
compressGamut(c, l);
|
|
79
|
-
return c;
|
|
80
|
-
}
|
|
81
|
-
function perDabStrength(e, spacing) {
|
|
82
|
-
return 1 - Math.pow(1 - Math.min(1, Math.max(0, e)), Math.min(1, Math.max(0.01, spacing)));
|
|
83
|
-
}
|
|
84
|
-
var RETOUCH_SAMPLES = ["current", "current-below", "all"];
|
|
85
|
-
var SPOT_HEAL_TYPES = ["proximity-match", "content-aware", "smooth"];
|
|
86
|
-
var DEFAULT_RETOUCH = {
|
|
87
|
-
aligned: true,
|
|
88
|
-
sample: "current",
|
|
89
|
-
spotType: "proximity-match",
|
|
90
|
-
range: "midtones",
|
|
91
|
-
exposure: 0.5,
|
|
92
|
-
protectTones: true,
|
|
93
|
-
spongeMode: "desaturate",
|
|
94
|
-
vibrance: true,
|
|
95
|
-
strength: 0.5,
|
|
96
|
-
historySteps: 0
|
|
97
|
-
};
|
|
98
|
-
function normalizeRetouch(raw = {}, base = DEFAULT_RETOUCH) {
|
|
99
|
-
const unit = (v, d) => typeof v === "number" && Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : d;
|
|
100
|
-
const bool = (v, d) => typeof v === "boolean" ? v : d;
|
|
101
|
-
const pick = (v, all, d) => all.includes(v) ? v : d;
|
|
102
|
-
return {
|
|
103
|
-
aligned: bool(raw.aligned, base.aligned),
|
|
104
|
-
sample: pick(raw.sample, RETOUCH_SAMPLES, base.sample),
|
|
105
|
-
spotType: pick(raw.spotType, SPOT_HEAL_TYPES, base.spotType),
|
|
106
|
-
range: pick(raw.range, TONE_RANGES, base.range),
|
|
107
|
-
exposure: unit(raw.exposure, base.exposure),
|
|
108
|
-
protectTones: bool(raw.protectTones, base.protectTones),
|
|
109
|
-
spongeMode: pick(raw.spongeMode, ["desaturate", "saturate"], base.spongeMode),
|
|
110
|
-
vibrance: bool(raw.vibrance, base.vibrance),
|
|
111
|
-
strength: unit(raw.strength, base.strength),
|
|
112
|
-
historySteps: typeof raw.historySteps === "number" && Number.isFinite(raw.historySteps) ? Math.min(1e3, Math.max(0, Math.round(raw.historySteps))) : base.historySteps
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function boxBlurPixels(data, w, h, n, r) {
|
|
116
|
-
if (r < 1) return;
|
|
117
|
-
if (n === 4) for (let i = 0; i < data.length; i += 4) for (let c = 0; c < 3; c++) data[i + c] *= data[i + 3] / 255;
|
|
118
|
-
const tmp = new Float32Array(data.length);
|
|
119
|
-
const k = 1 / (2 * r + 1);
|
|
120
|
-
for (let y = 0; y < h; y++) {
|
|
121
|
-
for (let x = 0; x < w; x++) {
|
|
122
|
-
for (let c = 0; c < n; c++) {
|
|
123
|
-
let s = 0;
|
|
124
|
-
for (let d = -r; d <= r; d++) s += data[(y * w + Math.min(w - 1, Math.max(0, x + d))) * n + c];
|
|
125
|
-
tmp[(y * w + x) * n + c] = s * k;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
for (let y = 0; y < h; y++) {
|
|
130
|
-
for (let x = 0; x < w; x++) {
|
|
131
|
-
for (let c = 0; c < n; c++) {
|
|
132
|
-
let s = 0;
|
|
133
|
-
for (let d = -r; d <= r; d++) s += tmp[(Math.min(h - 1, Math.max(0, y + d)) * w + x) * n + c];
|
|
134
|
-
data[(y * w + x) * n + c] = s * k;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (n === 4) {
|
|
139
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
140
|
-
const a = data[i + 3] / 255;
|
|
141
|
-
for (let c = 0; c < 3; c++) data[i + c] = a > 0 ? data[i + c] / a : 0;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function retouchFilter(data, w, h, n, kind, radius = 2, amount = 1) {
|
|
146
|
-
if (kind === "blur") {
|
|
147
|
-
boxBlurPixels(data, w, h, n, radius);
|
|
148
|
-
boxBlurPixels(data, w, h, n, radius);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const soft = data.slice();
|
|
152
|
-
boxBlurPixels(soft, w, h, n, 1);
|
|
153
|
-
for (let i = 0; i < data.length; i++) {
|
|
154
|
-
if (n === 4 && (i & 3) === 3) continue;
|
|
155
|
-
const v = data[i] + amount * (data[i] - soft[i]);
|
|
156
|
-
data[i] = v > 0 ? v : 0;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
var IDENTITY_CLONE_TRANSFORM = { scaleX: 1, scaleY: 1, rotate: 0 };
|
|
160
|
-
function isIdentityCloneTransform(t) {
|
|
161
|
-
return t.scaleX === 1 && t.scaleY === 1 && (t.rotate % 360 + 360) % 360 === 0;
|
|
162
|
-
}
|
|
163
|
-
function cloneSamplePoint(t, source, anchor, x, y) {
|
|
164
|
-
const a = -t.rotate * Math.PI / 180;
|
|
165
|
-
const c = Math.cos(a);
|
|
166
|
-
const s = Math.sin(a);
|
|
167
|
-
const dx = x - anchor.x;
|
|
168
|
-
const dy = y - anchor.y;
|
|
169
|
-
return [source.x + (c * dx - s * dy) / t.scaleX, source.y + (s * dx + c * dy) / t.scaleY];
|
|
170
|
-
}
|
|
171
|
-
var TransformedPixelSource = class {
|
|
172
|
-
constructor(inner, map) {
|
|
173
|
-
this.inner = inner;
|
|
174
|
-
this.map = map;
|
|
175
|
-
}
|
|
176
|
-
inner;
|
|
177
|
-
map;
|
|
178
|
-
px = [0, 0, 0, 0];
|
|
179
|
-
sample(x, y, out) {
|
|
180
|
-
const [u, v] = this.map(x, y);
|
|
181
|
-
const x0 = Math.floor(u);
|
|
182
|
-
const y0 = Math.floor(v);
|
|
183
|
-
const fx = u - x0;
|
|
184
|
-
const fy = v - y0;
|
|
185
|
-
let r = 0;
|
|
186
|
-
let g = 0;
|
|
187
|
-
let b = 0;
|
|
188
|
-
let a = 0;
|
|
189
|
-
for (let k = 0; k < 4; k++) {
|
|
190
|
-
const w = (k & 1 ? fx : 1 - fx) * (k & 2 ? fy : 1 - fy);
|
|
191
|
-
if (w <= 0) continue;
|
|
192
|
-
if (!this.inner.sample(x0 + (k & 1), y0 + (k >> 1), this.px)) continue;
|
|
193
|
-
const pa = this.px[3] * w;
|
|
194
|
-
r += this.px[0] * pa;
|
|
195
|
-
g += this.px[1] * pa;
|
|
196
|
-
b += this.px[2] * pa;
|
|
197
|
-
a += pa;
|
|
198
|
-
}
|
|
199
|
-
if (!(a > 0)) {
|
|
200
|
-
out[0] = out[1] = out[2] = out[3] = 0;
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
out[0] = r / a;
|
|
204
|
-
out[1] = g / a;
|
|
205
|
-
out[2] = b / a;
|
|
206
|
-
out[3] = a;
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
var TilePixelSource = class {
|
|
211
|
-
constructor(readTile, channels, offset = { x: 0, y: 0 }) {
|
|
212
|
-
this.readTile = readTile;
|
|
213
|
-
this.channels = channels;
|
|
214
|
-
this.offset = offset;
|
|
215
|
-
}
|
|
216
|
-
readTile;
|
|
217
|
-
channels;
|
|
218
|
-
offset;
|
|
219
|
-
cache = /* @__PURE__ */ new Map();
|
|
220
|
-
lastKey = NaN;
|
|
221
|
-
last = null;
|
|
222
|
-
sample(x, y, out) {
|
|
223
|
-
const lx = x - this.offset.x;
|
|
224
|
-
const ly = y - this.offset.y;
|
|
225
|
-
const tx = Math.floor(lx / TILE);
|
|
226
|
-
const ty = Math.floor(ly / TILE);
|
|
227
|
-
const key = tileKey(tx, ty);
|
|
228
|
-
if (key !== this.lastKey) {
|
|
229
|
-
let t2 = this.cache.get(key);
|
|
230
|
-
if (t2 === void 0) {
|
|
231
|
-
t2 = this.readTile(tx, ty);
|
|
232
|
-
this.cache.set(key, t2);
|
|
233
|
-
}
|
|
234
|
-
this.last = t2;
|
|
235
|
-
this.lastKey = key;
|
|
236
|
-
}
|
|
237
|
-
const t = this.last;
|
|
238
|
-
if (!t) {
|
|
239
|
-
out[0] = out[1] = out[2] = out[3] = 0;
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
const p = (ly - ty * TILE) * TILE + (lx - tx * TILE);
|
|
243
|
-
if (this.channels === 1) {
|
|
244
|
-
out[0] = out[1] = out[2] = t[p];
|
|
245
|
-
out[3] = 255;
|
|
246
|
-
return true;
|
|
247
|
-
}
|
|
248
|
-
const i = p * 4;
|
|
249
|
-
out[0] = t[i];
|
|
250
|
-
out[1] = t[i + 1];
|
|
251
|
-
out[2] = t[i + 2];
|
|
252
|
-
out[3] = t[i + 3];
|
|
253
|
-
return out[3] > 0;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var RegionPixelSource = class {
|
|
257
|
-
constructor(rect, data) {
|
|
258
|
-
this.rect = rect;
|
|
259
|
-
this.data = data;
|
|
260
|
-
}
|
|
261
|
-
rect;
|
|
262
|
-
data;
|
|
263
|
-
sample(x, y, out) {
|
|
264
|
-
const r = this.rect;
|
|
265
|
-
const lx = x - r.x;
|
|
266
|
-
const ly = y - r.y;
|
|
267
|
-
if (lx < 0 || ly < 0 || lx >= r.width || ly >= r.height) {
|
|
268
|
-
out[0] = out[1] = out[2] = out[3] = 0;
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
const i = (ly * r.width + lx) * 4;
|
|
272
|
-
out[0] = this.data[i];
|
|
273
|
-
out[1] = this.data[i + 1];
|
|
274
|
-
out[2] = this.data[i + 2];
|
|
275
|
-
out[3] = this.data[i + 3];
|
|
276
|
-
return out[3] > 0;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
function readSourceRegion(source, rect, dx = 0, dy = 0) {
|
|
280
|
-
const out = new Float32Array(rect.width * rect.height * 4);
|
|
281
|
-
const px = [0, 0, 0, 0];
|
|
282
|
-
for (let y = 0; y < rect.height; y++) {
|
|
283
|
-
for (let x = 0; x < rect.width; x++) {
|
|
284
|
-
source.sample(rect.x + x + dx, rect.y + y + dy, px);
|
|
285
|
-
const i = (y * rect.width + x) * 4;
|
|
286
|
-
out[i] = px[0];
|
|
287
|
-
out[i + 1] = px[1];
|
|
288
|
-
out[i + 2] = px[2];
|
|
289
|
-
out[i + 3] = px[3];
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return out;
|
|
293
|
-
}
|
|
294
|
-
function applyRetouchToTile(coverage, tileData, channels, tx, ty, paint, s, options = {}) {
|
|
295
|
-
const out = (options.into ?? tileData).slice();
|
|
296
|
-
const ox = tx * TILE + s.offset.x;
|
|
297
|
-
const oy = ty * TILE + s.offset.y;
|
|
298
|
-
let x0 = 0;
|
|
299
|
-
let y0 = 0;
|
|
300
|
-
let x1 = TILE;
|
|
301
|
-
let y1 = TILE;
|
|
302
|
-
if (options.region) {
|
|
303
|
-
const r = options.region;
|
|
304
|
-
x0 = Math.max(0, Math.floor(r.x) - ox);
|
|
305
|
-
y0 = Math.max(0, Math.floor(r.y) - oy);
|
|
306
|
-
x1 = Math.min(TILE, Math.ceil(r.x + r.width) - ox);
|
|
307
|
-
y1 = Math.min(TILE, Math.ceil(r.y + r.height) - oy);
|
|
308
|
-
if (x1 <= x0 || y1 <= y0) return out;
|
|
309
|
-
if (options.into) {
|
|
310
|
-
for (let y = y0; y < y1; y++) out.set(tileData.subarray((y * TILE + x0) * channels, (y * TILE + x1) * channels), (y * TILE + x0) * channels);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
const sel = s.selection;
|
|
314
|
-
const blend = s.blend ?? "normal";
|
|
315
|
-
const src = [0, 0, 0, 0];
|
|
316
|
-
const rgb = [0, 0, 0];
|
|
317
|
-
const cb = [0, 0, 0, 0];
|
|
318
|
-
const cs = [0, 0, 0, 0];
|
|
319
|
-
let covKey = NaN;
|
|
320
|
-
let covTile;
|
|
321
|
-
for (let y = y0; y < y1; y++) {
|
|
322
|
-
const dy = oy + y;
|
|
323
|
-
const cty = Math.floor(dy / TILE);
|
|
324
|
-
for (let x = x0; x < x1; x++) {
|
|
325
|
-
const dx = ox + x;
|
|
326
|
-
const ctx = Math.floor(dx / TILE);
|
|
327
|
-
const key = tileKey(ctx, cty);
|
|
328
|
-
if (key !== covKey) {
|
|
329
|
-
covKey = key;
|
|
330
|
-
covTile = coverage.tiles.get(key);
|
|
331
|
-
}
|
|
332
|
-
if (!covTile) continue;
|
|
333
|
-
const c = covTile[(dy - cty * TILE) * TILE + (dx - ctx * TILE)];
|
|
334
|
-
if (c <= 0) continue;
|
|
335
|
-
let k = c * s.opacity;
|
|
336
|
-
if (sel) {
|
|
337
|
-
if (dx < 0 || dy < 0 || dx >= sel.width || dy >= sel.height) continue;
|
|
338
|
-
k *= sel.data[dy * sel.width + dx] / 255;
|
|
339
|
-
}
|
|
340
|
-
if (k > 1) k = 1;
|
|
341
|
-
if (k <= 0) continue;
|
|
342
|
-
const p = y * TILE + x;
|
|
343
|
-
if (channels === 1) {
|
|
344
|
-
const g = out[p];
|
|
345
|
-
let t;
|
|
346
|
-
if (paint.kind === "tone") {
|
|
347
|
-
rgb[0] = rgb[1] = rgb[2] = g / 255;
|
|
348
|
-
paint.tone(rgb);
|
|
349
|
-
t = luma(rgb[0], rgb[1], rgb[2]) * 255;
|
|
350
|
-
} else if (paint.kind === "color") t = paint.color[0];
|
|
351
|
-
else {
|
|
352
|
-
if (!paint.source.sample(dx + paint.dx, dy + paint.dy, src)) continue;
|
|
353
|
-
t = src[0];
|
|
354
|
-
k *= src[3] / 255;
|
|
355
|
-
}
|
|
356
|
-
out[p] = Math.round(g + (t - g) * k);
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
const i = p * 4;
|
|
360
|
-
const a = out[i + 3];
|
|
361
|
-
if (paint.kind === "tone") {
|
|
362
|
-
if (a === 0) continue;
|
|
363
|
-
rgb[0] = out[i] / 255;
|
|
364
|
-
rgb[1] = out[i + 1] / 255;
|
|
365
|
-
rgb[2] = out[i + 2] / 255;
|
|
366
|
-
const r0 = rgb[0];
|
|
367
|
-
const g0 = rgb[1];
|
|
368
|
-
const b0 = rgb[2];
|
|
369
|
-
paint.tone(rgb);
|
|
370
|
-
put255(out, i, r0 + (rgb[0] - r0) * k);
|
|
371
|
-
put255(out, i + 1, g0 + (rgb[1] - g0) * k);
|
|
372
|
-
put255(out, i + 2, b0 + (rgb[2] - b0) * k);
|
|
373
|
-
continue;
|
|
374
|
-
}
|
|
375
|
-
if (s.lockTransparency && a === 0) continue;
|
|
376
|
-
if (paint.kind === "color") {
|
|
377
|
-
src[0] = paint.color[0];
|
|
378
|
-
src[1] = paint.color[1];
|
|
379
|
-
src[2] = paint.color[2];
|
|
380
|
-
src[3] = paint.color[3];
|
|
381
|
-
} else if (!paint.source.sample(dx + paint.dx, dy + paint.dy, src)) continue;
|
|
382
|
-
for (let ch = 0; ch < 4; ch++) {
|
|
383
|
-
cb[ch] = out[i + ch] / 255;
|
|
384
|
-
cs[ch] = src[ch] / 255;
|
|
385
|
-
}
|
|
386
|
-
const o = blendPixel(blend, cb, cs, k);
|
|
387
|
-
put255(out, i, o[0]);
|
|
388
|
-
put255(out, i + 1, o[1]);
|
|
389
|
-
put255(out, i + 2, o[2]);
|
|
390
|
-
if (!s.lockTransparency) put255(out, i + 3, o[3]);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return out;
|
|
394
|
-
}
|
|
395
|
-
function applyToneToDeepTile(coverage, samples, tx, ty, tone, s, options = {}) {
|
|
396
|
-
const linear = samples instanceof Float32Array;
|
|
397
|
-
const out = (options.into ?? samples).slice();
|
|
398
|
-
const ox = tx * TILE + s.offset.x;
|
|
399
|
-
const oy = ty * TILE + s.offset.y;
|
|
400
|
-
let x0 = 0;
|
|
401
|
-
let y0 = 0;
|
|
402
|
-
let x1 = TILE;
|
|
403
|
-
let y1 = TILE;
|
|
404
|
-
if (options.region) {
|
|
405
|
-
const r = options.region;
|
|
406
|
-
x0 = Math.max(0, Math.floor(r.x) - ox);
|
|
407
|
-
y0 = Math.max(0, Math.floor(r.y) - oy);
|
|
408
|
-
x1 = Math.min(TILE, Math.ceil(r.x + r.width) - ox);
|
|
409
|
-
y1 = Math.min(TILE, Math.ceil(r.y + r.height) - oy);
|
|
410
|
-
if (x1 <= x0 || y1 <= y0) return out;
|
|
411
|
-
if (options.into) for (let y = y0; y < y1; y++) out.set(samples.subarray((y * TILE + x0) * 4, (y * TILE + x1) * 4), (y * TILE + x0) * 4);
|
|
412
|
-
}
|
|
413
|
-
const sel = s.selection;
|
|
414
|
-
const rgb = [0, 0, 0];
|
|
415
|
-
const before = [0, 0, 0];
|
|
416
|
-
const excess = [0, 0, 0];
|
|
417
|
-
let covKey = NaN;
|
|
418
|
-
let covTile;
|
|
419
|
-
for (let y = y0; y < y1; y++) {
|
|
420
|
-
const dy = oy + y;
|
|
421
|
-
const cty = Math.floor(dy / TILE);
|
|
422
|
-
for (let x = x0; x < x1; x++) {
|
|
423
|
-
const dx = ox + x;
|
|
424
|
-
const ctx = Math.floor(dx / TILE);
|
|
425
|
-
const key = tileKey(ctx, cty);
|
|
426
|
-
if (key !== covKey) {
|
|
427
|
-
covKey = key;
|
|
428
|
-
covTile = coverage.tiles.get(key);
|
|
429
|
-
}
|
|
430
|
-
if (!covTile) continue;
|
|
431
|
-
const c = covTile[(dy - cty * TILE) * TILE + (dx - ctx * TILE)];
|
|
432
|
-
if (c <= 0) continue;
|
|
433
|
-
let k = c * s.opacity;
|
|
434
|
-
if (sel) {
|
|
435
|
-
if (dx < 0 || dy < 0 || dx >= sel.width || dy >= sel.height) continue;
|
|
436
|
-
k *= sel.data[dy * sel.width + dx] / 255;
|
|
437
|
-
}
|
|
438
|
-
if (k > 1) k = 1;
|
|
439
|
-
if (k <= 0) continue;
|
|
440
|
-
const i = (y * TILE + x) * 4;
|
|
441
|
-
if (out[i + 3] === 0) continue;
|
|
442
|
-
for (let ch = 0; ch < 3; ch++) {
|
|
443
|
-
const v = out[i + ch];
|
|
444
|
-
if (linear) {
|
|
445
|
-
excess[ch] = v > 1 ? v - 1 : 0;
|
|
446
|
-
rgb[ch] = srgbEncode(v > 1 ? 1 : v < 0 ? 0 : v);
|
|
447
|
-
} else rgb[ch] = v / 65535;
|
|
448
|
-
before[ch] = rgb[ch];
|
|
449
|
-
}
|
|
450
|
-
tone(rgb);
|
|
451
|
-
for (let ch = 0; ch < 3; ch++) {
|
|
452
|
-
const e = before[ch] + (rgb[ch] - before[ch]) * k;
|
|
453
|
-
if (linear) out[i + ch] = srgbDecode(e) + excess[ch];
|
|
454
|
-
else out[i + ch] = e <= 0 ? 0 : e >= 1 ? 65535 : Math.round(e * 65535);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
return out;
|
|
459
|
-
}
|
|
460
|
-
function toneOf(tool, settings) {
|
|
461
|
-
const burn = tool === "burn";
|
|
462
|
-
return (rgb) => {
|
|
463
|
-
dodgeBurn(rgb, settings.exposure, settings.range, burn, settings.protectTones);
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
function healPixels(w, h, src, dst, mask) {
|
|
467
|
-
const out = new Float32Array(dst);
|
|
468
|
-
const bb = maskBounds(w, h, mask);
|
|
469
|
-
if (!bb) return out;
|
|
470
|
-
const x0 = Math.max(0, bb[0] - 1);
|
|
471
|
-
const y0 = Math.max(0, bb[1] - 1);
|
|
472
|
-
const x1 = Math.min(w, bb[2] + 1);
|
|
473
|
-
const y1 = Math.min(h, bb[3] + 1);
|
|
474
|
-
const rw = x1 - x0;
|
|
475
|
-
const rh = y1 - y0;
|
|
476
|
-
const s = new Float32Array(rw * rh * 4);
|
|
477
|
-
const d = new Float32Array(rw * rh * 4);
|
|
478
|
-
const m = new Uint8Array(rw * rh);
|
|
479
|
-
for (let y = 0; y < rh; y++) {
|
|
480
|
-
for (let x = 0; x < rw; x++) {
|
|
481
|
-
const gi = (y + y0) * w + x + x0;
|
|
482
|
-
const li = y * rw + x;
|
|
483
|
-
m[li] = mask[gi] ? 1 : 0;
|
|
484
|
-
for (let c = 0; c < 4; c++) {
|
|
485
|
-
s[li * 4 + c] = src[gi * 4 + c];
|
|
486
|
-
d[li * 4 + c] = dst[gi * 4 + c];
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
const healed = seamlessClone(rw, rh, 4, s, d, m);
|
|
491
|
-
for (let y = 0; y < rh; y++) {
|
|
492
|
-
for (let x = 0; x < rw; x++) {
|
|
493
|
-
const gi = ((y + y0) * w + x + x0) * 4;
|
|
494
|
-
const li = (y * rw + x) * 4;
|
|
495
|
-
for (let c = 0; c < 4; c++) out[gi + c] = Math.min(255, Math.max(0, healed[li + c]));
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return out;
|
|
499
|
-
}
|
|
500
|
-
function spotHealPixels(w, h, img, hole, size, type, onOffset) {
|
|
501
|
-
const domain = dilateMask(w, h, hole, 2);
|
|
502
|
-
const healMask = dilateMask(w, h, hole, 1);
|
|
503
|
-
let filled = null;
|
|
504
|
-
let bestFound = null;
|
|
505
|
-
if (type === "proximity-match") {
|
|
506
|
-
const ring = Math.min(16, Math.max(3, Math.floor(size / 8)));
|
|
507
|
-
const off = bestOffset(w, h, 4, img, domain, ring, Math.floor(Math.max(w, h) / 2));
|
|
508
|
-
if (off) {
|
|
509
|
-
bestFound = off;
|
|
510
|
-
filled = new Float32Array(img);
|
|
511
|
-
const [ddx, ddy] = off;
|
|
512
|
-
for (let i = 0; i < w * h; i++) {
|
|
513
|
-
if (!domain[i]) continue;
|
|
514
|
-
const x = i % w + ddx;
|
|
515
|
-
const y = Math.floor(i / w) + ddy;
|
|
516
|
-
const j = (y * w + x) * 4;
|
|
517
|
-
for (let c = 0; c < 4; c++) filled[i * 4 + c] = img[j + c];
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
onOffset?.(filled ? bestFound : null);
|
|
522
|
-
if (!filled && type === "content-aware") filled = contentAwareFill(w, h, 4, img, domain);
|
|
523
|
-
if (!filled) filled = membraneFill(w, h, 4, img, domain);
|
|
524
|
-
return healPixels(w, h, filled, img, healMask);
|
|
525
|
-
}
|
|
526
|
-
function spotHealWindow(bounds, canvas) {
|
|
527
|
-
const g = Math.max(8, Math.ceil(Math.max(bounds.width, bounds.height)));
|
|
528
|
-
const x0 = Math.max(0, bounds.x - g);
|
|
529
|
-
const y0 = Math.max(0, bounds.y - g);
|
|
530
|
-
const x1 = Math.min(canvas.width, bounds.x + bounds.width + g);
|
|
531
|
-
const y1 = Math.min(canvas.height, bounds.y + bounds.height + g);
|
|
532
|
-
return { x: x0, y: y0, width: Math.max(0, x1 - x0), height: Math.max(0, y1 - y0) };
|
|
533
|
-
}
|
|
534
|
-
var RetouchDabStroke = class {
|
|
535
|
-
constructor(brush, target, effect) {
|
|
536
|
-
this.brush = brush;
|
|
537
|
-
this.effect = effect;
|
|
538
|
-
this.walker = new DabWalker(brush);
|
|
539
|
-
this.medium = new TileMedium(target);
|
|
540
|
-
}
|
|
541
|
-
brush;
|
|
542
|
-
effect;
|
|
543
|
-
dabCount = 0;
|
|
544
|
-
bounds = null;
|
|
545
|
-
walker;
|
|
546
|
-
medium;
|
|
547
|
-
smoothPos = null;
|
|
548
|
-
buf = new Float32Array(0);
|
|
549
|
-
push(points) {
|
|
550
|
-
const dabs = [];
|
|
551
|
-
for (const p of points) this.walker.push(this.smooth(p), dabs);
|
|
552
|
-
return this.paint(dabs);
|
|
553
|
-
}
|
|
554
|
-
finish(last) {
|
|
555
|
-
const dabs = [];
|
|
556
|
-
if (last && this.smoothPos && (this.smoothPos.x !== last.x || this.smoothPos.y !== last.y)) this.walker.push(last, dabs);
|
|
557
|
-
this.walker.finish(dabs);
|
|
558
|
-
return this.paint(dabs);
|
|
559
|
-
}
|
|
560
|
-
smooth(p) {
|
|
561
|
-
const a = 1 - Math.min(0.95, Math.max(0, this.brush.smoothing));
|
|
562
|
-
const cur = this.smoothPos;
|
|
563
|
-
const n = cur && a < 1 ? { ...p, x: cur.x + (p.x - cur.x) * a, y: cur.y + (p.y - cur.y) * a } : p;
|
|
564
|
-
this.smoothPos = n;
|
|
565
|
-
return n;
|
|
566
|
-
}
|
|
567
|
-
paint(dabs) {
|
|
568
|
-
const rects = [];
|
|
569
|
-
for (const d of dabs) {
|
|
570
|
-
const rect = dabRect(d, this.brush.hardness);
|
|
571
|
-
const n = rect.width * rect.height;
|
|
572
|
-
if (this.buf.length < n) this.buf = new Float32Array(n);
|
|
573
|
-
const cov = this.buf.subarray(0, n);
|
|
574
|
-
rasterizeDab({ ...d, alpha: 1 }, this.brush.hardness, rect, cov);
|
|
575
|
-
this.medium.reset();
|
|
576
|
-
this.effect(this.medium, d, rect, cov);
|
|
577
|
-
rects.push(rect);
|
|
578
|
-
this.bounds = unionRect(this.bounds, rect);
|
|
579
|
-
this.dabCount++;
|
|
580
|
-
}
|
|
581
|
-
return rects;
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
function smudgeEffect(brush, strength, mixing = "rgb") {
|
|
585
|
-
const s = Math.min(1, Math.max(0, strength));
|
|
586
|
-
const tip = new SmudgeTip({ strength: s, length: s, mixing }, brush.size);
|
|
587
|
-
return (medium, d, rect, cov) => tip.dab(medium, { x: d.x, y: d.y, radius: d.radius, opacity: d.opacity * d.alpha }, rect, cov);
|
|
588
|
-
}
|
|
589
|
-
function spongeEffect(brush, saturate, vibrance) {
|
|
590
|
-
const rgb = [0, 0, 0];
|
|
591
|
-
return (medium, d, rect, cov) => {
|
|
592
|
-
const w = rect.width;
|
|
593
|
-
for (let yy = 0; yy < rect.height; yy++) {
|
|
594
|
-
for (let xx = 0; xx < w; xx++) {
|
|
595
|
-
const cv = cov[yy * w + xx];
|
|
596
|
-
if (cv <= 0) continue;
|
|
597
|
-
const dx = rect.x + xx;
|
|
598
|
-
const dy = rect.y + yy;
|
|
599
|
-
const k = perDabStrength(cv * d.alpha * d.opacity * 0.5, brush.spacing) * medium.selectionAt(dx, dy);
|
|
600
|
-
if (k <= 0) continue;
|
|
601
|
-
const ri = medium.locate(dx, dy, false);
|
|
602
|
-
if (ri < 0 || medium.pixels[ri + 3] === 0) continue;
|
|
603
|
-
const i = medium.locate(dx, dy, true);
|
|
604
|
-
const px = medium.pixels;
|
|
605
|
-
rgb[0] = px[i] / 255;
|
|
606
|
-
rgb[1] = px[i + 1] / 255;
|
|
607
|
-
rgb[2] = px[i + 2] / 255;
|
|
608
|
-
sponge(rgb, k, saturate, vibrance);
|
|
609
|
-
put255(px, i, rgb[0]);
|
|
610
|
-
put255(px, i + 1, rgb[1]);
|
|
611
|
-
put255(px, i + 2, rgb[2]);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
function rgbaViewOfGrey(target) {
|
|
617
|
-
const views = /* @__PURE__ */ new Map();
|
|
618
|
-
const dirty = /* @__PURE__ */ new Map();
|
|
619
|
-
const expand = (g) => {
|
|
620
|
-
const out = new Uint8ClampedArray(g.length * 4);
|
|
621
|
-
for (let i = 0; i < g.length; i++) {
|
|
622
|
-
out[i * 4] = out[i * 4 + 1] = out[i * 4 + 2] = g[i];
|
|
623
|
-
out[i * 4 + 3] = 255;
|
|
624
|
-
}
|
|
625
|
-
return out;
|
|
626
|
-
};
|
|
627
|
-
const view = {
|
|
628
|
-
offset: target.offset,
|
|
629
|
-
lockTransparency: true,
|
|
630
|
-
selection: target.selection,
|
|
631
|
-
readTile: (tx, ty) => {
|
|
632
|
-
const key = tileKey(tx, ty);
|
|
633
|
-
let v = views.get(key);
|
|
634
|
-
if (!v) {
|
|
635
|
-
v = expand(target.readTile(tx, ty) ?? new Uint8ClampedArray(TILE * TILE));
|
|
636
|
-
views.set(key, v);
|
|
637
|
-
}
|
|
638
|
-
return v;
|
|
639
|
-
},
|
|
640
|
-
writeTile: (tx, ty) => {
|
|
641
|
-
const key = tileKey(tx, ty);
|
|
642
|
-
let v = views.get(key);
|
|
643
|
-
if (!v) {
|
|
644
|
-
v = expand(target.readTile(tx, ty) ?? new Uint8ClampedArray(TILE * TILE));
|
|
645
|
-
views.set(key, v);
|
|
646
|
-
}
|
|
647
|
-
dirty.set(key, { tx, ty, data: v });
|
|
648
|
-
return v;
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
return {
|
|
652
|
-
target: view,
|
|
653
|
-
flush: () => {
|
|
654
|
-
for (const { tx, ty, data } of dirty.values()) {
|
|
655
|
-
const g = target.writeTile(tx, ty);
|
|
656
|
-
for (let i = 0; i < g.length; i++) g[i] = data[i * 4];
|
|
657
|
-
}
|
|
658
|
-
dirty.clear();
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
function unionRect(a, b) {
|
|
663
|
-
if (!a) return { ...b };
|
|
664
|
-
const x = Math.min(a.x, b.x);
|
|
665
|
-
const y = Math.min(a.y, b.y);
|
|
666
|
-
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 };
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
export {
|
|
670
|
-
TONE_RANGES,
|
|
671
|
-
luma,
|
|
672
|
-
dodgeBurnCurve,
|
|
673
|
-
dodgeBurn,
|
|
674
|
-
saturationOf,
|
|
675
|
-
sponge,
|
|
676
|
-
perDabStrength,
|
|
677
|
-
RETOUCH_SAMPLES,
|
|
678
|
-
SPOT_HEAL_TYPES,
|
|
679
|
-
DEFAULT_RETOUCH,
|
|
680
|
-
normalizeRetouch,
|
|
681
|
-
boxBlurPixels,
|
|
682
|
-
retouchFilter,
|
|
683
|
-
IDENTITY_CLONE_TRANSFORM,
|
|
684
|
-
isIdentityCloneTransform,
|
|
685
|
-
cloneSamplePoint,
|
|
686
|
-
TransformedPixelSource,
|
|
687
|
-
TilePixelSource,
|
|
688
|
-
RegionPixelSource,
|
|
689
|
-
readSourceRegion,
|
|
690
|
-
applyRetouchToTile,
|
|
691
|
-
applyToneToDeepTile,
|
|
692
|
-
toneOf,
|
|
693
|
-
healPixels,
|
|
694
|
-
spotHealPixels,
|
|
695
|
-
spotHealWindow,
|
|
696
|
-
RetouchDabStroke,
|
|
697
|
-
smudgeEffect,
|
|
698
|
-
spongeEffect,
|
|
699
|
-
rgbaViewOfGrey
|
|
700
|
-
};
|