@stream-io/video-filters-web 0.1.0 → 0.1.2
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/CHANGELOG.md +14 -0
- package/dist/index.cjs.js +19 -11
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +19 -11
- package/dist/index.es.js.map +1 -1
- package/dist/src/createRenderer.d.ts +1 -1
- package/package.json +1 -1
- package/src/createRenderer.ts +10 -7
- package/src/webgl2/backgroundBlurStage.ts +19 -11
package/dist/index.es.js
CHANGED
|
@@ -131,11 +131,21 @@ function buildBackgroundBlurStage(gl, vertexShader, positionBuffer, texCoordBuff
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personMaskTexture, canvas, blurLevel) {
|
|
134
|
-
const
|
|
135
|
-
?
|
|
136
|
-
: blurLevel === '
|
|
137
|
-
?
|
|
138
|
-
:
|
|
134
|
+
const sigma = typeof blurLevel === 'number'
|
|
135
|
+
? blurLevel
|
|
136
|
+
: blurLevel === 'low'
|
|
137
|
+
? 2
|
|
138
|
+
: blurLevel === 'medium'
|
|
139
|
+
? 4
|
|
140
|
+
: 6;
|
|
141
|
+
const windowSize = Math.max(1, Math.floor(sigma * 3));
|
|
142
|
+
const offset = new Array(windowSize).fill(0).map((v, index) => index);
|
|
143
|
+
const variance = sigma ** 2;
|
|
144
|
+
const weights = offset.map((x) => {
|
|
145
|
+
var m = sigma * Math.sqrt(2 * Math.PI);
|
|
146
|
+
var e = Math.exp(-(x ** 2) / (2 * variance));
|
|
147
|
+
return e / m;
|
|
148
|
+
});
|
|
139
149
|
const fragmentShaderSource = glsl `#version 300 es
|
|
140
150
|
|
|
141
151
|
precision highp float;
|
|
@@ -147,10 +157,8 @@ function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personM
|
|
|
147
157
|
in vec2 v_texCoord;
|
|
148
158
|
out vec4 outColor;
|
|
149
159
|
|
|
150
|
-
const float offset[
|
|
151
|
-
const float weight[
|
|
152
|
-
${weights.join(',')}
|
|
153
|
-
);
|
|
160
|
+
const float offset[${windowSize}] = float[](${offset.map((i) => i.toFixed(10)).join(', ')});
|
|
161
|
+
const float weight[${windowSize}] = float[](${weights.map((i) => i.toFixed(10)).join(', ')});
|
|
154
162
|
|
|
155
163
|
void main() {
|
|
156
164
|
vec4 centerColor = texture(u_inputFrame, v_texCoord);
|
|
@@ -158,7 +166,7 @@ function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personM
|
|
|
158
166
|
|
|
159
167
|
vec4 frameColor = centerColor * weight[0] * (1.0 - personMask);
|
|
160
168
|
|
|
161
|
-
for (int i = 1; i <
|
|
169
|
+
for (int i = 1; i < ${windowSize}; i++) {
|
|
162
170
|
vec2 offset = vec2(offset[i]) * u_texelSize;
|
|
163
171
|
|
|
164
172
|
vec2 texCoord = v_texCoord + offset;
|
|
@@ -1521,7 +1529,7 @@ const createTFLiteSIMDModule = (__Module) => {
|
|
|
1521
1529
|
return __Module.ready;
|
|
1522
1530
|
};
|
|
1523
1531
|
|
|
1524
|
-
const version = "0.1.
|
|
1532
|
+
const version = "0.1.2" ;
|
|
1525
1533
|
const packageName = "@stream-io/video-filters-web" ;
|
|
1526
1534
|
|
|
1527
1535
|
// @ts-expect-error - module is not declared
|