1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Improved faking performance.

This commit is contained in:
kkapsner 2016-05-14 19:12:45 +02:00
parent 7a0cad6966
commit 699698f529

View File

@ -28,27 +28,40 @@
);
}
data = imageData.data;
var l = data.length;
var randomI = 65536;
var randomOffset = 0;
var randomNumbers = new Uint8Array(Math.min(65536, l));
for (var i = 0, l = data.length; i < l; i += 1){
for (var i = 0; i < l; i += 1, randomI += 1){
if (randomI >= randomNumbers.length){
randomI = 0;
randomOffset += randomNumbers.length;
if (l - i < 65536){
randomNumbers = new Uint8Array(l - i);
}
window.crypto.getRandomValues(randomNumbers);
}
var rnd = randomNumbers[randomI];
var value = source[i];
if (value >= 0x80){
value = value ^ Math.floor(Math.random() * 0x20);
value = value ^ (rnd & 0x1F);
}
else if (value >= 0x40){
value = value ^ Math.floor(Math.random() * 0x10);
value = value ^ (rnd & 0x0F);
}
else if (value >= 0x20){
value = value ^ Math.floor(Math.random() * 0x08);
value = value ^ (rnd & 0x07);
}
else if (value >= 0x10){
value = value ^ Math.floor(Math.random() * 0x04);
value = value ^ (rnd & 0x03);
}
else if (value >= 0x08){
value = value ^ Math.floor(Math.random() * 0x02);
}
else if (value >= 0x04){
value = value ^ Math.floor(Math.random() * 0x01);
value = value ^ (rnd & 0x01);
}
// else if (value >= 0x04){
// value = value ^ (rnd * 0x00);
// }
data[i] = value;
}
var canvas = original.cloneNode(true);