🎥 Make videos programmatically with React
`@remotion/effects`: Add levels effect (#10297)
Jonny Burger55cdd25fbc42
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.tsindex aae70fe325..29605ed51e 100644--- a/packages/docs/components/effects-demos/registry.ts+++ b/packages/docs/components/effects-demos/registry.ts@@ -23,6 +23,7 @@ import {halftone} from '@remotion/effects/halftone';import {halftoneLinearGradient} from '@remotion/effects/halftone-linear-gradient';import {hue} from '@remotion/effects/hue';import {invert} from '@remotion/effects/invert';+import {levels} from '@remotion/effects/levels';import {lightLeak} from '@remotion/effects/light-leak';import {lightTrail} from '@remotion/effects/light-trail';import {linearGradient} from '@remotion/effects/linear-gradient';@@ -89,6 +90,7 @@ import {EffectsHalftoneLinearGradientPreview} from '../effects/effects-halftone-import {EffectsHalftonePreview} from '../effects/effects-halftone-preview';import {EffectsHuePreview} from '../effects/effects-hue-preview';import {EffectsInvertPreview} from '../effects/effects-invert-preview';+import {EffectsLevelsPreview} from '../effects/effects-levels-preview';import {EffectsLightLeakPreview} from '../effects/effects-light-leak-preview';import {EffectsLightTrailPreview,@@ -318,6 +320,14 @@ export const effectsDemos: EffectsDemoType[] = [comp: EffectsInvertPreview,schema: invert().definition.schema,},+ {+ ...defaults,+ id: 'effects-levels',+ effectName: 'levels',+ effectImportPath: '@remotion/effects/levels',+ comp: EffectsLevelsPreview,+ schema: levels().definition.schema,+ },{...defaults,id: 'effects-saturation',diff --git a/packages/docs/components/effects/effects-levels-preview.tsx b/packages/docs/components/effects/effects-levels-preview.tsxnew file mode 100644index 0000000000..c676fc426f--- /dev/null+++ b/packages/docs/components/effects/effects-levels-preview.tsx@@ -0,0 +1,20 @@+import {levels} from '@remotion/effects/levels';+import React from 'react';+import {CanvasImage} from 'remotion';+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';++export const EffectsLevelsPreview: React.FC<{+ readonly blackPoint: number;+ readonly whitePoint: number;+ readonly gamma: number;+}> = ({blackPoint, whitePoint, gamma}) => {+ return (+ <CanvasImage+ src={EFFECTS_PREVIEW_IMAGE_SRC}+ width={1280}+ height={720}+ fit="cover"+ effects={[levels({blackPoint, whitePoint, gamma})]}+ />+ );+};diff --git a/packages/docs/docs/effects/levels.mdx b/packages/docs/docs/effects/levels.mdxnew file mode 100644index 0000000000..59234a75c9--- /dev/null+++ b/packages/docs/docs/effects/levels.mdx@@ -0,0 +1,76 @@+---+image: /generated/articles-docs-effects-levels.png+slug: /effects/levels+title: levels()+sidebar_label: levels()+crumb: '@remotion/effects'+---++# levels()<AvailableFrom v="4.0.508" />++_Part of the [`@remotion/effects`](/docs/effects/api) package._++Sets the black point, white point, and midtone gamma in one tonal adjustment.++## Preview++<EffectsDemo type="effects-levels" />++## Example++```tsx twoslash title="MyComp.tsx"+import {Video} from '@remotion/media';+import {levels} from '@remotion/effects/levels';++export const MyComp: React.FC = () => {+ return (+ <Video+ src="https://remotion.media/video.mp4"+ effects={[+ levels({+ blackPoint: 0.05,+ whitePoint: 0.95,+ gamma: 1.2,+ }),+ ]}+ />+ );+};+```++## API++You can call `levels()` without arguments or pass an object with the following properties.++### `blackPoint?`++The input value mapped to black, from `0` to `1`. Values below it are clipped to black. Defaults to `0`.++The black point must be less than the white point. Moving the points close together produces a steep tonal stretch.++### `whitePoint?`++The input value mapped to white, from `0` to `1`. Values above it are clipped to white. Defaults to `1`.++The white point must be greater than the black point.++### `gamma?`++The midtone gamma from `0.01` to `10`. Values below `1` darken midtones and values above `1` brighten them. Defaults to `1`.++The effect remaps unpremultiplied sRGB channel values, then applies the gamma curve.++### `disabled?`++When `true`, the effect is skipped. Defaults to `false`.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering serverSideRendering player studio hideServers />++## See also++- [`@remotion/effects`](/docs/effects/api)+- [`contrast()`](/docs/effects/contrast)+- [`exposure()`](/docs/effects/exposure)+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/levels.ts)diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 9bb1b176c4..d1bded965b 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -298,6 +298,7 @@ const sidebars: SidebarsConfig = {'effects/halftone-linear-gradient','effects/hue','effects/invert',+ 'effects/levels','effects/linear-gradient','effects/linear-gradient-tint','effects/linear-progressive-blur',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 9f2764deab..10568e84b6 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -2042,6 +2042,15 @@ export const articles = [noAi: false,slug: 'effects/invert',},+ {+ id: 'effects/levels',+ title: 'levels()',+ relativePath: 'docs/effects/levels.mdx',+ compId: 'articles-docs-effects-levels',+ crumb: '@remotion/effects',+ noAi: false,+ slug: 'effects/levels',+ },{id: 'effects/light-leak',title: 'lightLeak()',diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsxindex 09eb409c48..9a6fdbfb7f 100644--- a/packages/docs/src/remotion/Root.tsx+++ b/packages/docs/src/remotion/Root.tsx@@ -27,6 +27,7 @@ import {EffectsHalftoneLinearGradientPreview} from '../../components/effects/effimport {EffectsHalftonePreview} from '../../components/effects/effects-halftone-preview';import {EffectsHuePreview} from '../../components/effects/effects-hue-preview';import {EffectsInvertPreview} from '../../components/effects/effects-invert-preview';+import {EffectsLevelsPreview} from '../../components/effects/effects-levels-preview';import {EffectsLightLeakPreview} from '../../components/effects/effects-light-leak-preview';import {EffectsLightTrailPreview,@@ -291,6 +292,13 @@ export const RemotionRoot: React.FC = () => {height={720}defaultProps={{stops: 1}}/>+ <Still+ id="effects-levels-preview"+ component={EffectsLevelsPreview}+ width={1280}+ height={720}+ defaultProps={{blackPoint: 0.1, whitePoint: 0.9, gamma: 1.4}}+ /><Stillid="effects-white-balance-preview"component={EffectsWhiteBalancePreview}diff --git a/packages/docs/static/generated/articles-docs-effects-levels.png b/packages/docs/static/generated/articles-docs-effects-levels.pngnew file mode 100644index 0000000000..4bc367877dBinary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-levels.png differdiff --git a/packages/docs/static/img/effects-levels-preview.png b/packages/docs/static/img/effects-levels-preview.pngnew file mode 100644index 0000000000..f398362443Binary files /dev/null and b/packages/docs/static/img/effects-levels-preview.png differdiff --git a/packages/effects/bundle.ts b/packages/effects/bundle.tsindex 8ed41cce64..93c5b2c57a 100644--- a/packages/effects/bundle.ts+++ b/packages/effects/bundle.ts@@ -42,6 +42,7 @@ const effectEntrypoints = ['src/linear-progressive-pixelate.ts','src/light-leak.ts','src/light-trail.ts',+ 'src/levels.ts','src/mirror.ts','src/noise.ts','src/noise-displacement.ts',diff --git a/packages/effects/package.json b/packages/effects/package.jsonindex 98e70370ef..fee90c9bca 100644--- a/packages/effects/package.json+++ b/packages/effects/package.json@@ -194,6 +194,11 @@"module": "./dist/esm/linear-progressive-pixelate.mjs","import": "./dist/esm/linear-progressive-pixelate.mjs"},+ "./levels": {+ "types": "./dist/levels.d.ts",+ "module": "./dist/esm/levels.mjs",+ "import": "./dist/esm/levels.mjs"+ },"./light-leak": {"types": "./dist/light-leak.d.ts","module": "./dist/esm/light-leak.mjs",@@ -464,6 +469,9 @@"linear-progressive-pixelate": ["dist/linear-progressive-pixelate.d.ts"],+ "levels": [+ "dist/levels.d.ts"+ ],"light-leak": ["dist/light-leak.d.ts"],diff --git a/packages/effects/src/levels.ts b/packages/effects/src/levels.tsnew file mode 100644index 0000000000..6ca32d904f--- /dev/null+++ b/packages/effects/src/levels.ts@@ -0,0 +1,323 @@+import type {InteractivitySchema} from 'remotion';+import {Internals} from 'remotion';+import {+ assertOptionalFiniteNumber,+ validateUnitInterval,+} from './color-utils.js';+import {assertEffectParamsObject} from './validate-effect-param.js';++const {createEffect, createWebGL2ContextError} = Internals;++const DEFAULT_BLACK_POINT = 0 as const;+const DEFAULT_WHITE_POINT = 1 as const;+const DEFAULT_GAMMA = 1 as const;+const MIN_GAMMA = 0.01 as const;+const MAX_GAMMA = 10 as const;++const levelsSchema = {+ blackPoint: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: DEFAULT_BLACK_POINT,+ description: 'Black point',+ hiddenFromList: false,+ },+ whitePoint: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: DEFAULT_WHITE_POINT,+ description: 'White point',+ hiddenFromList: false,+ },+ gamma: {+ type: 'number',+ min: MIN_GAMMA,+ max: MAX_GAMMA,+ step: 0.01,+ default: DEFAULT_GAMMA,+ description: 'Gamma',+ hiddenFromList: false,+ },+} as const satisfies InteractivitySchema;++export type LevelsParams = {+ /** Input value mapped to black, from `0` to `1`. Defaults to `0`. */+ readonly blackPoint?: number;+ /** Input value mapped to white, from `0` to `1`. Defaults to `1`. */+ readonly whitePoint?: number;+ /** Midtone gamma from `0.01` to `10`. Defaults to `1`. */+ readonly gamma?: number;+};++type LevelsResolved = {+ blackPoint: number;+ whitePoint: number;+ gamma: number;+};++type LevelsState = {+ readonly gl: WebGL2RenderingContext;+ readonly program: WebGLProgram;+ readonly vao: WebGLVertexArrayObject;+ readonly vbo: WebGLBuffer;+ readonly textureSource: WebGLTexture;+ readonly uniforms: {+ readonly uSource: WebGLUniformLocation | null;+ readonly uBlackPoint: WebGLUniformLocation | null;+ readonly uWhitePoint: WebGLUniformLocation | null;+ readonly uGamma: WebGLUniformLocation | null;+ };+};++const resolve = (params: LevelsParams): LevelsResolved => ({+ blackPoint: params.blackPoint ?? DEFAULT_BLACK_POINT,+ whitePoint: params.whitePoint ?? DEFAULT_WHITE_POINT,+ gamma: params.gamma ?? DEFAULT_GAMMA,+});++const validateLevelsParams = (params: LevelsParams): void => {+ assertEffectParamsObject(params, 'Levels');+ assertOptionalFiniteNumber(params.blackPoint, 'blackPoint');+ assertOptionalFiniteNumber(params.whitePoint, 'whitePoint');+ assertOptionalFiniteNumber(params.gamma, 'gamma');++ const {blackPoint, whitePoint, gamma} = resolve(params);+ validateUnitInterval(blackPoint, 'blackPoint');+ validateUnitInterval(whitePoint, 'whitePoint');++ if (blackPoint >= whitePoint) {+ throw new TypeError(+ `"blackPoint" must be less than "whitePoint", but got ${JSON.stringify(blackPoint)} and ${JSON.stringify(whitePoint)}`,+ );+ }++ if (gamma < MIN_GAMMA) {+ throw new TypeError(+ `"gamma" must be >= ${MIN_GAMMA}, but got ${JSON.stringify(gamma)}`,+ );+ }++ if (gamma > MAX_GAMMA) {+ throw new TypeError(+ `"gamma" must be <= ${MAX_GAMMA}, but got ${JSON.stringify(gamma)}`,+ );+ }+};++const VERTEX_SHADER = /* glsl */ `#version 300 es+in vec2 aPos;+in vec2 aUv;+out vec2 vUv;++void main() {+ vUv = aUv;+ gl_Position = vec4(aPos, 0.0, 1.0);+}+`;++const FRAGMENT_SHADER = /* glsl */ `#version 300 es+precision highp float;++in vec2 vUv;+out vec4 fragColor;++uniform sampler2D uSource;+uniform float uBlackPoint;+uniform float uWhitePoint;+uniform float uGamma;++void main() {+ vec4 sourceColor = texture(uSource, vUv);+ float alpha = sourceColor.a;++ if (alpha <= 0.0) {+ fragColor = vec4(0.0);+ return;+ }++ vec3 color = sourceColor.rgb / alpha;+ vec3 normalized = clamp(+ (color - vec3(uBlackPoint)) / (uWhitePoint - uBlackPoint),+ 0.0,+ 1.0+ );+ vec3 corrected = pow(normalized, vec3(1.0 / uGamma));++ fragColor = vec4(corrected * alpha, alpha);+}+`;++const compileShader = (+ gl: WebGL2RenderingContext,+ type: number,+ source: string,+): WebGLShader => {+ const shader = gl.createShader(type);+ if (!shader) {+ throw new Error('Failed to create levels shader');+ }++ gl.shaderSource(shader, source);+ gl.compileShader(shader);+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {+ const log = gl.getShaderInfoLog(shader);+ gl.deleteShader(shader);+ throw new Error(`Levels shader compile failed: ${log ?? '(no log)'}`);+ }++ return shader;+};++const createProgram = (gl: WebGL2RenderingContext): WebGLProgram => {+ const vertexShader = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);+ const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);+ const program = gl.createProgram();+ if (!program) {+ throw new Error('Failed to create levels shader program');+ }++ gl.attachShader(program, vertexShader);+ gl.attachShader(program, fragmentShader);+ gl.linkProgram(program);+ gl.deleteShader(vertexShader);+ gl.deleteShader(fragmentShader);++ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {+ const log = gl.getProgramInfoLog(program);+ gl.deleteProgram(program);+ throw new Error(`Levels shader link failed: ${log ?? '(no log)'}`);+ }++ return program;+};++const createTexture = (gl: WebGL2RenderingContext): WebGLTexture => {+ const texture = gl.createTexture();+ if (!texture) {+ throw new Error('Failed to create levels texture');+ }++ gl.bindTexture(gl.TEXTURE_2D, texture);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);+ gl.bindTexture(gl.TEXTURE_2D, null);+ return texture;+};++const setupLevels = (target: HTMLCanvasElement): LevelsState => {+ const gl = target.getContext('webgl2', {+ premultipliedAlpha: true,+ alpha: true,+ preserveDrawingBuffer: true,+ });+ if (!gl) {+ throw createWebGL2ContextError('levels effect');+ }++ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);++ const program = createProgram(gl);+ const vao = gl.createVertexArray();+ if (!vao) {+ throw new Error('Failed to create levels vertex array');+ }++ const vbo = gl.createBuffer();+ if (!vbo) {+ throw new Error('Failed to create levels vertex buffer');+ }++ gl.bindVertexArray(vao);+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);+ 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,+ );++ const aPos = gl.getAttribLocation(program, 'aPos');+ const aUv = gl.getAttribLocation(program, 'aUv');+ gl.enableVertexAttribArray(aPos);+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);+ gl.enableVertexAttribArray(aUv);+ gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);+ gl.bindVertexArray(null);++ return {+ gl,+ program,+ vao,+ vbo,+ textureSource: createTexture(gl),+ uniforms: {+ uSource: gl.getUniformLocation(program, 'uSource'),+ uBlackPoint: gl.getUniformLocation(program, 'uBlackPoint'),+ uWhitePoint: gl.getUniformLocation(program, 'uWhitePoint'),+ uGamma: gl.getUniformLocation(program, 'uGamma'),+ },+ };+};++export const levels = createEffect<LevelsParams, LevelsState>({+ type: 'remotion/levels',+ label: 'levels()',+ documentationLink: 'https://www.remotion.dev/docs/effects/levels',+ backend: 'webgl2',+ calculateKey: (params) => {+ const {blackPoint, whitePoint, gamma} = resolve(params);+ return `levels-${blackPoint}-${whitePoint}-${gamma}`;+ },+ setup: setupLevels,+ apply: ({source, width, height, params, state, flipSourceY}) => {+ const {blackPoint, whitePoint, gamma} = resolve(params);+ const {gl, program, textureSource, uniforms, vao} = state;++ gl.viewport(0, 0, width, height);+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);+ gl.clearColor(0, 0, 0, 0);+ gl.clear(gl.COLOR_BUFFER_BIT);++ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, textureSource);+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);+ gl.texImage2D(+ gl.TEXTURE_2D,+ 0,+ gl.RGBA,+ gl.RGBA,+ gl.UNSIGNED_BYTE,+ source as TexImageSource,+ );++ gl.useProgram(program);+ if (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);+ if (uniforms.uBlackPoint) {+ gl.uniform1f(uniforms.uBlackPoint, blackPoint);+ }++ if (uniforms.uWhitePoint) {+ gl.uniform1f(uniforms.uWhitePoint, whitePoint);+ }++ if (uniforms.uGamma) gl.uniform1f(uniforms.uGamma, gamma);+ gl.bindVertexArray(vao);+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);+ gl.bindVertexArray(null);+ gl.bindTexture(gl.TEXTURE_2D, null);+ gl.useProgram(null);+ },+ cleanup: ({gl, program, vao, vbo, textureSource}) => {+ gl.deleteTexture(textureSource);+ gl.deleteBuffer(vbo);+ gl.deleteProgram(program);+ gl.deleteVertexArray(vao);+ },+ schema: levelsSchema,+ validateParams: validateLevelsParams,+});diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.tsindex 129748201b..91ebe600dc 100644--- a/packages/effects/src/test/effect-params.test.ts+++ b/packages/effects/src/test/effect-params.test.ts@@ -24,6 +24,7 @@ import {halftoneLinearGradient} from '../halftone-linear-gradient.js';import {halftone} from '../halftone.js';import {hue} from '../hue.js';import {invert} from '../invert.js';+import {levels} from '../levels.js';import {lightLeak} from '../light-leak.js';import {lightTrail} from '../light-trail/index.js';import {linearGradientTint} from '../linear-gradient-tint.js';@@ -171,6 +172,9 @@ test('@remotion/effects expose documentation links', () => {expect(invert().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/invert',);+ expect(levels().definition.documentationLink).toBe(+ 'https://www.remotion.dev/docs/effects/levels',+ );expect(lines().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/lines',);@@ -328,6 +332,7 @@ test('@remotion/effects expose API names as Studio labels', () => {expect(pixelDissolve().definition.label).toBe('pixelDissolve()');expect(hue().definition.label).toBe('hue()');expect(invert().definition.label).toBe('invert()');+ expect(levels().definition.label).toBe('levels()');expect(lines().definition.label).toBe('lines()');expect(linearGradient().definition.label).toBe('linearGradient()');expect(linearGradientTint().definition.label).toBe('linearGradientTint()');@@ -1043,6 +1048,48 @@ test('vibrance() amount produces distinct effect keys', () => {).toBe(3);});+test('levels() accepts default params', () => {+ expect(() => levels()).not.toThrow();+});++test('levels() rejects non-finite parameters', () => {+ expect(() => levels({blackPoint: Number.NaN})).toThrow(+ '"blackPoint" must be a finite number',+ );+ expect(() => levels({whitePoint: Number.POSITIVE_INFINITY})).toThrow(+ '"whitePoint" must be a finite number',+ );+ expect(() => levels({gamma: Number.NaN})).toThrow(+ '"gamma" must be a finite number',+ );+});++test('levels() validates black and white points', () => {+ expect(() => levels({blackPoint: -0.1})).toThrow('"blackPoint" must be >= 0');+ expect(() => levels({whitePoint: 1.1})).toThrow('"whitePoint" must be <= 1');+ expect(() => levels({blackPoint: 0.5, whitePoint: 0.5})).toThrow(+ '"blackPoint" must be less than "whitePoint"',+ );+ expect(() => levels({blackPoint: 0.6, whitePoint: 0.5})).toThrow(+ '"blackPoint" must be less than "whitePoint"',+ );+});++test('levels() validates gamma', () => {+ expect(() => levels({gamma: 0})).toThrow('"gamma" must be >= 0.01');+ expect(() => levels({gamma: 10.1})).toThrow('"gamma" must be <= 10');+});++test('levels() parameters produce distinct effect keys', () => {+ const neutral = levels();+ const clipped = levels({blackPoint: 0.1, whitePoint: 0.9});+ const brighterMidtones = levels({gamma: 2});+ expect(+ new Set([neutral.effectKey, clipped.effectKey, brighterMidtones.effectKey])+ .size,+ ).toBe(3);+});+test('contrast() accepts default params', () => {expect(() => contrast()).not.toThrow();});diff --git a/packages/effects/src/visual-test/effects-visual.test.ts b/packages/effects/src/visual-test/effects-visual.test.tsindex 6eab8ae776..cedb0eb2d9 100644--- a/packages/effects/src/visual-test/effects-visual.test.ts+++ b/packages/effects/src/visual-test/effects-visual.test.ts@@ -2,6 +2,7 @@ import {expect, test} from 'vitest';import {blur} from '../blur.js';import {evolve} from '../evolve.js';import {exposure} from '../exposure.js';+import {levels} from '../levels.js';import {noise} from '../noise.js';import {pixelDissolve} from '../pixel-dissolve.js';import {vibrance} from '../vibrance.js';@@ -172,6 +173,50 @@ test('vibrance() boosts muted colors more than vivid colors', async () => {expect(pixels[11]).toBe(128);});+test('levels() remaps endpoints and gamma while preserving alpha', async () => {+ const source = document.createElement('canvas');+ source.width = 3;+ source.height = 1;+ const sourceContext = source.getContext('2d');+ if (!sourceContext) {+ throw new Error('Could not get source context');+ }++ sourceContext.putImageData(+ new ImageData(+ new Uint8ClampedArray([+ 51, 51, 51, 128, 128, 128, 128, 128, 204, 204, 204, 128,+ ]),+ 3,+ 1,+ ),+ 0,+ 0,+ );++ const canvas = await renderEffectChainToCanvas({+ source,+ width: 3,+ height: 1,+ effects: descriptorsToMemoizedEffects([+ levels({blackPoint: 0.25, whitePoint: 0.75, gamma: 2}),+ ]),+ });+ const context = canvas.getContext('2d');+ if (!context) {+ throw new Error('Could not get output context');+ }++ const pixels = context.getImageData(0, 0, 3, 1).data;+ expect(pixels[0]).toBeLessThanOrEqual(1);+ expect(pixels[4]).toBeGreaterThanOrEqual(179);+ expect(pixels[4]).toBeLessThanOrEqual(182);+ expect(pixels[8]).toBeGreaterThanOrEqual(254);+ expect(pixels[3]).toBe(128);+ expect(pixels[7]).toBe(128);+ expect(pixels[11]).toBe(128);+});+test('vignette() color mode works on transparent sources', async () => {const width = 40;const height = 40;diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.tsindex 370bce265f..aaf3a9549e 100644--- a/packages/studio-shared/src/effect-catalog.ts+++ b/packages/studio-shared/src/effect-catalog.ts@@ -151,6 +151,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [config: {},},},+ {+ id: 'effects-levels',+ category: 'Color',+ label: 'levels()',+ description: 'Black point, white point, and gamma',+ effect: {+ name: 'levels',+ importPath: '@remotion/effects/levels',+ config: {},+ },+ },{id: 'effects-saturation',category: 'Color',