I been using JavaScript to code a chroma key program but it's running very slow and lagging. Below is the code snippet that I believe is causing the problem. Is there any way to make this more efficient?
l= data.length/4;
while(l--){
r= data[l*4];
g= data[l*4+1];
b= data[l*4+2];
if(Math.abs(r - colors[0]) < 250 - range
&&
Math.abs(g - colors[1]) < 250 - range
&&
Math.abs(b - colors[2]) < 250 - range)
{
frame.data[l*4+3]= 0;
}
}
ctxV.putImageData(frame, 0, 0);
frame = null;
data = null;
l=null;
r=null;
g=null;
b=null;
delete frame;
delete data;
delete l;
delete r;
delete g;
delete b;
//
};