2017-12-05 05:01:30 +03:00
|
|
|
/* global QUnit, $,testLog */
|
2014-01-12 03:08:04 +04:00
|
|
|
|
|
|
|
( function() {
|
|
|
|
var viewer;
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.module( 'Multi-Image', {
|
|
|
|
beforeEach: function() {
|
2016-02-24 03:37:41 +03:00
|
|
|
$( '<div id="example"></div>' ).appendTo( "#qunit-fixture" );
|
2014-01-12 03:08:04 +04:00
|
|
|
|
|
|
|
testLog.reset();
|
|
|
|
|
|
|
|
viewer = OpenSeadragon( {
|
2016-02-24 03:37:41 +03:00
|
|
|
id: 'example',
|
2014-01-12 03:08:04 +04:00
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
});
|
|
|
|
},
|
2017-12-05 05:01:30 +03:00
|
|
|
afterEach: function() {
|
2014-01-12 03:08:04 +04:00
|
|
|
if ( viewer && viewer.close ) {
|
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
2016-02-24 03:37:41 +03:00
|
|
|
$("#example").remove();
|
2014-01-12 03:08:04 +04:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test( 'Multi-image operations', function(assert) {
|
|
|
|
var done = assert.async();
|
|
|
|
assert.expect( 24 );
|
2014-01-22 04:24:47 +04:00
|
|
|
viewer.addHandler( "open", function( ) {
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( 1, viewer.world.getItemCount( ),
|
2014-08-20 02:02:35 +04:00
|
|
|
"One item should be present after opening." );
|
2014-01-12 03:08:04 +04:00
|
|
|
var options = {
|
|
|
|
tileSource: {
|
|
|
|
type: 'legacy-image-pyramid',
|
|
|
|
levels: [ {
|
2014-01-12 04:15:28 +04:00
|
|
|
url: "data/A.png",
|
2014-01-12 03:08:04 +04:00
|
|
|
width: 1000,
|
|
|
|
height: 1000
|
|
|
|
} ]
|
|
|
|
}
|
|
|
|
};
|
2014-08-20 02:02:35 +04:00
|
|
|
viewer.addTiledImage( options );
|
|
|
|
viewer.world.addHandler( "add-item", function addFirstItemHandler( event ) {
|
|
|
|
viewer.world.removeHandler( "add-item", addFirstItemHandler );
|
|
|
|
var item1 = event.item;
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemCount( ), 2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"2 items should be present after adding a item." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item1 ), 1,
|
2014-08-20 02:02:35 +04:00
|
|
|
"The first added item should have a index of 1" );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemAt( 1 ), item1,
|
2014-08-20 02:02:35 +04:00
|
|
|
"The item at index 1 should be the first added item." );
|
|
|
|
|
|
|
|
viewer.addTiledImage( options );
|
|
|
|
viewer.world.addHandler( "add-item", function addSecondItemHandler( event ) {
|
|
|
|
viewer.world.removeHandler( "add-item", addSecondItemHandler );
|
|
|
|
var item2 = event.item;
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemCount( ), 3,
|
2014-08-20 02:02:35 +04:00
|
|
|
"3 items should be present after adding a second item." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item2 ), 2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"If not specified, a item should be added with the highest index." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemAt( 2 ), item2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"The item at index 2 should be the second added item." );
|
|
|
|
|
2014-11-13 03:31:46 +03:00
|
|
|
viewer.world.addHandler( "item-index-change",
|
2014-08-20 02:02:35 +04:00
|
|
|
function itemIndexChangedHandler( event ) {
|
2014-11-13 03:31:46 +03:00
|
|
|
viewer.world.removeHandler( "item-index-change",
|
2014-08-20 02:02:35 +04:00
|
|
|
itemIndexChangedHandler );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( event.item, item2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"The item which changed index should be item2" );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( event.previousIndex, 2, "Previous index should be 2." );
|
|
|
|
assert.equal( event.newIndex, 1, "New index should be 1." );
|
2014-01-12 03:08:04 +04:00
|
|
|
});
|
2014-08-20 02:02:35 +04:00
|
|
|
viewer.world.setItemIndex( item2, 1 );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item2 ), 1,
|
2014-08-20 02:02:35 +04:00
|
|
|
"Item2 index should be 1 after setItemIndex." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item1 ), 2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"Item1 index should be 2 after setItemIndex." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemAt( 1 ), item2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"The item at index 1 should be item2." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemAt( 2 ), item1,
|
2014-08-20 02:02:35 +04:00
|
|
|
"The item at index 2 should be item1." );
|
|
|
|
|
|
|
|
options.index = 2;
|
2014-01-12 04:15:28 +04:00
|
|
|
options.tileSource.levels[0].url = "data/CCyan.png";
|
2014-08-20 02:02:35 +04:00
|
|
|
viewer.addTiledImage( options );
|
|
|
|
viewer.world.addHandler( "add-item", function addThirdItemHandler( event ) {
|
|
|
|
viewer.world.removeHandler( "add-item", addThirdItemHandler );
|
|
|
|
var item3 = event.item;
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemCount( ), 4,
|
2014-08-20 02:02:35 +04:00
|
|
|
"4 items should be present after adding a third item." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item3 ), 2,
|
2014-08-20 02:02:35 +04:00
|
|
|
"Item 3 should be added with index 2." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item2 ), 1,
|
2014-08-20 02:02:35 +04:00
|
|
|
"Item 2 should stay at index 1." );
|
|
|
|
|
2015-08-21 20:01:32 +03:00
|
|
|
options.index = 2;
|
|
|
|
options.replace = true;
|
|
|
|
viewer.addTiledImage( options );
|
|
|
|
viewer.world.addHandler( "add-item", function replaceAddItemHandler( event ) {
|
|
|
|
viewer.world.removeHandler( "add-item", replaceAddItemHandler );
|
|
|
|
var item4 = event.item;
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getItemCount( ), 4,
|
2015-08-21 20:01:32 +03:00
|
|
|
"4 items should still be present after replacing the second item." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item4 ), 2,
|
2015-08-21 20:01:32 +03:00
|
|
|
"Item 4 should be added with index 2." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item3 ), -1,
|
2015-08-21 20:01:32 +03:00
|
|
|
"Item 3 should be at index -1." );
|
2014-08-20 02:02:35 +04:00
|
|
|
|
2015-08-21 20:01:32 +03:00
|
|
|
viewer.world.addHandler( "remove-item", function removeItemHandler( event ) {
|
|
|
|
viewer.world.removeHandler( "remove-item", removeItemHandler );
|
2014-08-20 02:02:35 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( item2, event.item, "Removed item should be item2." );
|
2014-01-31 01:43:35 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item1 ), 2,
|
2015-08-21 20:01:32 +03:00
|
|
|
"Item 1 should be at index 2." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item2 ), -1,
|
2015-08-21 20:01:32 +03:00
|
|
|
"Item 2 should be at index -1." );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( viewer.world.getIndexOfItem( item4 ), 1,
|
2015-08-21 20:01:32 +03:00
|
|
|
"Item 4 should be at index 1." );
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2015-08-21 20:01:32 +03:00
|
|
|
});
|
2014-08-20 02:02:35 +04:00
|
|
|
|
2015-08-21 20:01:32 +03:00
|
|
|
viewer.world.removeItem( item2 );
|
|
|
|
});
|
2014-01-12 03:08:04 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
});
|
|
|
|
|
2014-11-19 03:28:08 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test( 'Sequences as items', function(assert) {
|
|
|
|
var done = assert.async();
|
2014-01-12 04:15:28 +04:00
|
|
|
var options = {
|
|
|
|
tileSource: [{
|
|
|
|
type: 'legacy-image-pyramid',
|
|
|
|
levels: [{
|
|
|
|
url: "data/A.png",
|
|
|
|
width: 1000,
|
|
|
|
height: 1000
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
type: 'legacy-image-pyramid',
|
|
|
|
levels: [{
|
|
|
|
url: "data/BBlue.png",
|
|
|
|
width: 1000,
|
|
|
|
height: 1000
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler( "open", function openHandler() {
|
|
|
|
viewer.removeHandler( "open", openHandler );
|
|
|
|
|
2014-08-20 02:02:35 +04:00
|
|
|
viewer.addHandler( "add-item-failed",
|
|
|
|
function addItemFailedHandler( event ) {
|
|
|
|
viewer.removeHandler( "add-item-failed", addItemFailedHandler );
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal( event.message, "[Viewer.addTiledImage] Sequences can not be added; add them one at a time instead." );
|
|
|
|
assert.equal( event.options, options, "Item failed event should give the options." );
|
|
|
|
done();
|
2014-01-12 04:15:28 +04:00
|
|
|
} );
|
2014-08-20 02:02:35 +04:00
|
|
|
viewer.addTiledImage( options );
|
2014-01-22 04:24:47 +04:00
|
|
|
|
2014-01-22 20:33:59 +04:00
|
|
|
});
|
2014-01-22 04:24:47 +04:00
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
2014-01-22 20:33:59 +04:00
|
|
|
});
|
2014-01-22 04:24:47 +04:00
|
|
|
|
2014-11-19 03:28:08 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('items are added in order', function(assert) {
|
|
|
|
var done = assert.async();
|
2014-11-19 03:28:08 +03:00
|
|
|
viewer.addHandler('open', function(event) {
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.world.getItemAt(0).getContentSize().y, 2000, 'first image is tall');
|
|
|
|
assert.equal(viewer.world.getItemAt(0).getBounds().width, 4, 'first image has 4 width');
|
|
|
|
assert.equal(viewer.world.getItemAt(1).getContentSize().x, 2000, 'second image is wide');
|
|
|
|
assert.equal(viewer.world.getItemAt(1).getBounds().width, 2, 'second image has 2 width');
|
|
|
|
done();
|
2014-11-19 03:28:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
viewer.open([
|
|
|
|
{
|
|
|
|
tileSource: '/test/data/tall.dzi',
|
|
|
|
width: 4
|
|
|
|
}, {
|
|
|
|
tileSource: '/test/data/wide.dzi',
|
|
|
|
width: 2
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Viewer.addSimpleImage', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-01-27 02:02:11 +03:00
|
|
|
viewer.addHandler("open", function openHandler() {
|
|
|
|
viewer.removeHandler("open", openHandler);
|
|
|
|
|
|
|
|
viewer.world.addHandler('add-item', function itemAdded(event) {
|
|
|
|
viewer.world.removeHandler('add-item', itemAdded);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(event.item.opacity, 0.5,
|
2016-01-28 05:49:05 +03:00
|
|
|
'Opacity option should be set when using addSimpleImage');
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-01-27 02:02:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addSimpleImage({
|
|
|
|
url: '/test/data/A.png',
|
|
|
|
opacity: 0.5
|
|
|
|
});
|
|
|
|
});
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Transparent image on top of others', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-02-24 03:37:41 +03:00
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
|
2016-08-16 20:18:39 +03:00
|
|
|
var density = OpenSeadragon.pixelDensityRatio;
|
|
|
|
|
|
|
|
viewer.addHandler('open', function() {
|
|
|
|
var firstImage = viewer.world.getItemAt(0);
|
|
|
|
firstImage.addHandler('fully-loaded-change', function() {
|
2023-09-08 09:47:43 +03:00
|
|
|
var aX = Math.round(500 * density), aY = Math.round(500 * density);
|
|
|
|
var imageData = viewer.drawer.context.getImageData(0, 0, aX, aY);
|
2016-08-16 20:18:39 +03:00
|
|
|
|
|
|
|
// Pixel 250,250 will be in the hole of the A
|
2023-09-08 09:47:43 +03:00
|
|
|
aX = Math.round(250 * density); aY = Math.round(250 * density);
|
|
|
|
var expectedVal = getPixelValue(imageData, aX, aY);
|
2016-08-16 20:18:39 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.notEqual(expectedVal.r, 0, 'Red channel should not be 0');
|
|
|
|
assert.notEqual(expectedVal.g, 0, 'Green channel should not be 0');
|
|
|
|
assert.notEqual(expectedVal.b, 0, 'Blue channel should not be 0');
|
|
|
|
assert.notEqual(expectedVal.a, 0, 'Alpha channel should not be 0');
|
2016-08-16 20:18:39 +03:00
|
|
|
|
|
|
|
viewer.addSimpleImage({
|
|
|
|
url: '/test/data/A.png',
|
|
|
|
success: function() {
|
|
|
|
var secondImage = viewer.world.getItemAt(1);
|
|
|
|
secondImage.addHandler('fully-loaded-change', function() {
|
2023-09-08 09:47:43 +03:00
|
|
|
var aX = Math.round(500 * density), aY = Math.round(500 * density);
|
|
|
|
var imageData = viewer.drawer.context.getImageData(0, 0, aX, aY);
|
|
|
|
aX = Math.round(250 * density); aY = Math.round(250 * density);
|
|
|
|
var actualVal = getPixelValue(imageData, aX, aY);
|
2016-08-16 20:18:39 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(actualVal.r, expectedVal.r,
|
2016-08-16 20:18:39 +03:00
|
|
|
'Red channel should not change in transparent part of the A');
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(actualVal.g, expectedVal.g,
|
2016-08-16 20:18:39 +03:00
|
|
|
'Green channel should not change in transparent part of the A');
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(actualVal.b, expectedVal.b,
|
2016-08-16 20:18:39 +03:00
|
|
|
'Blue channel should not change in transparent part of the A');
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(actualVal.a, expectedVal.a,
|
2016-08-16 20:18:39 +03:00
|
|
|
'Alpha channel should not change in transparent part of the A');
|
|
|
|
|
2023-09-08 09:47:43 +03:00
|
|
|
aX = Math.round(333 * density); aY = Math.round(250 * density);
|
|
|
|
var onAVal = getPixelValue(imageData, aX, aY);
|
|
|
|
assert.equal(onAVal.r, 0, 'Red channel should be null on the A pixel (' + aX + ', ' + aY + ')');
|
|
|
|
assert.equal(onAVal.g, 0, 'Green channel should be null on the A pixel (' + aX + ', ' + aY + ')');
|
|
|
|
assert.equal(onAVal.b, 0, 'Blue channel should be null on the A pixel (' + aX + ', ' + aY + ')');
|
|
|
|
assert.equal(onAVal.a, 255, 'Alpha channel should be 255 on the A pixel (' + aX + ', ' + aY + ')');
|
2016-08-16 20:18:39 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-08-16 20:18:39 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-02-24 03:37:41 +03:00
|
|
|
});
|
2016-08-16 20:18:39 +03:00
|
|
|
});
|
2016-02-24 03:37:41 +03:00
|
|
|
|
|
|
|
function getPixelValue(imageData, x, y) {
|
2016-02-25 03:48:11 +03:00
|
|
|
var offset = 4 * (y * imageData.width + x);
|
2016-02-24 03:37:41 +03:00
|
|
|
return {
|
|
|
|
r: imageData.data[offset],
|
|
|
|
g: imageData.data[offset + 1],
|
|
|
|
b: imageData.data[offset + 2],
|
|
|
|
a: imageData.data[offset + 3]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-01-12 03:08:04 +04:00
|
|
|
})();
|