@webex/ladon-ts 5.4.1 → 5.4.3
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 +177 -163
- package/LICENSE +5 -5
- package/README.md +34 -36
- package/build/module/index.d.ts +10 -10
- package/build/module/lib/config-builder.d.ts +179 -180
- package/build/module/lib/config-types.d.ts +101 -101
- package/build/module/lib/config.d.ts +28 -29
- package/build/module/lib/generator.d.ts +73 -74
- package/build/module/lib/pipeline.d.ts +82 -83
- package/build/module/lib/preload.d.ts +7 -8
- package/build/module/lib/renderer/blur-renderer.d.ts +17 -18
- package/build/module/lib/renderer/ladon-renderer.d.ts +5 -6
- package/build/module/lib/renderer/passthrough-renderer.d.ts +10 -11
- package/build/module/lib/renderer/replacement-renderer.d.ts +14 -15
- package/build/module/lib/renderer/webgl-renderer.d.ts +23 -24
- package/build/module/lib/renderer.d.ts +5 -5
- package/build/module/lib/shared-resource-manager.d.ts +92 -92
- package/build/module/lib/shared-resource-manager.js +25 -26
- package/build/module/lib/shared-resource-manager.js.map +1 -1
- package/build/module/lib/util.d.ts +64 -64
- package/build/module/lib/version.d.ts +1 -1
- package/build/module/lib/version.js +1 -1
- package/build/module/lib/version.js.map +1 -1
- package/build/worker/segmentation.js +253 -248
- package/build/worker/segmentation.js.map +1 -0
- package/package.json +102 -95
|
@@ -1,75 +1,74 @@
|
|
|
1
1
|
import { PipelineConfig } from './config-types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param {
|
|
42
|
-
* @
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
private
|
|
66
|
-
private
|
|
67
|
-
private
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
2
|
+
declare global {
|
|
3
|
+
interface ImportMeta {
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export type FrameData = Uint8ClampedArray | HTMLVideoElement;
|
|
8
|
+
export interface FacesAndLandmarks {
|
|
9
|
+
data: Float32Array;
|
|
10
|
+
dims: readonly number[];
|
|
11
|
+
}
|
|
12
|
+
export interface LadonOutput {
|
|
13
|
+
data: Float32Array;
|
|
14
|
+
facesAndLandmarks: FacesAndLandmarks;
|
|
15
|
+
gesture: Float32Array;
|
|
16
|
+
motion: number;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
warm: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface MaskGenerator {
|
|
21
|
+
getLadonOutput(input: Uint8ClampedArray, timestamp: number): Promise<LadonOutput>;
|
|
22
|
+
load(): Promise<void>;
|
|
23
|
+
isLoaded(): boolean;
|
|
24
|
+
postRender(input: Uint8ClampedArray, timestamp: number): Promise<void>;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class LocalGenerator implements MaskGenerator {
|
|
28
|
+
readonly config: PipelineConfig;
|
|
29
|
+
private lastResult;
|
|
30
|
+
private lastMask;
|
|
31
|
+
private maskModel?;
|
|
32
|
+
private lastMaskGenerationTime;
|
|
33
|
+
private output?;
|
|
34
|
+
constructor(config: PipelineConfig);
|
|
35
|
+
/**
|
|
36
|
+
* This method preprocesses an input Uint8ClampedArray to a Float32Array
|
|
37
|
+
* while maintaining memory efficiency by reusing a class-scoped output buffer.
|
|
38
|
+
* If the model rank is 4 (e.g., newer tiny model), it sets an alpha channel value.
|
|
39
|
+
*
|
|
40
|
+
* @param {Uint8ClampedArray} input - The input data to be preprocessed
|
|
41
|
+
* @param {Float32Array} alpha - The alpha channel data
|
|
42
|
+
* @returns {Float32Array} - The processed data
|
|
43
|
+
*/
|
|
44
|
+
private preprocess;
|
|
45
|
+
getTimeSinceLastGeneration(): number;
|
|
46
|
+
getLadonOutput(input: Uint8ClampedArray, timestamp: number): Promise<LadonOutput>;
|
|
47
|
+
load(): Promise<void>;
|
|
48
|
+
isLoaded(): boolean;
|
|
49
|
+
postRender(_: Uint8ClampedArray): Promise<void>;
|
|
50
|
+
destroy(): void;
|
|
51
|
+
}
|
|
52
|
+
export declare class NullGenerator implements MaskGenerator {
|
|
53
|
+
readonly config: PipelineConfig;
|
|
54
|
+
private lastMask;
|
|
55
|
+
constructor(config: PipelineConfig);
|
|
56
|
+
getLadonOutput(_: Uint8ClampedArray): Promise<LadonOutput>;
|
|
57
|
+
load(): Promise<void>;
|
|
58
|
+
isLoaded(): boolean;
|
|
59
|
+
postRender(_: Uint8ClampedArray): Promise<void>;
|
|
60
|
+
destroy(): void;
|
|
61
|
+
}
|
|
62
|
+
export declare class WorkerGenerator implements MaskGenerator {
|
|
63
|
+
readonly config: PipelineConfig;
|
|
64
|
+
private lastMask;
|
|
65
|
+
private newMask;
|
|
66
|
+
private worker?;
|
|
67
|
+
private lastResult;
|
|
68
|
+
constructor(config: PipelineConfig);
|
|
69
|
+
getLadonOutput(_: Uint8ClampedArray): Promise<LadonOutput>;
|
|
70
|
+
load(): Promise<void>;
|
|
71
|
+
isLoaded(): boolean;
|
|
72
|
+
postRender(input: Uint8ClampedArray, timestamp: number): Promise<void>;
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
@@ -1,85 +1,84 @@
|
|
|
1
1
|
import { PipelineConfig } from './config-types';
|
|
2
2
|
import { FacesAndLandmarks } from './generator';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
readonly
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @param
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @param {
|
|
62
|
-
* @
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
3
|
+
export interface IFrameInferenceResult {
|
|
4
|
+
facesAndLandmarks: FacesAndLandmarks;
|
|
5
|
+
gesture: Float32Array;
|
|
6
|
+
motion: number;
|
|
7
|
+
skipped: boolean;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
}
|
|
10
|
+
export interface IPipeline {
|
|
11
|
+
onFrame(timestamp: number, maskNeeded?: boolean): Promise<IFrameInferenceResult>;
|
|
12
|
+
isLoaded(): boolean;
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class Pipeline implements IPipeline {
|
|
17
|
+
private inputCanvas;
|
|
18
|
+
private outputCanvas;
|
|
19
|
+
readonly config: PipelineConfig;
|
|
20
|
+
private readonly videoElement?;
|
|
21
|
+
private generator?;
|
|
22
|
+
private renderer?;
|
|
23
|
+
private loaded;
|
|
24
|
+
private inputCanvasCtx;
|
|
25
|
+
private lastMaskResult?;
|
|
26
|
+
private frameQueue;
|
|
27
|
+
private maskQueue;
|
|
28
|
+
constructor(inputCanvas: HTMLCanvasElement, outputCanvas: HTMLCanvasElement, config: PipelineConfig, videoElement?: HTMLVideoElement | undefined);
|
|
29
|
+
/**
|
|
30
|
+
* Processes a single frame and returns the inference result.
|
|
31
|
+
*
|
|
32
|
+
* @param timestamp - The timestamp of the frame.
|
|
33
|
+
* @param performInference - Flag to perform mask inference.
|
|
34
|
+
* @returns The result of the frame processing.
|
|
35
|
+
* @throws If the pipeline (generator or renderer) is not loaded.
|
|
36
|
+
*/
|
|
37
|
+
onFrame(timestamp: number, performInference?: boolean): Promise<IFrameInferenceResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Synchronizes frames and masks to ensure they are rendered together.
|
|
40
|
+
*/
|
|
41
|
+
private renderSyncedFrameAndMask;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the raw image data from the input canvas context.
|
|
44
|
+
*
|
|
45
|
+
* @param needFreshImageData - Flag to indicate if fresh image data is needed.
|
|
46
|
+
*
|
|
47
|
+
* @returns The raw image data.
|
|
48
|
+
*/
|
|
49
|
+
private getInputFrameData;
|
|
50
|
+
/**
|
|
51
|
+
* Resizes the image data if the model expects a fixed size input.
|
|
52
|
+
*
|
|
53
|
+
* @param {Uint8ClampedArray} rawImageData - The raw image data.
|
|
54
|
+
* @returns {Uint8ClampedArray} - The processed mask image data.
|
|
55
|
+
*/
|
|
56
|
+
private getMaskImageData;
|
|
57
|
+
/**
|
|
58
|
+
* Creates the inference result object.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} timestamp - The timestamp of the frame.
|
|
61
|
+
* @param {boolean} performedInference - Indicates if the inference was performed.
|
|
62
|
+
* @returns {IFrameInferenceResult} - The result object containing inference details.
|
|
63
|
+
*/
|
|
64
|
+
private createInferenceResult;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if the pipeline is loaded.
|
|
67
|
+
*
|
|
68
|
+
* @returns True if the pipeline is loaded, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
isLoaded(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Loads the pipeline components such as the generator and renderer.
|
|
73
|
+
*/
|
|
74
|
+
load(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Resets the frame and mask queues.
|
|
77
|
+
*/
|
|
78
|
+
private resetQueues;
|
|
79
|
+
reset(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Destroys the pipeline and cleans up resources.
|
|
82
|
+
*/
|
|
83
|
+
destroy(): void;
|
|
84
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { PreloadConfig } from './config-types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare const preload: (config: PreloadConfig) => Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* Preload the resources using the provided configuration. This function is used to preload the model
|
|
4
|
+
* and the worker before creating the pipeline.
|
|
5
|
+
*
|
|
6
|
+
* @param config - The configuration object.
|
|
7
|
+
*/
|
|
8
|
+
export declare const preload: (config: PreloadConfig) => Promise<void>;
|
|
@@ -2,21 +2,20 @@ import { PipelineConfig } from '../config-types';
|
|
|
2
2
|
import { FrameData, LadonOutput } from '../generator';
|
|
3
3
|
import { LadonRenderer } from './ladon-renderer';
|
|
4
4
|
import { WebGLRenderer } from './webgl-renderer';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
5
|
+
export declare class BlurRenderer extends WebGLRenderer implements LadonRenderer {
|
|
6
|
+
output_canvas: HTMLCanvasElement;
|
|
7
|
+
readonly config: PipelineConfig;
|
|
8
|
+
private program_1;
|
|
9
|
+
private program_2;
|
|
10
|
+
private framebuffer;
|
|
11
|
+
private transfer_texture;
|
|
12
|
+
private u_blur;
|
|
13
|
+
private fragment_shader_common;
|
|
14
|
+
private fragment_shader_pass_1_src;
|
|
15
|
+
fragment_shader_pass_2_src: string;
|
|
16
|
+
constructor(output_canvas: HTMLCanvasElement, config: PipelineConfig);
|
|
17
|
+
render(input: FrameData, mask?: LadonOutput): Promise<void>;
|
|
18
|
+
load(): Promise<void>;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
private getBlurKernel;
|
|
21
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FrameData, LadonOutput } from '../generator';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
export interface LadonRenderer {
|
|
3
|
+
render(input: FrameData, mask?: LadonOutput): Promise<void>;
|
|
4
|
+
load(): Promise<void>;
|
|
5
|
+
destroy(): void;
|
|
6
|
+
}
|
|
@@ -2,14 +2,13 @@ import { PipelineConfig } from '../config-types';
|
|
|
2
2
|
import { FrameData } from '../generator';
|
|
3
3
|
import { LadonRenderer } from './ladon-renderer';
|
|
4
4
|
import { WebGLRenderer } from './webgl-renderer';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
5
|
+
export declare class PassthroughRenderer extends WebGLRenderer implements LadonRenderer {
|
|
6
|
+
output_canvas: HTMLCanvasElement;
|
|
7
|
+
readonly config: PipelineConfig;
|
|
8
|
+
private program;
|
|
9
|
+
private fragment_shader;
|
|
10
|
+
constructor(output_canvas: HTMLCanvasElement, config: PipelineConfig);
|
|
11
|
+
render(input: FrameData): Promise<void>;
|
|
12
|
+
load(): Promise<void>;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
@@ -2,18 +2,17 @@ import { PipelineConfig } from '../config-types';
|
|
|
2
2
|
import { FrameData, LadonOutput } from '../generator';
|
|
3
3
|
import { LadonRenderer } from './ladon-renderer';
|
|
4
4
|
import { WebGLRenderer } from './webgl-renderer';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
protected
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
protected
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
5
|
+
export declare class ReplacementRenderer extends WebGLRenderer implements LadonRenderer {
|
|
6
|
+
output_canvas: HTMLCanvasElement;
|
|
7
|
+
readonly config: PipelineConfig;
|
|
8
|
+
private program;
|
|
9
|
+
private background_canvas_ctx;
|
|
10
|
+
protected background_texture: WebGLTexture;
|
|
11
|
+
protected fragment_shader: string;
|
|
12
|
+
constructor(output_canvas: HTMLCanvasElement, config: PipelineConfig);
|
|
13
|
+
protected buildFragmentShader(): string;
|
|
14
|
+
protected setupBackgroundTexture(): void;
|
|
15
|
+
render(input: FrameData, mask?: LadonOutput): Promise<void>;
|
|
16
|
+
load(): Promise<void>;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { PipelineConfig } from '../config-types';
|
|
2
2
|
import { FrameData, LadonOutput } from '../generator';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
protected
|
|
9
|
-
protected
|
|
10
|
-
protected
|
|
11
|
-
protected
|
|
12
|
-
protected
|
|
13
|
-
protected
|
|
14
|
-
protected
|
|
15
|
-
protected
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
protected
|
|
19
|
-
protected
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
22
|
-
protected
|
|
23
|
-
protected
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
3
|
+
type TextureInitializer = () => void;
|
|
4
|
+
export declare abstract class WebGLRenderer {
|
|
5
|
+
output_canvas: HTMLCanvasElement;
|
|
6
|
+
readonly config: PipelineConfig;
|
|
7
|
+
protected intermediate_canvas?: HTMLCanvasElement;
|
|
8
|
+
protected output_canvas_2d?: CanvasRenderingContext2D;
|
|
9
|
+
protected gl: WebGL2RenderingContext;
|
|
10
|
+
protected image_texture: WebGLTexture;
|
|
11
|
+
protected mask_texture: WebGLTexture;
|
|
12
|
+
protected verts: Float32Array;
|
|
13
|
+
protected vertex_shader_src: string;
|
|
14
|
+
protected fragment_shader_header: string;
|
|
15
|
+
protected shared_shader_functions: string;
|
|
16
|
+
constructor(output_canvas: HTMLCanvasElement, config: PipelineConfig);
|
|
17
|
+
protected initTexturesAndBuffers(): void;
|
|
18
|
+
protected createTexture(internalFormat: number, width: number, height: number, initializeTexture?: TextureInitializer): WebGLTexture;
|
|
19
|
+
protected getUVCalculation(): "vec2 st = vec2(1.0 - gl_FragCoord.x / u_resolution.x, 1.0 - gl_FragCoord.y / u_resolution.y);" | "vec2 st = vec2(gl_FragCoord.x / u_resolution.x, 1.0 - gl_FragCoord.y / u_resolution.y);";
|
|
20
|
+
protected setSharedUniforms(program: WebGLProgram): void;
|
|
21
|
+
protected uploadVideoStream(input: FrameData): void;
|
|
22
|
+
protected uploadMask(mask?: LadonOutput): void;
|
|
23
|
+
protected postDraw(): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './renderer/blur-renderer';
|
|
2
|
-
export * from './renderer/ladon-renderer';
|
|
3
|
-
export * from './renderer/passthrough-renderer';
|
|
4
|
-
export * from './renderer/replacement-renderer';
|
|
5
|
-
export * from './renderer/webgl-renderer';
|
|
1
|
+
export * from './renderer/blur-renderer';
|
|
2
|
+
export * from './renderer/ladon-renderer';
|
|
3
|
+
export * from './renderer/passthrough-renderer';
|
|
4
|
+
export * from './renderer/replacement-renderer';
|
|
5
|
+
export * from './renderer/webgl-renderer';
|