Skip to content

🎥 Make videos programmatically with React

Remove tear visual test changes

JonnyBurgera86d33243d8b
diff --git a/packages/effects/src/visual-test/effects-visual.test.ts b/packages/effects/src/visual-test/effects-visual.test.ts
index 700807ee31..62efdab099 100644
--- a/packages/effects/src/visual-test/effects-visual.test.ts
+++ b/packages/effects/src/visual-test/effects-visual.test.ts
@@ -12,7 +12,6 @@ import {pixelDissolve} from '../pixel-dissolve.js';
import {saturation} from '../saturation.js';
import {scale} from '../scale.js';
import {shadowsHighlights} from '../shadows-highlights.js';
-import {tear} from '../tear.js';
import {tile} from '../tile.js';
import {vibrance} from '../vibrance.js';
import {vignette} from '../vignette.js';
@@ -797,161 +796,3 @@ test('pixelDissolve() smoothly fades to full transparency with feather', async (
const doneAlpha = await maxAlphaForPixelDissolveProgress(1);
expect(doneAlpha).toBe(0);
});
-
-test('tear() progresses downward, rotates both sides outward, and preserves alpha through a stack', async () => {
- const width = 320;
- const height = 240;
- const source = document.createElement('canvas');
- source.width = width;
- source.height = height;
- const context = source.getContext('2d')!;
- context.fillStyle = 'rgba(200, 80, 40, 0.5)';
- context.fillRect(0, 0, width, height);
- // Markers on each side make the rotation observable in the rendered pixels.
- context.fillStyle = '#ff0000';
- context.fillRect(118, 32, 8, 8);
- context.fillStyle = '#00ff00';
- context.fillRect(194, 32, 8, 8);
- context.fillStyle = 'rgba(40, 80, 200, 0.5)';
- context.fillRect(0, 124, width, 8);
- const render = async (
- progress: number,
- rotation: number,
- jaggedness: number,
- ) => {
- const canvas = await renderEffectChainToCanvas({
- source,
- width,
- height,
- effects: descriptorsToMemoizedEffects([
- tear({progress: 0}),
- tear({progress, rotation, jaggedness}),
- tear({progress: 0}),
- ]),
- });
- return canvas.getContext('2d')!;
- };
-
- const intact = await render(0, 20, 12);
- expect([...intact.getImageData(160, 20, 1, 1).data]).toEqual([
- ...context.getImageData(160, 20, 1, 1).data,
- ]);
- const half = await render(0.5, 20, 0);
- expect(half.getImageData(160, 20, 1, 1).data[3]).toBe(0);
- expect([...half.getImageData(160, 180, 1, 1).data]).toEqual([
- ...context.getImageData(160, 180, 1, 1).data,
- ]);
- expect([...half.getImageData(0, 124, width, 8).data]).toEqual([
- ...context.getImageData(0, 124, width, 8).data,
- ]);
- // The markers rotate about the tip (160, 120) by -10 and +10 degrees.
- expect([...half.getImageData(108, 43, 1, 1).data]).toEqual([255, 0, 0, 255]);
- expect([...half.getImageData(212, 43, 1, 1).data]).toEqual([0, 255, 0, 255]);
- // Changing the edge shape must not move the image content. These two
- // progress values put the tear tip at opposite zigzag extremes.
- for (const progress of [0.625, 17 / 24]) {
- const markerPositions: number[][] = [];
- for (const jaggedness of [0, 24]) {
- const rendered = await render(progress, 20, jaggedness);
- const {data} = rendered.getImageData(0, 0, width, height);
- let sumX = 0;
- let sumY = 0;
- let count = 0;
- for (let index = 0; index < data.length; index += 4) {
- if (data[index] > 250 && data[index + 1] < 5 && data[index + 3] > 250) {
- sumX += (index / 4) % width;
- sumY += Math.floor(index / 4 / width);
- count++;
- }
- }
-
- expect(count).toBeGreaterThan(30);
- markerPositions.push([sumX / count, sumY / count]);
- }
-
- expect(
- Math.abs(markerPositions[0][0] - markerPositions[1][0]),
- ).toBeLessThan(0.25);
- expect(
- Math.abs(markerPositions[0][1] - markerPositions[1][1]),
- ).toBeLessThan(0.25);
- }
-
- const complete = await render(1, 20, 12);
- expect(complete.getImageData(160, 180, 1, 1).data[3]).toBe(0);
- expect(complete.getImageData(40, 120, 1, 1).data[3]).toBe(128);
- const expanded = await render(2, 20, 12);
- expect(expanded.getImageData(40, 120, 1, 1).data[3]).toBe(0);
- const offscreen = await render(3, 20, 12);
- const pixels = offscreen.getImageData(0, 0, width, height).data;
- let maxAlpha = 0;
- for (let index = 3; index < pixels.length; index += 4) {
- maxAlpha = Math.max(maxAlpha, pixels[index]);
- }
-
- expect(maxAlpha).toBe(0);
- const noRotation = await render(1, 0, 12);
- expect([...noRotation.getImageData(160, 20, 1, 1).data]).toEqual([
- ...context.getImageData(160, 20, 1, 1).data,
- ]);
-});
-
-test('tear() supports any direction without rotating the source image', async () => {
- const width = 320;
- const height = 240;
- const source = document.createElement('canvas');
- source.width = width;
- source.height = height;
- const context = source.getContext('2d')!;
- context.fillStyle = '#ff0000';
- context.fillRect(0, 0, width, height / 2);
- context.fillStyle = '#0000ff';
- context.fillRect(0, height / 2, width, height / 2);
- const directions = [
- {angle: 0, open: [160, 20], intact: [160, 220]},
- {angle: 90, open: [20, 120], intact: [300, 120]},
- {angle: 180, open: [160, 220], intact: [160, 20]},
- {angle: 270, open: [300, 120], intact: [20, 120]},
- {angle: 45, open: [80, 40], intact: [240, 200]},
- {angle: -90, open: [300, 120], intact: [20, 120]},
- {angle: 450, open: [20, 120], intact: [300, 120]},
- ];
- for (const {angle, open, intact} of directions) {
- for (const progress of [0, 0.5, 3]) {
- const canvas = await renderEffectChainToCanvas({
- source,
- width,
- height,
- effects: descriptorsToMemoizedEffects([
- tear({angle, progress, jaggedness: 0}),
- ]),
- });
- const output = canvas.getContext('2d')!;
- if (progress === 0) {
- for (const [x, y] of [
- [5, 5],
- [315, 5],
- [5, 235],
- [315, 235],
- ]) {
- expect([...output.getImageData(x, y, 1, 1).data]).toEqual([
- ...context.getImageData(x, y, 1, 1).data,
- ]);
- }
- } else if (progress === 0.5) {
- expect(output.getImageData(open[0], open[1], 1, 1).data[3]).toBe(0);
- expect([
- ...output.getImageData(intact[0], intact[1], 1, 1).data,
- ]).toEqual([...context.getImageData(intact[0], intact[1], 1, 1).data]);
- } else {
- const pixels = output.getImageData(0, 0, width, height).data;
- let maxAlpha = 0;
- for (let index = 3; index < pixels.length; index += 4) {
- maxAlpha = Math.max(maxAlpha, pixels[index]);
- }
-
- expect(maxAlpha).toBe(0);
- }
- }
- }
-});