Desaturate Command

This commit is contained in:
Dragon Fire
2020-06-13 19:04:18 -04:00
parent fbd4e3a34a
commit 72973dbcca
3 changed files with 68 additions and 1 deletions
+17
View File
@@ -60,6 +60,23 @@ module.exports = class CanvasUtil {
return ctx;
}
static desaturate(ctx, level, x, y, width, height) {
const data = ctx.getImageData(x, y, width, height);
for (let i = 0; i < height; i++) {
for (let j = 0; j < width; j++) {
const dest = ((j * width) + i) * 4;
const grey = Number.parseInt(
(0.2125 * data.data[dest]) + (0.7154 * data.data[dest + 1]) + (0.0721 * data.data[dest + 2])
, 10);
data.data[dest] += level * (grey - data.data[dest]);
data.data[dest + 1] += level * (grey - data.data[dest + 1]);
data.data[dest + 2] += level * (grey - data.data[dest + 2]);
}
}
ctx.putImageData(data, x, y);
return ctx;
}
static distort(ctx, amplitude, x, y, width, height, strideLevel = 4) {
const data = ctx.getImageData(x, y, width, height);
const temp = ctx.getImageData(x, y, width, height);