UNPKG

konva

Version:

HTML5 2d canvas library.

15 lines (14 loc) 419 B
export const Solarize = function (imageData) { const threshold = 128; const d = imageData.data; for (let i = 0; i < d.length; i += 4) { const r = d[i], g = d[i + 1], b = d[i + 2]; const L = 0.2126 * r + 0.7152 * g + 0.0722 * b; if (L >= threshold) { d[i] = 255 - r; d[i + 1] = 255 - g; d[i + 2] = 255 - b; } } return imageData; };