mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 04:26:35 +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;
|
||||
}
|
||||
};
|
||||
}());
|
|
@ -79,10 +79,16 @@
|
|||
var l = desc.length;
|
||||
|
||||
var ignoredColors = {};
|
||||
var statistic;
|
||||
if (prefs("ignoreFrequentColors")){
|
||||
var statistic = colorStatistics.compute(source);
|
||||
statistic = colorStatistics.compute(source);
|
||||
ignoredColors = statistic.getMaxColors(prefs("ignoreFrequentColors"));
|
||||
}
|
||||
if (prefs("minColors")){
|
||||
if (!colorStatistics.hasMoreColors(source, prefs("minColors"), statistic)){
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
var rng = randomSupply.getPixelRng(l, window, ignoredColors);
|
||||
var fakeAlphaChannel = prefs("fakeAlphaChannel");
|
||||
|
|
|
@ -67,6 +67,10 @@
|
|||
name: "ignoreFrequentColors",
|
||||
defaultValue: 0
|
||||
},
|
||||
{
|
||||
name: "minColors",
|
||||
defaultValue: 0
|
||||
},
|
||||
{
|
||||
name: "fakeAlphaChannel",
|
||||
defaultValue: false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue