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

Added setting for alpha channel faking.

This commit is contained in:
kkapsner 2017-08-11 16:26:24 +02:00
parent 6f9e2ad686
commit 73e4848ffd
5 changed files with 27 additions and 5 deletions

View File

@ -202,6 +202,15 @@
"description": "" "description": ""
}, },
"fakeAlphaChannel_title": {
"message": "Alhpa-Kanal auch vortäuschen",
"description": ""
},
"fakeAlphaChannel_description": {
"message": "Aktiviert das Vortäuschen des Alpha-Kanals (Transparenz).",
"description": ""
},
"useCanvasCache_title": { "useCanvasCache_title": {
"message": "Zwischenspeicher für Canvas verwenden", "message": "Zwischenspeicher für Canvas verwenden",
"description": "" "description": ""

View File

@ -202,6 +202,15 @@
"description": "" "description": ""
}, },
"fakeAlphaChannel_title": {
"message": "Fakt the alpha channel",
"description": ""
},
"fakeAlphaChannel_description": {
"message": "Activates the faking of the alhpa channel (transparency).",
"description": ""
},
"useCanvasCache_title": { "useCanvasCache_title": {
"message": "Use canvas cache", "message": "Use canvas cache",
"description": "" "description": ""

View File

@ -10,6 +10,7 @@ var settings = {
rng: "nonPersistent", rng: "nonPersistent",
useCanvasCache: true, useCanvasCache: true,
ignoreFrequentColors: 0, ignoreFrequentColors: 0,
fakeAlphaChannel: false,
persistentRndStorage: "", persistentRndStorage: "",
storePersistentRnd: false, storePersistentRnd: false,
askOnlyOnce: true, askOnlyOnce: true,

View File

@ -77,7 +77,7 @@
} }
var rng = randomSupply.getPixelRng(l, window, ignoredColors); var rng = randomSupply.getPixelRng(l, window, ignoredColors);
var fakeAlphaChannel = prefs("fakeAlphaChannel");
for (var i = 0; i < l; i += 4){ for (var i = 0; i < l; i += 4){
var [r, g, b, a] = rng( var [r, g, b, a] = rng(
source[i + 0], source[i + 0],
@ -89,13 +89,14 @@
desc[i + 0] = r; desc[i + 0] = r;
desc[i + 1] = g; desc[i + 1] = g;
desc[i + 2] = b; desc[i + 2] = b;
desc[i + 3] = a; desc[i + 3] = fakeAlphaChannel? a: source[i + 3];
} }
var canvas = original.cloneNode(true); var canvas = original.cloneNode(true);
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d"); context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
context.putImageData(imageData, 0, 0); context.putImageData(imageData, 0, 0);
if (prefs("useCanvasCache")){ if (prefs("useCanvasCache")){
canvasCache[originalDataURL] = canvas; canvasCache[originalDataURL] = canvas;
canvasCache[canvas.toDataURL()] = canvas;
} }
return canvas; return canvas;
} }
@ -373,7 +374,7 @@
ignoredColors = statistic.getMaxColors(prefs("ignoreFrequentColors")); ignoredColors = statistic.getMaxColors(prefs("ignoreFrequentColors"));
} }
var rng = randomSupply.getPixelRng(l, window, ignoredColors); var rng = randomSupply.getPixelRng(l, window, ignoredColors);
var fakeAlphaChannel = prefs("fakeAlphaChannel");
for (var i = 0; i < l; i += 4){ for (var i = 0; i < l; i += 4){
var [r, g, b, a] = rng( var [r, g, b, a] = rng(
xPixels[i + 0], xPixels[i + 0],
@ -385,9 +386,10 @@
xPixels[i + 0] = r; xPixels[i + 0] = r;
xPixels[i + 1] = g; xPixels[i + 1] = g;
xPixels[i + 2] = b; xPixels[i + 2] = b;
if (fakeAlphaChannel){
xPixels[i + 3] = a; xPixels[i + 3] = a;
} }
}
return ret; return ret;
} }
else { else {

View File

@ -18,6 +18,7 @@ Version 0.4.0:
* setting to not fake the most frequent colors in a canvas * setting to not fake the most frequent colors in a canvas
* setting to enable canvas cache * setting to enable canvas cache
* setting to hide expert settings * setting to hide expert settings
* setting to control if the alpha channel should be faked as wel
fixes: fixes:
- ask mode did not work for input types - ask mode did not work for input types