chore(plugins): 同步标注插件 1.20.4
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 2m12s
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 2m12s
This commit is contained in:
1 parent
ac62c3bfbc
commit
aff77cef75
2 files changed
+51
-14
No files matched your search
+3
-3
@@ -13,9 +13,9 @@
|
||||
},
|
||||
{
|
||||
"id": "image-annotate",
|
||||
"file": "plugin-image-annotate.443423515c0e.js",
|
||||
"version": "1.20.3",
|
||||
"integrity": "sha256-RDQjUVwOogb+baL6NDlfRFNJSznTM7q3lMraGe8jal4="
|
||||
"file": "plugin-image-annotate.10f2df918936.js",
|
||||
"version": "1.20.4",
|
||||
"integrity": "sha256-EPLfkYk2D1wgqeRslEy3lJs0ER3CmEyekS2FkP7BcaE="
|
||||
},
|
||||
{
|
||||
"id": "image-vectorize",
|
||||
|
||||
+48
-11
@@ -9,7 +9,7 @@
|
||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
id: 'image-annotate',
|
||||
name: '标注 / 修图',
|
||||
version: '1.20.3',
|
||||
version: '1.20.4',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
@@ -3918,7 +3918,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
filterCanvas(canvas, "invert(" + k + ")");
|
||||
return;
|
||||
}
|
||||
mapPixels(canvas, (r, g, b) => [clamp255(255 - (255 - r) * k), clamp255(255 - (255 - g) * k), clamp255(255 - (255 - b) * k)]);
|
||||
const okInv = mapPixels(canvas, (r, g, b) => [clamp255(255 - (255 - r) * k), clamp255(255 - (255 - g) * k), clamp255(255 - (255 - b) * k)]);
|
||||
if (!okInv) blendFallback(canvas, "invert");
|
||||
}
|
||||
},
|
||||
gray: {
|
||||
@@ -3937,10 +3938,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
filterCanvas(canvas, "grayscale(" + k + ")");
|
||||
return;
|
||||
}
|
||||
mapPixels(canvas, (r, g, b) => {
|
||||
const okGray = mapPixels(canvas, (r, g, b) => {
|
||||
const y = luma(r, g, b);
|
||||
return [clamp255(r + (y - r) * k), clamp255(g + (y - g) * k), clamp255(b + (y - b) * k)];
|
||||
});
|
||||
if (!okGray) blendFallback(canvas, "gray");
|
||||
}
|
||||
},
|
||||
boost: {
|
||||
@@ -4037,20 +4039,34 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
var FILTER_SUPPORTED = function() {
|
||||
try {
|
||||
const c = document.createElement("canvas");
|
||||
const ctx = c.getContext("2d");
|
||||
if (!ctx) return false;
|
||||
ctx.filter = "invert(1)";
|
||||
return ctx.filter === "invert(1)";
|
||||
const src = document.createElement("canvas");
|
||||
src.width = 2;
|
||||
src.height = 2;
|
||||
const sctx = src.getContext("2d");
|
||||
sctx.fillStyle = "#ff0000";
|
||||
sctx.fillRect(0, 0, 2, 2);
|
||||
const dst = document.createElement("canvas");
|
||||
dst.width = 2;
|
||||
dst.height = 2;
|
||||
const dctx = dst.getContext("2d");
|
||||
dctx.filter = "invert(1)";
|
||||
dctx.drawImage(src, 0, 0);
|
||||
const d = dctx.getImageData(0, 0, 1, 1).data;
|
||||
return d[0] < 60 && d[1] > 180 && d[2] > 180;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}();
|
||||
function mapPixels(canvas, fn) {
|
||||
const w = canvas.width, h = canvas.height;
|
||||
if (!w || !h) return;
|
||||
if (!w || !h) return false;
|
||||
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
||||
const img = ctx.getImageData(0, 0, w, h);
|
||||
let img;
|
||||
try {
|
||||
img = ctx.getImageData(0, 0, w, h);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
const d = img.data;
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
if (d[i + 3] === 0) continue;
|
||||
@@ -4061,6 +4077,22 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
ctx.putImageData(img, 0, 0);
|
||||
return true;
|
||||
}
|
||||
function blendFallback(canvas, mode) {
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.save();
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
ctx.globalAlpha = 1;
|
||||
if (mode === "invert") {
|
||||
ctx.globalCompositeOperation = "difference";
|
||||
ctx.fillStyle = "#ffffff";
|
||||
} else {
|
||||
ctx.globalCompositeOperation = "saturation";
|
||||
ctx.fillStyle = "#808080";
|
||||
}
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.restore();
|
||||
}
|
||||
function luma(r, g, b) {
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
@@ -4166,7 +4198,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
ctx.imageSmoothingEnabled = true;
|
||||
ctx.drawImage(st.source, 0, 0);
|
||||
ctx.restore();
|
||||
fx.render(target.canvas, value);
|
||||
try {
|
||||
fx.render(target.canvas, value);
|
||||
} catch (e) {
|
||||
toast("效果失败:" + (e && e.message || e), "error");
|
||||
throw e;
|
||||
}
|
||||
target._bounds = void 0;
|
||||
S.pickerComposite = null;
|
||||
}
|
||||
Reference in new issue
Block a user