@tradalab/mediakit 1.2.0 → 1.3.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/dist/NOTICE +22 -0
- package/dist/{chunk-V47SDU4L.js → chunk-WRKQ2NFI.js} +60 -5
- package/dist/chunk-WRKQ2NFI.js.map +1 -0
- package/dist/index.d.ts +64 -4
- package/dist/index.js +1239 -32
- package/dist/index.js.map +1 -1
- package/dist/mediakit.wasm +0 -0
- package/dist/recipe.d.ts +85 -1
- package/dist/recipe.js +9 -1
- package/dist/whiten_pink.png +0 -0
- package/dist/worker.js +190 -22
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-V47SDU4L.js.map +0 -1
package/dist/NOTICE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
whiten_pink.png
|
|
2
|
+
|
|
3
|
+
A colour lookup table baked from GPUPixel's skin-whitening chain - lookup_gray.png,
|
|
4
|
+
lookup_origin.png, lookup_skin.png and lookup_light.png, combined as in
|
|
5
|
+
src/filter/beauty_face_unit_filter.cc at whitening 0.35 - into mediakit's 512x512 LUT layout.
|
|
6
|
+
|
|
7
|
+
GPUPixel
|
|
8
|
+
Copyright 2021 PixPark
|
|
9
|
+
https://github.com/pixpark/gpupixel
|
|
10
|
+
|
|
11
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
12
|
+
in compliance with the License. You may obtain a copy of the License at
|
|
13
|
+
|
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
|
|
16
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
17
|
+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
18
|
+
or implied. See the License for the specific language governing permissions and limitations under
|
|
19
|
+
the License.
|
|
20
|
+
|
|
21
|
+
Changes: the four tables were combined into one, evaluated once per LUT entry with bilinear
|
|
22
|
+
sampling; nothing else.
|
|
@@ -16,8 +16,18 @@ var NO_EFFECTS = {
|
|
|
16
16
|
blushColor: [0.9, 0.5, 0.42],
|
|
17
17
|
iris: 0,
|
|
18
18
|
irisColor: [0.3, 0.5, 0.75],
|
|
19
|
+
eyeShadow: 0,
|
|
20
|
+
eyeShadowColor: [0.55, 0.42, 0.37],
|
|
21
|
+
lipGloss: 0,
|
|
22
|
+
rosy: 0,
|
|
23
|
+
rosyColor: [0.9, 0.42, 0.49],
|
|
24
|
+
whiten: 0,
|
|
25
|
+
skinLight: 0,
|
|
26
|
+
clarity: 0,
|
|
27
|
+
skinScope: "person",
|
|
19
28
|
lut: "",
|
|
20
29
|
grade: 0,
|
|
30
|
+
gradeScope: "frame",
|
|
21
31
|
chromaKey: false,
|
|
22
32
|
keyColor: [0, 0, 0],
|
|
23
33
|
keyTolerance: 0,
|
|
@@ -26,7 +36,18 @@ var NO_EFFECTS = {
|
|
|
26
36
|
slimFace: 0,
|
|
27
37
|
enlargeEyes: 0,
|
|
28
38
|
noseSlim: 0,
|
|
29
|
-
chin: 0
|
|
39
|
+
chin: 0,
|
|
40
|
+
jaw: 0,
|
|
41
|
+
cheekbone: 0,
|
|
42
|
+
forehead: 0,
|
|
43
|
+
brow: 0,
|
|
44
|
+
browColor: [0.36, 0.27, 0.22],
|
|
45
|
+
contour: 0,
|
|
46
|
+
highlight: 0,
|
|
47
|
+
makeupTexture: "",
|
|
48
|
+
makeup: 0,
|
|
49
|
+
makeupBlend: "softLight",
|
|
50
|
+
whitenStyle: "natural"
|
|
30
51
|
};
|
|
31
52
|
function touchUp(amount) {
|
|
32
53
|
const a = Math.min(1, Math.max(0, amount));
|
|
@@ -56,6 +77,9 @@ var MODE_NONE = 0;
|
|
|
56
77
|
var MODE_BLUR = 1;
|
|
57
78
|
var MODE_IMAGE = 2;
|
|
58
79
|
var MODE_CUTOUT = 3;
|
|
80
|
+
var SKIN_SCOPE = { person: 0, face: 1 };
|
|
81
|
+
var MAKEUP_BLEND = { softLight: 0, multiply: 1, overlay: 2, hardLight: 3, normal: 4 };
|
|
82
|
+
var GRADE_SCOPE = { frame: 0, person: 1, skin: 2 };
|
|
59
83
|
function backgroundMode(f) {
|
|
60
84
|
switch (f.kind) {
|
|
61
85
|
case "blur":
|
|
@@ -69,13 +93,20 @@ function backgroundMode(f) {
|
|
|
69
93
|
}
|
|
70
94
|
}
|
|
71
95
|
function needsMask(f, e) {
|
|
72
|
-
return f.kind !== "none" || e.beautify > 0 || e.autoframe;
|
|
96
|
+
return f.kind !== "none" || e.beautify > 0 || e.autoframe || hasSkin(e) || e.grade > 0 && (e.gradeScope ?? "frame") !== "frame";
|
|
97
|
+
}
|
|
98
|
+
function hasSkin(e) {
|
|
99
|
+
return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || (e.clarity ?? 0) > 0;
|
|
73
100
|
}
|
|
74
101
|
function needsSegmentation(f, e) {
|
|
75
102
|
return needsMask(f, e) && !e.chromaKey;
|
|
76
103
|
}
|
|
104
|
+
function needsSkinClasses(_f, e) {
|
|
105
|
+
return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || e.grade > 0 && (e.gradeScope ?? "frame") !== "frame";
|
|
106
|
+
}
|
|
77
107
|
function needsFace(e) {
|
|
78
|
-
return e.teeth > 0 || e.eyeBright > 0 || e.underEye > 0 || e.smileLines > 0 || e.lips > 0 || e.blush > 0 || e.iris > 0 || e.
|
|
108
|
+
return e.teeth > 0 || e.eyeBright > 0 || e.underEye > 0 || e.smileLines > 0 || e.lips > 0 || e.blush > 0 || e.iris > 0 || (e.eyeShadow ?? 0) > 0 || (e.lipGloss ?? 0) > 0 || (e.rosy ?? 0) > 0 || e.skinScope === "face" && (e.beautify > 0 || hasSkin(e)) || // Whitening and skin light measure skin on the face; clarity is held to it.
|
|
109
|
+
hasSkin(e) || e.grade > 0 && e.gradeScope === "skin" || e.slimFace > 0 || e.enlargeEyes > 0 || e.noseSlim > 0 || e.chin !== 0 || (e.jaw ?? 0) > 0 || (e.cheekbone ?? 0) > 0 || (e.forehead ?? 0) !== 0 || (e.brow ?? 0) > 0 || (e.contour ?? 0) > 0 || (e.highlight ?? 0) > 0 || (e.makeup ?? 0) > 0 && !!e.makeupTexture;
|
|
79
110
|
}
|
|
80
111
|
function coreRecipe(f, e) {
|
|
81
112
|
return {
|
|
@@ -97,7 +128,17 @@ function coreRecipe(f, e) {
|
|
|
97
128
|
blushColor: e.blushColor,
|
|
98
129
|
iris: e.iris,
|
|
99
130
|
irisColor: e.irisColor,
|
|
131
|
+
eyeShadow: e.eyeShadow ?? 0,
|
|
132
|
+
eyeShadowColor: e.eyeShadowColor ?? NO_EFFECTS.eyeShadowColor,
|
|
133
|
+
lipGloss: e.lipGloss ?? 0,
|
|
134
|
+
rosy: e.rosy ?? 0,
|
|
135
|
+
rosyColor: e.rosyColor ?? NO_EFFECTS.rosyColor,
|
|
136
|
+
whiten: e.whiten ?? 0,
|
|
137
|
+
skinLight: e.skinLight ?? 0,
|
|
138
|
+
clarity: e.clarity ?? 0,
|
|
139
|
+
skinScope: SKIN_SCOPE[e.skinScope] ?? 0,
|
|
100
140
|
grade: e.grade,
|
|
141
|
+
gradeScope: GRADE_SCOPE[e.gradeScope] ?? 0,
|
|
101
142
|
chromaKey: e.chromaKey,
|
|
102
143
|
keyColor: e.keyColor,
|
|
103
144
|
keyTolerance: e.keyTolerance,
|
|
@@ -106,7 +147,17 @@ function coreRecipe(f, e) {
|
|
|
106
147
|
slimFace: e.slimFace,
|
|
107
148
|
enlargeEyes: e.enlargeEyes,
|
|
108
149
|
noseSlim: e.noseSlim,
|
|
109
|
-
chin: e.chin
|
|
150
|
+
chin: e.chin,
|
|
151
|
+
jaw: e.jaw ?? 0,
|
|
152
|
+
cheekbone: e.cheekbone ?? 0,
|
|
153
|
+
forehead: e.forehead ?? 0,
|
|
154
|
+
brow: e.brow ?? 0,
|
|
155
|
+
browColor: e.browColor ?? NO_EFFECTS.browColor,
|
|
156
|
+
contour: e.contour ?? 0,
|
|
157
|
+
highlight: e.highlight ?? 0,
|
|
158
|
+
makeup: e.makeupTexture ? e.makeup ?? 0 : 0,
|
|
159
|
+
makeupBlend: MAKEUP_BLEND[e.makeupBlend] ?? 0,
|
|
160
|
+
whitenStyle: e.whitenStyle === "pink" ? 1 : 0
|
|
110
161
|
};
|
|
111
162
|
}
|
|
112
163
|
|
|
@@ -119,10 +170,14 @@ export {
|
|
|
119
170
|
MODE_BLUR,
|
|
120
171
|
MODE_IMAGE,
|
|
121
172
|
MODE_CUTOUT,
|
|
173
|
+
SKIN_SCOPE,
|
|
174
|
+
MAKEUP_BLEND,
|
|
175
|
+
GRADE_SCOPE,
|
|
122
176
|
backgroundMode,
|
|
123
177
|
needsMask,
|
|
124
178
|
needsSegmentation,
|
|
179
|
+
needsSkinClasses,
|
|
125
180
|
needsFace,
|
|
126
181
|
coreRecipe
|
|
127
182
|
};
|
|
128
|
-
//# sourceMappingURL=chunk-
|
|
183
|
+
//# sourceMappingURL=chunk-WRKQ2NFI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/recipe.ts"],"sourcesContent":["/**\n * The bridge between what the user picked and the recipe the Go core takes.\n *\n * Both halves live here because both map onto `core.Recipe` field for field: BgFilter carries\n * the background mode and its one parameter, Effects carries everything else. They are two\n * types rather than one because the UI edits them from two different places - a preset picker\n * and a slider panel - not because they belong to different layers.\n */\n\n/**\n * What replaces the background.\n *\n * `imagePath` is a URL the consuming app serves: a path under its own public root, or a data\n * URL for something the user uploaded. The Engine fetches it and cover-crops it to the frame\n * aspect, so any shape is safe to pass.\n */\nexport type BgFilter =\n | { kind: \"none\" }\n | { kind: \"blur\"; blurRadius: number }\n | { kind: \"image\"; imagePath: string }\n /**\n * The background becomes TRANSPARENT and the person stays: the output canvas carries the\n * mask as alpha. For a {@link Scene} to put the person over another source; a plain video\n * track has no alpha, so on its own this shows the person over black.\n */\n | { kind: \"cutout\" }\n\n/** A colour as red, green, blue, each 0..1. */\nexport type Rgb = [number, number, number]\n\n/** Where smoothing (`beautify`) may land. */\nexport type SkinScope = \"person\" | \"face\"\n\n/** Where the colour LUT lands. */\nexport type GradeScope = \"frame\" | \"person\" | \"skin\"\n\nexport interface Effects {\n /** Skin smoothing, 0..1. Needs the person mask, so it pulls in the segmentation cost. */\n beautify: number\n /** Exposure, -1..1. Positive lifts the shadows more than the highlights. */\n exposure: number\n /** Contrast, -1..1. */\n contrast: number\n /** Saturation, -1..1. */\n saturation: number\n /** Warm (positive) or cool (negative), -1..1. */\n warmth: number\n /** Keep the person framed. Needs the person mask. */\n autoframe: boolean\n\n // ── Need FACE landmarks ──────────────────────────────────────────────────────────\n /** Teeth whitening, 0..1. */\n teeth: number\n /** Brighten the whites of the eyes, 0..1. */\n eyeBright: number\n /** Reduce under-eye shadow, 0..1. */\n underEye: number\n /** Soften the nasolabial folds, 0..1. */\n smileLines: number\n\n /**\n * Makeup, 0..1 each, in its colour. Drawn against the full landmark mesh, so the lip tint\n * follows the lip line rather than an ellipse. Not offered in meet, like reshaping.\n */\n lips: number\n lipColor: Rgb\n blush: number\n blushColor: Rgb\n /** Iris colour: the ring only, clipped by the eyelids, the pupil left black. */\n iris: number\n irisColor: Rgb\n /** Eye shadow, 0..1, multiplied into the lower part of the lid-to-brow band. */\n eyeShadow: number\n eyeShadowColor: Rgb\n /** A white highlight across the middle of the lower lip, 0..1. Matte is 0. */\n lipGloss: number\n /** A faint flush over the whole face's skin, 0..1 - the face, where `blush` is the cheeks. */\n rosy: number\n rosyColor: Rgb\n\n // ── Skin, beside beautify.\n /** Lift and cool the skin, 0..1: brighter, less yellow. */\n whiten: number\n /**\n * How `whiten` whitens. `natural` relights the skin and cools its yellow, keeping its colour.\n * `pink` is the \"fair and rosy\" look East Asian beauty apps ship - GPUPixel's tuned skin\n * tables (Apache-2.0, see NOTICE), served as `/mediakit/whiten_pink.png`; it fades out on\n * darker skin, which those tables were not tuned for.\n */\n whitenStyle: \"natural\" | \"pink\"\n /** Exposure on the skin only. */\n skinLight: number\n /** Local contrast on the face. */\n clarity: number\n /** Where smoothing may land. See {@link SkinScope}. */\n skinScope: SkinScope\n\n /**\n * A colour LUT: `lut` is a URL the host serves (a 512x512 \"lookup\" PNG, 64 levels, 8x8 tiles,\n * row 0 at the top), `grade` how strongly it applies. \"\" means none.\n */\n lut: string\n grade: number\n /** Where the LUT lands. See {@link GradeScope}. */\n gradeScope: GradeScope\n\n /**\n * Take the person mask from a coloured screen instead of segmentation. Cheaper - MediaPipe\n * is never loaded - and the edge keeps hair the model loses. `keyColor` is the screen's\n * colour; [0, 0, 0] means \"find it\" from the frame's border. `keyTolerance` widens (+) or\n * narrows (-) what counts as screen, -1..1 around a tuned default.\n */\n chromaKey: boolean\n keyColor: Rgb\n keyTolerance: number\n\n /**\n * Lift exposure when the room is dark, on top of `exposure`. Only ever brightens. Needs no\n * detector: it reads the frame's own brightness.\n */\n autoLight: boolean\n\n /**\n * Flip the picture left to right, as a selfie preview shows it. Costs nothing on top of any\n * other effect; on its own it is one pass. Text on a whiteboard then reads backwards to\n * everyone watching, which is why it is a choice and not the default.\n */\n mirror: boolean\n\n /**\n * Jawline slimming, 0..1.\n *\n * Deliberately NOT offered in meet: Zoom, Google Meet and Teams all ship without face\n * reshaping, and in a work setting it reads as unserious. The field is here because the\n * second consumer of mediakit is slate, where reshaping is ordinary.\n */\n slimFace: number\n /** Eye enlargement, 0..1. Withheld from meet for the same reason as slimFace. */\n enlargeEyes: number\n /** Nose narrowing, 0..1. Withheld from meet like slimFace. */\n noseSlim: number\n /** Chin length, -1 (shorter) .. 1 (longer). Withheld from meet like slimFace. */\n chin: number\n /** Reshaping along the face's own outline. */\n jaw: number\n cheekbone: number\n forehead: number\n /** Brow fill, 0..1, multiplied in so the hairs show; lighter at the inner end. */\n brow: number\n browColor: Rgb\n /** Shading under the cheekbones, along the jaw and beside the nose, 0..1. */\n contour: number\n /** Light on the nose bridge, cheekbone tops, mid forehead and chin, 0..1. */\n highlight: number\n /** A look painted as an image on the canonical face. */\n makeupTexture: string\n makeup: number\n /** How the makeup texture blends: soft light (default), multiply, overlay, hard light, normal. */\n makeupBlend: \"softLight\" | \"multiply\" | \"overlay\" | \"hardLight\" | \"normal\"\n}\n\nexport const NO_EFFECTS: Effects = {\n beautify: 0,\n exposure: 0,\n contrast: 0,\n saturation: 0,\n warmth: 0,\n autoframe: false,\n teeth: 0,\n eyeBright: 0,\n underEye: 0,\n smileLines: 0,\n lips: 0,\n lipColor: [0.55, 0.18, 0.24],\n blush: 0,\n blushColor: [0.9, 0.5, 0.42],\n iris: 0,\n irisColor: [0.3, 0.5, 0.75],\n eyeShadow: 0,\n eyeShadowColor: [0.55, 0.42, 0.37],\n lipGloss: 0,\n rosy: 0,\n rosyColor: [0.9, 0.42, 0.49],\n whiten: 0,\n skinLight: 0,\n clarity: 0,\n skinScope: \"person\",\n lut: \"\",\n grade: 0,\n gradeScope: \"frame\",\n chromaKey: false,\n keyColor: [0, 0, 0],\n keyTolerance: 0,\n autoLight: false,\n mirror: false,\n slimFace: 0,\n enlargeEyes: 0,\n noseSlim: 0,\n chin: 0,\n jaw: 0,\n cheekbone: 0,\n forehead: 0,\n brow: 0,\n browColor: [0.36, 0.27, 0.22],\n contour: 0,\n highlight: 0,\n makeupTexture: \"\",\n makeup: 0,\n makeupBlend: \"softLight\",\n whitenStyle: \"natural\",\n}\n\n/**\n * One knob for \"look a little fresher\": skin, eyes, under-eyes, smile lines and teeth, moved\n * together in proportions tuned to read as rested rather than filtered at 1.\n *\n * A host that shows this instead of five sliders gets the shape Zoom and TikTok ship - people\n * reach for one control, not five, and five half-understood knobs mostly get set too high. The\n * ratios live here, next to the fields they drive, so every host means the same thing by it.\n */\nexport function touchUp(amount: number): Pick<Effects, \"beautify\" | \"eyeBright\" | \"underEye\" | \"smileLines\" | \"teeth\"> {\n const a = Math.min(1, Math.max(0, amount))\n return {\n beautify: a * TOUCH_UP.beautify,\n eyeBright: a * TOUCH_UP.eyeBright,\n underEye: a * TOUCH_UP.underEye,\n smileLines: a * TOUCH_UP.smileLines,\n teeth: a * TOUCH_UP.teeth,\n }\n}\n\n/** What `touchUp(1)` sets. Exported so a host can read a stored recipe back into one knob. */\nexport const TOUCH_UP = {\n beautify: 0.6,\n eyeBright: 0.5,\n underEye: 0.45,\n smileLines: 0.5,\n teeth: 0.4,\n} as const\n\n/**\n * The touch-up position a recipe corresponds to: the LARGEST of its five fields relative to\n * `touchUp(1)`. A recipe whose fields were set one by one has no single answer, and reading one\n * field only would show 0 for a recipe still whitening teeth - a knob at 0 that cannot turn off\n * what is running. Taking the largest, any effect still on shows, and moving the knob rewrites\n * all five consistently.\n */\nexport function touchUpAmount(e: Effects): number {\n let a = 0\n for (const k of Object.keys(TOUCH_UP) as (keyof typeof TOUCH_UP)[]) {\n a = Math.max(a, (e[k] ?? 0) / TOUCH_UP[k])\n }\n return Math.min(1, a)\n}\n\n/** Go-side `BackgroundMode`. Must match `core/recipe.go`. */\nexport const MODE_NONE = 0\nexport const MODE_BLUR = 1\nexport const MODE_IMAGE = 2\nexport const MODE_CUTOUT = 3\n\n/** Go-side `SkinScope` and `Scope`. Must match `core/recipe.go`. */\nexport const SKIN_SCOPE = { person: 0, face: 1 } as const\nexport const MAKEUP_BLEND = { softLight: 0, multiply: 1, overlay: 2, hardLight: 3, normal: 4 } as const\nexport const GRADE_SCOPE = { frame: 0, person: 1, skin: 2 } as const\n\nexport function backgroundMode(f: BgFilter): number {\n switch (f.kind) {\n case \"blur\":\n return MODE_BLUR\n case \"image\":\n return MODE_IMAGE\n case \"cutout\":\n return MODE_CUTOUT\n default:\n return MODE_NONE\n }\n}\n\n/**\n * Whether this recipe needs the person mask.\n *\n * Must match `Recipe.NeedsMask` on the Go side. This is the single biggest saving in the\n * module: a colour-only recipe skips MediaPipe entirely - the most expensive part of a frame,\n * and 9 MB of wasm the user then never downloads.\n *\n * The Go version is authoritative; this one exists so the JS side knows whether to load the\n * segmenter at all, BEFORE it can ask Go.\n */\nexport function needsMask(f: BgFilter, e: Effects): boolean {\n return (\n f.kind !== \"none\" ||\n e.beautify > 0 ||\n e.autoframe ||\n hasSkin(e) ||\n (e.grade > 0 && (e.gradeScope ?? \"frame\") !== \"frame\")\n )\n}\n\nfunction hasSkin(e: Effects): boolean {\n return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || (e.clarity ?? 0) > 0\n}\n\n/**\n * Whether this recipe needs the SEGMENTER: a mask, and not one a colour key already gives.\n * Must match `Recipe.NeedsSegmentation` on the Go side. This, not {@link needsMask}, decides\n * whether MediaPipe is loaded - with `chromaKey` on, its 9 MB are never fetched.\n */\nexport function needsSegmentation(f: BgFilter, e: Effects): boolean {\n return needsMask(f, e) && !e.chromaKey\n}\n\n/** Whether this recipe is better served by the multiclass segmenter. */\nexport function needsSkinClasses(_f: BgFilter, e: Effects): boolean {\n return (e.whiten ?? 0) > 0 || (e.skinLight ?? 0) > 0 || (e.grade > 0 && (e.gradeScope ?? \"frame\") !== \"frame\")\n}\n\n/**\n * Whether this recipe needs face landmarks.\n *\n * Must match `Recipe.NeedsFace` on the Go side. Split from {@link needsMask} because the two\n * detectors are independent costs, and the landmark model is 15 times the size of the\n * segmentation one - making someone who only wants a blurred background download it is waste\n * that shows up on the first load.\n */\nexport function needsFace(e: Effects): boolean {\n return (\n e.teeth > 0 ||\n e.eyeBright > 0 ||\n e.underEye > 0 ||\n e.smileLines > 0 ||\n e.lips > 0 ||\n e.blush > 0 ||\n e.iris > 0 ||\n (e.eyeShadow ?? 0) > 0 ||\n (e.lipGloss ?? 0) > 0 ||\n (e.rosy ?? 0) > 0 ||\n (e.skinScope === \"face\" && (e.beautify > 0 || hasSkin(e))) ||\n // Whitening and skin light measure skin on the face; clarity is held to it.\n hasSkin(e) ||\n (e.grade > 0 && e.gradeScope === \"skin\") ||\n e.slimFace > 0 ||\n e.enlargeEyes > 0 ||\n e.noseSlim > 0 ||\n e.chin !== 0 ||\n (e.jaw ?? 0) > 0 ||\n (e.cheekbone ?? 0) > 0 ||\n (e.forehead ?? 0) !== 0 ||\n (e.brow ?? 0) > 0 ||\n (e.contour ?? 0) > 0 ||\n (e.highlight ?? 0) > 0 ||\n ((e.makeup ?? 0) > 0 && !!e.makeupTexture)\n )\n}\n\n/** The recipe in the shape the Go core takes. Field names must match `setRecipe` in wasmjs/main.go. */\nexport interface CoreRecipe {\n background: number\n blurRadius: number\n beautify: number\n exposure: number\n contrast: number\n saturation: number\n warmth: number\n autoframe: boolean\n teeth: number\n eyeBright: number\n underEye: number\n smileLines: number\n lips: number\n lipColor: Rgb\n blush: number\n blushColor: Rgb\n iris: number\n irisColor: Rgb\n eyeShadow: number\n eyeShadowColor: Rgb\n lipGloss: number\n rosy: number\n rosyColor: Rgb\n whiten: number\n skinLight: number\n clarity: number\n skinScope: number\n grade: number\n gradeScope: number\n chromaKey: boolean\n keyColor: Rgb\n keyTolerance: number\n autoLight: boolean\n mirror: boolean\n slimFace: number\n enlargeEyes: number\n noseSlim: number\n chin: number\n jaw: number\n cheekbone: number\n forehead: number\n brow: number\n browColor: Rgb\n contour: number\n highlight: number\n makeup: number\n makeupBlend: number\n whitenStyle: number\n}\n\nexport function coreRecipe(f: BgFilter, e: Effects): CoreRecipe {\n return {\n background: backgroundMode(f),\n blurRadius: f.kind === \"blur\" ? f.blurRadius : 0,\n beautify: e.beautify,\n exposure: e.exposure,\n contrast: e.contrast,\n saturation: e.saturation,\n warmth: e.warmth,\n autoframe: e.autoframe,\n teeth: e.teeth,\n eyeBright: e.eyeBright,\n underEye: e.underEye,\n smileLines: e.smileLines,\n lips: e.lips,\n lipColor: e.lipColor,\n blush: e.blush,\n blushColor: e.blushColor,\n iris: e.iris,\n irisColor: e.irisColor,\n eyeShadow: e.eyeShadow ?? 0,\n eyeShadowColor: e.eyeShadowColor ?? NO_EFFECTS.eyeShadowColor,\n lipGloss: e.lipGloss ?? 0,\n rosy: e.rosy ?? 0,\n rosyColor: e.rosyColor ?? NO_EFFECTS.rosyColor,\n whiten: e.whiten ?? 0,\n skinLight: e.skinLight ?? 0,\n clarity: e.clarity ?? 0,\n skinScope: SKIN_SCOPE[e.skinScope] ?? 0,\n grade: e.grade,\n gradeScope: GRADE_SCOPE[e.gradeScope] ?? 0,\n chromaKey: e.chromaKey,\n keyColor: e.keyColor,\n keyTolerance: e.keyTolerance,\n autoLight: e.autoLight,\n mirror: e.mirror,\n slimFace: e.slimFace,\n enlargeEyes: e.enlargeEyes,\n noseSlim: e.noseSlim,\n chin: e.chin,\n jaw: e.jaw ?? 0,\n cheekbone: e.cheekbone ?? 0,\n forehead: e.forehead ?? 0,\n brow: e.brow ?? 0,\n browColor: e.browColor ?? NO_EFFECTS.browColor,\n contour: e.contour ?? 0,\n highlight: e.highlight ?? 0,\n makeup: e.makeupTexture ? (e.makeup ?? 0) : 0,\n makeupBlend: MAKEUP_BLEND[e.makeupBlend] ?? 0,\n whitenStyle: e.whitenStyle === \"pink\" ? 1 : 0,\n }\n}\n"],"mappings":";AAiKO,IAAM,aAAsB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,UAAU,CAAC,MAAM,MAAM,IAAI;AAAA,EAC3B,OAAO;AAAA,EACP,YAAY,CAAC,KAAK,KAAK,IAAI;AAAA,EAC3B,MAAM;AAAA,EACN,WAAW,CAAC,KAAK,KAAK,IAAI;AAAA,EAC1B,WAAW;AAAA,EACX,gBAAgB,CAAC,MAAM,MAAM,IAAI;AAAA,EACjC,UAAU;AAAA,EACV,MAAM;AAAA,EACN,WAAW,CAAC,KAAK,MAAM,IAAI;AAAA,EAC3B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,KAAK;AAAA,EACL,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAA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MAAM,EAAE,QAAQ;AAAA,IAChB,WAAW,EAAE,aAAa,WAAW;AAAA,IACrC,SAAS,EAAE,WAAW;AAAA,IACtB,WAAW,EAAE,aAAa;AAAA,IAC1B,QAAQ,EAAE,gBAAiB,EAAE,UAAU,IAAK;AAAA,IAC5C,aAAa,aAAa,EAAE,WAAW,KAAK;AAAA,IAC5C,aAAa,EAAE,gBAAgB,SAAS,IAAI;AAAA,EAChD;AACJ;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,10 @@ declare class Engine {
|
|
|
49
49
|
private backgroundPath;
|
|
50
50
|
/** The LUT the core holds, by path, so a slider drag does not decode it again. */
|
|
51
51
|
private lutPath;
|
|
52
|
+
/** The makeup texture the core holds, by path - see setRecipe. */
|
|
53
|
+
private makeupPath;
|
|
54
|
+
/** Whether the core holds the pink whitening table. */
|
|
55
|
+
private skinLutState;
|
|
52
56
|
private closed;
|
|
53
57
|
/**
|
|
54
58
|
* The segmenter loads LAZILY - only once a recipe actually needs a person mask.
|
|
@@ -58,6 +62,11 @@ declare class Engine {
|
|
|
58
62
|
*/
|
|
59
63
|
private segmenter;
|
|
60
64
|
private segmenterLoading;
|
|
65
|
+
/** The multiclass segmenter, for recipes that tell skin from clothes (`needsSkinClasses`). */
|
|
66
|
+
private classSegmenter;
|
|
67
|
+
private classLoading;
|
|
68
|
+
/** The segmenter whose result this frame borrowed, to give it back after process(). */
|
|
69
|
+
private used;
|
|
61
70
|
/**
|
|
62
71
|
* The landmark detector, also lazy and independent of the segmenter.
|
|
63
72
|
*
|
|
@@ -74,13 +83,14 @@ declare class Engine {
|
|
|
74
83
|
last: FrameStats;
|
|
75
84
|
private constructor();
|
|
76
85
|
/** Main thread: makes its own canvas. A worker calls `on` with an OffscreenCanvas. */
|
|
77
|
-
static create(width: number, height: number, filter: BgFilter, effects?: Effects): Promise<Engine>;
|
|
86
|
+
static create(width: number, height: number, filter: BgFilter, effects?: Effects, alpha?: boolean): Promise<Engine>;
|
|
78
87
|
/**
|
|
79
88
|
* `background`: see {@link Engine.setRecipe}. `alpha` keeps the output's alpha channel, which
|
|
80
89
|
* only a `cutout` background writes; it is fixed for the life of the context, so a host that
|
|
81
90
|
* may switch to `cutout` later has to ask for it here.
|
|
82
91
|
*/
|
|
83
92
|
static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects, background?: ImageBitmap, alpha?: boolean): Promise<Engine>;
|
|
93
|
+
get loading(): boolean;
|
|
84
94
|
get outputCanvas(): EngineCanvas;
|
|
85
95
|
/**
|
|
86
96
|
* Change the recipe without rebuilding the pipeline, so dragging a slider does not flash.
|
|
@@ -91,6 +101,7 @@ declare class Engine {
|
|
|
91
101
|
*/
|
|
92
102
|
setRecipe(filter: BgFilter, effects?: Effects, background?: ImageBitmap): Promise<void>;
|
|
93
103
|
private ensureFace;
|
|
104
|
+
private ensureClassSegmenter;
|
|
94
105
|
private ensureSegmenter;
|
|
95
106
|
/**
|
|
96
107
|
* Draw one source frame onto the output canvas. `false` means nothing was drawn - no mask
|
|
@@ -115,7 +126,7 @@ declare class Engine {
|
|
|
115
126
|
* for the governor and the graph to decide with. See the ToMicros comment in
|
|
116
127
|
* `core/clock.go`.
|
|
117
128
|
*/
|
|
118
|
-
capture(timestampUs: number): VideoFrame;
|
|
129
|
+
capture(timestampUs: number, keepAlpha?: boolean): VideoFrame;
|
|
119
130
|
close(): void;
|
|
120
131
|
}
|
|
121
132
|
|
|
@@ -146,12 +157,43 @@ declare class Engine {
|
|
|
146
157
|
* 3. No WebCodecs needed: the `<video>` element goes straight into `texImage2D`.
|
|
147
158
|
*/
|
|
148
159
|
type Transport = "worker" | "insertable" | "canvas";
|
|
160
|
+
interface PipelineOptions {
|
|
161
|
+
/** Keep the output's alpha channel, for `subscribeFrames` with a `cutout` background. */
|
|
162
|
+
alpha?: boolean;
|
|
163
|
+
/** No processed frame for 2 s while the camera is live (20 s while a detector loads). */
|
|
164
|
+
onStall?: (info: {
|
|
165
|
+
transport: Transport;
|
|
166
|
+
sinceMs: number;
|
|
167
|
+
}) => void;
|
|
168
|
+
/** The pipeline replaced `processedTrack` mid-session. */
|
|
169
|
+
onTrackReplaced?: (track: MediaStreamTrack, previous: MediaStreamTrack | undefined) => void;
|
|
170
|
+
}
|
|
171
|
+
/** What `health` reports. */
|
|
172
|
+
interface PipelineHealth {
|
|
173
|
+
transport: Transport;
|
|
174
|
+
/** Frames out since start, or since the last transport change. */
|
|
175
|
+
frames: number;
|
|
176
|
+
/** Milliseconds since a frame last came out. */
|
|
177
|
+
sinceMs: number;
|
|
178
|
+
stalled: boolean;
|
|
179
|
+
}
|
|
149
180
|
/** Whether mediakit can run in this browser at all. */
|
|
150
181
|
declare function mediakitSupported(): boolean;
|
|
151
182
|
declare class VideoPipeline {
|
|
152
183
|
processedTrack?: MediaStreamTrack;
|
|
153
184
|
private filter;
|
|
154
185
|
private effects;
|
|
186
|
+
private opts;
|
|
187
|
+
private source;
|
|
188
|
+
private size;
|
|
189
|
+
private lastBeat;
|
|
190
|
+
private frames;
|
|
191
|
+
private stalled;
|
|
192
|
+
private watchdog;
|
|
193
|
+
private movedOff;
|
|
194
|
+
/** What the worker last said about loading detectors. */
|
|
195
|
+
private workerLoading;
|
|
196
|
+
private frameSubs;
|
|
155
197
|
private engine;
|
|
156
198
|
private transport;
|
|
157
199
|
private abort;
|
|
@@ -162,11 +204,22 @@ declare class VideoPipeline {
|
|
|
162
204
|
private video;
|
|
163
205
|
private rvfcHandle;
|
|
164
206
|
private stopped;
|
|
165
|
-
constructor(filter: BgFilter, effects?: Effects);
|
|
207
|
+
constructor(filter: BgFilter, effects?: Effects, opts?: PipelineOptions);
|
|
208
|
+
/** Whether frames are coming out, and how long since the last one. */
|
|
209
|
+
get health(): PipelineHealth;
|
|
210
|
+
/** Every processed frame. */
|
|
211
|
+
subscribeFrames(cb: (frame: VideoFrame) => void): () => void;
|
|
212
|
+
private deliver;
|
|
213
|
+
private beat;
|
|
214
|
+
private startWatchdog;
|
|
215
|
+
private stopWatchdog;
|
|
216
|
+
/** The worker failed or stalled AFTER the host published its track. */
|
|
217
|
+
private moveOffWorker;
|
|
166
218
|
get stats(): FrameStats | null;
|
|
167
219
|
get transportName(): Transport;
|
|
168
220
|
/** Take over `source` and publish the result on {@link processedTrack}. */
|
|
169
221
|
start(source: MediaStreamTrack): Promise<void>;
|
|
222
|
+
private startMain;
|
|
170
223
|
/** Swap the background in place - no pipeline rebuild, so the picture does not flash. */
|
|
171
224
|
switchTo(filter: BgFilter): Promise<void>;
|
|
172
225
|
/** Change the effects outside the background. */
|
|
@@ -209,6 +262,10 @@ declare class VideoPipeline {
|
|
|
209
262
|
* not get this path and stays on the canvas transport until someone can test that.
|
|
210
263
|
*/
|
|
211
264
|
private startWorker;
|
|
265
|
+
/** Safari's dialect (see `startTrack` in worker/entry.ts). */
|
|
266
|
+
private startWorkerWithTrack;
|
|
267
|
+
/** Starts the worker and waits for its "ready". */
|
|
268
|
+
private attachWorker;
|
|
212
269
|
private startInsertable;
|
|
213
270
|
private startCanvas;
|
|
214
271
|
}
|
|
@@ -355,4 +412,7 @@ declare class Scene {
|
|
|
355
412
|
/** Draw text onto its own canvas, sized to fit it. */
|
|
356
413
|
declare function renderText(text: string, style?: TextStyle): HTMLCanvasElement;
|
|
357
414
|
|
|
358
|
-
|
|
415
|
+
/** Where each of the face landmarker's first 468 landmarks lies on the canonical face texture. */
|
|
416
|
+
declare const FACE_UV: Float32Array<ArrayBuffer>;
|
|
417
|
+
|
|
418
|
+
export { BgFilter, Color, Effects, Engine, type EngineCanvas, FACE_UV, type FrameStats, type PipelineHealth, type PipelineOptions, Scene, SceneLayer, type SceneOptions, type SceneSource, type SceneStats, type TextStyle, TransitionKind, type Transport, VideoPipeline, mediakitSupported, renderText };
|