2021-05-05 22:54:03 +08:00
|
|
|
import { Filter } from '../Node';
|
2019-06-19 04:29:07 +08:00
|
|
|
|
2019-02-21 03:04:58 +08:00
|
|
|
// based on https://stackoverflow.com/questions/1061093/how-is-a-sepia-tone-created
|
|
|
|
|
2019-01-02 04:59:27 +08:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name Sepia
|
|
|
|
* @memberof Konva.Filters
|
|
|
|
* @param {Object} imageData
|
|
|
|
* @example
|
|
|
|
* node.cache();
|
|
|
|
* node.filters([Konva.Filters.Sepia]);
|
|
|
|
*/
|
2021-05-05 22:19:24 +08:00
|
|
|
export const Sepia: Filter = function (imageData) {
|
2024-10-29 21:30:37 +08:00
|
|
|
const data = imageData.data,
|
|
|
|
nPixels = data.length;
|
2019-01-02 04:59:27 +08:00
|
|
|
|
2024-10-29 21:30:37 +08:00
|
|
|
for (let i = 0; i < nPixels; i += 4) {
|
|
|
|
const r = data[i + 0];
|
|
|
|
const g = data[i + 1];
|
|
|
|
const b = data[i + 2];
|
2019-01-02 04:59:27 +08:00
|
|
|
|
2019-02-21 03:04:58 +08:00
|
|
|
data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
|
|
|
|
data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
|
|
|
|
data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
|
|
|
|
}
|
2019-01-02 04:59:27 +08:00
|
|
|
};
|