@remotion/effects 4.0.540 → 4.0.542

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,97 @@
1
+ import {
2
+ setupSinglePass,
3
+ prepareSinglePassSource,
4
+ drawSinglePass,
5
+ cleanupSinglePass
6
+ } from "./index-8p04sssx.mjs";
7
+ import {
8
+ WEBGPU_SINGLE_PASS_VERTEX,
9
+ setupWebGpuSinglePass,
10
+ cleanupWebGpuSinglePass,
11
+ applyWebGpuSinglePass
12
+ } from "./index-tvfexb7s.mjs";
13
+
14
+ // src/rect-transform-runtime.ts
15
+ import { Internals } from "remotion";
16
+ var WEBGL_SHADER = `#version 300 es
17
+ precision highp float;
18
+ in vec2 vUv;
19
+ out vec4 fragColor;
20
+ uniform sampler2D uSource;
21
+ uniform vec2 uResolution;
22
+ uniform vec4 uRect;
23
+ void main() {
24
+ vec2 p = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y);
25
+ vec2 coverage = clamp(min(p + 0.5, uRect.xy + uRect.zw) - max(p - 0.5, uRect.xy), 0.0, 1.0);
26
+ vec2 uv = (p - uRect.xy) / uRect.zw;
27
+ if (any(lessThanEqual(uv, vec2(0.0))) || any(greaterThan(uv, vec2(1.0)))) { fragColor = vec4(0.0); return; }
28
+ fragColor = texture(uSource, vec2(uv.x, 1.0 - uv.y)) * min(coverage.x, coverage.y);
29
+ }
30
+ `;
31
+ var WEBGPU_SHADER = `
32
+ ${WEBGPU_SINGLE_PASS_VERTEX}
33
+ struct Params {
34
+ resolution: vec2f,
35
+ padding: vec2f,
36
+ rect: vec4f,
37
+ }
38
+ @group(0) @binding(0) var source: texture_2d<f32>;
39
+ @group(0) @binding(1) var sourceSampler: sampler;
40
+ @group(0) @binding(2) var<uniform> params: Params;
41
+ @fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
42
+ let p = input.position.xy;
43
+ let coverage = clamp(min(p + vec2f(0.5), params.rect.xy + params.rect.zw) - max(p - vec2f(0.5), params.rect.xy), vec2f(0), vec2f(1));
44
+ let uv = (p - params.rect.xy) / params.rect.zw;
45
+ if (any(uv <= vec2f(0)) || any(uv > vec2f(1))) { return vec4f(0); }
46
+ return textureSampleLevel(source, sourceSampler, uv, 0) * min(coverage.x, coverage.y);
47
+ }
48
+ `;
49
+ var createRectTransformImplementations = (label, getRect) => ({
50
+ webgl2: Internals.createEffectImplementation({
51
+ setup: (target) => setupSinglePass(target, WEBGL_SHADER, label, ["uResolution", "uRect"]),
52
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
53
+ const rect = getRect(params, width, height);
54
+ prepareSinglePassSource({
55
+ state,
56
+ source,
57
+ width,
58
+ height,
59
+ flipSourceY
60
+ });
61
+ state.gl.uniform2f(state.uniforms.uResolution, width, height);
62
+ state.gl.uniform4f(state.uniforms.uRect, rect.x, rect.y, rect.width, rect.height);
63
+ drawSinglePass(state);
64
+ },
65
+ cleanup: cleanupSinglePass
66
+ }),
67
+ webgpu: Internals.createEffectImplementation({
68
+ setup: (target) => setupWebGpuSinglePass(target, label),
69
+ apply: ({ source, width, height, params, state, gpuDevice }) => {
70
+ if (!gpuDevice) {
71
+ throw new Error(`A WebGPU device is required for the ${label} effect`);
72
+ }
73
+ const rect = getRect(params, width, height);
74
+ applyWebGpuSinglePass({
75
+ state,
76
+ source,
77
+ width,
78
+ height,
79
+ device: gpuDevice,
80
+ shader: WEBGPU_SHADER,
81
+ uniformData: new Float32Array([
82
+ width,
83
+ height,
84
+ 0,
85
+ 0,
86
+ rect.x,
87
+ rect.y,
88
+ rect.width,
89
+ rect.height
90
+ ])
91
+ });
92
+ },
93
+ cleanup: cleanupWebGpuSinglePass
94
+ })
95
+ });
96
+
97
+ export { createRectTransformImplementations };
@@ -0,0 +1,164 @@
1
+ // src/webgpu-single-pass-runtime.ts
2
+ var WEBGPU_SINGLE_PASS_VERTEX = `
3
+ struct VertexOutput {
4
+ @builtin(position) position: vec4f,
5
+ @location(0) uv: vec2f,
6
+ }
7
+
8
+ @vertex fn vertex(@builtin(vertex_index) index: u32) -> VertexOutput {
9
+ let positions = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
10
+ let position = positions[index];
11
+ var output: VertexOutput;
12
+ output.position = vec4f(position, 0, 1);
13
+ output.uv = vec2f(position.x * 0.5 + 0.5, 0.5 - position.y * 0.5);
14
+ return output;
15
+ }
16
+ `;
17
+ var setupWebGpuSinglePass = (target, label) => {
18
+ const context = target.getContext("webgpu");
19
+ if (!context) {
20
+ throw new Error(`WebGPU is not available for the ${label} effect`);
21
+ }
22
+ return { context, label, resources: null };
23
+ };
24
+ var cleanupWebGpuSinglePass = (state) => {
25
+ state.resources?.source?.texture.destroy();
26
+ state.resources?.uniforms.destroy();
27
+ state.resources?.auxiliary?.texture.destroy();
28
+ state.resources = null;
29
+ state.context.unconfigure();
30
+ };
31
+ var applyWebGpuSinglePass = ({
32
+ state,
33
+ source,
34
+ device,
35
+ shader,
36
+ uniformData
37
+ }, options = null) => {
38
+ const sourceFilter = options?.sourceFilter ?? "linear";
39
+ const auxiliaryTexture = options?.auxiliaryTexture ?? null;
40
+ const width = "displayWidth" in source ? source.displayWidth : ("videoWidth" in source) ? source.videoWidth : ("naturalWidth" in source) ? source.naturalWidth : typeof source.width === "number" ? source.width : source.width.baseVal.value;
41
+ const height = "displayHeight" in source ? source.displayHeight : ("videoHeight" in source) ? source.videoHeight : ("naturalHeight" in source) ? source.naturalHeight : typeof source.height === "number" ? source.height : source.height.baseVal.value;
42
+ const uniformBufferSize = Math.max(16, Math.ceil(uniformData.byteLength / 16) * 16);
43
+ if (state.resources && (state.resources.device !== device || state.resources.shader !== shader || state.resources.uniformBufferSize !== uniformBufferSize || state.resources.sourceFilter !== sourceFilter || (state.resources.auxiliary?.width ?? null) !== (auxiliaryTexture?.width ?? null) || (state.resources.auxiliary?.height ?? null) !== (auxiliaryTexture?.height ?? null) || (state.resources.auxiliary?.format ?? null) !== (auxiliaryTexture?.format ?? null))) {
44
+ cleanupWebGpuSinglePass(state);
45
+ }
46
+ if (!state.resources) {
47
+ const format = navigator.gpu.getPreferredCanvasFormat();
48
+ state.context.configure({ device, format, alphaMode: "premultiplied" });
49
+ const module = device.createShaderModule({
50
+ code: shader,
51
+ label: state.label
52
+ });
53
+ const bindGroupLayout = device.createBindGroupLayout({
54
+ entries: [
55
+ ...auxiliaryTexture ? [
56
+ {
57
+ binding: 3,
58
+ visibility: GPUShaderStage.FRAGMENT,
59
+ texture: {
60
+ sampleType: auxiliaryTexture.format === "rgba32float" ? "unfilterable-float" : "float"
61
+ }
62
+ }
63
+ ] : [],
64
+ { binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: {} },
65
+ { binding: 1, visibility: GPUShaderStage.FRAGMENT, sampler: {} },
66
+ {
67
+ binding: 2,
68
+ visibility: GPUShaderStage.FRAGMENT,
69
+ buffer: { type: "uniform" }
70
+ }
71
+ ]
72
+ });
73
+ const pipeline = device.createRenderPipeline({
74
+ label: state.label,
75
+ layout: device.createPipelineLayout({
76
+ bindGroupLayouts: [bindGroupLayout]
77
+ }),
78
+ vertex: { module, entryPoint: "vertex" },
79
+ fragment: { module, entryPoint: "fragment", targets: [{ format }] },
80
+ primitive: { topology: "triangle-list" }
81
+ });
82
+ const uniforms = device.createBuffer({
83
+ size: uniformBufferSize,
84
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
85
+ });
86
+ const sampler = device.createSampler({
87
+ addressModeU: "clamp-to-edge",
88
+ addressModeV: "clamp-to-edge",
89
+ magFilter: sourceFilter,
90
+ minFilter: sourceFilter
91
+ });
92
+ const auxiliary = auxiliaryTexture ? {
93
+ texture: device.createTexture({
94
+ size: [auxiliaryTexture.width, auxiliaryTexture.height],
95
+ format: auxiliaryTexture.format,
96
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
97
+ }),
98
+ width: auxiliaryTexture.width,
99
+ height: auxiliaryTexture.height,
100
+ format: auxiliaryTexture.format,
101
+ uploadedData: null
102
+ } : null;
103
+ state.resources = {
104
+ device,
105
+ shader,
106
+ uniformBufferSize,
107
+ sourceFilter,
108
+ auxiliary,
109
+ pipeline,
110
+ uniforms,
111
+ sampler,
112
+ bindGroupLayout,
113
+ source: null
114
+ };
115
+ }
116
+ const { resources } = state;
117
+ if (resources.source && (resources.source.width !== width || resources.source.height !== height)) {
118
+ resources.source.texture.destroy();
119
+ resources.source = null;
120
+ }
121
+ if (!resources.source) {
122
+ const texture = device.createTexture({
123
+ size: [width, height],
124
+ format: "rgba8unorm",
125
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
126
+ });
127
+ const bindGroup = device.createBindGroup({
128
+ layout: resources.bindGroupLayout,
129
+ entries: [
130
+ ...resources.auxiliary ? [{ binding: 3, resource: resources.auxiliary.texture.createView() }] : [],
131
+ { binding: 0, resource: texture.createView() },
132
+ { binding: 1, resource: resources.sampler },
133
+ { binding: 2, resource: { buffer: resources.uniforms } }
134
+ ]
135
+ });
136
+ resources.source = { texture, bindGroup, width, height };
137
+ }
138
+ if (auxiliaryTexture && resources.auxiliary && resources.auxiliary.uploadedData !== auxiliaryTexture.data) {
139
+ device.queue.writeTexture({ texture: resources.auxiliary.texture }, auxiliaryTexture.data, {
140
+ bytesPerRow: auxiliaryTexture.width * 4 * auxiliaryTexture.data.BYTES_PER_ELEMENT
141
+ }, [auxiliaryTexture.width, auxiliaryTexture.height]);
142
+ resources.auxiliary.uploadedData = auxiliaryTexture.data;
143
+ }
144
+ device.queue.copyExternalImageToTexture({ source }, { texture: resources.source.texture, premultipliedAlpha: true }, [width, height]);
145
+ device.queue.writeBuffer(resources.uniforms, 0, uniformData);
146
+ const encoder = device.createCommandEncoder();
147
+ const pass = encoder.beginRenderPass({
148
+ colorAttachments: [
149
+ {
150
+ view: state.context.getCurrentTexture().createView(),
151
+ clearValue: { r: 0, g: 0, b: 0, a: 0 },
152
+ loadOp: "clear",
153
+ storeOp: "store"
154
+ }
155
+ ]
156
+ });
157
+ pass.setPipeline(resources.pipeline);
158
+ pass.setBindGroup(0, resources.source.bindGroup);
159
+ pass.draw(3);
160
+ pass.end();
161
+ device.queue.submit([encoder.finish()]);
162
+ };
163
+
164
+ export { WEBGPU_SINGLE_PASS_VERTEX, setupWebGpuSinglePass, cleanupWebGpuSinglePass, applyWebGpuSinglePass };
@@ -0,0 +1,215 @@
1
+ // src/webgl-projection-runtime.ts
2
+ import { Internals } from "remotion";
3
+ var setupWebGlProjection = (target, shader) => {
4
+ const gl = target.getContext("webgl2");
5
+ if (!gl)
6
+ throw Internals.createWebGL2ContextError("projection effect");
7
+ const program = gl.createProgram();
8
+ const shaders = [];
9
+ try {
10
+ for (const [type, code] of [
11
+ [
12
+ gl.VERTEX_SHADER,
13
+ `#version 300 es
14
+ void main() {
15
+ vec2 positions[3] = vec2[3](vec2(-1, -1), vec2(3, -1), vec2(-1, 3));
16
+ gl_Position = vec4(positions[gl_VertexID], 0, 1);
17
+ }`
18
+ ],
19
+ [gl.FRAGMENT_SHADER, shader]
20
+ ]) {
21
+ const compiled = gl.createShader(type);
22
+ shaders.push(compiled);
23
+ gl.shaderSource(compiled, code);
24
+ gl.compileShader(compiled);
25
+ if (!gl.getShaderParameter(compiled, gl.COMPILE_STATUS))
26
+ throw new Error(gl.getShaderInfoLog(compiled) ?? "Projection shader compilation failed");
27
+ gl.attachShader(program, compiled);
28
+ }
29
+ gl.linkProgram(program);
30
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS))
31
+ throw new Error(gl.getProgramInfoLog(program) ?? "Projection program linking failed");
32
+ } catch (err) {
33
+ gl.deleteProgram(program);
34
+ throw err;
35
+ } finally {
36
+ for (const compiled of shaders)
37
+ gl.deleteShader(compiled);
38
+ }
39
+ const texture = gl.createTexture();
40
+ gl.bindTexture(gl.TEXTURE_2D, texture);
41
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
42
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
43
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
44
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
45
+ return {
46
+ gl,
47
+ program,
48
+ texture,
49
+ vao: gl.createVertexArray(),
50
+ uniforms: gl.getUniformLocation(program, "uParams"),
51
+ source: gl.getUniformLocation(program, "uSource")
52
+ };
53
+ };
54
+ var applyWebGlProjection = ({
55
+ state,
56
+ source,
57
+ width,
58
+ height,
59
+ flipSourceY,
60
+ uniformData
61
+ }) => {
62
+ const { gl } = state;
63
+ gl.viewport(0, 0, width, height);
64
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
65
+ gl.disable(gl.BLEND);
66
+ gl.disable(gl.DEPTH_TEST);
67
+ gl.disable(gl.SCISSOR_TEST);
68
+ gl.useProgram(state.program);
69
+ gl.bindVertexArray(state.vao);
70
+ gl.activeTexture(gl.TEXTURE0);
71
+ gl.bindTexture(gl.TEXTURE_2D, state.texture);
72
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
73
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
74
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
75
+ gl.uniform1i(state.source, 0);
76
+ gl.uniform4fv(state.uniforms, uniformData);
77
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
78
+ };
79
+ var cleanupWebGlProjection = ({
80
+ gl,
81
+ program,
82
+ texture,
83
+ vao
84
+ }) => {
85
+ gl.deleteTexture(texture);
86
+ gl.deleteProgram(program);
87
+ gl.deleteVertexArray(vao);
88
+ };
89
+
90
+ // src/webgpu-projection-runtime.ts
91
+ var deviceResources = new WeakMap;
92
+ var lostDevices = new WeakSet;
93
+ var cleanupWebGpuProjection = (state) => {
94
+ state.resources?.source?.texture.destroy();
95
+ state.resources?.uniforms.destroy();
96
+ state.resources = null;
97
+ state.context.unconfigure();
98
+ };
99
+ var setupWebGpuProjection = (target, label) => {
100
+ const context = target.getContext("webgpu");
101
+ if (!context) {
102
+ throw new Error(`WebGPU is not available for the ${label} effect`);
103
+ }
104
+ return { context, resources: null };
105
+ };
106
+ var applyWebGpuProjection = ({
107
+ state,
108
+ source,
109
+ device,
110
+ shader,
111
+ uniformData
112
+ }) => {
113
+ if (lostDevices.has(device)) {
114
+ throw new Error("Cannot apply a WebGPU projection with a lost device");
115
+ }
116
+ const width = "displayWidth" in source ? source.displayWidth : ("videoWidth" in source) ? source.videoWidth : ("naturalWidth" in source) ? source.naturalWidth : typeof source.width === "number" ? source.width : source.width.baseVal.value;
117
+ const height = "displayHeight" in source ? source.displayHeight : ("videoHeight" in source) ? source.videoHeight : ("naturalHeight" in source) ? source.naturalHeight : typeof source.height === "number" ? source.height : source.height.baseVal.value;
118
+ const format = navigator.gpu.getPreferredCanvasFormat();
119
+ if (state.resources && (state.resources.device !== device || state.resources.shader !== shader || state.resources.format !== format || state.resources.uniforms.size !== uniformData.byteLength)) {
120
+ cleanupWebGpuProjection(state);
121
+ }
122
+ if (!state.resources) {
123
+ let shared = deviceResources.get(device);
124
+ if (!shared) {
125
+ const pipelines = new Map;
126
+ shared = {
127
+ pipelines,
128
+ sampler: device.createSampler({
129
+ addressModeU: "repeat",
130
+ magFilter: "linear",
131
+ minFilter: "linear"
132
+ })
133
+ };
134
+ deviceResources.set(device, shared);
135
+ device.lost.then(() => {
136
+ lostDevices.add(device);
137
+ pipelines.clear();
138
+ deviceResources.delete(device);
139
+ });
140
+ }
141
+ let pipelinesByFormat = shared.pipelines.get(shader);
142
+ if (!pipelinesByFormat) {
143
+ pipelinesByFormat = new Map;
144
+ shared.pipelines.set(shader, pipelinesByFormat);
145
+ }
146
+ let pipeline = pipelinesByFormat.get(format);
147
+ if (!pipeline) {
148
+ const module = device.createShaderModule({ code: shader });
149
+ pipeline = device.createRenderPipeline({
150
+ layout: "auto",
151
+ vertex: { module, entryPoint: "vertex" },
152
+ fragment: { module, entryPoint: "fragment", targets: [{ format }] },
153
+ primitive: { topology: "triangle-list" }
154
+ });
155
+ pipelinesByFormat.set(format, pipeline);
156
+ }
157
+ state.context.configure({ device, format, alphaMode: "premultiplied" });
158
+ const uniforms = device.createBuffer({
159
+ size: uniformData.byteLength,
160
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
161
+ });
162
+ state.resources = {
163
+ device,
164
+ shader,
165
+ format,
166
+ pipeline,
167
+ uniforms,
168
+ sampler: shared.sampler,
169
+ source: null
170
+ };
171
+ }
172
+ const { resources } = state;
173
+ if (!resources.source || resources.source.width !== width || resources.source.height !== height) {
174
+ const texture = device.createTexture({
175
+ size: [width, height],
176
+ format: "rgba8unorm",
177
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
178
+ });
179
+ try {
180
+ const bindGroup = device.createBindGroup({
181
+ layout: resources.pipeline.getBindGroupLayout(0),
182
+ entries: [
183
+ { binding: 0, resource: texture.createView() },
184
+ { binding: 1, resource: resources.sampler },
185
+ { binding: 2, resource: { buffer: resources.uniforms } }
186
+ ]
187
+ });
188
+ resources.source?.texture.destroy();
189
+ resources.source = { texture, bindGroup, width, height };
190
+ } catch (err) {
191
+ texture.destroy();
192
+ throw err;
193
+ }
194
+ }
195
+ device.queue.copyExternalImageToTexture({ source }, { texture: resources.source.texture, premultipliedAlpha: true }, [width, height]);
196
+ device.queue.writeBuffer(resources.uniforms, 0, uniformData);
197
+ const encoder = device.createCommandEncoder();
198
+ const pass = encoder.beginRenderPass({
199
+ colorAttachments: [
200
+ {
201
+ view: state.context.getCurrentTexture().createView(),
202
+ clearValue: { r: 0, g: 0, b: 0, a: 0 },
203
+ loadOp: "clear",
204
+ storeOp: "store"
205
+ }
206
+ ]
207
+ });
208
+ pass.setPipeline(resources.pipeline);
209
+ pass.setBindGroup(0, resources.source.bindGroup);
210
+ pass.draw(3);
211
+ pass.end();
212
+ device.queue.submit([encoder.finish()]);
213
+ };
214
+
215
+ export { setupWebGlProjection, applyWebGlProjection, cleanupWebGlProjection, cleanupWebGpuProjection, setupWebGpuProjection, applyWebGpuProjection };
@@ -0,0 +1,79 @@
1
+ import {
2
+ assertRequiredFiniteNumber
3
+ } from "./index-4fvp93ps.mjs";
4
+
5
+ // src/color-utils.ts
6
+ var DEFAULT_AMOUNT = 1;
7
+ var DEFAULT_BRIGHTNESS_AMOUNT = 0;
8
+ var DEFAULT_HUE_DEGREES = 0;
9
+ var colorAmountSchema = {
10
+ type: "number",
11
+ min: 0,
12
+ max: 1,
13
+ step: 0.01,
14
+ default: DEFAULT_AMOUNT,
15
+ description: "Amount",
16
+ hiddenFromList: false
17
+ };
18
+ var colorMultiplierSchema = {
19
+ type: "number",
20
+ min: 0,
21
+ step: 0.01,
22
+ default: DEFAULT_AMOUNT,
23
+ description: "Amount",
24
+ hiddenFromList: false
25
+ };
26
+ var brightnessAmountSchema = {
27
+ type: "number",
28
+ min: -1,
29
+ max: 1,
30
+ step: 0.01,
31
+ default: DEFAULT_BRIGHTNESS_AMOUNT,
32
+ description: "Amount",
33
+ hiddenFromList: false
34
+ };
35
+ var hueDegreesSchema = {
36
+ type: "rotation-degrees",
37
+ step: 1,
38
+ default: DEFAULT_HUE_DEGREES,
39
+ description: "Degrees"
40
+ };
41
+ var assertOptionalFiniteNumber = (value, name) => {
42
+ if (value === undefined) {
43
+ return;
44
+ }
45
+ assertRequiredFiniteNumber(value, name);
46
+ };
47
+ var validateUnitInterval = (value, name) => {
48
+ if (value < 0) {
49
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
50
+ }
51
+ if (value > 1) {
52
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
53
+ }
54
+ };
55
+ var validateNonNegative = (value, name) => {
56
+ if (value < 0) {
57
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
58
+ }
59
+ };
60
+ var validateSignedUnitInterval = (value, name) => {
61
+ if (value < -1) {
62
+ throw new TypeError(`"${name}" must be >= -1, 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 clampColorChannel = (value) => {
69
+ return Math.max(0, Math.min(255, value));
70
+ };
71
+ var parseColorRgba = (ctx, color) => {
72
+ ctx.clearRect(0, 0, 1, 1);
73
+ ctx.fillStyle = color;
74
+ ctx.fillRect(0, 0, 1, 1);
75
+ const { data } = ctx.getImageData(0, 0, 1, 1);
76
+ return [data[0], data[1], data[2], data[3]];
77
+ };
78
+
79
+ export { DEFAULT_AMOUNT, DEFAULT_BRIGHTNESS_AMOUNT, DEFAULT_HUE_DEGREES, colorAmountSchema, colorMultiplierSchema, brightnessAmountSchema, hueDegreesSchema, assertOptionalFiniteNumber, validateUnitInterval, validateNonNegative, validateSignedUnitInterval, clampColorChannel, parseColorRgba };