Can anyone suggest a way to shave any time off this script?
var countObject = new Object();
var length = data.length;
for(var i = 0; i < length; i += 4) {
var key = data[i] + ',' + data[i+1] + ',' + data[i+2];
if(typeof(countObject[key]) == 'number') {
countObject[key]++
} else {
countObject[key] = 0
}
}
It is to build up a count of occurrences of RGB values found in data retrieved from a canvas. Presumably the data from context.getImageData() is already an optimised array type...?
EDIT: I do not require the RGB value in the format "255,255,255" necessarily, it's just all I could come up with for use as the array key. A different approach is also welcome :-D