From 0507132a218eacdcc935ec1c47689ee7bedf72f0 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Tue, 2 Jul 2019 13:21:09 +0200 Subject: [PATCH] Correct and test IIIF version 3 image info parser --- src/ol/format/IIIFInfo.js | 2 +- test/spec/ol/format/iiif.test.js | 69 ++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/ol/format/IIIFInfo.js b/src/ol/format/IIIFInfo.js index c8f7714ef2..311349cfb2 100644 --- a/src/ol/format/IIIFInfo.js +++ b/src/ol/format/IIIFInfo.js @@ -264,7 +264,7 @@ function generateVersion3Options(iiifInfo) { [...levelProfile.supports, ...iiifInfo.imageInfo.extraFeatures], formats: formats, qualities: iiifInfo.imageInfo.extraQualities === undefined ? levelProfile.qualities : - [...levelProfile.supports, ...iiifInfo.imageInfo.extraQualities], + [...levelProfile.qualities, ...iiifInfo.imageInfo.extraQualities], preferredFormat: preferredFormat }; } diff --git a/test/spec/ol/format/iiif.test.js b/test/spec/ol/format/iiif.test.js index debce651b5..cbd9d08517 100644 --- a/test/spec/ol/format/iiif.test.js +++ b/test/spec/ol/format/iiif.test.js @@ -323,7 +323,22 @@ describe('ol.format.IIIFInfo', function() { height: 1500, profile: ['http://iiif.io/api/image/2/level2.json'] }); - const options = iiifInfo.getTileSourceOptions({ + let options = iiifInfo.getTileSourceOptions({ + quality: 'bitonal', + format: 'png' + }); + expect(options).to.have.property('quality', 'bitonal'); + expect(options).to.have.property('format', 'png'); + + iiifInfo.setImageInfo({ + '@context': 'http://iiif.io/api/image/3/context.json', + '@id': 'http://iiif.test/version3/id', + width: 2000, + height: 1500, + profile: 'level2', + extraQualities: ['gray', 'bitonal'] + }); + options = iiifInfo.getTileSourceOptions({ quality: 'bitonal', format: 'png' }); @@ -341,7 +356,21 @@ describe('ol.format.IIIFInfo', function() { height: 1500, profile: ['http://iiif.io/api/image/2/level1.json'] }); - const options = iiifInfo.getTileSourceOptions({ + let options = iiifInfo.getTileSourceOptions({ + quality: 'bitonal', + format: 'png' + }); + expect(options).to.have.property('quality', 'default'); + expect(options).to.have.property('format', 'jpg'); + + iiifInfo.setImageInfo({ + '@context': 'http://iiif.io/api/image/3/context.json', + '@id': 'http://iiif.test/version3/id', + width: 2000, + height: 1500, + profile: 'level1', + }); + options = iiifInfo.getTileSourceOptions({ quality: 'bitonal', format: 'png' }); @@ -482,6 +511,26 @@ describe('ol.format.IIIFInfo', function() { expect(options.tileSize[0]).to.be(512); expect(options.tileSize[1]).to.be(1024); + iiifInfo.setImageInfo({ + '@context': 'http://iiif.io/api/image/3/context.json', + '@id': 'http://iiif.test/id', + profile: 'level0', + tiles: [{ + scaleFactors: [1, 2, 4, 8], + width: 512, + height: 256 + }] + }); + options = iiifInfo.getTileSourceOptions(); + expect(options.resolutions).to.have.length(4); + expect(options.resolutions).to.contain(1); + expect(options.resolutions).to.contain(2); + expect(options.resolutions).to.contain(4); + expect(options.resolutions).to.contain(8); + expect(options.tileSize).to.have.length(2); + expect(options.tileSize[0]).to.be(512); + expect(options.tileSize[1]).to.be(256); + }); }); @@ -504,7 +553,7 @@ describe('ol.format.IIIFInfo', function() { height: 250 }] }); - const options = iiifInfo.getTileSourceOptions(); + let options = iiifInfo.getTileSourceOptions(); expect(options.sizes).to.have.length(3); expect(options.sizes[0]).to.have.length(2); expect(options.sizes[0][0]).to.be(2000); @@ -516,6 +565,20 @@ describe('ol.format.IIIFInfo', function() { expect(options.sizes[2][0]).to.be(500); expect(options.sizes[2][1]).to.be(250); + iiifInfo.setImageInfo({ + '@context': 'http://iiif.io/api/image/3/context.json', + '@id': 'http://iiif.test/id', + 'sizes': [{ + width: 1500, + height: 800 + }] + }); + options = iiifInfo.getTileSourceOptions(); + expect(options.sizes).to.have.length(1); + expect(options.sizes[0]).to.have.length(2); + expect(options.sizes[0][0]).to.be(1500); + expect(options.sizes[0][1]).to.be(800); + }); it('respects the preferred image formats', function() {