@vfx-js/effects 1.4.3 → 1.4.4
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/lib/cjs/ascii.js +63 -73
- package/lib/cjs/ascii.js.map +1 -1
- package/lib/cjs/bad-jpeg.js +7 -5
- package/lib/cjs/bad-jpeg.js.map +1 -1
- package/lib/cjs/bloom.js +68 -78
- package/lib/cjs/bloom.js.map +1 -1
- package/lib/cjs/chromatic.js +1 -0
- package/lib/cjs/chromatic.js.map +1 -1
- package/lib/cjs/colored-edges.js +1 -0
- package/lib/cjs/colored-edges.js.map +1 -1
- package/lib/cjs/datamosh.js +173 -183
- package/lib/cjs/datamosh.js.map +1 -1
- package/lib/cjs/dither.js +6 -3
- package/lib/cjs/dither.js.map +1 -1
- package/lib/cjs/duotone.js +4 -2
- package/lib/cjs/duotone.js.map +1 -1
- package/lib/cjs/fluid.js +62 -74
- package/lib/cjs/fluid.js.map +1 -1
- package/lib/cjs/glitch.js +1 -0
- package/lib/cjs/glitch.js.map +1 -1
- package/lib/cjs/gradient-map.js +4 -1
- package/lib/cjs/gradient-map.js.map +1 -1
- package/lib/cjs/halftone.js +3 -0
- package/lib/cjs/halftone.js.map +1 -1
- package/lib/cjs/hue-shift.js +1 -0
- package/lib/cjs/hue-shift.js.map +1 -1
- package/lib/cjs/jpeg-glitch.js +273 -277
- package/lib/cjs/jpeg-glitch.js.map +1 -1
- package/lib/cjs/light-streak.js +34 -47
- package/lib/cjs/light-streak.js.map +1 -1
- package/lib/cjs/matrix.js +48 -59
- package/lib/cjs/matrix.js.map +1 -1
- package/lib/cjs/package.json +2 -1
- package/lib/cjs/particle-explode.js +122 -128
- package/lib/cjs/particle-explode.js.map +1 -1
- package/lib/cjs/particle.js +253 -258
- package/lib/cjs/particle.js.map +1 -1
- package/lib/cjs/pattern-refraction.js +1 -0
- package/lib/cjs/pattern-refraction.js.map +1 -1
- package/lib/cjs/pixel-stretch.js +1 -0
- package/lib/cjs/pixel-stretch.js.map +1 -1
- package/lib/cjs/pixelate.js +1 -0
- package/lib/cjs/pixelate.js.map +1 -1
- package/lib/cjs/pixelsort.js +102 -121
- package/lib/cjs/pixelsort.js.map +1 -1
- package/lib/cjs/rainbow.js +1 -0
- package/lib/cjs/rainbow.js.map +1 -1
- package/lib/cjs/rgb-glitch.js +1 -0
- package/lib/cjs/rgb-glitch.js.map +1 -1
- package/lib/cjs/rgb-shift.js +1 -0
- package/lib/cjs/rgb-shift.js.map +1 -1
- package/lib/cjs/scanline.js +1 -0
- package/lib/cjs/scanline.js.map +1 -1
- package/lib/cjs/sinewave.js +1 -0
- package/lib/cjs/sinewave.js.map +1 -1
- package/lib/cjs/slice-shift.js +1 -0
- package/lib/cjs/slice-shift.js.map +1 -1
- package/lib/cjs/tile-pixelate.js +4 -1
- package/lib/cjs/tile-pixelate.js.map +1 -1
- package/lib/cjs/tritone.js +5 -2
- package/lib/cjs/tritone.js.map +1 -1
- package/lib/cjs/vignette.js +1 -0
- package/lib/cjs/vignette.js.map +1 -1
- package/lib/cjs/voronoi.js +4 -1
- package/lib/cjs/voronoi.js.map +1 -1
- package/lib/cjs/warp.js +1 -0
- package/lib/cjs/warp.js.map +1 -1
- package/lib/esm/ascii.js +63 -73
- package/lib/esm/ascii.js.map +1 -1
- package/lib/esm/bad-jpeg.js +7 -5
- package/lib/esm/bad-jpeg.js.map +1 -1
- package/lib/esm/bloom.js +67 -77
- package/lib/esm/bloom.js.map +1 -1
- package/lib/esm/chromatic.js +1 -0
- package/lib/esm/chromatic.js.map +1 -1
- package/lib/esm/colored-edges.js +1 -0
- package/lib/esm/colored-edges.js.map +1 -1
- package/lib/esm/datamosh.js +172 -182
- package/lib/esm/datamosh.js.map +1 -1
- package/lib/esm/dither.js +6 -3
- package/lib/esm/dither.js.map +1 -1
- package/lib/esm/duotone.js +4 -2
- package/lib/esm/duotone.js.map +1 -1
- package/lib/esm/fluid.js +62 -74
- package/lib/esm/fluid.js.map +1 -1
- package/lib/esm/glitch.js +1 -0
- package/lib/esm/glitch.js.map +1 -1
- package/lib/esm/gradient-map.js +4 -1
- package/lib/esm/gradient-map.js.map +1 -1
- package/lib/esm/halftone.js +3 -0
- package/lib/esm/halftone.js.map +1 -1
- package/lib/esm/hue-shift.js +1 -0
- package/lib/esm/hue-shift.js.map +1 -1
- package/lib/esm/jpeg-glitch.js +272 -276
- package/lib/esm/jpeg-glitch.js.map +1 -1
- package/lib/esm/light-streak.js +34 -47
- package/lib/esm/light-streak.js.map +1 -1
- package/lib/esm/matrix.js +48 -59
- package/lib/esm/matrix.js.map +1 -1
- package/lib/esm/package.json +2 -1
- package/lib/esm/particle-explode.js +122 -128
- package/lib/esm/particle-explode.js.map +1 -1
- package/lib/esm/particle.js +253 -258
- package/lib/esm/particle.js.map +1 -1
- package/lib/esm/pattern-refraction.js +1 -0
- package/lib/esm/pattern-refraction.js.map +1 -1
- package/lib/esm/pixel-stretch.js +1 -0
- package/lib/esm/pixel-stretch.js.map +1 -1
- package/lib/esm/pixelate.js +1 -0
- package/lib/esm/pixelate.js.map +1 -1
- package/lib/esm/pixelsort.js +102 -121
- package/lib/esm/pixelsort.js.map +1 -1
- package/lib/esm/rainbow.js +1 -0
- package/lib/esm/rainbow.js.map +1 -1
- package/lib/esm/rgb-glitch.js +1 -0
- package/lib/esm/rgb-glitch.js.map +1 -1
- package/lib/esm/rgb-shift.js +1 -0
- package/lib/esm/rgb-shift.js.map +1 -1
- package/lib/esm/scanline.js +1 -0
- package/lib/esm/scanline.js.map +1 -1
- package/lib/esm/sinewave.js +1 -0
- package/lib/esm/sinewave.js.map +1 -1
- package/lib/esm/slice-shift.js +1 -0
- package/lib/esm/slice-shift.js.map +1 -1
- package/lib/esm/tile-pixelate.js +4 -1
- package/lib/esm/tile-pixelate.js.map +1 -1
- package/lib/esm/tritone.js +5 -2
- package/lib/esm/tritone.js.map +1 -1
- package/lib/esm/vignette.js +1 -0
- package/lib/esm/vignette.js.map +1 -1
- package/lib/esm/voronoi.js +4 -1
- package/lib/esm/voronoi.js.map +1 -1
- package/lib/esm/warp.js +1 -0
- package/lib/esm/warp.js.map +1 -1
- package/package.json +4 -3
package/lib/cjs/jpeg-glitch.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var _JPEGGlitchEffect_instances, _JPEGGlitchEffect_supported, _JPEGGlitchEffect_readRT, _JPEGGlitchEffect_outTex, _JPEGGlitchEffect_gl, _JPEGGlitchEffect_outGLTex, _JPEGGlitchEffect_uploadPending, _JPEGGlitchEffect_restoreUnsub, _JPEGGlitchEffect_srcCanvas, _JPEGGlitchEffect_srcCtx, _JPEGGlitchEffect_encCanvas, _JPEGGlitchEffect_encCtx, _JPEGGlitchEffect_outCanvas, _JPEGGlitchEffect_outCtx, _JPEGGlitchEffect_raw, _JPEGGlitchEffect_imageData, _JPEGGlitchEffect_w, _JPEGGlitchEffect_h, _JPEGGlitchEffect_srcW, _JPEGGlitchEffect_srcH, _JPEGGlitchEffect_dirty, _JPEGGlitchEffect_busy, _JPEGGlitchEffect_lastGlitchTime, _JPEGGlitchEffect_generation, _JPEGGlitchEffect_glitchCount, _JPEGGlitchEffect_hasResult, _JPEGGlitchEffect_producedFrames, _JPEGGlitchEffect_createOutTexture, _JPEGGlitchEffect_passthrough, _JPEGGlitchEffect_shouldGlitch, _JPEGGlitchEffect_resize, _JPEGGlitchEffect_startGlitch, _JPEGGlitchEffect_uploadOutCanvas, _JPEGGlitchEffect_runGlitch;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.JPEGGlitchEffect = void 0;
|
|
16
4
|
const _capture_js_1 = require("./_capture.js");
|
|
17
5
|
// Passthrough of the live source to the canvas (used until the first
|
|
18
|
-
// glitch result is ready).
|
|
6
|
+
// glitch result is ready). `src` is already premultiplied.
|
|
19
7
|
const FRAG_PASSTHROUGH = `#version 300 es
|
|
20
8
|
precision highp float;
|
|
21
9
|
in vec2 uvSrc;
|
|
@@ -28,8 +16,7 @@ void main() {
|
|
|
28
16
|
outColor = vec4(0.0);
|
|
29
17
|
return;
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
outColor = vec4(c.rgb * c.a, c.a);
|
|
19
|
+
outColor = texture(src, uvSrc);
|
|
33
20
|
}
|
|
34
21
|
`;
|
|
35
22
|
// Draw the decoded glitch canvas (element-sized, upright) to the canvas.
|
|
@@ -176,109 +163,133 @@ function glitchBytes(bytes, headerLength, iterations, rng) {
|
|
|
176
163
|
* render loop. The source passes through until the first result lands.
|
|
177
164
|
*/
|
|
178
165
|
class JPEGGlitchEffect {
|
|
166
|
+
params;
|
|
167
|
+
enabled = true;
|
|
168
|
+
#supported = false;
|
|
169
|
+
#readRT = null;
|
|
170
|
+
#outTex = null;
|
|
171
|
+
// Raw GL handles for the on-demand display-texture upload.
|
|
172
|
+
#gl = null;
|
|
173
|
+
// Display texture we upload `outCanvas` into only when a new glitch
|
|
174
|
+
// lands, instead of re-uploading the canvas every frame.
|
|
175
|
+
#outGLTex = null;
|
|
176
|
+
#uploadPending = false;
|
|
177
|
+
#restoreUnsub = null;
|
|
178
|
+
#srcCanvas = null;
|
|
179
|
+
#srcCtx = null;
|
|
180
|
+
// Holds the (optionally rotated) image that actually gets encoded; its
|
|
181
|
+
// size is set per-glitch since a quarter turn swaps width and height.
|
|
182
|
+
#encCanvas = null;
|
|
183
|
+
#encCtx = null;
|
|
184
|
+
#outCanvas = null;
|
|
185
|
+
#outCtx = null;
|
|
186
|
+
#raw = new Uint8Array(0);
|
|
187
|
+
#imageData = null;
|
|
188
|
+
#w = 0;
|
|
189
|
+
#h = 0;
|
|
190
|
+
// Source native size last seen — a change (e.g. an image finishing
|
|
191
|
+
// loading) re-arms a static glitch so it doesn't latch a blank frame.
|
|
192
|
+
#srcW = 0;
|
|
193
|
+
#srcH = 0;
|
|
194
|
+
// Re-glitch when a static frame's inputs change (params / resize).
|
|
195
|
+
#dirty = true;
|
|
196
|
+
// An encode/decode round trip is in flight; gate new glitches on it.
|
|
197
|
+
#busy = false;
|
|
198
|
+
// Last glitch start time (seconds), for the `speed` throttle.
|
|
199
|
+
#lastGlitchTime = -1e9;
|
|
200
|
+
// Bumped on resize so a stale in-flight result is discarded.
|
|
201
|
+
#generation = 0;
|
|
202
|
+
// Drives the animated seed walk when `speed > 0`.
|
|
203
|
+
#glitchCount = 0;
|
|
204
|
+
#hasResult = false;
|
|
205
|
+
// Number of decoded glitch results produced. Increments once per
|
|
206
|
+
// completed encode/decode round trip — sample it to measure the real
|
|
207
|
+
// output rate, which is capped by codec latency below high `speed`.
|
|
208
|
+
#producedFrames = 0;
|
|
179
209
|
/** Count of decoded glitch results produced so far. */
|
|
180
210
|
get producedFrames() {
|
|
181
|
-
return
|
|
211
|
+
return this.#producedFrames;
|
|
182
212
|
}
|
|
183
213
|
constructor(initial = {}) {
|
|
184
|
-
_JPEGGlitchEffect_instances.add(this);
|
|
185
|
-
this.enabled = true;
|
|
186
|
-
_JPEGGlitchEffect_supported.set(this, false);
|
|
187
|
-
_JPEGGlitchEffect_readRT.set(this, null);
|
|
188
|
-
_JPEGGlitchEffect_outTex.set(this, null);
|
|
189
|
-
// Raw GL handles for the on-demand display-texture upload.
|
|
190
|
-
_JPEGGlitchEffect_gl.set(this, null);
|
|
191
|
-
// Display texture we upload `outCanvas` into only when a new glitch
|
|
192
|
-
// lands, instead of re-uploading the canvas every frame.
|
|
193
|
-
_JPEGGlitchEffect_outGLTex.set(this, null);
|
|
194
|
-
_JPEGGlitchEffect_uploadPending.set(this, false);
|
|
195
|
-
_JPEGGlitchEffect_restoreUnsub.set(this, null);
|
|
196
|
-
_JPEGGlitchEffect_srcCanvas.set(this, null);
|
|
197
|
-
_JPEGGlitchEffect_srcCtx.set(this, null);
|
|
198
|
-
// Holds the (optionally rotated) image that actually gets encoded; its
|
|
199
|
-
// size is set per-glitch since a quarter turn swaps width and height.
|
|
200
|
-
_JPEGGlitchEffect_encCanvas.set(this, null);
|
|
201
|
-
_JPEGGlitchEffect_encCtx.set(this, null);
|
|
202
|
-
_JPEGGlitchEffect_outCanvas.set(this, null);
|
|
203
|
-
_JPEGGlitchEffect_outCtx.set(this, null);
|
|
204
|
-
_JPEGGlitchEffect_raw.set(this, new Uint8Array(0));
|
|
205
|
-
_JPEGGlitchEffect_imageData.set(this, null);
|
|
206
|
-
_JPEGGlitchEffect_w.set(this, 0);
|
|
207
|
-
_JPEGGlitchEffect_h.set(this, 0);
|
|
208
|
-
// Source native size last seen — a change (e.g. an image finishing
|
|
209
|
-
// loading) re-arms a static glitch so it doesn't latch a blank frame.
|
|
210
|
-
_JPEGGlitchEffect_srcW.set(this, 0);
|
|
211
|
-
_JPEGGlitchEffect_srcH.set(this, 0);
|
|
212
|
-
// Re-glitch when a static frame's inputs change (params / resize).
|
|
213
|
-
_JPEGGlitchEffect_dirty.set(this, true);
|
|
214
|
-
// An encode/decode round trip is in flight; gate new glitches on it.
|
|
215
|
-
_JPEGGlitchEffect_busy.set(this, false);
|
|
216
|
-
// Last glitch start time (seconds), for the `speed` throttle.
|
|
217
|
-
_JPEGGlitchEffect_lastGlitchTime.set(this, -1e9);
|
|
218
|
-
// Bumped on resize so a stale in-flight result is discarded.
|
|
219
|
-
_JPEGGlitchEffect_generation.set(this, 0);
|
|
220
|
-
// Drives the animated seed walk when `speed > 0`.
|
|
221
|
-
_JPEGGlitchEffect_glitchCount.set(this, 0);
|
|
222
|
-
_JPEGGlitchEffect_hasResult.set(this, false);
|
|
223
|
-
// Number of decoded glitch results produced. Increments once per
|
|
224
|
-
// completed encode/decode round trip — sample it to measure the real
|
|
225
|
-
// output rate, which is capped by codec latency below high `speed`.
|
|
226
|
-
_JPEGGlitchEffect_producedFrames.set(this, 0);
|
|
227
214
|
this.params = { ...DEFAULT_PARAMS, ...initial };
|
|
228
215
|
}
|
|
229
216
|
setParams(updates) {
|
|
230
217
|
Object.assign(this.params, updates);
|
|
231
|
-
|
|
218
|
+
this.#dirty = true;
|
|
232
219
|
}
|
|
233
220
|
init(ctx) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
typeof
|
|
237
|
-
|
|
221
|
+
this.#supported =
|
|
222
|
+
typeof createImageBitmap === "function" &&
|
|
223
|
+
(typeof OffscreenCanvas !== "undefined" ||
|
|
224
|
+
typeof document !== "undefined");
|
|
225
|
+
if (!this.#supported) {
|
|
238
226
|
return;
|
|
239
227
|
}
|
|
240
228
|
// The element's time base restarts at 0 on each (re-)attach.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
229
|
+
this.#lastGlitchTime = -1e9;
|
|
230
|
+
this.#dirty = true;
|
|
231
|
+
this.#srcCanvas = createCanvas(1, 1);
|
|
232
|
+
this.#srcCtx = get2d(this.#srcCanvas);
|
|
233
|
+
this.#encCanvas = createCanvas(1, 1);
|
|
234
|
+
this.#encCtx = get2d(this.#encCanvas);
|
|
235
|
+
this.#outCanvas = createCanvas(1, 1);
|
|
236
|
+
this.#outCtx = get2d(this.#outCanvas);
|
|
249
237
|
// Sized to the processing resolution in #resize; start at 1×1.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
238
|
+
this.#readRT = ctx.createRenderTarget({ size: [1, 1] });
|
|
239
|
+
this.#gl = ctx.gl;
|
|
240
|
+
this.#createOutTexture(ctx);
|
|
253
241
|
// The display texture dies on context loss; rebuild it.
|
|
254
|
-
|
|
255
|
-
|
|
242
|
+
this.#restoreUnsub = ctx.onContextRestored(() => {
|
|
243
|
+
this.#createOutTexture(ctx);
|
|
256
244
|
// Re-push the last decoded frame, if any.
|
|
257
|
-
|
|
258
|
-
})
|
|
245
|
+
this.#uploadPending = this.#hasResult;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// Create (or recreate) the display texture and wrap it for sampling.
|
|
249
|
+
// We own the GL handle and upload into it manually, so context-loss
|
|
250
|
+
// rebuilds are our responsibility.
|
|
251
|
+
#createOutTexture(ctx) {
|
|
252
|
+
const gl = ctx.gl;
|
|
253
|
+
const tex = gl.createTexture();
|
|
254
|
+
if (!tex) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
258
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
259
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
260
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
261
|
+
// Nearest mag so low resolutionScale upscales crisp, not blurry.
|
|
262
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
263
|
+
// 1×1 placeholder so the sampler is valid before the first upload.
|
|
264
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
|
|
265
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
266
|
+
this.#outGLTex = tex;
|
|
267
|
+
this.#outTex = ctx.wrapTexture(tex, {
|
|
268
|
+
size: [this.#w || 1, this.#h || 1],
|
|
269
|
+
});
|
|
259
270
|
}
|
|
260
271
|
// update() runs even while disabled (the chain only skips render); drop
|
|
261
272
|
// the cached glitch so re-enabling starts clean instead of flashing it.
|
|
262
273
|
update() {
|
|
263
274
|
if (this.enabled === false) {
|
|
264
|
-
|
|
275
|
+
this.#hasResult = false;
|
|
265
276
|
}
|
|
266
277
|
}
|
|
267
278
|
render(ctx) {
|
|
268
|
-
if (this.params.bypass || !
|
|
279
|
+
if (this.params.bypass || !this.#supported || !this.#readRT) {
|
|
269
280
|
// Drop any stale decoded frame so re-enabling starts clean rather
|
|
270
281
|
// than flashing the last glitch.
|
|
271
|
-
|
|
272
|
-
|
|
282
|
+
this.#hasResult = false;
|
|
283
|
+
this.#passthrough(ctx);
|
|
273
284
|
return;
|
|
274
285
|
}
|
|
275
286
|
// Re-arm a static glitch when the source first loads / changes size.
|
|
276
287
|
const srcW = ctx.src.width;
|
|
277
288
|
const srcH = ctx.src.height;
|
|
278
|
-
if (srcW !==
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
289
|
+
if (srcW !== this.#srcW || srcH !== this.#srcH) {
|
|
290
|
+
this.#srcW = srcW;
|
|
291
|
+
this.#srcH = srcH;
|
|
292
|
+
this.#dirty = true;
|
|
282
293
|
}
|
|
283
294
|
// Process at a fraction of the element resolution. The decoded
|
|
284
295
|
// output is sampled by uvContent so it scales back up to fit.
|
|
@@ -287,216 +298,201 @@ class JPEGGlitchEffect {
|
|
|
287
298
|
const w = Math.max(1, Math.round(ew * scale));
|
|
288
299
|
const h = Math.max(1, Math.round(eh * scale));
|
|
289
300
|
if (ew >= 2 && eh >= 2 && srcW > 0 && srcH > 0) {
|
|
290
|
-
if (w !==
|
|
291
|
-
|
|
301
|
+
if (w !== this.#w || h !== this.#h) {
|
|
302
|
+
this.#resize(ctx, w, h);
|
|
292
303
|
}
|
|
293
|
-
if (
|
|
294
|
-
|
|
304
|
+
if (this.#shouldGlitch(ctx)) {
|
|
305
|
+
this.#startGlitch(ctx);
|
|
295
306
|
}
|
|
296
307
|
}
|
|
297
|
-
if (
|
|
308
|
+
if (this.#hasResult && this.#outTex) {
|
|
298
309
|
// Upload the decoded canvas to the GPU only when it changed.
|
|
299
|
-
if (
|
|
300
|
-
|
|
310
|
+
if (this.#uploadPending) {
|
|
311
|
+
this.#uploadOutCanvas(ctx);
|
|
301
312
|
}
|
|
302
313
|
ctx.draw({
|
|
303
314
|
frag: FRAG_OUTPUT,
|
|
304
|
-
uniforms: { tex:
|
|
315
|
+
uniforms: { tex: this.#outTex },
|
|
305
316
|
target: ctx.target,
|
|
306
317
|
});
|
|
307
318
|
}
|
|
308
319
|
else {
|
|
309
|
-
|
|
320
|
+
this.#passthrough(ctx);
|
|
310
321
|
}
|
|
311
322
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_outGLTex, null, "f");
|
|
320
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_gl, null, "f");
|
|
321
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_uploadPending, false, "f");
|
|
322
|
-
__classPrivateFieldGet(this, _JPEGGlitchEffect_readRT, "f")?.dispose();
|
|
323
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_readRT, null, "f");
|
|
324
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_outTex, null, "f");
|
|
325
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_srcCanvas, null, "f");
|
|
326
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_srcCtx, null, "f");
|
|
327
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_encCanvas, null, "f");
|
|
328
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_encCtx, null, "f");
|
|
329
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_outCanvas, null, "f");
|
|
330
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_outCtx, null, "f");
|
|
331
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_imageData, null, "f");
|
|
332
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_raw, new Uint8Array(0), "f");
|
|
333
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_hasResult, false, "f");
|
|
334
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_busy, false, "f");
|
|
335
|
-
// Forget the processed size so a re-init reallocates the readback RT
|
|
336
|
-
// (which dispose just freed) instead of mistaking it for current.
|
|
337
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_w, 0, "f");
|
|
338
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_h, 0, "f");
|
|
339
|
-
// Invalidate any in-flight round trip.
|
|
340
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_generation, (_a = __classPrivateFieldGet(this, _JPEGGlitchEffect_generation, "f"), _a++, _a), "f");
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
exports.JPEGGlitchEffect = JPEGGlitchEffect;
|
|
344
|
-
_JPEGGlitchEffect_supported = new WeakMap(), _JPEGGlitchEffect_readRT = new WeakMap(), _JPEGGlitchEffect_outTex = new WeakMap(), _JPEGGlitchEffect_gl = new WeakMap(), _JPEGGlitchEffect_outGLTex = new WeakMap(), _JPEGGlitchEffect_uploadPending = new WeakMap(), _JPEGGlitchEffect_restoreUnsub = new WeakMap(), _JPEGGlitchEffect_srcCanvas = new WeakMap(), _JPEGGlitchEffect_srcCtx = new WeakMap(), _JPEGGlitchEffect_encCanvas = new WeakMap(), _JPEGGlitchEffect_encCtx = new WeakMap(), _JPEGGlitchEffect_outCanvas = new WeakMap(), _JPEGGlitchEffect_outCtx = new WeakMap(), _JPEGGlitchEffect_raw = new WeakMap(), _JPEGGlitchEffect_imageData = new WeakMap(), _JPEGGlitchEffect_w = new WeakMap(), _JPEGGlitchEffect_h = new WeakMap(), _JPEGGlitchEffect_srcW = new WeakMap(), _JPEGGlitchEffect_srcH = new WeakMap(), _JPEGGlitchEffect_dirty = new WeakMap(), _JPEGGlitchEffect_busy = new WeakMap(), _JPEGGlitchEffect_lastGlitchTime = new WeakMap(), _JPEGGlitchEffect_generation = new WeakMap(), _JPEGGlitchEffect_glitchCount = new WeakMap(), _JPEGGlitchEffect_hasResult = new WeakMap(), _JPEGGlitchEffect_producedFrames = new WeakMap(), _JPEGGlitchEffect_instances = new WeakSet(), _JPEGGlitchEffect_createOutTexture = function _JPEGGlitchEffect_createOutTexture(ctx) {
|
|
345
|
-
const gl = ctx.gl;
|
|
346
|
-
const tex = gl.createTexture();
|
|
347
|
-
if (!tex) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
351
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
352
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
353
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
354
|
-
// Nearest mag so low resolutionScale upscales crisp, not blurry.
|
|
355
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
356
|
-
// 1×1 placeholder so the sampler is valid before the first upload.
|
|
357
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
|
|
358
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
359
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_outGLTex, tex, "f");
|
|
360
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_outTex, ctx.wrapTexture(tex, {
|
|
361
|
-
size: [__classPrivateFieldGet(this, _JPEGGlitchEffect_w, "f") || 1, __classPrivateFieldGet(this, _JPEGGlitchEffect_h, "f") || 1],
|
|
362
|
-
}), "f");
|
|
363
|
-
}, _JPEGGlitchEffect_passthrough = function _JPEGGlitchEffect_passthrough(ctx) {
|
|
364
|
-
ctx.draw({
|
|
365
|
-
frag: FRAG_PASSTHROUGH,
|
|
366
|
-
uniforms: { src: ctx.src },
|
|
367
|
-
target: ctx.target,
|
|
368
|
-
});
|
|
369
|
-
}, _JPEGGlitchEffect_shouldGlitch = function _JPEGGlitchEffect_shouldGlitch(ctx) {
|
|
370
|
-
if (__classPrivateFieldGet(this, _JPEGGlitchEffect_busy, "f")) {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
const speed = this.params.speed;
|
|
374
|
-
if (speed > 0) {
|
|
375
|
-
return ctx.time - __classPrivateFieldGet(this, _JPEGGlitchEffect_lastGlitchTime, "f") >= 1 / speed;
|
|
376
|
-
}
|
|
377
|
-
return __classPrivateFieldGet(this, _JPEGGlitchEffect_dirty, "f");
|
|
378
|
-
}, _JPEGGlitchEffect_resize = function _JPEGGlitchEffect_resize(ctx, w, h) {
|
|
379
|
-
var _a;
|
|
380
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_w, w, "f");
|
|
381
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_h, h, "f");
|
|
382
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_raw, new Uint8Array(w * h * 4), "f");
|
|
383
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_imageData, new ImageData(w, h), "f");
|
|
384
|
-
if (__classPrivateFieldGet(this, _JPEGGlitchEffect_srcCanvas, "f")) {
|
|
385
|
-
__classPrivateFieldGet(this, _JPEGGlitchEffect_srcCanvas, "f").width = w;
|
|
386
|
-
__classPrivateFieldGet(this, _JPEGGlitchEffect_srcCanvas, "f").height = h;
|
|
387
|
-
}
|
|
388
|
-
if (__classPrivateFieldGet(this, _JPEGGlitchEffect_outCanvas, "f")) {
|
|
389
|
-
__classPrivateFieldGet(this, _JPEGGlitchEffect_outCanvas, "f").width = w;
|
|
390
|
-
__classPrivateFieldGet(this, _JPEGGlitchEffect_outCanvas, "f").height = h;
|
|
391
|
-
}
|
|
392
|
-
// The readback RT is sized to the processing resolution, so recreate
|
|
393
|
-
// it (explicit-size RTs don't auto-track the element).
|
|
394
|
-
__classPrivateFieldGet(this, _JPEGGlitchEffect_readRT, "f")?.dispose();
|
|
395
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_readRT, ctx.createRenderTarget({ size: [w, h] }), "f");
|
|
396
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_hasResult, false, "f");
|
|
397
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_dirty, true, "f");
|
|
398
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_busy, false, "f");
|
|
399
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_uploadPending, false, "f");
|
|
400
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_generation, (_a = __classPrivateFieldGet(this, _JPEGGlitchEffect_generation, "f"), _a++, _a), "f");
|
|
401
|
-
}, _JPEGGlitchEffect_startGlitch = function _JPEGGlitchEffect_startGlitch(ctx) {
|
|
402
|
-
var _a;
|
|
403
|
-
const w = __classPrivateFieldGet(this, _JPEGGlitchEffect_w, "f");
|
|
404
|
-
const h = __classPrivateFieldGet(this, _JPEGGlitchEffect_h, "f");
|
|
405
|
-
const srcCanvas = __classPrivateFieldGet(this, _JPEGGlitchEffect_srcCanvas, "f");
|
|
406
|
-
const srcCtx = __classPrivateFieldGet(this, _JPEGGlitchEffect_srcCtx, "f");
|
|
407
|
-
const encCanvas = __classPrivateFieldGet(this, _JPEGGlitchEffect_encCanvas, "f");
|
|
408
|
-
const encCtx = __classPrivateFieldGet(this, _JPEGGlitchEffect_encCtx, "f");
|
|
409
|
-
const imageData = __classPrivateFieldGet(this, _JPEGGlitchEffect_imageData, "f");
|
|
410
|
-
if (!srcCanvas ||
|
|
411
|
-
!srcCtx ||
|
|
412
|
-
!encCanvas ||
|
|
413
|
-
!encCtx ||
|
|
414
|
-
!imageData ||
|
|
415
|
-
!__classPrivateFieldGet(this, _JPEGGlitchEffect_readRT, "f")) {
|
|
416
|
-
return;
|
|
323
|
+
#passthrough(ctx) {
|
|
324
|
+
ctx.draw({
|
|
325
|
+
frag: FRAG_PASSTHROUGH,
|
|
326
|
+
uniforms: { src: ctx.src },
|
|
327
|
+
target: ctx.target,
|
|
328
|
+
});
|
|
417
329
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
// GL framebuffers are bottom-up; flip rows so the canvas is upright.
|
|
428
|
-
// Force opaque alpha — JPEG has no alpha channel.
|
|
429
|
-
const data = imageData.data;
|
|
430
|
-
const rowBytes = w * 4;
|
|
431
|
-
for (let y = 0; y < h; y++) {
|
|
432
|
-
const srcRow = (h - 1 - y) * rowBytes;
|
|
433
|
-
data.set(__classPrivateFieldGet(this, _JPEGGlitchEffect_raw, "f").subarray(srcRow, srcRow + rowBytes), y * rowBytes);
|
|
330
|
+
#shouldGlitch(ctx) {
|
|
331
|
+
if (this.#busy) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
const speed = this.params.speed;
|
|
335
|
+
if (speed > 0) {
|
|
336
|
+
return ctx.time - this.#lastGlitchTime >= 1 / speed;
|
|
337
|
+
}
|
|
338
|
+
return this.#dirty;
|
|
434
339
|
}
|
|
435
|
-
|
|
436
|
-
|
|
340
|
+
#resize(ctx, w, h) {
|
|
341
|
+
this.#w = w;
|
|
342
|
+
this.#h = h;
|
|
343
|
+
this.#raw = new Uint8Array(w * h * 4);
|
|
344
|
+
this.#imageData = new ImageData(w, h);
|
|
345
|
+
if (this.#srcCanvas) {
|
|
346
|
+
this.#srcCanvas.width = w;
|
|
347
|
+
this.#srcCanvas.height = h;
|
|
348
|
+
}
|
|
349
|
+
if (this.#outCanvas) {
|
|
350
|
+
this.#outCanvas.width = w;
|
|
351
|
+
this.#outCanvas.height = h;
|
|
352
|
+
}
|
|
353
|
+
// The readback RT is sized to the processing resolution, so recreate
|
|
354
|
+
// it (explicit-size RTs don't auto-track the element).
|
|
355
|
+
this.#readRT?.dispose();
|
|
356
|
+
this.#readRT = ctx.createRenderTarget({ size: [w, h] });
|
|
357
|
+
this.#hasResult = false;
|
|
358
|
+
this.#dirty = true;
|
|
359
|
+
this.#busy = false;
|
|
360
|
+
this.#uploadPending = false;
|
|
361
|
+
this.#generation++;
|
|
437
362
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
363
|
+
#startGlitch(ctx) {
|
|
364
|
+
const w = this.#w;
|
|
365
|
+
const h = this.#h;
|
|
366
|
+
const srcCanvas = this.#srcCanvas;
|
|
367
|
+
const srcCtx = this.#srcCtx;
|
|
368
|
+
const encCanvas = this.#encCanvas;
|
|
369
|
+
const encCtx = this.#encCtx;
|
|
370
|
+
const imageData = this.#imageData;
|
|
371
|
+
if (!srcCanvas ||
|
|
372
|
+
!srcCtx ||
|
|
373
|
+
!encCanvas ||
|
|
374
|
+
!encCtx ||
|
|
375
|
+
!imageData ||
|
|
376
|
+
!this.#readRT) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
// Read the element capture back to the CPU. The draw leaves the
|
|
380
|
+
// readback RT's framebuffer bound, so readPixels reads from it.
|
|
381
|
+
(0, _capture_js_1.captureContent)(ctx, this.#readRT);
|
|
382
|
+
const gl = ctx.gl;
|
|
383
|
+
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, this.#raw);
|
|
384
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
385
|
+
this.#busy = true;
|
|
386
|
+
this.#dirty = false;
|
|
387
|
+
this.#lastGlitchTime = ctx.time;
|
|
388
|
+
// GL framebuffers are bottom-up; flip rows so the canvas is upright.
|
|
389
|
+
// Force opaque alpha — JPEG has no alpha channel.
|
|
390
|
+
const data = imageData.data;
|
|
391
|
+
const rowBytes = w * 4;
|
|
392
|
+
for (let y = 0; y < h; y++) {
|
|
393
|
+
const srcRow = (h - 1 - y) * rowBytes;
|
|
394
|
+
data.set(this.#raw.subarray(srcRow, srcRow + rowBytes), y * rowBytes);
|
|
395
|
+
}
|
|
396
|
+
for (let i = 3; i < data.length; i += 4) {
|
|
397
|
+
data[i] = 255;
|
|
398
|
+
}
|
|
399
|
+
// Static glitch (speed 0) stays on variant 0 so it's reproducible;
|
|
400
|
+
// animated glitch advances the variant each round.
|
|
401
|
+
const variant = this.params.speed > 0 ? this.#glitchCount : 0;
|
|
402
|
+
this.#glitchCount++;
|
|
403
|
+
const { quality, seed, iterations, randomFlip, vertical } = this.params;
|
|
404
|
+
// One seeded sequence drives both the flip decision and the byte
|
|
405
|
+
// corruption, so the whole glitch is reproducible from the seed.
|
|
406
|
+
const rng = makeRng(seed, variant);
|
|
407
|
+
const flip = randomFlip && rng() < 0.5;
|
|
408
|
+
srcCtx.putImageData(imageData, 0, 0);
|
|
409
|
+
// Rotate the source before corrupting: 180° (flip) balances the tear
|
|
410
|
+
// direction, -90° (vertical, i.e. 270°) turns the tears sideways.
|
|
411
|
+
// The angles compose; runGlitch rotates the decoded output back.
|
|
412
|
+
const srcAngle = ((flip ? 180 : 0) + (vertical ? 270 : 0)) % 360;
|
|
413
|
+
const swap = vertical; // a quarter turn swaps width and height
|
|
414
|
+
const encW = swap ? h : w;
|
|
415
|
+
const encH = swap ? w : h;
|
|
416
|
+
encCanvas.width = encW;
|
|
417
|
+
encCanvas.height = encH;
|
|
418
|
+
drawRotated(encCtx, srcCanvas, w, h, srcAngle, encW, encH);
|
|
419
|
+
void this.#runGlitch(encCanvas, w, h, quality, iterations, srcAngle, rng, this.#generation);
|
|
463
420
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}, _JPEGGlitchEffect_runGlitch = async function _JPEGGlitchEffect_runGlitch(canvas, w, h, quality, iterations, srcAngle, rng, generation) {
|
|
472
|
-
var _a;
|
|
473
|
-
try {
|
|
474
|
-
const blob = await canvasToJpegBlob(canvas, quality);
|
|
475
|
-
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
476
|
-
const header = jpegScanStart(bytes);
|
|
477
|
-
glitchBytes(bytes, header, iterations, rng);
|
|
478
|
-
const bmp = await createImageBitmap(new Blob([bytes], { type: "image/jpeg" }));
|
|
479
|
-
// Discard if a resize happened while we were encoding/decoding.
|
|
480
|
-
if (generation === __classPrivateFieldGet(this, _JPEGGlitchEffect_generation, "f") && __classPrivateFieldGet(this, _JPEGGlitchEffect_outCtx, "f")) {
|
|
481
|
-
// Rotate the decoded glitch back upright (inverse of the
|
|
482
|
-
// source rotation) into the w×h output canvas.
|
|
483
|
-
const outAngle = (360 - srcAngle) % 360;
|
|
484
|
-
drawRotated(__classPrivateFieldGet(this, _JPEGGlitchEffect_outCtx, "f"), bmp, bmp.width, bmp.height, outAngle, w, h);
|
|
485
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_hasResult, true, "f");
|
|
486
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_producedFrames, (_a = __classPrivateFieldGet(this, _JPEGGlitchEffect_producedFrames, "f"), _a++, _a), "f");
|
|
487
|
-
// New pixels — upload to the display texture on the next draw.
|
|
488
|
-
__classPrivateFieldSet(this, _JPEGGlitchEffect_uploadPending, true, "f");
|
|
421
|
+
// Upload the decoded glitch canvas into our display texture. FLIP_Y
|
|
422
|
+
// matches the framework's canvas-as-image convention so FRAG_OUTPUT
|
|
423
|
+
// (which samples by uvContent) shows it upright.
|
|
424
|
+
#uploadOutCanvas(ctx) {
|
|
425
|
+
const gl = ctx.gl;
|
|
426
|
+
if (!this.#outGLTex || !this.#outCanvas) {
|
|
427
|
+
return;
|
|
489
428
|
}
|
|
490
|
-
|
|
429
|
+
gl.bindTexture(gl.TEXTURE_2D, this.#outGLTex);
|
|
430
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
431
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
432
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this.#outCanvas);
|
|
433
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
434
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
435
|
+
this.#uploadPending = false;
|
|
491
436
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
437
|
+
async #runGlitch(canvas, w, h, quality, iterations, srcAngle, rng, generation) {
|
|
438
|
+
try {
|
|
439
|
+
const blob = await canvasToJpegBlob(canvas, quality);
|
|
440
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
441
|
+
const header = jpegScanStart(bytes);
|
|
442
|
+
glitchBytes(bytes, header, iterations, rng);
|
|
443
|
+
const bmp = await createImageBitmap(new Blob([bytes], { type: "image/jpeg" }));
|
|
444
|
+
// Discard if a resize happened while we were encoding/decoding.
|
|
445
|
+
if (generation === this.#generation && this.#outCtx) {
|
|
446
|
+
// Rotate the decoded glitch back upright (inverse of the
|
|
447
|
+
// source rotation) into the w×h output canvas.
|
|
448
|
+
const outAngle = (360 - srcAngle) % 360;
|
|
449
|
+
drawRotated(this.#outCtx, bmp, bmp.width, bmp.height, outAngle, w, h);
|
|
450
|
+
this.#hasResult = true;
|
|
451
|
+
this.#producedFrames++;
|
|
452
|
+
// New pixels — upload to the display texture on the next draw.
|
|
453
|
+
this.#uploadPending = true;
|
|
454
|
+
}
|
|
455
|
+
bmp.close();
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
// Corrupted past the decoder's tolerance — keep the last good
|
|
459
|
+
// frame and try again on the next tick.
|
|
460
|
+
}
|
|
461
|
+
finally {
|
|
462
|
+
if (generation === this.#generation) {
|
|
463
|
+
this.#busy = false;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
495
466
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
467
|
+
dispose() {
|
|
468
|
+
this.#restoreUnsub?.();
|
|
469
|
+
this.#restoreUnsub = null;
|
|
470
|
+
if (this.#gl && this.#outGLTex) {
|
|
471
|
+
this.#gl.deleteTexture(this.#outGLTex);
|
|
499
472
|
}
|
|
473
|
+
this.#outGLTex = null;
|
|
474
|
+
this.#gl = null;
|
|
475
|
+
this.#uploadPending = false;
|
|
476
|
+
this.#readRT?.dispose();
|
|
477
|
+
this.#readRT = null;
|
|
478
|
+
this.#outTex = null;
|
|
479
|
+
this.#srcCanvas = null;
|
|
480
|
+
this.#srcCtx = null;
|
|
481
|
+
this.#encCanvas = null;
|
|
482
|
+
this.#encCtx = null;
|
|
483
|
+
this.#outCanvas = null;
|
|
484
|
+
this.#outCtx = null;
|
|
485
|
+
this.#imageData = null;
|
|
486
|
+
this.#raw = new Uint8Array(0);
|
|
487
|
+
this.#hasResult = false;
|
|
488
|
+
this.#busy = false;
|
|
489
|
+
// Forget the processed size so a re-init reallocates the readback RT
|
|
490
|
+
// (which dispose just freed) instead of mistaking it for current.
|
|
491
|
+
this.#w = 0;
|
|
492
|
+
this.#h = 0;
|
|
493
|
+
// Invalidate any in-flight round trip.
|
|
494
|
+
this.#generation++;
|
|
500
495
|
}
|
|
501
|
-
}
|
|
496
|
+
}
|
|
497
|
+
exports.JPEGGlitchEffect = JPEGGlitchEffect;
|
|
502
498
|
//# sourceMappingURL=jpeg-glitch.js.map
|