This commit is contained in:
Elie Roux 2019-03-14 14:04:12 +01:00
parent 6426f6fc21
commit 661fef19b5

View File

@ -55,6 +55,16 @@ $.IIIFTileSource = function( options ){
options.tileSizePerScaleFactor = {}; 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 // N.B. 2.0 renamed scale_factors to scaleFactors
if ( this.tile_width && this.tile_height ) { if ( this.tile_width && this.tile_height ) {
options.tileWidth = this.tile_width; options.tileWidth = this.tile_width;
@ -337,33 +347,47 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
iiifTileW, iiifTileW,
iiifTileH, iiifTileH,
iiifSize, iiifSize,
iiifSizeW,
iiifQuality, iiifQuality,
uri; uri,
isv1;
tileWidth = this.getTileWidth(level); tileWidth = this.getTileWidth(level);
tileHeight = this.getTileHeight(level); tileHeight = this.getTileHeight(level);
iiifTileSizeWidth = Math.ceil( tileWidth / scale ); iiifTileSizeWidth = Math.ceil( tileWidth / scale );
iiifTileSizeHeight = Math.ceil( tileHeight / scale ); iiifTileSizeHeight = Math.ceil( tileHeight / scale );
isv1 = ( this['@context'].indexOf('/1.0/context.json') > -1 ||
if ( this['@context'].indexOf('/1.0/context.json') > -1 ||
this['@context'].indexOf('/1.1/context.json') > -1 || this['@context'].indexOf('/1.1/context.json') > -1 ||
this['@context'].indexOf('/1/context.json') > -1 ) { this['@context'].indexOf('/1/context.json') > -1 );
iiifQuality = "native.jpg"; if (isv1) {
iiifQuality = "native." + this.usedFormat;
} else { } else {
iiifQuality = "default.jpg"; iiifQuality = "default." + this.usedFormat;
} }
if ( levelWidth < tileWidth && levelHeight < tileHeight ){ if ( levelWidth < tileWidth && levelHeight < tileHeight ){
if (isv1) {
iiifSize = levelWidth + ","; iiifSize = levelWidth + ",";
} else {
iiifSize = "max";
}
iiifRegion = 'full'; iiifRegion = 'full';
} else { } else {
iiifTileX = x * iiifTileSizeWidth; iiifTileX = x * iiifTileSizeWidth;
iiifTileY = y * iiifTileSizeHeight; iiifTileY = y * iiifTileSizeHeight;
iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX ); iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX );
iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY ); iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY );
iiifSize = Math.ceil( iiifTileW * scale ) + ","; if ( x == 0 && y == 0 && iiifTileW == this.width && iiifTileH == this.height ) {
iiifRegion = "full";
} else {
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' ); 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( '/' ); uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
return uri; return uri;
@ -374,7 +398,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
/** /**
* Determine whether arbitrary tile requests can be made against a service with the given profile * Determine whether arbitrary tile requests can be made against a service with the given profile
* @function * @function
* @param {object} profile - IIIF profile object * @param {array} profile - IIIF profile array
* @throws {Error} * @throws {Error}
*/ */
function canBeTiled ( profile ) { function canBeTiled ( profile ) {
@ -384,7 +408,11 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
"http://iiif.io/api/image/2/level0.json" "http://iiif.io/api/image/2/level0.json"
]; ];
var isLevel0 = (level0Profiles.indexOf(profile[0]) != -1); 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 = []; var levels = [];
for(var i = 0; i < options.sizes.length; i++) { for(var i = 0; i < options.sizes.length; i++) {
levels.push({ 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, width: options.sizes[i].width,
height: options.sizes[i].height height: options.sizes[i].height
}); });