preprocessFilters - internal function called as part of the Display cycle. The process-image filter action loads a Scrawl-canvas asset into the SC Workstore, where it can be used as a lineIn or lineMix argument for other filter actions.
P.preprocessFilters = function (filters, hostWidth, hostHeight) {
for (let i = 0, iz = filters.length, filter; i < iz; i++) {
filter = filters[i];
for (let j = 0, jz = filter.actions.length, obj; j < jz; j++) {
obj = filter.actions[j];
if (obj.action === PROCESS_IMAGE) {
const img = asset[obj.asset];
if (img) {
let width, height, snd, cnd,
copyX, copyY, copyWidth, copyHeight;
if (T_IMAGE !== img.type) {
img.checkSource();
obj.identifier = `user-image-${obj.asset}-${generateUuid()}`;
this.dirtyFilterIdentifier = true;
}
if (!checkForWorkstoreItem(obj.identifier)) {
width = img.sourceNaturalWidth;
height = img.sourceNaturalHeight;
snd = img.sourceNaturalDimensions;
cnd = img.currentDimensions;
if (!width || !height) {
if (snd && snd[0] && snd[1]) {
width = width || snd[0];
height = height || snd[1];
}
else if (cnd && cnd[0] && cnd[1]) {
width = width || cnd[0];
height = height || cnd[1];
}
}
if (width && height) {
copyX = obj.copyX || 0;
copyY = obj.copyY || 0;
copyWidth = obj.copyWidth || 1;
copyHeight = obj.copyHeight || 1;
if (copyX.substring) copyX = (parseFloat(copyX) / 100) * width;
if (copyY.substring) copyY = (parseFloat(copyY) / 100) * height;
if (copyWidth.substring) copyWidth = (parseFloat(copyWidth) / 100) * width;
if (copyHeight.substring) copyHeight = (parseFloat(copyHeight) / 100) * height;
copyX = _floor(_abs(copyX));
copyY = _floor(_abs(copyY));
copyWidth = _floor(_abs(copyWidth));
copyHeight = _floor(_abs(copyHeight));
if (copyX >= width) {
copyX = width - 1;
copyWidth = 1;
}
if (copyWidth > width) {
copyWidth = width;
copyX = 0;
}
if (copyX + copyWidth > width) copyX = width - copyWidth;
if (copyY >= height) {
copyY = height - 1;
copyHeight = 1;
}
if (copyHeight > height) {
copyHeight = height;
copyY = 0;
}
if (copyY + copyHeight > height) copyY = height - copyHeight;
const mycell = requestCell(),
engine = mycell.engine,
canvas = mycell.element;