@stream-io/video-filters-web 0.10.0 → 1.0.0-beta.1
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 +13 -1
- package/README.md +1 -1
- package/dist/esm/index.js +1 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/compatibility.js +1 -18
- package/dist/esm/src/compatibility.js.map +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/index.cjs.js +1 -1559
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/src/compatibility.d.ts +0 -5
- package/index.ts +0 -3
- package/package.json +2 -5
- package/src/compatibility.ts +0 -22
- package/dist/esm/src/legacy/createRenderer.js +0 -33
- package/dist/esm/src/legacy/createRenderer.js.map +0 -1
- package/dist/esm/src/legacy/helpers/webglHelper.js +0 -94
- package/dist/esm/src/legacy/helpers/webglHelper.js.map +0 -1
- package/dist/esm/src/legacy/segmentation.js +0 -14
- package/dist/esm/src/legacy/segmentation.js.map +0 -1
- package/dist/esm/src/legacy/tflite-simd.js +0 -728
- package/dist/esm/src/legacy/tflite-simd.js.map +0 -1
- package/dist/esm/src/legacy/tflite.js +0 -31
- package/dist/esm/src/legacy/tflite.js.map +0 -1
- package/dist/esm/src/legacy/webgl2/backgroundBlurStage.js +0 -202
- package/dist/esm/src/legacy/webgl2/backgroundBlurStage.js.map +0 -1
- package/dist/esm/src/legacy/webgl2/backgroundImageStage.js +0 -157
- package/dist/esm/src/legacy/webgl2/backgroundImageStage.js.map +0 -1
- package/dist/esm/src/legacy/webgl2/jointBilateralFilterStage.js +0 -113
- package/dist/esm/src/legacy/webgl2/jointBilateralFilterStage.js.map +0 -1
- package/dist/esm/src/legacy/webgl2/resizingStage.js +0 -57
- package/dist/esm/src/legacy/webgl2/resizingStage.js.map +0 -1
- package/dist/esm/src/legacy/webgl2/softmaxStage.js +0 -51
- package/dist/esm/src/legacy/webgl2/softmaxStage.js.map +0 -1
- package/dist/esm/src/legacy/webgl2/webgl2Pipeline.js +0 -105
- package/dist/esm/src/legacy/webgl2/webgl2Pipeline.js.map +0 -1
- package/dist/src/legacy/createRenderer.d.ts +0 -16
- package/dist/src/legacy/helpers/webglHelper.d.ts +0 -17
- package/dist/src/legacy/segmentation.d.ts +0 -9
- package/dist/src/legacy/tflite.d.ts +0 -18
- package/dist/src/legacy/webgl2/backgroundBlurStage.d.ts +0 -7
- package/dist/src/legacy/webgl2/backgroundImageStage.d.ts +0 -8
- package/dist/src/legacy/webgl2/jointBilateralFilterStage.d.ts +0 -7
- package/dist/src/legacy/webgl2/resizingStage.d.ts +0 -6
- package/dist/src/legacy/webgl2/softmaxStage.d.ts +0 -6
- package/dist/src/legacy/webgl2/webgl2Pipeline.d.ts +0 -8
- package/src/legacy/createRenderer.ts +0 -73
- package/src/legacy/helpers/webglHelper.ts +0 -144
- package/src/legacy/segmentation.ts +0 -18
- package/src/legacy/tflite-simd.js +0 -874
- package/src/legacy/tflite.ts +0 -59
- package/src/legacy/webgl2/backgroundBlurStage.ts +0 -315
- package/src/legacy/webgl2/backgroundImageStage.ts +0 -222
- package/src/legacy/webgl2/jointBilateralFilterStage.ts +0 -159
- package/src/legacy/webgl2/resizingStage.ts +0 -106
- package/src/legacy/webgl2/softmaxStage.ts +0 -103
- package/src/legacy/webgl2/webgl2Pipeline.ts +0 -203
- package/tf/models/segm_full_v679.tflite +0 -0
- package/tf/tflite/tflite-simd.wasm +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export * from './src/compatibility';
|
|
2
|
-
export * from './src/legacy/createRenderer';
|
|
3
|
-
export { SegmentationLevel } from './src/legacy/segmentation';
|
|
4
|
-
export * from './src/legacy/tflite';
|
|
5
2
|
export * from './src/mediapipe';
|
|
6
3
|
export * from './src/types';
|
|
7
4
|
export * from './src/BaseVideoProcessor';
|
|
@@ -9,11 +9,6 @@ export type PlatformSupportFlags = {
|
|
|
9
9
|
*/
|
|
10
10
|
forceSafariSupport?: boolean;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* Runs a check to see if the current platform supports
|
|
14
|
-
* the necessary APIs required for the video filters.
|
|
15
|
-
*/
|
|
16
|
-
export declare const isPlatformSupported: ({ forceMobileSupport, forceSafariSupport, }?: PlatformSupportFlags) => Promise<boolean>;
|
|
17
12
|
/**
|
|
18
13
|
* Runs a check to see if the current platform supports
|
|
19
14
|
* the necessary APIs required for the MediaPipe-based video filters.
|
package/index.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export * from './src/compatibility';
|
|
2
|
-
export * from './src/legacy/createRenderer';
|
|
3
|
-
export { SegmentationLevel } from './src/legacy/segmentation';
|
|
4
|
-
export * from './src/legacy/tflite';
|
|
5
2
|
export * from './src/mediapipe';
|
|
6
3
|
export * from './src/types';
|
|
7
4
|
export * from './src/BaseVideoProcessor';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-filters-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"main": "./dist/index.cjs.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
|
-
"tf",
|
|
22
21
|
"mediapipe",
|
|
23
22
|
"src",
|
|
24
23
|
"index.ts",
|
|
@@ -29,15 +28,13 @@
|
|
|
29
28
|
],
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"@mediapipe/tasks-vision": "^0.10.35",
|
|
32
|
-
"@stream-io/worker-timer": "^1.2.5"
|
|
33
|
-
"wasm-feature-detect": "^1.8.0"
|
|
31
|
+
"@stream-io/worker-timer": "^1.2.5"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
36
34
|
"@rollup/plugin-replace": "^6.0.3",
|
|
37
35
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
38
36
|
"@stream-io/typescript-config": "^0.0.0",
|
|
39
37
|
"@types/dom-mediacapture-transform": "^0.1.12",
|
|
40
|
-
"@types/emscripten": "^1.41.5",
|
|
41
38
|
"@types/node": "^25.9.5",
|
|
42
39
|
"rimraf": "^6.1.3",
|
|
43
40
|
"rollup": "^4.62.4",
|
package/src/compatibility.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { simd } from 'wasm-feature-detect';
|
|
2
|
-
|
|
3
1
|
export type PlatformSupportFlags = {
|
|
4
2
|
/**
|
|
5
3
|
* Forces support for mobile devices, although performance isn't optimal.
|
|
@@ -27,26 +25,6 @@ const isMobile = () => /Mobi/i.test(navigator.userAgent);
|
|
|
27
25
|
const isSafari = () =>
|
|
28
26
|
/^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
29
27
|
|
|
30
|
-
/**
|
|
31
|
-
* Runs a check to see if the current platform supports
|
|
32
|
-
* the necessary APIs required for the video filters.
|
|
33
|
-
*/
|
|
34
|
-
export const isPlatformSupported = async ({
|
|
35
|
-
forceMobileSupport = false,
|
|
36
|
-
forceSafariSupport = false,
|
|
37
|
-
}: PlatformSupportFlags = {}) =>
|
|
38
|
-
typeof document !== 'undefined' &&
|
|
39
|
-
typeof window !== 'undefined' &&
|
|
40
|
-
typeof navigator !== 'undefined' &&
|
|
41
|
-
// we don't support mobile devices yet due to performance issues
|
|
42
|
-
(forceMobileSupport || !isMobile()) &&
|
|
43
|
-
// Safari has issues with timer throttling, causing low FPS when the tab goes to the background
|
|
44
|
-
(forceSafariSupport || !isSafari()) &&
|
|
45
|
-
typeof WebAssembly !== 'undefined' &&
|
|
46
|
-
!!window.WebGL2RenderingContext && // WebGL2 is required for the video filters
|
|
47
|
-
!!document.createElement('canvas').getContext('webgl2') &&
|
|
48
|
-
(await simd()); // SIMD is required for the wasm module
|
|
49
|
-
|
|
50
28
|
/**
|
|
51
29
|
* Runs a check to see if the current platform supports
|
|
52
30
|
* the necessary APIs required for the MediaPipe-based video filters.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { WorkerTimer } from '@stream-io/worker-timer';
|
|
2
|
-
import { buildWebGL2Pipeline } from './webgl2/webgl2Pipeline.js';
|
|
3
|
-
import { SegmentationLevel, getSegmentationParams } from './segmentation.js';
|
|
4
|
-
|
|
5
|
-
function createRenderer(tflite, videoSource, targetCanvas, options, onError) {
|
|
6
|
-
const { backgroundFilter, backgroundImage, backgroundBlurLevel, segmentationLevel = SegmentationLevel.HIGH, fps = 30, } = options;
|
|
7
|
-
if (backgroundFilter === 'image' && !backgroundImage) {
|
|
8
|
-
throw new Error(`backgroundImage element is required when backgroundFilter is image`);
|
|
9
|
-
}
|
|
10
|
-
const pipeline = buildWebGL2Pipeline(videoSource, backgroundImage, backgroundBlurLevel, backgroundFilter, targetCanvas, tflite, getSegmentationParams(segmentationLevel));
|
|
11
|
-
const timers = new WorkerTimer({ useWorker: true });
|
|
12
|
-
const id = timers.setInterval(() => {
|
|
13
|
-
try {
|
|
14
|
-
pipeline.render();
|
|
15
|
-
if (backgroundFilter === 'image') {
|
|
16
|
-
pipeline.updatePostProcessingConfig();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
onError?.(error);
|
|
21
|
-
}
|
|
22
|
-
}, Math.floor(1000 / (fps <= 0 ? 30 : fps)));
|
|
23
|
-
return {
|
|
24
|
-
dispose: () => {
|
|
25
|
-
pipeline.cleanUp();
|
|
26
|
-
timers.clearInterval(id);
|
|
27
|
-
timers.destroy();
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { createRenderer };
|
|
33
|
-
//# sourceMappingURL=createRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.js","sources":["../../../../../../src/legacy/createRenderer.ts"],"sourcesContent":["import { WorkerTimer } from '@stream-io/worker-timer';\nimport { TFLite } from './tflite';\nimport { buildWebGL2Pipeline } from './webgl2/webgl2Pipeline';\nimport { getSegmentationParams, SegmentationLevel } from './segmentation';\nimport { BackgroundBlurLevel, BackgroundFilter } from '../types';\n\nexport type Renderer = {\n /**\n * Disposes of the renderer.\n */\n dispose: () => void;\n};\n\nexport function createRenderer(\n tflite: TFLite,\n videoSource: HTMLVideoElement,\n targetCanvas: HTMLCanvasElement,\n options: {\n backgroundFilter: BackgroundFilter;\n segmentationLevel?: SegmentationLevel;\n backgroundImage?: HTMLImageElement;\n backgroundBlurLevel?: BackgroundBlurLevel;\n fps?: number;\n },\n onError?: (error: any) => void,\n): Renderer {\n const {\n backgroundFilter,\n backgroundImage,\n backgroundBlurLevel,\n segmentationLevel = SegmentationLevel.HIGH,\n fps = 30,\n } = options;\n if (backgroundFilter === 'image' && !backgroundImage) {\n throw new Error(\n `backgroundImage element is required when backgroundFilter is image`,\n );\n }\n\n const pipeline = buildWebGL2Pipeline(\n videoSource,\n backgroundImage,\n backgroundBlurLevel,\n backgroundFilter,\n targetCanvas,\n tflite,\n getSegmentationParams(segmentationLevel),\n );\n\n const timers = new WorkerTimer({ useWorker: true });\n const id = timers.setInterval(\n () => {\n try {\n pipeline.render();\n\n if (backgroundFilter === 'image') {\n pipeline.updatePostProcessingConfig();\n }\n } catch (error) {\n onError?.(error);\n }\n },\n Math.floor(1000 / (fps <= 0 ? 30 : fps)),\n );\n\n return {\n dispose: () => {\n pipeline.cleanUp();\n timers.clearInterval(id);\n timers.destroy();\n },\n };\n}\n"],"names":[],"mappings":";;;;AAaM,SAAU,cAAc,CAC5B,MAAc,EACd,WAA6B,EAC7B,YAA+B,EAC/B,OAMC,EACD,OAA8B,EAAA;AAE9B,IAAA,MAAM,EACJ,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,GAAG,iBAAiB,CAAC,IAAI,EAC1C,GAAG,GAAG,EAAE,GACT,GAAG,OAAO;AACX,IAAA,IAAI,gBAAgB,KAAK,OAAO,IAAI,CAAC,eAAe,EAAE;AACpD,QAAA,MAAM,IAAI,KAAK,CACb,CAAA,kEAAA,CAAoE,CACrE;IACH;IAEA,MAAM,QAAQ,GAAG,mBAAmB,CAClC,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,qBAAqB,CAAC,iBAAiB,CAAC,CACzC;IAED,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACnD,IAAA,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAC3B,MAAK;AACH,QAAA,IAAI;YACF,QAAQ,CAAC,MAAM,EAAE;AAEjB,YAAA,IAAI,gBAAgB,KAAK,OAAO,EAAE;gBAChC,QAAQ,CAAC,0BAA0B,EAAE;YACvC;QACF;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,GAAG,KAAK,CAAC;QAClB;IACF,CAAC,EACD,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CACzC;IAED,OAAO;QACL,OAAO,EAAE,MAAK;YACZ,QAAQ,CAAC,OAAO,EAAE;AAClB,YAAA,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,OAAO,EAAE;QAClB,CAAC;KACF;AACH;;;;"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Use it along with boyswan.glsl-literal VSCode extension
|
|
3
|
-
* to get GLSL syntax highlighting.
|
|
4
|
-
* https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
|
|
5
|
-
*
|
|
6
|
-
* On VSCode OSS, boyswan.glsl-literal requires slevesque.shader extension
|
|
7
|
-
* to be installed as well.
|
|
8
|
-
* https://marketplace.visualstudio.com/items?itemName=slevesque.shader
|
|
9
|
-
*/
|
|
10
|
-
const glsl = String.raw;
|
|
11
|
-
function createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer) {
|
|
12
|
-
const program = createProgram(gl, vertexShader, fragmentShader);
|
|
13
|
-
const positionAttributeLocation = gl.getAttribLocation(program, 'a_position');
|
|
14
|
-
gl.enableVertexAttribArray(positionAttributeLocation);
|
|
15
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
16
|
-
gl.vertexAttribPointer(positionAttributeLocation, 2, gl.FLOAT, false, 0, 0);
|
|
17
|
-
const texCoordAttributeLocation = gl.getAttribLocation(program, 'a_texCoord');
|
|
18
|
-
gl.enableVertexAttribArray(texCoordAttributeLocation);
|
|
19
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
|
|
20
|
-
gl.vertexAttribPointer(texCoordAttributeLocation, 2, gl.FLOAT, false, 0, 0);
|
|
21
|
-
return program;
|
|
22
|
-
}
|
|
23
|
-
function createProgram(gl, vertexShader, fragmentShader) {
|
|
24
|
-
const program = gl.createProgram();
|
|
25
|
-
gl.attachShader(program, vertexShader);
|
|
26
|
-
gl.attachShader(program, fragmentShader);
|
|
27
|
-
gl.linkProgram(program);
|
|
28
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
29
|
-
throw new Error(`Could not link WebGL program: ${gl.getProgramInfoLog(program)}`);
|
|
30
|
-
}
|
|
31
|
-
return program;
|
|
32
|
-
}
|
|
33
|
-
function compileShader(gl, shaderType, shaderSource) {
|
|
34
|
-
const shader = gl.createShader(shaderType);
|
|
35
|
-
gl.shaderSource(shader, shaderSource);
|
|
36
|
-
gl.compileShader(shader);
|
|
37
|
-
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
38
|
-
throw new Error(`Could not compile shader: ${gl.getShaderInfoLog(shader)}`);
|
|
39
|
-
}
|
|
40
|
-
return shader;
|
|
41
|
-
}
|
|
42
|
-
function createTexture(gl, internalformat, width, height, minFilter = gl.NEAREST, magFilter = gl.NEAREST) {
|
|
43
|
-
const texture = gl.createTexture();
|
|
44
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
45
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
46
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
47
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
|
|
48
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
|
|
49
|
-
gl.texStorage2D(gl.TEXTURE_2D, 1, internalformat, width, height);
|
|
50
|
-
return texture;
|
|
51
|
-
}
|
|
52
|
-
async function readPixelsAsync(gl, x, y, width, height, format, type, dest) {
|
|
53
|
-
const buf = gl.createBuffer();
|
|
54
|
-
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);
|
|
55
|
-
gl.bufferData(gl.PIXEL_PACK_BUFFER, dest.byteLength, gl.STREAM_READ);
|
|
56
|
-
gl.readPixels(x, y, width, height, format, type, 0);
|
|
57
|
-
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
|
|
58
|
-
await getBufferSubDataAsync(gl, gl.PIXEL_PACK_BUFFER, buf, 0, dest);
|
|
59
|
-
gl.deleteBuffer(buf);
|
|
60
|
-
return dest;
|
|
61
|
-
}
|
|
62
|
-
async function getBufferSubDataAsync(gl, target, buffer, srcByteOffset, dstBuffer, dstOffset, length) {
|
|
63
|
-
const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
64
|
-
gl.flush();
|
|
65
|
-
if (!sync)
|
|
66
|
-
return;
|
|
67
|
-
const res = await clientWaitAsync(gl, sync);
|
|
68
|
-
gl.deleteSync(sync);
|
|
69
|
-
if (res !== gl.WAIT_FAILED) {
|
|
70
|
-
gl.bindBuffer(target, buffer);
|
|
71
|
-
gl.getBufferSubData(target, srcByteOffset, dstBuffer, dstOffset, length);
|
|
72
|
-
gl.bindBuffer(target, null);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function clientWaitAsync(gl, sync) {
|
|
76
|
-
return new Promise((resolve) => {
|
|
77
|
-
function test() {
|
|
78
|
-
const res = gl.clientWaitSync(sync, 0, 0);
|
|
79
|
-
if (res === gl.WAIT_FAILED) {
|
|
80
|
-
resolve(res);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (res === gl.TIMEOUT_EXPIRED) {
|
|
84
|
-
setTimeout(test);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
resolve(res);
|
|
88
|
-
}
|
|
89
|
-
setTimeout(test);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { compileShader, createPipelineStageProgram, createProgram, createTexture, glsl, readPixelsAsync };
|
|
94
|
-
//# sourceMappingURL=webglHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webglHelper.js","sources":["../../../../../../../src/legacy/helpers/webglHelper.ts"],"sourcesContent":["/**\n * Use it along with boyswan.glsl-literal VSCode extension\n * to get GLSL syntax highlighting.\n * https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal\n *\n * On VSCode OSS, boyswan.glsl-literal requires slevesque.shader extension\n * to be installed as well.\n * https://marketplace.visualstudio.com/items?itemName=slevesque.shader\n */\nexport const glsl = String.raw;\n\nexport function createPipelineStageProgram(\n gl: WebGL2RenderingContext,\n vertexShader: WebGLShader,\n fragmentShader: WebGLShader,\n positionBuffer: WebGLBuffer,\n texCoordBuffer: WebGLBuffer,\n) {\n const program = createProgram(gl, vertexShader, fragmentShader);\n\n const positionAttributeLocation = gl.getAttribLocation(program, 'a_position');\n gl.enableVertexAttribArray(positionAttributeLocation);\n gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);\n gl.vertexAttribPointer(positionAttributeLocation, 2, gl.FLOAT, false, 0, 0);\n\n const texCoordAttributeLocation = gl.getAttribLocation(program, 'a_texCoord');\n gl.enableVertexAttribArray(texCoordAttributeLocation);\n gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);\n gl.vertexAttribPointer(texCoordAttributeLocation, 2, gl.FLOAT, false, 0, 0);\n\n return program;\n}\n\nexport function createProgram(\n gl: WebGL2RenderingContext,\n vertexShader: WebGLShader,\n fragmentShader: WebGLShader,\n) {\n const program = gl.createProgram()!;\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n throw new Error(\n `Could not link WebGL program: ${gl.getProgramInfoLog(program)}`,\n );\n }\n return program;\n}\n\nexport function compileShader(\n gl: WebGL2RenderingContext,\n shaderType: number,\n shaderSource: string,\n) {\n const shader = gl.createShader(shaderType)!;\n gl.shaderSource(shader, shaderSource);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n throw new Error(`Could not compile shader: ${gl.getShaderInfoLog(shader)}`);\n }\n return shader;\n}\n\nexport function createTexture(\n gl: WebGL2RenderingContext,\n internalformat: number,\n width: number,\n height: number,\n minFilter = gl.NEAREST,\n magFilter = gl.NEAREST,\n) {\n const texture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n gl.texStorage2D(gl.TEXTURE_2D, 1, internalformat, width, height);\n return texture;\n}\n\nexport async function readPixelsAsync(\n gl: WebGL2RenderingContext,\n x: number,\n y: number,\n width: number,\n height: number,\n format: number,\n type: number,\n dest: ArrayBufferView,\n) {\n const buf = gl.createBuffer()!;\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);\n gl.bufferData(gl.PIXEL_PACK_BUFFER, dest.byteLength, gl.STREAM_READ);\n gl.readPixels(x, y, width, height, format, type, 0);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n\n await getBufferSubDataAsync(gl, gl.PIXEL_PACK_BUFFER, buf, 0, dest);\n\n gl.deleteBuffer(buf);\n return dest;\n}\n\nasync function getBufferSubDataAsync(\n gl: WebGL2RenderingContext,\n target: number,\n buffer: WebGLBuffer,\n srcByteOffset: number,\n dstBuffer: ArrayBufferView,\n dstOffset?: number,\n length?: number,\n) {\n const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);\n gl.flush();\n if (!sync) return;\n\n const res = await clientWaitAsync(gl, sync);\n gl.deleteSync(sync);\n\n if (res !== gl.WAIT_FAILED) {\n gl.bindBuffer(target, buffer);\n gl.getBufferSubData(target, srcByteOffset, dstBuffer, dstOffset, length);\n gl.bindBuffer(target, null);\n }\n}\n\nfunction clientWaitAsync(gl: WebGL2RenderingContext, sync: WebGLSync) {\n return new Promise<number>((resolve) => {\n function test() {\n const res = gl.clientWaitSync(sync, 0, 0);\n if (res === gl.WAIT_FAILED) {\n resolve(res);\n return;\n }\n if (res === gl.TIMEOUT_EXPIRED) {\n setTimeout(test);\n return;\n }\n resolve(res);\n }\n setTimeout(test);\n });\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;AAQG;AACI,MAAM,IAAI,GAAG,MAAM,CAAC;AAErB,SAAU,0BAA0B,CACxC,EAA0B,EAC1B,YAAyB,EACzB,cAA2B,EAC3B,cAA2B,EAC3B,cAA2B,EAAA;IAE3B,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,EAAE,YAAY,EAAE,cAAc,CAAC;IAE/D,MAAM,yBAAyB,GAAG,EAAE,CAAC,iBAAiB,CAAC,OA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,CAAC,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC;AACxE,QAAA,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC;IAC7B;AACF;AAEA,SAAS,eAAe,CAAC,EAA0B,EAAE,IAAe,EAAA;AAClE,IAAA,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,KAAI;AACrC,QAAA,SAAS,IAAI,GAAA;AACX,YAAA,MAAM,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AACzC,YAAA,IAAI,GAAG,KAAK,EAAE,CAAC,WAAW,EAAE;gBAC1B,OAAO,CAAC,GAAG,CAAC;gBACZ;YACF;AACA,YAAA,IAAI,GAAG,KAAK,EAAE,CAAC,eAAe,EAAE;gBAC9B,UAAU,CAAC,IAAI,CAAC;gBAChB;YACF;YACA,OAAO,CAAC,GAAG,CAAC;QACd;QACA,UAAU,CAAC,IAAI,CAAC;AAClB,IAAA,CAAC,CAAC;AACJ;;;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var SegmentationLevel;
|
|
2
|
-
(function (SegmentationLevel) {
|
|
3
|
-
SegmentationLevel["LOW"] = "low";
|
|
4
|
-
SegmentationLevel["HIGH"] = "high";
|
|
5
|
-
})(SegmentationLevel || (SegmentationLevel = {}));
|
|
6
|
-
const getSegmentationParams = (level) => {
|
|
7
|
-
if (level === SegmentationLevel.HIGH) {
|
|
8
|
-
return { width: 256, height: 144 };
|
|
9
|
-
}
|
|
10
|
-
return { width: 160, height: 96 };
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { SegmentationLevel, getSegmentationParams };
|
|
14
|
-
//# sourceMappingURL=segmentation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"segmentation.js","sources":["../../../../../../src/legacy/segmentation.ts"],"sourcesContent":["export type SegmentationParams = {\n width: number;\n height: number;\n};\n\nexport enum SegmentationLevel {\n LOW = 'low',\n HIGH = 'high',\n}\n\nexport const getSegmentationParams = (\n level: SegmentationLevel,\n): SegmentationParams => {\n if (level === SegmentationLevel.HIGH) {\n return { width: 256, height: 144 };\n }\n return { width: 160, height: 96 };\n};\n"],"names":[],"mappings":"IAKY;AAAZ,CAAA,UAAY,iBAAiB,EAAA;AAC3B,IAAA,iBAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,iBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACf,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,GAAA,EAAA,CAAA,CAAA;AAKtB,MAAM,qBAAqB,GAAG,CACnC,KAAwB,KACF;AACtB,IAAA,IAAI,KAAK,KAAK,iBAAiB,CAAC,IAAI,EAAE;QACpC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IACpC;IACA,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE;AACnC;;;;"}
|