Skip to content

Commit

Permalink
fix edges not being blurred
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushnirwal committed Apr 17, 2023
1 parent 359aa7a commit 9440559
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,26 @@ function PlaybackMedia() {
context.save();

const segmentationMask = new Uint8ClampedArray(

Check warning on line 110 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L110

Added line #L110 was not covered by tests
streamNode.videoWidth * streamNode.videoHeight * 4
canvas.width * canvas.height * 4
);
const mask = masks[0];
for (let i = 0; i < mask.length; i++) {
const isBackround = mask[i] === 0;
segmentationMask[i * 4] = isBackround ? 255 : 0;
segmentationMask[i * 4 + 1] = isBackround ? 255 : 0;
segmentationMask[i * 4 + 2] = isBackround ? 255 : 0;
segmentationMask[i * 4 + 3] = isBackround ? 255 : 0;
segmentationMask[i * 4] = isBackround ? 0 : 255;
segmentationMask[i * 4 + 1] = isBackround ? 0 : 255;
segmentationMask[i * 4 + 2] = isBackround ? 0 : 255;
segmentationMask[i * 4 + 3] = isBackround ? 0 : 255;

Check warning on line 119 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L113-L119

Added lines #L113 - L119 were not covered by tests
}
const segmentationMaskBitMap = await createImageBitmap(

Check warning on line 121 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L121

Added line #L121 was not covered by tests
new ImageData(
segmentationMask,
streamNode.videoWidth,
streamNode.videoHeight
)
new ImageData(segmentationMask, canvas.width, canvas.height)
);

if (!canvasBlur) {
context.drawImage(streamNode, 0, 0, canvas.width, canvas.height);

Check warning on line 126 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L126

Added line #L126 was not covered by tests

blur(context, BACKGROUND_BLUR_PX);

context.globalCompositeOperation = 'destination-in';
context.globalCompositeOperation = 'destination-out';
context.drawImage(
segmentationMaskBitMap,
0,
Expand All @@ -143,7 +139,7 @@ function PlaybackMedia() {
context.drawImage(streamNode, 0, 0, canvas.width, canvas.height);

Check warning on line 139 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L139

Added line #L139 was not covered by tests
} else {
context.globalCompositeOperation = 'copy';
context.filter = 'none';
context.filter = `blur(${BACKGROUND_BLUR_PX}px)`;
context.drawImage(
segmentationMaskBitMap,
0,
Expand All @@ -153,11 +149,11 @@ function PlaybackMedia() {
);

context.globalCompositeOperation = 'source-in';
context.filter = `blur(${BACKGROUND_BLUR_PX}px)`;
context.filter = `none`;
context.drawImage(streamNode, 0, 0, canvas.width, canvas.height);

Check warning on line 153 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L152-L153

Added lines #L152 - L153 were not covered by tests

context.globalCompositeOperation = 'destination-over';
context.filter = 'none';
context.filter = `blur(${BACKGROUND_BLUR_PX}px)`;
context.drawImage(streamNode, 0, 0, canvas.width, canvas.height);

Check warning on line 157 in packages/story-editor/src/components/mediaRecording/playbackMedia.js

View check run for this annotation

Codecov / codecov/patch

packages/story-editor/src/components/mediaRecording/playbackMedia.js#L157

Added line #L157 was not covered by tests
}

Expand Down

0 comments on commit 9440559

Please sign in to comment.