Add fixes for working smoothing in the webgl renderer.

This commit is contained in:
Aiosa 2024-11-21 16:51:38 +01:00
parent ce4b16616d
commit f03f2a5d31
4 changed files with 38 additions and 13 deletions

View File

@ -128,6 +128,16 @@ OpenSeadragon.DrawerBase = class DrawerBase{
return undefined;
}
/**
* Retrieve required data formats the data must be converted to.
* This list MUST BE A VALID SUBSET OF getSupportedDataFormats()
* @abstract
* @return {string[]}
*/
getRequiredDataFormats() {
return this.getSupportedDataFormats();
}
/**
* Retrieve data types
* @abstract

View File

@ -256,22 +256,29 @@
}
internalCache = internalCache[drawerId];
if (internalCache) {
if (internalCache && supportedTypes.includes(internalCache.type)) {
// already done
return $.Promise.resolve(this);
}
internalCache = this[DRAWER_INTERNAL_CACHE][drawerId] = new $.SimpleCacheRecord();
const conversionPath = $.convertor.getConversionPath(this.type, supportedTypes);
if (!conversionPath) {
$.console.error(`[getDataForRendering] Conversion ${this.type} ---> ${supportedTypes} cannot be done!`);
return $.Promise.resolve(this);
}
internalCache.withTileReference(this._tRef);
const newInternalCache = new $.SimpleCacheRecord();
newInternalCache.withTileReference(this._tRef);
const selectedFormat = conversionPath[conversionPath.length - 1].target.value;
return $.convertor.convert(this._tRef, this.data, this.type, selectedFormat).then(data => {
internalCache.setDataAs(data, selectedFormat); // synchronous, SimpleCacheRecord call
return internalCache;
newInternalCache.setDataAs(data, selectedFormat); // synchronous, SimpleCacheRecord call
// if existed, delete
if (internalCache) {
internalCache.destroy();
}
this[DRAWER_INTERNAL_CACHE][drawerId] = newInternalCache;
return newInternalCache;
});
}

View File

@ -100,9 +100,9 @@
this._setupCanvases();
this._setupRenderer();
this._supportedFormats = [];
this._supportedFormats = this._setupTextureHandlers();
this._requiredFormats = this._supportedFormats;
this._setupCallCount = 1;
this._setupTextureHandlers();
this.context = this._outputContext; // API required by tests
}
@ -468,6 +468,10 @@
}
getRequiredDataFormats() {
return this._requiredFormats;
}
// Public API required by all Drawer implementations
/**
* Sets whether image smoothing is enabled or disabled
@ -476,7 +480,12 @@
setImageSmoothingEnabled(enabled){
if( this._imageSmoothingEnabled !== enabled ){
this._imageSmoothingEnabled = enabled;
this._setupTextureHandlers(); // re-sets the type to enforce re-initialization
// Todo consider removing old type handlers if _supportedFormats had already types defined,
// and remove support for rendering old types...
const newFormats = this._setupTextureHandlers(); // re-sets the type to enforce re-initialization
this._supportedFormats.push(...newFormats);
this._requiredFormats = newFormats;
return this.viewer.requestInvalidate();
}
return $.Promise.resolve();
@ -892,8 +901,8 @@
// Set the parameters so we can render any size image.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, _this._textureFilter());
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, _this._textureFilter());
try{
// This depends on gl.TEXTURE_2D being bound to the texture
@ -919,8 +928,6 @@
// Differentiate type also based on type used to upload data: we can support bidirectional conversion.
const c2dTexType = thisType + ":context2d",
imageTexType = thisType + ":image";
// Todo consider removing old type handlers if _supportedFormats had already types defined
this._supportedFormats = [c2dTexType, imageTexType];
// We should be OK uploading any of these types. The complexity is selected to be O(3n), should be
// more than linear pass over pixels
@ -929,6 +936,7 @@
$.convertor.learnDestroy(c2dTexType, tex2DCompatibleDestructor);
$.convertor.learnDestroy(imageTexType, tex2DCompatibleDestructor);
return [c2dTexType, imageTexType];
}
// private

View File

@ -303,7 +303,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
// We call the event on the parent viewer window no matter what
const eventTarget = this.viewer.viewer || this.viewer;
// However, we must pick the correct drawer reference (navigator VS viewer)
const supportedFormats = this.viewer.drawer.getSupportedDataFormats();
const supportedFormats = this.viewer.drawer.getRequiredDataFormats();
const keepInternalCacheCopy = this.viewer.drawer.options.usePrivateCache;
const drawerId = this.viewer.drawer.getId();