watermark-js-plus 1.6.5 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/src/core/blind-decode.js +16 -0
- package/dist/es/src/core/blind.js +9 -5
- package/dist/ie/es/src/compat/ie/blind-decode.js +155 -0
- package/dist/ie/es/src/core/blind-decode.js +28 -0
- package/dist/ie/es/src/core/blind.js +9 -5
- package/dist/ie/es/src/index.ie.js +4 -0
- package/dist/ie/index.cjs.js +192 -6
- package/dist/ie/index.cjs.js.map +1 -1
- package/dist/ie/index.cjs.min.js +1 -1
- package/dist/ie/index.esm.js +192 -6
- package/dist/ie/index.esm.js.map +1 -1
- package/dist/ie/index.esm.min.js +1 -1
- package/dist/ie/index.iife.js +192 -6
- package/dist/ie/index.iife.js.map +1 -1
- package/dist/ie/index.iife.min.js +1 -1
- package/dist/ie/index.umd.js +192 -6
- package/dist/ie/index.umd.js.map +1 -1
- package/dist/ie/index.umd.min.js +1 -1
- package/dist/index.cjs.js +24 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.esm.js +24 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.iife.js +24 -6
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.umd.js +24 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/types/compat/ie/blind-decode.d.ts +3 -0
- package/dist/types/core/blind-decode.d.ts +15 -0
- package/package.json +16 -16
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var blindDecodeFallback;
|
|
2
|
+
var applyBlindDecodeComposite = function (_a) {
|
|
3
|
+
var ctx = _a.ctx, width = _a.width, height = _a.height, fillColor = _a.fillColor, compositeOperation = _a.compositeOperation, compositeTimes = _a.compositeTimes;
|
|
4
|
+
if (!(compositeTimes > 0)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
ctx.globalCompositeOperation;
|
|
8
|
+
ctx.globalCompositeOperation = compositeOperation;
|
|
9
|
+
if (ctx.globalCompositeOperation !== compositeOperation && blindDecodeFallback) ;
|
|
10
|
+
ctx.fillStyle = fillColor;
|
|
11
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
12
|
+
ctx.fillRect(0, 0, width, height);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { applyBlindDecodeComposite };
|
|
@@ -2,6 +2,7 @@ import { __extends, __assign, __awaiter, __generator } from '../../node_modules/
|
|
|
2
2
|
import { convertImage, isFunction } from '../utils/index.js';
|
|
3
3
|
import { Watermark } from './watermark.js';
|
|
4
4
|
import { WatermarkCanvas } from './canvas.js';
|
|
5
|
+
import { applyBlindDecodeComposite } from './blind-decode.js';
|
|
5
6
|
import protection from '../utils/protection.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -64,11 +65,14 @@ var BlindWatermark = /** @class */ (function (_super) {
|
|
|
64
65
|
throw new Error('get context error');
|
|
65
66
|
}
|
|
66
67
|
ctx.drawImage(img_1, 0, 0, width, height);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
applyBlindDecodeComposite({
|
|
69
|
+
ctx: ctx,
|
|
70
|
+
width: width,
|
|
71
|
+
height: height,
|
|
72
|
+
fillColor: fillColor,
|
|
73
|
+
compositeOperation: compositeOperation,
|
|
74
|
+
compositeTimes: compositeTimes,
|
|
75
|
+
});
|
|
72
76
|
var resultImage = convertImage(canvas);
|
|
73
77
|
if (isFunction(onSuccess)) {
|
|
74
78
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resultImage);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var MAX_CHANNEL_VALUE = 255;
|
|
2
|
+
var overlay = function (backdrop, source) {
|
|
3
|
+
if (backdrop <= 0.5) {
|
|
4
|
+
return 2 * backdrop * source;
|
|
5
|
+
}
|
|
6
|
+
return 1 - 2 * (1 - backdrop) * (1 - source);
|
|
7
|
+
};
|
|
8
|
+
var colorBurn = function (backdrop, source) {
|
|
9
|
+
if (backdrop === 1) {
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
if (source === 0) {
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
return 1 - Math.min(1, (1 - backdrop) / source);
|
|
16
|
+
};
|
|
17
|
+
var getBlendFunction = function (compositeOperation) {
|
|
18
|
+
switch (compositeOperation) {
|
|
19
|
+
case 'overlay':
|
|
20
|
+
return overlay;
|
|
21
|
+
case 'color-burn':
|
|
22
|
+
return colorBurn;
|
|
23
|
+
default:
|
|
24
|
+
throw new Error("Unsupported blind watermark composite operation: ".concat(compositeOperation));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var parseNormalizedColor = function (fillStyle) {
|
|
28
|
+
var hexColor = /^#([\da-f]{6})$/i.exec(fillStyle);
|
|
29
|
+
if (hexColor) {
|
|
30
|
+
return {
|
|
31
|
+
color: [
|
|
32
|
+
parseInt(hexColor[1].slice(0, 2), 16),
|
|
33
|
+
parseInt(hexColor[1].slice(2, 4), 16),
|
|
34
|
+
parseInt(hexColor[1].slice(4, 6), 16),
|
|
35
|
+
],
|
|
36
|
+
alpha: 1,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var rgbColor = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)$/i.exec(fillStyle);
|
|
40
|
+
if (rgbColor) {
|
|
41
|
+
return {
|
|
42
|
+
color: [Number(rgbColor[1]), Number(rgbColor[2]), Number(rgbColor[3])],
|
|
43
|
+
alpha: rgbColor[4] === undefined ? 1 : Math.max(0, Math.min(1, Number(rgbColor[4]))),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
var getFillColor = function (ctx, fillColor) {
|
|
49
|
+
var colorCanvas = (ctx.canvas.ownerDocument || document).createElement('canvas');
|
|
50
|
+
colorCanvas.width = 1;
|
|
51
|
+
colorCanvas.height = 1;
|
|
52
|
+
var colorContext = colorCanvas.getContext('2d');
|
|
53
|
+
if (!colorContext) {
|
|
54
|
+
throw new Error('get context error');
|
|
55
|
+
}
|
|
56
|
+
colorContext.fillStyle = fillColor;
|
|
57
|
+
if (typeof colorContext.fillStyle === 'string') {
|
|
58
|
+
var parsedColor = parseNormalizedColor(colorContext.fillStyle);
|
|
59
|
+
if (parsedColor) {
|
|
60
|
+
return parsedColor;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
colorContext.fillRect(0, 0, 1, 1);
|
|
64
|
+
var color = colorContext.getImageData(0, 0, 1, 1).data;
|
|
65
|
+
return {
|
|
66
|
+
color: [color[0], color[1], color[2]],
|
|
67
|
+
alpha: color[3] / MAX_CHANNEL_VALUE,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
var isOpaque = function (data) {
|
|
71
|
+
for (var i = 3; i < data.length; i += 4) {
|
|
72
|
+
if (data[i] !== MAX_CHANNEL_VALUE) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
var applyCommonOpaqueBlend = function (data, sourceColor, compositeOperation, compositeTimes) {
|
|
79
|
+
var isBlack = sourceColor[0] === 0 && sourceColor[1] === 0 && sourceColor[2] === 0;
|
|
80
|
+
var isWhite = sourceColor[0] === 1 && sourceColor[1] === 1 && sourceColor[2] === 1;
|
|
81
|
+
if (compositeOperation === 'color-burn' && (isBlack || isWhite)) {
|
|
82
|
+
if (isBlack) {
|
|
83
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
84
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
85
|
+
data[offset + channel] = data[offset + channel] === MAX_CHANNEL_VALUE ? MAX_CHANNEL_VALUE : 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (compositeOperation !== 'overlay' || (!isBlack && !isWhite)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
var iterations = Math.ceil(compositeTimes);
|
|
95
|
+
var multiplier = Math.pow(2, Math.min(iterations, 8));
|
|
96
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
97
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
98
|
+
var value = data[offset + channel];
|
|
99
|
+
data[offset + channel] = isBlack
|
|
100
|
+
? Math.max(0, multiplier * value - MAX_CHANNEL_VALUE * (multiplier - 1))
|
|
101
|
+
: Math.min(MAX_CHANNEL_VALUE, multiplier * value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
};
|
|
106
|
+
var applyOpaqueBlend = function (data, sourceColor, compositeTimes, blend) {
|
|
107
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
108
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
109
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
110
|
+
data[offset + channel] =
|
|
111
|
+
blend(data[offset + channel] / MAX_CHANNEL_VALUE, sourceColor[channel]) * MAX_CHANNEL_VALUE;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var applyAlphaBlend = function (data, sourceColor, sourceAlpha, compositeTimes, blend) {
|
|
117
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
118
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
119
|
+
var backdropAlpha = data[offset + 3] / MAX_CHANNEL_VALUE;
|
|
120
|
+
var outputAlpha = sourceAlpha + backdropAlpha * (1 - sourceAlpha);
|
|
121
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
122
|
+
var backdrop = data[offset + channel] / MAX_CHANNEL_VALUE;
|
|
123
|
+
var blendedSource = (1 - backdropAlpha) * sourceColor[channel] + backdropAlpha * blend(backdrop, sourceColor[channel]);
|
|
124
|
+
var premultipliedOutput = sourceAlpha * blendedSource + backdropAlpha * (1 - sourceAlpha) * backdrop;
|
|
125
|
+
data[offset + channel] = outputAlpha === 0 ? 0 : (premultipliedOutput / outputAlpha) * MAX_CHANNEL_VALUE;
|
|
126
|
+
}
|
|
127
|
+
data[offset + 3] = outputAlpha * MAX_CHANNEL_VALUE;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var softwareBlindDecodeFallback = function (_a) {
|
|
132
|
+
var ctx = _a.ctx, fillColor = _a.fillColor, compositeOperation = _a.compositeOperation, compositeTimes = _a.compositeTimes;
|
|
133
|
+
var blend = getBlendFunction(compositeOperation);
|
|
134
|
+
var _b = getFillColor(ctx, fillColor), color = _b.color, alpha = _b.alpha;
|
|
135
|
+
if (alpha === 0 || !(compositeTimes > 0)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
var imageData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
139
|
+
var sourceColor = [
|
|
140
|
+
color[0] / MAX_CHANNEL_VALUE,
|
|
141
|
+
color[1] / MAX_CHANNEL_VALUE,
|
|
142
|
+
color[2] / MAX_CHANNEL_VALUE,
|
|
143
|
+
];
|
|
144
|
+
if (alpha === 1 && isOpaque(imageData.data)) {
|
|
145
|
+
if (!applyCommonOpaqueBlend(imageData.data, sourceColor, compositeOperation, compositeTimes)) {
|
|
146
|
+
applyOpaqueBlend(imageData.data, sourceColor, compositeTimes, blend);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
applyAlphaBlend(imageData.data, sourceColor, alpha, compositeTimes, blend);
|
|
151
|
+
}
|
|
152
|
+
ctx.putImageData(imageData, 0, 0);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export { softwareBlindDecodeFallback };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var blindDecodeFallback;
|
|
2
|
+
var registerBlindDecodeFallback = function (fallback) {
|
|
3
|
+
blindDecodeFallback = fallback;
|
|
4
|
+
};
|
|
5
|
+
var applyBlindDecodeComposite = function (_a) {
|
|
6
|
+
var ctx = _a.ctx, width = _a.width, height = _a.height, fillColor = _a.fillColor, compositeOperation = _a.compositeOperation, compositeTimes = _a.compositeTimes;
|
|
7
|
+
if (!(compositeTimes > 0)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var previousCompositeOperation = ctx.globalCompositeOperation;
|
|
11
|
+
ctx.globalCompositeOperation = compositeOperation;
|
|
12
|
+
if (ctx.globalCompositeOperation !== compositeOperation && blindDecodeFallback) {
|
|
13
|
+
ctx.globalCompositeOperation = previousCompositeOperation;
|
|
14
|
+
blindDecodeFallback({
|
|
15
|
+
ctx: ctx,
|
|
16
|
+
fillColor: fillColor,
|
|
17
|
+
compositeOperation: compositeOperation,
|
|
18
|
+
compositeTimes: compositeTimes,
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
ctx.fillStyle = fillColor;
|
|
23
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
24
|
+
ctx.fillRect(0, 0, width, height);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { applyBlindDecodeComposite, registerBlindDecodeFallback };
|
|
@@ -2,6 +2,7 @@ import { __extends, __assign, __awaiter, __generator } from '../../node_modules/
|
|
|
2
2
|
import { convertImage, isFunction } from '../utils/index.js';
|
|
3
3
|
import { Watermark } from './watermark.js';
|
|
4
4
|
import { WatermarkCanvas } from './canvas.js';
|
|
5
|
+
import { applyBlindDecodeComposite } from './blind-decode.js';
|
|
5
6
|
import protection from '../utils/protection.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -64,11 +65,14 @@ var BlindWatermark = /** @class */ (function (_super) {
|
|
|
64
65
|
throw new Error('get context error');
|
|
65
66
|
}
|
|
66
67
|
ctx.drawImage(img_1, 0, 0, width, height);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
applyBlindDecodeComposite({
|
|
69
|
+
ctx: ctx,
|
|
70
|
+
width: width,
|
|
71
|
+
height: height,
|
|
72
|
+
fillColor: fillColor,
|
|
73
|
+
compositeOperation: compositeOperation,
|
|
74
|
+
compositeTimes: compositeTimes,
|
|
75
|
+
});
|
|
72
76
|
var resultImage = convertImage(canvas);
|
|
73
77
|
if (isFunction(onSuccess)) {
|
|
74
78
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resultImage);
|
|
@@ -4,6 +4,10 @@ import '../_virtual/es.array.includes.js';
|
|
|
4
4
|
import '../_virtual/es.array.fill.js';
|
|
5
5
|
import '../node_modules/whatwg-fetch/fetch.js';
|
|
6
6
|
import './utils/polyfill.js';
|
|
7
|
+
import { registerBlindDecodeFallback } from './core/blind-decode.js';
|
|
8
|
+
import { softwareBlindDecodeFallback } from './compat/ie/blind-decode.js';
|
|
7
9
|
export { Watermark } from './core/watermark.js';
|
|
8
10
|
export { BlindWatermark } from './core/blind.js';
|
|
9
11
|
export { ImageWatermark } from './core/image.js';
|
|
12
|
+
|
|
13
|
+
registerBlindDecodeFallback(softwareBlindDecodeFallback);
|
package/dist/ie/index.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* watermark-js-plus v1.6.
|
|
2
|
+
* watermark-js-plus v1.6.6
|
|
3
3
|
* (c) 2022-2024 Michael Sun
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -4273,6 +4273,187 @@ if (typeof CanvasRenderingContext2D !== 'undefined' && !CanvasRenderingContext2D
|
|
|
4273
4273
|
};
|
|
4274
4274
|
}
|
|
4275
4275
|
|
|
4276
|
+
var blindDecodeFallback;
|
|
4277
|
+
var registerBlindDecodeFallback = function (fallback) {
|
|
4278
|
+
blindDecodeFallback = fallback;
|
|
4279
|
+
};
|
|
4280
|
+
var applyBlindDecodeComposite = function (_a) {
|
|
4281
|
+
var ctx = _a.ctx, width = _a.width, height = _a.height, fillColor = _a.fillColor, compositeOperation = _a.compositeOperation, compositeTimes = _a.compositeTimes;
|
|
4282
|
+
if (!(compositeTimes > 0)) {
|
|
4283
|
+
return;
|
|
4284
|
+
}
|
|
4285
|
+
var previousCompositeOperation = ctx.globalCompositeOperation;
|
|
4286
|
+
ctx.globalCompositeOperation = compositeOperation;
|
|
4287
|
+
if (ctx.globalCompositeOperation !== compositeOperation && blindDecodeFallback) {
|
|
4288
|
+
ctx.globalCompositeOperation = previousCompositeOperation;
|
|
4289
|
+
blindDecodeFallback({
|
|
4290
|
+
ctx: ctx,
|
|
4291
|
+
fillColor: fillColor,
|
|
4292
|
+
compositeOperation: compositeOperation,
|
|
4293
|
+
compositeTimes: compositeTimes,
|
|
4294
|
+
});
|
|
4295
|
+
return;
|
|
4296
|
+
}
|
|
4297
|
+
ctx.fillStyle = fillColor;
|
|
4298
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
4299
|
+
ctx.fillRect(0, 0, width, height);
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
|
|
4303
|
+
var MAX_CHANNEL_VALUE = 255;
|
|
4304
|
+
var overlay = function (backdrop, source) {
|
|
4305
|
+
if (backdrop <= 0.5) {
|
|
4306
|
+
return 2 * backdrop * source;
|
|
4307
|
+
}
|
|
4308
|
+
return 1 - 2 * (1 - backdrop) * (1 - source);
|
|
4309
|
+
};
|
|
4310
|
+
var colorBurn = function (backdrop, source) {
|
|
4311
|
+
if (backdrop === 1) {
|
|
4312
|
+
return 1;
|
|
4313
|
+
}
|
|
4314
|
+
if (source === 0) {
|
|
4315
|
+
return 0;
|
|
4316
|
+
}
|
|
4317
|
+
return 1 - Math.min(1, (1 - backdrop) / source);
|
|
4318
|
+
};
|
|
4319
|
+
var getBlendFunction = function (compositeOperation) {
|
|
4320
|
+
switch (compositeOperation) {
|
|
4321
|
+
case 'overlay':
|
|
4322
|
+
return overlay;
|
|
4323
|
+
case 'color-burn':
|
|
4324
|
+
return colorBurn;
|
|
4325
|
+
default:
|
|
4326
|
+
throw new Error("Unsupported blind watermark composite operation: ".concat(compositeOperation));
|
|
4327
|
+
}
|
|
4328
|
+
};
|
|
4329
|
+
var parseNormalizedColor = function (fillStyle) {
|
|
4330
|
+
var hexColor = /^#([\da-f]{6})$/i.exec(fillStyle);
|
|
4331
|
+
if (hexColor) {
|
|
4332
|
+
return {
|
|
4333
|
+
color: [
|
|
4334
|
+
parseInt(hexColor[1].slice(0, 2), 16),
|
|
4335
|
+
parseInt(hexColor[1].slice(2, 4), 16),
|
|
4336
|
+
parseInt(hexColor[1].slice(4, 6), 16),
|
|
4337
|
+
],
|
|
4338
|
+
alpha: 1,
|
|
4339
|
+
};
|
|
4340
|
+
}
|
|
4341
|
+
var rgbColor = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)$/i.exec(fillStyle);
|
|
4342
|
+
if (rgbColor) {
|
|
4343
|
+
return {
|
|
4344
|
+
color: [Number(rgbColor[1]), Number(rgbColor[2]), Number(rgbColor[3])],
|
|
4345
|
+
alpha: rgbColor[4] === undefined ? 1 : Math.max(0, Math.min(1, Number(rgbColor[4]))),
|
|
4346
|
+
};
|
|
4347
|
+
}
|
|
4348
|
+
return undefined;
|
|
4349
|
+
};
|
|
4350
|
+
var getFillColor = function (ctx, fillColor) {
|
|
4351
|
+
var colorCanvas = (ctx.canvas.ownerDocument || document).createElement('canvas');
|
|
4352
|
+
colorCanvas.width = 1;
|
|
4353
|
+
colorCanvas.height = 1;
|
|
4354
|
+
var colorContext = colorCanvas.getContext('2d');
|
|
4355
|
+
if (!colorContext) {
|
|
4356
|
+
throw new Error('get context error');
|
|
4357
|
+
}
|
|
4358
|
+
colorContext.fillStyle = fillColor;
|
|
4359
|
+
if (typeof colorContext.fillStyle === 'string') {
|
|
4360
|
+
var parsedColor = parseNormalizedColor(colorContext.fillStyle);
|
|
4361
|
+
if (parsedColor) {
|
|
4362
|
+
return parsedColor;
|
|
4363
|
+
}
|
|
4364
|
+
}
|
|
4365
|
+
colorContext.fillRect(0, 0, 1, 1);
|
|
4366
|
+
var color = colorContext.getImageData(0, 0, 1, 1).data;
|
|
4367
|
+
return {
|
|
4368
|
+
color: [color[0], color[1], color[2]],
|
|
4369
|
+
alpha: color[3] / MAX_CHANNEL_VALUE,
|
|
4370
|
+
};
|
|
4371
|
+
};
|
|
4372
|
+
var isOpaque = function (data) {
|
|
4373
|
+
for (var i = 3; i < data.length; i += 4) {
|
|
4374
|
+
if (data[i] !== MAX_CHANNEL_VALUE) {
|
|
4375
|
+
return false;
|
|
4376
|
+
}
|
|
4377
|
+
}
|
|
4378
|
+
return true;
|
|
4379
|
+
};
|
|
4380
|
+
var applyCommonOpaqueBlend = function (data, sourceColor, compositeOperation, compositeTimes) {
|
|
4381
|
+
var isBlack = sourceColor[0] === 0 && sourceColor[1] === 0 && sourceColor[2] === 0;
|
|
4382
|
+
var isWhite = sourceColor[0] === 1 && sourceColor[1] === 1 && sourceColor[2] === 1;
|
|
4383
|
+
if (compositeOperation === 'color-burn' && (isBlack || isWhite)) {
|
|
4384
|
+
if (isBlack) {
|
|
4385
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
4386
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
4387
|
+
data[offset + channel] = data[offset + channel] === MAX_CHANNEL_VALUE ? MAX_CHANNEL_VALUE : 0;
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4391
|
+
return true;
|
|
4392
|
+
}
|
|
4393
|
+
if (compositeOperation !== 'overlay' || (!isBlack && !isWhite)) {
|
|
4394
|
+
return false;
|
|
4395
|
+
}
|
|
4396
|
+
var iterations = Math.ceil(compositeTimes);
|
|
4397
|
+
var multiplier = Math.pow(2, Math.min(iterations, 8));
|
|
4398
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
4399
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
4400
|
+
var value = data[offset + channel];
|
|
4401
|
+
data[offset + channel] = isBlack
|
|
4402
|
+
? Math.max(0, multiplier * value - MAX_CHANNEL_VALUE * (multiplier - 1))
|
|
4403
|
+
: Math.min(MAX_CHANNEL_VALUE, multiplier * value);
|
|
4404
|
+
}
|
|
4405
|
+
}
|
|
4406
|
+
return true;
|
|
4407
|
+
};
|
|
4408
|
+
var applyOpaqueBlend = function (data, sourceColor, compositeTimes, blend) {
|
|
4409
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
4410
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
4411
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
4412
|
+
data[offset + channel] =
|
|
4413
|
+
blend(data[offset + channel] / MAX_CHANNEL_VALUE, sourceColor[channel]) * MAX_CHANNEL_VALUE;
|
|
4414
|
+
}
|
|
4415
|
+
}
|
|
4416
|
+
}
|
|
4417
|
+
};
|
|
4418
|
+
var applyAlphaBlend = function (data, sourceColor, sourceAlpha, compositeTimes, blend) {
|
|
4419
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
4420
|
+
for (var offset = 0; offset < data.length; offset += 4) {
|
|
4421
|
+
var backdropAlpha = data[offset + 3] / MAX_CHANNEL_VALUE;
|
|
4422
|
+
var outputAlpha = sourceAlpha + backdropAlpha * (1 - sourceAlpha);
|
|
4423
|
+
for (var channel = 0; channel < 3; channel++) {
|
|
4424
|
+
var backdrop = data[offset + channel] / MAX_CHANNEL_VALUE;
|
|
4425
|
+
var blendedSource = (1 - backdropAlpha) * sourceColor[channel] + backdropAlpha * blend(backdrop, sourceColor[channel]);
|
|
4426
|
+
var premultipliedOutput = sourceAlpha * blendedSource + backdropAlpha * (1 - sourceAlpha) * backdrop;
|
|
4427
|
+
data[offset + channel] = outputAlpha === 0 ? 0 : (premultipliedOutput / outputAlpha) * MAX_CHANNEL_VALUE;
|
|
4428
|
+
}
|
|
4429
|
+
data[offset + 3] = outputAlpha * MAX_CHANNEL_VALUE;
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
};
|
|
4433
|
+
var softwareBlindDecodeFallback = function (_a) {
|
|
4434
|
+
var ctx = _a.ctx, fillColor = _a.fillColor, compositeOperation = _a.compositeOperation, compositeTimes = _a.compositeTimes;
|
|
4435
|
+
var blend = getBlendFunction(compositeOperation);
|
|
4436
|
+
var _b = getFillColor(ctx, fillColor), color = _b.color, alpha = _b.alpha;
|
|
4437
|
+
if (alpha === 0 || !(compositeTimes > 0)) {
|
|
4438
|
+
return;
|
|
4439
|
+
}
|
|
4440
|
+
var imageData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
4441
|
+
var sourceColor = [
|
|
4442
|
+
color[0] / MAX_CHANNEL_VALUE,
|
|
4443
|
+
color[1] / MAX_CHANNEL_VALUE,
|
|
4444
|
+
color[2] / MAX_CHANNEL_VALUE,
|
|
4445
|
+
];
|
|
4446
|
+
if (alpha === 1 && isOpaque(imageData.data)) {
|
|
4447
|
+
if (!applyCommonOpaqueBlend(imageData.data, sourceColor, compositeOperation, compositeTimes)) {
|
|
4448
|
+
applyOpaqueBlend(imageData.data, sourceColor, compositeTimes, blend);
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
else {
|
|
4452
|
+
applyAlphaBlend(imageData.data, sourceColor, alpha, compositeTimes, blend);
|
|
4453
|
+
}
|
|
4454
|
+
ctx.putImageData(imageData, 0, 0);
|
|
4455
|
+
};
|
|
4456
|
+
|
|
4276
4457
|
function styleInject(css, ref) {
|
|
4277
4458
|
if ( ref === void 0 ) ref = {};
|
|
4278
4459
|
var insertAt = ref.insertAt;
|
|
@@ -5514,11 +5695,14 @@ var BlindWatermark = /** @class */ (function (_super) {
|
|
|
5514
5695
|
throw new Error('get context error');
|
|
5515
5696
|
}
|
|
5516
5697
|
ctx.drawImage(img_1, 0, 0, width, height);
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5698
|
+
applyBlindDecodeComposite({
|
|
5699
|
+
ctx: ctx,
|
|
5700
|
+
width: width,
|
|
5701
|
+
height: height,
|
|
5702
|
+
fillColor: fillColor,
|
|
5703
|
+
compositeOperation: compositeOperation,
|
|
5704
|
+
compositeTimes: compositeTimes,
|
|
5705
|
+
});
|
|
5522
5706
|
var resultImage = convertImage(canvas);
|
|
5523
5707
|
if (isFunction(onSuccess)) {
|
|
5524
5708
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resultImage);
|
|
@@ -5585,6 +5769,8 @@ var ImageWatermark = /** @class */ (function () {
|
|
|
5585
5769
|
return ImageWatermark;
|
|
5586
5770
|
}());
|
|
5587
5771
|
|
|
5772
|
+
registerBlindDecodeFallback(softwareBlindDecodeFallback);
|
|
5773
|
+
|
|
5588
5774
|
exports.BlindWatermark = BlindWatermark;
|
|
5589
5775
|
exports.ImageWatermark = ImageWatermark;
|
|
5590
5776
|
exports.Watermark = Watermark;
|