@snovakow/greenscreen 0.0.0-stage → 0.6.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/LICENSE +21 -0
- package/README.md +239 -2
- package/dist/greenscreen.d.ts +32 -0
- package/dist/greenscreen.d.ts.map +1 -0
- package/dist/greenscreen.global.js +350 -0
- package/dist/greenscreen.global.js.map +1 -0
- package/dist/greenscreen.js +250 -0
- package/dist/greenscreen.js.map +1 -0
- package/dist/greenscreen.min.js +350 -0
- package/dist/greenscreen.min.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/pack.d.ts +7 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +63 -0
- package/dist/pack.js.map +1 -0
- package/dist/react.d.ts +26 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +78 -0
- package/dist/react.js.map +1 -0
- package/dist/renderer.d.ts +19 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +25 -0
- package/dist/renderer.js.map +1 -0
- package/dist/settings.d.ts +36 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +112 -0
- package/dist/settings.js.map +1 -0
- package/dist/shader.glsl.d.ts +3 -0
- package/dist/shader.glsl.d.ts.map +1 -0
- package/dist/shader.glsl.js +199 -0
- package/dist/shader.glsl.js.map +1 -0
- package/dist/shader.wgsl.d.ts +2 -0
- package/dist/shader.wgsl.d.ts.map +1 -0
- package/dist/shader.wgsl.js +177 -0
- package/dist/shader.wgsl.js.map +1 -0
- package/dist/source.d.ts +16 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +103 -0
- package/dist/source.js.map +1 -0
- package/dist/three-webgpu.d.ts +20 -0
- package/dist/three-webgpu.d.ts.map +1 -0
- package/dist/three-webgpu.js +193 -0
- package/dist/three-webgpu.js.map +1 -0
- package/dist/three.d.ts +27 -0
- package/dist/three.d.ts.map +1 -0
- package/dist/three.js +81 -0
- package/dist/three.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/webgl.d.ts +13 -0
- package/dist/webgl.d.ts.map +1 -0
- package/dist/webgl.js +183 -0
- package/dist/webgl.js.map +1 -0
- package/dist/webgpu.d.ts +19 -0
- package/dist/webgpu.d.ts.map +1 -0
- package/dist/webgpu.js +303 -0
- package/dist/webgpu.js.map +1 -0
- package/package.json +103 -4
- package/src/global.ts +11 -0
- package/src/greenscreen.ts +286 -0
- package/src/index.ts +5 -0
- package/src/pack.ts +73 -0
- package/src/react.tsx +126 -0
- package/src/renderer.ts +53 -0
- package/src/settings.ts +179 -0
- package/src/shader.glsl.ts +199 -0
- package/src/shader.wgsl.ts +176 -0
- package/src/source.ts +105 -0
- package/src/three-webgpu.ts +279 -0
- package/src/three.ts +114 -0
- package/src/types.ts +10 -0
- package/src/webgl.ts +191 -0
- package/src/webgpu.ts +312 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greenscreen.min.js","names":["CB","CR","pack","r","g","b","channels","settings","out","gamma","contrast","tint","toLinear","i","corner","hex","c","RANGES","KEY_COLORS","WHOLE","DEFAULT_SETTINGS","NUMBERS","WHOLE_NUMBERS","mergeSettings","next","base","patch","flag","colour","corners","name","value","number","clamp","x","low","high","clamped","point","y","STALLED","sizeOf","source","warnUnkeyable","error","Feed","#watch","video","#disposed","#handle","#fresh","#lastFrame","width","height","#time","#src","#failedOn","what","first","tooLarge","backend","limit","contextOf","context","canvas","id","options","FRAGMENT","VERTEX","ATTRIBUTES","WebGLRenderer","gl","#canvas","#gl","#events","events","#onLost","#onRestored","#build","#lost","program","vertex","compile","fragment","#program","#settings","texture","#texture","#width","#height","texture2D","viewport","sides","#limit","side","#straight","#bitmaps","event","shader","type","SHADER","TEXTURE_RENDER_ATTACHMENT","shared","current","preferred","known","requestDevice","attempt","adapter","given","requestAdapter","device","currentDevice","gpu","prefersWebGPU","webgpu","knownPreference","pipelines","pipelineFor","byFormat","made","format","module","preferredFormat","WebGPURenderer","surface","output","#output","#surface","#context","#device","#pipeline","#uniforms","#bindGroup","#asDrawn","#videos","stagingCanvas","bindGroup","encoder","pass","FALLBACK_INTERVAL","Greenscreen","createCanvas","#onError","#initialize","choice","#useWebGL","#useWebGPU","#renderer","start","#ready","#uploaded","#feed","#dirty","#frame","packed","#scratch","#packed","renderer","feed","draw","#loop","handle","step","schedule","unschedule","warmUp"],"sources":["../src/pack.ts","../src/settings.ts","../src/source.ts","../src/renderer.ts","../src/shader.glsl.ts","../src/webgl.ts","../src/shader.wgsl.ts","../src/webgpu.ts","../src/greenscreen.ts"],"sourcesContent":["import type { Settings } from './settings.ts'\n\n// The settings as the shaders read them: eight sets of four numbers, a vec4 array in GLSL and a struct of vec4s in\n// WGSL. Every shader works from these, so none of them can come to mean a setting differently. The first three hold\n// what OBS's filter works from, worked out from the settings as OBS works it out; the rest are the add-ons' and the\n// renderers'\n// 0 key: its Cb and Cr, 1 / its chroma's distance from grey for hueSpill, the filter on\n// 1 matte: similarity, smoothness and spill, each a thousandth of its setting, and opacity\n// 2 correction: gamma's exponent, contrast's factor, brightness, unused\n// 3 add-ons: tint's r, g and b in linear light, saturation\n// 4 flags: flip, texture's rows bottom up, output linear, texture linear. The last three are the renderer's own\n// 5 corners 0 and 1\n// 6 corners 2 and 3\n// 7 switches: crop on, hueSpill on, unused\nexport const PACKED_LENGTH = 32\n\n// A colour's Cb and Cr from its sRGB values, as OBS's filter has them: BT.709's, in studio range\nexport const CB = [-0.100644, -0.338572, 0.439216, 0.501961] as const\nexport const CR = [0.439216, -0.398942, -0.040274, 0.501961] as const\n\n// Into out, which is PACKED_LENGTH long, and returned\nexport function pack<T extends Float32Array>(settings: Readonly<Settings>, out: T): T {\n // The key's chroma comes from its own sRGB values, as OBS takes them from the colour chosen\n const [r, g, b] = channels(settings.keyColor)\n out[0] = CB[0] * r + CB[1] * g + CB[2] * b + CB[3]\n out[1] = CR[0] * r + CR[1] * g + CR[2] * b + CR[3]\n // For hueSpill, the key's direction from grey, scaled to 1. A key on grey has none, and takes nothing out\n out[2] = 1 / Math.max(Math.hypot(out[0] - CB[3], out[1] - CR[3]), 1e-3)\n out[3] = settings.key ? 1 : 0\n\n out[4] = settings.similarity / 1000\n out[5] = settings.smoothness / 1000\n out[6] = settings.spill / 1000\n out[7] = settings.opacity\n\n // An exponent from 2 down to 1/2, and a factor from 1/5 up to 5, each 1 for no change, as OBS makes them\n const { gamma, contrast } = settings\n out[8] = gamma < 0 ? 1 - gamma : 1 / (1 + gamma)\n out[9] = contrast < 0 ? 1 / (1 - contrast) : 1 + contrast\n out[10] = settings.brightness\n out[11] = 0\n\n // The tint multiplies linear colour, so it's made linear too\n const tint = channels(settings.tint)\n out[12] = toLinear(tint[0])\n out[13] = toLinear(tint[1])\n out[14] = toLinear(tint[2])\n out[15] = settings.saturation\n\n out[16] = settings.flip ? 1 : 0\n out[17] = 0\n out[18] = 0\n out[19] = 0\n\n settings.corners.forEach((corner, i) => {\n out[20 + i * 2] = corner.x\n out[21 + i * 2] = corner.y\n })\n out[28] = settings.crop ? 1 : 0\n out[29] = settings.hueSpill ? 1 : 0\n out.fill(0, 30)\n return out\n}\n\n// A 0xrrggbb colour's channels, 0 to 1\nexport function channels(hex: number): [number, number, number] {\n return [((hex >> 16) & 0xff) / 255, ((hex >> 8) & 0xff) / 255, (hex & 0xff) / 255]\n}\n\n// sRGB's value to linear light\nfunction toLinear(c: number): number {\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n}\n","// What the keyer does to a picture, and how that's packed into the numbers each of its shaders reads\n\n// A point on the picture: 0 to 1 across it from the left, and 0 to 1 down it from the top\nexport interface Point {\n x: number\n y: number\n}\n\n// The keyer keys as OBS Studio's chroma key filter does, the filter's second version, and takes its settings in OBS's\n// units, ranges and defaults, so a filter's numbers can be copied from OBS as they are. The add-ons are the library's\n// own, and not in OBS. At their defaults they change nothing, and the picture is keyed exactly as OBS keys it\n// https://github.com/obsproject/obs-studio/blob/master/plugins/obs-filters/chroma-key-filter.c\nexport interface Settings {\n // OBS's chroma key filter\n\n // Whether the filter runs, as its eye in OBS's list of filters. Off, the picture passes through it as it came, and\n // only the add-ons apply\n key: boolean\n // OBS's Key Color, as 0xrrggbb. KEY_COLORS has OBS's Green, Blue and Magenta. Any other colour is OBS's Custom Color\n keyColor: number\n // OBS's Similarity, 1 to 1000: how near the key a colour's chroma must be to be taken out\n similarity: number\n // OBS's Smoothness, 1 to 1000: how far past similarity a colour fades back in\n smoothness: number\n // OBS's Key Color Spill Reduction, 1 to 1000: how far past similarity a colour kept is desaturated, which takes the\n // key's cast off edges and hair\n spill: number\n // OBS's Opacity, 0 to 1\n opacity: number\n // OBS's Contrast, −4 to 4: a factor from 1/5 to 5, 0 for no change\n contrast: number\n // OBS's Brightness, −1 to 1, added: 0 for no change\n brightness: number\n // OBS's Gamma, −1 to 1: an exponent from 2 to 1/2, 0 for no change\n gamma: number\n\n // Add-ons: the library's own, not OBS's. Flip and crop act on the picture OBS's filter gives. Tint, saturation and\n // hueSpill act inside the filter, between its steps or in place of one\n\n // Spill takes out only the key's hue, keeping each colour's luma and its other hues, where OBS's spill desaturates\n // the whole colour. It reaches as far as spill does, and takes as much of the key's hue out as OBS would of the colour\n hueSpill: boolean\n // Mirrors the picture left to right\n flip: boolean\n // Cuts the picture down to the shape its corners make\n crop: boolean\n // The cut's four corners, clockwise from the top left, in the picture's own coordinates: not mirrored by flip. The\n // shape they make must be convex. They're kept while crop is off\n corners: readonly Readonly<Point>[]\n // Multiplies the picture's colour, as 0xrrggbb: white for no change. It acts once the key's distance is measured, so\n // it doesn't change what's keyed, and before spill and gamma, contrast and brightness\n tint: number\n // Scales the colour's HSB saturation, keeping its hue and its brightest channel, after tint and before spill: 0 for\n // the grey of that channel, 1 for no change, up to 2. No colour goes past full saturation\n saturation: number\n}\n\nexport type NumericSetting = 'similarity' | 'smoothness' | 'spill' | 'opacity' | 'contrast' | 'brightness' | 'gamma' | 'saturation'\n\nexport interface Range {\n readonly min: number\n readonly max: number\n // The step OBS's slider moves in, or the add-on's. Values between steps are kept as they are, except similarity's,\n // smoothness's and spill's, which OBS keeps as whole numbers, and which are rounded to them\n readonly step: number\n}\n\n// Each number's limits, for a control panel to use: OBS's sliders', and the add-on's. Values outside them are clamped\nexport const RANGES: Readonly<Record<NumericSetting, Range>> = Object.freeze({\n similarity: { min: 1, max: 1000, step: 1 },\n smoothness: { min: 1, max: 1000, step: 1 },\n spill: { min: 1, max: 1000, step: 1 },\n opacity: { min: 0, max: 1, step: 0.0001 },\n contrast: { min: -4, max: 4, step: 0.01 },\n brightness: { min: -1, max: 1, step: 0.0001 },\n gamma: { min: -1, max: 1, step: 0.01 },\n saturation: { min: 0, max: 2, step: 0.01 },\n})\n\n// OBS's Green, Blue and Magenta. OBS writes its blue as 0xFF9900, as it keeps colours as 0xbbggrr\nexport const KEY_COLORS: Readonly<{ green: number; blue: number; magenta: number }> = Object.freeze({\n green: 0x00ff00,\n blue: 0x0099ff,\n magenta: 0xff00ff,\n})\n\n// The whole picture, which is where the cut starts\nconst WHOLE: readonly Readonly<Point>[] = Object.freeze([\n Object.freeze({ x: 0, y: 0 }),\n Object.freeze({ x: 1, y: 0 }),\n Object.freeze({ x: 1, y: 1 }),\n Object.freeze({ x: 0, y: 1 }),\n])\n\n// OBS's defaults for its filter, with the add-ons changing nothing\nexport const DEFAULT_SETTINGS: Readonly<Settings> = Object.freeze({\n key: true,\n keyColor: KEY_COLORS.green,\n similarity: 400,\n smoothness: 80,\n spill: 100,\n opacity: 1,\n contrast: 0,\n brightness: 0,\n gamma: 0,\n hueSpill: false,\n flip: false,\n crop: false,\n corners: WHOLE,\n tint: 0xffffff,\n saturation: 1,\n})\n\nconst NUMBERS: readonly NumericSetting[] = [\n 'similarity',\n 'smoothness',\n 'spill',\n 'opacity',\n 'contrast',\n 'brightness',\n 'gamma',\n 'saturation',\n]\n\n// The numbers OBS keeps as whole numbers, as its sliders for them move in whole steps and it stores them as integers\nconst WHOLE_NUMBERS: ReadonlySet<NumericSetting> = new Set(['similarity', 'smoothness', 'spill'])\n\n// The settings with the patch's changes made, as a new frozen object. A value that's undefined leaves the setting as\n// it was, and a name that isn't a setting is passed over, so an app's own object of settings can be given as it is.\n// A value of the wrong kind throws, so a mistake shows where it's made\nexport function mergeSettings(base: Readonly<Settings>, patch: Readonly<Partial<Settings>>): Readonly<Settings> {\n const next: Settings = { ...base }\n if (patch.key !== undefined) next.key = flag('key', patch.key)\n if (patch.hueSpill !== undefined) next.hueSpill = flag('hueSpill', patch.hueSpill)\n if (patch.flip !== undefined) next.flip = flag('flip', patch.flip)\n if (patch.crop !== undefined) next.crop = flag('crop', patch.crop)\n if (patch.keyColor !== undefined) next.keyColor = colour('keyColor', patch.keyColor)\n if (patch.tint !== undefined) next.tint = colour('tint', patch.tint)\n if (patch.corners !== undefined) next.corners = corners(patch.corners)\n for (const name of NUMBERS) {\n const value = patch[name]\n if (value !== undefined) next[name] = number(name, value)\n }\n return Object.freeze(next)\n}\n\nconst clamp = (x: number, low: number, high: number) => Math.min(Math.max(x, low), high)\n\nfunction flag(name: string, value: unknown): boolean {\n if (typeof value !== 'boolean') throw new TypeError(`Greenscreen: ${name} must be true or false`)\n return value\n}\n\nfunction colour(name: string, value: unknown): number {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > 0xffffff) {\n throw new TypeError(`Greenscreen: ${name} must be a colour from 0x000000 to 0xffffff`)\n }\n return value\n}\n\nfunction number(name: NumericSetting, value: unknown): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) throw new TypeError(`Greenscreen: ${name} must be a number`)\n const clamped = clamp(value, RANGES[name].min, RANGES[name].max)\n return WHOLE_NUMBERS.has(name) ? Math.round(clamped) : clamped\n}\n\nfunction corners(value: unknown): readonly Readonly<Point>[] {\n if (!Array.isArray(value) || value.length !== 4) throw new TypeError('Greenscreen: corners must be four points')\n return Object.freeze(\n value.map((point: unknown) => {\n const x: unknown = typeof point === 'object' && point !== null && 'x' in point ? point.x : undefined\n const y: unknown = typeof point === 'object' && point !== null && 'y' in point ? point.y : undefined\n if (typeof x !== 'number' || typeof y !== 'number' || !Number.isFinite(x) || !Number.isFinite(y)) {\n throw new TypeError('Greenscreen: each corner must have a number x and y')\n }\n return Object.freeze({ x: clamp(x, 0, 1), y: clamp(y, 0, 1) })\n }),\n )\n}\n","import type { Source } from './types.ts'\n\n// How a keyer tells when its source has a new picture to take. A video's frames are watched for. An image is new when\n// its source changes. A canvas can be drawn on at any time with nothing to say so, so it's taken every time. The rest\n// never change. Each kind is told apart by what it has rather than its class, so an element from another window, as a\n// pop-out's would be, is still known\n\n// How long a video goes without a frame callback before its clock is watched instead: callbacks come only while the\n// page is drawing, and some browsers have none\nconst STALLED = 100\n\n// The source's own size in pixels\nexport function sizeOf(source: Source): [number, number] {\n if ('videoWidth' in source) return [source.videoWidth, source.videoHeight]\n if ('naturalWidth' in source) return [source.naturalWidth, source.naturalHeight]\n if ('displayWidth' in source) return [source.displayWidth, source.displayHeight]\n return [source.width, source.height]\n}\n\n// What a keyer given no onError does with a picture it can't key\nexport function warnUnkeyable(error: unknown): void {\n console.warn('Greenscreen: the picture could not be keyed', error)\n}\n\n// One source as a keyer follows it: whether it has a picture yet, and whether it has a new one since it was last taken\nexport class Feed {\n readonly source: Source\n #fresh = true\n #time = -1\n #src = ''\n #handle = 0\n #lastFrame = -Infinity\n // The picture that last failed, by its src where it has one, so each failure is reported once. Null once one is taken\n #failedOn: string | null = null\n #disposed = false\n\n constructor(source: Source) {\n this.source = source\n this.#watch()\n }\n\n #watch() {\n const video = this.source\n if (!('requestVideoFrameCallback' in video) || this.#disposed) return\n this.#handle = video.requestVideoFrameCallback(() => {\n this.#fresh = true\n this.#lastFrame = performance.now()\n this.#watch()\n })\n }\n\n // Whether there's a picture to take: a video with a frame, an image that has loaded, anything else with a size\n hasPicture(): boolean {\n const source = this.source\n if ('videoWidth' in source) return source.readyState >= 2 && source.videoWidth > 0 && source.videoHeight > 0\n if ('naturalWidth' in source) return source.complete && source.naturalWidth > 0\n const [width, height] = sizeOf(source)\n return width > 0 && height > 0\n }\n\n // Whether the picture has changed since it was last taken\n changed(): boolean {\n if (this.#fresh) return true\n const source = this.source\n if ('videoWidth' in source) return performance.now() - this.#lastFrame > STALLED && source.currentTime !== this.#time\n if ('naturalWidth' in source) return source.currentSrc !== this.#src\n return 'getContext' in source\n }\n\n size(): [number, number] {\n return sizeOf(this.source)\n }\n\n // The picture has been taken\n taken() {\n this.#fresh = false\n this.#failedOn = null\n const source = this.source\n if ('videoWidth' in source) this.#time = source.currentTime\n else if ('naturalWidth' in source) this.#src = source.currentSrc\n }\n\n // Taking the picture failed, as it does for one larger than the GPU's textures, or from another site without CORS.\n // It's tried again only when the picture changes. Returns whether this failure is new: the first since a picture was\n // last taken, or of an image or video since given another src, so each is reported once however often it's tried\n failed(): boolean {\n const source = this.source\n const what = 'currentSrc' in source ? source.currentSrc : ''\n const first = this.#failedOn !== what\n this.taken()\n this.#failedOn = what\n return first\n }\n\n // Take the picture again on the next render, as its pixels have changed\n invalidate() {\n this.#fresh = true\n }\n\n dispose() {\n this.#disposed = true\n const video = this.source\n if (this.#handle && 'cancelVideoFrameCallback' in video) video.cancelVideoFrameCallback(this.#handle)\n }\n}\n","import type { BackendName, Canvas, Source } from './types.ts'\n\n// One keyer's drawing: a texture holding the source's picture, and a pass that keys it into the canvas\nexport interface Renderer {\n readonly backend: BackendName\n // True from the moment the graphics context or device is lost until it's been made again\n readonly lost: boolean\n // Takes the source's current picture into the texture, at its size. Throws where the picture can't be taken\n upload(source: Source, width: number, height: number): void\n // Keys the texture into the canvas, sized to the texture, with the packed settings\n draw(settings: Float32Array<ArrayBuffer>): void\n // Leaves the canvas see-through, at the size it has, for a picture that can't be keyed\n clear(): void\n dispose(): void\n}\n\n// What upload() throws for a picture larger than the backend's textures\nexport function tooLarge(width: number, height: number, backend: string, limit: number): RangeError {\n return new RangeError(`Greenscreen: the picture is ${width}×${height}, and ${backend} here takes up to ${limit} a side`)\n}\n\n// What a renderer tells its keyer\nexport interface RendererEvents {\n // The context or device is gone, and the texture with it\n lost(): void\n // It's been made again, with nothing in the texture\n restored(): void\n}\n\n// The canvas's context of that kind, whichever kind of canvas it is, or null where it can't have one: it has another\n// kind already, or the browser has none of that kind\nexport function contextOf(canvas: Canvas, id: 'webgl2', options: WebGLContextAttributes): WebGL2RenderingContext | null\nexport function contextOf(canvas: Canvas, id: 'webgpu'): GPUCanvasContext | null\nexport function contextOf(canvas: Canvas, id: '2d'): Context2D | null\nexport function contextOf(canvas: Canvas, id: 'webgl2' | 'webgpu' | '2d', options?: WebGLContextAttributes) {\n let context: unknown = null\n if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {\n context = canvas.getContext(id, options)\n } else if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {\n context = canvas.getContext(id, options)\n }\n if (id === 'webgl2') return context instanceof WebGL2RenderingContext ? context : null\n if (id === '2d') {\n if (typeof CanvasRenderingContext2D !== 'undefined' && context instanceof CanvasRenderingContext2D) return context\n if (typeof OffscreenCanvasRenderingContext2D !== 'undefined' && context instanceof OffscreenCanvasRenderingContext2D) {\n return context\n }\n return null\n }\n return typeof GPUCanvasContext !== 'undefined' && context instanceof GPUCanvasContext ? context : null\n}\n\nexport type Context2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D\n","// The keyer in GLSL ES 3.00. The fragment shader is shared by the WebGL2 renderer and the three.js material, each\n// giving it vUv, where the pixel is on the output: 0 to 1 across and down. pack.ts says what's in settings.\n//\n// First it keys as OBS Studio's chroma key filter does, the filter's second version, in the same steps and order:\n// https://github.com/obsproject/obs-studio/blob/master/plugins/obs-filters/data/chroma_key_filter_v2.effect\n// - The picture is sampled as OBS holds a source: premultiplied, in linear light, and blended between pixels in\n// linear light, as OBS's sampler blends its texture. The pixel's own colour is then divided by its alpha.\n// - How far a colour's chroma is from the key's is measured on its sRGB values. The measure is blurred: four samples\n// round the pixel, a pixel across and half a pixel down, and half a pixel across and a pixel up, each either way,\n// count twice each, and the pixel itself once, of nine.\n// - Past similarity the alpha fades in over smoothness, and the colour is desaturated over spill, each on a curve of\n// power 1.5. Opacity multiplies the alpha, and gamma, contrast and brightness the colour, in linear light. The\n// colour is clamped, as OBS's target of 8 bits a channel holds it.\n// The add-ons aren't OBS's. Tint and saturation act inside the filter, once the key's distance is measured, which they\n// don't change, and before spill and the colour step: the tint multiplies, OBS's spill takes the tinted colour's luma\n// to desaturate to, and saturation scales the colour's HSB saturation. They act with the key off too. hueSpill, where\n// it's on, takes the key's hue out of the colour in place of OBS's desaturation, by as much, keeping the colour's luma\n// and other hues, on its sRGB values. Crop cuts, and flip mirrors the result. The output is the colour multiplied by\n// its alpha\nexport const FRAGMENT: string = /* glsl */ `precision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nuniform sampler2D image;\nuniform vec4 settings[8];\n\nin vec2 vUv;\nout vec4 fragColor;\n\n// A colour's Cb and Cr from its sRGB values, as OBS's filter has them: BT.709's, in studio range\nconst vec3 CB = vec3(-0.100644, -0.338572, 0.439216);\nconst vec3 CR = vec3(0.439216, -0.398942, -0.040274);\nconst float CHROMA_OFFSET = 0.501961;\n// BT.709's luma, which OBS desaturates to\nconst vec3 LUMA = vec3(0.2126, 0.7152, 0.0722);\n// The scales that take B' − Y' and R' − Y' to BT.709's Pb and Pr, for hueSpill\nconst vec2 CHROMA_SCALE = vec2(1.8556, 1.5748);\n\nfloat toLinear(float c) {\n return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4);\n}\n\nfloat toEncoded(float c) {\n return c <= 0.0031308 ? 12.92 * c : 1.055 * pow(c, 1.0 / 2.4) - 0.055;\n}\n\nvec3 toLinear(vec3 c) {\n return vec3(toLinear(c.r), toLinear(c.g), toLinear(c.b));\n}\n\nvec3 toEncoded(vec3 c) {\n return vec3(toEncoded(c.r), toEncoded(c.g), toEncoded(c.b));\n}\n\n// The picture's pixel at a column, and a row from the top, clamped to the picture's edges as OBS's sampler clamps.\n// It's premultiplied, in linear light, as OBS holds a source, whichever way the texture holds it\nvec4 pixelAt(ivec2 at, ivec2 size) {\n at = clamp(at, ivec2(0), size - 1);\n if (settings[4].y > 0.5) at.y = size.y - 1 - at.y;\n vec4 texel = texelFetch(image, at, 0);\n vec3 rgb = settings[4].w > 0.5 ? texel.rgb : toLinear(texel.rgb);\n return vec4(rgb * texel.a, texel.a);\n}\n\n// The picture at q, 0 to 1 across and down it, as OBS's linear sampler gives it: the four pixels round q, blended\nvec4 sampleAt(vec2 q, ivec2 size) {\n vec2 f = q * vec2(size) - 0.5;\n vec2 corner = floor(f);\n vec2 w = f - corner;\n ivec2 i = ivec2(corner);\n vec4 above = mix(pixelAt(i, size), pixelAt(i + ivec2(1, 0), size), w.x);\n vec4 below = mix(pixelAt(i + ivec2(0, 1), size), pixelAt(i + ivec2(1, 1), size), w.x);\n return mix(above, below, w.y);\n}\n\n// How far a colour's chroma is from the key's, from its sRGB values\nfloat keyDistance(vec3 encoded) {\n return distance(vec2(dot(encoded, CB), dot(encoded, CR)) + CHROMA_OFFSET, settings[0].xy);\n}\n\n// hueSpill's: an sRGB colour's Pb and Pr, and the colour again from its luma and those\nvec2 chromaOf(vec3 encoded) {\n float y = dot(encoded, LUMA);\n return vec2(encoded.b - y, encoded.r - y) / CHROMA_SCALE;\n}\n\nvec3 fromLumaChroma(float y, vec2 c) {\n float r = y + c.y * CHROMA_SCALE.y;\n float b = y + c.x * CHROMA_SCALE.x;\n return vec3(r, (y - LUMA.r * r - LUMA.b * b) / LUMA.g, b);\n}\n\n// The add-on saturation: the colour's HSB saturation scaled by s, keeping its hue and its brightest channel. Each\n// channel's distance below the brightest scales by s, but no further than takes the dimmest to 0, as saturated as a\n// colour can be\nvec3 saturated(vec3 rgb, float s) {\n float top = max(max(rgb.r, rgb.g), rgb.b);\n float spread = top - min(min(rgb.r, rgb.g), rgb.b);\n return top - (top - rgb) * min(s, top / max(spread, 1e-12));\n}\n\n// How far inside the cut's side from a to b the point p is, in output pixels. The points are in the picture's\n// coordinates, and size scales them to output pixels once they're subtracted, so a short side between two corners\n// close together keeps its direction. Two corners together leave no side, and a triangle\nfloat cutSide(vec2 a, vec2 b, vec2 p, vec2 size) {\n vec2 side = (b - a) * size;\n float len = length(side);\n if (len == 0.0) return 1.0e6;\n vec2 q = (p - a) * size;\n return (q.y * side.x - q.x * side.y) / len;\n}\n\n// 1 inside the cut, 0 outside, and between across the output pixel a side passes through, so its edges are smooth at\n// any size. The corners must make a convex shape, which a point is inside where it is inside all of its sides. They\n// go clockwise, which puts the inside of each side on its right\nfloat cutMask(vec2 p, vec2 size) {\n vec2 c0 = settings[5].xy;\n vec2 c1 = settings[5].zw;\n vec2 c2 = settings[6].xy;\n vec2 c3 = settings[6].zw;\n float d = min(\n min(cutSide(c0, c1, p, size), cutSide(c1, c2, p, size)),\n min(cutSide(c2, c3, p, size), cutSide(c3, c0, p, size))\n );\n return clamp(d + 0.5, 0.0, 1.0);\n}\n\nvoid main() {\n // Output pixels to the picture's width and height, for the cut's soft edge\n vec2 size = 1.0 / max(fwidth(vUv), vec2(1e-6));\n vec4 key = settings[0];\n vec4 matte = settings[1];\n vec4 correction = settings[2];\n vec4 extras = settings[3];\n vec4 flags = settings[4];\n\n // Where this pixel is on the picture, mirrored by flip\n vec2 p = vec2(flags.x > 0.5 ? 1.0 - vUv.x : vUv.x, vUv.y);\n ivec2 pixels = textureSize(image, 0);\n\n vec4 sampled = sampleAt(p, pixels);\n float alpha = sampled.a;\n vec3 rgb = alpha > 0.0 ? sampled.rgb / alpha : vec3(0.0);\n\n // OBS's filter: the key's distance, and from it the alpha and how much of the colour spill keeps\n bool keyed = key.w > 0.5;\n float kept = 1.0;\n if (keyed) {\n vec2 texel = 1.0 / vec2(pixels);\n vec2 across = vec2(texel.x, 0.5 * texel.y);\n vec2 up = vec2(0.5 * texel.x, -texel.y);\n float around = keyDistance(toEncoded(sampleAt(p - across, pixels).rgb))\n + keyDistance(toEncoded(sampleAt(p + across, pixels).rgb))\n + keyDistance(toEncoded(sampleAt(p - up, pixels).rgb))\n + keyDistance(toEncoded(sampleAt(p + up, pixels).rgb));\n float beyond = (2.0 * around + keyDistance(toEncoded(rgb))) / 9.0 - matte.x;\n alpha *= matte.w;\n alpha *= pow(clamp(beyond / matte.y, 0.0, 1.0), 1.5);\n kept = pow(clamp(beyond / matte.z, 0.0, 1.0), 1.5);\n }\n\n // The add-ons tint and saturation. Spill desaturates to the tinted colour's luma, as it was before saturation\n rgb *= extras.rgb;\n float grey = dot(rgb, LUMA);\n if (extras.w != 1.0) rgb = saturated(rgb, extras.w);\n\n // The rest of OBS's filter: spill, then gamma, contrast and brightness\n if (keyed) {\n if (settings[7].y > 0.5) {\n // The add-on hueSpill: only the part of the colour's chroma that points the key's way comes out\n vec3 encoded = toEncoded(rgb);\n vec2 toward = (key.xy - CHROMA_OFFSET) * key.z;\n vec2 c = chromaOf(encoded);\n c -= toward * max(dot(c, toward), 0.0) * (1.0 - kept);\n rgb = toLinear(clamp(fromLumaChroma(dot(encoded, LUMA), c), 0.0, 1.0));\n } else {\n rgb = mix(vec3(grey), rgb, kept);\n }\n rgb = pow(max(rgb, 0.0), vec3(correction.x)) * correction.y + correction.z;\n }\n rgb = clamp(rgb, 0.0, 1.0);\n\n // The add-on crop\n if (settings[7].x > 0.5) alpha *= cutMask(p, size);\n\n if (flags.z < 0.5) rgb = toEncoded(rgb);\n fragColor = vec4(rgb * alpha, alpha);\n}\n`\n\n// One triangle over the whole canvas, its corners made from their index, so there's nothing to upload\nexport const VERTEX: string = /* glsl */ `#version 300 es\nout vec2 vUv;\nvoid main() {\n vec2 position = vec2(float((gl_VertexID & 1) << 2) - 1.0, float((gl_VertexID & 2) << 1) - 1.0);\n vUv = vec2(position.x + 1.0, 1.0 - position.y) * 0.5;\n gl_Position = vec4(position, 0.0, 1.0);\n}\n`\n","import { contextOf, tooLarge } from './renderer.ts'\nimport type { Renderer, RendererEvents } from './renderer.ts'\nimport { FRAGMENT, VERTEX } from './shader.glsl.ts'\nimport type { Canvas, Source } from './types.ts'\n\n// Drawn with blending premultiplied, as the shader's output is, and kept between draws, so the canvas can be copied\n// from at any time and not just in the task that drew it\nconst ATTRIBUTES: WebGLContextAttributes = {\n alpha: true,\n premultipliedAlpha: true,\n antialias: false,\n depth: false,\n stencil: false,\n preserveDrawingBuffer: true,\n}\n\nexport class WebGLRenderer implements Renderer {\n readonly backend = 'webgl'\n readonly #canvas: Canvas\n readonly #gl: WebGL2RenderingContext\n readonly #events: RendererEvents\n #program: WebGLProgram | null = null\n #settings: WebGLUniformLocation | null = null\n #texture: WebGLTexture | null = null\n #width = 0\n #height = 0\n // The most pixels a side it can take and draw\n #limit = 0\n #lost = false\n\n constructor(canvas: Canvas, events: RendererEvents) {\n const gl = contextOf(canvas, 'webgl2', ATTRIBUTES)\n if (!gl) throw new Error('Greenscreen: WebGL2 is not available on this canvas')\n this.#canvas = canvas\n this.#gl = gl\n this.#events = events\n canvas.addEventListener('webglcontextlost', this.#onLost)\n canvas.addEventListener('webglcontextrestored', this.#onRestored)\n this.#build()\n }\n\n get lost() {\n return this.#lost\n }\n\n // The program and the texture, as at first and again once a lost context is back. The picture is uploaded as it\n // comes: top row first, not premultiplied, in sRGB\n #build() {\n const gl = this.#gl\n const program = gl.createProgram()\n const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX)\n const fragment = compile(gl, gl.FRAGMENT_SHADER, `#version 300 es\\n${FRAGMENT}`)\n gl.attachShader(program, vertex)\n gl.attachShader(program, fragment)\n gl.linkProgram(program)\n if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) {\n throw new Error(`Greenscreen: the shader didn't link: ${gl.getProgramInfoLog(program)}`)\n }\n gl.deleteShader(vertex)\n gl.deleteShader(fragment)\n gl.useProgram(program)\n gl.uniform1i(gl.getUniformLocation(program, 'image'), 0)\n this.#program = program\n this.#settings = gl.getUniformLocation(program, 'settings')\n\n const texture = gl.createTexture()\n gl.activeTexture(gl.TEXTURE0)\n gl.bindTexture(gl.TEXTURE_2D, texture)\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)\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.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false)\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false)\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL)\n this.#texture = texture\n this.#width = 0\n this.#height = 0\n // The widest picture it can take and draw: its largest texture, and its largest viewport, as the canvas is sized to\n // the picture. A lost context says neither, and draws nothing until it's back\n const texture2D: unknown = gl.getParameter(gl.MAX_TEXTURE_SIZE)\n const viewport: unknown = gl.getParameter(gl.MAX_VIEWPORT_DIMS)\n const sides = [texture2D, ...(viewport instanceof Int32Array ? viewport : [])]\n this.#limit = Math.min(...sides.filter((side) => typeof side === 'number'))\n }\n\n // A picture larger than the context's textures throws, as it would otherwise be drawn black\n upload(source: Source, width: number, height: number) {\n if (this.#lost) return\n const limit = this.#limit\n if (width > limit || height > limit) throw tooLarge(width, height, 'WebGL2', limit)\n const gl = this.#gl\n gl.activeTexture(gl.TEXTURE0)\n gl.bindTexture(gl.TEXTURE_2D, this.#texture)\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, this.#straight(source, width, height))\n this.#width = width\n this.#height = height\n }\n\n // WebGL uploads an ImageBitmap as it was made, ignoring the unpacking flags, so one made premultiplied, as they are\n // by default, would arrive premultiplied. Drawn into a canvas first, it arrives straight, as everything else does\n #bitmaps: OffscreenCanvasRenderingContext2D | null = null\n\n #straight(source: Source, width: number, height: number): Source {\n if (typeof ImageBitmap === 'undefined' || !(source instanceof ImageBitmap) || typeof OffscreenCanvas === 'undefined') {\n return source\n }\n let context = this.#bitmaps\n if (!context) {\n context = new OffscreenCanvas(width, height).getContext('2d')\n if (!context) return source\n this.#bitmaps = context\n }\n const canvas = context.canvas\n if (canvas.width !== width || canvas.height !== height) {\n canvas.width = width\n canvas.height = height\n } else {\n context.clearRect(0, 0, width, height)\n }\n context.drawImage(source, 0, 0)\n return canvas\n }\n\n // Every pixel is drawn over, unblended, so there's nothing to clear first\n draw(settings: Float32Array<ArrayBuffer>) {\n if (this.#lost || !this.#width || !this.#height) return\n const gl = this.#gl\n const canvas = this.#canvas\n if (canvas.width !== this.#width || canvas.height !== this.#height) {\n canvas.width = this.#width\n canvas.height = this.#height\n }\n gl.viewport(0, 0, this.#width, this.#height)\n gl.useProgram(this.#program)\n gl.uniform4fv(this.#settings, settings)\n gl.activeTexture(gl.TEXTURE0)\n gl.bindTexture(gl.TEXTURE_2D, this.#texture)\n gl.drawArrays(gl.TRIANGLES, 0, 3)\n }\n\n // The drawing buffer is kept between draws, so it stays clear until the next\n clear() {\n if (this.#lost) return\n const gl = this.#gl\n gl.clearColor(0, 0, 0, 0)\n gl.clear(gl.COLOR_BUFFER_BIT)\n }\n\n // Lost, its default is prevented, which lets the browser give it back\n #onLost = (event: Event) => {\n event.preventDefault()\n this.#lost = true\n this.#program = null\n this.#texture = null\n this.#width = 0\n this.#height = 0\n this.#events.lost()\n }\n\n #onRestored = () => {\n this.#lost = false\n this.#build()\n this.#events.restored()\n }\n\n // Loses the context on purpose, as that frees it at once rather than when it's collected, and a page can only have\n // so many\n dispose() {\n const gl = this.#gl\n this.#canvas.removeEventListener('webglcontextlost', this.#onLost)\n this.#canvas.removeEventListener('webglcontextrestored', this.#onRestored)\n if (!this.#lost) {\n gl.deleteTexture(this.#texture)\n gl.deleteProgram(this.#program)\n }\n this.#lost = true\n gl.getExtension('WEBGL_lose_context')?.loseContext()\n }\n}\n\nfunction compile(gl: WebGL2RenderingContext, type: number, source: string) {\n const shader = gl.createShader(type)\n if (!shader) throw new Error('Greenscreen: no shader could be made')\n gl.shaderSource(shader, source)\n gl.compileShader(shader)\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS) && !gl.isContextLost()) {\n throw new Error(`Greenscreen: the shader didn't compile: ${gl.getShaderInfoLog(shader)}`)\n }\n return shader\n}\n","// The keyer in WGSL, for the WebGPU renderer: OBS's chroma key filter and the add-ons, in the same steps as the GLSL\n// in shader.glsl.ts, which says what they are. Its texture always holds the picture's sRGB values with the top row\n// first, so it reads none of the renderer flags that the GLSL takes from three.js\nexport const SHADER: string = /* wgsl */ `\nstruct Settings {\n key: vec4f,\n matte: vec4f,\n correction: vec4f,\n extras: vec4f,\n flags: vec4f,\n corners: array<vec4f, 2>,\n switches: vec4f,\n}\n\n@group(0) @binding(0) var image: texture_2d<f32>;\n@group(0) @binding(1) var<uniform> settings: Settings;\n\nstruct Varyings {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f,\n}\n\n// One triangle over the whole canvas, its corners made from their index\n@vertex\nfn vertexMain(@builtin(vertex_index) index: u32) -> Varyings {\n let position = vec2f(f32((index & 1u) << 2u) - 1.0, f32((index & 2u) << 1u) - 1.0);\n var result: Varyings;\n result.position = vec4f(position, 0.0, 1.0);\n result.uv = vec2f(position.x + 1.0, 1.0 - position.y) * 0.5;\n return result;\n}\n\nconst CB = vec3f(-0.100644, -0.338572, 0.439216);\nconst CR = vec3f(0.439216, -0.398942, -0.040274);\nconst CHROMA_OFFSET = 0.501961;\nconst LUMA = vec3f(0.2126, 0.7152, 0.0722);\nconst CHROMA_SCALE = vec2f(1.8556, 1.5748);\n\nfn channelToLinear(c: f32) -> f32 {\n return select(pow((c + 0.055) / 1.055, 2.4), c / 12.92, c <= 0.04045);\n}\n\nfn channelToEncoded(c: f32) -> f32 {\n return select(1.055 * pow(c, 1.0 / 2.4) - 0.055, 12.92 * c, c <= 0.0031308);\n}\n\nfn toLinear(c: vec3f) -> vec3f {\n return vec3f(channelToLinear(c.r), channelToLinear(c.g), channelToLinear(c.b));\n}\n\nfn toEncoded(c: vec3f) -> vec3f {\n return vec3f(channelToEncoded(c.r), channelToEncoded(c.g), channelToEncoded(c.b));\n}\n\nfn pixelAt(at: vec2i, size: vec2i) -> vec4f {\n let texel = textureLoad(image, clamp(at, vec2i(0), size - 1), 0);\n return vec4f(toLinear(texel.rgb) * texel.a, texel.a);\n}\n\nfn sampleAt(q: vec2f, size: vec2i) -> vec4f {\n let f = q * vec2f(size) - 0.5;\n let corner = floor(f);\n let w = f - corner;\n let i = vec2i(corner);\n let above = mix(pixelAt(i, size), pixelAt(i + vec2i(1, 0), size), w.x);\n let below = mix(pixelAt(i + vec2i(0, 1), size), pixelAt(i + vec2i(1, 1), size), w.x);\n return mix(above, below, w.y);\n}\n\nfn keyDistance(encoded: vec3f) -> f32 {\n return distance(vec2f(dot(encoded, CB), dot(encoded, CR)) + CHROMA_OFFSET, settings.key.xy);\n}\n\nfn chromaOf(encoded: vec3f) -> vec2f {\n let y = dot(encoded, LUMA);\n return vec2f(encoded.b - y, encoded.r - y) / CHROMA_SCALE;\n}\n\nfn fromLumaChroma(y: f32, c: vec2f) -> vec3f {\n let r = y + c.y * CHROMA_SCALE.y;\n let b = y + c.x * CHROMA_SCALE.x;\n return vec3f(r, (y - LUMA.r * r - LUMA.b * b) / LUMA.g, b);\n}\n\nfn saturated(rgb: vec3f, s: f32) -> vec3f {\n let top = max(max(rgb.r, rgb.g), rgb.b);\n let spread = top - min(min(rgb.r, rgb.g), rgb.b);\n return top - (top - rgb) * min(s, top / max(spread, 1e-12));\n}\n\nfn cutSide(a: vec2f, b: vec2f, p: vec2f, size: vec2f) -> f32 {\n let side = (b - a) * size;\n let len = length(side);\n if (len == 0.0) {\n return 1.0e6;\n }\n let q = (p - a) * size;\n return (q.y * side.x - q.x * side.y) / len;\n}\n\nfn cutMask(p: vec2f, size: vec2f) -> f32 {\n let c0 = settings.corners[0].xy;\n let c1 = settings.corners[0].zw;\n let c2 = settings.corners[1].xy;\n let c3 = settings.corners[1].zw;\n let d = min(\n min(cutSide(c0, c1, p, size), cutSide(c1, c2, p, size)),\n min(cutSide(c2, c3, p, size), cutSide(c3, c0, p, size))\n );\n return clamp(d + 0.5, 0.0, 1.0);\n}\n\n@fragment\nfn fragmentMain(input: Varyings) -> @location(0) vec4f {\n // Taken first, while every pixel takes the same way, as a derivative must be\n let size = 1.0 / max(fwidth(input.uv), vec2f(1e-6));\n let key = settings.key;\n let matte = settings.matte;\n let correction = settings.correction;\n let extras = settings.extras;\n\n let p = vec2f(select(input.uv.x, 1.0 - input.uv.x, settings.flags.x > 0.5), input.uv.y);\n let pixels = vec2i(textureDimensions(image));\n\n let sampled = sampleAt(p, pixels);\n var alpha = sampled.a;\n var rgb = select(vec3f(0.0), sampled.rgb / alpha, alpha > 0.0);\n\n // OBS's filter: the key's distance, and from it the alpha and how much of the colour spill keeps\n let keyed = key.w > 0.5;\n var kept = 1.0;\n if (keyed) {\n let texel = 1.0 / vec2f(pixels);\n let across = vec2f(texel.x, 0.5 * texel.y);\n let up = vec2f(0.5 * texel.x, -texel.y);\n let around = keyDistance(toEncoded(sampleAt(p - across, pixels).rgb))\n + keyDistance(toEncoded(sampleAt(p + across, pixels).rgb))\n + keyDistance(toEncoded(sampleAt(p - up, pixels).rgb))\n + keyDistance(toEncoded(sampleAt(p + up, pixels).rgb));\n let beyond = (2.0 * around + keyDistance(toEncoded(rgb))) / 9.0 - matte.x;\n alpha *= matte.w;\n alpha *= pow(clamp(beyond / matte.y, 0.0, 1.0), 1.5);\n kept = pow(clamp(beyond / matte.z, 0.0, 1.0), 1.5);\n }\n\n // The add-ons tint and saturation. Spill desaturates to the tinted colour's luma, as it was before saturation\n rgb *= extras.rgb;\n let grey = dot(rgb, LUMA);\n if (extras.w != 1.0) {\n rgb = saturated(rgb, extras.w);\n }\n\n // The rest of OBS's filter: spill, then gamma, contrast and brightness\n if (keyed) {\n if (settings.switches.y > 0.5) {\n // The add-on, hueSpill\n let encoded = toEncoded(rgb);\n let toward = (key.xy - CHROMA_OFFSET) * key.z;\n var c = chromaOf(encoded);\n c -= toward * max(dot(c, toward), 0.0) * (1.0 - kept);\n rgb = toLinear(clamp(fromLumaChroma(dot(encoded, LUMA), c), vec3f(0.0), vec3f(1.0)));\n } else {\n rgb = mix(vec3f(grey), rgb, kept);\n }\n rgb = pow(max(rgb, vec3f(0.0)), vec3f(correction.x)) * correction.y + correction.z;\n }\n rgb = clamp(rgb, vec3f(0.0), vec3f(1.0));\n\n // The add-on crop\n if (settings.switches.x > 0.5) {\n alpha *= cutMask(p, size);\n }\n\n return vec4f(toEncoded(rgb) * alpha, alpha);\n}\n`\n","import { PACKED_LENGTH } from './pack.ts'\nimport { contextOf, tooLarge } from './renderer.ts'\nimport type { Context2D, Renderer, RendererEvents } from './renderer.ts'\nimport { SHADER } from './shader.wgsl.ts'\nimport type { Canvas, Source } from './types.ts'\n\n// The WebGPU usage flags, as the spec numbers them, rather than the browser's globals, which TypeScript doesn't declare\nconst TEXTURE_COPY_DST = 0x02\nconst TEXTURE_BINDING = 0x04\nconst TEXTURE_RENDER_ATTACHMENT = 0x10\nconst BUFFER_COPY_DST = 0x08\nconst BUFFER_UNIFORM = 0x40\n\n// One device for every keyer on the page, as a page can have many, and WebGPU, unlike WebGL, doesn't need a context of\n// its own for each. It's asked for once, and asked for again only after it's lost\nlet shared: Promise<GPUDevice> | null = null\n// The device once it's there, for a keyer made after it to start with at once\nlet current: GPUDevice | null = null\n\n// Whether 'auto' takes WebGPU, found once, and again after the device is lost. known is what it came to, for a keyer to\n// choose by at once, and null until then\nlet preferred: Promise<boolean> | null = null\nlet known: boolean | null = null\n\n// The page's device, from the adapter given or the browser's own. It's asked for with the largest texture the adapter\n// has, as a device takes pictures of only 8192 pixels a side unless more is asked for\nexport function requestDevice(given?: GPUAdapter): Promise<GPUDevice> {\n if (shared) return shared\n const attempt = (async () => {\n const adapter = given ?? (await requestAdapter())\n const device = await adapter.requestDevice({\n requiredLimits: { maxTextureDimension2D: adapter.limits.maxTextureDimension2D },\n })\n void device.lost.then(() => {\n if (shared !== attempt) return\n shared = null\n current = null\n preferred = null\n known = null\n })\n return device\n })()\n shared = attempt\n // Before anything that waits for it goes on, as this waits first\n void attempt.then(\n (device) => {\n if (shared === attempt) current = device\n },\n () => {},\n )\n return attempt\n}\n\n// The device, where it has been had already and not lost since\nexport function currentDevice(): GPUDevice | null {\n return current\n}\n\nasync function requestAdapter(): Promise<GPUAdapter> {\n const gpu = typeof navigator === 'undefined' ? undefined : navigator.gpu\n if (!gpu) throw new Error('Greenscreen: WebGPU is not available here')\n const adapter = await gpu.requestAdapter()\n if (!adapter) throw new Error('Greenscreen: WebGPU has no adapter here')\n return adapter\n}\n\n// Whether 'auto' takes WebGPU: where the browser has an adapter for it on the GPU, and a device from that adapter. A\n// fallback adapter, which runs WebGPU on the CPU, doesn't count, as WebGL2 is then likely on the GPU, and faster\nexport function prefersWebGPU(): Promise<boolean> {\n if (preferred) return preferred\n const attempt = (async () => {\n try {\n const adapter = await requestAdapter()\n if (adapter.info.isFallbackAdapter) return false\n await requestDevice(adapter)\n return true\n } catch {\n return false\n }\n })()\n preferred = attempt\n void attempt.then((webgpu) => {\n if (preferred === attempt) known = webgpu\n })\n return attempt\n}\n\n// What prefersWebGPU() comes to, where that's known already: once it has resolved, or at once where there's no WebGPU\nexport function knownPreference(): boolean | null {\n if (typeof navigator === 'undefined' || !navigator.gpu) return false\n return known\n}\n\nconst pipelines = new WeakMap<GPUDevice, Map<GPUTextureFormat, GPURenderPipeline>>()\n\n// The keying pipeline for the device and canvas format, made once. It has no sampler: the shader reads the texture's\n// pixels itself, and blends them as OBS's sampler would\nexport function pipelineFor(device: GPUDevice, format: GPUTextureFormat): GPURenderPipeline {\n let byFormat = pipelines.get(device)\n if (!byFormat) {\n byFormat = new Map()\n pipelines.set(device, byFormat)\n }\n let made = byFormat.get(format)\n if (!made) {\n const module = device.createShaderModule({ label: 'Greenscreen', code: SHADER })\n made = device.createRenderPipeline({\n label: 'Greenscreen',\n layout: 'auto',\n vertex: { module, entryPoint: 'vertexMain' },\n fragment: { module, entryPoint: 'fragmentMain', targets: [{ format }] },\n primitive: { topology: 'triangle-list' },\n })\n byFormat.set(format, made)\n }\n return made\n}\n\nexport function preferredFormat(): GPUTextureFormat {\n return navigator.gpu.getPreferredCanvasFormat()\n}\n\n// WebGPU keys into a canvas of its own, off the page, and each picture is copied from there into the keyer's canvas,\n// which shows it through a 2D context. A WebGPU canvas on the page gives drawImage nothing once the browser has drawn\n// the page, where a 2D canvas keeps its picture until it's drawn again, on the page or off it\nexport class WebGPURenderer implements Renderer {\n readonly backend = 'webgpu'\n readonly #canvas: Canvas\n readonly #output: Context2D\n readonly #surface: OffscreenCanvas\n readonly #context: GPUCanvasContext\n readonly #events: RendererEvents\n #device!: GPUDevice\n #pipeline!: GPURenderPipeline\n #uniforms!: GPUBuffer\n #texture: GPUTexture | null = null\n #bindGroup: GPUBindGroup | null = null\n #videos: Context2D | null = null\n #lost = false\n #disposed = false\n\n constructor(canvas: Canvas, device: GPUDevice, events: RendererEvents) {\n // WebGPU first, so a canvas WebGPU can't draw for is left as it was\n const surface = new OffscreenCanvas(1, 1)\n const context = contextOf(surface, 'webgpu')\n if (!context) throw new Error('Greenscreen: WebGPU is not available on this canvas')\n const output = contextOf(canvas, '2d')\n if (!output) throw new Error('Greenscreen: this canvas has a context of another kind already')\n this.#canvas = canvas\n this.#output = output\n this.#surface = surface\n this.#context = context\n this.#events = events\n this.#build(device)\n }\n\n get lost() {\n return this.#lost\n }\n\n // The surface set up for the device, premultiplied as the shader's output is\n #build(device: GPUDevice) {\n const format = preferredFormat()\n this.#device = device\n this.#context.configure({ device, format, alphaMode: 'premultiplied', usage: TEXTURE_RENDER_ATTACHMENT })\n this.#pipeline = pipelineFor(device, format)\n this.#uniforms = device.createBuffer({\n label: 'Greenscreen settings',\n size: PACKED_LENGTH * 4,\n usage: BUFFER_UNIFORM | BUFFER_COPY_DST,\n })\n this.#texture = null\n this.#bindGroup = null\n void device.lost.then(() => this.#onLost(device))\n }\n\n // Lost with the device, it asks for the next one and starts again with it\n async #onLost(device: GPUDevice) {\n if (this.#disposed || device !== this.#device) return\n this.#lost = true\n this.#texture = null\n this.#bindGroup = null\n this.#events.lost()\n try {\n const next = await requestDevice()\n if (this.#disposed) return\n this.#build(next)\n this.#lost = false\n this.#events.restored()\n } catch {\n // No device to be had: it stays lost\n }\n }\n\n // The picture as it comes, top row first and not premultiplied, in a texture of its size. copyExternalImageToTexture\n // takes every kind of source, a video by way of a 2D canvas. A picture larger than the device's textures throws, as\n // a texture of its size would be made without an error thrown, and never drawn\n upload(source: Source, width: number, height: number) {\n if (this.#lost) return\n const device = this.#device\n const limit = device.limits.maxTextureDimension2D\n if (width > limit || height > limit) throw tooLarge(width, height, 'WebGPU', limit)\n let texture = this.#texture\n if (!texture || texture.width !== width || texture.height !== height) {\n texture?.destroy()\n texture = device.createTexture({\n label: 'Greenscreen picture',\n size: { width, height },\n format: 'rgba8unorm',\n usage: TEXTURE_BINDING | TEXTURE_COPY_DST | TEXTURE_RENDER_ATTACHMENT,\n })\n this.#texture = texture\n this.#bindGroup = device.createBindGroup({\n layout: this.#pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: texture.createView() },\n { binding: 1, resource: { buffer: this.#uniforms } },\n ],\n })\n }\n device.queue.copyExternalImageToTexture(\n { source: this.#asDrawn(source, width, height), flipY: false },\n { texture, colorSpace: 'srgb', premultipliedAlpha: false },\n { width, height },\n )\n }\n\n // A video comes in through a 2D canvas. WebGPU's own copy converts a video's colours from the video's colour space\n // to sRGB, which moves those of a BT.601 video, as cameras' and recordings often are, by as much as 20 levels in 255:\n // the keyer would key colours a little apart from those WebGL keys, and from those a 2D canvas reads, as an\n // eyedropper does. A 2D canvas reads a video as WebGL does. It also reads a camera's first frame, which WebGPU's copy\n // can't. A VideoFrame of RGB pixels, as one made from a canvas is, has nothing to convert, and comes as it is\n #asDrawn(source: Source, width: number, height: number): Source {\n const video = 'videoWidth' in source || ('displayWidth' in source && !/^(RGB|BGR)/.test(source.format ?? ''))\n if (!video) return source\n let context = this.#videos\n if (!context) {\n context = contextOf(stagingCanvas(), '2d')\n if (!context) return source\n this.#videos = context\n }\n const canvas = context.canvas\n if (canvas.width !== width || canvas.height !== height) {\n canvas.width = width\n canvas.height = height\n }\n context.globalCompositeOperation = 'copy'\n context.drawImage(source, 0, 0, width, height)\n return canvas\n }\n\n // The surface's texture is taken just before it's drawn over whole, and the picture is copied across, alpha and all,\n // into the keyer's canvas\n draw(settings: Float32Array<ArrayBuffer>) {\n const texture = this.#texture\n const bindGroup = this.#bindGroup\n if (this.#lost || !texture || !bindGroup) return\n const { width, height } = texture\n for (const canvas of [this.#surface, this.#canvas]) {\n if (canvas.width !== width || canvas.height !== height) {\n canvas.width = width\n canvas.height = height\n }\n }\n const device = this.#device\n device.queue.writeBuffer(this.#uniforms, 0, settings, 0, settings.length)\n const encoder = device.createCommandEncoder()\n const pass = encoder.beginRenderPass({\n colorAttachments: [\n {\n view: this.#context.getCurrentTexture().createView(),\n loadOp: 'clear',\n clearValue: [0, 0, 0, 0],\n storeOp: 'store',\n },\n ],\n })\n pass.setPipeline(this.#pipeline)\n pass.setBindGroup(0, bindGroup)\n pass.draw(3)\n pass.end()\n device.queue.submit([encoder.finish()])\n const output = this.#output\n output.globalCompositeOperation = 'copy'\n output.drawImage(this.#surface, 0, 0)\n }\n\n // The keyer's canvas shows its picture through a 2D context, which clears whatever its composite operation\n clear() {\n const canvas = this.#canvas\n this.#output.clearRect(0, 0, canvas.width, canvas.height)\n }\n\n dispose() {\n this.#disposed = true\n this.#lost = true\n this.#texture?.destroy()\n this.#uniforms.destroy()\n this.#texture = null\n this.#bindGroup = null\n this.#videos = null\n this.#context.unconfigure()\n }\n}\n\n// The canvas a video is drawn into on its way in: an element, off the page, where there's a document. WebGPU's copy\n// from a 2D OffscreenCanvas comes out empty on SwiftShader, Chrome's software renderer, where one from an element\n// doesn't. A worker has only OffscreenCanvas\nfunction stagingCanvas(): Canvas {\n if (typeof document !== 'undefined') return document.createElement('canvas')\n return new OffscreenCanvas(1, 1)\n}\n","import { pack, PACKED_LENGTH } from './pack.ts'\nimport type { Renderer, RendererEvents } from './renderer.ts'\nimport { DEFAULT_SETTINGS, mergeSettings } from './settings.ts'\nimport type { Settings } from './settings.ts'\nimport { Feed, warnUnkeyable } from './source.ts'\nimport type { BackendName, Canvas, Source } from './types.ts'\nimport { WebGLRenderer } from './webgl.ts'\nimport {\n currentDevice,\n knownPreference,\n pipelineFor,\n preferredFormat,\n prefersWebGPU,\n requestDevice,\n WebGPURenderer,\n} from './webgpu.ts'\n\n// The backend to draw with: 'auto' lets the keyer choose\nexport type BackendChoice = 'auto' | BackendName\n\nexport interface GreenscreenOptions<C extends Canvas = HTMLCanvasElement> {\n // The canvas to draw in. It must be one no context has been taken from. Without one, the keyer makes its own: a\n // canvas element, or an OffscreenCanvas in a worker\n canvas?: C\n // 'auto' by default: WebGPU where the browser has it on the GPU, and WebGL2 elsewhere\n backend?: BackendChoice\n // The settings to start with, over the defaults\n settings?: Readonly<Partial<Settings>>\n // The graphics context or device has been lost, and the canvas no longer has a picture\n onLost?: () => void\n // It's back. The next render draws again\n onRestored?: () => void\n // The source's picture can't be keyed: it's larger than the GPU's textures, or from another site without CORS. Called\n // once for each picture that fails, with what was thrown, and the canvas is left see-through until a picture can be\n // keyed. Without it, the keyer warns in the console\n onError?: (error: unknown) => void\n}\n\n// The time between a keyer's own frames, where there are no animation frames to draw on\nconst FALLBACK_INTERVAL = 1000 / 60\n\n// A chroma keyer: it takes the picture from its source and draws it, keyed, into its canvas, at the picture's own size.\n// The canvas is see-through where the key and the cut take the picture out, with its colour premultiplied by its\n// alpha, and it keeps its picture between renders, so it can be drawn from with drawImage, or put on the page, at any\n// time. Call render() on every frame, or start() for the keyer to call it itself: it draws only when there's something\n// new to draw\nexport class Greenscreen<C extends Canvas = HTMLCanvasElement> {\n readonly canvas: C\n // Which backend it draws with, once it has one. It rejects where the backend can't be had\n readonly initialized: Promise<BackendName>\n #renderer: Renderer | null = null\n #settings: Readonly<Settings> = DEFAULT_SETTINGS\n #packed = new Float32Array(PACKED_LENGTH)\n #scratch = new Float32Array(PACKED_LENGTH)\n #dirty = true\n #feed: Feed | null = null\n // Whether the renderer has a picture of the current source to draw\n #uploaded = false\n #ready = false\n #frame = 0\n #loop: { cancel: () => void } | null = null\n #disposed = false\n readonly #onLost?: () => void\n readonly #onRestored?: () => void\n readonly #onError: (error: unknown) => void\n\n constructor(source: Source | null = null, options: GreenscreenOptions<C> = {}) {\n // A canvas it makes is the default type's, or an OffscreenCanvas in a worker, which a worker's code types as C\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n this.canvas = options.canvas ?? (createCanvas() as C)\n this.#onLost = options.onLost\n this.#onRestored = options.onRestored\n this.#onError = options.onError ?? warnUnkeyable\n this.set(options.settings ?? {})\n this.source = source\n this.initialized = this.#initialize(options.backend ?? 'auto')\n // Handled here, so a keyer whose backend can't be had doesn't report it to a page that never asked\n this.initialized.catch(() => {})\n }\n\n // A WebGL2 keyer has its backend at once. A WebGPU one has it once the device is ready, and an 'auto' one once it's\n // known which to take, both of which warmUp() can see to before the keyer is made. The canvas isn't touched until the\n // backend is known, as a canvas can only ever have one kind of context\n #initialize(choice: BackendChoice): Promise<BackendName> {\n if (choice === 'webgl') return this.#useWebGL()\n if (choice === 'webgpu') return this.#useWebGPU()\n if (choice === 'auto') {\n const known = knownPreference()\n if (known !== null) return known ? this.#useWebGPU() : this.#useWebGL()\n return prefersWebGPU().then((webgpu) => (webgpu ? this.#useWebGPU() : this.#useWebGL()))\n }\n // Only from JavaScript, which the types don't stop\n const name: string = choice\n return Promise.reject(new TypeError(`Greenscreen: no backend called ${name}`))\n }\n\n #useWebGL(): Promise<BackendName> {\n if (this.#disposed) return Promise.reject(new Error('Greenscreen: disposed before its backend was ready'))\n try {\n this.#renderer = new WebGLRenderer(this.canvas, this.#events)\n return Promise.resolve('webgl')\n } catch (error) {\n return Promise.reject(error)\n }\n }\n\n #useWebGPU(): Promise<BackendName> {\n const start = (device: GPUDevice): BackendName => {\n if (this.#disposed) throw new Error('Greenscreen: disposed before WebGPU was ready')\n this.#renderer = new WebGPURenderer(this.canvas, device, this.#events)\n return 'webgpu'\n }\n // With the device there already, as it is once warmUp() has resolved, the keyer starts at once, and its first\n // render draws, even in the task that made it\n const device = currentDevice()\n if (!device) return requestDevice().then(start)\n try {\n return Promise.resolve(start(device))\n } catch (error) {\n return Promise.reject(error)\n }\n }\n\n #events: RendererEvents = {\n lost: () => {\n this.#ready = false\n this.#uploaded = false\n this.#onLost?.()\n },\n restored: () => {\n this.#feed?.invalidate()\n this.#dirty = true\n this.#onRestored?.()\n },\n }\n\n get backend(): BackendName | null {\n return this.#renderer?.backend ?? null\n }\n\n // Whether the canvas has a picture of the current source, keyed: false until the first is drawn, while the source's\n // picture can't be keyed, while the context is lost, and after dispose()\n get ready(): boolean {\n return this.#ready\n }\n\n // How many pictures it has drawn, for whoever draws from the canvas to tell when there's a new one\n get frame(): number {\n return this.#frame\n }\n\n // The settings it keys with. Each change makes a new frozen object, so one held stays as it was\n get settings(): Readonly<Settings> {\n return this.#settings\n }\n\n get source(): Source | null {\n return this.#feed?.source ?? null\n }\n\n // A new source isn't ready until its first picture is drawn\n set source(source: Source | null) {\n if (source === this.source) return\n this.#feed?.dispose()\n this.#feed = source ? new Feed(source) : null\n this.#uploaded = false\n this.#ready = false\n }\n\n // Changes the settings named, leaving the rest. The values are copied, corners and all, so changing the object\n // afterwards changes nothing until it's given again\n set(patch: Readonly<Partial<Settings>>): void {\n this.#settings = mergeSettings(this.#settings, patch)\n const packed = pack(this.#settings, this.#scratch)\n if (packed.some((value, i) => value !== this.#packed[i])) {\n this.#scratch = this.#packed\n this.#packed = packed\n this.#dirty = true\n }\n }\n\n // Back to the defaults\n reset(): void {\n this.set(DEFAULT_SETTINGS)\n }\n\n // Takes the source's picture again on the next render. Needed only for a still source whose pixels change: an\n // ImageBitmap, ImageData or VideoFrame. Videos, images and canvases are watched\n invalidate(): void {\n this.#feed?.invalidate()\n }\n\n // Draws the source keyed, if there's something new to draw: a new picture from it, or new settings. Cheap when\n // there's nothing new. Returns whether the canvas has a picture of the source\n render(): boolean {\n const renderer = this.#renderer\n const feed = this.#feed\n if (this.#disposed || !renderer || renderer.lost || !feed) return false\n let draw = this.#dirty\n if (feed.hasPicture() && feed.changed()) {\n const [width, height] = feed.size()\n try {\n renderer.upload(feed.source, width, height)\n feed.taken()\n this.#uploaded = true\n draw = true\n } catch (error) {\n // Nothing is drawn until a picture can be taken, so the canvas doesn't show another source's picture, or an\n // older one of this source's, as if it were this one. The handler is called last, so one that disposes the\n // keyer or gives it another source finds it settled\n this.#uploaded = false\n this.#ready = false\n if (feed.failed()) {\n renderer.clear()\n this.#onError(error)\n }\n return false\n }\n }\n if (!this.#uploaded || !draw) return this.#ready\n renderer.draw(this.#packed)\n this.#dirty = false\n this.#ready = true\n this.#frame += 1\n return true\n }\n\n // Renders on every animation frame until stop()\n start(): void {\n if (this.#loop || this.#disposed) return\n let handle = 0\n const step = () => {\n handle = schedule(step)\n this.render()\n }\n handle = schedule(step)\n this.#loop = { cancel: () => unschedule(handle) }\n }\n\n stop(): void {\n this.#loop?.cancel()\n this.#loop = null\n }\n\n // Frees the context or device's resources at once. The keyer draws no more, and its canvas can't be used again\n dispose(): void {\n if (this.#disposed) return\n this.stop()\n this.#disposed = true\n this.#feed?.dispose()\n this.#feed = null\n this.#renderer?.dispose()\n this.#renderer = null\n this.#ready = false\n }\n}\n\n// Gets the backend ready before the first keyer needs it: for 'auto', which backend it is, and for WebGPU, the device\n// and the pipeline, so a keyer made afterwards draws from its first render. Resolves with the backend that 'auto' or the\n// choice comes to. 'auto' always comes to one; WebGPU asked for by name rejects where it can't be had\nexport async function warmUp(backend: BackendChoice = 'auto'): Promise<BackendName> {\n const choice = backend === 'auto' ? ((await prefersWebGPU()) ? 'webgpu' : 'webgl') : backend\n if (choice === 'webgpu') pipelineFor(await requestDevice(), preferredFormat())\n return choice\n}\n\nfunction createCanvas(): Canvas {\n if (typeof document !== 'undefined') {\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n return canvas\n }\n if (typeof OffscreenCanvas !== 'undefined') return new OffscreenCanvas(1, 1)\n throw new Error('Greenscreen: there is no canvas to draw in here. Give it one with options.canvas')\n}\n\nfunction schedule(step: () => void): number {\n if (typeof requestAnimationFrame === 'function') return requestAnimationFrame(step)\n return setTimeout(step, FALLBACK_INTERVAL)\n}\n\nfunction unschedule(handle: number) {\n if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(handle)\n else clearTimeout(handle)\n}\n"],"mappings":"AAiBA,IAAaA,EAAK,CAAC,SAAW,SAAW,QAAU,OAAQ,EAC9CC,EAAK,CAAC,QAAU,SAAW,SAAW,OAAQ,EAG3D,SAAgBC,EAA6B,EAA8B,EAAW,CAEpF,GAAM,CAACC,EAAGC,EAAGC,GAAKC,EAASC,EAAS,QAAQ,EAC5C,EAAI,GAAKP,EAAG,GAAKG,EAAIH,EAAG,GAAKI,EAAIJ,EAAG,GAAKK,EAAIL,EAAG,GAChD,EAAI,GAAKC,EAAG,GAAKE,EAAIF,EAAG,GAAKG,EAAIH,EAAG,GAAKI,EAAIJ,EAAG,GAEhD,EAAI,GAAK,EAAI,KAAK,IAAI,KAAK,MAAMO,EAAI,GAAKR,EAAG,GAAIQ,EAAI,GAAKP,EAAG,EAAE,EAAG,IAAI,EACtE,EAAI,GAAK,KAAS,IAElB,EAAI,GAAKM,EAAS,WAAa,IAC/B,EAAI,GAAKA,EAAS,WAAa,IAC/B,EAAI,GAAKA,EAAS,MAAQ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,OADIqF,IAAW,UAAU3B,EAAY,MAAMZ,EAAc,EAAGiB,EAAgB,CAAC,EACtEsB,CACT,CAEA,SAASH,GAAuB,CAC9B,GAAI,OAAO,SAAa,IAAa,CACnC,IAAM9E,EAAS,SAAS,cAAc,QAAQ,EAG9C,MAFA,GAAO,MAAQ,EACf,EAAO,OAAS,EACTA,CACT,CACA,GAAI,OAAO,gBAAoB,IAAa,OAAO,IAAI,gBAAgB,EAAG,CAAC,EAC3E,MAAU,MAAM,kFAAkF,CACpG,CAEA,SAASoG,EAAS,EAA0B,CAE1C,OADI,OAAO,uBAA0B,WAAmB,sBAAsBD,CAAI,EAC3E,WAAWA,EAAMvB,CAAiB,CAC3C,CAEA,SAASyB,EAAW,EAAgB,CAC9B,OAAO,sBAAyB,WAAY,qBAAqBH,CAAM,EACtE,aAAaA,CAAM,CAC1B,C"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Greenscreen, warmUp } from './greenscreen.js';
|
|
2
|
+
export type { BackendChoice, GreenscreenOptions } from './greenscreen.js';
|
|
3
|
+
export { DEFAULT_SETTINGS, KEY_COLORS, RANGES } from './settings.js';
|
|
4
|
+
export type { NumericSetting, Point, Range, Settings } from './settings.js';
|
|
5
|
+
export type { BackendName, Source } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACpE,YAAY,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC3E,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/pack.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Settings } from './settings.js';
|
|
2
|
+
export declare const PACKED_LENGTH = 32;
|
|
3
|
+
export declare const CB: readonly [-0.100644, -0.338572, 0.439216, 0.501961];
|
|
4
|
+
export declare const CR: readonly [0.439216, -0.398942, -0.040274, 0.501961];
|
|
5
|
+
export declare function pack<T extends Float32Array>(settings: Readonly<Settings>, out: T): T;
|
|
6
|
+
export declare function channels(hex: number): [number, number, number];
|
|
7
|
+
//# sourceMappingURL=pack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAc7C,eAAO,MAAM,aAAa,KAAK,CAAA;AAG/B,eAAO,MAAM,EAAE,YAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;AACrE,eAAO,MAAM,EAAE,YAAI,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAU,CAAA;AAGrE,wBAAgB,IAAI,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAyCpF;AAGD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAE9D"}
|
package/dist/pack.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The settings as the shaders read them: eight sets of four numbers, a vec4 array in GLSL and a struct of vec4s in
|
|
2
|
+
// WGSL. Every shader works from these, so none of them can come to mean a setting differently. The first three hold
|
|
3
|
+
// what OBS's filter works from, worked out from the settings as OBS works it out; the rest are the add-ons' and the
|
|
4
|
+
// renderers'
|
|
5
|
+
// 0 key: its Cb and Cr, 1 / its chroma's distance from grey for hueSpill, the filter on
|
|
6
|
+
// 1 matte: similarity, smoothness and spill, each a thousandth of its setting, and opacity
|
|
7
|
+
// 2 correction: gamma's exponent, contrast's factor, brightness, unused
|
|
8
|
+
// 3 add-ons: tint's r, g and b in linear light, saturation
|
|
9
|
+
// 4 flags: flip, texture's rows bottom up, output linear, texture linear. The last three are the renderer's own
|
|
10
|
+
// 5 corners 0 and 1
|
|
11
|
+
// 6 corners 2 and 3
|
|
12
|
+
// 7 switches: crop on, hueSpill on, unused
|
|
13
|
+
export const PACKED_LENGTH = 32;
|
|
14
|
+
// A colour's Cb and Cr from its sRGB values, as OBS's filter has them: BT.709's, in studio range
|
|
15
|
+
export const CB = [-0.100644, -0.338572, 0.439216, 0.501961];
|
|
16
|
+
export const CR = [0.439216, -0.398942, -0.040274, 0.501961];
|
|
17
|
+
// Into out, which is PACKED_LENGTH long, and returned
|
|
18
|
+
export function pack(settings, out) {
|
|
19
|
+
// The key's chroma comes from its own sRGB values, as OBS takes them from the colour chosen
|
|
20
|
+
const [r, g, b] = channels(settings.keyColor);
|
|
21
|
+
out[0] = CB[0] * r + CB[1] * g + CB[2] * b + CB[3];
|
|
22
|
+
out[1] = CR[0] * r + CR[1] * g + CR[2] * b + CR[3];
|
|
23
|
+
// For hueSpill, the key's direction from grey, scaled to 1. A key on grey has none, and takes nothing out
|
|
24
|
+
out[2] = 1 / Math.max(Math.hypot(out[0] - CB[3], out[1] - CR[3]), 1e-3);
|
|
25
|
+
out[3] = settings.key ? 1 : 0;
|
|
26
|
+
out[4] = settings.similarity / 1000;
|
|
27
|
+
out[5] = settings.smoothness / 1000;
|
|
28
|
+
out[6] = settings.spill / 1000;
|
|
29
|
+
out[7] = settings.opacity;
|
|
30
|
+
// An exponent from 2 down to 1/2, and a factor from 1/5 up to 5, each 1 for no change, as OBS makes them
|
|
31
|
+
const { gamma, contrast } = settings;
|
|
32
|
+
out[8] = gamma < 0 ? 1 - gamma : 1 / (1 + gamma);
|
|
33
|
+
out[9] = contrast < 0 ? 1 / (1 - contrast) : 1 + contrast;
|
|
34
|
+
out[10] = settings.brightness;
|
|
35
|
+
out[11] = 0;
|
|
36
|
+
// The tint multiplies linear colour, so it's made linear too
|
|
37
|
+
const tint = channels(settings.tint);
|
|
38
|
+
out[12] = toLinear(tint[0]);
|
|
39
|
+
out[13] = toLinear(tint[1]);
|
|
40
|
+
out[14] = toLinear(tint[2]);
|
|
41
|
+
out[15] = settings.saturation;
|
|
42
|
+
out[16] = settings.flip ? 1 : 0;
|
|
43
|
+
out[17] = 0;
|
|
44
|
+
out[18] = 0;
|
|
45
|
+
out[19] = 0;
|
|
46
|
+
settings.corners.forEach((corner, i) => {
|
|
47
|
+
out[20 + i * 2] = corner.x;
|
|
48
|
+
out[21 + i * 2] = corner.y;
|
|
49
|
+
});
|
|
50
|
+
out[28] = settings.crop ? 1 : 0;
|
|
51
|
+
out[29] = settings.hueSpill ? 1 : 0;
|
|
52
|
+
out.fill(0, 30);
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
// A 0xrrggbb colour's channels, 0 to 1
|
|
56
|
+
export function channels(hex) {
|
|
57
|
+
return [((hex >> 16) & 0xff) / 255, ((hex >> 8) & 0xff) / 255, (hex & 0xff) / 255];
|
|
58
|
+
}
|
|
59
|
+
// sRGB's value to linear light
|
|
60
|
+
function toLinear(c) {
|
|
61
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055)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C,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAA;AACpF,CAAC;AAED,+BAA+B;AAC/B,SAAS,QAAQ,CAAC,CAAS;IACzB,OAAO,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,CAAA;AAChE,CAAC"}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import { Greenscreen as Keyer } from './greenscreen.js';
|
|
3
|
+
import type { BackendChoice } from './greenscreen.js';
|
|
4
|
+
import type { Settings } from './settings.js';
|
|
5
|
+
import type { Source } from './types.js';
|
|
6
|
+
export type { Greenscreen as Keyer } from './greenscreen.js';
|
|
7
|
+
export type { BackendChoice, GreenscreenOptions } from './greenscreen.js';
|
|
8
|
+
export { warmUp } from './greenscreen.js';
|
|
9
|
+
export { DEFAULT_SETTINGS, KEY_COLORS, RANGES } from './settings.js';
|
|
10
|
+
export type { NumericSetting, Point, Range, Settings } from './settings.js';
|
|
11
|
+
export type { BackendName, Source } from './types.js';
|
|
12
|
+
export interface UseGreenscreenOptions {
|
|
13
|
+
backend?: BackendChoice;
|
|
14
|
+
paused?: boolean;
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function useGreenscreen(source: Source | null | undefined, settings?: Readonly<Partial<Settings>>, options?: UseGreenscreenOptions): Keyer | null;
|
|
18
|
+
export interface GreenscreenProps extends UseGreenscreenOptions {
|
|
19
|
+
source: Source | null | undefined;
|
|
20
|
+
settings?: Readonly<Partial<Settings>>;
|
|
21
|
+
fit?: CSSProperties['objectFit'];
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: CSSProperties;
|
|
24
|
+
}
|
|
25
|
+
export declare const Greenscreen: import("react").ForwardRefExoticComponent<GreenscreenProps & import("react").RefAttributes<Keyer<HTMLCanvasElement> | null>>;
|
|
26
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMxC,YAAY,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC5D,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACpE,YAAY,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC3E,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,WAAW,qBAAqB;IAEpC,OAAO,CAAC,EAAE,aAAa,CAAA;IAEvB,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnC;AAcD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EACtC,OAAO,GAAE,qBAA0B,GAClC,KAAK,GAAG,IAAI,CAoCd;AAED,MAAM,WAAW,gBAAiB,SAAQ,qBAAqB;IAE7D,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAEjC,QAAQ,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEtC,GAAG,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAID,eAAO,MAAM,WAAW,8HAsBtB,CAAA"}
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// The keyer is an object outside React that these effects drive, as a canvas or a media element would be, not state
|
|
4
|
+
// to be copied, so setting its source and its canvas's style is what they're for. And this is a library's entry, which
|
|
5
|
+
// exports its hook and constants beside the component, as fast refresh, which wants components alone, isn't for it
|
|
6
|
+
/* oxlint-disable react/immutability, react/only-export-components */
|
|
7
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
8
|
+
import { Greenscreen as Keyer } from './greenscreen.js';
|
|
9
|
+
import { DEFAULT_SETTINGS } from './settings.js';
|
|
10
|
+
import { warnUnkeyable } from './source.js';
|
|
11
|
+
export { warmUp } from './greenscreen.js';
|
|
12
|
+
export { DEFAULT_SETTINGS, KEY_COLORS, RANGES } from './settings.js';
|
|
13
|
+
// The settings that are given, without the ones set to undefined, which go back to their defaults
|
|
14
|
+
function given(settings) {
|
|
15
|
+
const found = {};
|
|
16
|
+
if (!settings)
|
|
17
|
+
return found;
|
|
18
|
+
for (const key in settings)
|
|
19
|
+
if (settings[key] !== undefined)
|
|
20
|
+
found[key] = settings[key];
|
|
21
|
+
return found;
|
|
22
|
+
}
|
|
23
|
+
// A keyer keying source with settings, rendering on every animation frame unless paused. It's made after the first
|
|
24
|
+
// render, so the hook returns null until then, and disposed when the component unmounts
|
|
25
|
+
export function useGreenscreen(source, settings, options = {}) {
|
|
26
|
+
const { backend = 'auto', paused = false, onError } = options;
|
|
27
|
+
const [keyer, setKeyer] = useState(null);
|
|
28
|
+
// The latest handler, which the keyer calls through, so a new one doesn't make a new keyer. It's brought up to date
|
|
29
|
+
// after each render, before that render's source is given to the keyer
|
|
30
|
+
const handler = useRef(onError);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
handler.current = onError;
|
|
33
|
+
});
|
|
34
|
+
// Made in an effect, which StrictMode runs twice, so each mount has its own, disposed as it goes
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const made = new Keyer(null, { backend, onError: (error) => (handler.current ?? warnUnkeyable)(error) });
|
|
37
|
+
// oxlint-disable-next-line react/set-state-in-effect -- the keyer is made here, where it can be disposed
|
|
38
|
+
setKeyer(made);
|
|
39
|
+
return () => made.dispose();
|
|
40
|
+
}, [backend]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (keyer)
|
|
43
|
+
keyer.source = source ?? null;
|
|
44
|
+
}, [keyer, source]);
|
|
45
|
+
// On every render, the settings over the defaults, so one no longer given goes back. set() compares, and draws
|
|
46
|
+
// again only when something has changed
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
keyer?.set({ ...DEFAULT_SETTINGS, ...given(settings) });
|
|
49
|
+
});
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!keyer || paused)
|
|
52
|
+
return undefined;
|
|
53
|
+
keyer.start();
|
|
54
|
+
return () => keyer.stop();
|
|
55
|
+
}, [keyer, paused]);
|
|
56
|
+
return keyer;
|
|
57
|
+
}
|
|
58
|
+
// The keyed picture, in a div the canvas fills: size the div with className or style. See-through where the key and
|
|
59
|
+
// the cut take the picture out. The ref is the keyer, null until it's made after the first render
|
|
60
|
+
export const Greenscreen = forwardRef(function Greenscreen({ source, settings, backend, paused, onError, fit = 'contain', className, style }, ref) {
|
|
61
|
+
const keyer = useGreenscreen(source, settings, { backend, paused, onError });
|
|
62
|
+
const host = useRef(null);
|
|
63
|
+
useImperativeHandle(ref, () => keyer, [keyer]);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const element = host.current;
|
|
66
|
+
if (!element || !keyer)
|
|
67
|
+
return undefined;
|
|
68
|
+
const canvas = keyer.canvas;
|
|
69
|
+
canvas.style.display = 'block';
|
|
70
|
+
canvas.style.width = '100%';
|
|
71
|
+
canvas.style.height = '100%';
|
|
72
|
+
canvas.style.objectFit = fit ?? 'contain';
|
|
73
|
+
element.append(canvas);
|
|
74
|
+
return () => canvas.remove();
|
|
75
|
+
}, [keyer, fit]);
|
|
76
|
+
return _jsx("div", { ref: host, className: className, style: style });
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,oHAAoH;AACpH,uHAAuH;AACvH,mHAAmH;AACnH,qEAAqE;AAErE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpF,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAS3C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAepE,kGAAkG;AAClG,SAAS,KAAK,CAAmB,QAAuB;IACtD,MAAM,KAAK,GA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AC,OAAO,GAAG,OAAO,CAAA;QAC9B,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAA;QAC3B,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;QAC5B,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,IAAI,SAAS,CAAA;QACzC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACtB,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IAC9B,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;IAEhB,OAAO,cAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI,CAAA;AAC/D,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BackendName, Canvas, Source } from './types.js';
|
|
2
|
+
export interface Renderer {
|
|
3
|
+
readonly backend: BackendName;
|
|
4
|
+
readonly lost: boolean;
|
|
5
|
+
upload(source: Source, width: number, height: number): void;
|
|
6
|
+
draw(settings: Float32Array<ArrayBuffer>): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
dispose(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function tooLarge(width: number, height: number, backend: string, limit: number): RangeError;
|
|
11
|
+
export interface RendererEvents {
|
|
12
|
+
lost(): void;
|
|
13
|
+
restored(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function contextOf(canvas: Canvas, id: 'webgl2', options: WebGLContextAttributes): WebGL2RenderingContext | null;
|
|
16
|
+
export declare function contextOf(canvas: Canvas, id: 'webgpu'): GPUCanvasContext | null;
|
|
17
|
+
export declare function contextOf(canvas: Canvas, id: '2d'): Context2D | null;
|
|
18
|
+
export type Context2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
19
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAG7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;IAE7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IAEtB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAE3D,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,GAAG,IAAI,CAAA;IAE/C,KAAK,IAAI,IAAI,CAAA;IACb,OAAO,IAAI,IAAI,CAAA;CAChB;AAGD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAElG;AAGD,MAAM,WAAW,cAAc;IAE7B,IAAI,IAAI,IAAI,CAAA;IAEZ,QAAQ,IAAI,IAAI,CAAA;CACjB;AAID,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB,GAAG,sBAAsB,GAAG,IAAI,CAAA;AACvH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,gBAAgB,GAAG,IAAI,CAAA;AAChF,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,GAAG,SAAS,GAAG,IAAI,CAAA;AAmBrE,MAAM,MAAM,SAAS,GAAG,wBAAwB,GAAG,iCAAiC,CAAA"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// What upload() throws for a picture larger than the backend's textures
|
|
2
|
+
export function tooLarge(width, height, backend, limit) {
|
|
3
|
+
return new RangeError(`Greenscreen: the picture is ${width}×${height}, and ${backend} here takes up to ${limit} a side`);
|
|
4
|
+
}
|
|
5
|
+
export function contextOf(canvas, id, options) {
|
|
6
|
+
let context = null;
|
|
7
|
+
if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {
|
|
8
|
+
context = canvas.getContext(id, options);
|
|
9
|
+
}
|
|
10
|
+
else if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {
|
|
11
|
+
context = canvas.getContext(id, options);
|
|
12
|
+
}
|
|
13
|
+
if (id === 'webgl2')
|
|
14
|
+
return context instanceof WebGL2RenderingContext ? context : null;
|
|
15
|
+
if (id === '2d') {
|
|
16
|
+
if (typeof CanvasRenderingContext2D !== 'undefined' && context instanceof CanvasRenderingContext2D)
|
|
17
|
+
return context;
|
|
18
|
+
if (typeof OffscreenCanvasRenderingContext2D !== 'undefined' && context instanceof OffscreenCanvasRenderingContext2D) {
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return typeof GPUCanvasContext !== 'undefined' && context instanceof GPUCanvasContext ? context : null;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAgBA,wEAAwE;AACxE,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE,KAAa;IACpF,OAAO,IAAI,UAAU,CAAC,+BAA+B,KAAK,IAAI,MAAM,SAAS,OAAO,qBAAqB,KAAK,SAAS,CAAC,CAAA;AAC1H,CAAC;AAeD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,EAA8B,EAAE,OAAgC;IACxG,IAAI,OAAO,GAAY,IAAI,CAAA;IAC3B,IAAI,OAAO,iBAAiB,KAAK,WAAW,IAAI,MAAM,YAAY,iBAAiB,EAAE,CAAC;QACpF,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;SAAM,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,MAAM,YAAY,eAAe,EAAE,CAAC;QACvF,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;IACD,IAAI,EAAE,KAAK,QAAQ;QAAE,OAAO,OAAO,YAAY,sBAAsB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;IACtF,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QAChB,IAAI,OAAO,wBAAwB,KAAK,WAAW,IAAI,OAAO,YAAY,wBAAwB;YAAE,OAAO,OAAO,CAAA;QAClH,IAAI,OAAO,iCAAiC,KAAK,WAAW,IAAI,OAAO,YAAY,iCAAiC,EAAE,CAAC;YACrH,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,OAAO,gBAAgB,KAAK,WAAW,IAAI,OAAO,YAAY,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;AACxG,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Point {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
export interface Settings {
|
|
6
|
+
key: boolean;
|
|
7
|
+
keyColor: number;
|
|
8
|
+
similarity: number;
|
|
9
|
+
smoothness: number;
|
|
10
|
+
spill: number;
|
|
11
|
+
opacity: number;
|
|
12
|
+
contrast: number;
|
|
13
|
+
brightness: number;
|
|
14
|
+
gamma: number;
|
|
15
|
+
hueSpill: boolean;
|
|
16
|
+
flip: boolean;
|
|
17
|
+
crop: boolean;
|
|
18
|
+
corners: readonly Readonly<Point>[];
|
|
19
|
+
tint: number;
|
|
20
|
+
saturation: number;
|
|
21
|
+
}
|
|
22
|
+
export type NumericSetting = 'similarity' | 'smoothness' | 'spill' | 'opacity' | 'contrast' | 'brightness' | 'gamma' | 'saturation';
|
|
23
|
+
export interface Range {
|
|
24
|
+
readonly min: number;
|
|
25
|
+
readonly max: number;
|
|
26
|
+
readonly step: number;
|
|
27
|
+
}
|
|
28
|
+
export declare const RANGES: Readonly<Record<NumericSetting, Range>>;
|
|
29
|
+
export declare const KEY_COLORS: Readonly<{
|
|
30
|
+
green: number;
|
|
31
|
+
blue: number;
|
|
32
|
+
magenta: number;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const DEFAULT_SETTINGS: Readonly<Settings>;
|
|
35
|
+
export declare function mergeSettings(base: Readonly<Settings>, patch: Readonly<Partial<Settings>>): Readonly<Settings>;
|
|
36
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAMD,MAAM,WAAW,QAAQ;IAKvB,GAAG,EAAE,OAAO,CAAA;IAEZ,QAAQ,EAAE,MAAM,CAAA;IAEhB,UAAU,EAAE,MAAM,CAAA;IAElB,UAAU,EAAE,MAAM,CAAA;IAGlB,KAAK,EAAE,MAAM,CAAA;IAEb,OAAO,EAAE,MAAM,CAAA;IAEf,QAAQ,EAAE,MAAM,CAAA;IAEhB,UAAU,EAAE,MAAM,CAAA;IAElB,KAAK,EAAE,MAAM,CAAA;IAOb,QAAQ,EAAE,OAAO,CAAA;IAEjB,IAAI,EAAE,OAAO,CAAA;IAEb,IAAI,EAAE,OAAO,CAAA;IAGb,OAAO,EAAE,SAAS,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;IAGnC,IAAI,EAAE,MAAM,CAAA;IAGZ,U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