@remotion/effects 4.0.465 → 4.0.466

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.
@@ -1,428 +0,0 @@
1
- // src/halftone.ts
2
- import { Internals } from "remotion";
3
- var { createEffect, createWebGL2ContextError } = Internals;
4
- var SHADE_OUTSIDE_DOT_SCALE = 0.5;
5
- var halftoneSchema = {
6
- dotSize: {
7
- type: "number",
8
- min: 1,
9
- max: 200,
10
- step: 1,
11
- default: 20,
12
- description: "Dot size"
13
- },
14
- dotSpacing: {
15
- type: "number",
16
- min: 1,
17
- max: 200,
18
- step: 1,
19
- default: 20,
20
- description: "Dot spacing"
21
- },
22
- rotation: {
23
- type: "number",
24
- min: -180,
25
- max: 180,
26
- step: 1,
27
- default: 0,
28
- description: "Rotation"
29
- },
30
- offsetX: {
31
- type: "number",
32
- step: 1,
33
- default: 0,
34
- description: "Offset X"
35
- },
36
- offsetY: {
37
- type: "number",
38
- step: 1,
39
- default: 0,
40
- description: "Offset Y"
41
- },
42
- shape: {
43
- type: "enum",
44
- variants: {
45
- circle: {},
46
- square: {},
47
- line: {}
48
- },
49
- default: "circle",
50
- description: "Shape"
51
- }
52
- };
53
- var resolve = (p) => ({
54
- shape: p.shape ?? "circle",
55
- dotSize: p.dotSize ?? 20,
56
- dotSpacing: p.dotSpacing ?? p.dotSize ?? 20,
57
- rotation: p.rotation ?? 0,
58
- offsetX: p.offsetX ?? 0,
59
- offsetY: p.offsetY ?? 0,
60
- sampling: p.sampling ?? "bilinear",
61
- color: p.color ?? "black",
62
- shadeOutside: p.shadeOutside ?? false
63
- });
64
- var HALFTONE_VS = `#version 300 es
65
- in vec2 aPos;
66
- in vec2 aUv;
67
- out vec2 vUv;
68
- void main() {
69
- vUv = aUv;
70
- gl_Position = vec4(aPos, 0.0, 1.0);
71
- }
72
- `;
73
- var HALFTONE_FS = `#version 300 es
74
- precision highp float;
75
-
76
- in vec2 vUv;
77
- out vec4 fragColor;
78
-
79
- uniform sampler2D uSource;
80
- uniform vec2 uResolution;
81
- uniform float uDotSize;
82
- uniform float uDotSpacing;
83
- uniform float uRotation;
84
- uniform vec2 uOffset;
85
- uniform vec4 uColor;
86
- uniform int uShape;
87
- uniform bool uShadeOutside;
88
-
89
- const float SHADE_OUTSIDE_SCALE = ${SHADE_OUTSIDE_DOT_SCALE.toFixed(1)};
90
-
91
- void main() {
92
- vec2 fragPos = vUv * uResolution;
93
- vec2 center = uResolution * 0.5;
94
-
95
- vec2 d = fragPos - center;
96
- float cosR = cos(uRotation);
97
- float sinR = sin(uRotation);
98
-
99
- vec2 gridPos = vec2(
100
- d.x * cosR + d.y * sinR,
101
- -d.x * sinR + d.y * cosR
102
- );
103
-
104
- float spacing = max(uDotSpacing, 0.001);
105
- vec2 cellIndex = floor((gridPos + uOffset) / spacing + 0.5);
106
- vec2 gridCenter = cellIndex * spacing - uOffset;
107
-
108
- vec2 canvasPos = center + vec2(
109
- gridCenter.x * cosR - gridCenter.y * sinR,
110
- gridCenter.x * sinR + gridCenter.y * cosR
111
- );
112
-
113
- vec2 sampleUv = clamp(canvasPos / uResolution, vec2(0.0), vec2(1.0));
114
- vec4 texColor = texture(uSource, sampleUv);
115
-
116
- float alpha = texColor.a;
117
- vec3 rgb = alpha > 0.001 ? texColor.rgb / alpha : vec3(0.0);
118
- float lum = dot(rgb, vec3(0.299, 0.587, 0.114));
119
-
120
- float lumDefault = lum * alpha + (1.0 - alpha);
121
- float dotScale = uShadeOutside
122
- ? (1.0 - alpha) * SHADE_OUTSIDE_SCALE
123
- : 1.0 - lumDefault;
124
-
125
- if (dotScale <= 0.01) {
126
- fragColor = vec4(0.0);
127
- return;
128
- }
129
-
130
- vec2 diff = gridPos - gridCenter;
131
- float halfSize = uDotSize * 0.5;
132
- float coverage = 0.0;
133
-
134
- if (uShape == 0) {
135
- float radius = halfSize * dotScale;
136
- float dist = length(diff);
137
- coverage = 1.0 - smoothstep(radius - 0.75, radius + 0.75, dist);
138
- } else if (uShape == 1) {
139
- float s = uDotSize * dotScale * 0.5;
140
- coverage = (1.0 - smoothstep(s - 0.5, s + 0.5, abs(diff.x)))
141
- * (1.0 - smoothstep(s - 0.5, s + 0.5, abs(diff.y)));
142
- } else {
143
- float lineHalf = uDotSize * dotScale * 0.5;
144
- coverage = (1.0 - smoothstep(halfSize - 0.5, halfSize + 0.5, abs(diff.x)))
145
- * (1.0 - smoothstep(lineHalf - 0.5, lineHalf + 0.5, abs(diff.y)));
146
- }
147
-
148
- fragColor = uColor * coverage;
149
- }
150
- `;
151
- var SHAPE_INDEX = {
152
- circle: 0,
153
- square: 1,
154
- line: 2
155
- };
156
- var compileShader = (gl, type, source) => {
157
- const shader = gl.createShader(type);
158
- if (!shader) {
159
- throw new Error("Failed to create WebGL shader");
160
- }
161
- gl.shaderSource(shader, source);
162
- gl.compileShader(shader);
163
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
164
- const log = gl.getShaderInfoLog(shader);
165
- gl.deleteShader(shader);
166
- throw new Error(`Halftone shader compile failed: ${log ?? "(no log)"}`);
167
- }
168
- return shader;
169
- };
170
- var linkProgram = (gl, vs, fs) => {
171
- const program = gl.createProgram();
172
- if (!program) {
173
- throw new Error("Failed to create WebGL program");
174
- }
175
- gl.attachShader(program, vs);
176
- gl.attachShader(program, fs);
177
- gl.linkProgram(program);
178
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
179
- const log = gl.getProgramInfoLog(program);
180
- gl.deleteProgram(program);
181
- throw new Error(`Halftone program link failed: ${log ?? "(no log)"}`);
182
- }
183
- return program;
184
- };
185
- var parseColorRgba = (ctx, color) => {
186
- ctx.clearRect(0, 0, 1, 1);
187
- ctx.fillStyle = color;
188
- ctx.fillRect(0, 0, 1, 1);
189
- const { data } = ctx.getImageData(0, 0, 1, 1);
190
- return [data[0] / 255, data[1] / 255, data[2] / 255, data[3] / 255];
191
- };
192
- var halftone = createEffect({
193
- type: "remotion/halftone",
194
- label: "Halftone",
195
- backend: "webgl2",
196
- calculateKey: (params) => {
197
- const r = resolve(params);
198
- return `halftone-${r.shape}-${r.dotSize}-${r.dotSpacing}-${r.rotation}-${r.offsetX}-${r.offsetY}-${r.sampling}-${r.color}-${r.shadeOutside ? 1 : 0}`;
199
- },
200
- setup: (target) => {
201
- const gl = target.getContext("webgl2", {
202
- premultipliedAlpha: true,
203
- alpha: true,
204
- preserveDrawingBuffer: true
205
- });
206
- if (!gl) {
207
- throw createWebGL2ContextError("halftone effect");
208
- }
209
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
210
- const vs = compileShader(gl, gl.VERTEX_SHADER, HALFTONE_VS);
211
- const fs = compileShader(gl, gl.FRAGMENT_SHADER, HALFTONE_FS);
212
- const program = linkProgram(gl, vs, fs);
213
- gl.deleteShader(vs);
214
- gl.deleteShader(fs);
215
- const vao = gl.createVertexArray();
216
- if (!vao) {
217
- throw new Error("Failed to create WebGL vertex array");
218
- }
219
- gl.bindVertexArray(vao);
220
- const data = new Float32Array([
221
- -1,
222
- -1,
223
- 0,
224
- 0,
225
- 1,
226
- -1,
227
- 1,
228
- 0,
229
- -1,
230
- 1,
231
- 0,
232
- 1,
233
- 1,
234
- 1,
235
- 1,
236
- 1
237
- ]);
238
- const vbo = gl.createBuffer();
239
- if (!vbo) {
240
- throw new Error("Failed to create WebGL buffer");
241
- }
242
- gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
243
- gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
244
- const aPos = gl.getAttribLocation(program, "aPos");
245
- const aUv = gl.getAttribLocation(program, "aUv");
246
- gl.enableVertexAttribArray(aPos);
247
- gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
248
- gl.enableVertexAttribArray(aUv);
249
- gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
250
- gl.bindVertexArray(null);
251
- const texture = gl.createTexture();
252
- if (!texture) {
253
- throw new Error("Failed to create WebGL texture");
254
- }
255
- gl.bindTexture(gl.TEXTURE_2D, texture);
256
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
257
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
258
- gl.bindTexture(gl.TEXTURE_2D, null);
259
- const colorCanvas = document.createElement("canvas");
260
- colorCanvas.width = 1;
261
- colorCanvas.height = 1;
262
- const colorCtx = colorCanvas.getContext("2d", { willReadFrequently: true });
263
- if (!colorCtx) {
264
- throw new Error("Failed to acquire 2D context for color parsing");
265
- }
266
- return {
267
- gl,
268
- program,
269
- vao,
270
- vbo,
271
- texture,
272
- uSource: gl.getUniformLocation(program, "uSource"),
273
- uResolution: gl.getUniformLocation(program, "uResolution"),
274
- uDotSize: gl.getUniformLocation(program, "uDotSize"),
275
- uDotSpacing: gl.getUniformLocation(program, "uDotSpacing"),
276
- uRotation: gl.getUniformLocation(program, "uRotation"),
277
- uOffset: gl.getUniformLocation(program, "uOffset"),
278
- uColor: gl.getUniformLocation(program, "uColor"),
279
- uShape: gl.getUniformLocation(program, "uShape"),
280
- uShadeOutside: gl.getUniformLocation(program, "uShadeOutside"),
281
- colorCtx,
282
- cachedColorStr: "",
283
- cachedColorRgba: [0, 0, 0, 1]
284
- };
285
- },
286
- apply: ({ source, width, height, params, state, flipSourceY }) => {
287
- const r = resolve(params);
288
- const { gl, program, vao, texture } = state;
289
- if (state.cachedColorStr !== r.color) {
290
- state.cachedColorStr = r.color;
291
- state.cachedColorRgba = parseColorRgba(state.colorCtx, r.color);
292
- }
293
- const [cr, cg, cb, ca] = state.cachedColorRgba;
294
- const filter = r.sampling === "nearest" ? gl.NEAREST : gl.LINEAR;
295
- gl.viewport(0, 0, width, height);
296
- gl.clearColor(0, 0, 0, 0);
297
- gl.clear(gl.COLOR_BUFFER_BIT);
298
- gl.useProgram(program);
299
- gl.bindVertexArray(vao);
300
- gl.activeTexture(gl.TEXTURE0);
301
- gl.bindTexture(gl.TEXTURE_2D, texture);
302
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
303
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
304
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
305
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
306
- if (state.uSource)
307
- gl.uniform1i(state.uSource, 0);
308
- if (state.uResolution)
309
- gl.uniform2f(state.uResolution, width, height);
310
- if (state.uDotSize)
311
- gl.uniform1f(state.uDotSize, r.dotSize);
312
- if (state.uDotSpacing)
313
- gl.uniform1f(state.uDotSpacing, r.dotSpacing);
314
- if (state.uRotation)
315
- gl.uniform1f(state.uRotation, r.rotation * Math.PI / 180);
316
- if (state.uOffset)
317
- gl.uniform2f(state.uOffset, r.offsetX, r.offsetY);
318
- if (state.uColor)
319
- gl.uniform4f(state.uColor, cr * ca, cg * ca, cb * ca, ca);
320
- if (state.uShape)
321
- gl.uniform1i(state.uShape, SHAPE_INDEX[r.shape]);
322
- if (state.uShadeOutside)
323
- gl.uniform1i(state.uShadeOutside, r.shadeOutside ? 1 : 0);
324
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
325
- gl.bindVertexArray(null);
326
- gl.bindTexture(gl.TEXTURE_2D, null);
327
- gl.useProgram(null);
328
- },
329
- cleanup: ({ gl, program, vao, vbo, texture }) => {
330
- gl.deleteBuffer(vbo);
331
- gl.deleteProgram(program);
332
- gl.deleteVertexArray(vao);
333
- gl.deleteTexture(texture);
334
- },
335
- schema: halftoneSchema,
336
- validateParams: () => {}
337
- });
338
-
339
- // src/tint.ts
340
- import { Internals as Internals2 } from "remotion";
341
-
342
- // src/validate-effect-param.ts
343
- var assertEffectParamsObject = (params, effectLabel) => {
344
- if (params === null || typeof params !== "object") {
345
- throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
346
- }
347
- };
348
- var assertRequiredFiniteNumber = (value, name) => {
349
- if (typeof value !== "number" || !Number.isFinite(value)) {
350
- throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
351
- }
352
- };
353
- var assertRequiredColor = (value, name) => {
354
- if (typeof value !== "string" || value.length === 0) {
355
- throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
356
- }
357
- };
358
-
359
- // src/tint.ts
360
- var { createEffect: createEffect2 } = Internals2;
361
- var DEFAULT_AMOUNT = 0.5;
362
- var tintSchema = {
363
- color: {
364
- type: "color",
365
- default: undefined,
366
- description: "Color"
367
- },
368
- amount: {
369
- type: "number",
370
- min: 0,
371
- max: 1,
372
- step: 0.01,
373
- default: DEFAULT_AMOUNT,
374
- description: "Amount"
375
- }
376
- };
377
- var resolve2 = (p) => ({
378
- color: p.color,
379
- amount: p.amount ?? DEFAULT_AMOUNT
380
- });
381
- var validateTintParams = (params) => {
382
- assertEffectParamsObject(params, "Tint");
383
- assertRequiredColor(params.color, "color");
384
- };
385
- var tint = createEffect2({
386
- type: "remotion/tint",
387
- label: "Tint",
388
- backend: "2d",
389
- calculateKey: (params) => {
390
- const r = resolve2(params);
391
- return `tint-${r.color}-${r.amount}`;
392
- },
393
- setup: () => null,
394
- apply: ({ source, target, width, height, params }) => {
395
- const ctx = target.getContext("2d");
396
- if (!ctx) {
397
- throw new Error("Failed to acquire 2D context for tint effect. The canvas may have been assigned a different context type.");
398
- }
399
- const r = resolve2(params);
400
- const amount = Math.max(0, Math.min(1, r.amount));
401
- ctx.clearRect(0, 0, width, height);
402
- ctx.globalAlpha = 1;
403
- ctx.globalCompositeOperation = "source-over";
404
- ctx.drawImage(source, 0, 0, width, height);
405
- ctx.globalAlpha = amount;
406
- ctx.globalCompositeOperation = "source-atop";
407
- ctx.fillStyle = r.color;
408
- ctx.fillRect(0, 0, width, height);
409
- ctx.globalAlpha = 1;
410
- ctx.globalCompositeOperation = "source-over";
411
- },
412
- cleanup: () => {
413
- return;
414
- },
415
- schema: tintSchema,
416
- validateParams: validateTintParams
417
- });
418
-
419
- // src/effect-internals.ts
420
- var EffectInternals = {
421
- halftone,
422
- tint
423
- };
424
- export {
425
- tintSchema,
426
- halftoneSchema,
427
- EffectInternals
428
- };
@@ -0,0 +1,128 @@
1
+ // src/invert.ts
2
+ import { Internals } from "remotion";
3
+
4
+ // src/validate-effect-param.ts
5
+ var assertEffectParamsObject = (params, effectLabel) => {
6
+ if (params === null || typeof params !== "object") {
7
+ throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
8
+ }
9
+ };
10
+ var assertRequiredFiniteNumber = (value, name) => {
11
+ if (typeof value !== "number" || !Number.isFinite(value)) {
12
+ throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
13
+ }
14
+ };
15
+ var assertRequiredColor = (value, name) => {
16
+ if (typeof value !== "string" || value.length === 0) {
17
+ throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
+ }
19
+ };
20
+
21
+ // src/color-utils.ts
22
+ var DEFAULT_AMOUNT = 1;
23
+ var DEFAULT_BRIGHTNESS_AMOUNT = 0;
24
+ var DEFAULT_HUE_DEGREES = 0;
25
+ var colorAmountSchema = {
26
+ type: "number",
27
+ min: 0,
28
+ max: 1,
29
+ step: 0.01,
30
+ default: DEFAULT_AMOUNT,
31
+ description: "Amount"
32
+ };
33
+ var colorMultiplierSchema = {
34
+ type: "number",
35
+ min: 0,
36
+ step: 0.01,
37
+ default: DEFAULT_AMOUNT,
38
+ description: "Amount"
39
+ };
40
+ var brightnessAmountSchema = {
41
+ type: "number",
42
+ min: -1,
43
+ max: 1,
44
+ step: 0.01,
45
+ default: DEFAULT_BRIGHTNESS_AMOUNT,
46
+ description: "Amount"
47
+ };
48
+ var hueDegreesSchema = {
49
+ type: "number",
50
+ step: 1,
51
+ default: DEFAULT_HUE_DEGREES,
52
+ description: "Degrees"
53
+ };
54
+ var assertOptionalFiniteNumber = (value, name) => {
55
+ if (value === undefined) {
56
+ return;
57
+ }
58
+ assertRequiredFiniteNumber(value, name);
59
+ };
60
+ var validateUnitInterval = (value, name) => {
61
+ if (value < 0) {
62
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
63
+ }
64
+ if (value > 1) {
65
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
66
+ }
67
+ };
68
+ var validateNonNegative = (value, name) => {
69
+ if (value < 0) {
70
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
71
+ }
72
+ };
73
+ var validateSignedUnitInterval = (value, name) => {
74
+ if (value < -1) {
75
+ throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
76
+ }
77
+ if (value > 1) {
78
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
79
+ }
80
+ };
81
+ var clampColorChannel = (value) => {
82
+ return Math.max(0, Math.min(255, value));
83
+ };
84
+
85
+ // src/invert.ts
86
+ var { createEffect } = Internals;
87
+ var invertSchema = {
88
+ amount: colorAmountSchema
89
+ };
90
+ var resolve = (p) => ({
91
+ amount: p.amount ?? DEFAULT_AMOUNT
92
+ });
93
+ var validateInvertParams = (params) => {
94
+ assertEffectParamsObject(params, "Invert");
95
+ assertOptionalFiniteNumber(params.amount, "amount");
96
+ const { amount } = resolve(params);
97
+ validateUnitInterval(amount, "amount");
98
+ };
99
+ var invert = createEffect({
100
+ type: "remotion/invert",
101
+ label: "Invert",
102
+ documentationLink: "https://www.remotion.dev/docs/effects/invert",
103
+ backend: "2d",
104
+ calculateKey: (params) => {
105
+ const r = resolve(params);
106
+ return `invert-${r.amount}`;
107
+ },
108
+ setup: () => null,
109
+ apply: ({ source, target, width, height, params }) => {
110
+ const ctx = target.getContext("2d");
111
+ if (!ctx) {
112
+ throw new Error("Failed to acquire 2D context for invert effect. The canvas may have been assigned a different context type.");
113
+ }
114
+ const r = resolve(params);
115
+ ctx.clearRect(0, 0, width, height);
116
+ ctx.filter = `invert(${r.amount * 100}%)`;
117
+ ctx.drawImage(source, 0, 0, width, height);
118
+ ctx.filter = "none";
119
+ },
120
+ cleanup: () => {
121
+ return;
122
+ },
123
+ schema: invertSchema,
124
+ validateParams: validateInvertParams
125
+ });
126
+ export {
127
+ invert
128
+ };