diff --git a/src/drawer.js b/src/drawer.js index fbf66a76..f3ecada4 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -600,6 +600,27 @@ $.Drawer.prototype = { } }, + + /** + * Turns image smoothing on or off for this viewer. Note: Ignored in some (especially older) browsers that do not support this property. + * + * @function + * @param {Boolean} [imageSmoothingEnabled] - Whether or not the image is + * drawn smoothly on the canvas; see imageSmoothingEnabled in + * {@link OpenSeadragon.Options} for more explanation. + */ + setImageSmoothingEnabled: function(imageSmoothingEnabled){ + if ( this.useCanvas ) { + var context = this.context; + context.mozImageSmoothingEnabled = imageSmoothingEnabled; + context.webkitImageSmoothingEnabled = imageSmoothingEnabled; + context.msImageSmoothingEnabled = imageSmoothingEnabled; + context.imageSmoothingEnabled = imageSmoothingEnabled; + + this.viewer.forceRedraw(); + } + }, + /** * Get the canvas size * @param {Boolean} sketch If set to true return the size of the sketch canvas diff --git a/src/openseadragon.js b/src/openseadragon.js index 8f52b599..77616346 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -198,6 +198,11 @@ * 'destination-over', 'destination-atop', 'destination-in', * 'destination-out', 'lighter', 'copy' or 'xor' * + * @property {Boolean} [imageSmoothingEnabled=true] + * Image smoothing for canvas rendering (only if canvas is used). Note: Ignored + * by some (especially older) browsers which do not support this canvas property. + * This property can be changed in {@link Viewer.Drawer.setImageSmoothingEnabled}. + * * @property {String|CanvasGradient|CanvasPattern|Function} [placeholderFillStyle=null] * Draws a colored rectangle behind the tile if it is not loaded yet. * You can pass a CSS color value like "#FF8800". @@ -1178,6 +1183,7 @@ function OpenSeadragon( options ){ opacity: 1, preload: false, compositeOperation: null, + imageSmoothingEnabled: true, placeholderFillStyle: null, //REFERENCE STRIP SETTINGS diff --git a/src/viewer.js b/src/viewer.js index c9bc2c99..2ccea983 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -466,6 +466,12 @@ $.Viewer = function( options ) { $.requestAnimationFrame( function(){ beginControlsAutoHide( _this ); } ); + + // Initial canvas options + if ( this.imageSmoothingEnabled !== undefined && !this.imageSmoothingEnabled){ + this.drawer.setImageSmoothingEnabled(this.imageSmoothingEnabled); + } + }; $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, /** @lends OpenSeadragon.Viewer.prototype */{