|
import { BasePostProcess } from './base.js';
|
|
|
|
|
|
|
|
|
|
export class InvertPostProcess extends BasePostProcess {
|
|
constructor() {
|
|
super();
|
|
this.name = 'invert';
|
|
this.label = '色反転';
|
|
this.ui = {
|
|
template: `
|
|
<p class="text-muted mb-0"><small>設定はありません</small></p>
|
|
`
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async apply(canvas) {
|
|
|
|
const newCanvas = document.createElement('canvas');
|
|
newCanvas.width = canvas.width;
|
|
newCanvas.height = canvas.height;
|
|
const ctx = newCanvas.getContext('2d');
|
|
|
|
|
|
ctx.drawImage(canvas, 0, 0);
|
|
|
|
|
|
const imageData = ctx.getImageData(0, 0, newCanvas.width, newCanvas.height);
|
|
const data = imageData.data;
|
|
|
|
|
|
for (let i = 0; i < data.length; i += 4) {
|
|
|
|
data[i] = 255 - data[i];
|
|
data[i + 1] = 255 - data[i + 1];
|
|
data[i + 2] = 255 - data[i + 2];
|
|
|
|
}
|
|
|
|
|
|
ctx.putImageData(imageData, 0, 0);
|
|
|
|
return newCanvas;
|
|
}
|
|
} |