@volorio/beauty-effect 0.2.0
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/README.md +7 -0
- package/dist/src/index.d.ts +37 -0
- package/dist/src/index.js +76 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { VolorioRoomClient } from "@volorio/rtc";
|
|
2
|
+
export declare const volorioBeautyEffectProductId = "beauty_effect";
|
|
3
|
+
export declare const volorioBeautyEffectSessionFeatures: {
|
|
4
|
+
readonly beautyEffect: true;
|
|
5
|
+
};
|
|
6
|
+
export interface VolorioBeautyEffectOptions {
|
|
7
|
+
smoothness?: number;
|
|
8
|
+
lightening?: number;
|
|
9
|
+
redness?: number;
|
|
10
|
+
sharpness?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface VolorioBeautyProcessor {
|
|
13
|
+
name?: string;
|
|
14
|
+
update?(options: VolorioBeautyEffectOptions): Promise<void> | void;
|
|
15
|
+
processFrame?(source: CanvasImageSource): HTMLCanvasElement | OffscreenCanvas;
|
|
16
|
+
}
|
|
17
|
+
export interface VolorioVideoTrackLike {
|
|
18
|
+
setProcessor(processor: VolorioBeautyProcessor): Promise<void>;
|
|
19
|
+
stopProcessor(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare class VolorioBeautyEffectExtension {
|
|
22
|
+
private readonly processorFactory;
|
|
23
|
+
constructor(processorFactory: (options: VolorioBeautyEffectOptions) => VolorioBeautyProcessor | Promise<VolorioBeautyProcessor>);
|
|
24
|
+
applyToTrack(track: VolorioVideoTrackLike, options?: VolorioBeautyEffectOptions): Promise<VolorioBeautyProcessor>;
|
|
25
|
+
clearTrack(track: VolorioVideoTrackLike): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class VolorioBeautyEffectProcessor implements VolorioBeautyProcessor {
|
|
28
|
+
readonly name = "volorio_beauty_effect";
|
|
29
|
+
private options;
|
|
30
|
+
private readonly canvas;
|
|
31
|
+
private readonly context;
|
|
32
|
+
constructor(options?: VolorioBeautyEffectOptions, canvas?: HTMLCanvasElement | OffscreenCanvas);
|
|
33
|
+
update(options: VolorioBeautyEffectOptions): void;
|
|
34
|
+
processFrame(source: CanvasImageSource): HTMLCanvasElement | OffscreenCanvas;
|
|
35
|
+
}
|
|
36
|
+
export declare function createVolorioBeautyEffectProcessor(options?: VolorioBeautyEffectOptions): VolorioBeautyEffectProcessor;
|
|
37
|
+
export type { VolorioRoomClient };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VolorioBeautyEffectProcessor = exports.VolorioBeautyEffectExtension = exports.volorioBeautyEffectSessionFeatures = exports.volorioBeautyEffectProductId = void 0;
|
|
4
|
+
exports.createVolorioBeautyEffectProcessor = createVolorioBeautyEffectProcessor;
|
|
5
|
+
exports.volorioBeautyEffectProductId = "beauty_effect";
|
|
6
|
+
exports.volorioBeautyEffectSessionFeatures = { beautyEffect: true };
|
|
7
|
+
class VolorioBeautyEffectExtension {
|
|
8
|
+
processorFactory;
|
|
9
|
+
constructor(processorFactory) {
|
|
10
|
+
this.processorFactory = processorFactory;
|
|
11
|
+
}
|
|
12
|
+
async applyToTrack(track, options = {}) {
|
|
13
|
+
const processor = await this.processorFactory(options);
|
|
14
|
+
await track.setProcessor(processor);
|
|
15
|
+
return processor;
|
|
16
|
+
}
|
|
17
|
+
async clearTrack(track) {
|
|
18
|
+
await track.stopProcessor();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.VolorioBeautyEffectExtension = VolorioBeautyEffectExtension;
|
|
22
|
+
class VolorioBeautyEffectProcessor {
|
|
23
|
+
name = "volorio_beauty_effect";
|
|
24
|
+
options;
|
|
25
|
+
canvas;
|
|
26
|
+
context;
|
|
27
|
+
constructor(options = {}, canvas = createCanvas(1280, 720)) {
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.canvas = canvas;
|
|
30
|
+
const context = canvas.getContext("2d");
|
|
31
|
+
if (context === null) {
|
|
32
|
+
throw new Error("Volorio beauty effect requires a 2D canvas context");
|
|
33
|
+
}
|
|
34
|
+
this.context = context;
|
|
35
|
+
}
|
|
36
|
+
update(options) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
}
|
|
39
|
+
processFrame(source) {
|
|
40
|
+
const size = readFrameSize(source);
|
|
41
|
+
this.canvas.width = size.width;
|
|
42
|
+
this.canvas.height = size.height;
|
|
43
|
+
const smoothness = Math.max(0, Math.min(1, this.options.smoothness ?? 0.35));
|
|
44
|
+
const lightening = Math.max(0, Math.min(1, this.options.lightening ?? 0.12));
|
|
45
|
+
const redness = Math.max(0, Math.min(1, this.options.redness ?? 0.05));
|
|
46
|
+
const sharpness = Math.max(0, Math.min(1, this.options.sharpness ?? 0.1));
|
|
47
|
+
this.context.filter = `blur(${smoothness * 1.8}px) brightness(${1 + lightening}) saturate(${1 + redness + sharpness})`;
|
|
48
|
+
this.context.drawImage(source, 0, 0, size.width, size.height);
|
|
49
|
+
this.context.filter = "none";
|
|
50
|
+
return this.canvas;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.VolorioBeautyEffectProcessor = VolorioBeautyEffectProcessor;
|
|
54
|
+
function createVolorioBeautyEffectProcessor(options = {}) {
|
|
55
|
+
return new VolorioBeautyEffectProcessor(options);
|
|
56
|
+
}
|
|
57
|
+
function createCanvas(width, height) {
|
|
58
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
59
|
+
return new OffscreenCanvas(width, height);
|
|
60
|
+
}
|
|
61
|
+
if (typeof document !== "undefined") {
|
|
62
|
+
const canvas = document.createElement("canvas");
|
|
63
|
+
canvas.width = width;
|
|
64
|
+
canvas.height = height;
|
|
65
|
+
return canvas;
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Volorio video processors require a browser canvas runtime");
|
|
68
|
+
}
|
|
69
|
+
function readFrameSize(source) {
|
|
70
|
+
const candidate = source;
|
|
71
|
+
return {
|
|
72
|
+
width: candidate.videoWidth ?? candidate.naturalWidth ?? (Number(candidate.width) || 1280),
|
|
73
|
+
height: candidate.videoHeight ?? candidate.naturalHeight ?? (Number(candidate.height) || 720),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAwEA,gFAEC;AAxEY,QAAA,4BAA4B,GAAG,eAAe,CAAC;AAC/C,QAAA,kCAAkC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAW,CAAC;AAoBlF,MAAa,4BAA4B;IACV;IAA7B,YAA6B,gBAAmH;QAAnH,qBAAgB,GAAhB,gBAAgB,CAAmG;IAAG,CAAC;IAEpJ,KAAK,CAAC,YAAY,CAAC,KAA4B,EAAE,UAAsC,EAAE;QACvF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACvD,MAAM,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACpC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAA4B;QAC3C,MAAM,KAAK,CAAC,aAAa,EAAE,CAAC;IAC9B,CAAC;CACF;AAZD,oEAYC;AAED,MAAa,4BAA4B;IAC9B,IAAI,GAAG,uBAAuB,CAAC;IAChC,OAAO,CAA6B;IAC3B,MAAM,CAAsC;IAC5C,OAAO,CAA+D;IAEvF,YAAY,UAAsC,EAAE,EAAE,SAA8C,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC;QACzH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC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2
|
+
"name": "@volorio/beauty-effect",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Volorio beauty effect extension for browser RTC video tracks.",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"types": "dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"default": "./dist/src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist/src", "README.md"],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"test": "pnpm build",
|
|
22
|
+
"pack:local": "pnpm build && npm pack --pack-destination dist"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@volorio/rtc": "^0.2.0"
|
|
26
|
+
}
|
|
27
|
+
}
|