Update demo plugins to the new api design

This commit is contained in:
Aiosa 2024-11-13 15:04:09 +01:00
parent 541fe2e4df
commit e24f7d1358
2 changed files with 6 additions and 22 deletions

View File

@ -49,10 +49,6 @@
this.viewer = options.viewer; this.viewer = options.viewer;
this.viewer.addHandler('tile-invalidated', applyFilters); this.viewer.addHandler('tile-invalidated', applyFilters);
// filterIncrement allows to determine whether a tile contains the
// latest filters results.
this.filterIncrement = 0;
setOptions(this, options); setOptions(this, options);
async function applyFilters(e) { async function applyFilters(e) {
@ -66,23 +62,12 @@
const contextCopy = await e.getData('context2d'); const contextCopy = await e.getData('context2d');
if (!contextCopy) return; if (!contextCopy) return;
if (contextCopy.canvas.width === 0) { for (let i = 0; i < processors.length; i++) {
debugger; if (e.outdated()) return;
} await processors[i](contextCopy);
try {
const currentIncrement = self.filterIncrement;
for (let i = 0; i < processors.length; i++) {
if (self.filterIncrement !== currentIncrement) {
break;
}
await processors[i](contextCopy);
}
await e.setData(contextCopy, 'context2d');
} catch (e) {
// pass, this is error caused by canvas being destroyed & replaced
} }
if (e.outdated()) return;
await e.setData(contextCopy, 'context2d');
} }
}; };
@ -99,7 +84,6 @@
filter.processors = $.isArray(filter.processors) ? filter.processors = $.isArray(filter.processors) ?
filter.processors : [filter.processors]; filter.processors : [filter.processors];
} }
instance.filterIncrement++;
instance.viewer.requestInvalidate(); instance.viewer.requestInvalidate();
} }

View File

@ -109,7 +109,7 @@ window.pluginB = async function(e) {
const canvas = ctx.canvas; const canvas = ctx.canvas;
ctx.fillStyle = "rgba(156, 0, 26, 0.4)"; ctx.fillStyle = "rgba(156, 0, 26, 0.4)";
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height);
await tile.setData(ctx, 'context2d'); await e.setData(ctx, 'context2d');
} }
}; };
// higher number = earlier execution // higher number = earlier execution