mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 03:56:26 +02:00
Made readPixels consistent with the other faked readout functions.
This commit is contained in:
parent
bdbdf1d04a
commit
d8f6fb1ac9
3 changed files with 128 additions and 27 deletions
|
@ -15,6 +15,8 @@
|
|||
}
|
||||
|
||||
const colorStatistics = require("./colorStatistics");
|
||||
const logging = require("./logging");
|
||||
const {copyCanvasToWebgl} = require("./webgl");
|
||||
|
||||
// let Cu = require("chrome").Cu;
|
||||
|
||||
|
@ -101,6 +103,7 @@
|
|||
return canvas;
|
||||
}
|
||||
catch (e){
|
||||
logging.warning("Error while faking:", e);
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
@ -363,34 +366,10 @@
|
|||
fakeGenerator: function(prefs, notify, window, original){
|
||||
return function readPixels(x, y, width, height, format, type, pixels){
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
// not able to use the getFakeCanvas function because the context type is wrong...
|
||||
notify.call(this, "fakedReadout");
|
||||
var xPixels = pixels;
|
||||
var ret = original.apply(this, window.Array.from(arguments));
|
||||
var l = xPixels.length;
|
||||
var ignoredColors = {};
|
||||
if (prefs("ignoreFrequentColors")){
|
||||
var statistic = colorStatistics.compute(pixels);
|
||||
ignoredColors = statistic.getMaxColors(prefs("ignoreFrequentColors"));
|
||||
}
|
||||
var rng = randomSupply.getPixelRng(l, window, ignoredColors);
|
||||
var fakeAlphaChannel = prefs("fakeAlphaChannel");
|
||||
for (var i = 0; i < l; i += 4){
|
||||
var [r, g, b, a] = rng(
|
||||
xPixels[i + 0],
|
||||
xPixels[i + 1],
|
||||
xPixels[i + 2],
|
||||
xPixels[i + 3],
|
||||
i / 4
|
||||
);
|
||||
xPixels[i + 0] = r;
|
||||
xPixels[i + 1] = g;
|
||||
xPixels[i + 2] = b;
|
||||
if (fakeAlphaChannel){
|
||||
xPixels[i + 3] = a;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
var fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
|
||||
var {context} = copyCanvasToWebgl(window, fakeCanvas, this instanceof window.WebGLRenderingContext? "webgl": "webgl2");
|
||||
return original.apply(context, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue