adds some workers work

This commit is contained in:
Francisco Dans 2015-05-04 18:13:29 +02:00
parent 5d143d4270
commit 50fa5c356e

View File

@ -276,29 +276,44 @@ BallRenderer.prototype = {
}, },
colorize: function () { colorize: function () {
// if (!this.colorWorkers){ if (!this.colorWorkers){
// this.initColorWorkers(); this.initColorWorkers();
// } }
// this.colorWorkers[0].postMessage([this.pointLayer, 123]); for(k in this.colorWorkers){
this.colorWorkers[k].postMessage([this.pointLayer,k, 3]);
}
var grad = this.gradientData; var grad = this.gradientData;
if(!this.heatmapLayer) this.heatmapLayer = new Uint8ClampedArray(this.size * 4); this.heatmapLayer = new Uint8ClampedArray(this.size * 4);
for (var i = this.pointLayer.length-4, alpha; i>=0; i-=4){ // while(Object.keys(this.loadedColorizedChunks).length < this.colorWorkers.length){
alpha = this.pointLayer[i+3] * 4; // get gradient color from opacity value // console.log(Object.keys(this.loadedColorizedChunks).length)
// }
if (alpha>0) { // var i = 0;
this.heatmapLayer[i] = grad[alpha]; // R // while(i<=this.colorWorkers.length){
this.heatmapLayer[i + 1] = grad[alpha + 1]; // G // this.heatmapLayer += this.loadedColorizedChunks[i];
this.heatmapLayer[i + 2] = grad[alpha + 2]; // B // }
this.heatmapLayer[i + 3] = alpha; // A // for (var i = this.pointLayer.length-4, alpha; i>=0; i-=4){
} // alpha = this.pointLayer[i+3] * 4; // get gradient color from opacity value
} // if (alpha>0) {
// this.heatmapLayer[i] = grad[alpha]; // R
// this.heatmapLayer[i + 1] = grad[alpha + 1]; // G
// this.heatmapLayer[i + 2] = grad[alpha + 2]; // B
// this.heatmapLayer[i + 3] = alpha; // A
// }
// }
}, },
initColorWorkers: function(){ initColorWorkers: function(){
var workerCount = 3 var workerCount = 3
this.colorWorkers = []; this.colorWorkers = [];
if(!this.loadedColorizedChunks) this.loadedColorizedChunks = {};
for (var i = 0; i < workerCount; i++) { for (var i = 0; i < workerCount; i++) {
this.colorWorkers.push(work(require('./colorWorker.js'))); var worker = work(require('./colorWorker.js'));
worker.grad = this.gradientData;
worker.onmessage = function(data){
this.loadedColorizedChunks[data.data[0]] = data.data[1];
}
this.colorWorkers.push(worker);
} }
} }
} }