imagescript 1.2.9 → 1.2.16
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/ImageScript.d.ts +223 -0
- package/ImageScript.js +1646 -1682
- package/LICENSE +619 -0
- package/README.md +46 -45
- package/bench/_.mjs +166 -0
- package/bench/all.mjs +4 -0
- package/bench/blur.mjs +59 -0
- package/bench/flip.mjs +63 -0
- package/bench/overlay.mjs +35 -0
- package/bench/package.json +7 -0
- package/bench/readme.md +64 -0
- package/bench/resize.mjs +52 -0
- package/codecs/LICENSE +21 -0
- package/codecs/lib.d.ts +50 -0
- package/codecs/lib.js +6 -0
- package/codecs/lib.mjs +1 -0
- package/codecs/node/bin/arm64-darwin.node +0 -0
- package/{node → codecs/node/bin}/arm64-linux.node +0 -0
- package/codecs/node/bin/x64-darwin.node +0 -0
- package/{node → codecs/node/bin}/x64-linux.node +0 -0
- package/{node → codecs/node/bin}/x64-win32.node +0 -0
- package/codecs/node/index.js +3 -0
- package/codecs/node/index.mjs +6 -0
- package/codecs/package.json +14 -0
- package/codecs/readme.md +38 -0
- package/{wasm/simd.wasm → codecs/tests/gif.js} +0 -0
- package/{wasm/unknown.wasm → codecs/tests/jpeg.js} +0 -0
- package/codecs/tests/png.js +0 -0
- package/codecs/tests/results/gif/1024.nis.gif +0 -0
- package/codecs/tests/results/gif/1024.skyra.gif +0 -0
- package/codecs/tests/results/gif/256.nis.gif +0 -0
- package/codecs/tests/results/gif/256.skyra.gif +0 -0
- package/codecs/tests/results/jpeg/256.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/256.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/256.sharp.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.sharp.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.sharp.jpeg +0 -0
- package/codecs/tests/results/png/256.jis.png +0 -0
- package/codecs/tests/results/png/256.nis.png +0 -0
- package/codecs/tests/results/png/256.sharp.png +0 -0
- package/codecs/tests/results/png/256.upng.png +0 -0
- package/codecs/tests/results/png/512.jis.png +0 -0
- package/codecs/tests/results/png/512.nis.png +0 -0
- package/codecs/tests/results/png/512.sharp.png +0 -0
- package/codecs/tests/results/png/512.upng.png +0 -0
- package/codecs/tests/results/png/64.jis.png +0 -0
- package/codecs/tests/results/png/64.nis.png +0 -0
- package/codecs/tests/results/png/64.sharp.png +0 -0
- package/codecs/tests/results/png/64.upng.png +0 -0
- package/codecs/tests/webp.js +0 -0
- package/codecs/wasm/bin/codecs.wasm +0 -0
- package/codecs/wasm/bin/simd.wasm +0 -0
- package/codecs/wasm/bundle/browser.js +1 -0
- package/codecs/wasm/index.js +1 -0
- package/codecs/wasm/index.mjs +1 -0
- package/package.json +41 -28
- package/png/node.js +1137 -1137
- package/png/src/{crc.js → crc.mjs} +48 -48
- package/png/src/{mem.js → mem.mjs} +23 -23
- package/png/src/{png.js → png.mjs} +254 -254
- package/png/src/{zlib.js → zlib.mjs} +617 -617
- package/tsconfig.json +21 -0
- package/utils/mem.js +25 -25
- package/v2/codecs/magic.js +24 -24
- package/v2/framebuffer.d.ts +66 -66
- package/v2/framebuffer.js +2352 -2371
- package/v2/framebuffer.mjs +125 -125
- package/v2/framebuffer.rs +1264 -0
- package/v2/index.d.ts +83 -83
- package/v2/index.js +260 -260
- package/v2/ops/{blur.js → blur.mjs} +302 -302
- package/v2/ops/{color.js → color.mjs} +276 -276
- package/v2/ops/{crop.js → crop.mjs} +63 -63
- package/v2/ops/{fill.js → fill.mjs} +32 -32
- package/v2/ops/{flip.js → flip.mjs} +32 -32
- package/v2/ops/index.mjs +9 -0
- package/v2/ops/{iterator.js → iterator.mjs} +33 -33
- package/v2/ops/overlay.mjs +63 -0
- package/v2/ops/{resize.js → resize.mjs} +165 -165
- package/v2/ops/{rotate.js → rotate.mjs} +116 -117
- package/v2/util/{mem.js → mem.mjs} +24 -26
- package/wasm/any/font.wasm +0 -0
- package/wasm/any/png.wasm +0 -0
- package/wasm/node/font.js +141 -141
- package/wasm/node/gif.js +76 -76
- package/wasm/node/jpeg.js +91 -91
- package/wasm/node/png.js +49 -0
- package/wasm/node/svg.js +55 -55
- package/wasm/node/tiff.js +46 -46
- package/node/arm64-darwin.node +0 -0
- package/node/index.js +0 -7
- package/node/x64-darwin.node +0 -0
- package/v2/ops/index.js +0 -9
- package/v2/ops/overlay.js +0 -56
- package/wasm/node.js +0 -23
- package/wasm/web.js +0 -10
|
@@ -1,303 +1,303 @@
|
|
|
1
|
-
export function cubic(framebuffer) {
|
|
2
|
-
const width = framebuffer.width;
|
|
3
|
-
const height = framebuffer.height;
|
|
4
|
-
framebuffer.resize('cubic', Math.max(1, .008 * width), Math.max(1, .008 * height));
|
|
5
|
-
|
|
6
|
-
framebuffer.resize('cubic', width, height);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function box(radius, framebuffer) {
|
|
10
|
-
if (!radius) return;
|
|
11
|
-
const u8 = framebuffer.u8;
|
|
12
|
-
const width = framebuffer.width;
|
|
13
|
-
const height = framebuffer.height;
|
|
14
|
-
const old = framebuffer.u8.slice();
|
|
15
|
-
bb(u8, old, width, height, radius);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function gaussian(radius, framebuffer) {
|
|
19
|
-
if (0 >= radius) return;
|
|
20
|
-
const a = Math.exp(.726 ** 2) / radius;
|
|
21
|
-
|
|
22
|
-
const g1 = Math.exp(-a);
|
|
23
|
-
const g2 = Math.exp(a * -2);
|
|
24
|
-
const old = framebuffer.u8.slice();
|
|
25
|
-
const k = ((1 - g1) ** 2) / (1 - g2 + 2 * a * g1);
|
|
26
|
-
|
|
27
|
-
const b2 = -g2;
|
|
28
|
-
const b1 = 2 * g1;
|
|
29
|
-
const a3 = -k * g2;
|
|
30
|
-
const a1 = k * g1 * (a - 1);
|
|
31
|
-
const a2 = k * g1 * (a + 1);
|
|
32
|
-
const lc = (k + a1) / (1 - b1 - b2);
|
|
33
|
-
const width = framebuffer.width | 0;
|
|
34
|
-
const rc = (a2 + a3) / (1 - b1 - b2);
|
|
35
|
-
const height = framebuffer.height | 0;
|
|
36
|
-
const tmp = new Float32Array(4 * Math.max(width, height));
|
|
37
|
-
gc(old, framebuffer.u8, tmp, width, height, k, a1, a2, a3, b1, b2, lc, rc);
|
|
38
|
-
gc(framebuffer.u8, old, tmp, height, width, k, a1, a2, a3, b1, b2, lc, rc);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function bb(u8, old, width, height, radius) {
|
|
42
|
-
const divisor = 1 / (1 + radius + radius);
|
|
43
|
-
bbt(u8, old, width, height, radius, divisor);
|
|
44
|
-
bbh(u8, old, width, height, radius, divisor);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function bbh(u8, old, width, height, radius, divisor) {
|
|
48
|
-
for (var y = 0; y < height; y++) {
|
|
49
|
-
let y_offset = y * width;
|
|
50
|
-
|
|
51
|
-
let li = y_offset;
|
|
52
|
-
let ri = radius + y_offset;
|
|
53
|
-
const fv_offset = 4 * y_offset;
|
|
54
|
-
const lv_offset = 4 * (width - 1 + y_offset);
|
|
55
|
-
|
|
56
|
-
const rfv = old[fv_offset];
|
|
57
|
-
const gfv = old[1 + fv_offset];
|
|
58
|
-
const bfv = old[2 + fv_offset];
|
|
59
|
-
const afv = old[3 + fv_offset];
|
|
60
|
-
|
|
61
|
-
const rlv = old[lv_offset];
|
|
62
|
-
const glv = old[1 + lv_offset];
|
|
63
|
-
const blv = old[2 + lv_offset];
|
|
64
|
-
const alv = old[3 + lv_offset];
|
|
65
|
-
|
|
66
|
-
let r = rfv * (1 + radius);
|
|
67
|
-
let g = gfv * (1 + radius);
|
|
68
|
-
let b = bfv * (1 + radius);
|
|
69
|
-
let a = afv * (1 + radius);
|
|
70
|
-
|
|
71
|
-
for (let x = 0; x < radius; x++) {
|
|
72
|
-
const offset = 4 * (x + y_offset);
|
|
73
|
-
|
|
74
|
-
r += old[offset];
|
|
75
|
-
g += old[1 + offset];
|
|
76
|
-
b += old[2 + offset];
|
|
77
|
-
a += old[3 + offset];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (let x = 0; x <= radius; x++) {
|
|
81
|
-
let offset = 4 * ri++;
|
|
82
|
-
r += old[offset] - rfv;
|
|
83
|
-
g += old[1 + offset] - gfv;
|
|
84
|
-
b += old[2 + offset] - bfv;
|
|
85
|
-
a += old[3 + offset] - afv;
|
|
86
|
-
|
|
87
|
-
offset = 4 * y_offset++;
|
|
88
|
-
u8[offset] = Math.round(r * divisor);
|
|
89
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
90
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
91
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for (let x = 1 + radius; x < (width - radius); x++) {
|
|
95
|
-
let offset = 4 * ri++;
|
|
96
|
-
const roffset = 4 * li++;
|
|
97
|
-
r += old[offset] - old[roffset];
|
|
98
|
-
g += old[1 + offset] - old[1 + roffset];
|
|
99
|
-
b += old[2 + offset] - old[2 + roffset];
|
|
100
|
-
a += old[3 + offset] - old[3 + roffset];
|
|
101
|
-
// todo: how far is roffset
|
|
102
|
-
|
|
103
|
-
offset = 4 * y_offset++;
|
|
104
|
-
u8[offset] = Math.round(r * divisor);
|
|
105
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
106
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
107
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (let x = width - radius; x < width; x++) {
|
|
111
|
-
let offset = 4 * li++;
|
|
112
|
-
r += rlv - old[offset];
|
|
113
|
-
g += glv - old[1 + offset];
|
|
114
|
-
b += blv - old[2 + offset];
|
|
115
|
-
a += alv - old[3 + offset];
|
|
116
|
-
|
|
117
|
-
offset = 4 * y_offset++;
|
|
118
|
-
u8[offset] = Math.round(r * divisor);
|
|
119
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
120
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
121
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function bbt(u8, old, width, height, radius, divisor) {
|
|
127
|
-
for (var x = 0; x < width; x++) {
|
|
128
|
-
let ti = x;
|
|
129
|
-
let li = ti;
|
|
130
|
-
const fv_offset = 4 * ti;
|
|
131
|
-
let ri = ti + width * radius;
|
|
132
|
-
const lv_offset = 4 * (ti + width * (height - 1));
|
|
133
|
-
|
|
134
|
-
const rfv = old[fv_offset];
|
|
135
|
-
const gfv = old[1 + fv_offset];
|
|
136
|
-
const bfv = old[2 + fv_offset];
|
|
137
|
-
const afv = old[3 + fv_offset];
|
|
138
|
-
|
|
139
|
-
const rlv = old[lv_offset];
|
|
140
|
-
const glv = old[1 + lv_offset];
|
|
141
|
-
const blv = old[2 + lv_offset];
|
|
142
|
-
const alv = old[3 + lv_offset];
|
|
143
|
-
|
|
144
|
-
let r = rfv * (1 + radius);
|
|
145
|
-
let g = gfv * (1 + radius);
|
|
146
|
-
let b = bfv * (1 + radius);
|
|
147
|
-
let a = afv * (1 + radius);
|
|
148
|
-
|
|
149
|
-
for (let y = 0; y < radius; y++) {
|
|
150
|
-
const offset = 4 * (ti + y * width);
|
|
151
|
-
|
|
152
|
-
r += old[offset];
|
|
153
|
-
g += old[1 + offset];
|
|
154
|
-
b += old[2 + offset];
|
|
155
|
-
a += old[3 + offset];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
for (let y = 0; y <= radius; y++) {
|
|
159
|
-
let offset = 4 * ri;
|
|
160
|
-
r += old[offset] - rfv;
|
|
161
|
-
g += old[1 + offset] - gfv;
|
|
162
|
-
b += old[2 + offset] - bfv;
|
|
163
|
-
a += old[3 + offset] - afv;
|
|
164
|
-
|
|
165
|
-
offset = 4 * ti;
|
|
166
|
-
u8[offset] = Math.round(r * divisor);
|
|
167
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
168
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
169
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
170
|
-
|
|
171
|
-
ri += width;
|
|
172
|
-
ti += width;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
for (let y = 1 + radius; y < (height - radius); y++) {
|
|
176
|
-
let offset = 4 * ri;
|
|
177
|
-
const xoffset = 4 * li;
|
|
178
|
-
r += old[offset] - old[xoffset];
|
|
179
|
-
g += old[1 + offset] - old[1 + xoffset];
|
|
180
|
-
b += old[2 + offset] - old[2 + xoffset];
|
|
181
|
-
a += old[3 + offset] - old[3 + xoffset];
|
|
182
|
-
// todo: how far is xoffset
|
|
183
|
-
|
|
184
|
-
offset = 4 * ti;
|
|
185
|
-
u8[offset] = Math.round(r * divisor);
|
|
186
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
187
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
188
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
189
|
-
|
|
190
|
-
li += width;
|
|
191
|
-
ri += width;
|
|
192
|
-
ti += width;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
for (let y = height - radius; y < height; y++) {
|
|
196
|
-
let offset = 4 * li;
|
|
197
|
-
r += rlv - old[offset];
|
|
198
|
-
g += glv - old[1 + offset];
|
|
199
|
-
b += blv - old[2 + offset];
|
|
200
|
-
a += alv - old[3 + offset];
|
|
201
|
-
|
|
202
|
-
offset = 4 * ti;
|
|
203
|
-
u8[offset] = Math.round(r * divisor);
|
|
204
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
205
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
206
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
207
|
-
|
|
208
|
-
li += width;
|
|
209
|
-
ti += width;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function gc(u8, old, tmp, width, height, k, a1, a2, a3, b1, b2, lc, rc) {
|
|
215
|
-
const width4 = width * 4;
|
|
216
|
-
const height4 = height * 4;
|
|
217
|
-
const hw1 = height * (width - 1);
|
|
218
|
-
|
|
219
|
-
for (let y = 0; y < height; y++) {
|
|
220
|
-
let toffset = 0 | 0;
|
|
221
|
-
let ooffset = (y * width4) | 0;
|
|
222
|
-
let offset = (4 * (y + hw1)) | 0;
|
|
223
|
-
|
|
224
|
-
let por = old[ooffset];
|
|
225
|
-
let pog = old[1 + ooffset];
|
|
226
|
-
let pob = old[2 + ooffset];
|
|
227
|
-
let poa = old[3 + ooffset];
|
|
228
|
-
|
|
229
|
-
let pur = lc * por;
|
|
230
|
-
let pug = lc * pog;
|
|
231
|
-
let pub = lc * pob;
|
|
232
|
-
let pua = lc * poa;
|
|
233
|
-
|
|
234
|
-
let ppur = pur;
|
|
235
|
-
let ppug = pug;
|
|
236
|
-
let ppub = pub;
|
|
237
|
-
let ppua = pua;
|
|
238
|
-
|
|
239
|
-
for (let x = 0; x < width; x++) {
|
|
240
|
-
const cor = old[ooffset++];
|
|
241
|
-
const cog = old[ooffset++];
|
|
242
|
-
const cob = old[ooffset++];
|
|
243
|
-
const coa = old[ooffset++];
|
|
244
|
-
|
|
245
|
-
const cur = k * cor + a1 * por + b1 * pur + b2 * ppur;
|
|
246
|
-
const cug = k * cog + a1 * pog + b1 * pug + b2 * ppug;
|
|
247
|
-
const cub = k * cob + a1 * pob + b1 * pub + b2 * ppub;
|
|
248
|
-
const cua = k * coa + a1 * poa + b1 * pua + b2 * ppua;
|
|
249
|
-
|
|
250
|
-
ppur = pur; pur = cur; por = cor;
|
|
251
|
-
ppug = pug; pug = cug; pog = cog;
|
|
252
|
-
ppub = pub; pub = cub; pob = cob;
|
|
253
|
-
ppua = pua; pua = cua; poa = coa;
|
|
254
|
-
|
|
255
|
-
tmp[toffset++] = pur;
|
|
256
|
-
tmp[toffset++] = pug;
|
|
257
|
-
tmp[toffset++] = pub;
|
|
258
|
-
tmp[toffset++] = pua;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
ooffset -= 4;
|
|
262
|
-
toffset -= 4;
|
|
263
|
-
ppur = rc * (por = old[ooffset]);
|
|
264
|
-
ppug = rc * (pog = old[1 + ooffset]);
|
|
265
|
-
ppub = rc * (pob = old[2 + ooffset]);
|
|
266
|
-
ppua = rc * (poa = old[3 + ooffset]);
|
|
267
|
-
|
|
268
|
-
pur = ppur;
|
|
269
|
-
pug = ppug;
|
|
270
|
-
pub = ppub;
|
|
271
|
-
pua = ppua;
|
|
272
|
-
let cor = por;
|
|
273
|
-
let cog = pog;
|
|
274
|
-
let cob = pob;
|
|
275
|
-
let coa = poa;
|
|
276
|
-
|
|
277
|
-
for (let x = width - 1; 0 <= x; x--) {
|
|
278
|
-
const cur = a2 * cor + a3 * por + b1 * pur + b2 * ppur;
|
|
279
|
-
const cug = a2 * cog + a3 * pog + b1 * pug + b2 * ppug;
|
|
280
|
-
const cub = a2 * cob + a3 * pob + b1 * pub + b2 * ppub;
|
|
281
|
-
const cua = a2 * coa + a3 * poa + b1 * pua + b2 * ppua;
|
|
282
|
-
|
|
283
|
-
ppur = pur; pur = cur; por = cor;
|
|
284
|
-
ppug = pug; pug = cug; pog = cog;
|
|
285
|
-
ppub = pub; pub = cub; pob = cob;
|
|
286
|
-
ppua = pua; pua = cua; poa = coa;
|
|
287
|
-
|
|
288
|
-
cor = old[ooffset];
|
|
289
|
-
cog = old[1 + ooffset];
|
|
290
|
-
cob = old[2 + ooffset];
|
|
291
|
-
coa = old[3 + ooffset];
|
|
292
|
-
|
|
293
|
-
u8[offset] = pur + tmp[toffset];
|
|
294
|
-
u8[1 + offset] = pug + tmp[1 + toffset];
|
|
295
|
-
u8[2 + offset] = pub + tmp[2 + toffset];
|
|
296
|
-
u8[3 + offset] = pua + tmp[3 + toffset];
|
|
297
|
-
|
|
298
|
-
ooffset -= 4;
|
|
299
|
-
toffset -= 4;
|
|
300
|
-
offset -= height4;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
1
|
+
export function cubic(framebuffer) {
|
|
2
|
+
const width = framebuffer.width;
|
|
3
|
+
const height = framebuffer.height;
|
|
4
|
+
framebuffer.resize('cubic', Math.max(1, .008 * width), Math.max(1, .008 * height));
|
|
5
|
+
|
|
6
|
+
framebuffer.resize('cubic', width, height);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function box(radius, framebuffer) {
|
|
10
|
+
if (!radius) return;
|
|
11
|
+
const u8 = framebuffer.u8;
|
|
12
|
+
const width = framebuffer.width;
|
|
13
|
+
const height = framebuffer.height;
|
|
14
|
+
const old = framebuffer.u8.slice();
|
|
15
|
+
bb(u8, old, width, height, radius);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function gaussian(radius, framebuffer) {
|
|
19
|
+
if (0 >= radius) return;
|
|
20
|
+
const a = Math.exp(.726 ** 2) / radius;
|
|
21
|
+
|
|
22
|
+
const g1 = Math.exp(-a);
|
|
23
|
+
const g2 = Math.exp(a * -2);
|
|
24
|
+
const old = framebuffer.u8.slice();
|
|
25
|
+
const k = ((1 - g1) ** 2) / (1 - g2 + 2 * a * g1);
|
|
26
|
+
|
|
27
|
+
const b2 = -g2;
|
|
28
|
+
const b1 = 2 * g1;
|
|
29
|
+
const a3 = -k * g2;
|
|
30
|
+
const a1 = k * g1 * (a - 1);
|
|
31
|
+
const a2 = k * g1 * (a + 1);
|
|
32
|
+
const lc = (k + a1) / (1 - b1 - b2);
|
|
33
|
+
const width = framebuffer.width | 0;
|
|
34
|
+
const rc = (a2 + a3) / (1 - b1 - b2);
|
|
35
|
+
const height = framebuffer.height | 0;
|
|
36
|
+
const tmp = new Float32Array(4 * Math.max(width, height));
|
|
37
|
+
gc(old, framebuffer.u8, tmp, width, height, k, a1, a2, a3, b1, b2, lc, rc);
|
|
38
|
+
gc(framebuffer.u8, old, tmp, height, width, k, a1, a2, a3, b1, b2, lc, rc);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function bb(u8, old, width, height, radius) {
|
|
42
|
+
const divisor = 1 / (1 + radius + radius);
|
|
43
|
+
bbt(u8, old, width, height, radius, divisor);
|
|
44
|
+
bbh(u8, old, width, height, radius, divisor);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function bbh(u8, old, width, height, radius, divisor) {
|
|
48
|
+
for (var y = 0; y < height; y++) {
|
|
49
|
+
let y_offset = y * width;
|
|
50
|
+
|
|
51
|
+
let li = y_offset;
|
|
52
|
+
let ri = radius + y_offset;
|
|
53
|
+
const fv_offset = 4 * y_offset;
|
|
54
|
+
const lv_offset = 4 * (width - 1 + y_offset);
|
|
55
|
+
|
|
56
|
+
const rfv = old[fv_offset];
|
|
57
|
+
const gfv = old[1 + fv_offset];
|
|
58
|
+
const bfv = old[2 + fv_offset];
|
|
59
|
+
const afv = old[3 + fv_offset];
|
|
60
|
+
|
|
61
|
+
const rlv = old[lv_offset];
|
|
62
|
+
const glv = old[1 + lv_offset];
|
|
63
|
+
const blv = old[2 + lv_offset];
|
|
64
|
+
const alv = old[3 + lv_offset];
|
|
65
|
+
|
|
66
|
+
let r = rfv * (1 + radius);
|
|
67
|
+
let g = gfv * (1 + radius);
|
|
68
|
+
let b = bfv * (1 + radius);
|
|
69
|
+
let a = afv * (1 + radius);
|
|
70
|
+
|
|
71
|
+
for (let x = 0; x < radius; x++) {
|
|
72
|
+
const offset = 4 * (x + y_offset);
|
|
73
|
+
|
|
74
|
+
r += old[offset];
|
|
75
|
+
g += old[1 + offset];
|
|
76
|
+
b += old[2 + offset];
|
|
77
|
+
a += old[3 + offset];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (let x = 0; x <= radius; x++) {
|
|
81
|
+
let offset = 4 * ri++;
|
|
82
|
+
r += old[offset] - rfv;
|
|
83
|
+
g += old[1 + offset] - gfv;
|
|
84
|
+
b += old[2 + offset] - bfv;
|
|
85
|
+
a += old[3 + offset] - afv;
|
|
86
|
+
|
|
87
|
+
offset = 4 * y_offset++;
|
|
88
|
+
u8[offset] = Math.round(r * divisor);
|
|
89
|
+
u8[1 + offset] = Math.round(g * divisor);
|
|
90
|
+
u8[2 + offset] = Math.round(b * divisor);
|
|
91
|
+
u8[3 + offset] = Math.round(a * divisor);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (let x = 1 + radius; x < (width - radius); x++) {
|
|
95
|
+
let offset = 4 * ri++;
|
|
96
|
+
const roffset = 4 * li++;
|
|
97
|
+
r += old[offset] - old[roffset];
|
|
98
|
+
g += old[1 + offset] - old[1 + roffset];
|
|
99
|
+
b += old[2 + offset] - old[2 + roffset];
|
|
100
|
+
a += old[3 + offset] - old[3 + roffset];
|
|
101
|
+
// todo: how far is roffset
|
|
102
|
+
|
|
103
|
+
offset = 4 * y_offset++;
|
|
104
|
+
u8[offset] = Math.round(r * divisor);
|
|
105
|
+
u8[1 + offset] = Math.round(g * divisor);
|
|
106
|
+
u8[2 + offset] = Math.round(b * divisor);
|
|
107
|
+
u8[3 + offset] = Math.round(a * divisor);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (let x = width - radius; x < width; x++) {
|
|
111
|
+
let offset = 4 * li++;
|
|
112
|
+
r += rlv - old[offset];
|
|
113
|
+
g += glv - old[1 + offset];
|
|
114
|
+
b += blv - old[2 + offset];
|
|
115
|
+
a += alv - old[3 + offset];
|
|
116
|
+
|
|
117
|
+
offset = 4 * y_offset++;
|
|
118
|
+
u8[offset] = Math.round(r * divisor);
|
|
119
|
+
u8[1 + offset] = Math.round(g * divisor);
|
|
120
|
+
u8[2 + offset] = Math.round(b * divisor);
|
|
121
|
+
u8[3 + offset] = Math.round(a * divisor);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function bbt(u8, old, width, height, radius, divisor) {
|
|
127
|
+
for (var x = 0; x < width; x++) {
|
|
128
|
+
let ti = x;
|
|
129
|
+
let li = ti;
|
|
130
|
+
const fv_offset = 4 * ti;
|
|
131
|
+
let ri = ti + width * radius;
|
|
132
|
+
const lv_offset = 4 * (ti + width * (height - 1));
|
|
133
|
+
|
|
134
|
+
const rfv = old[fv_offset];
|
|
135
|
+
const gfv = old[1 + fv_offset];
|
|
136
|
+
const bfv = old[2 + fv_offset];
|
|
137
|
+
const afv = old[3 + fv_offset];
|
|
138
|
+
|
|
139
|
+
const rlv = old[lv_offset];
|
|
140
|
+
const glv = old[1 + lv_offset];
|
|
141
|
+
const blv = old[2 + lv_offset];
|
|
142
|
+
const alv = old[3 + lv_offset];
|
|
143
|
+
|
|
144
|
+
let r = rfv * (1 + radius);
|
|
145
|
+
let g = gfv * (1 + radius);
|
|
146
|
+
let b = bfv * (1 + radius);
|
|
147
|
+
let a = afv * (1 + radius);
|
|
148
|
+
|
|
149
|
+
for (let y = 0; y < radius; y++) {
|
|
150
|
+
const offset = 4 * (ti + y * width);
|
|
151
|
+
|
|
152
|
+
r += old[offset];
|
|
153
|
+
g += old[1 + offset];
|
|
154
|
+
b += old[2 + offset];
|
|
155
|
+
a += old[3 + offset];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (let y = 0; y <= radius; y++) {
|
|
159
|
+
let offset = 4 * ri;
|
|
160
|
+
r += old[offset] - rfv;
|
|
161
|
+
g += old[1 + offset] - gfv;
|
|
162
|
+
b += old[2 + offset] - bfv;
|
|
163
|
+
a += old[3 + offset] - afv;
|
|
164
|
+
|
|
165
|
+
offset = 4 * ti;
|
|
166
|
+
u8[offset] = Math.round(r * divisor);
|
|
167
|
+
u8[1 + offset] = Math.round(g * divisor);
|
|
168
|
+
u8[2 + offset] = Math.round(b * divisor);
|
|
169
|
+
u8[3 + offset] = Math.round(a * divisor);
|
|
170
|
+
|
|
171
|
+
ri += width;
|
|
172
|
+
ti += width;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (let y = 1 + radius; y < (height - radius); y++) {
|
|
176
|
+
let offset = 4 * ri;
|
|
177
|
+
const xoffset = 4 * li;
|
|
178
|
+
r += old[offset] - old[xoffset];
|
|
179
|
+
g += old[1 + offset] - old[1 + xoffset];
|
|
180
|
+
b += old[2 + offset] - old[2 + xoffset];
|
|
181
|
+
a += old[3 + offset] - old[3 + xoffset];
|
|
182
|
+
// todo: how far is xoffset
|
|
183
|
+
|
|
184
|
+
offset = 4 * ti;
|
|
185
|
+
u8[offset] = Math.round(r * divisor);
|
|
186
|
+
u8[1 + offset] = Math.round(g * divisor);
|
|
187
|
+
u8[2 + offset] = Math.round(b * divisor);
|
|
188
|
+
u8[3 + offset] = Math.round(a * divisor);
|
|
189
|
+
|
|
190
|
+
li += width;
|
|
191
|
+
ri += width;
|
|
192
|
+
ti += width;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (let y = height - radius; y < height; y++) {
|
|
196
|
+
let offset = 4 * li;
|
|
197
|
+
r += rlv - old[offset];
|
|
198
|
+
g += glv - old[1 + offset];
|
|
199
|
+
b += blv - old[2 + offset];
|
|
200
|
+
a += alv - old[3 + offset];
|
|
201
|
+
|
|
202
|
+
offset = 4 * ti;
|
|
203
|
+
u8[offset] = Math.round(r * divisor);
|
|
204
|
+
u8[1 + offset] = Math.round(g * divisor);
|
|
205
|
+
u8[2 + offset] = Math.round(b * divisor);
|
|
206
|
+
u8[3 + offset] = Math.round(a * divisor);
|
|
207
|
+
|
|
208
|
+
li += width;
|
|
209
|
+
ti += width;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function gc(u8, old, tmp, width, height, k, a1, a2, a3, b1, b2, lc, rc) {
|
|
215
|
+
const width4 = width * 4;
|
|
216
|
+
const height4 = height * 4;
|
|
217
|
+
const hw1 = height * (width - 1);
|
|
218
|
+
|
|
219
|
+
for (let y = 0; y < height; y++) {
|
|
220
|
+
let toffset = 0 | 0;
|
|
221
|
+
let ooffset = (y * width4) | 0;
|
|
222
|
+
let offset = (4 * (y + hw1)) | 0;
|
|
223
|
+
|
|
224
|
+
let por = old[ooffset];
|
|
225
|
+
let pog = old[1 + ooffset];
|
|
226
|
+
let pob = old[2 + ooffset];
|
|
227
|
+
let poa = old[3 + ooffset];
|
|
228
|
+
|
|
229
|
+
let pur = lc * por;
|
|
230
|
+
let pug = lc * pog;
|
|
231
|
+
let pub = lc * pob;
|
|
232
|
+
let pua = lc * poa;
|
|
233
|
+
|
|
234
|
+
let ppur = pur;
|
|
235
|
+
let ppug = pug;
|
|
236
|
+
let ppub = pub;
|
|
237
|
+
let ppua = pua;
|
|
238
|
+
|
|
239
|
+
for (let x = 0; x < width; x++) {
|
|
240
|
+
const cor = old[ooffset++];
|
|
241
|
+
const cog = old[ooffset++];
|
|
242
|
+
const cob = old[ooffset++];
|
|
243
|
+
const coa = old[ooffset++];
|
|
244
|
+
|
|
245
|
+
const cur = k * cor + a1 * por + b1 * pur + b2 * ppur;
|
|
246
|
+
const cug = k * cog + a1 * pog + b1 * pug + b2 * ppug;
|
|
247
|
+
const cub = k * cob + a1 * pob + b1 * pub + b2 * ppub;
|
|
248
|
+
const cua = k * coa + a1 * poa + b1 * pua + b2 * ppua;
|
|
249
|
+
|
|
250
|
+
ppur = pur; pur = cur; por = cor;
|
|
251
|
+
ppug = pug; pug = cug; pog = cog;
|
|
252
|
+
ppub = pub; pub = cub; pob = cob;
|
|
253
|
+
ppua = pua; pua = cua; poa = coa;
|
|
254
|
+
|
|
255
|
+
tmp[toffset++] = pur;
|
|
256
|
+
tmp[toffset++] = pug;
|
|
257
|
+
tmp[toffset++] = pub;
|
|
258
|
+
tmp[toffset++] = pua;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
ooffset -= 4;
|
|
262
|
+
toffset -= 4;
|
|
263
|
+
ppur = rc * (por = old[ooffset]);
|
|
264
|
+
ppug = rc * (pog = old[1 + ooffset]);
|
|
265
|
+
ppub = rc * (pob = old[2 + ooffset]);
|
|
266
|
+
ppua = rc * (poa = old[3 + ooffset]);
|
|
267
|
+
|
|
268
|
+
pur = ppur;
|
|
269
|
+
pug = ppug;
|
|
270
|
+
pub = ppub;
|
|
271
|
+
pua = ppua;
|
|
272
|
+
let cor = por;
|
|
273
|
+
let cog = pog;
|
|
274
|
+
let cob = pob;
|
|
275
|
+
let coa = poa;
|
|
276
|
+
|
|
277
|
+
for (let x = width - 1; 0 <= x; x--) {
|
|
278
|
+
const cur = a2 * cor + a3 * por + b1 * pur + b2 * ppur;
|
|
279
|
+
const cug = a2 * cog + a3 * pog + b1 * pug + b2 * ppug;
|
|
280
|
+
const cub = a2 * cob + a3 * pob + b1 * pub + b2 * ppub;
|
|
281
|
+
const cua = a2 * coa + a3 * poa + b1 * pua + b2 * ppua;
|
|
282
|
+
|
|
283
|
+
ppur = pur; pur = cur; por = cor;
|
|
284
|
+
ppug = pug; pug = cug; pog = cog;
|
|
285
|
+
ppub = pub; pub = cub; pob = cob;
|
|
286
|
+
ppua = pua; pua = cua; poa = coa;
|
|
287
|
+
|
|
288
|
+
cor = old[ooffset];
|
|
289
|
+
cog = old[1 + ooffset];
|
|
290
|
+
cob = old[2 + ooffset];
|
|
291
|
+
coa = old[3 + ooffset];
|
|
292
|
+
|
|
293
|
+
u8[offset] = pur + tmp[toffset];
|
|
294
|
+
u8[1 + offset] = pug + tmp[1 + toffset];
|
|
295
|
+
u8[2 + offset] = pub + tmp[2 + toffset];
|
|
296
|
+
u8[3 + offset] = pua + tmp[3 + toffset];
|
|
297
|
+
|
|
298
|
+
ooffset -= 4;
|
|
299
|
+
toffset -= 4;
|
|
300
|
+
offset -= height4;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
303
|
}
|