Skip to content

Commit

Permalink
Fix browser check to only check at startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jul 21, 2016
1 parent 9ad175d commit 4f5dccf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/gui/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,32 @@ dwv.browser.hasTypedArray = function()
return "Uint8Array" in window && "Uint16Array" in window;
};

//only check at startup (since we propose a replacement)
dwv.browser._hasTypedArraySlice = (typeof Uint8Array.prototype.slice !== "undefined");

/**
* Browser check for typed array slice method.
* Missing in Internet Explorer 11.
*/
dwv.browser.hasTypedArraySlice = function()
{
return (typeof Uint8Array.prototype.slice !== "undefined");
return dwv.browser._hasTypedArraySlice;
};

// only check at startup (since we propose a replacement)
dwv.browser._hasFloat64Array = ("Float64Array" in window);

/**
* Browser check for Float64Array array.
* Missing in PhantomJS 1.9.20 (on Travis).
*/
dwv.browser.hasFloat64Array = function()
{
return "Float64Array" in window;
return dwv.browser._hasFloat64Array;
};

//only check at startup (since we propose a replacement)
dwv.browser._hasClampedArray = ("Uint8ClampedArray" in window);

/**
* Browser check for clamped array.
Expand All @@ -65,7 +73,7 @@ dwv.browser.hasFloat64Array = function()
*/
dwv.browser.hasClampedArray = function()
{
return "Uint8ClampedArray" in window;
return dwv.browser._hasClampedArray;
};

/**
Expand Down Expand Up @@ -126,4 +134,12 @@ dwv.browser.check = function()
// TODO Find better replacement!
window.Uint8ClampedArray = window.Uint8Array;
}
// check Float64 array
if( !dwv.browser.hasFloat64Array() ) {
// silent fail with warning
console.warn("The Float64Array is not supported in this browser. This may impair performance. ");
// Use Float32Array instead... Not good
// TODO Find better replacement!
window.Float64Array = window.Float32Array;
}
};
6 changes: 2 additions & 4 deletions tests/image/view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ QUnit.test("Test generate data MONO.", function (assert) {
// create a view
var view0 = new dwv.image.View(image0);
// create the image data
// TODO Uint8ClampedArray not in phantom??
var imageData = {'width': size0, 'height': size0, 'data': new Uint8Array(size0*size0*4) };
var imageData = {'width': size0, 'height': size0, 'data': new Uint8ClampedArray(size0*size0*4) };

// default window level
view0.setWindowLevelMinMax();
Expand Down Expand Up @@ -112,8 +111,7 @@ QUnit.test("Test generate data RGB.", function (assert) {
// create a view
var view0 = new dwv.image.View(image0);
// create the image data
// TODO Uint8ClampedArray not in phantom??
var imageData = {'width': size0, 'height': size0, 'data': new Uint8Array(size0*size0*4) };
var imageData = {'width': size0, 'height': size0, 'data': new Uint8ClampedArray(size0*size0*4) };

// default window level
view0.setWindowLevel(127, 255);
Expand Down

0 comments on commit 4f5dccf

Please sign in to comment.