@remotion/effects 4.0.465 → 4.0.467
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/dist/barrel-distortion/barrel-distortion-runtime.d.ts +21 -0
- package/dist/barrel-distortion/barrel-distortion-shaders.d.ts +2 -0
- package/dist/barrel-distortion/index.d.ts +7 -0
- package/dist/barrel-distortion.d.ts +1 -0
- package/dist/brightness.d.ts +7 -0
- package/dist/chromatic-aberration/chromatic-aberration-runtime.d.ts +22 -0
- package/dist/chromatic-aberration/chromatic-aberration-shaders.d.ts +2 -0
- package/dist/chromatic-aberration/index.d.ts +9 -0
- package/dist/chromatic-aberration.d.ts +1 -0
- package/dist/color-utils.d.ts +37 -0
- package/dist/contrast.d.ts +7 -0
- package/dist/esm/barrel-distortion.mjs +329 -0
- package/dist/esm/blur.mjs +2 -1
- package/dist/esm/brightness.mjs +138 -0
- package/dist/esm/chromatic-aberration.mjs +330 -0
- package/dist/esm/contrast.mjs +138 -0
- package/dist/esm/grayscale.mjs +128 -0
- package/dist/esm/halftone.mjs +178 -25
- package/dist/esm/hue.mjs +126 -0
- package/dist/esm/index.mjs +0 -428
- package/dist/esm/invert.mjs +128 -0
- package/dist/esm/mirror.mjs +358 -0
- package/dist/esm/saturation.mjs +128 -0
- package/dist/esm/scale.mjs +103 -0
- package/dist/esm/tint.mjs +72 -14
- package/dist/esm/translate.mjs +205 -0
- package/dist/esm/wave.mjs +1 -0
- package/dist/grayscale.d.ts +7 -0
- package/dist/halftone.d.ts +39 -10
- package/dist/hue.d.ts +7 -0
- package/dist/index.d.ts +1 -3
- package/dist/invert.d.ts +7 -0
- package/dist/mirror/index.d.ts +13 -0
- package/dist/mirror/mirror-runtime.d.ts +26 -0
- package/dist/mirror/mirror-shaders.d.ts +2 -0
- package/dist/mirror.d.ts +1 -0
- package/dist/saturation.d.ts +7 -0
- package/dist/scale/index.d.ts +11 -0
- package/dist/scale.d.ts +1 -0
- package/dist/translate/index.d.ts +18 -0
- package/dist/translate.d.ts +1 -0
- package/package.json +107 -3
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// src/chromatic-aberration/index.ts
|
|
2
|
+
import { Internals as Internals2 } 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/chromatic-aberration/chromatic-aberration-runtime.ts
|
|
86
|
+
import { Internals } from "remotion";
|
|
87
|
+
|
|
88
|
+
// src/chromatic-aberration/chromatic-aberration-shaders.ts
|
|
89
|
+
var CHROMATIC_ABERRATION_VS = `#version 300 es
|
|
90
|
+
layout(location = 0) in vec2 aPos;
|
|
91
|
+
layout(location = 1) in vec2 aUv;
|
|
92
|
+
out vec2 vUv;
|
|
93
|
+
void main() {
|
|
94
|
+
vUv = aUv;
|
|
95
|
+
gl_Position = vec4(aPos, 0.0, 1.0);
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
var CHROMATIC_ABERRATION_FS = `#version 300 es
|
|
99
|
+
precision highp float;
|
|
100
|
+
in vec2 vUv;
|
|
101
|
+
out vec4 fragColor;
|
|
102
|
+
|
|
103
|
+
uniform sampler2D uSource;
|
|
104
|
+
uniform vec2 uOffset;
|
|
105
|
+
|
|
106
|
+
void main() {
|
|
107
|
+
vec4 redSample = texture(uSource, vUv - uOffset);
|
|
108
|
+
vec4 centerSample = texture(uSource, vUv);
|
|
109
|
+
vec4 blueSample = texture(uSource, vUv + uOffset);
|
|
110
|
+
|
|
111
|
+
fragColor = vec4(redSample.r, centerSample.g, blueSample.b, centerSample.a);
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
// src/chromatic-aberration/chromatic-aberration-runtime.ts
|
|
116
|
+
var { createWebGL2ContextError } = Internals;
|
|
117
|
+
var compileShader = (gl, type, source) => {
|
|
118
|
+
const shader = gl.createShader(type);
|
|
119
|
+
if (!shader) {
|
|
120
|
+
throw new Error("Failed to create WebGL shader");
|
|
121
|
+
}
|
|
122
|
+
gl.shaderSource(shader, source);
|
|
123
|
+
gl.compileShader(shader);
|
|
124
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
125
|
+
const log = gl.getShaderInfoLog(shader);
|
|
126
|
+
gl.deleteShader(shader);
|
|
127
|
+
throw new Error(`Shader compile failed: ${log ?? "(no log)"}`);
|
|
128
|
+
}
|
|
129
|
+
return shader;
|
|
130
|
+
};
|
|
131
|
+
var linkProgram = (gl, vs, fs) => {
|
|
132
|
+
const program = gl.createProgram();
|
|
133
|
+
if (!program) {
|
|
134
|
+
throw new Error("Failed to create WebGL program");
|
|
135
|
+
}
|
|
136
|
+
gl.attachShader(program, vs);
|
|
137
|
+
gl.attachShader(program, fs);
|
|
138
|
+
gl.linkProgram(program);
|
|
139
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
140
|
+
const log = gl.getProgramInfoLog(program);
|
|
141
|
+
gl.deleteProgram(program);
|
|
142
|
+
throw new Error(`Program link failed: ${log ?? "(no log)"}`);
|
|
143
|
+
}
|
|
144
|
+
return program;
|
|
145
|
+
};
|
|
146
|
+
var createProgram = (gl, vertexSource, fragmentSource) => {
|
|
147
|
+
const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
|
|
148
|
+
const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
149
|
+
const program = linkProgram(gl, vs, fs);
|
|
150
|
+
gl.deleteShader(vs);
|
|
151
|
+
gl.deleteShader(fs);
|
|
152
|
+
return program;
|
|
153
|
+
};
|
|
154
|
+
var createRgbaTexture = (gl) => {
|
|
155
|
+
const texture = gl.createTexture();
|
|
156
|
+
if (!texture) {
|
|
157
|
+
throw new Error("Failed to create WebGL texture");
|
|
158
|
+
}
|
|
159
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
160
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
161
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
162
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
163
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
164
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
165
|
+
return texture;
|
|
166
|
+
};
|
|
167
|
+
var setupChromaticAberration = (target) => {
|
|
168
|
+
const gl = target.getContext("webgl2", {
|
|
169
|
+
premultipliedAlpha: true,
|
|
170
|
+
alpha: true,
|
|
171
|
+
preserveDrawingBuffer: true
|
|
172
|
+
});
|
|
173
|
+
if (!gl) {
|
|
174
|
+
throw createWebGL2ContextError("chromatic aberration effect");
|
|
175
|
+
}
|
|
176
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
177
|
+
const program = createProgram(gl, CHROMATIC_ABERRATION_VS, CHROMATIC_ABERRATION_FS);
|
|
178
|
+
const vao = gl.createVertexArray();
|
|
179
|
+
if (!vao) {
|
|
180
|
+
throw new Error("Failed to create WebGL vertex array");
|
|
181
|
+
}
|
|
182
|
+
gl.bindVertexArray(vao);
|
|
183
|
+
const data = new Float32Array([
|
|
184
|
+
-1,
|
|
185
|
+
-1,
|
|
186
|
+
0,
|
|
187
|
+
0,
|
|
188
|
+
1,
|
|
189
|
+
-1,
|
|
190
|
+
1,
|
|
191
|
+
0,
|
|
192
|
+
-1,
|
|
193
|
+
1,
|
|
194
|
+
0,
|
|
195
|
+
1,
|
|
196
|
+
1,
|
|
197
|
+
1,
|
|
198
|
+
1,
|
|
199
|
+
1
|
|
200
|
+
]);
|
|
201
|
+
const vbo = gl.createBuffer();
|
|
202
|
+
if (!vbo) {
|
|
203
|
+
throw new Error("Failed to create WebGL buffer");
|
|
204
|
+
}
|
|
205
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
206
|
+
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
207
|
+
gl.enableVertexAttribArray(0);
|
|
208
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
|
|
209
|
+
gl.enableVertexAttribArray(1);
|
|
210
|
+
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
|
|
211
|
+
gl.bindVertexArray(null);
|
|
212
|
+
const textureSource = createRgbaTexture(gl);
|
|
213
|
+
return {
|
|
214
|
+
gl,
|
|
215
|
+
program,
|
|
216
|
+
vao,
|
|
217
|
+
vbo,
|
|
218
|
+
textureSource,
|
|
219
|
+
uniforms: {
|
|
220
|
+
uSource: gl.getUniformLocation(program, "uSource"),
|
|
221
|
+
uOffset: gl.getUniformLocation(program, "uOffset")
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
var cleanupChromaticAberration = (state) => {
|
|
226
|
+
const { gl, program, vao, vbo, textureSource } = state;
|
|
227
|
+
gl.deleteTexture(textureSource);
|
|
228
|
+
gl.deleteBuffer(vbo);
|
|
229
|
+
gl.deleteProgram(program);
|
|
230
|
+
gl.deleteVertexArray(vao);
|
|
231
|
+
};
|
|
232
|
+
var drawFullscreenQuad = (state) => {
|
|
233
|
+
const { gl, vao } = state;
|
|
234
|
+
gl.bindVertexArray(vao);
|
|
235
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
236
|
+
gl.bindVertexArray(null);
|
|
237
|
+
};
|
|
238
|
+
var applyChromaticAberration = ({
|
|
239
|
+
state,
|
|
240
|
+
source,
|
|
241
|
+
width,
|
|
242
|
+
height,
|
|
243
|
+
amount,
|
|
244
|
+
angle,
|
|
245
|
+
flipSourceY
|
|
246
|
+
}) => {
|
|
247
|
+
const { gl, program, textureSource, uniforms } = state;
|
|
248
|
+
const radians = angle * Math.PI / 180;
|
|
249
|
+
const x = Math.cos(radians) * amount / width;
|
|
250
|
+
const y = Math.sin(radians) * amount / height;
|
|
251
|
+
gl.viewport(0, 0, width, height);
|
|
252
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
|
|
253
|
+
gl.bindTexture(gl.TEXTURE_2D, textureSource);
|
|
254
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
255
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
256
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
257
|
+
gl.clearColor(0, 0, 0, 0);
|
|
258
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
259
|
+
gl.useProgram(program);
|
|
260
|
+
if (uniforms.uSource)
|
|
261
|
+
gl.uniform1i(uniforms.uSource, 0);
|
|
262
|
+
if (uniforms.uOffset)
|
|
263
|
+
gl.uniform2f(uniforms.uOffset, x, y);
|
|
264
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
265
|
+
gl.bindTexture(gl.TEXTURE_2D, textureSource);
|
|
266
|
+
drawFullscreenQuad(state);
|
|
267
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
268
|
+
gl.useProgram(null);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/chromatic-aberration/index.ts
|
|
272
|
+
var { createEffect } = Internals2;
|
|
273
|
+
var DEFAULT_CHROMATIC_ABERRATION_AMOUNT = 8;
|
|
274
|
+
var DEFAULT_CHROMATIC_ABERRATION_ANGLE = 0;
|
|
275
|
+
var chromaticAberrationSchema = {
|
|
276
|
+
amount: {
|
|
277
|
+
type: "number",
|
|
278
|
+
min: 0,
|
|
279
|
+
max: 100,
|
|
280
|
+
step: 1,
|
|
281
|
+
default: DEFAULT_CHROMATIC_ABERRATION_AMOUNT,
|
|
282
|
+
description: "Amount"
|
|
283
|
+
},
|
|
284
|
+
angle: {
|
|
285
|
+
type: "number",
|
|
286
|
+
step: 1,
|
|
287
|
+
default: DEFAULT_CHROMATIC_ABERRATION_ANGLE,
|
|
288
|
+
description: "Angle"
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
var resolve = (params) => ({
|
|
292
|
+
amount: params.amount ?? DEFAULT_CHROMATIC_ABERRATION_AMOUNT,
|
|
293
|
+
angle: params.angle ?? DEFAULT_CHROMATIC_ABERRATION_ANGLE
|
|
294
|
+
});
|
|
295
|
+
var validateChromaticAberrationParams = (params) => {
|
|
296
|
+
assertEffectParamsObject(params, "Chromatic Aberration");
|
|
297
|
+
assertOptionalFiniteNumber(params.amount, "amount");
|
|
298
|
+
assertOptionalFiniteNumber(params.angle, "angle");
|
|
299
|
+
const resolved = resolve(params);
|
|
300
|
+
validateNonNegative(resolved.amount, "amount");
|
|
301
|
+
};
|
|
302
|
+
var chromaticAberration = createEffect({
|
|
303
|
+
type: "remotion/chromatic-aberration",
|
|
304
|
+
label: "Chromatic Aberration",
|
|
305
|
+
documentationLink: "https://www.remotion.dev/docs/effects/chromatic-aberration",
|
|
306
|
+
backend: "webgl2",
|
|
307
|
+
calculateKey: (params) => {
|
|
308
|
+
const resolved = resolve(params);
|
|
309
|
+
return `chromatic-aberration-${resolved.amount}-${resolved.angle}`;
|
|
310
|
+
},
|
|
311
|
+
setup: (target) => setupChromaticAberration(target),
|
|
312
|
+
apply: ({ source, width, height, params, state, flipSourceY }) => {
|
|
313
|
+
const resolved = resolve(params);
|
|
314
|
+
applyChromaticAberration({
|
|
315
|
+
state,
|
|
316
|
+
source,
|
|
317
|
+
width,
|
|
318
|
+
height,
|
|
319
|
+
amount: resolved.amount,
|
|
320
|
+
angle: resolved.angle,
|
|
321
|
+
flipSourceY
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
cleanup: (state) => cleanupChromaticAberration(state),
|
|
325
|
+
schema: chromaticAberrationSchema,
|
|
326
|
+
validateParams: validateChromaticAberrationParams
|
|
327
|
+
});
|
|
328
|
+
export {
|
|
329
|
+
chromaticAberration
|
|
330
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// src/contrast.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/contrast.ts
|
|
86
|
+
var { createEffect } = Internals;
|
|
87
|
+
var contrastSchema = {
|
|
88
|
+
amount: colorMultiplierSchema
|
|
89
|
+
};
|
|
90
|
+
var resolve = (p) => ({
|
|
91
|
+
amount: p.amount ?? DEFAULT_AMOUNT
|
|
92
|
+
});
|
|
93
|
+
var validateContrastParams = (params) => {
|
|
94
|
+
assertEffectParamsObject(params, "Contrast");
|
|
95
|
+
assertOptionalFiniteNumber(params.amount, "amount");
|
|
96
|
+
const { amount } = resolve(params);
|
|
97
|
+
validateNonNegative(amount, "amount");
|
|
98
|
+
};
|
|
99
|
+
var contrast = createEffect({
|
|
100
|
+
type: "remotion/contrast",
|
|
101
|
+
label: "Contrast",
|
|
102
|
+
documentationLink: "https://www.remotion.dev/docs/effects/contrast",
|
|
103
|
+
backend: "2d",
|
|
104
|
+
calculateKey: (params) => {
|
|
105
|
+
const r = resolve(params);
|
|
106
|
+
return `contrast-${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 contrast 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.drawImage(source, 0, 0, width, height);
|
|
117
|
+
if (r.amount === 1) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const imageData = ctx.getImageData(0, 0, width, height);
|
|
121
|
+
const { data } = imageData;
|
|
122
|
+
const factor = r.amount;
|
|
123
|
+
for (let i = 0;i < data.length; i += 4) {
|
|
124
|
+
data[i] = clampColorChannel((data[i] - 128) * factor + 128);
|
|
125
|
+
data[i + 1] = clampColorChannel((data[i + 1] - 128) * factor + 128);
|
|
126
|
+
data[i + 2] = clampColorChannel((data[i + 2] - 128) * factor + 128);
|
|
127
|
+
}
|
|
128
|
+
ctx.putImageData(imageData, 0, 0);
|
|
129
|
+
},
|
|
130
|
+
cleanup: () => {
|
|
131
|
+
return;
|
|
132
|
+
},
|
|
133
|
+
schema: contrastSchema,
|
|
134
|
+
validateParams: validateContrastParams
|
|
135
|
+
});
|
|
136
|
+
export {
|
|
137
|
+
contrast
|
|
138
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// src/grayscale.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/grayscale.ts
|
|
86
|
+
var { createEffect } = Internals;
|
|
87
|
+
var grayscaleSchema = {
|
|
88
|
+
amount: colorAmountSchema
|
|
89
|
+
};
|
|
90
|
+
var resolve = (p) => ({
|
|
91
|
+
amount: p.amount ?? DEFAULT_AMOUNT
|
|
92
|
+
});
|
|
93
|
+
var validateGrayscaleParams = (params) => {
|
|
94
|
+
assertEffectParamsObject(params, "Grayscale");
|
|
95
|
+
assertOptionalFiniteNumber(params.amount, "amount");
|
|
96
|
+
const { amount } = resolve(params);
|
|
97
|
+
validateUnitInterval(amount, "amount");
|
|
98
|
+
};
|
|
99
|
+
var grayscale = createEffect({
|
|
100
|
+
type: "remotion/grayscale",
|
|
101
|
+
label: "Grayscale",
|
|
102
|
+
documentationLink: "https://www.remotion.dev/docs/effects/grayscale",
|
|
103
|
+
backend: "2d",
|
|
104
|
+
calculateKey: (params) => {
|
|
105
|
+
const r = resolve(params);
|
|
106
|
+
return `grayscale-${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 grayscale 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 = `grayscale(${r.amount * 100}%)`;
|
|
117
|
+
ctx.drawImage(source, 0, 0, width, height);
|
|
118
|
+
ctx.filter = "none";
|
|
119
|
+
},
|
|
120
|
+
cleanup: () => {
|
|
121
|
+
return;
|
|
122
|
+
},
|
|
123
|
+
schema: grayscaleSchema,
|
|
124
|
+
validateParams: validateGrayscaleParams
|
|
125
|
+
});
|
|
126
|
+
export {
|
|
127
|
+
grayscale
|
|
128
|
+
};
|