@vfx-js/effects 1.0.0 → 1.2.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/README.md +3 -1
- package/lib/cjs/bad-jpeg.d.ts +25 -0
- package/lib/cjs/bad-jpeg.js +221 -0
- package/lib/cjs/bad-jpeg.js.map +1 -0
- package/lib/cjs/datamosh.d.ts +43 -0
- package/lib/cjs/datamosh.js +559 -0
- package/lib/cjs/datamosh.js.map +1 -0
- package/lib/cjs/index.d.ts +4 -0
- package/lib/cjs/index.js +9 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/jpeg-glitch.d.ts +82 -0
- package/lib/cjs/jpeg-glitch.js +501 -0
- package/lib/cjs/jpeg-glitch.js.map +1 -0
- package/lib/cjs/package.json +4 -4
- package/lib/cjs/particle-explode.js +1 -14
- package/lib/cjs/particle-explode.js.map +1 -1
- package/lib/cjs/pixelsort.d.ts +37 -0
- package/lib/cjs/pixelsort.js +474 -0
- package/lib/cjs/pixelsort.js.map +1 -0
- package/lib/esm/bad-jpeg.d.ts +25 -0
- package/lib/esm/bad-jpeg.js +217 -0
- package/lib/esm/bad-jpeg.js.map +1 -0
- package/lib/esm/datamosh.d.ts +43 -0
- package/lib/esm/datamosh.js +555 -0
- package/lib/esm/datamosh.js.map +1 -0
- package/lib/esm/index.d.ts +4 -0
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/jpeg-glitch.d.ts +82 -0
- package/lib/esm/jpeg-glitch.js +497 -0
- package/lib/esm/jpeg-glitch.js.map +1 -0
- package/lib/esm/package.json +4 -4
- package/lib/esm/particle-explode.js +1 -14
- package/lib/esm/particle-explode.js.map +1 -1
- package/lib/esm/pixelsort.d.ts +37 -0
- package/lib/esm/pixelsort.js +470 -0
- package/lib/esm/pixelsort.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// The 2D 8x8 DCT is separable: a rows pass then a columns pass, 8 taps each.
|
|
2
|
+
// All passes run premultiplied so transparent texels don't bleed into the DCT
|
|
3
|
+
// or chroma subsampling; alpha rides along as a 4th plane using the luma table.
|
|
4
|
+
const HEADER = `#version 300 es
|
|
5
|
+
precision highp float;
|
|
6
|
+
in vec2 uvSrc;
|
|
7
|
+
out vec4 outColor;
|
|
8
|
+
uniform sampler2D src;
|
|
9
|
+
`;
|
|
10
|
+
const DCT = `
|
|
11
|
+
const float PI = 3.141592653589793;
|
|
12
|
+
float cc(int k){ return k == 0 ? 0.7071067811865476 : 1.0; }
|
|
13
|
+
`;
|
|
14
|
+
const YCC = `
|
|
15
|
+
vec3 rgb2ycc(vec3 c){
|
|
16
|
+
return vec3(
|
|
17
|
+
0.299*c.r + 0.587*c.g + 0.114*c.b,
|
|
18
|
+
-0.168736*c.r - 0.331264*c.g + 0.5*c.b,
|
|
19
|
+
0.5*c.r - 0.418688*c.g - 0.081312*c.b);
|
|
20
|
+
}
|
|
21
|
+
vec3 ycc2rgb(vec3 y){
|
|
22
|
+
return vec3(
|
|
23
|
+
y.x + 1.402 * y.z,
|
|
24
|
+
y.x - 0.344136* y.y - 0.714136 * y.z,
|
|
25
|
+
y.x + 1.772 * y.y);
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
// b = 8x8 block origin, l = position within the block
|
|
29
|
+
const BLOCK = `
|
|
30
|
+
ivec2 res = textureSize(src, 0);
|
|
31
|
+
ivec2 p = ivec2(uvSrc * vec2(res));
|
|
32
|
+
ivec2 b = (p / 8) * 8;
|
|
33
|
+
ivec2 l = p - b;
|
|
34
|
+
`;
|
|
35
|
+
/* straight-alpha capture -> premultiplied low-res raster */
|
|
36
|
+
const PRE = `${HEADER}
|
|
37
|
+
void main(){
|
|
38
|
+
vec4 c = texture(src, uvSrc);
|
|
39
|
+
outColor = vec4(c.rgb * c.a, c.a);
|
|
40
|
+
}`;
|
|
41
|
+
/* forward DCT, rows: RGB->YCbCr, level-shift, 1D DCT across x */
|
|
42
|
+
const FWDH = `${HEADER}${DCT}${YCC}
|
|
43
|
+
void main(){
|
|
44
|
+
${BLOCK}
|
|
45
|
+
vec4 sum = vec4(0.0);
|
|
46
|
+
for (int x = 0; x < 8; x++) {
|
|
47
|
+
vec4 t = texelFetch(src, clamp(b + ivec2(x, l.y), ivec2(0), res - 1), 0);
|
|
48
|
+
vec4 f = (vec4(rgb2ycc(t.rgb), t.a) - vec4(0.5, 0.0, 0.0, 0.5)) * 255.0;
|
|
49
|
+
sum += f * cos(float(2*x+1) * float(l.x) * PI / 16.0);
|
|
50
|
+
}
|
|
51
|
+
outColor = sum * 0.5 * cc(l.x);
|
|
52
|
+
}`;
|
|
53
|
+
/* forward DCT, columns: 1D DCT across y -> full DCT coefficients */
|
|
54
|
+
const FWDV = `${HEADER}${DCT}
|
|
55
|
+
void main(){
|
|
56
|
+
${BLOCK}
|
|
57
|
+
vec4 sum = vec4(0.0);
|
|
58
|
+
for (int y = 0; y < 8; y++)
|
|
59
|
+
sum += texelFetch(src, clamp(b + ivec2(l.x, y), ivec2(0), res - 1), 0)
|
|
60
|
+
* cos(float(2*y+1) * float(l.y) * PI / 16.0);
|
|
61
|
+
outColor = sum * 0.5 * cc(l.y);
|
|
62
|
+
}`;
|
|
63
|
+
/* inverse pass 1: quantize each coeff, 1D iDCT across columns */
|
|
64
|
+
const INVV = `${HEADER}${DCT}
|
|
65
|
+
uniform float uS; // libjpeg quality scale
|
|
66
|
+
const float LQ[64] = float[64](
|
|
67
|
+
16.,11.,10.,16.,24.,40.,51.,61., 12.,12.,14.,19.,26.,58.,60.,55.,
|
|
68
|
+
14.,13.,16.,24.,40.,57.,69.,56., 14.,17.,22.,29.,51.,87.,80.,62.,
|
|
69
|
+
18.,22.,37.,56.,68.,109.,103.,77., 24.,35.,55.,64.,81.,104.,113.,92.,
|
|
70
|
+
49.,64.,78.,87.,103.,121.,120.,101., 72.,92.,95.,98.,112.,100.,103.,99.);
|
|
71
|
+
const float CQ[64] = float[64](
|
|
72
|
+
17.,18.,24.,47.,99.,99.,99.,99., 18.,21.,26.,66.,99.,99.,99.,99.,
|
|
73
|
+
24.,26.,56.,99.,99.,99.,99.,99., 47.,66.,99.,99.,99.,99.,99.,99.,
|
|
74
|
+
99.,99.,99.,99.,99.,99.,99.,99., 99.,99.,99.,99.,99.,99.,99.,99.,
|
|
75
|
+
99.,99.,99.,99.,99.,99.,99.,99., 99.,99.,99.,99.,99.,99.,99.,99.);
|
|
76
|
+
float qstep(float base){ return clamp(floor((base * uS + 50.0) / 100.0), 1.0, 255.0); }
|
|
77
|
+
void main(){
|
|
78
|
+
${BLOCK}
|
|
79
|
+
vec4 sum = vec4(0.0);
|
|
80
|
+
for (int v = 0; v < 8; v++) {
|
|
81
|
+
int idx = v * 8 + l.x;
|
|
82
|
+
vec4 F = texelFetch(src, clamp(b + ivec2(l.x, v), ivec2(0), res - 1), 0);
|
|
83
|
+
vec4 q = vec4(qstep(LQ[idx]), qstep(CQ[idx]), qstep(CQ[idx]), qstep(LQ[idx]));
|
|
84
|
+
sum += cc(v) * round(F / q) * q * cos(float(2*l.y+1) * float(v) * PI / 16.0);
|
|
85
|
+
}
|
|
86
|
+
outColor = sum * 0.5;
|
|
87
|
+
}`;
|
|
88
|
+
/* inverse pass 2: 1D iDCT across rows, un-shift, YCbCr->RGB (still premultiplied) */
|
|
89
|
+
const INVH = `${HEADER}${DCT}${YCC}
|
|
90
|
+
void main(){
|
|
91
|
+
${BLOCK}
|
|
92
|
+
vec4 sum = vec4(0.0);
|
|
93
|
+
for (int u = 0; u < 8; u++)
|
|
94
|
+
sum += cc(u) * texelFetch(src, clamp(b + ivec2(u, l.y), ivec2(0), res - 1), 0)
|
|
95
|
+
* cos(float(2*l.x+1) * float(u) * PI / 16.0);
|
|
96
|
+
sum = sum * 0.5 / 255.0 + vec4(0.5, 0.0, 0.0, 0.5);
|
|
97
|
+
outColor = clamp(vec4(ycc2rgb(sum.xyz), sum.w), 0.0, 1.0);
|
|
98
|
+
}`;
|
|
99
|
+
/* 4:2:0 chroma subsample: box-downsample Cb/Cr to half res, bilinear upsample.
|
|
100
|
+
Not a fixed point — chroma blurs further each pass, so the loop accumulates. */
|
|
101
|
+
const SUB = `${HEADER}${YCC}
|
|
102
|
+
vec2 cellChroma(ivec2 res, ivec2 cell){
|
|
103
|
+
vec2 s = vec2(0.0);
|
|
104
|
+
for (int j = 0; j < 2; j++)
|
|
105
|
+
for (int i = 0; i < 2; i++) {
|
|
106
|
+
ivec2 ip = clamp(cell * 2 + ivec2(i, j), ivec2(0), res - 1);
|
|
107
|
+
s += rgb2ycc(texelFetch(src, ip, 0).rgb).yz;
|
|
108
|
+
}
|
|
109
|
+
return s * 0.25;
|
|
110
|
+
}
|
|
111
|
+
void main(){
|
|
112
|
+
ivec2 res = textureSize(src, 0);
|
|
113
|
+
ivec2 p = ivec2(uvSrc * vec2(res));
|
|
114
|
+
vec4 c0 = texelFetch(src, clamp(p, ivec2(0), res - 1), 0);
|
|
115
|
+
float Y = rgb2ycc(c0.rgb).x; // luma stays full-res
|
|
116
|
+
vec2 gpos = (vec2(p) + 0.5) * 0.5 - 0.5; // position on the half-res chroma grid
|
|
117
|
+
vec2 gi = floor(gpos);
|
|
118
|
+
vec2 f = gpos - gi;
|
|
119
|
+
ivec2 c = ivec2(gi);
|
|
120
|
+
vec2 cb = mix(
|
|
121
|
+
mix(cellChroma(res, c + ivec2(0,0)), cellChroma(res, c + ivec2(1,0)), f.x),
|
|
122
|
+
mix(cellChroma(res, c + ivec2(0,1)), cellChroma(res, c + ivec2(1,1)), f.x), f.y);
|
|
123
|
+
outColor = vec4(clamp(ycc2rgb(vec3(Y, cb)), 0.0, 1.0), c0.a);
|
|
124
|
+
}`;
|
|
125
|
+
const LOW_RES_KEYS = ["coeff", "tmp", "sub", "a", "b"];
|
|
126
|
+
/**
|
|
127
|
+
* Simulates JPEG degradation: chroma subsampling, blocky DCT quantization,
|
|
128
|
+
* and generation loss from re-encoding the result `iterations` times.
|
|
129
|
+
* Mutate `quality` / `iterations` / `downscale` directly for runtime tweaks.
|
|
130
|
+
*
|
|
131
|
+
* @see GABIBI https://amix-design.com/tl/tool-gabibi/
|
|
132
|
+
* @see DCT glitch https://qiita.com/FMS_Cat/items/6943c708a875984228b9
|
|
133
|
+
*/
|
|
134
|
+
export class BadJpegEffect {
|
|
135
|
+
constructor({ quality = 8, iterations = 3, downscale = 1.0, } = {}) {
|
|
136
|
+
this.lowRes = null;
|
|
137
|
+
this.quality = quality;
|
|
138
|
+
this.iterations = iterations;
|
|
139
|
+
this.downscale = downscale;
|
|
140
|
+
}
|
|
141
|
+
// Low-res RT set sized floor(element * downscale); reallocated when dims change.
|
|
142
|
+
ensureLowRes(ctx, w, h) {
|
|
143
|
+
if (this.lowRes && this.lowRes.w === w && this.lowRes.h === h) {
|
|
144
|
+
return this.lowRes;
|
|
145
|
+
}
|
|
146
|
+
this.disposeLowRes();
|
|
147
|
+
const size = [w, h];
|
|
148
|
+
this.lowRes = {
|
|
149
|
+
w,
|
|
150
|
+
h,
|
|
151
|
+
coeff: ctx.createRenderTarget({ float: true, size }), // DCT coeffs (signed, large)
|
|
152
|
+
tmp: ctx.createRenderTarget({ float: true, size }), // separable scratch
|
|
153
|
+
sub: ctx.createRenderTarget({ size }), // chroma-subsampled spatial RGB
|
|
154
|
+
a: ctx.createRenderTarget({ size }), // 8-bit ping-pong (generation loss)
|
|
155
|
+
b: ctx.createRenderTarget({ size }),
|
|
156
|
+
};
|
|
157
|
+
return this.lowRes;
|
|
158
|
+
}
|
|
159
|
+
disposeLowRes() {
|
|
160
|
+
if (this.lowRes) {
|
|
161
|
+
for (const k of LOW_RES_KEYS) {
|
|
162
|
+
this.lowRes[k].dispose();
|
|
163
|
+
}
|
|
164
|
+
this.lowRes = null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
render(ctx) {
|
|
168
|
+
const N = Math.max(1, Math.min(10, this.iterations | 0));
|
|
169
|
+
const q = Math.max(1, Math.min(100, this.quality));
|
|
170
|
+
const S = q < 50 ? 5000 / q : 200 - 2 * q;
|
|
171
|
+
const ds = Math.max(0.02, Math.min(1, this.downscale));
|
|
172
|
+
// element size in CSS px, so the 8x8 block scale is DPI-independent
|
|
173
|
+
const [W, H] = ctx.dims.element;
|
|
174
|
+
const lw = Math.max(1, Math.floor(W * ds));
|
|
175
|
+
const lh = Math.max(1, Math.floor(H * ds));
|
|
176
|
+
const lowRes = this.ensureLowRes(ctx, lw, lh);
|
|
177
|
+
// premultiply + shrink source onto the low-res raster
|
|
178
|
+
ctx.draw({ frag: PRE, uniforms: { src: ctx.src }, target: lowRes.a });
|
|
179
|
+
let input = lowRes.a;
|
|
180
|
+
// JPEG-degrade loop, entirely at low res
|
|
181
|
+
for (let k = 0; k < N; k++) {
|
|
182
|
+
ctx.draw({
|
|
183
|
+
frag: SUB,
|
|
184
|
+
uniforms: { src: input },
|
|
185
|
+
target: lowRes.sub,
|
|
186
|
+
});
|
|
187
|
+
ctx.draw({
|
|
188
|
+
frag: FWDH,
|
|
189
|
+
uniforms: { src: lowRes.sub },
|
|
190
|
+
target: lowRes.tmp,
|
|
191
|
+
});
|
|
192
|
+
ctx.draw({
|
|
193
|
+
frag: FWDV,
|
|
194
|
+
uniforms: { src: lowRes.tmp },
|
|
195
|
+
target: lowRes.coeff,
|
|
196
|
+
});
|
|
197
|
+
ctx.draw({
|
|
198
|
+
frag: INVV,
|
|
199
|
+
uniforms: { src: lowRes.coeff, uS: S },
|
|
200
|
+
target: lowRes.tmp,
|
|
201
|
+
});
|
|
202
|
+
const out = k % 2 === 0 ? lowRes.b : lowRes.a;
|
|
203
|
+
ctx.draw({
|
|
204
|
+
frag: INVH,
|
|
205
|
+
uniforms: { src: lowRes.tmp },
|
|
206
|
+
target: out,
|
|
207
|
+
});
|
|
208
|
+
input = out;
|
|
209
|
+
}
|
|
210
|
+
// bilinear up-scale back to full output for the soft look
|
|
211
|
+
ctx.blit(input, ctx.target);
|
|
212
|
+
}
|
|
213
|
+
dispose() {
|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G,CAAC;QAChB,CAAC;QAED,0DAA0D;QAC1D,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,OAAO;QACH,IAAI,CAAC,aAAa,EAAE,CAAC;IACzB,CAAC;CACJ"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Effect, EffectContext } from "@vfx-js/core";
|
|
2
|
+
export type DatamoshColorSpace = "rgb" | "ycbcr";
|
|
3
|
+
/** Stage routed to the canvas; non-`output` views are for debugging. */
|
|
4
|
+
export type DatamoshView = "output" | "motion" | "residual" | "current" | "previous";
|
|
5
|
+
export type DatamoshParams = {
|
|
6
|
+
/** Motion-estimation block size in px. */
|
|
7
|
+
blockSize: number;
|
|
8
|
+
/** Motion search radius, in steps. Coverage = searchRange * searchStep px. */
|
|
9
|
+
searchRange: number;
|
|
10
|
+
/** Pixels per search step. Widens coverage at a fixed candidate count. */
|
|
11
|
+
searchStep: number;
|
|
12
|
+
/** Add the residual during decode (off = pure motion). */
|
|
13
|
+
useResidual: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* P-frame duplication: re-apply the frame's motion this many extra
|
|
16
|
+
* times per frame, dragging the accumulator further along the field
|
|
17
|
+
* (the bloom/smear amplifier). 0 = one normal application.
|
|
18
|
+
*/
|
|
19
|
+
dup: number;
|
|
20
|
+
/** Color model. `"ycbcr"` is 4:2:0 (half-res chroma w/ truncated MV). */
|
|
21
|
+
colorSpace: DatamoshColorSpace;
|
|
22
|
+
/** Chroma saturation boost (YCbCr output). 1 = unchanged. */
|
|
23
|
+
chromaGain: number;
|
|
24
|
+
/** Stage shown on the canvas. */
|
|
25
|
+
view: DatamoshView;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Pseudo-datamosh via a faked H.264 block codec. Passes the input
|
|
29
|
+
* through until `enable()`, then holds a motion-compensated accumulator
|
|
30
|
+
* so motion smears stale texture around. Mutate `params` directly or via
|
|
31
|
+
* `setParams`; toggle the mosh with `enable()` / `disable()`.
|
|
32
|
+
*/
|
|
33
|
+
export declare class DatamoshEffect implements Effect {
|
|
34
|
+
#private;
|
|
35
|
+
params: DatamoshParams;
|
|
36
|
+
constructor(initial?: Partial<DatamoshParams>);
|
|
37
|
+
setParams(partial: Partial<DatamoshParams>): void;
|
|
38
|
+
enable(): void;
|
|
39
|
+
disable(): void;
|
|
40
|
+
get enabled(): boolean;
|
|
41
|
+
render(ctx: EffectContext): void;
|
|
42
|
+
dispose(): void;
|
|
43
|
+
}
|