Merge branch 'effect'

This commit is contained in:
2024-02-08 18:06:30 +01:00
4 changed files with 94 additions and 11 deletions

View File

@@ -7,3 +7,13 @@ export function grayScale(pixels: Uint8ClampedArray): void {
pixels[i + 2] = lightness;
}
}
export function blackAndWhite(pixels: Uint8ClampedArray): void {
for (let i = 0; i < pixels.length; i += 4) {
const lightness = (pixels[i] * .299 + pixels[i + 1] * .587 + pixels[i + 2] * .114) | 0;
const value = lightness < 128 ? 0 : 255;
pixels[i] = value;
pixels[i + 1] = value;
pixels[i + 2] = value;
}
}