diff --git a/src/gui/browser.js b/src/gui/browser.js index 23350fd981..b349683ba2 100644 --- a/src/gui/browser.js +++ b/src/gui/browser.js @@ -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. @@ -65,7 +73,7 @@ dwv.browser.hasFloat64Array = function() */ dwv.browser.hasClampedArray = function() { - return "Uint8ClampedArray" in window; + return dwv.browser._hasClampedArray; }; /** @@ -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; + } }; diff --git a/tests/image/view.test.js b/tests/image/view.test.js index d10f1bc836..cb877b7bf8 100644 --- a/tests/image/view.test.js +++ b/tests/image/view.test.js @@ -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(); @@ -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);