mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 14:04:38 +02:00
Sepia stuff
This commit is contained in:
@@ -94,6 +94,18 @@ class Util {
|
||||
ctx.putImageData(data, x, y);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static sepia(ctx, x, y, width, height) {
|
||||
const data = ctx.getImageData(x, y, width, height);
|
||||
for (let i = 0; i < data.data.length; i += 4) {
|
||||
const brightness = (0.34 * data.data[i]) + (0.5 * data.data[i + 1]) + (0.16 * data.data[i + 2]);
|
||||
data.data[i] = brightness + 100;
|
||||
data.data[i + 1] = brightness + 50;
|
||||
data.data[i + 2] = brightness;
|
||||
}
|
||||
ctx.putImageData(data, x, y);
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user