P.cleanOutput = function () {
this.dirtyOutput = false;
const sourceDimension = this.sourceDimension,
sourceData = this.sourceImageData;
if (sourceDimension && sourceData) {
const fromPathData = this.fromPathData,
toPathData = this.toPathData,
dataLen = fromPathData.length,
fPathStart = this.fromPathStart,
fStep = this.fromPathSteps || 1,
tPathStart = this.toPathStart,
tStep = this.toPathSteps || 1,
magicVerticalPi = _piHalf - 1.5708,
isHorizontalCopy = this.isHorizontalCopy,
loop = this.loopPathCursors,
watchFromPath = this.watchFromPath,
engineInstructions = this.engineInstructions,
engineDeltaLengths = this.engineDeltaLengths;
let fCursor = fPathStart * dataLen,
tCursor = tPathStart * dataLen,
watchIndex = this.watchIndex,
fx, fy, tx, ty, dx, dy, dLength, dAngle, cos, sin, i, j,
instruction;
let [, , outputWidth, outputHeight] = this.getBoundingBox();
if (outputWidth && outputHeight) {
outputWidth = ~~outputWidth;
outputHeight = ~~outputHeight;
const inputCell = requestCell(),
inputEngine = inputCell.engine,
inputCanvas = inputCell.element;
inputCanvas.width = sourceDimension;
inputCanvas.height = sourceDimension;
inputEngine.resetTransform();
inputEngine.putImageData(sourceData, 0, 0);
const outputCell = requestCell(),
outputEngine = outputCell.engine,
outputCanvas = outputCell.element;
outputCanvas.width = outputWidth;
outputCanvas.height = outputHeight;
outputEngine.globalAlpha = this.state.globalAlpha;
outputEngine.resetTransform();
if(!engineInstructions.length) {
for (i = 0; i < sourceDimension; i++) {
if (watchIndex < 0) {
if (watchFromPath && fCursor < 1) watchIndex = i;
else if (!watchFromPath && tCursor < 1) watchIndex = i;
}
if (fCursor < dataLen && tCursor < dataLen && fCursor >= 0 && tCursor >= 0) {
[fx, fy] = fromPathData[_floor(fCursor)];
[tx, ty] = toPathData[_floor(tCursor)];
dx = tx - fx;
dy = ty - fy;
dLength = _hypot(dx, dy);
if (isHorizontalCopy) {
dAngle = -_atan2(dx, dy) + _piHalf;
cos = _cos(dAngle);
sin = _sin(dAngle);
engineInstructions.push([cos, sin, -sin, cos, fx, fy]);
engineDeltaLengths.push(dLength);
}
else {
dAngle = -_atan2(dx, dy) + magicVerticalPi;
cos = _cos(dAngle);
sin = _sin(dAngle);
engineInstructions.push([cos, sin, -sin, cos, fx, fy, dLength]);
engineDeltaLengths.push(dLength);
}
}
else {
engineInstructions.push(false);
engineDeltaLengths.push(false);
}
fCursor += fStep;
tCursor += tStep;
if (loop) {
if (fCursor >= dataLen) fCursor -= dataLen;
if (tCursor >= dataLen) tCursor -= dataLen;
}
}
if (watchIndex < 0) watchIndex = 0;
this.watchIndex = watchIndex;
}
if (isHorizontalCopy) {
for (i = 0; i < sourceDimension; i++) {
instruction = engineInstructions[watchIndex];
if (instruction) {
outputEngine.setTransform(...instruction);
outputEngine.drawImage(inputCanvas, 0, ~~watchIndex, ~~sourceDimension, 1, 0, 0, ~~engineDeltaLengths[watchIndex], 1);
}
watchIndex++;
if (watchIndex >= sourceDimension) watchIndex = 0;
}
}
else {
for (i = 0; i < sourceDimension; i++) {
instruction = engineInstructions[watchIndex];
if (instruction) {
outputEngine.setTransform(...instruction);
outputEngine.drawImage(inputCanvas, ~~watchIndex, 0, 1, ~~sourceDimension, 0, 0, 1, ~~engineDeltaLengths[watchIndex]);
}
watchIndex++;
if (watchIndex >= sourceDimension) watchIndex = 0;
}
}
const iFactor = this.interferenceFactor,
iLoops = this.interferenceLoops,
iWidth = ~~(outputWidth * iFactor) + 1,
iHeight = ~~(outputHeight * iFactor) + 1;
inputCanvas.width = iWidth;
inputCanvas.height = iHeight;
outputEngine.resetTransform();
inputEngine.resetTransform();
for (j = 0; j < iLoops; j++) {
inputEngine.drawImage(outputCanvas, 0, 0, outputWidth, outputHeight, 0, 0, iWidth, iHeight);
outputEngine.drawImage(inputCanvas, 0, 0, iWidth, iHeight, 0, 0, outputWidth, outputHeight);
}
const outputData = outputEngine.getImageData(0, 0, outputWidth, outputHeight);
releaseCell(inputCell, outputCell);
this.dirtyTargetImage = true;
return outputData;
}
else this.dirtyOutput = true;
}
return false;
};