Small bugfixes, rename some properties. Add more redraw calls.

This commit is contained in:
Aiosa 2024-03-04 19:23:47 +01:00
parent 47419a090a
commit e2c633a23b
9 changed files with 45 additions and 22 deletions

View File

@ -37,7 +37,7 @@
/**
* @typedef BaseDrawerOptions
* @memberOf OpenSeadragon
* @property {boolean} [detachedCache=false] specify whether the drawer should use
* @property {boolean} [usePrivateCache=false] specify whether the drawer should use
* detached (=internal) cache object in case it has to perform type conversion
*/
@ -96,7 +96,7 @@ OpenSeadragon.DrawerBase = class DrawerBase{
*/
get defaultOptions() {
return {
detachedCache: false
usePrivateCache: false
};
}
@ -142,7 +142,7 @@ OpenSeadragon.DrawerBase = class DrawerBase{
$.console.warn("Attempt to draw tile %s when not cached!", tile);
return null;
}
return cache.getDataForRendering(this.getSupportedDataFormats(), this.options.detachedCache);
return cache.getDataForRendering(this);
}
/**

View File

@ -2660,11 +2660,13 @@ function OpenSeadragon( options ){
}
if (i >= tileList.length) {
viewer.forceRedraw();
clearInterval(interval);
return;
}
const tiledImage = tile.tiledImage;
if (tiledImage.invalidatedAt > tStamp) {
viewer.forceRedraw();
clearInterval(interval);
return;
}

View File

@ -472,9 +472,11 @@ $.Tile.prototype = {
* Get the original data data for this tile
* @param {string} type data type to require
* @param {boolean} [copy=this.loaded] whether to force copy retrieval
* note that if you do not copy the data and save the data to a different cache,
* its destruction will also delete this original data which will likely cause issues
* @return {*|undefined} data in the desired type, or undefined if a conversion is ongoing
*/
getOriginalData: function(type, copy = false) {
getOriginalData: function(type, copy = true) {
if (!this.tiledImage) {
return null; //async can access outside its lifetime
}

View File

@ -167,19 +167,20 @@
*
* When drawers access data, they can choose to access this data as internal copy
*
* @param {Array<string>} supportedTypes required data (or one of) type(s)
* @param {boolean} keepInternalCopy if true, the cache keeps internally the drawer data
* @param {OpenSeadragon.DrawerBase} drawer
* until 'setData' is called
* @returns {any|undefined} desired data if available, undefined if conversion must be done
*/
getDataForRendering(supportedTypes, keepInternalCopy = true) {
getDataForRendering(drawer) {
const supportedTypes = drawer.getSupportedDataFormats(),
keepInternalCopy = drawer.options.usePrivateCache;
if (this.loaded && supportedTypes.includes(this.type)) {
return this.data;
}
let internalCache = this[DRAWER_INTERNAL_CACHE];
if (keepInternalCopy && !internalCache) {
this.prepareForRendering(supportedTypes, keepInternalCopy);
this.prepareForRendering(supportedTypes, keepInternalCopy).then(() => this._triggerNeedsDraw);
return undefined;
}
@ -191,6 +192,7 @@
// Cache in the process of loading, no-op
if (!internalCache.loaded) {
this._triggerNeedsDraw();
return undefined;
}
@ -204,6 +206,7 @@
}
/**
* Should not be called if cache type is already among supported types
* @private
* @param supportedTypes
* @param keepInternalCopy
@ -215,6 +218,10 @@
return $.Promise.resolve(this);
}
if (!keepInternalCopy) {
return this.transformTo(supportedTypes);
}
// we can get here only if we want to render incompatible type
let internalCache = this[DRAWER_INTERNAL_CACHE] = new $.SimpleCacheRecord();
const conversionPath = $.convertor.getConversionPath(this.type, supportedTypes);
@ -423,7 +430,7 @@
_triggerNeedsDraw() {
if (this._tiles.length > 0) {
this._tiles[0].tiledImage.redraw();
this._tiles[0].tiledImage.viewer.forceRedraw();
}
}

View File

@ -302,7 +302,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
return;
}
const tiles = this.tileCache.getLoadedTilesFor(this);
const tiles = this._tileCache.getLoadedTilesFor(this);
$.invalidateTilesLater(tiles, tStamp, this.viewer);
},
@ -2149,7 +2149,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
resolver(tile);
} else if (!requiredTypes.includes(cache.type)) {
//initiate conversion as soon as possible if incompatible with the drawer
cache.prepareForRendering(requiredTypes, _this._drawer.options.detachedCache).then(cacheRef => {
cache.prepareForRendering(requiredTypes, _this._drawer.options.usePrivateCache).then(cacheRef => {
if (!cacheRef) {
return cache.transformTo(requiredTypes);
}

View File

@ -1001,7 +1001,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
* @returns {Boolean}
*/
isMouseNavEnabled: function () {
return this.innerTracker.isTracking();
return this.innerTracker.tracking;
},
/**

View File

@ -109,7 +109,7 @@
get defaultOptions() {
return {
// use detached cache: our type conversion will not collide (and does not have to preserve CPU data ref)
detachedCache: true
usePrivateCache: true
};
}

View File

@ -131,7 +131,12 @@ const switcher = new DrawerSwitcher();
switcher.addDrawerOption("drawer");
$("#title-drawer").html(switcher.activeName("drawer"));
switcher.render("#title-banner");
const sources = {
'Highsmith': "https://openseadragon.github.io/example-images/highsmith/highsmith.dzi",
'Rainbow Grid': "../../data/testpattern.dzi",
'Leaves': "../../data/iiif_2_0_sizes/info.json",
"Duomo":"https://openseadragon.github.io/example-images/duomo/duomo.dzi",
}
const url = new URL(window.location);
const targetSource = url.searchParams.get("image") || Object.values(sources)[0];
const viewer = window.viewer = new OpenSeadragon({
@ -142,12 +147,6 @@ const viewer = window.viewer = new OpenSeadragon({
drawer: switcher.activeImplementation("drawer"),
});
const sources = {
'Highsmith': "https://openseadragon.github.io/example-images/highsmith/highsmith.dzi",
'Rainbow Grid': "../../data/testpattern.dzi",
'Leaves': "../../data/iiif_2_0_sizes/info.json",
"Duomo":"https://openseadragon.github.io/example-images/duomo/duomo.dzi",
}
$("#image-select")
.html(Object.entries(sources).map(([k, v]) =>
`<option value="${v}" ${targetSource === v ? "selected" : ""}>${k}</option>`).join("\n"))
@ -772,3 +771,17 @@ function updateFilters() {
});
}
window.debugCache = function () {
for (let cacheKey in viewer.tileCache._cachesLoaded) {
let cache = viewer.tileCache._cachesLoaded[cacheKey];
if (!cache.loaded) {
console.log(cacheKey, "skipping...");
}
if (cache.type === "context2d") {
console.log(cacheKey, cache.data.canvas.width, cache.data.canvas.height);
} else {
console.log(cacheKey, cache.data);
}
}
}

View File

@ -83,7 +83,7 @@
if (processors.length === 0) {
//restore the original data
const context = await tile.getOriginalData('context2d', false);
const context = await tile.getOriginalData('context2d', true);
tile.setData(context, 'context2d');
tile._filterIncrement = self.filterIncrement;
return;
@ -117,7 +117,6 @@
}
instance.filterIncrement++;
instance.viewer.world.invalidateItems();
instance.viewer.forceRedraw();
}
function getFiltersProcessors(instance, item) {