mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
e128cba84a
commit
096db123d7
7 changed files with 70 additions and 2 deletions
|
@ -82,4 +82,29 @@
|
|||
}
|
||||
return statistic;
|
||||
};
|
||||
scope.hasMoreColors = function hasMoreColors(rawData, threshold, statistic){
|
||||
if (statistic){
|
||||
return statistic.numberOfColors > threshold;
|
||||
}
|
||||
else {
|
||||
var colors = Object.create(null);
|
||||
var count = 0;
|
||||
for (var i = 0, l = rawData.length; i < l; i += 4){
|
||||
var index = String.fromCharCode(
|
||||
rawData[i + 0],
|
||||
rawData[i + 1],
|
||||
rawData[i + 2],
|
||||
rawData[i + 3]
|
||||
);
|
||||
if (!Object.prototype.hasOwnProperty.call(colors, index)){
|
||||
colors[index] = true;
|
||||
count += 1;
|
||||
if (count > threshold){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count > threshold;
|
||||
}
|
||||
};
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue