Images now parse into Blobs properly.

This commit is contained in:
Richard Davey 2016-12-07 00:27:56 +00:00
parent 393791706e
commit 2d90ae2b08
6 changed files with 39 additions and 25 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: 'ecf1bb90-bbc7-11e6-beca-a9f2e8e0caf0'
build: 'c61e8bf0-bc13-11e6-b7e8-cb3f69be926d'
};
module.exports = CHECKSUM;

View file

@ -193,7 +193,7 @@ BaseLoader.prototype = {
finishedLoading: function ()
{
// console.log('BaseLoader.finishedLoading PROCESSING');
console.log('BaseLoader.finishedLoading PROCESSING');
this._state = CONST.LOADER_PROCESSING;
@ -201,29 +201,32 @@ BaseLoader.prototype = {
storage.clear();
// This could be Promise based as well, allowing for async processing
var _this = this;
this.queue.each(function (file)
{
file.onProcess();
// The File specific process handler has run
// Now run any custom callbacks
if (file.processCallback)
{
file.processCallback(file);
}
file.onComplete();
storage.add(file);
file.onProcess(_this.processUpdate.bind(_this));
});
},
processUpdate: function (file)
{
this.storage.add(file);
if (this.storage.size === this.queue.size && this._state === CONST.LOADER_PROCESSING)
{
// We've processed all the files we loaded
this.processComplete();
}
},
processComplete: function ()
{
this.list.clear();
this.inflight.clear();
this.queue.clear();
// console.log('Loader Complete. Loaded:', storage.size, 'Failed:', this.failed.size);
console.log('Loader Process Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
this._state = CONST.LOADER_COMPLETE;

View file

@ -57,11 +57,11 @@ File.prototype = {
// ProgressEvent
onLoad: function (event)
{
// console.log('image loaded');
console.log('image loaded');
// console.log(event);
// this.onStateChange(LOADING);
this.process();
// this.process();
this.resetXHR();
@ -88,9 +88,14 @@ File.prototype = {
console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
},
process: function ()
onProcess: function (callback)
{
// Override by an extending class
this.state = CONST.FILE_PROCESSING;
// If overridden by another class, it must call the callback when finished, then onComplete
callback(this);
this.onComplete();
},
onComplete: function ()

View file

@ -26,17 +26,23 @@ var ImageFile = function (key, url, path)
ImageFile.prototype = Object.create(File.prototype);
ImageFile.prototype.constructor = ImageFile;
ImageFile.prototype.process = function ()
ImageFile.prototype.onProcess = function (callback)
{
console.log('ImageFile.onProcess');
this.state = CONST.FILE_PROCESSING;
this.data = new Image();
var _this = this;
this.data.onload = function ()
{
window.URL.revokeObjectURL(this.src);
window.URL.revokeObjectURL(_this.src);
this.onComplete();
callback(_this);
_this.onComplete();
};
this.data.src = window.URL.createObjectURL(this.xhrLoader.response);

View file

@ -11,4 +11,4 @@ var IsPowerOfTwo = function (width, height)
return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0);
};
module.exports = isPowerOfTwo;
module.exports = IsPowerOfTwo;

View file

@ -18,7 +18,7 @@ Loader.prototype.constructor = Loader;
Loader.prototype.image = function (key, url)
{
var file = ImageLoader(key, url, this.path);
var file = new ImageLoader(key, url, this.path);
this.addFile(file);