diff --git a/Gruntfile.js b/Gruntfile.js index 9871806b..d1e86ae2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -39,6 +39,7 @@ module.exports = function(grunt) { "src/iiiftilesource.js", "src/osmtilesource.js", "src/tmstilesource.js", + "src/zoomifytilesource.js", "src/legacytilesource.js", "src/imagetilesource.js", "src/tilesourcecollection.js", diff --git a/src/zoomifytilesource.js b/src/zoomifytilesource.js new file mode 100644 index 00000000..7066db9e --- /dev/null +++ b/src/zoomifytilesource.js @@ -0,0 +1,142 @@ +(function($) { + + /** + * @class ZoomifyTileSource + * @classdesc A tilesource implementation for the zoomify format. + * + * A description of the format can be found here: + * https://ecommons.cornell.edu/bitstream/handle/1813/5410/Introducing_Zoomify_Image.pdf + * + * There are two ways of creating a zoomify tilesource for openseadragon + * + * 1) Supplying all necessary information in the tilesource object. A minimal example object for this method looks like this: + * + * { + * type: "zoomifytileservice", + * width: 1000, + * height: 1000, + * tilesUrl: "/test/data/zoomify/" + * } + * + * The tilesize if currently hardcoded to 256. The tileUrl must the the path to the image _directory_. + * + * 2) Loading image metadata from xml file: (CURRENTLY NOT SUPPORTED) + * + * When creating zoomify formatted images one "xml" like file with name ImageProperties.xml + * will be created as well. Here is an example of such a file: + * + * + * + * To use this xml file as metadata source you must supply the path to the ImageProperties.xml file and leave out all other parameters: + * As stated above, this method of loading a zoomify tilesource is currently not supported + * + * { + * type: "zoomifytileservice", + * tilesUrl: "/test/data/zoomify/ImageProperties.xml" + * } + + * + * @memberof OpenSeadragon + * @extends OpenSeadragon.TileSource + * @param {Number} width - the pixel width of the image. + * @param {Number} height + * @param {Number} tileSize + * @param {String} tilesUrl + */ + $.ZoomifyTileSource = function(options) { + options.tileSize = 256; + + var currentImageSize = { + x: options.width, + y: options.height + }; + options.imageSizes = [{ + x: options.width, + y: options.height + }]; + options.gridSize = [this._getGridSize(options.width, options.height, options.tileSize)]; + + while (parseInt(currentImageSize.x, 10) > options.tileSize || parseInt(currentImageSize.y, 10) > options.tileSize) { + currentImageSize.x = Math.floor(currentImageSize.x / 2); + currentImageSize.y = Math.floor(currentImageSize.y / 2); + options.imageSizes.push({ + x: currentImageSize.x, + y: currentImageSize.y + }); + options.gridSize.push(this._getGridSize(currentImageSize.x, currentImageSize.y, options.tileSize)); + } + options.imageSizes.reverse(); + options.gridSize.reverse(); + options.minLevel = 0; + options.maxLevel = options.gridSize.length - 1; + + OpenSeadragon.TileSource.apply(this, [options]); + }; + + $.extend($.ZoomifyTileSource.prototype, $.TileSource.prototype, /** @lends OpenSeadragon.ZoomifyTileSource.prototype */ { + + //private + _getGridSize: function(width, height, tileSize) { + return { + x: Math.ceil(width / tileSize), + y: Math.ceil(height / tileSize) + }; + }, + + //private + _calculateAbsoluteTileNumber: function(level, x, y) { + var num = 0; + var size = {}; + + //Sum up all tiles below the level we want the number of tiles + for (var z = 0; z < level; z++) { + size = this.gridSize[z]; + num += size.x * size.y; + } + //Add the tiles of the level + size = this.gridSize[level]; + num += size.x * y + x; + return num; + }, + + /** + * Determine if the data and/or url imply the image service is supported by + * this tile source. + * @function + * @param {Object|Array} data + * @param {String} optional - url + */ + supports: function(data, url) { + return (data.type && "zoomifytileservice" == data.type); + }, + + /** + * + * @function + * @param {Object} data - the raw configuration + * @param {String} url - the url the data was retreived from if any. + * @return {Object} options - A dictionary of keyword arguments sufficient + * to configure this tile sources constructor. + */ + configure: function(data, url) { + return data; + }, + + /** + * @function + * @param {Number} level + * @param {Number} x + * @param {Number} y + */ + getTileUrl: function(level, x, y) { + //console.log(level); + var result = 0; + var num = this._calculateAbsoluteTileNumber(level, x, y); + result = Math.floor(num / 256); + return this.tilesUrl + 'TileGroup' + result + '/' + level + '-' + x + '-' + y + '.jpg'; + + } + }); + +}(OpenSeadragon)); + diff --git a/test/data/zoomify/ImageProperties.xml b/test/data/zoomify/ImageProperties.xml new file mode 100644 index 00000000..60ddf251 --- /dev/null +++ b/test/data/zoomify/ImageProperties.xml @@ -0,0 +1 @@ + diff --git a/test/data/zoomify/TileGroup0/0-0-0.jpg b/test/data/zoomify/TileGroup0/0-0-0.jpg new file mode 100644 index 00000000..d441805d Binary files /dev/null and b/test/data/zoomify/TileGroup0/0-0-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/1-0-0.jpg b/test/data/zoomify/TileGroup0/1-0-0.jpg new file mode 100644 index 00000000..8f8cd6f5 Binary files /dev/null and b/test/data/zoomify/TileGroup0/1-0-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/1-0-1.jpg b/test/data/zoomify/TileGroup0/1-0-1.jpg new file mode 100644 index 00000000..2ccb6d1b Binary files /dev/null and b/test/data/zoomify/TileGroup0/1-0-1.jpg differ diff --git a/test/data/zoomify/TileGroup0/1-1-0.jpg b/test/data/zoomify/TileGroup0/1-1-0.jpg new file mode 100644 index 00000000..9f9523fe Binary files /dev/null and b/test/data/zoomify/TileGroup0/1-1-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/1-1-1.jpg b/test/data/zoomify/TileGroup0/1-1-1.jpg new file mode 100644 index 00000000..9425bd73 Binary files /dev/null and b/test/data/zoomify/TileGroup0/1-1-1.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-0-0.jpg b/test/data/zoomify/TileGroup0/2-0-0.jpg new file mode 100644 index 00000000..c2645b3b Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-0-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-0-1.jpg b/test/data/zoomify/TileGroup0/2-0-1.jpg new file mode 100644 index 00000000..9e74a8b0 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-0-1.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-0-2.jpg b/test/data/zoomify/TileGroup0/2-0-2.jpg new file mode 100644 index 00000000..501e35a6 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-0-2.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-0-3.jpg b/test/data/zoomify/TileGroup0/2-0-3.jpg new file mode 100644 index 00000000..01d24f10 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-0-3.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-1-0.jpg b/test/data/zoomify/TileGroup0/2-1-0.jpg new file mode 100644 index 00000000..43b0f4e6 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-1-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-1-1.jpg b/test/data/zoomify/TileGroup0/2-1-1.jpg new file mode 100644 index 00000000..56cd401c Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-1-1.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-1-2.jpg b/test/data/zoomify/TileGroup0/2-1-2.jpg new file mode 100644 index 00000000..e9df496e Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-1-2.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-1-3.jpg b/test/data/zoomify/TileGroup0/2-1-3.jpg new file mode 100644 index 00000000..02169f4a Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-1-3.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-2-0.jpg b/test/data/zoomify/TileGroup0/2-2-0.jpg new file mode 100644 index 00000000..3fd8a9d8 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-2-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-2-1.jpg b/test/data/zoomify/TileGroup0/2-2-1.jpg new file mode 100644 index 00000000..444d3936 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-2-1.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-2-2.jpg b/test/data/zoomify/TileGroup0/2-2-2.jpg new file mode 100644 index 00000000..54c45605 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-2-2.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-2-3.jpg b/test/data/zoomify/TileGroup0/2-2-3.jpg new file mode 100644 index 00000000..215d5a8a Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-2-3.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-3-0.jpg b/test/data/zoomify/TileGroup0/2-3-0.jpg new file mode 100644 index 00000000..ee428acb Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-3-0.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-3-1.jpg b/test/data/zoomify/TileGroup0/2-3-1.jpg new file mode 100644 index 00000000..d0ed1808 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-3-1.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-3-2.jpg b/test/data/zoomify/TileGroup0/2-3-2.jpg new file mode 100644 index 00000000..7eb9598f Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-3-2.jpg differ diff --git a/test/data/zoomify/TileGroup0/2-3-3.jpg b/test/data/zoomify/TileGroup0/2-3-3.jpg new file mode 100644 index 00000000..5eb4d303 Binary files /dev/null and b/test/data/zoomify/TileGroup0/2-3-3.jpg differ diff --git a/test/modules/formats.js b/test/modules/formats.js index f0edea75..c3a6c850 100644 --- a/test/modules/formats.js +++ b/test/modules/formats.js @@ -154,6 +154,16 @@ url: "/test/data/A.png" }); }); + // ---------- + asyncTest('Zoomify', function () { + testOpen({ + type: "zoomifytileservice", + tileSize: 256, + width: 1000, + height: 1000, + tilesUrl: "/test/data/zoomify/" + }); + }); // ----------