starts webworker support for colorizing
This commit is contained in:
parent
6d16120336
commit
4e6744abe9
@ -4,6 +4,8 @@
|
|||||||
// developed by Francisco Dans
|
// developed by Francisco Dans
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
|
var work = require('webworkify');
|
||||||
|
|
||||||
function BallRenderer(thecanvas){
|
function BallRenderer(thecanvas){
|
||||||
this.canvas = thecanvas;
|
this.canvas = thecanvas;
|
||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
@ -129,7 +131,7 @@ BallRenderer.prototype = {
|
|||||||
invalidate: function(full){
|
invalidate: function(full){
|
||||||
// if(!transit){
|
// if(!transit){
|
||||||
for (var i = 0, len = this.pointLayer.length; i< len; i+=4){
|
for (var i = 0, len = this.pointLayer.length; i< len; i+=4){
|
||||||
this.pointLayer[i + 3] -= 20;
|
this.pointLayer[i + 3] -= 10;
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
// else{
|
// else{
|
||||||
@ -137,7 +139,7 @@ BallRenderer.prototype = {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if(this.heatmapLayer){
|
if(this.heatmapLayer){
|
||||||
this.heatmapLayer = new Uint8ClampedArray(this.size * 4);
|
this.heatmapLayer = new Uint8ClampedArray(this.size * 4);
|
||||||
}
|
}
|
||||||
else if(this.contourLayer){
|
else if(this.contourLayer){
|
||||||
this.contourLayer = new Uint8ClampedArray(this.size * 4);
|
this.contourLayer = new Uint8ClampedArray(this.size * 4);
|
||||||
@ -245,7 +247,7 @@ BallRenderer.prototype = {
|
|||||||
0.4: 'blue',
|
0.4: 'blue',
|
||||||
0.6: 'cyan',
|
0.6: 'cyan',
|
||||||
0.7: 'lightgreen',
|
0.7: 'lightgreen',
|
||||||
0.8: 'yellow',
|
0.9: 'yellow',
|
||||||
1.0: 'red'
|
1.0: 'red'
|
||||||
};
|
};
|
||||||
if(JSON.stringify(this.gradient) !== JSON.stringify(gradient)){
|
if(JSON.stringify(this.gradient) !== JSON.stringify(gradient)){
|
||||||
@ -270,18 +272,30 @@ BallRenderer.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
colorize: function () {
|
colorize: function () {
|
||||||
var alpha, grad = this.gradientData;
|
// if (!this.colorWorkers){
|
||||||
|
// this.initColorWorkers();
|
||||||
|
// }
|
||||||
|
// this.colorWorkers[0].postMessage([this.pointLayer, 123]);
|
||||||
|
var grad = this.gradientData;
|
||||||
if(!this.heatmapLayer) this.heatmapLayer = new Uint8ClampedArray(this.size * 4);
|
if(!this.heatmapLayer) this.heatmapLayer = new Uint8ClampedArray(this.size * 4);
|
||||||
for (var i = 0, len = this.pointLayer.length; i< len; i+=4){
|
for (var i = this.pointLayer.length-4, alpha; i>=0; i-=4){
|
||||||
alpha = this.pointLayer[i+3] * 4; // get gradient color from opacity value
|
alpha = this.pointLayer[i+3] * 4; // get gradient color from opacity value
|
||||||
|
|
||||||
if (alpha>0) {
|
if (alpha>0) {
|
||||||
this.heatmapLayer[i] = grad[alpha]; // R
|
this.heatmapLayer[i] = grad[alpha]; // R
|
||||||
this.heatmapLayer[i + 1] = grad[alpha + 1]; // G
|
this.heatmapLayer[i + 1] = grad[alpha + 1]; // G
|
||||||
this.heatmapLayer[i + 2] = grad[alpha + 2]; // B
|
this.heatmapLayer[i + 2] = grad[alpha + 2]; // B
|
||||||
this.heatmapLayer[i + 3] = alpha; // A
|
this.heatmapLayer[i + 3] = alpha; // A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
initColorWorkers: function(){
|
||||||
|
var workerCount = 3
|
||||||
|
this.colorWorkers = [];
|
||||||
|
for (var i = 0; i < workerCount; i++) {
|
||||||
|
this.colorWorkers.push(work(require('./colorWorker.js')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user