Skip to content

Commit

Permalink
ImageBitmapLoader: Latest Firefox no longer complains about options a…
Browse files Browse the repository at this point in the history
…nymore.
  • Loading branch information
mrdoob committed Nov 15, 2017
1 parent a8f1818 commit cb20c47
Showing 1 changed file with 4 additions and 68 deletions.
72 changes: 4 additions & 68 deletions examples/js/loaders/ImageBitmapLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,13 @@
* @author thespite / http://clicktorelease.com/
*/

function detectCreateImageBitmap( optionsList ) {

var url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';

return new Promise( function ( resolve, reject ) {

if ( ! ( 'createImageBitmap' in window ) ) {

reject();
return;

}

fetch( url ).then( function ( res ) {

return res.blob();

} ).then( function ( blob ) {

var pendingImages = [];

for ( var i = 0; i < optionsList.length; i ++ ) {

var pendingImage = optionsList[ i ] === undefined
? createImageBitmap( blob )
: createImageBitmap( blob, optionsList[ i ] );

pendingImages.push( pendingImage );

}

Promise.all( pendingImages ).then( function () {

resolve();

} ).catch( function () {

reject();

} );

} );

} );

}

var canUseImageBitmap = detectCreateImageBitmap( [ undefined ] );

var canUseImageBitmapOptions = detectCreateImageBitmap( [
{ imageOrientation: 'none', premultiplyAlpha: 'none' },
{ imageOrientation: 'flipY', premultiplyAlpha: 'none' },
{ imageOrientation: 'none', premultiplyAlpha: 'premultiply' },
{ imageOrientation: 'flipY', premultiplyAlpha: 'premultiply' }
] );


THREE.ImageBitmapLoader = function ( manager ) {

canUseImageBitmap.catch( function () {
if ( typeof createImageBitmap === 'undefined' ) {

console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );

} );
}

this.manager = manager !== undefined ? manager : THREE.DefaultLoadingManager;
this.options = undefined;
Expand All @@ -78,13 +21,8 @@ THREE.ImageBitmapLoader.prototype = {

setOptions: function setOptions( options ) {

canUseImageBitmapOptions.catch( function () {

console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() options not supported.' );

} );

this.options = options;

return this;

},
Expand Down Expand Up @@ -121,9 +59,7 @@ THREE.ImageBitmapLoader.prototype = {

} ).then( function ( blob ) {

return scope.options === undefined
? createImageBitmap( blob )
: createImageBitmap( blob, scope.options );
return createImageBitmap( blob, scope.options );

} ).then( function ( imageBitmap ) {

Expand Down

0 comments on commit cb20c47

Please sign in to comment.