mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Changed rng interface to use colors instead of separate channels.
This commit is contained in:
parent
26457b2a7f
commit
921c7dbd5f
@ -59,10 +59,22 @@
|
||||
var {imageData, source} = getImageData(window, context);
|
||||
var desc = imageData.data;
|
||||
var l = desc.length;
|
||||
var rng = randomSupply.getRng(l, window);
|
||||
|
||||
for (var i = 0; i < l; i += 1){
|
||||
desc[i] = rng(source[i], i);
|
||||
var ignoredColors = {};
|
||||
var rng = randomSupply.getPixelRng(l, window, ignoredColors);
|
||||
|
||||
for (var i = 0; i < l; i += 4){
|
||||
var [r, g, b, a] = rng(
|
||||
source[i + 0],
|
||||
source[i + 1],
|
||||
source[i + 2],
|
||||
source[i + 3],
|
||||
i / 4
|
||||
);
|
||||
desc[i + 0] = r;
|
||||
desc[i + 1] = g;
|
||||
desc[i + 2] = b;
|
||||
desc[i + 3] = a;
|
||||
}
|
||||
var canvas = original.cloneNode(true);
|
||||
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||
@ -337,10 +349,20 @@
|
||||
var xPixels = pixels;
|
||||
var ret = original.apply(this, window.Array.from(arguments));
|
||||
var l = xPixels.length;
|
||||
var rng = randomSupply.getRng(l, window);
|
||||
var rng = randomSupply.getPixelRng(l, window, {});
|
||||
|
||||
for (var i = 0; i < l; i += 1){
|
||||
xPixels[i] = rng(xPixels[i], i);
|
||||
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;
|
||||
xPixels[i + 3] = a;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -68,6 +68,22 @@
|
||||
// XOR the bit and the value to alter the last bit of it... or not
|
||||
return value ^ bit;
|
||||
};
|
||||
},
|
||||
getPixelRng: function(length, window, ignoredColors){
|
||||
var rng = this.getRng(length, window);
|
||||
return function(r, g, b, a, i){
|
||||
var index = String.fromCharCode(r, g, b, a);
|
||||
if (ignoredColors[index]){
|
||||
return [r, g, b, a];
|
||||
}
|
||||
var baseIndex = i * 4;
|
||||
return [
|
||||
rng(r, baseIndex + 0),
|
||||
rng(g, baseIndex + 1),
|
||||
rng(b, baseIndex + 2),
|
||||
rng(a, baseIndex + 3)
|
||||
];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -92,6 +108,22 @@
|
||||
// XOR the last bit to alter it... or not
|
||||
return value ^ (rnd & 0x01);
|
||||
};
|
||||
},
|
||||
getPixelRng: function(length, window, ignoredColors){
|
||||
var rng = this.getRng(length, window);
|
||||
return function(r, g, b, a, i){
|
||||
var index = String.fromCharCode(r, g, b, a);
|
||||
if (ignoredColors[index]){
|
||||
return [r, g, b, a];
|
||||
}
|
||||
var baseIndex = i * 4;
|
||||
return [
|
||||
rng(r, baseIndex + 0),
|
||||
rng(g, baseIndex + 1),
|
||||
rng(b, baseIndex + 2),
|
||||
rng(a, baseIndex + 3)
|
||||
];
|
||||
}
|
||||
}
|
||||
};
|
||||
}());
|
Loading…
x
Reference in New Issue
Block a user