From 661fef19b5e7fede4dd7451cdf2251d1e6c7af96 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Thu, 14 Mar 2019 14:04:12 +0100 Subject: [PATCH 1/9] fix for #1617 and #1343 --- src/iiiftilesource.js | 56 ++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index c80a3f2d..fee31f68 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -55,6 +55,16 @@ $.IIIFTileSource = function( options ){ options.tileSizePerScaleFactor = {}; + this.usedFormat = "jpg"; + if ( this.formatHints ) { + for (var f = 0; f < this.formatHints.length; f++ ) { + if ( $.imageFormatSupported(this.formatHints[f]) ) { + this.usedFormat = this.formatHints[f]; + break; + } + } + } + // N.B. 2.0 renamed scale_factors to scaleFactors if ( this.tile_width && this.tile_height ) { options.tileWidth = this.tile_width; @@ -337,32 +347,46 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea iiifTileW, iiifTileH, iiifSize, + iiifSizeW, iiifQuality, - uri; + uri, + isv1; tileWidth = this.getTileWidth(level); tileHeight = this.getTileHeight(level); iiifTileSizeWidth = Math.ceil( tileWidth / scale ); iiifTileSizeHeight = Math.ceil( tileHeight / scale ); - - if ( this['@context'].indexOf('/1.0/context.json') > -1 || + isv1 = ( this['@context'].indexOf('/1.0/context.json') > -1 || this['@context'].indexOf('/1.1/context.json') > -1 || - this['@context'].indexOf('/1/context.json') > -1 ) { - iiifQuality = "native.jpg"; + this['@context'].indexOf('/1/context.json') > -1 ); + if (isv1) { + iiifQuality = "native." + this.usedFormat; } else { - iiifQuality = "default.jpg"; + iiifQuality = "default." + this.usedFormat; } - if ( levelWidth < tileWidth && levelHeight < tileHeight ){ - iiifSize = levelWidth + ","; + if (isv1) { + iiifSize = levelWidth + ","; + } else { + iiifSize = "max"; + } iiifRegion = 'full'; } else { iiifTileX = x * iiifTileSizeWidth; iiifTileY = y * iiifTileSizeHeight; iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX ); iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY ); - iiifSize = Math.ceil( iiifTileW * scale ) + ","; - iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' ); + if ( x == 0 && y == 0 && iiifTileW == this.width && iiifTileH == this.height ) { + iiifRegion = "full"; + } else { + iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' ); + } + iiifSizeW = Math.ceil( iiifTileW * scale ); + if ( (!isv1) && iiifSizeW == this.width ) { + iiifSize = "max"; + } else { + iiifSize = iiifSizeW + ","; + } } uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' ); @@ -374,17 +398,21 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea /** * Determine whether arbitrary tile requests can be made against a service with the given profile * @function - * @param {object} profile - IIIF profile object + * @param {array} profile - IIIF profile array * @throws {Error} */ - function canBeTiled (profile ) { + function canBeTiled ( profile ) { var level0Profiles = [ "http://library.stanford.edu/iiif/image-api/compliance.html#level0", "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", "http://iiif.io/api/image/2/level0.json" ]; var isLevel0 = (level0Profiles.indexOf(profile[0]) != -1); - return !isLevel0 || (profile.indexOf("sizeByW") != -1); + var hasSizeByW = false; + if ( profile.length > 1 && profile[1].supports ) { + hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) != -1; + } + return !isLevel0 || hasSizeByW; } /** @@ -397,7 +425,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea var levels = []; for(var i = 0; i < options.sizes.length; i++) { levels.push({ - url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.jpg', + url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.' + this.usedFormat, width: options.sizes[i].width, height: options.sizes[i].height }); From e4987f9701a1e822c673a6b0c45bfd0f1f3ba342 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Thu, 14 Mar 2019 16:10:28 +0100 Subject: [PATCH 2/9] fix too agressive canonicalization --- src/iiiftilesource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index fee31f68..df1d0154 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -365,7 +365,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea iiifQuality = "default." + this.usedFormat; } if ( levelWidth < tileWidth && levelHeight < tileHeight ){ - if (isv1) { + if ( isv1 || levelWidth != this.width ) { iiifSize = levelWidth + ","; } else { iiifSize = "max"; From b38f5d609bd3c23b2b1267c06596ff8a219b97df Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Thu, 14 Mar 2019 19:10:40 +0100 Subject: [PATCH 3/9] use === and !== --- src/iiiftilesource.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index df1d0154..0b97e661 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -365,7 +365,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea iiifQuality = "default." + this.usedFormat; } if ( levelWidth < tileWidth && levelHeight < tileHeight ){ - if ( isv1 || levelWidth != this.width ) { + if ( isv1 || levelWidth !== this.width ) { iiifSize = levelWidth + ","; } else { iiifSize = "max"; @@ -376,13 +376,13 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea iiifTileY = y * iiifTileSizeHeight; iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX ); iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY ); - if ( x == 0 && y == 0 && iiifTileW == this.width && iiifTileH == this.height ) { + if ( x === 0 && y === 0 && iiifTileW === this.width && iiifTileH === this.height ) { iiifRegion = "full"; } else { iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' ); } iiifSizeW = Math.ceil( iiifTileW * scale ); - if ( (!isv1) && iiifSizeW == this.width ) { + if ( (!isv1) && iiifSizeW === this.width ) { iiifSize = "max"; } else { iiifSize = iiifSizeW + ","; @@ -407,10 +407,10 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", "http://iiif.io/api/image/2/level0.json" ]; - var isLevel0 = (level0Profiles.indexOf(profile[0]) != -1); + var isLevel0 = (level0Profiles.indexOf(profile[0]) !== -1); var hasSizeByW = false; if ( profile.length > 1 && profile[1].supports ) { - hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) != -1; + hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) !== -1; } return !isLevel0 || hasSizeByW; } From f8022385f7c8716bcbd0f24c995c45e93a9d1232 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Thu, 14 Mar 2019 19:58:38 +0100 Subject: [PATCH 4/9] fix qunit error --- src/iiiftilesource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index 0b97e661..54f744f8 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -425,7 +425,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea var levels = []; for(var i = 0; i < options.sizes.length; i++) { levels.push({ - url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.' + this.usedFormat, + url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.' + options.usedFormat, width: options.sizes[i].width, height: options.sizes[i].height }); From 81e030e6538090e437b0df5c6b761488d22a5a6c Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Thu, 14 Mar 2019 21:03:28 +0100 Subject: [PATCH 5/9] add formatHints options --- src/tilesource.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tilesource.js b/src/tilesource.js index d85f5ee6..cda10d7a 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -69,6 +69,11 @@ * the XHR's withCredentials (for accessing secure data). * @param {Object} [options.ajaxHeaders] * A set of headers to include in AJAX requests. + * @param {Object} [options.formatHints] + * An array of extensions to use for image URLs, by descending order of + * preference. The extensions are tested against the supported formats, + * in case none of the extension values is supported, the default (jpg) + * will be used. * @param {Number} [options.width] * Width of the source image at max resolution in pixels. * @param {Number} [options.height] @@ -218,6 +223,7 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve } this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0; + this.formatHints = options.formatHints; this.minLevel = options.minLevel ? options.minLevel : 0; this.maxLevel = ( undefined !== options.maxLevel && null !== options.maxLevel ) ? options.maxLevel : ( From 0810d97b6975466a388ce8f5413e46fde9e0abc5 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Tue, 19 Mar 2019 08:39:01 +0100 Subject: [PATCH 6/9] no direct support for formatHints --- src/iiiftilesource.js | 8 -------- src/tilesource.js | 6 ------ 2 files changed, 14 deletions(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index 54f744f8..0e9f53b8 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -56,14 +56,6 @@ $.IIIFTileSource = function( options ){ options.tileSizePerScaleFactor = {}; this.usedFormat = "jpg"; - if ( this.formatHints ) { - for (var f = 0; f < this.formatHints.length; f++ ) { - if ( $.imageFormatSupported(this.formatHints[f]) ) { - this.usedFormat = this.formatHints[f]; - break; - } - } - } // N.B. 2.0 renamed scale_factors to scaleFactors if ( this.tile_width && this.tile_height ) { diff --git a/src/tilesource.js b/src/tilesource.js index cda10d7a..d85f5ee6 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -69,11 +69,6 @@ * the XHR's withCredentials (for accessing secure data). * @param {Object} [options.ajaxHeaders] * A set of headers to include in AJAX requests. - * @param {Object} [options.formatHints] - * An array of extensions to use for image URLs, by descending order of - * preference. The extensions are tested against the supported formats, - * in case none of the extension values is supported, the default (jpg) - * will be used. * @param {Number} [options.width] * Width of the source image at max resolution in pixels. * @param {Number} [options.height] @@ -223,7 +218,6 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve } this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0; - this.formatHints = options.formatHints; this.minLevel = options.minLevel ? options.minLevel : 0; this.maxLevel = ( undefined !== options.maxLevel && null !== options.maxLevel ) ? options.maxLevel : ( From 3f91bafcf80265b516a7085f94b35427aff98b13 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Tue, 19 Mar 2019 08:47:40 +0100 Subject: [PATCH 7/9] rename usedFormat to tileFormat --- src/iiiftilesource.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index 0e9f53b8..f7054643 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -55,7 +55,7 @@ $.IIIFTileSource = function( options ){ options.tileSizePerScaleFactor = {}; - this.usedFormat = "jpg"; + this.tileFormat = "jpg"; // N.B. 2.0 renamed scale_factors to scaleFactors if ( this.tile_width && this.tile_height ) { @@ -352,9 +352,9 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea this['@context'].indexOf('/1.1/context.json') > -1 || this['@context'].indexOf('/1/context.json') > -1 ); if (isv1) { - iiifQuality = "native." + this.usedFormat; + iiifQuality = "native." + this.tileFormat; } else { - iiifQuality = "default." + this.usedFormat; + iiifQuality = "default." + this.tileFormat; } if ( levelWidth < tileWidth && levelHeight < tileHeight ){ if ( isv1 || levelWidth !== this.width ) { @@ -417,7 +417,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea var levels = []; for(var i = 0; i < options.sizes.length; i++) { levels.push({ - url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.' + options.usedFormat, + url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.' + options.tileFormat, width: options.sizes[i].width, height: options.sizes[i].height }); From db86ae28c8d92c471035f353bfc6cbd6cd8eb968 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Tue, 19 Mar 2019 18:22:09 +0100 Subject: [PATCH 8/9] address PR comments --- src/iiiftilesource.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index f7054643..8c6c11a6 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -42,6 +42,8 @@ * @memberof OpenSeadragon * @extends OpenSeadragon.TileSource * @see http://iiif.io/api/image/ + * @param {String} [options.tileFormat] + * The extension that will be used when requiring tiles (defaults to "jpg"). */ $.IIIFTileSource = function( options ){ @@ -55,7 +57,7 @@ $.IIIFTileSource = function( options ){ options.tileSizePerScaleFactor = {}; - this.tileFormat = "jpg"; + this.tileFormat = this.tileFormat || 'jpg'; // N.B. 2.0 renamed scale_factors to scaleFactors if ( this.tile_width && this.tile_height ) { From 427ac45a8af56652a41ccdc457e488b0a0d45c02 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Tue, 19 Mar 2019 18:23:27 +0100 Subject: [PATCH 9/9] better description --- src/iiiftilesource.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index 8c6c11a6..9840a853 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -42,8 +42,8 @@ * @memberof OpenSeadragon * @extends OpenSeadragon.TileSource * @see http://iiif.io/api/image/ - * @param {String} [options.tileFormat] - * The extension that will be used when requiring tiles (defaults to "jpg"). + * @param {String} [options.tileFormat='jpg'] + * The extension that will be used when requiring tiles. */ $.IIIFTileSource = function( options ){