@pixerate/editor 0.115.0 → 0.117.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 +3 -0
- package/dist/animation-editor/index.cjs +54 -54
- package/dist/animation-editor/index.d.cts +2 -2
- package/dist/animation-editor/index.d.ts +2 -2
- package/dist/animation-editor/index.js +2 -2
- package/dist/{chunk-I7FQBWMQ.cjs → chunk-2J3LS7JZ.cjs} +333 -333
- package/dist/{chunk-I7FQBWMQ.cjs.map → chunk-2J3LS7JZ.cjs.map} +1 -1
- package/dist/{chunk-TFOPHZ3U.cjs → chunk-7ISPWEJA.cjs} +302 -5
- package/dist/chunk-7ISPWEJA.cjs.map +1 -0
- package/dist/{chunk-VXR7XWMF.js → chunk-7LNZAWSJ.js} +437 -41
- package/dist/chunk-7LNZAWSJ.js.map +1 -0
- package/dist/{chunk-DFQEX3AM.cjs → chunk-BYAWOAST.cjs} +223 -30
- package/dist/chunk-BYAWOAST.cjs.map +1 -0
- package/dist/chunk-COAMRKVI.cjs +159 -0
- package/dist/chunk-COAMRKVI.cjs.map +1 -0
- package/dist/{chunk-ST7E3NEE.cjs → chunk-EBSYZRSW.cjs} +230 -732
- package/dist/chunk-EBSYZRSW.cjs.map +1 -0
- package/dist/chunk-EJVDBITD.cjs +501 -0
- package/dist/chunk-EJVDBITD.cjs.map +1 -0
- package/dist/{chunk-LPLCWZTM.cjs → chunk-FODKPD44.cjs} +555 -159
- package/dist/chunk-FODKPD44.cjs.map +1 -0
- package/dist/{chunk-XK5LZKBD.js → chunk-HKDTM6VC.js} +298 -1
- package/dist/chunk-HKDTM6VC.js.map +1 -0
- package/dist/chunk-IPFRWILU.js +1908 -0
- package/dist/chunk-IPFRWILU.js.map +1 -0
- package/dist/chunk-IVSNUXW7.js +3339 -0
- package/dist/chunk-IVSNUXW7.js.map +1 -0
- package/dist/{chunk-LKCYANMW.js → chunk-JHXMNOMF.js} +198 -5
- package/dist/chunk-JHXMNOMF.js.map +1 -0
- package/dist/{chunk-FV5AXTSF.cjs → chunk-JSSBHMMU.cjs} +36 -188
- package/dist/chunk-JSSBHMMU.cjs.map +1 -0
- package/dist/chunk-L2T6EJ5S.cjs +3339 -0
- package/dist/chunk-L2T6EJ5S.cjs.map +1 -0
- package/dist/chunk-LF4WOZXZ.js +159 -0
- package/dist/chunk-LF4WOZXZ.js.map +1 -0
- package/dist/{chunk-26PGXHY7.cjs → chunk-M7O4BJRH.cjs} +36 -36
- package/dist/{chunk-26PGXHY7.cjs.map → chunk-M7O4BJRH.cjs.map} +1 -1
- package/dist/chunk-N3467VD6.js +501 -0
- package/dist/chunk-N3467VD6.js.map +1 -0
- package/dist/{chunk-XICA4PVO.js → chunk-R2JE6SA7.js} +17 -17
- package/dist/chunk-SMJGE7HM.cjs +1908 -0
- package/dist/chunk-SMJGE7HM.cjs.map +1 -0
- package/dist/{chunk-MMVHBKMM.js → chunk-T2P5TIZ6.js} +2 -2
- package/dist/{chunk-C6C5PDKU.js → chunk-VD2UDVF7.js} +102 -604
- package/dist/chunk-VD2UDVF7.js.map +1 -0
- package/dist/{chunk-FGW5OWJ4.js → chunk-VJUML33I.js} +4 -156
- package/dist/chunk-VJUML33I.js.map +1 -0
- package/dist/export/index.cjs +4 -2
- package/dist/export/index.cjs.map +1 -1
- package/dist/export/index.js +5 -3
- package/dist/{export-BJE8T0YA.d.cts → export-DMOuzgZZ.d.cts} +9 -4
- package/dist/{export-Con3UKkm.d.ts → export-Dul1SbPv.d.ts} +9 -4
- package/dist/export-Dv0-ZVrV.d.cts +501 -0
- package/dist/export-Dv0-ZVrV.d.ts +501 -0
- package/dist/{retouch-Bxkuc0KH.d.cts → flow-4-OC-UkQ.d.cts} +582 -2
- package/dist/{retouch-Do6tBs2H.d.ts → flow-Cb7lkPm8.d.ts} +582 -2
- package/dist/image-editor/index.cjs +1345 -1095
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +8 -8
- package/dist/image-editor/index.d.ts +8 -8
- package/dist/image-editor/index.js +300 -50
- package/dist/image-editor/index.js.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/kernel-wasm-WYCGNZR4.js +10 -0
- package/dist/kernel-wasm-WYCGNZR4.js.map +1 -0
- package/dist/kernel-wasm-YPVAEMVN.cjs +10 -0
- package/dist/kernel-wasm-YPVAEMVN.cjs.map +1 -0
- package/dist/paint/index.cjs +170 -4
- package/dist/paint/index.cjs.map +1 -1
- package/dist/paint/index.d.cts +225 -3
- package/dist/paint/index.d.ts +225 -3
- package/dist/paint/index.js +171 -5
- package/dist/paint-editor/index.cjs +4735 -890
- package/dist/paint-editor/index.cjs.map +1 -1
- package/dist/paint-editor/index.d.cts +1526 -278
- package/dist/paint-editor/index.d.ts +1526 -278
- package/dist/paint-editor/index.js +4561 -716
- package/dist/paint-editor/index.js.map +1 -1
- package/dist/raster/index.cjs +7 -4
- package/dist/raster/index.cjs.map +1 -1
- package/dist/raster/index.d.cts +2 -2
- package/dist/raster/index.d.ts +2 -2
- package/dist/raster/index.js +36 -33
- package/dist/{render-CrmHOgpo.d.ts → render-B05K68_h.d.ts} +9 -1
- package/dist/{render-B1K_OoLy.d.cts → render-DnAbIKcs.d.cts} +9 -1
- package/dist/{svg-BnRj0q8i.d.cts → svg-CVdFc80-.d.cts} +2 -2
- package/dist/{svg-CmmBFfGT.d.ts → svg-DlEuhwoX.d.ts} +2 -2
- package/dist/{types-1SUQKDAw.d.ts → types-CDLGhAZp.d.ts} +40 -2
- package/dist/{types-yINF17Ta.d.cts → types-Tfly4Aya.d.cts} +40 -2
- package/dist/vector/index.cjs +6536 -4525
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.cts +426 -32
- package/dist/vector/index.d.ts +426 -32
- package/dist/vector/index.js +11397 -9386
- package/dist/vector/index.js.map +1 -1
- package/dist/video-editor/index.cjs +502 -2165
- package/dist/video-editor/index.cjs.map +1 -1
- package/dist/video-editor/index.d.cts +3 -501
- package/dist/video-editor/index.d.ts +3 -501
- package/dist/video-editor/index.js +151 -1814
- package/dist/video-editor/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/pixerate-image-editor/references/photoshop-files.md +7 -3
- package/skills/pixerate-vector/SKILL.md +3 -0
- package/dist/chunk-C6C5PDKU.js.map +0 -1
- package/dist/chunk-DFQEX3AM.cjs.map +0 -1
- package/dist/chunk-FGW5OWJ4.js.map +0 -1
- package/dist/chunk-FV5AXTSF.cjs.map +0 -1
- package/dist/chunk-GX332W2C.js +0 -181
- package/dist/chunk-GX332W2C.js.map +0 -1
- package/dist/chunk-LKCYANMW.js.map +0 -1
- package/dist/chunk-LPLCWZTM.cjs.map +0 -1
- package/dist/chunk-MUUXNRU4.cjs +0 -181
- package/dist/chunk-MUUXNRU4.cjs.map +0 -1
- package/dist/chunk-ST7E3NEE.cjs.map +0 -1
- package/dist/chunk-TCKIXI46.cjs +0 -1136
- package/dist/chunk-TCKIXI46.cjs.map +0 -1
- package/dist/chunk-TFOPHZ3U.cjs.map +0 -1
- package/dist/chunk-UBIXVXPR.js +0 -1136
- package/dist/chunk-UBIXVXPR.js.map +0 -1
- package/dist/chunk-VXR7XWMF.js.map +0 -1
- package/dist/chunk-XK5LZKBD.js.map +0 -1
- /package/dist/{chunk-XICA4PVO.js.map → chunk-R2JE6SA7.js.map} +0 -0
- /package/dist/{chunk-MMVHBKMM.js.map → chunk-T2P5TIZ6.js.map} +0 -0
|
@@ -7,274 +7,34 @@ import {
|
|
|
7
7
|
invertHomography,
|
|
8
8
|
isIdentityHomography,
|
|
9
9
|
multiplyHomographies
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-N3467VD6.js";
|
|
11
11
|
import {
|
|
12
12
|
TILE,
|
|
13
13
|
TiledSurface,
|
|
14
14
|
blendChannel,
|
|
15
15
|
blendRgb,
|
|
16
16
|
contentBounds,
|
|
17
|
+
deepTile,
|
|
17
18
|
emptySurface,
|
|
18
19
|
finishTile,
|
|
19
20
|
isBlendMode,
|
|
20
21
|
isSeparableBlendMode,
|
|
21
22
|
mixPigment8,
|
|
22
23
|
mixPigmentRgb,
|
|
24
|
+
readDeepRegion,
|
|
23
25
|
readRegion,
|
|
26
|
+
srgbDecode,
|
|
27
|
+
srgbEncode,
|
|
28
|
+
surfaceDepth,
|
|
24
29
|
surfaceFromPixels,
|
|
25
30
|
tileKey,
|
|
31
|
+
tileSamples,
|
|
26
32
|
tilesInRect,
|
|
33
|
+
to32From8,
|
|
27
34
|
translateSurface,
|
|
35
|
+
writeDeepRegion,
|
|
28
36
|
writeRegion
|
|
29
|
-
} from "./chunk-
|
|
30
|
-
import {
|
|
31
|
-
deflate,
|
|
32
|
-
inflate
|
|
33
|
-
} from "./chunk-6FCKOS2B.js";
|
|
34
|
-
|
|
35
|
-
// src/raster/deep.ts
|
|
36
|
-
var BIT_DEPTHS = [8, 16, 32];
|
|
37
|
-
var isBitDepth = (v) => v === 8 || v === 16 || v === 32;
|
|
38
|
-
var TILE_PIXELS = TILE * TILE;
|
|
39
|
-
function srgbDecode(v) {
|
|
40
|
-
return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
41
|
-
}
|
|
42
|
-
function srgbEncode(v) {
|
|
43
|
-
if (!(v > 0)) return 0;
|
|
44
|
-
return v <= 31308e-7 ? v * 12.92 : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
|
|
45
|
-
}
|
|
46
|
-
var LIN8 = null;
|
|
47
|
-
var LIN16 = null;
|
|
48
|
-
function lin8() {
|
|
49
|
-
if (!LIN8) {
|
|
50
|
-
LIN8 = new Float32Array(256);
|
|
51
|
-
for (let i = 0; i < 256; i++) LIN8[i] = srgbDecode(i / 255);
|
|
52
|
-
}
|
|
53
|
-
return LIN8;
|
|
54
|
-
}
|
|
55
|
-
function lin16() {
|
|
56
|
-
if (!LIN16) {
|
|
57
|
-
LIN16 = new Float32Array(65536);
|
|
58
|
-
for (let i = 0; i < 65536; i++) LIN16[i] = srgbDecode(i / 65535);
|
|
59
|
-
}
|
|
60
|
-
return LIN16;
|
|
61
|
-
}
|
|
62
|
-
function encode16(v) {
|
|
63
|
-
if (!(v > 0)) return 0;
|
|
64
|
-
if (v >= 1) return 65535;
|
|
65
|
-
return Math.round(srgbEncode(v) * 65535);
|
|
66
|
-
}
|
|
67
|
-
var ENC8 = null;
|
|
68
|
-
function encode8(v) {
|
|
69
|
-
if (!(v > 0)) return 0;
|
|
70
|
-
if (v >= 1) return 255;
|
|
71
|
-
if (!ENC8) {
|
|
72
|
-
ENC8 = new Uint8Array(65536);
|
|
73
|
-
for (let i = 0; i < 65536; i++) ENC8[i] = Math.round(srgbEncode(i / 65535) * 255);
|
|
74
|
-
}
|
|
75
|
-
return ENC8[Math.round(v * 65535)];
|
|
76
|
-
}
|
|
77
|
-
function to16From8(data, out = new Uint16Array(data.length)) {
|
|
78
|
-
for (let i = 0; i < data.length; i++) out[i] = data[i] * 257;
|
|
79
|
-
return out;
|
|
80
|
-
}
|
|
81
|
-
function to32From8(data, channels, out = new Float32Array(data.length)) {
|
|
82
|
-
if (channels === 1) {
|
|
83
|
-
for (let i = 0; i < data.length; i++) out[i] = data[i] / 255;
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
const t = lin8();
|
|
87
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
88
|
-
out[i] = t[data[i]];
|
|
89
|
-
out[i + 1] = t[data[i + 1]];
|
|
90
|
-
out[i + 2] = t[data[i + 2]];
|
|
91
|
-
out[i + 3] = data[i + 3] / 255;
|
|
92
|
-
}
|
|
93
|
-
return out;
|
|
94
|
-
}
|
|
95
|
-
function to32From16(data, channels, out = new Float32Array(data.length)) {
|
|
96
|
-
if (channels === 1) {
|
|
97
|
-
for (let i = 0; i < data.length; i++) out[i] = data[i] / 65535;
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
const t = lin16();
|
|
101
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
102
|
-
out[i] = t[data[i]];
|
|
103
|
-
out[i + 1] = t[data[i + 1]];
|
|
104
|
-
out[i + 2] = t[data[i + 2]];
|
|
105
|
-
out[i + 3] = data[i + 3] / 65535;
|
|
106
|
-
}
|
|
107
|
-
return out;
|
|
108
|
-
}
|
|
109
|
-
function to16From32(data, channels, out = new Uint16Array(data.length)) {
|
|
110
|
-
const unit = (v) => v > 0 ? v < 1 ? Math.round(v * 65535) : 65535 : 0;
|
|
111
|
-
if (channels === 1) {
|
|
112
|
-
for (let i = 0; i < data.length; i++) out[i] = unit(data[i]);
|
|
113
|
-
return out;
|
|
114
|
-
}
|
|
115
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
116
|
-
out[i] = encode16(data[i]);
|
|
117
|
-
out[i + 1] = encode16(data[i + 1]);
|
|
118
|
-
out[i + 2] = encode16(data[i + 2]);
|
|
119
|
-
out[i + 3] = unit(data[i + 3]);
|
|
120
|
-
}
|
|
121
|
-
return out;
|
|
122
|
-
}
|
|
123
|
-
function to8From16(data, out = new Uint8ClampedArray(data.length)) {
|
|
124
|
-
for (let i = 0; i < data.length; i++) out[i] = Math.round(data[i] / 257);
|
|
125
|
-
return out;
|
|
126
|
-
}
|
|
127
|
-
function to8From32(data, channels, out = new Uint8ClampedArray(data.length)) {
|
|
128
|
-
if (channels === 1) {
|
|
129
|
-
for (let i = 0; i < data.length; i++) out[i] = Math.round(data[i] * 255);
|
|
130
|
-
return out;
|
|
131
|
-
}
|
|
132
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
133
|
-
out[i] = encode8(data[i]);
|
|
134
|
-
out[i + 1] = encode8(data[i + 1]);
|
|
135
|
-
out[i + 2] = encode8(data[i + 2]);
|
|
136
|
-
out[i + 3] = Math.round(Math.min(1, Math.max(0, data[i + 3])) * 255);
|
|
137
|
-
}
|
|
138
|
-
return out;
|
|
139
|
-
}
|
|
140
|
-
function proxyOf(deep, channels, out) {
|
|
141
|
-
return deep instanceof Uint16Array ? to8From16(deep, out) : to8From32(deep, channels, out);
|
|
142
|
-
}
|
|
143
|
-
var depthOf = (deep) => deep instanceof Uint16Array ? 16 : 32;
|
|
144
|
-
function deepTile(deep, channels, defaultValue = 0) {
|
|
145
|
-
const data = proxyOf(deep, channels);
|
|
146
|
-
if (deep instanceof Uint16Array) {
|
|
147
|
-
let exact = true;
|
|
148
|
-
for (let i = 0; i < deep.length; i++) {
|
|
149
|
-
if (deep[i] % 257 !== 0) {
|
|
150
|
-
exact = false;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (exact) return finishTile(data, channels, defaultValue);
|
|
155
|
-
} else if (channels === 4 && defaultValue === 0) {
|
|
156
|
-
let empty = true;
|
|
157
|
-
for (let i = 3; i < deep.length; i += 4) {
|
|
158
|
-
if (deep[i] !== 0) {
|
|
159
|
-
empty = false;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (empty) return null;
|
|
164
|
-
}
|
|
165
|
-
return { data, uniform: null, deep };
|
|
166
|
-
}
|
|
167
|
-
function tileSamples16(tile, channels, defaultValue = 0) {
|
|
168
|
-
const deep = tile?.deep;
|
|
169
|
-
if (deep instanceof Uint16Array) return deep;
|
|
170
|
-
if (deep instanceof Float32Array) return to16From32(deep, channels);
|
|
171
|
-
if (tile) return to16From8(tile.data);
|
|
172
|
-
return new Uint16Array(TILE_PIXELS * channels).fill(defaultValue * 257);
|
|
173
|
-
}
|
|
174
|
-
function tileSamples32(tile, channels, defaultValue = 0) {
|
|
175
|
-
const deep = tile?.deep;
|
|
176
|
-
if (deep instanceof Float32Array) return deep;
|
|
177
|
-
if (deep instanceof Uint16Array) return to32From16(deep, channels);
|
|
178
|
-
if (tile) return to32From8(tile.data, channels);
|
|
179
|
-
const out = new Float32Array(TILE_PIXELS * channels);
|
|
180
|
-
if (defaultValue) {
|
|
181
|
-
if (channels === 1) out.fill(defaultValue / 255);
|
|
182
|
-
else to32From8(new Uint8ClampedArray(TILE_PIXELS * 4).fill(defaultValue), 4, out);
|
|
183
|
-
}
|
|
184
|
-
return out;
|
|
185
|
-
}
|
|
186
|
-
function tileSamples(tile, channels, depth, defaultValue = 0) {
|
|
187
|
-
return depth === 16 ? tileSamples16(tile, channels, defaultValue) : tileSamples32(tile, channels, defaultValue);
|
|
188
|
-
}
|
|
189
|
-
function surfaceDepth(surface) {
|
|
190
|
-
let d = 8;
|
|
191
|
-
for (const t of surface.tiles.values()) {
|
|
192
|
-
if (t.deep instanceof Float32Array) return 32;
|
|
193
|
-
if (t.deep) d = 16;
|
|
194
|
-
}
|
|
195
|
-
return d;
|
|
196
|
-
}
|
|
197
|
-
function readDeepRegion(surface, rect, depth) {
|
|
198
|
-
const ch = surface.channels;
|
|
199
|
-
const w = rect.width;
|
|
200
|
-
const h = rect.height;
|
|
201
|
-
const out = depth === 16 ? new Uint16Array(w * h * ch) : new Float32Array(w * h * ch);
|
|
202
|
-
const fill2 = tileSamples(void 0, ch, depth, surface.defaultValue);
|
|
203
|
-
if (surface.defaultValue) for (let i = 0; i < out.length; i += ch) for (let c = 0; c < ch; c++) out[i + c] = fill2[c];
|
|
204
|
-
for (const { tx, ty } of tilesInRect(rect)) {
|
|
205
|
-
const tile = surface.tiles.get(tileKey(tx, ty));
|
|
206
|
-
if (!tile) continue;
|
|
207
|
-
const src = tileSamples(tile, ch, depth, surface.defaultValue);
|
|
208
|
-
const ox = tx * TILE;
|
|
209
|
-
const oy = ty * TILE;
|
|
210
|
-
const x0 = Math.max(rect.x, ox);
|
|
211
|
-
const y0 = Math.max(rect.y, oy);
|
|
212
|
-
const x1 = Math.min(rect.x + w, ox + TILE);
|
|
213
|
-
const y1 = Math.min(rect.y + h, oy + TILE);
|
|
214
|
-
const span = (x1 - x0) * ch;
|
|
215
|
-
for (let yy = y0; yy < y1; yy++) {
|
|
216
|
-
const s = ((yy - oy) * TILE + (x0 - ox)) * ch;
|
|
217
|
-
const d = ((yy - rect.y) * w + (x0 - rect.x)) * ch;
|
|
218
|
-
out.set(src.subarray(s, s + span), d);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return out;
|
|
222
|
-
}
|
|
223
|
-
function writeDeepRegion(surface, rect, samples) {
|
|
224
|
-
const ch = surface.channels;
|
|
225
|
-
const w = rect.width;
|
|
226
|
-
const h = rect.height;
|
|
227
|
-
if (w <= 0 || h <= 0) return surface;
|
|
228
|
-
if (samples.length < w * h * ch) throw new Error(`writeDeepRegion: expected ${w * h * ch} samples, got ${samples.length}`);
|
|
229
|
-
const depth = depthOf(samples);
|
|
230
|
-
const tiles = new Map(surface.tiles);
|
|
231
|
-
for (const { tx, ty } of tilesInRect(rect)) {
|
|
232
|
-
const key = tileKey(tx, ty);
|
|
233
|
-
const ox = tx * TILE;
|
|
234
|
-
const oy = ty * TILE;
|
|
235
|
-
const x0 = Math.max(rect.x, ox);
|
|
236
|
-
const y0 = Math.max(rect.y, oy);
|
|
237
|
-
const x1 = Math.min(rect.x + w, ox + TILE);
|
|
238
|
-
const y1 = Math.min(rect.y + h, oy + TILE);
|
|
239
|
-
const full = x0 === ox && y0 === oy && x1 === ox + TILE && y1 === oy + TILE;
|
|
240
|
-
const base = full ? null : tileSamples(surface.tiles.get(key), ch, depth, surface.defaultValue);
|
|
241
|
-
const t = base ? base.slice() : depth === 16 ? new Uint16Array(TILE_PIXELS * ch) : new Float32Array(TILE_PIXELS * ch);
|
|
242
|
-
const span = (x1 - x0) * ch;
|
|
243
|
-
for (let yy = y0; yy < y1; yy++) {
|
|
244
|
-
const s = ((yy - rect.y) * w + (x0 - rect.x)) * ch;
|
|
245
|
-
const d = ((yy - oy) * TILE + (x0 - ox)) * ch;
|
|
246
|
-
t.set(samples.subarray(s, s + span), d);
|
|
247
|
-
}
|
|
248
|
-
const tile = deepTile(t, ch, surface.defaultValue);
|
|
249
|
-
if (tile) tiles.set(key, tile);
|
|
250
|
-
else tiles.delete(key);
|
|
251
|
-
}
|
|
252
|
-
return new TiledSurface(ch, tiles, surface.defaultValue);
|
|
253
|
-
}
|
|
254
|
-
function surfaceFromDeepPixels(pixels, channels = 4, x = 0, y = 0, defaultValue = 0) {
|
|
255
|
-
return writeDeepRegion(emptySurface(channels, defaultValue), { x, y, width: pixels.width, height: pixels.height }, pixels.data);
|
|
256
|
-
}
|
|
257
|
-
function convertSurfaceDepth(surface, depth) {
|
|
258
|
-
let changed = false;
|
|
259
|
-
const tiles = new Map(surface.tiles);
|
|
260
|
-
const ch = surface.channels;
|
|
261
|
-
for (const [key, tile] of surface.tiles) {
|
|
262
|
-
const deep = tile.deep;
|
|
263
|
-
if (!deep || depthOf(deep) === depth) continue;
|
|
264
|
-
changed = true;
|
|
265
|
-
let next;
|
|
266
|
-
if (depth === 8) next = finishTile(tile.data, ch, surface.defaultValue);
|
|
267
|
-
else next = deepTile(depth === 16 ? to16From32(deep, ch) : to32From16(deep, ch), ch, surface.defaultValue);
|
|
268
|
-
if (next) tiles.set(key, next);
|
|
269
|
-
else tiles.delete(key);
|
|
270
|
-
}
|
|
271
|
-
return changed ? new TiledSurface(ch, tiles, surface.defaultValue) : surface;
|
|
272
|
-
}
|
|
273
|
-
function deepBytes(surface) {
|
|
274
|
-
let n = 0;
|
|
275
|
-
for (const t of surface.tiles.values()) if (t.deep) n += t.deep.byteLength;
|
|
276
|
-
return n;
|
|
277
|
-
}
|
|
37
|
+
} from "./chunk-HKDTM6VC.js";
|
|
278
38
|
|
|
279
39
|
// src/raster/effects/model.ts
|
|
280
40
|
var DEFAULT_GLOBAL_LIGHT = { angle: 120, altitude: 30 };
|
|
@@ -2584,8 +2344,8 @@ function renderLayerEffects(effects, layer, backdrop, canvas, ctx) {
|
|
|
2584
2344
|
}
|
|
2585
2345
|
|
|
2586
2346
|
// src/raster/compositor.ts
|
|
2587
|
-
var
|
|
2588
|
-
var TILE_BYTES =
|
|
2347
|
+
var TILE_PIXELS = TILE * TILE;
|
|
2348
|
+
var TILE_BYTES = TILE_PIXELS * 4;
|
|
2589
2349
|
function sameSig(a, b) {
|
|
2590
2350
|
if (!a || a.key !== b.key || a.refs.length !== b.refs.length) return false;
|
|
2591
2351
|
for (let i = 0; i < a.refs.length; i++) if (a.refs[i] !== b.refs[i]) return false;
|
|
@@ -3605,13 +3365,13 @@ function hasTilesIn(src, r) {
|
|
|
3605
3365
|
for (const { tx, ty } of tilesInRect(r)) if (src.getTile(tx, ty)) return true;
|
|
3606
3366
|
return false;
|
|
3607
3367
|
}
|
|
3608
|
-
function readWindow(src, srcRect, rect) {
|
|
3368
|
+
function readWindow(src, srcRect, rect, depth = null) {
|
|
3609
3369
|
const n = src.channels === 4 ? 4 : 2;
|
|
3610
3370
|
const data = new Float32Array(rect.width * rect.height * n);
|
|
3611
3371
|
const win = { x: rect.x, y: rect.y, w: rect.width, h: rect.height, n, data };
|
|
3612
3372
|
const r = intersect(rect, srcRect);
|
|
3613
3373
|
if (!r) return win;
|
|
3614
|
-
const px = readRegion(src, r);
|
|
3374
|
+
const px = depth ? readScaled(src, r, depth) : readRegion(src, r);
|
|
3615
3375
|
for (let y = 0; y < r.height; y++) {
|
|
3616
3376
|
let s = y * r.width * src.channels;
|
|
3617
3377
|
let d = ((r.y - rect.y + y) * rect.width + (r.x - rect.x)) * n;
|
|
@@ -3745,7 +3505,44 @@ function store(out, o, acc, ch, def) {
|
|
|
3745
3505
|
out[o] = acc[0] + def * (1 - inside);
|
|
3746
3506
|
return true;
|
|
3747
3507
|
}
|
|
3748
|
-
function
|
|
3508
|
+
function resampleDepth(src, step) {
|
|
3509
|
+
if (src.channels !== 4 || src.defaultValue !== 0 || step !== 1) return null;
|
|
3510
|
+
const d = surfaceDepth(src);
|
|
3511
|
+
return d === 8 ? null : d;
|
|
3512
|
+
}
|
|
3513
|
+
function readScaled(src, rect, depth) {
|
|
3514
|
+
const d = readDeepRegion(src, rect, depth);
|
|
3515
|
+
const out = new Float32Array(d.length);
|
|
3516
|
+
const k = depth === 16 ? 1 / 257 : 255;
|
|
3517
|
+
for (let i = 0; i < d.length; i++) out[i] = d[i] * k;
|
|
3518
|
+
return out;
|
|
3519
|
+
}
|
|
3520
|
+
function fromScaled(v, depth) {
|
|
3521
|
+
if (depth === 16) {
|
|
3522
|
+
const out2 = new Uint16Array(v.length);
|
|
3523
|
+
for (let i = 0; i < v.length; i++) {
|
|
3524
|
+
const x = Math.round(v[i] * 257);
|
|
3525
|
+
out2[i] = x <= 0 ? 0 : x >= 65535 ? 65535 : x;
|
|
3526
|
+
}
|
|
3527
|
+
return out2;
|
|
3528
|
+
}
|
|
3529
|
+
const out = new Float32Array(v.length);
|
|
3530
|
+
for (let i = 0; i < v.length; i++) {
|
|
3531
|
+
const x = v[i] / 255;
|
|
3532
|
+
out[i] = (i & 3) === 3 ? x <= 0 ? 0 : x >= 1 ? 1 : x : x;
|
|
3533
|
+
}
|
|
3534
|
+
return out;
|
|
3535
|
+
}
|
|
3536
|
+
function storeScaled(out, o, acc) {
|
|
3537
|
+
const al = acc[3] > 1 ? 1 : acc[3];
|
|
3538
|
+
if (!(al > 1e-6)) return false;
|
|
3539
|
+
out[o] = acc[0] / al;
|
|
3540
|
+
out[o + 1] = acc[1] / al;
|
|
3541
|
+
out[o + 2] = acc[2] / al;
|
|
3542
|
+
out[o + 3] = al * 255;
|
|
3543
|
+
return true;
|
|
3544
|
+
}
|
|
3545
|
+
function boxReduce(src, srcRect, kx, ky, depth = null) {
|
|
3749
3546
|
const ch = src.channels;
|
|
3750
3547
|
const rx0 = Math.floor(srcRect.x / kx);
|
|
3751
3548
|
const ry0 = Math.floor(srcRect.y / ky);
|
|
@@ -3759,8 +3556,8 @@ function boxReduce(src, srcRect, kx, ky) {
|
|
|
3759
3556
|
for (let ry = ry0; ry < ry1; ry += rowsPer) {
|
|
3760
3557
|
const rows = Math.min(rowsPer, ry1 - ry);
|
|
3761
3558
|
const strip = { x: rx0 * kx, y: ry * ky, width: rw * kx, height: rows * ky };
|
|
3762
|
-
const px = readRegion(src, strip);
|
|
3763
|
-
const red = new Uint8ClampedArray(rw * rows * ch);
|
|
3559
|
+
const px = depth ? readScaled(src, strip, depth) : readRegion(src, strip);
|
|
3560
|
+
const red = depth ? new Float32Array(rw * rows * ch) : new Uint8ClampedArray(rw * rows * ch);
|
|
3764
3561
|
for (let j = 0; j < rows; j++) {
|
|
3765
3562
|
for (let i = 0; i < rw; i++) {
|
|
3766
3563
|
if (ch === 4) {
|
|
@@ -3795,7 +3592,8 @@ function boxReduce(src, srcRect, kx, ky) {
|
|
|
3795
3592
|
}
|
|
3796
3593
|
}
|
|
3797
3594
|
}
|
|
3798
|
-
|
|
3595
|
+
const region = { x: rx0, y: ry, width: rw, height: rows };
|
|
3596
|
+
out = depth ? writeDeepRegion(out, region, fromScaled(red, depth)) : writeRegion(out, region, red);
|
|
3799
3597
|
}
|
|
3800
3598
|
return { surface: out, rect };
|
|
3801
3599
|
}
|
|
@@ -3844,11 +3642,18 @@ function transformSurface(src, h, options = {}) {
|
|
|
3844
3642
|
const empty = emptySurface(ch, def);
|
|
3845
3643
|
const given = options.source;
|
|
3846
3644
|
const step = normalizeStep(options.step);
|
|
3645
|
+
const depth = resampleDepth(src, step);
|
|
3847
3646
|
if (isIdentityHomography(h, 1e-12) && !given && !options.clip) return src;
|
|
3848
3647
|
const dx = h[2] / h[8];
|
|
3849
3648
|
const dy = h[5] / h[8];
|
|
3850
3649
|
if (!given && !options.clip && isIdentityHomography([h[0], h[1], 0, h[3], h[4], 0, h[6], h[7], h[8]], 1e-12) && Math.abs(dx - Math.round(dx)) < 1e-9 && Math.abs(dy - Math.round(dy)) < 1e-9) {
|
|
3851
|
-
|
|
3650
|
+
const mx = Math.round(dx);
|
|
3651
|
+
const my = Math.round(dy);
|
|
3652
|
+
const b = src.bounds;
|
|
3653
|
+
if (depth && b && (mx % TILE !== 0 || my % TILE !== 0)) {
|
|
3654
|
+
return writeDeepRegion(emptySurface(ch, def), { ...b, x: b.x + mx, y: b.y + my }, readDeepRegion(src, b, depth));
|
|
3655
|
+
}
|
|
3656
|
+
return translateSurface(src, mx, my);
|
|
3852
3657
|
}
|
|
3853
3658
|
let srcRect = given ? intersect(given, given) : contentBounds(src);
|
|
3854
3659
|
if (!srcRect) return empty;
|
|
@@ -3862,7 +3667,7 @@ function transformSurface(src, h, options = {}) {
|
|
|
3862
3667
|
const kx = reduction(su);
|
|
3863
3668
|
const ky = reduction(sv);
|
|
3864
3669
|
if (kx > 1 || ky > 1) {
|
|
3865
|
-
const red = boxReduce(src, srcRect, kx, ky);
|
|
3670
|
+
const red = boxReduce(src, srcRect, kx, ky, depth);
|
|
3866
3671
|
S = red.surface;
|
|
3867
3672
|
srcRect = red.rect;
|
|
3868
3673
|
H = multiplyHomographies([kx, 0, 0, 0, ky, 0, 0, 0, 1], H);
|
|
@@ -3946,9 +3751,10 @@ function transformSurface(src, h, options = {}) {
|
|
|
3946
3751
|
if (!foot) continue;
|
|
3947
3752
|
const readable = intersect(foot, sr);
|
|
3948
3753
|
if (!readable || !hasTilesIn(S, readable)) continue;
|
|
3949
|
-
const win = readWindow(S, sr, foot);
|
|
3754
|
+
const win = readWindow(S, sr, foot, depth);
|
|
3950
3755
|
const out = new Uint8ClampedArray(TILE * TILE * ch);
|
|
3951
3756
|
if (def) out.fill(def);
|
|
3757
|
+
const deepOut = depth ? new Float32Array(TILE * TILE * 4) : null;
|
|
3952
3758
|
let any = false;
|
|
3953
3759
|
const ox = tx * TILE;
|
|
3954
3760
|
const oy = ty * TILE;
|
|
@@ -3977,6 +3783,10 @@ function transformSurface(src, h, options = {}) {
|
|
|
3977
3783
|
sv = widen(s[1]);
|
|
3978
3784
|
}
|
|
3979
3785
|
sample(win, interp, u, v, su, sv, acc);
|
|
3786
|
+
if (deepOut) {
|
|
3787
|
+
if (storeScaled(deepOut, ((y - oy) * TILE + (x - ox)) * 4, acc)) any = true;
|
|
3788
|
+
continue;
|
|
3789
|
+
}
|
|
3980
3790
|
if (!store(scratch, 0, acc, ch, def)) continue;
|
|
3981
3791
|
rowSet[bi] = 1;
|
|
3982
3792
|
rowVals[bi] = ch === 4 ? scratchWord[0] : scratch[0];
|
|
@@ -3999,7 +3809,7 @@ function transformSurface(src, h, options = {}) {
|
|
|
3999
3809
|
}
|
|
4000
3810
|
}
|
|
4001
3811
|
if (!any) continue;
|
|
4002
|
-
const tile = finishTile(out, ch, def);
|
|
3812
|
+
const tile = deepOut ? deepTile(fromScaled(deepOut, depth), 4, def) : finishTile(out, ch, def);
|
|
4003
3813
|
if (tile) tiles.set(tileKey(tx, ty), tile);
|
|
4004
3814
|
}
|
|
4005
3815
|
return assemble(src, tiles);
|
|
@@ -4015,6 +3825,7 @@ function warpSurface(src, f, options = {}) {
|
|
|
4015
3825
|
const sr = options.source ? intersect(options.source, options.source) : contentBounds(src);
|
|
4016
3826
|
if (!sr) return empty;
|
|
4017
3827
|
const step = normalizeStep(options.step);
|
|
3828
|
+
const depth = resampleDepth(src, step);
|
|
4018
3829
|
const nx = Math.min(MAX_CELLS, Math.max(1, Math.ceil(sr.width / CELL)));
|
|
4019
3830
|
const ny = Math.min(MAX_CELLS, Math.max(1, Math.ceil(sr.height / CELL)));
|
|
4020
3831
|
const w1 = nx + 1;
|
|
@@ -4182,9 +3993,10 @@ function warpSurface(src, f, options = {}) {
|
|
|
4182
3993
|
if (fx0 > fx1) continue;
|
|
4183
3994
|
const foot = intersect({ x: Math.floor(fx0) - 3, y: Math.floor(fy0) - 3, width: Math.ceil(fx1) - Math.floor(fx0) + 6, height: Math.ceil(fy1) - Math.floor(fy0) + 6 }, sr);
|
|
4184
3995
|
if (!foot || !hasTilesIn(src, foot)) continue;
|
|
4185
|
-
const win = readWindow(src, sr, foot);
|
|
3996
|
+
const win = readWindow(src, sr, foot, depth);
|
|
4186
3997
|
const out = new Uint8ClampedArray(TILE * TILE * ch);
|
|
4187
3998
|
if (def) out.fill(def);
|
|
3999
|
+
const deepOut = depth ? new Float32Array(TILE * TILE * 4) : null;
|
|
4188
4000
|
let any = false;
|
|
4189
4001
|
const ox = ttx * TILE;
|
|
4190
4002
|
const oy = tty * TILE;
|
|
@@ -4218,7 +4030,8 @@ function warpSurface(src, f, options = {}) {
|
|
|
4218
4030
|
pointAt(o, acc);
|
|
4219
4031
|
const x = t.x + o % tw;
|
|
4220
4032
|
const y = t.y + Math.floor(o / tw);
|
|
4221
|
-
|
|
4033
|
+
const o4 = ((y - oy) * TILE + (x - ox)) * ch;
|
|
4034
|
+
if (deepOut ? storeScaled(deepOut, o4, acc) : store(out, o4, acc, ch, def)) any = true;
|
|
4222
4035
|
}
|
|
4223
4036
|
} else {
|
|
4224
4037
|
for (let by = 0; by < th; by += step) {
|
|
@@ -4237,7 +4050,7 @@ function warpSurface(src, f, options = {}) {
|
|
|
4237
4050
|
}
|
|
4238
4051
|
}
|
|
4239
4052
|
if (!any) continue;
|
|
4240
|
-
const tile = finishTile(out, ch, def);
|
|
4053
|
+
const tile = deepOut ? deepTile(fromScaled(deepOut, depth), 4, def) : finishTile(out, ch, def);
|
|
4241
4054
|
if (tile) tiles.set(tileKey(ttx, tty), tile);
|
|
4242
4055
|
}
|
|
4243
4056
|
}
|
|
@@ -4248,12 +4061,34 @@ function compositeSurfaceOver(base, top) {
|
|
|
4248
4061
|
if (!top.tiles.size) return base;
|
|
4249
4062
|
const ch = base.channels;
|
|
4250
4063
|
const tiles = new Map(base.tiles);
|
|
4064
|
+
const bd = ch === 4 && base.defaultValue === 0 ? Math.max(surfaceDepth(base), surfaceDepth(top)) : 8;
|
|
4065
|
+
const depth = bd === 8 ? null : bd;
|
|
4251
4066
|
for (const [key, t] of top.tiles) {
|
|
4252
4067
|
const under = base.tiles.get(key);
|
|
4253
4068
|
if (!under && ch === 4) {
|
|
4254
4069
|
tiles.set(key, t);
|
|
4255
4070
|
continue;
|
|
4256
4071
|
}
|
|
4072
|
+
if (depth) {
|
|
4073
|
+
const k = depth === 16 ? 65535 : 1;
|
|
4074
|
+
const d2 = tileSamples(under, 4, depth, 0).slice();
|
|
4075
|
+
const sd = tileSamples(t, 4, depth, 0);
|
|
4076
|
+
for (let i = 0; i < d2.length; i += 4) {
|
|
4077
|
+
const ta = Math.min(1, sd[i + 3] / k);
|
|
4078
|
+
if (ta <= 0) continue;
|
|
4079
|
+
const da = d2[i + 3] / k;
|
|
4080
|
+
const oa = ta + da * (1 - ta);
|
|
4081
|
+
for (let c = 0; c < 3; c++) {
|
|
4082
|
+
const v = (sd[i + c] * ta + d2[i + c] * da * (1 - ta)) / oa;
|
|
4083
|
+
d2[i + c] = depth === 16 ? Math.round(v) : v;
|
|
4084
|
+
}
|
|
4085
|
+
d2[i + 3] = depth === 16 ? Math.round(oa * k) : oa;
|
|
4086
|
+
}
|
|
4087
|
+
const tile2 = deepTile(d2, 4, 0);
|
|
4088
|
+
if (tile2) tiles.set(key, tile2);
|
|
4089
|
+
else tiles.delete(key);
|
|
4090
|
+
continue;
|
|
4091
|
+
}
|
|
4257
4092
|
const d = new Uint8ClampedArray(TILE * TILE * ch);
|
|
4258
4093
|
if (under) d.set(under.data);
|
|
4259
4094
|
else if (base.defaultValue) d.fill(base.defaultValue);
|
|
@@ -4287,337 +4122,7 @@ function compositeSurfaceOver(base, top) {
|
|
|
4287
4122
|
return new TiledSurface(ch, tiles, base.defaultValue);
|
|
4288
4123
|
}
|
|
4289
4124
|
|
|
4290
|
-
// src/raster/png.ts
|
|
4291
|
-
var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
4292
|
-
var crcTable = null;
|
|
4293
|
-
function crc32(bytes, start, end) {
|
|
4294
|
-
if (!crcTable) {
|
|
4295
|
-
crcTable = new Uint32Array(256);
|
|
4296
|
-
for (let n = 0; n < 256; n++) {
|
|
4297
|
-
let c2 = n;
|
|
4298
|
-
for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
|
|
4299
|
-
crcTable[n] = c2 >>> 0;
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
let c = 4294967295;
|
|
4303
|
-
for (let i = start; i < end; i++) c = crcTable[(c ^ bytes[i]) & 255] ^ c >>> 8;
|
|
4304
|
-
return (c ^ 4294967295) >>> 0;
|
|
4305
|
-
}
|
|
4306
|
-
function paeth(a, b, c) {
|
|
4307
|
-
const p = a + b - c;
|
|
4308
|
-
const pa = Math.abs(p - a);
|
|
4309
|
-
const pb = Math.abs(p - b);
|
|
4310
|
-
const pc = Math.abs(p - c);
|
|
4311
|
-
return pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
4312
|
-
}
|
|
4313
|
-
function encodePng(width, height, data, channels = 4) {
|
|
4314
|
-
const stride = width * channels;
|
|
4315
|
-
const raw = new Uint8Array((stride + 1) * height);
|
|
4316
|
-
const bpp = channels;
|
|
4317
|
-
const cand = [new Uint8Array(stride), new Uint8Array(stride), new Uint8Array(stride), new Uint8Array(stride), new Uint8Array(stride)];
|
|
4318
|
-
for (let y = 0; y < height; y++) {
|
|
4319
|
-
const row = y * stride;
|
|
4320
|
-
const prevRow = (y - 1) * stride;
|
|
4321
|
-
let best = 0;
|
|
4322
|
-
let bestScore = Infinity;
|
|
4323
|
-
for (let f = 0; f < 5; f++) {
|
|
4324
|
-
const out2 = cand[f];
|
|
4325
|
-
let score = 0;
|
|
4326
|
-
for (let x = 0; x < stride; x++) {
|
|
4327
|
-
const v = data[row + x];
|
|
4328
|
-
const a = x >= bpp ? data[row + x - bpp] : 0;
|
|
4329
|
-
const b = y > 0 ? data[prevRow + x] : 0;
|
|
4330
|
-
const c = x >= bpp && y > 0 ? data[prevRow + x - bpp] : 0;
|
|
4331
|
-
let r;
|
|
4332
|
-
switch (f) {
|
|
4333
|
-
case 0:
|
|
4334
|
-
r = v;
|
|
4335
|
-
break;
|
|
4336
|
-
case 1:
|
|
4337
|
-
r = v - a;
|
|
4338
|
-
break;
|
|
4339
|
-
case 2:
|
|
4340
|
-
r = v - b;
|
|
4341
|
-
break;
|
|
4342
|
-
case 3:
|
|
4343
|
-
r = v - (a + b >> 1);
|
|
4344
|
-
break;
|
|
4345
|
-
default:
|
|
4346
|
-
r = v - paeth(a, b, c);
|
|
4347
|
-
}
|
|
4348
|
-
r &= 255;
|
|
4349
|
-
out2[x] = r;
|
|
4350
|
-
score += r < 128 ? r : 256 - r;
|
|
4351
|
-
if (score >= bestScore) break;
|
|
4352
|
-
}
|
|
4353
|
-
if (score < bestScore) {
|
|
4354
|
-
bestScore = score;
|
|
4355
|
-
best = f;
|
|
4356
|
-
}
|
|
4357
|
-
}
|
|
4358
|
-
const o = y * (stride + 1);
|
|
4359
|
-
raw[o] = best;
|
|
4360
|
-
raw.set(cand[best], o + 1);
|
|
4361
|
-
}
|
|
4362
|
-
const idat = deflate(raw);
|
|
4363
|
-
const chunks = [];
|
|
4364
|
-
const ihdr = new Uint8Array(13);
|
|
4365
|
-
writeU32(ihdr, 0, width);
|
|
4366
|
-
writeU32(ihdr, 4, height);
|
|
4367
|
-
ihdr[8] = 8;
|
|
4368
|
-
ihdr[9] = channels === 1 ? 0 : 6;
|
|
4369
|
-
chunks.push(["IHDR", ihdr], ["IDAT", idat], ["IEND", new Uint8Array(0)]);
|
|
4370
|
-
let size = 8;
|
|
4371
|
-
for (const [, d] of chunks) size += 12 + d.length;
|
|
4372
|
-
const out = new Uint8Array(size);
|
|
4373
|
-
out.set(SIGNATURE, 0);
|
|
4374
|
-
let p = 8;
|
|
4375
|
-
for (const [type, d] of chunks) {
|
|
4376
|
-
writeU32(out, p, d.length);
|
|
4377
|
-
for (let i = 0; i < 4; i++) out[p + 4 + i] = type.charCodeAt(i);
|
|
4378
|
-
out.set(d, p + 8);
|
|
4379
|
-
writeU32(out, p + 8 + d.length, crc32(out, p + 4, p + 8 + d.length));
|
|
4380
|
-
p += 12 + d.length;
|
|
4381
|
-
}
|
|
4382
|
-
return out;
|
|
4383
|
-
}
|
|
4384
|
-
function writeU32(b, o, v) {
|
|
4385
|
-
b[o] = v >>> 24;
|
|
4386
|
-
b[o + 1] = v >>> 16 & 255;
|
|
4387
|
-
b[o + 2] = v >>> 8 & 255;
|
|
4388
|
-
b[o + 3] = v & 255;
|
|
4389
|
-
}
|
|
4390
|
-
function readU32(b, o) {
|
|
4391
|
-
return (b[o] << 24 | b[o + 1] << 16 | b[o + 2] << 8 | b[o + 3]) >>> 0;
|
|
4392
|
-
}
|
|
4393
|
-
function isPng(bytes) {
|
|
4394
|
-
return bytes.length > 8 && SIGNATURE.every((v, i) => bytes[i] === v);
|
|
4395
|
-
}
|
|
4396
|
-
function decodePng(bytes, options = {}) {
|
|
4397
|
-
if (!isPng(bytes)) throw new Error("Not a PNG image.");
|
|
4398
|
-
let p = 8;
|
|
4399
|
-
let width = 0;
|
|
4400
|
-
let height = 0;
|
|
4401
|
-
let depth = 0;
|
|
4402
|
-
let type = 0;
|
|
4403
|
-
let interlace = 0;
|
|
4404
|
-
let palette = null;
|
|
4405
|
-
let trns = null;
|
|
4406
|
-
const idat = [];
|
|
4407
|
-
while (p + 8 <= bytes.length) {
|
|
4408
|
-
const len = readU32(bytes, p);
|
|
4409
|
-
const t = String.fromCharCode(bytes[p + 4], bytes[p + 5], bytes[p + 6], bytes[p + 7]);
|
|
4410
|
-
const body = bytes.subarray(p + 8, p + 8 + len);
|
|
4411
|
-
if (p + 12 + len > bytes.length) throw new Error("Truncated PNG.");
|
|
4412
|
-
if (t === "IHDR") {
|
|
4413
|
-
width = readU32(body, 0);
|
|
4414
|
-
height = readU32(body, 4);
|
|
4415
|
-
depth = body[8];
|
|
4416
|
-
type = body[9];
|
|
4417
|
-
interlace = body[12];
|
|
4418
|
-
} else if (t === "PLTE") palette = body;
|
|
4419
|
-
else if (t === "tRNS") trns = body;
|
|
4420
|
-
else if (t === "IDAT") idat.push(body);
|
|
4421
|
-
else if (t === "IEND") break;
|
|
4422
|
-
p += 12 + len;
|
|
4423
|
-
}
|
|
4424
|
-
if (!width || !height) throw new Error("PNG has no image header.");
|
|
4425
|
-
if (interlace) throw new Error("Interlaced PNGs are not supported here; decode them with a canvas.");
|
|
4426
|
-
const maxPixels = options.maxPixels ?? 1 << 28;
|
|
4427
|
-
if (width * height > maxPixels) throw new Error(`PNG is too large (${width}\xD7${height}).`);
|
|
4428
|
-
const samples = type === 0 ? 1 : type === 2 ? 3 : type === 3 ? 1 : type === 4 ? 2 : type === 6 ? 4 : 0;
|
|
4429
|
-
if (!samples || ![1, 2, 4, 8, 16].includes(depth)) throw new Error(`Unsupported PNG format (type ${type}, depth ${depth}).`);
|
|
4430
|
-
let total = 0;
|
|
4431
|
-
for (const c of idat) total += c.length;
|
|
4432
|
-
const z = new Uint8Array(total);
|
|
4433
|
-
let o = 0;
|
|
4434
|
-
for (const c of idat) {
|
|
4435
|
-
z.set(c, o);
|
|
4436
|
-
o += c.length;
|
|
4437
|
-
}
|
|
4438
|
-
const bitsPerPixel = samples * depth;
|
|
4439
|
-
const stride = Math.ceil(width * bitsPerPixel / 8);
|
|
4440
|
-
const raw = inflate(z, { maxOutput: (stride + 1) * height, sizeHint: (stride + 1) * height });
|
|
4441
|
-
if (raw.length < (stride + 1) * height) throw new Error("PNG image data is truncated.");
|
|
4442
|
-
const bpp = Math.max(1, bitsPerPixel >> 3);
|
|
4443
|
-
const lines = new Uint8Array(stride * height);
|
|
4444
|
-
for (let y = 0; y < height; y++) {
|
|
4445
|
-
const f = raw[y * (stride + 1)];
|
|
4446
|
-
const src = y * (stride + 1) + 1;
|
|
4447
|
-
const dst = y * stride;
|
|
4448
|
-
const up = dst - stride;
|
|
4449
|
-
for (let x = 0; x < stride; x++) {
|
|
4450
|
-
const v = raw[src + x];
|
|
4451
|
-
const a = x >= bpp ? lines[dst + x - bpp] : 0;
|
|
4452
|
-
const b = y > 0 ? lines[up + x] : 0;
|
|
4453
|
-
const c = x >= bpp && y > 0 ? lines[up + x - bpp] : 0;
|
|
4454
|
-
let r;
|
|
4455
|
-
switch (f) {
|
|
4456
|
-
case 0:
|
|
4457
|
-
r = v;
|
|
4458
|
-
break;
|
|
4459
|
-
case 1:
|
|
4460
|
-
r = v + a;
|
|
4461
|
-
break;
|
|
4462
|
-
case 2:
|
|
4463
|
-
r = v + b;
|
|
4464
|
-
break;
|
|
4465
|
-
case 3:
|
|
4466
|
-
r = v + (a + b >> 1);
|
|
4467
|
-
break;
|
|
4468
|
-
case 4:
|
|
4469
|
-
r = v + paeth(a, b, c);
|
|
4470
|
-
break;
|
|
4471
|
-
default:
|
|
4472
|
-
throw new Error(`Invalid PNG filter ${f}.`);
|
|
4473
|
-
}
|
|
4474
|
-
lines[dst + x] = r & 255;
|
|
4475
|
-
}
|
|
4476
|
-
}
|
|
4477
|
-
const sample2 = (y, i) => {
|
|
4478
|
-
const row = y * stride;
|
|
4479
|
-
if (depth === 8) return lines[row + i];
|
|
4480
|
-
if (depth === 16) return lines[row + i * 2];
|
|
4481
|
-
const perByte = 8 / depth;
|
|
4482
|
-
const byte = lines[row + Math.floor(i / perByte)];
|
|
4483
|
-
const shift = 8 - depth * (i % perByte + 1);
|
|
4484
|
-
const v = byte >> shift & (1 << depth) - 1;
|
|
4485
|
-
return type === 3 ? v : Math.round(v * 255 / ((1 << depth) - 1));
|
|
4486
|
-
};
|
|
4487
|
-
const gray = options.keepGray && type === 0 && !trns;
|
|
4488
|
-
const channels = gray ? 1 : 4;
|
|
4489
|
-
const out = new Uint8ClampedArray(width * height * channels);
|
|
4490
|
-
const trnsGray = trns && type === 0 ? depth === 16 ? trns[0] : sample16(trns, 0, depth) : -1;
|
|
4491
|
-
const trnsRgb = trns && type === 2 ? [0, 1, 2].map((k) => depth === 16 ? trns[k * 2] : sample16(trns, k, depth)) : null;
|
|
4492
|
-
for (let y = 0; y < height; y++) {
|
|
4493
|
-
for (let x = 0; x < width; x++) {
|
|
4494
|
-
const d = (y * width + x) * channels;
|
|
4495
|
-
if (type === 0) {
|
|
4496
|
-
const v = sample2(y, x);
|
|
4497
|
-
if (gray) out[d] = v;
|
|
4498
|
-
else {
|
|
4499
|
-
out[d] = out[d + 1] = out[d + 2] = v;
|
|
4500
|
-
out[d + 3] = v === trnsGray && trns ? 0 : 255;
|
|
4501
|
-
}
|
|
4502
|
-
} else if (type === 2) {
|
|
4503
|
-
const r = sample2(y, x * 3);
|
|
4504
|
-
const g = sample2(y, x * 3 + 1);
|
|
4505
|
-
const b = sample2(y, x * 3 + 2);
|
|
4506
|
-
out[d] = r;
|
|
4507
|
-
out[d + 1] = g;
|
|
4508
|
-
out[d + 2] = b;
|
|
4509
|
-
out[d + 3] = trnsRgb && r === trnsRgb[0] && g === trnsRgb[1] && b === trnsRgb[2] ? 0 : 255;
|
|
4510
|
-
} else if (type === 3) {
|
|
4511
|
-
const i = sample2(y, x);
|
|
4512
|
-
if (!palette || i * 3 + 2 >= palette.length) throw new Error("PNG palette index out of range.");
|
|
4513
|
-
out[d] = palette[i * 3];
|
|
4514
|
-
out[d + 1] = palette[i * 3 + 1];
|
|
4515
|
-
out[d + 2] = palette[i * 3 + 2];
|
|
4516
|
-
out[d + 3] = trns && i < trns.length ? trns[i] : 255;
|
|
4517
|
-
} else if (type === 4) {
|
|
4518
|
-
const v = sample2(y, x * 2);
|
|
4519
|
-
out[d] = out[d + 1] = out[d + 2] = v;
|
|
4520
|
-
out[d + 3] = sample2(y, x * 2 + 1);
|
|
4521
|
-
} else {
|
|
4522
|
-
out[d] = sample2(y, x * 4);
|
|
4523
|
-
out[d + 1] = sample2(y, x * 4 + 1);
|
|
4524
|
-
out[d + 2] = sample2(y, x * 4 + 2);
|
|
4525
|
-
out[d + 3] = sample2(y, x * 4 + 3);
|
|
4526
|
-
}
|
|
4527
|
-
}
|
|
4528
|
-
}
|
|
4529
|
-
return { width, height, channels, data: out };
|
|
4530
|
-
}
|
|
4531
|
-
function sample16(trns, k, depth) {
|
|
4532
|
-
const v = trns[k * 2] << 8 | trns[k * 2 + 1];
|
|
4533
|
-
if (depth === 8) return v & 255;
|
|
4534
|
-
return Math.round((v & (1 << depth) - 1) * 255 / ((1 << depth) - 1));
|
|
4535
|
-
}
|
|
4536
|
-
var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4537
|
-
var B64_INV = null;
|
|
4538
|
-
function bytesToBase64(bytes) {
|
|
4539
|
-
const parts = [];
|
|
4540
|
-
const CHUNK = 3 * 4096;
|
|
4541
|
-
for (let start = 0; start < bytes.length; start += CHUNK) {
|
|
4542
|
-
const end = Math.min(bytes.length, start + CHUNK);
|
|
4543
|
-
let s = "";
|
|
4544
|
-
let i = start;
|
|
4545
|
-
for (; i + 2 < end; i += 3) {
|
|
4546
|
-
const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
|
|
4547
|
-
s += B64[n >> 18] + B64[n >> 12 & 63] + B64[n >> 6 & 63] + B64[n & 63];
|
|
4548
|
-
}
|
|
4549
|
-
if (i < end) {
|
|
4550
|
-
const n = bytes[i] << 16 | (i + 1 < end ? bytes[i + 1] << 8 : 0);
|
|
4551
|
-
s += B64[n >> 18] + B64[n >> 12 & 63] + (i + 1 < end ? B64[n >> 6 & 63] : "=") + "=";
|
|
4552
|
-
}
|
|
4553
|
-
parts.push(s);
|
|
4554
|
-
}
|
|
4555
|
-
return parts.join("");
|
|
4556
|
-
}
|
|
4557
|
-
function base64ToBytes(text) {
|
|
4558
|
-
if (!B64_INV) {
|
|
4559
|
-
B64_INV = new Int16Array(128).fill(-1);
|
|
4560
|
-
for (let i = 0; i < 64; i++) B64_INV[B64.charCodeAt(i)] = i;
|
|
4561
|
-
B64_INV["-".charCodeAt(0)] = 62;
|
|
4562
|
-
B64_INV["_".charCodeAt(0)] = 63;
|
|
4563
|
-
}
|
|
4564
|
-
const inv = B64_INV;
|
|
4565
|
-
const clean = text.replace(/[\s=]/g, "");
|
|
4566
|
-
const out = new Uint8Array(Math.floor(clean.length * 3 / 4));
|
|
4567
|
-
let bits = 0;
|
|
4568
|
-
let acc = 0;
|
|
4569
|
-
let o = 0;
|
|
4570
|
-
for (let i = 0; i < clean.length; i++) {
|
|
4571
|
-
const c = clean.charCodeAt(i);
|
|
4572
|
-
const v = c < 128 ? inv[c] : -1;
|
|
4573
|
-
if (v < 0) throw new Error("Invalid base64 data.");
|
|
4574
|
-
acc = acc << 6 | v;
|
|
4575
|
-
bits += 6;
|
|
4576
|
-
if (bits >= 8) {
|
|
4577
|
-
bits -= 8;
|
|
4578
|
-
out[o++] = acc >> bits & 255;
|
|
4579
|
-
}
|
|
4580
|
-
}
|
|
4581
|
-
return out.subarray(0, o);
|
|
4582
|
-
}
|
|
4583
|
-
function parseDataUrl(url) {
|
|
4584
|
-
const m = /^data:([^;,]*)((?:;[^;,]*)*?),/i.exec(url);
|
|
4585
|
-
if (!m) return null;
|
|
4586
|
-
const body = url.slice(m[0].length);
|
|
4587
|
-
const isBase64 = /;base64/i.test(m[2]);
|
|
4588
|
-
if (isBase64) return { mime: m[1] || "text/plain", bytes: base64ToBytes(body) };
|
|
4589
|
-
const text = decodeURIComponent(body);
|
|
4590
|
-
const bytes = new Uint8Array(text.length);
|
|
4591
|
-
for (let i = 0; i < text.length; i++) bytes[i] = text.charCodeAt(i) & 255;
|
|
4592
|
-
return { mime: m[1] || "text/plain", bytes };
|
|
4593
|
-
}
|
|
4594
|
-
function pngDataUrl(width, height, data, channels = 4) {
|
|
4595
|
-
return `data:image/png;base64,${bytesToBase64(encodePng(width, height, data, channels))}`;
|
|
4596
|
-
}
|
|
4597
|
-
|
|
4598
4125
|
export {
|
|
4599
|
-
BIT_DEPTHS,
|
|
4600
|
-
isBitDepth,
|
|
4601
|
-
srgbDecode,
|
|
4602
|
-
srgbEncode,
|
|
4603
|
-
to16From8,
|
|
4604
|
-
to32From8,
|
|
4605
|
-
to32From16,
|
|
4606
|
-
to16From32,
|
|
4607
|
-
to8From16,
|
|
4608
|
-
to8From32,
|
|
4609
|
-
proxyOf,
|
|
4610
|
-
depthOf,
|
|
4611
|
-
deepTile,
|
|
4612
|
-
tileSamples16,
|
|
4613
|
-
tileSamples32,
|
|
4614
|
-
tileSamples,
|
|
4615
|
-
surfaceDepth,
|
|
4616
|
-
readDeepRegion,
|
|
4617
|
-
writeDeepRegion,
|
|
4618
|
-
surfaceFromDeepPixels,
|
|
4619
|
-
convertSurfaceDepth,
|
|
4620
|
-
deepBytes,
|
|
4621
4126
|
DEFAULT_GLOBAL_LIGHT,
|
|
4622
4127
|
LAYER_EFFECT_KINDS,
|
|
4623
4128
|
layerEffectLabel,
|
|
@@ -4679,13 +4184,6 @@ export {
|
|
|
4679
4184
|
transformedBounds,
|
|
4680
4185
|
transformSurface,
|
|
4681
4186
|
warpSurface,
|
|
4682
|
-
compositeSurfaceOver
|
|
4683
|
-
encodePng,
|
|
4684
|
-
isPng,
|
|
4685
|
-
decodePng,
|
|
4686
|
-
bytesToBase64,
|
|
4687
|
-
base64ToBytes,
|
|
4688
|
-
parseDataUrl,
|
|
4689
|
-
pngDataUrl
|
|
4187
|
+
compositeSurfaceOver
|
|
4690
4188
|
};
|
|
4691
|
-
//# sourceMappingURL=chunk-
|
|
4189
|
+
//# sourceMappingURL=chunk-VD2UDVF7.js.map
|