@remotion/effects 4.0.541 → 4.0.543

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.
Files changed (133) hide show
  1. package/THIRD_PARTY_LICENSES.md +10 -0
  2. package/dist/esm/lightning.mjs +603 -0
  3. package/dist/esm/magnify.mjs +403 -0
  4. package/dist/esm/preview/barrel-distortion.mjs +303 -0
  5. package/dist/esm/preview/bevel-alpha.mjs +525 -0
  6. package/dist/esm/preview/blur.mjs +435 -0
  7. package/dist/esm/preview/brightness.mjs +95 -0
  8. package/dist/esm/preview/burlap.mjs +481 -0
  9. package/dist/esm/preview/checkerboard.mjs +8 -0
  10. package/dist/esm/preview/chromatic-aberration.mjs +308 -0
  11. package/dist/esm/preview/color-correction.mjs +522 -0
  12. package/dist/esm/preview/color-key.mjs +440 -0
  13. package/dist/esm/preview/contour-lines.mjs +608 -0
  14. package/dist/esm/preview/contrast.mjs +95 -0
  15. package/dist/esm/preview/corner-pin.mjs +6 -0
  16. package/dist/esm/preview/curves.mjs +357 -0
  17. package/dist/esm/preview/cylinder.mjs +273 -0
  18. package/dist/esm/preview/dot-grid.mjs +333 -0
  19. package/dist/esm/preview/drop-shadow.mjs +607 -0
  20. package/dist/esm/preview/duotone.mjs +344 -0
  21. package/dist/esm/preview/emboss.mjs +479 -0
  22. package/dist/esm/preview/evolve.mjs +485 -0
  23. package/dist/esm/preview/exposure.mjs +264 -0
  24. package/dist/esm/preview/film-burn.mjs +298 -0
  25. package/dist/esm/preview/fisheye.mjs +422 -0
  26. package/dist/esm/preview/flannel.mjs +401 -0
  27. package/dist/esm/preview/fractal-noise.mjs +642 -0
  28. package/dist/esm/preview/glow.mjs +598 -0
  29. package/dist/esm/preview/grayscale.mjs +86 -0
  30. package/dist/esm/preview/gridlines.mjs +8 -0
  31. package/dist/esm/preview/halftone-linear-gradient.mjs +523 -0
  32. package/dist/esm/preview/halftone.mjs +552 -0
  33. package/dist/esm/preview/hue.mjs +83 -0
  34. package/dist/esm/preview/index-00v3hr66.mjs +299 -0
  35. package/dist/esm/preview/index-0w4eqht8.mjs +351 -0
  36. package/dist/esm/preview/index-18y0zcy2.mjs +440 -0
  37. package/dist/esm/preview/index-1m1b1ad7.mjs +520 -0
  38. package/dist/esm/preview/index-34fxm3ax.mjs +518 -0
  39. package/dist/esm/preview/index-4fvp93ps.mjs +32 -0
  40. package/dist/esm/preview/index-4scpn12x.mjs +224 -0
  41. package/dist/esm/preview/index-4z6pt3ka.mjs +104 -0
  42. package/dist/esm/preview/index-618ky75w.mjs +51 -0
  43. package/dist/esm/preview/index-6agxdrvr.mjs +411 -0
  44. package/dist/esm/preview/index-6jkps947.mjs +120 -0
  45. package/dist/esm/preview/index-8agtsbw4.mjs +617 -0
  46. package/dist/esm/preview/index-8jx11jyn.mjs +29 -0
  47. package/dist/esm/preview/index-8p04sssx.mjs +123 -0
  48. package/dist/esm/preview/index-afdtmrh2.mjs +596 -0
  49. package/dist/esm/preview/index-b86qstcs.mjs +18 -0
  50. package/dist/esm/preview/index-cb77qg3g.mjs +587 -0
  51. package/dist/esm/preview/index-cdp7tr8x.mjs +122 -0
  52. package/dist/esm/preview/index-evy8hyah.mjs +55 -0
  53. package/dist/esm/preview/index-gnsce796.mjs +6 -0
  54. package/dist/esm/preview/index-kkvzt8b7.mjs +199 -0
  55. package/dist/esm/preview/index-r0v18b2n.mjs +425 -0
  56. package/dist/esm/preview/index-rswpzmm5.mjs +926 -0
  57. package/dist/esm/preview/index-s9mrx750.mjs +97 -0
  58. package/dist/esm/preview/index-tvfexb7s.mjs +164 -0
  59. package/dist/esm/preview/index-vp56k1gj.mjs +215 -0
  60. package/dist/esm/preview/index-wxhvgv2s.mjs +79 -0
  61. package/dist/esm/preview/index-wy95a41r.mjs +407 -0
  62. package/dist/esm/preview/index-ysnwfc4t.mjs +306 -0
  63. package/dist/esm/preview/index.mjs +51 -0
  64. package/dist/esm/preview/invert.mjs +84 -0
  65. package/dist/esm/preview/iris-wipe.mjs +315 -0
  66. package/dist/esm/preview/lens-blur.mjs +563 -0
  67. package/dist/esm/preview/levels.mjs +400 -0
  68. package/dist/esm/preview/light-leak.mjs +8 -0
  69. package/dist/esm/preview/light-trail.mjs +516 -0
  70. package/dist/esm/preview/lightning.mjs +603 -0
  71. package/dist/esm/preview/linear-gradient-tint.mjs +6 -0
  72. package/dist/esm/preview/linear-gradient.mjs +6 -0
  73. package/dist/esm/preview/linear-progressive-blur.mjs +516 -0
  74. package/dist/esm/preview/linear-progressive-pixelate.mjs +176 -0
  75. package/dist/esm/preview/lines.mjs +536 -0
  76. package/dist/esm/preview/liquid-contours.mjs +512 -0
  77. package/dist/esm/preview/long-shadows.mjs +437 -0
  78. package/dist/esm/preview/lut.mjs +601 -0
  79. package/dist/esm/preview/magnify.mjs +403 -0
  80. package/dist/esm/preview/mirror.mjs +341 -0
  81. package/dist/esm/preview/noise-displacement.mjs +584 -0
  82. package/dist/esm/preview/noise.mjs +318 -0
  83. package/dist/esm/preview/outline.mjs +725 -0
  84. package/dist/esm/preview/page-turn.mjs +302 -0
  85. package/dist/esm/preview/paper.mjs +1249 -0
  86. package/dist/esm/preview/pattern.mjs +6 -0
  87. package/dist/esm/preview/pixel-dissolve.mjs +360 -0
  88. package/dist/esm/preview/pixelate.mjs +249 -0
  89. package/dist/esm/preview/radial-progressive-blur.mjs +582 -0
  90. package/dist/esm/preview/radial-progressive-pixelate.mjs +220 -0
  91. package/dist/esm/preview/radial-wipe.mjs +224 -0
  92. package/dist/esm/preview/rain-fall.mjs +114 -0
  93. package/dist/esm/preview/region-blur.mjs +500 -0
  94. package/dist/esm/preview/rings.mjs +8 -0
  95. package/dist/esm/preview/roughen-edges.mjs +590 -0
  96. package/dist/esm/preview/saturation.mjs +86 -0
  97. package/dist/esm/preview/scale.mjs +109 -0
  98. package/dist/esm/preview/scanlines.mjs +362 -0
  99. package/dist/esm/preview/shadows-highlights.mjs +284 -0
  100. package/dist/esm/preview/shatter.mjs +868 -0
  101. package/dist/esm/preview/shine.mjs +368 -0
  102. package/dist/esm/preview/shrinkwrap.mjs +769 -0
  103. package/dist/esm/preview/skew.mjs +300 -0
  104. package/dist/esm/preview/snow-fall.mjs +170 -0
  105. package/dist/esm/preview/speckle.mjs +356 -0
  106. package/dist/esm/preview/sphere.mjs +252 -0
  107. package/dist/esm/preview/starburst.mjs +8 -0
  108. package/dist/esm/preview/tear.mjs +375 -0
  109. package/dist/esm/preview/thermal-vision.mjs +387 -0
  110. package/dist/esm/preview/tile.mjs +7 -0
  111. package/dist/esm/preview/tint.mjs +125 -0
  112. package/dist/esm/preview/translate.mjs +151 -0
  113. package/dist/esm/preview/turbulent-displace.mjs +613 -0
  114. package/dist/esm/preview/tv-signal-off.mjs +308 -0
  115. package/dist/esm/preview/venetian-blinds.mjs +341 -0
  116. package/dist/esm/preview/vibrance.mjs +254 -0
  117. package/dist/esm/preview/vignette.mjs +458 -0
  118. package/dist/esm/preview/wave.mjs +384 -0
  119. package/dist/esm/preview/waves.mjs +599 -0
  120. package/dist/esm/preview/white-balance.mjs +280 -0
  121. package/dist/esm/preview/white-noise.mjs +244 -0
  122. package/dist/esm/preview/zigzag.mjs +8 -0
  123. package/dist/esm/preview/zoom-blur.mjs +389 -0
  124. package/dist/lightning/geometry.d.ts +10 -0
  125. package/dist/lightning/index.d.ts +4 -0
  126. package/dist/lightning/mask.d.ts +2 -0
  127. package/dist/lightning/params.d.ts +259 -0
  128. package/dist/lightning/shaders.d.ts +2 -0
  129. package/dist/lightning.d.ts +2 -0
  130. package/dist/magnify/shader.d.ts +1 -0
  131. package/dist/magnify/webgpu-shader.d.ts +1 -0
  132. package/dist/magnify.d.ts +28 -0
  133. package/package.json +30 -6
@@ -0,0 +1,522 @@
1
+ import {
2
+ COLOR_SPACE_GLSL,
3
+ WHITE_BALANCE_GLSL,
4
+ SHADOWS_HIGHLIGHTS_GLSL,
5
+ VIBRANCE_GLSL,
6
+ COLOR_SPACE_WGSL,
7
+ WHITE_BALANCE_WGSL,
8
+ SHADOWS_HIGHLIGHTS_WGSL,
9
+ VIBRANCE_WGSL
10
+ } from "./index-6jkps947.mjs";
11
+ import {
12
+ assertOptionalFiniteNumber,
13
+ validateUnitInterval,
14
+ validateNonNegative,
15
+ validateSignedUnitInterval
16
+ } from "./index-wxhvgv2s.mjs";
17
+ import {
18
+ WEBGPU_SINGLE_PASS_VERTEX,
19
+ setupWebGpuSinglePass,
20
+ cleanupWebGpuSinglePass,
21
+ applyWebGpuSinglePass
22
+ } from "./index-tvfexb7s.mjs";
23
+ import {
24
+ assertEffectParamsObject
25
+ } from "./index-4fvp93ps.mjs";
26
+
27
+ // src/color-correction.ts
28
+ import { Internals } from "remotion";
29
+ var { createEffect, createWebGL2ContextError } = Internals;
30
+ var DEFAULT_EXPOSURE = 0;
31
+ var DEFAULT_CONTRAST = 1;
32
+ var DEFAULT_PIVOT = 0.5;
33
+ var DEFAULT_SHADOWS = 0;
34
+ var DEFAULT_HIGHLIGHTS = 0;
35
+ var DEFAULT_WHITES = 0;
36
+ var DEFAULT_BLACKS = 0;
37
+ var DEFAULT_TEMPERATURE = 0;
38
+ var DEFAULT_TINT = 0;
39
+ var DEFAULT_SATURATION = 1;
40
+ var DEFAULT_VIBRANCE = 0;
41
+ var MIN_EXPOSURE = -5;
42
+ var MAX_EXPOSURE = 5;
43
+ var signedAdjustmentSchema = (description) => ({
44
+ type: "number",
45
+ min: -1,
46
+ max: 1,
47
+ step: 0.01,
48
+ default: 0,
49
+ description,
50
+ hiddenFromList: false
51
+ });
52
+ var colorCorrectionSchema = {
53
+ exposure: {
54
+ type: "number",
55
+ min: MIN_EXPOSURE,
56
+ max: MAX_EXPOSURE,
57
+ step: 0.1,
58
+ default: DEFAULT_EXPOSURE,
59
+ description: "Exposure",
60
+ hiddenFromList: false
61
+ },
62
+ contrast: {
63
+ type: "number",
64
+ min: 0,
65
+ max: 3,
66
+ step: 0.01,
67
+ default: DEFAULT_CONTRAST,
68
+ description: "Contrast",
69
+ hiddenFromList: false
70
+ },
71
+ pivot: {
72
+ type: "number",
73
+ min: 0,
74
+ max: 1,
75
+ step: 0.01,
76
+ default: DEFAULT_PIVOT,
77
+ description: "Contrast pivot",
78
+ hiddenFromList: false
79
+ },
80
+ shadows: signedAdjustmentSchema("Shadows"),
81
+ highlights: signedAdjustmentSchema("Highlights"),
82
+ whites: signedAdjustmentSchema("Whites"),
83
+ blacks: signedAdjustmentSchema("Blacks"),
84
+ temperature: signedAdjustmentSchema("Temperature"),
85
+ tint: signedAdjustmentSchema("Tint"),
86
+ saturation: {
87
+ type: "number",
88
+ min: 0,
89
+ max: 3,
90
+ step: 0.01,
91
+ default: DEFAULT_SATURATION,
92
+ description: "Saturation",
93
+ hiddenFromList: false
94
+ },
95
+ vibrance: signedAdjustmentSchema("Vibrance")
96
+ };
97
+ var resolve = (params) => ({
98
+ exposure: params.exposure ?? DEFAULT_EXPOSURE,
99
+ contrast: params.contrast ?? DEFAULT_CONTRAST,
100
+ pivot: params.pivot ?? DEFAULT_PIVOT,
101
+ shadows: params.shadows ?? DEFAULT_SHADOWS,
102
+ highlights: params.highlights ?? DEFAULT_HIGHLIGHTS,
103
+ whites: params.whites ?? DEFAULT_WHITES,
104
+ blacks: params.blacks ?? DEFAULT_BLACKS,
105
+ temperature: params.temperature ?? DEFAULT_TEMPERATURE,
106
+ tint: params.tint ?? DEFAULT_TINT,
107
+ saturation: params.saturation ?? DEFAULT_SATURATION,
108
+ vibrance: params.vibrance ?? DEFAULT_VIBRANCE
109
+ });
110
+ var validateColorCorrectionParams = (params) => {
111
+ assertEffectParamsObject(params, "Color correction");
112
+ assertOptionalFiniteNumber(params.exposure, "exposure");
113
+ assertOptionalFiniteNumber(params.contrast, "contrast");
114
+ assertOptionalFiniteNumber(params.pivot, "pivot");
115
+ assertOptionalFiniteNumber(params.shadows, "shadows");
116
+ assertOptionalFiniteNumber(params.highlights, "highlights");
117
+ assertOptionalFiniteNumber(params.whites, "whites");
118
+ assertOptionalFiniteNumber(params.blacks, "blacks");
119
+ assertOptionalFiniteNumber(params.temperature, "temperature");
120
+ assertOptionalFiniteNumber(params.tint, "tint");
121
+ assertOptionalFiniteNumber(params.saturation, "saturation");
122
+ assertOptionalFiniteNumber(params.vibrance, "vibrance");
123
+ const resolved = resolve(params);
124
+ if (resolved.exposure < MIN_EXPOSURE) {
125
+ throw new TypeError(`"exposure" must be >= ${MIN_EXPOSURE}, but got ${JSON.stringify(resolved.exposure)}`);
126
+ }
127
+ if (resolved.exposure > MAX_EXPOSURE) {
128
+ throw new TypeError(`"exposure" must be <= ${MAX_EXPOSURE}, but got ${JSON.stringify(resolved.exposure)}`);
129
+ }
130
+ validateNonNegative(resolved.contrast, "contrast");
131
+ validateUnitInterval(resolved.pivot, "pivot");
132
+ validateSignedUnitInterval(resolved.shadows, "shadows");
133
+ validateSignedUnitInterval(resolved.highlights, "highlights");
134
+ validateSignedUnitInterval(resolved.whites, "whites");
135
+ validateSignedUnitInterval(resolved.blacks, "blacks");
136
+ validateSignedUnitInterval(resolved.temperature, "temperature");
137
+ validateSignedUnitInterval(resolved.tint, "tint");
138
+ validateNonNegative(resolved.saturation, "saturation");
139
+ validateSignedUnitInterval(resolved.vibrance, "vibrance");
140
+ };
141
+ var VERTEX_SHADER = `#version 300 es
142
+ in vec2 aPos;
143
+ in vec2 aUv;
144
+ out vec2 vUv;
145
+
146
+ void main() {
147
+ vUv = aUv;
148
+ gl_Position = vec4(aPos, 0.0, 1.0);
149
+ }
150
+ `;
151
+ var FRAGMENT_SHADER = `#version 300 es
152
+ precision highp float;
153
+
154
+ in vec2 vUv;
155
+ out vec4 fragColor;
156
+
157
+ uniform sampler2D uSource;
158
+ uniform float uExposure;
159
+ uniform float uContrast;
160
+ uniform float uPivot;
161
+ uniform float uShadows;
162
+ uniform float uHighlights;
163
+ uniform float uWhites;
164
+ uniform float uBlacks;
165
+ uniform float uTemperature;
166
+ uniform float uTint;
167
+ uniform float uSaturation;
168
+ uniform float uVibrance;
169
+
170
+ ${COLOR_SPACE_GLSL}
171
+ ${WHITE_BALANCE_GLSL}
172
+ ${SHADOWS_HIGHLIGHTS_GLSL}
173
+ ${VIBRANCE_GLSL}
174
+
175
+ vec3 applyEndpointTones(vec3 color, float blacks, float whites) {
176
+ float luminance = dot(color, vec3(0.2126, 0.7152, 0.0722));
177
+ float blackWeight = 1.0 - smoothstep(0.0, 0.35, luminance);
178
+ float whiteWeight = smoothstep(0.65, 1.0, luminance);
179
+ blackWeight *= blackWeight;
180
+ whiteWeight *= whiteWeight;
181
+
182
+ // Moving tones toward their named endpoint uses the full adjustment.
183
+ // Moving them away is damped to avoid flattening the image too aggressively.
184
+ if (blacks >= 0.0) {
185
+ color += (vec3(1.0) - color) * blacks * blackWeight * 0.2;
186
+ } else {
187
+ color *= 1.0 + blacks * blackWeight;
188
+ }
189
+
190
+ if (whites >= 0.0) {
191
+ color += (vec3(1.0) - color) * whites * whiteWeight;
192
+ } else {
193
+ color *= 1.0 + whites * whiteWeight * 0.2;
194
+ }
195
+
196
+ return clamp(color, 0.0, 1.0);
197
+ }
198
+
199
+ void main() {
200
+ vec4 sourceColor = texture(uSource, vUv);
201
+ float alpha = sourceColor.a;
202
+
203
+ if (alpha <= 0.0) {
204
+ fragColor = vec4(0.0);
205
+ return;
206
+ }
207
+
208
+ if (
209
+ uExposure == 0.0 &&
210
+ uContrast == 1.0 &&
211
+ uPivot == 0.5 &&
212
+ uShadows == 0.0 &&
213
+ uHighlights == 0.0 &&
214
+ uWhites == 0.0 &&
215
+ uBlacks == 0.0 &&
216
+ uTemperature == 0.0 &&
217
+ uTint == 0.0 &&
218
+ uSaturation == 1.0 &&
219
+ uVibrance == 0.0
220
+ ) {
221
+ fragColor = sourceColor;
222
+ return;
223
+ }
224
+
225
+ vec3 color = sourceColor.rgb / alpha;
226
+ vec3 linear = srgbToLinear(color) * exp2(uExposure);
227
+ linear = applyWhiteBalanceLinear(linear, uTemperature, uTint);
228
+ color = linearToSrgb(linear);
229
+
230
+ float tonalStops = getShadowsHighlightsStops(
231
+ color,
232
+ uShadows,
233
+ uHighlights
234
+ );
235
+ linear = srgbToLinear(color) * exp2(tonalStops);
236
+ color = linearToSrgb(linear);
237
+ color = applyEndpointTones(color, uBlacks, uWhites);
238
+ color = clamp((color - vec3(uPivot)) * uContrast + vec3(uPivot), 0.0, 1.0);
239
+
240
+ float luminance = dot(color, vec3(0.213, 0.715, 0.072));
241
+ color = clamp(
242
+ vec3(luminance) + (color - vec3(luminance)) * uSaturation,
243
+ 0.0,
244
+ 1.0
245
+ );
246
+ color = applyVibrance(color, uVibrance);
247
+
248
+ fragColor = vec4(color * alpha, alpha);
249
+ }
250
+ `;
251
+ var WEBGPU_SHADER = `
252
+ ${WEBGPU_SINGLE_PASS_VERTEX}
253
+ struct Params {
254
+ exposure: f32,
255
+ contrast: f32,
256
+ pivot: f32,
257
+ shadows: f32,
258
+ highlights: f32,
259
+ whites: f32,
260
+ blacks: f32,
261
+ temperature: f32,
262
+ tint: f32,
263
+ saturation: f32,
264
+ vibrance: f32,
265
+ padding0: f32,
266
+ }
267
+ @group(0) @binding(0) var source: texture_2d<f32>;
268
+ @group(0) @binding(1) var sourceSampler: sampler;
269
+ @group(0) @binding(2) var<uniform> params: Params;
270
+ ${COLOR_SPACE_WGSL}
271
+ ${WHITE_BALANCE_WGSL}
272
+ ${SHADOWS_HIGHLIGHTS_WGSL}
273
+ ${VIBRANCE_WGSL}
274
+
275
+ fn applyEndpointTones(inputColor: vec3f, blacks: f32, whites: f32) -> vec3f {
276
+ var color = inputColor;
277
+ let luminance = dot(color, vec3f(0.2126, 0.7152, 0.0722));
278
+ var blackWeight = 1.0 - smoothstep(0.0, 0.35, luminance);
279
+ var whiteWeight = smoothstep(0.65, 1.0, luminance);
280
+ blackWeight *= blackWeight;
281
+ whiteWeight *= whiteWeight;
282
+ if (blacks >= 0.0) {
283
+ color += (vec3f(1.0) - color) * blacks * blackWeight * 0.2;
284
+ } else {
285
+ color *= 1.0 + blacks * blackWeight;
286
+ }
287
+ if (whites >= 0.0) {
288
+ color += (vec3f(1.0) - color) * whites * whiteWeight;
289
+ } else {
290
+ color *= 1.0 + whites * whiteWeight * 0.2;
291
+ }
292
+ return clamp(color, vec3f(0.0), vec3f(1.0));
293
+ }
294
+
295
+ @fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
296
+ let sourceColor = textureSampleLevel(source, sourceSampler, input.uv, 0.0);
297
+ let alpha = sourceColor.a;
298
+ if (alpha <= 0.0) {
299
+ return vec4f(0.0);
300
+ }
301
+ if (
302
+ params.exposure == 0.0 && params.contrast == 1.0 && params.pivot == 0.5 &&
303
+ params.shadows == 0.0 && params.highlights == 0.0 && params.whites == 0.0 &&
304
+ params.blacks == 0.0 && params.temperature == 0.0 && params.tint == 0.0 &&
305
+ params.saturation == 1.0 && params.vibrance == 0.0
306
+ ) {
307
+ return sourceColor;
308
+ }
309
+ var color = sourceColor.rgb / alpha;
310
+ var linear = srgbToLinear(color) * exp2(params.exposure);
311
+ linear = applyWhiteBalanceLinear(linear, params.temperature, params.tint);
312
+ color = linearToSrgb(linear);
313
+ let tonalStops = getShadowsHighlightsStops(color, params.shadows, params.highlights);
314
+ linear = srgbToLinear(color) * exp2(tonalStops);
315
+ color = linearToSrgb(linear);
316
+ color = applyEndpointTones(color, params.blacks, params.whites);
317
+ color = clamp((color - vec3f(params.pivot)) * params.contrast + vec3f(params.pivot), vec3f(0.0), vec3f(1.0));
318
+ let luminance = dot(color, vec3f(0.213, 0.715, 0.072));
319
+ color = clamp(vec3f(luminance) + (color - vec3f(luminance)) * params.saturation, vec3f(0.0), vec3f(1.0));
320
+ color = applyVibrance(color, params.vibrance);
321
+ return vec4f(color * alpha, alpha);
322
+ }
323
+ `;
324
+ var compileShader = (gl, type, source) => {
325
+ const shader = gl.createShader(type);
326
+ if (!shader) {
327
+ throw new Error("Failed to create color correction shader");
328
+ }
329
+ gl.shaderSource(shader, source);
330
+ gl.compileShader(shader);
331
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
332
+ const log = gl.getShaderInfoLog(shader);
333
+ gl.deleteShader(shader);
334
+ throw new Error(`Color correction shader compile failed: ${log ?? "(no log)"}`);
335
+ }
336
+ return shader;
337
+ };
338
+ var createProgram = (gl) => {
339
+ const vertexShader = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
340
+ const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
341
+ const program = gl.createProgram();
342
+ if (!program) {
343
+ throw new Error("Failed to create color correction shader program");
344
+ }
345
+ gl.attachShader(program, vertexShader);
346
+ gl.attachShader(program, fragmentShader);
347
+ gl.linkProgram(program);
348
+ gl.deleteShader(vertexShader);
349
+ gl.deleteShader(fragmentShader);
350
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
351
+ const log = gl.getProgramInfoLog(program);
352
+ gl.deleteProgram(program);
353
+ throw new Error(`Color correction shader link failed: ${log ?? "(no log)"}`);
354
+ }
355
+ return program;
356
+ };
357
+ var createTexture = (gl) => {
358
+ const texture = gl.createTexture();
359
+ if (!texture) {
360
+ throw new Error("Failed to create color correction texture");
361
+ }
362
+ gl.bindTexture(gl.TEXTURE_2D, texture);
363
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
364
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
365
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
366
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
367
+ gl.bindTexture(gl.TEXTURE_2D, null);
368
+ return texture;
369
+ };
370
+ var setupColorCorrection = (target) => {
371
+ const gl = target.getContext("webgl2", {
372
+ premultipliedAlpha: true,
373
+ alpha: true,
374
+ preserveDrawingBuffer: true
375
+ });
376
+ if (!gl) {
377
+ throw createWebGL2ContextError("color correction effect");
378
+ }
379
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
380
+ const program = createProgram(gl);
381
+ const vao = gl.createVertexArray();
382
+ if (!vao) {
383
+ throw new Error("Failed to create color correction vertex array");
384
+ }
385
+ const vbo = gl.createBuffer();
386
+ if (!vbo) {
387
+ throw new Error("Failed to create color correction vertex buffer");
388
+ }
389
+ gl.bindVertexArray(vao);
390
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
391
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1]), gl.STATIC_DRAW);
392
+ const aPos = gl.getAttribLocation(program, "aPos");
393
+ const aUv = gl.getAttribLocation(program, "aUv");
394
+ gl.enableVertexAttribArray(aPos);
395
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
396
+ gl.enableVertexAttribArray(aUv);
397
+ gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
398
+ gl.bindVertexArray(null);
399
+ return {
400
+ gl,
401
+ program,
402
+ vao,
403
+ vbo,
404
+ textureSource: createTexture(gl),
405
+ uniforms: {
406
+ uSource: gl.getUniformLocation(program, "uSource"),
407
+ uExposure: gl.getUniformLocation(program, "uExposure"),
408
+ uContrast: gl.getUniformLocation(program, "uContrast"),
409
+ uPivot: gl.getUniformLocation(program, "uPivot"),
410
+ uShadows: gl.getUniformLocation(program, "uShadows"),
411
+ uHighlights: gl.getUniformLocation(program, "uHighlights"),
412
+ uWhites: gl.getUniformLocation(program, "uWhites"),
413
+ uBlacks: gl.getUniformLocation(program, "uBlacks"),
414
+ uTemperature: gl.getUniformLocation(program, "uTemperature"),
415
+ uTint: gl.getUniformLocation(program, "uTint"),
416
+ uSaturation: gl.getUniformLocation(program, "uSaturation"),
417
+ uVibrance: gl.getUniformLocation(program, "uVibrance")
418
+ }
419
+ };
420
+ };
421
+ var colorCorrection = createEffect({
422
+ type: "remotion/color-correction",
423
+ label: "colorCorrection()",
424
+ documentationLink: "https://www.remotion.dev/docs/effects/color-correction",
425
+ calculateKey: (params) => {
426
+ const r = resolve(params);
427
+ return `color-correction-${r.exposure}-${r.contrast}-${r.pivot}-${r.shadows}-${r.highlights}-${r.whites}-${r.blacks}-${r.temperature}-${r.tint}-${r.saturation}-${r.vibrance}`;
428
+ },
429
+ implementations: {
430
+ webgpu: Internals.createEffectImplementation({
431
+ setup: (target) => setupWebGpuSinglePass(target, "color correction"),
432
+ apply: ({ source, width, height, params, state, gpuDevice }) => {
433
+ if (!gpuDevice) {
434
+ throw new Error("A WebGPU device is required for the color correction effect");
435
+ }
436
+ const r = resolve(params);
437
+ applyWebGpuSinglePass({
438
+ state,
439
+ source,
440
+ width,
441
+ height,
442
+ device: gpuDevice,
443
+ shader: WEBGPU_SHADER,
444
+ uniformData: new Float32Array([
445
+ r.exposure,
446
+ r.contrast,
447
+ r.pivot,
448
+ r.shadows,
449
+ r.highlights,
450
+ r.whites,
451
+ r.blacks,
452
+ r.temperature,
453
+ r.tint,
454
+ r.saturation,
455
+ r.vibrance,
456
+ 0
457
+ ])
458
+ });
459
+ },
460
+ cleanup: cleanupWebGpuSinglePass
461
+ }),
462
+ webgl2: Internals.createEffectImplementation({
463
+ setup: setupColorCorrection,
464
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
465
+ const r = resolve(params);
466
+ const { gl, program, textureSource, uniforms, vao } = state;
467
+ gl.viewport(0, 0, width, height);
468
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
469
+ gl.clearColor(0, 0, 0, 0);
470
+ gl.clear(gl.COLOR_BUFFER_BIT);
471
+ gl.activeTexture(gl.TEXTURE0);
472
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
473
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
474
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
475
+ gl.useProgram(program);
476
+ if (uniforms.uSource)
477
+ gl.uniform1i(uniforms.uSource, 0);
478
+ if (uniforms.uExposure)
479
+ gl.uniform1f(uniforms.uExposure, r.exposure);
480
+ if (uniforms.uContrast)
481
+ gl.uniform1f(uniforms.uContrast, r.contrast);
482
+ if (uniforms.uPivot)
483
+ gl.uniform1f(uniforms.uPivot, r.pivot);
484
+ if (uniforms.uShadows)
485
+ gl.uniform1f(uniforms.uShadows, r.shadows);
486
+ if (uniforms.uHighlights) {
487
+ gl.uniform1f(uniforms.uHighlights, r.highlights);
488
+ }
489
+ if (uniforms.uWhites)
490
+ gl.uniform1f(uniforms.uWhites, r.whites);
491
+ if (uniforms.uBlacks)
492
+ gl.uniform1f(uniforms.uBlacks, r.blacks);
493
+ if (uniforms.uTemperature) {
494
+ gl.uniform1f(uniforms.uTemperature, r.temperature);
495
+ }
496
+ if (uniforms.uTint)
497
+ gl.uniform1f(uniforms.uTint, r.tint);
498
+ if (uniforms.uSaturation) {
499
+ gl.uniform1f(uniforms.uSaturation, r.saturation);
500
+ }
501
+ if (uniforms.uVibrance)
502
+ gl.uniform1f(uniforms.uVibrance, r.vibrance);
503
+ gl.bindVertexArray(vao);
504
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
505
+ gl.bindVertexArray(null);
506
+ gl.bindTexture(gl.TEXTURE_2D, null);
507
+ gl.useProgram(null);
508
+ },
509
+ cleanup: ({ gl, program, vao, vbo, textureSource }) => {
510
+ gl.deleteTexture(textureSource);
511
+ gl.deleteBuffer(vbo);
512
+ gl.deleteProgram(program);
513
+ gl.deleteVertexArray(vao);
514
+ }
515
+ })
516
+ },
517
+ schema: colorCorrectionSchema,
518
+ validateParams: validateColorCorrectionParams
519
+ });
520
+ export {
521
+ colorCorrection
522
+ };