speedy-vision
Version:
GPU-accelerated Computer Vision for JavaScript
10 lines • 320 kB
JavaScript
/*!
* Speedy Vision version 0.9.0-wip
* GPU-accelerated Computer Vision for JavaScript
* Copyright 2020-2022 Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart)
* https://github.com/alemart/speedy-vision
*
* @license Apache-2.0
* Date: 2022-04-19T18:11:03.845Z
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Speedy=t():e.Speedy=t()}(self,(function(){return(()=>{var e={5137:(e,t,n)=>{"use strict";n.d(t,{N:()=>A});var i=n(4368),o=n(5484),s=n(3841);const r=Object.freeze({float32:Float32Array});class A{constructor(e,t,n){o.c.assert(e>0&&t>0),o.c.assert(n===A.DEFAULT_DTYPE),this._rows=0|e,this._columns=0|t,this._dtype=n}get rows(){return this._rows}get columns(){return this._columns}get dtype(){return this._dtype}static get DEFAULT_DTYPE(){return"float32"}static get BUFFER_TYPE(){return r}plus(e){return new u(this,e)}minus(e){return new I(this,e)}times(e){return"number"==typeof e?new p(this,e):new f(this,e)}transpose(){return new g(this)}inverse(){return new h(this)}compMult(e){return new m(this,e)}ldiv(e){return new C(this,e)}toString(){return`SpeedyMatrixExpr(rows=${this.rows}, columns=${this.columns})`}_evaluate(e,t){throw new s.Mi}}const{SpeedyMatrix:a}=n(8007);class c extends A{constructor(e,t,n){super(e,t,n),this._tempMatrix=a.Zeros(this.rows,this.columns,this.dtype)}}class l extends c{constructor(e,t,n){super(e,t,n.dtype),this._operand=n}_evaluate(e,t){const n=this._operand._evaluate(e,t),o=this._tempMatrix,s=i.r.allocateMat32(e,t,o),r=i.r.allocateMat32(e,t,n);return i.r.copyToMat32(e,t,r,n),this._compute(e,t,s,r),i.r.copyFromMat32(e,t,s,o),i.r.deallocateMat32(e,t,r),i.r.deallocateMat32(e,t,s),o}_compute(e,t,n,i){throw new s.Mi}}class d extends c{constructor(e,t,n,i){o.c.assert(n.dtype===i.dtype),super(e,t,n.dtype),this._left=n,this._right=i}_evaluate(e,t){const n=this._left._evaluate(e,t),o=this._right._evaluate(e,t),s=this._tempMatrix,r=i.r.allocateMat32(e,t,s),A=i.r.allocateMat32(e,t,n),a=i.r.allocateMat32(e,t,o);return i.r.copyToMat32(e,t,A,n),i.r.copyToMat32(e,t,a,o),this._compute(e,t,r,A,a),i.r.copyFromMat32(e,t,r,s),i.r.deallocateMat32(e,t,a),i.r.deallocateMat32(e,t,A),i.r.deallocateMat32(e,t,r),s}_compute(e,t,n,i,o){throw new s.Mi}}class g extends l{constructor(e){super(e.columns,e.rows,e)}_compute(e,t,n,i){e.exports.Mat32_transpose(n,i)}}class h extends l{constructor(e){o.c.assert(e.rows===e.columns),super(e.rows,e.columns,e),this._size=e.rows}_compute(e,t,n,i){switch(this._size){case 0:break;case 1:e.exports.Mat32_inverse1(n,i);break;case 2:e.exports.Mat32_inverse2(n,i);break;case 3:e.exports.Mat32_inverse3(n,i);break;default:e.exports.Mat32_qr_inverse(n,i)}}}class p extends l{constructor(e,t){super(e.rows,e.columns,e),this._scalar=+t}_compute(e,t,n,i){e.exports.Mat32_scale(n,i,this._scalar)}}class u extends d{constructor(e,t){o.c.assert(e.rows===t.rows&&e.columns===t.columns),super(e.rows,e.columns,e,t)}_compute(e,t,n,i,o){e.exports.Mat32_add(n,i,o)}}class I extends d{constructor(e,t){o.c.assert(e.rows===t.rows&&e.columns===t.columns),super(e.rows,e.columns,e,t)}_compute(e,t,n,i,o){e.exports.Mat32_subtract(n,i,o)}}class f extends d{constructor(e,t){o.c.assert(e.columns===t.rows),super(e.rows,t.columns,e,t)}_compute(e,t,n,i,o){e.exports.Mat32_multiply(n,i,o)}}class m extends d{constructor(e,t){o.c.assert(e.rows===t.rows&&e.columns===t.columns),super(t.rows,t.columns,e,t)}_compute(e,t,n,i,o){e.exports.Mat32_compmult(n,i,o)}}class C extends d{constructor(e,t){const n=e.rows,i=e.columns;o.c.assert(n>=i&&t.rows===n&&1===t.columns),super(i,1,e,t)}_compute(e,t,n,i,o){e.exports.Mat32_qr_ols(n,i,o,2)}}},4368:(e,t,n)=>{"use strict";n.d(t,{r:()=>g});var i=n(4500),o=n(3841),s=n(5484),r=n(3020);const A=n(4209);let a=null,c=null;const l={as:{object:d=new WebAssembly.Memory({initial:16,maximum:256}),uint8:new Uint8Array(d.buffer),int32:new Int32Array(d.buffer),uint32:new Uint32Array(d.buffer),float32:new Float32Array(d.buffer),float64:new Float64Array(d.buffer)}};var d;class g{static ready(){return new i.s(((e,t)=>{g._ready(e,t)}))}static get handle(){if(!a||!c)throw new o.IT("Can't get WASM handle: routines not yet loaded");return{wasm:a,memory:l,module:c}}static imports(e){const t=new h(e);return Object.getOwnPropertyNames(h.prototype).filter((e=>"function"==typeof t[e]&&"constructor"!==e)).reduce(((e,n)=>(e[n]=t[n],e)),Object.create(null))}static allocateMat32(e,t,n){const i=e.exports.malloc(n.data.byteLength);return e.exports.Mat32_create(n.rows,n.columns,n.step0,n.step1,n._data.length,i)}static deallocateMat32(e,t,n){const i=e.exports.Mat32_data(n);return e.exports.free(n),e.exports.free(i),0}static copyToMat32(e,t,n,i){s.c.assert(i.data.byteLength===e.exports.Mat32_dataSize(n));const o=e.exports.Mat32_data(n);return t.as.float32.set(i.data,o/Float32Array.BYTES_PER_ELEMENT),n}static copyFromMat32(e,t,n,i){s.c.assert(i.data.byteLength===e.exports.Mat32_dataSize(n));const o=e.exports.Mat32_data(n)/Float32Array.BYTES_PER_ELEMENT;for(let e=i.data.length-1;e>=0;e--)i.data[e]=t.as.float32[o+e];return n}static _ready(e,t,n=1e3){null!==a&&null!==c?e({wasm:a,memory:l,module:c}):n<=0?t(new o.W5("Can't load WASM routines")):setTimeout(g._ready,0,e,t,n-1)}}class h{constructor(e){return Object.getOwnPropertyNames(this.constructor.prototype).filter((e=>"function"==typeof this[e])).filter((e=>"constructor"!==e)).forEach((e=>{this[e]=this[e].bind(this)})),this.memory=e,this.cstring=new p(e),Object.freeze(this)}print(e){s.c.log(this.cstring.get(e))}fatal(e){throw new o.IT(this.cstring.get(e))}bytefill(e,t,n){this.memory.as.uint8.fill(e,t,n)}copyWithin(e,t,n){this.memory.as.uint8.copyWithin(e,t,n)}}class p{constructor(e){this._decoder=new TextDecoder("utf-8"),this._memory=e}get(e){const t=this._memory.as.uint8,n=this._memory.as.uint8.byteLength;let i=e;for(;i<n&&0!==t[i];)++i;return this._decoder.decode(t.subarray(e,i))}}!function(e){if(!r.LITTLE_ENDIAN)throw new o.B8("Can't run WebAssembly code: not in a little-endian machine!");i.s.resolve(A).then((e=>(e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))))(e))).then((t=>WebAssembly.instantiate(t,{env:{memory:e.as.object,...g.imports(e)}}))).then((e=>{a=e.instance,c=e.module,e.instance.exports.srand(.001*Date.now()&4294967295),s.c.log("The WebAssembly routines have been loaded!")})).catch((e=>{throw new o.IT(`Can't load the WebAssembly routines: ${e}`,e)}))}(l)},8007:(e,t,n)=>{"use strict";n.r(t),n.d(t,{SpeedyMatrix:()=>A});var i=n(5137),o=n(4368),s=n(4500),r=n(5484);class A extends i.N{constructor(e,t,n,o,s){super(e,t,i.N.DEFAULT_DTYPE),r.c.assert(s.constructor===i.N.BUFFER_TYPE[this.dtype]),r.c.assert(n>0&&o>=n),r.c.assert(s.length+e*t===0||s.length===1+n*(e-1)+o*(t-1)),this._step0=0|n,this._step1=0|o,this._data=s}static Create(e,t,n,o=i.N.DEFAULT_DTYPE){return r.c.assert(e*t>0,"Can't create a matrix without a shape"),r.c.assert(e*t===n.length,`Can't create matrix: expected ${e*t} entries, but found ${n.length}`),r.c.assert(Object.prototype.hasOwnProperty.call(i.N.BUFFER_TYPE,o),`Invalid dtype: "${o}"`),new A(e,t,1,e,Reflect.construct(i.N.BUFFER_TYPE[o],[n]))}static Zeros(e,t=e,n=i.N.DEFAULT_DTYPE){return r.c.assert(e*t>0,"Can't create a matrix without a shape"),r.c.assert(Object.prototype.hasOwnProperty.call(i.N.BUFFER_TYPE,n),`Invalid dtype: "${n}"`),new A(e,t,1,e,Reflect.construct(i.N.BUFFER_TYPE[n],[e*t]))}static Ones(e,t=e,n=i.N.DEFAULT_DTYPE){return r.c.assert(e*t>0,"Can't create a matrix without a shape"),r.c.assert(Object.prototype.hasOwnProperty.call(i.N.BUFFER_TYPE,n),`Invalid dtype: "${n}"`),new A(e,t,1,e,Reflect.construct(i.N.BUFFER_TYPE[n],[e*t]).fill(1))}static Eye(e,t=e,n=i.N.DEFAULT_DTYPE){r.c.assert(e*t>0,"Can't create a matrix without a shape"),r.c.assert(Object.prototype.hasOwnProperty.call(i.N.BUFFER_TYPE,n),`Invalid dtype: "${n}"`);const o=Reflect.construct(i.N.BUFFER_TYPE[n],[e*t]);for(let n=Math.min(e,t)-1;n>=0;n--)o[n*e+n]=1;return new A(e,t,1,e,o)}static From(e){return A.Zeros(e.rows,e.columns,e.dtype).setToSync(e)}static ready(){return o.r.ready().then((e=>{}))}get data(){return this._data}get step0(){return this._step0}get step1(){return this._step1}block(e,t,n,i){r.c.assert(e<=t&&n<=i,`Invalid indices: [${e}:${t},${n}:${i}]`),e=Math.max(e,0),t=Math.min(t,this._rows-1),n=Math.max(n,0);const o=t-e+1,s=(i=Math.min(i,this._columns-1))-n+1,a=this._step0,c=this._step1,l=e*a+n*c,d=1+t*a+i*c;return new A(o,s,a,c,this._data.subarray(l,d))}row(e){return this.block(e,e,0,this._columns-1)}column(e){return this.block(0,this._rows-1,e,e)}diagonal(){const e=Math.min(this._rows,this._columns),t=e,n=this._step0+this._step1,i=1+(e-1)*n;return new A(t,1,n,n,this._data.subarray(0,i))}at(e,t){return e>=0&&e<this._rows&&t>=0&&t<this._columns?this._data[this._step0*e+this._step1*t]:Number.NaN}read(){const e=new Array(this._rows*this._columns),t=this._step0,n=this._step1;let i=0;for(let o=0;o<this._columns;o++)for(let s=0;s<this._rows;s++)e[i++]=this._data[s*t+o*n];return e}toString(){const e=this.rows,t=this.columns,n=this.read(),i=new Array(e);for(let o=0;o<e;o++){i[o]=new Array(t);for(let s=0;s<t;s++)i[o][s]=n[s*e+o]}const o=e=>e.toFixed(5);return`SpeedyMatrix(rows=${e}, columns=${t}, data=[\n${i.map((e=>" "+e.map(o).join(", "))).join(",\n")}\n])`}setTo(e){return o.r.ready().then((t=>this.setToSync(e)))}setToSync(e){const{wasm:t,memory:n}=o.r.handle,i=e._evaluate(t,n);r.c.assert(this._rows===i._rows&&this._columns===i._columns&&this.dtype===i.dtype,`Can't set the values of a ${this.rows} x ${this.columns} ${this.dtype} matrix to those of a ${i.rows} x ${i.columns} ${i.dtype} matrix`);const s=this._step0,A=this._step1,a=i._step0,c=i._step1;if(s===a&&A===c&&this._data.length===i._data.length)this._data.set(i._data);else for(let e=this._columns-1;e>=0;e--)for(let t=this._rows-1;t>=0;t--)this._data[t*s+e*A]=i._data[t*a+e*c];return this}fill(e){return this.fillSync(e),s.s.resolve(this)}fillSync(e){if(e=+e,this._rows*this._columns===this._data.length)return this._data.fill(e),this;for(let t=0;t<this._columns;t++)for(let n=0;n<this._rows;n++)this._data[n*this._step0+t*this._step1]=e;return this}_evaluate(e,t){return this}}},4500:(e,t,n)=>{"use strict";n.d(t,{s:()=>o});const i="undefined"!=typeof queueMicrotask&&queueMicrotask||"undefined"!=typeof process&&process.nextTick||(e=>Promise.resolve().then((()=>e())));class o{constructor(e){this._state=0,this._value=void 0,this._onFulfillment=null,this._onRejection=null,this._children=0,this[0]=this,this._parent=void 0,this._flags=0,this._fulfill=this._fulfill.bind(this),this._reject=this._reject.bind(this),this._resolve=this._resolve.bind(this),this._broadcastIfAsync=this._broadcastIfAsync.bind(this),e(this._fulfill,this._reject)}then(e,t=null){const n=new o(this._nop);return n._onFulfillment="function"==typeof e&&e,n._onRejection="function"==typeof t&&t,n._parent=this,this[this._children++]=n,this._flags&=-2,this._notify(),n}catch(e){return this.then(null,e)}finally(e){const t=t=>(e(),t);return this.then(t,t)}turbocharge(){let e=this;for(this._flags|=1;void 0!==e._parent;)e=e._parent,e._flags|=1;return e._notify(),this}toString(){switch(this._state){case 0:return"SpeedyPromise { <pending> }";case 1:return`SpeedyPromise { <fulfilled> ${this._value} }`;case 2:return`SpeedyPromise { <rejected> ${this._value} }`;default:return""}}get[Symbol.toStringTag](){return"SpeedyPromise"}static resolve(e){const t=new o(this._snop);return"object"==typeof e&&null!==e&&"then"in e||"function"==typeof e&&"then"in e?t._resolve(e):(t._value=e,t._state=1),t}static reject(e){const t=new o(this._snop);return t._value=e,t._state=2,t}static all(e){return new o(((t,n)=>{const i=[];for(const t of e)i.push(t);const s=i.length;if(0==s)return void t([]);let r=s;const A=new Array(s),a=e=>n=>{A[e]=n,0==--r&&t(A)};for(let e=0;e<s;e++){const t=i[e];t.__proto__===o.prototype||t.__proto__===Promise.prototype?t.then(a(e),n):o.resolve(t).then(a(e),n)}}))}static race(e){return new o(((t,n)=>{const i=[];for(const t of e)i.push(t);const s=i.length;for(let e=0;e<s;e++){const s=i[e];s.__proto__===o.prototype||s.__proto__===Promise.prototype?s.then(t,n):o.resolve(s).then(t,n)}}))}_fulfill(e){this._setState(1,e)}_reject(e){this._setState(2,e)}_setState(e,t){0==this._state&&(this._state=e,this._value=t,this._notify())}_notify(){0!=this._state&&(1&this._flags?this._broadcast():i(this._broadcastIfAsync))}_broadcastIfAsync(){1&this._flags||this._broadcast()}_broadcast(){const e=this._children,t=this._state;if(1===t)for(let t=0;t<e;t++){const e=this[t],n=e._onFulfillment;try{n?n!==e._nop&&(e._resolve(n(this._value)),e._onFulfillment=e._nop):e._fulfill(this._value)}catch(t){e._reject(t)}}else if(2===t)for(let t=0;t<e;t++){const e=this[t],n=e._onRejection;try{n?n!==e._nop&&(e._resolve(n(this._value)),e._onRejection=e._nop):e._reject(this._value)}catch(t){e._reject(t)}}}_resolve(e){if("object"!=typeof e&&"function"!=typeof e||null===e)this._fulfill(e);else{if(e===this)throw new TypeError;if(e.__proto__!==o.prototype&&e.__proto__!==Promise.prototype)try{const t=e.then;if("function"==typeof t){let n=this._resolve,i=this._reject;try{t.call(e,(e=>{n(e),n=i=this._nop}),(e=>{i(e),n=i=this._nop}))}catch(e){n!==this._nop&&i!==this._nop&&this._reject(e)}}else this._fulfill(e)}catch(e){this._reject(e)}else e.then(this._resolve,this._reject)}}_nop(){}static _snop(){}}},9759:(e,t,n)=>{"use strict";n.d(t,{ef:()=>P,Nt:()=>S});var i=n(5484),o=n(6731),s=n(3841);const r=n(3020),A=Object.keys(r).filter((e=>"number"==typeof r[e])).reduce(((e,t)=>(e[t]=r[t],e)),{}),a=Object.freeze({...A,FS_USE_CUSTOM_PRECISION:0,FS_OUTPUT_TYPE:0,PIXELCOMPONENT_RED:o.hE.RED,PIXELCOMPONENT_GREEN:o.hE.GREEN,PIXELCOMPONENT_BLUE:o.hE.BLUE,PIXELCOMPONENT_ALPHA:o.hE.ALPHA}),c=[/\/\*(.|\s)*?\*\//g,/\/\/.*$/gm],l=/^\s*@\s*include\s+"(.*?)"/gm,d=/@(\w+)@/g,g=[/@\s*unroll\s+?for\s*\(\s*(int|)\s*(?<counter>\w+)\s*=\s*(-?\d+|\w+)\s*;\s*\k<counter>\s*(<=?)\s*(-?\d+|\w+)\s*;\s*\k<counter>\s*\+\+()\s*\)\s*\{\s*([\s\S]+?)\s*\}/g,/@\s*unroll\s+?for\s*\(\s*(int|)\s*(?<counter>\w+)\s*=\s*(-?\d+|\w+)\s*;\s*\k<counter>\s*(<=?)\s*(-?\d+|\w+)\s*;\s*\k<counter>\s*\+=\s*(-?\d+)\s*\)\s*\{\s*([\s\S]+?)\s*\}/g];class h{static run(e,t=new Map){const n=[];return function(e,t){const n=u.bind(t),i=g.length;for(let t=0;t<i;t++)e=e.replace(g[t],n);return e}(String(e).replace(c[0],"").replace(c[1],"").replace(l,((e,n)=>h.run(p(n),t))).replace(d,((e,i)=>String(t.has(i)?Number(t.get(i)):void 0!==a[i]?Number(a[i]):(n.push(`Undefined constant: ${i}`),0)))),t)+(n.length>0?n.map((e=>`\n#error ${e}\n`)).join(""):"")}}function p(e){if(String(e).match(/^[a-zA-Z0-9_-]+\.glsl$/))return n(524)("./"+e);throw new s.Xg(`Shader preprocessor: can't read file "${e}"`)}function u(e,t,n,o,r,A,a,c){const l=this,d=Number.isFinite(+o)||l.has(o),g=Number.isFinite(+A)||l.has(A);if(!d||!g){if(l.size>0)throw new s.D3(`Can't unroll loop: unknown limits (start=${o}, end=${A}). Code:\n\n${e}`);return e}let h=l.has(o)?l.get(o):parseInt(o),p=l.has(A)?l.get(A):parseInt(A),u=0==a.length?1:parseInt(a);i.c.assert(h<=p&&u>0);let I=null!==c.match(/\bbreak\s*;/)?"switch(1) { default:\n":"{\n";I+=`${t} ${n};\n`,p+="<="==r?1:0;for(let e=h;e<p;e+=u)I+=`{\n${n} = ${e};\n${c}\n}\n`;return I+="}\n",I}const I=Object.freeze({position:"a_position",texCoord:"a_texCoord"}),f=Object.freeze({position:0,texCoord:1}),m=`#version 300 es\nprecision highp float;\nprecision highp int;\n\nlayout (location=${f.position}) in vec2 ${I.position};\nlayout (location=${f.texCoord}) in vec2 ${I.texCoord};\nout highp vec2 texCoord;\nuniform highp vec2 texSize;\n\n#define vsinit() gl_Position = vec4(${I.position}, 0.0f, 1.0f); texCoord = ${I.texCoord};\n\n\n`,C="#define vsmain() ;",E="\n\nvoid main() { vsinit(); vsmain(); }\n",x='#version 300 es\n\n#if @FS_USE_CUSTOM_PRECISION@ == 0\nprecision mediump float; // ~float16\nprecision mediump sampler2D;\nprecision highp int; // int32\n#endif\n\n#if @FS_OUTPUT_TYPE@ == 0\n#define OUT_TYPE mediump vec4\n#elif @FS_OUTPUT_TYPE@ == 1\n#define OUT_TYPE mediump ivec4\n#elif @FS_OUTPUT_TYPE@ == 2\n#define OUT_TYPE mediump uvec4\n#else\n#error Unknown FS_OUTPUT_TYPE\n#endif\n\nout OUT_TYPE color;\nin highp vec2 texCoord;\nuniform highp vec2 texSize;\n\n@include "global.glsl"\n\n',y=Symbol();class _{constructor(e,t){if(t!==y)throw new s.js;this._source=(()=>{switch(e.type){case"filepath":return n(2863)("./"+e.filepath);case"source":return e.source;default:return""}})(),this._vssource=(()=>{switch(e.type){case"filepath":return e.vsfilepath?n(2863)("./"+e.vsfilepath):C;case"source":return e.vssource?e.vssource:C;default:return""}})(),this._fragmentSource=h.run(x+this._source),this._vertexSource=h.run(m+this._vssource+E),this._filepath="filepath"===e.type?e.filepath:"<in-memory>",this._vsfilepath="filepath"===e.type&&e.vsfilepath?e.vsfilepath:"<in-memory>",this._arguments=[],this._uniforms=this._autodetectUniforms(this._fragmentSource+"\n"+this._vertexSource),this._defines=new Map}static create(e,t=null){return new _({type:"source",source:e,vssource:t},y)}static import(e,t=null){if(!String(e).match(/^[a-zA-Z0-9_\-/]+\.glsl$/))throw new s.Xg(`Can't import fragment shader at "${e}"`);if(null!=t&&!String(t).match(/^[a-zA-Z0-9_\-/]+\.vs\.glsl$/))throw new s.Xg(`Can't import vertex shader at "${t}"`);return new _({type:"filepath",filepath:e,vsfilepath:t},y)}withArguments(...e){if(this._arguments.length>0)throw new s.js("Redefinition of shader arguments");this._arguments=e.map((e=>String(e)));for(const e of this._arguments)if(!this._uniforms.has(e)&&!this._uniforms.has(e+"[0]"))throw new s.mG(`Argument "${e}" has not been declared in the shader`);return this}withDefines(e){if(this._defines.size>0)throw new s.js("Redefinition of externally defined constants of a shader");const t=[],n=Object.keys(e);for(const i of n){const n=Number(e[i]);this._defines.set(i,n),t.push(`#define ${i} ${n}\n`)}const i=x+t.join("")+this._source,o=m+t.join("")+this._vssource+E;return this._fragmentSource=h.run(i,this._defines),this._vertexSource=h.run(o,this._defines),this._uniforms=this._autodetectUniforms(this._fragmentSource+"\n"+this._vertexSource),this}get fragmentSource(){return this._fragmentSource}get vertexSource(){return this._vertexSource}get attributes(){return I}get locationOfAttributes(){return f}get arguments(){return this._arguments}get uniforms(){return Array.from(this._uniforms.keys())}uniformType(e){if(!this._uniforms.has(e))throw new s.mG(`Unrecognized uniform variable: "${e}"`);return this._uniforms.get(e)}definedConstant(e){if(!this._defines.has(e))throw new s.mG(`Unrecognized externally defined constant: "${e}"`);return this._defines.get(e)}_autodetectUniforms(e){const t=e,n=/^\s*uniform\s+(highp\s+|mediump\s+|lowp\s+)?(\w+)\s+([^;]+)/gm,i=new Map;let o;for(;null!==(o=n.exec(t));){const e=o[2],t=o[3].split(",").map((e=>e.trim())).filter((e=>e));for(const n of t)if(n.endsWith("]")){if(!(o=n.match(/(\w+)\s*\[\s*(\d+)\s*\]$/)))throw new s.D3(`Unspecified array length for uniform "${n}" in the shader`);const[t,r]=[o[1],Number(o[2])];for(let n=0;n<r;n++)i.set(`${t}[${n}]`,e)}else{if(i.has(n)&&i.get(n)!==e)throw new s.js(`Redefinition of uniform "${n}" in the shader`);i.set(n,e)}}return i}}function S(e,t=null){return _.import(e,t)}function P(e,t=null){return _.create(e,t)}},6776:(e,t,n)=>{"use strict";n.r(t),n.d(t,{conv2D:()=>r,convX:()=>A,convY:()=>a});var i=n(9759),o=n(5484),s=n(3841);function r(e,t=1){const n=new Float32Array(e.map((e=>+e*+t))),r=0|Math.sqrt(n.length),A=r>>1;if(r<1||r%2==0)throw new s.mG(`Can't perform a 2D convolution with an invalid kSize of ${r}`);if(r*r!=n.length)throw new s.mG(`Invalid 2D convolution kernel of ${n.length} elements (expected: square)`);const a=A<=7?"pixelAtShortOffset":"pixelAtLongOffset",c=`\n uniform sampler2D image;\n\n void main()\n {\n float alpha = threadPixel(image).a;\n vec4 result = vec4(0.0f);\n\n ${l=(e,t,n)=>`\n result += ${a}(image, ivec2(${0|-n}, ${0|-t})) * float(${+e});\n `,o.c.cartesian(o.c.symmetricRange(A),o.c.symmetricRange(A)).map((e=>l(n[(e[0]+A)*r+(e[1]+A)],e[0],e[1]))).join("\n")}\n\n color = vec4(result.rgb, alpha);\n }\n `;var l;return(0,i.ef)(c).withArguments("image")}function A(e,t=1){return c("x",e,t)}function a(e,t=1){return c("y",e,t)}function c(e,t,n=1){const r=new Float32Array(t.map((e=>+e*+n))),A=r.length,a=A>>1;if(A<1||A%2==0)throw new s.mG(`Can't perform a 1D convolution with an invalid kSize of ${A}`);if("x"!=e&&"y"!=e)throw new s.mG(`Can't perform 1D convolution: invalid axis "${e}"`);const c=a<=7?"pixelAtShortOffset":"pixelAtLongOffset",l=`\n uniform sampler2D image;\n\n void main()\n {\n float alpha = threadPixel(image).a;\n vec4 pixel = vec4(0.0f);\n\n ${d=(t,n)=>"x"==e?`\n pixel += ${c}(image, ivec2(${0|-n}, 0)) * float(${+t});\n `:`\n pixel += ${c}(image, ivec2(0, ${0|-n})) * float(${+t});\n `,o.c.symmetricRange(a).reduce(((e,t)=>e+d(r[t+a],t)),"")}\n\n color = vec4(pixel.rgb, alpha);\n }\n `;var d;return(0,i.ef)(l).withArguments("image")}},524:(e,t,n)=>{var i={"./colors.glsl":2545,"./filters.glsl":7373,"./fixed-point.glsl":2229,"./float16.glsl":919,"./global.glsl":3815,"./int32.glsl":1830,"./keypoint-descriptors.glsl":1364,"./keypoint-matches.glsl":4004,"./keypoints.glsl":8714,"./math.glsl":9010,"./pyramids.glsl":6433,"./subpixel.glsl":4697};function o(e){var t=s(e);return n(t)}function s(e){if(!n.o(i,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return i[e]}o.keys=function(){return Object.keys(i)},o.resolve=s,e.exports=o,o.id=524},2863:(e,t,n)=>{var i={"./filters/convolution":6776,"./filters/convolution.js":6776,"./filters/convolution1d.glsl":4645,"./filters/convolution2d.glsl":6942,"./filters/fast-median.glsl":7054,"./filters/nightvision.glsl":8961,"./filters/normalize-image.glsl":9571,"./filters/rgb2grey.glsl":8466,"./include/colors.glsl":2545,"./include/filters.glsl":7373,"./include/fixed-point.glsl":2229,"./include/float16.glsl":919,"./include/global.glsl":3815,"./include/int32.glsl":1830,"./include/keypoint-descriptors.glsl":1364,"./include/keypoint-matches.glsl":4004,"./include/keypoints.glsl":8714,"./include/math.glsl":9010,"./include/pyramids.glsl":6433,"./include/subpixel.glsl":4697,"./keypoints/allocate-descriptors.glsl":2289,"./keypoints/allocate-extra.glsl":5725,"./keypoints/apply-homography.glsl":3801,"./keypoints/bf-knn.glsl":2346,"./keypoints/clip-border.glsl":4180,"./keypoints/clip.glsl":7771,"./keypoints/distance-filter.glsl":8938,"./keypoints/encode-keypoint-long-offsets.glsl":4802,"./keypoints/encode-keypoint-offsets.glsl":6253,"./keypoints/encode-keypoint-positions.glsl":384,"./keypoints/encode-keypoint-properties.glsl":500,"./keypoints/encode-keypoints.glsl":3673,"./keypoints/encode-null-keypoints.glsl":1703,"./keypoints/fast.glsl":2633,"./keypoints/fast.vs.glsl":535,"./keypoints/hamming-distance-filter.glsl":3232,"./keypoints/harris-cutoff.glsl":8356,"./keypoints/harris.glsl":7339,"./keypoints/knn-init.glsl":3177,"./keypoints/knn-transfer.glsl":2769,"./keypoints/laplacian.glsl":2006,"./keypoints/lk.glsl":3329,"./keypoints/lookup-of-locations.glsl":4251,"./keypoints/lookup-of-locations.vs.glsl":4747,"./keypoints/lsh-knn.glsl":7421,"./keypoints/mix-keypoints.glsl":4523,"./keypoints/nonmax-scale.glsl":2277,"./keypoints/nonmax-space.glsl":8430,"./keypoints/nonmax-suppression.glsl":9743,"./keypoints/orb-descriptor.glsl":3464,"./keypoints/orb-orientation.glsl":7184,"./keypoints/refine-scale.glsl":7220,"./keypoints/score-findmax.glsl":805,"./keypoints/shuffle.glsl":8736,"./keypoints/sort-keypoints.glsl":9311,"./keypoints/subpixel-refinement.glsl":9423,"./keypoints/transfer-flow.glsl":2060,"./keypoints/transfer-orientation.glsl":5463,"./keypoints/transfer-to-extra.glsl":6986,"./keypoints/upload-keypoints.glsl":3179,"./pyramids/downsample2.glsl":8680,"./pyramids/upsample2.glsl":3384,"./transforms/additive-mix.glsl":1976,"./transforms/resize.glsl":4543,"./transforms/warp-perspective.glsl":6296,"./utils/copy-components.glsl":747,"./utils/copy-raster.glsl":9176,"./utils/copy.glsl":8960,"./utils/fill-components.glsl":3294,"./utils/fill.glsl":1959,"./utils/flip-y.vs.glsl":7290,"./utils/scan-minmax2d.glsl":7270,"./utils/sobel-derivatives.glsl":48,"./utils/sobel-derivatives.vs.glsl":3713};function o(e){var t=s(e);return n(t)}function s(e){if(!n.o(i,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return i[e]}o.keys=function(){return Object.keys(i)},o.resolve=s,e.exports=o,o.id=2863},3841:(e,t,n)=>{"use strict";n.d(t,{B8:()=>o,Ql:()=>s,Mi:()=>r,mG:()=>A,js:()=>a,Cx:()=>c,Xg:()=>l,W5:()=>d,D3:()=>g,ps:()=>h,$y:()=>p,IT:()=>u});class i extends Error{constructor(e,t=null){super([e,t?t.toString():"[speedy-vision.js]"].join("\n-> ")),this._cause=t}get name(){return this.constructor.name}set name(e){}get cause(){return this._cause}}class o extends i{constructor(e="",t=null){super(`Unsupported operation. ${e}`,t)}}class s extends i{constructor(e="",t=null){super(`WebGL error. ${e}`,t)}static from(e){const t=e.getError(),n=["NO_ERROR","INVALID_ENUM","INVALID_VALUE","INVALID_OPERATION","INVALID_FRAMEBUFFER_OPERATION","OUT_OF_MEMORY","CONTEXT_LOST_WEBGL"].find((n=>e[n]==t))||"Unknown";return new s(n)}}class r extends i{constructor(e="",t=null){super(`Can't call abstract method. ${e}`,t)}}class A extends i{constructor(e="",t=null){super(`Illegal argument. ${e}`,t)}}class a extends i{constructor(e="",t=null){super(`Illegal operation. ${e}`,t)}}class c extends i{constructor(e="",t=null){super(`Out of memory. ${e}`,t)}}class l extends i{constructor(e="",t=null){super(`File not found. ${e}`,t)}}class d extends i{constructor(e="",t=null){super(`Timeout error. ${e}`,t)}}class g extends i{constructor(e="",t=null){super(`Parse error. ${e}`,t)}}class h extends i{constructor(e="",t=null){super(`Assertion failed. ${e}`,t)}}class p extends i{constructor(e="",t=null){super(`Access denied. ${e}`,t)}}class u extends i{constructor(e="",t=null){super(`WebAssembly error. ${e}`,t)}}},3020:(e,t,n)=>{"use strict";n.r(t),n.d(t,{PYRAMID_MAX_LEVELS:()=>i,LOG2_PYRAMID_MAX_SCALE:()=>o,PYRAMID_MAX_SCALE:()=>s,FIX_BITS:()=>r,FIX_RESOLUTION:()=>A,MAX_TEXTURE_LENGTH:()=>a,MIN_KEYPOINT_SIZE:()=>c,MIN_ENCODER_LENGTH:()=>l,MAX_ENCODER_CAPACITY:()=>d,DEFAULT_ENCODER_CAPACITY:()=>g,LOG2_MAX_DESCRIPTOR_SIZE:()=>h,MAX_DESCRIPTOR_SIZE:()=>p,MATCH_INDEX_BITS:()=>u,MATCH_INDEX_MASK:()=>I,MATCH_MAX_INDEX:()=>f,MATCH_MAX_DISTANCE:()=>m,LITTLE_ENDIAN:()=>C});const i=8,o=0,s=1<<o,r=3,A=1<<r,a=(1<<16-r)-1,c=8,l=2,d=8192,g=2048,h=6,p=1<<h,u=32-(h+3),I=(1<<u)-1,f=(1<<u)-1,m=(1<<32-u)-1,C=51966===new Uint16Array(new Uint8Array([254,202]).buffer)[0]},6731:(e,t,n)=>{"use strict";n.d(t,{DD:()=>i,D3:()=>o,hE:()=>s,rY:()=>r});const i=Object.freeze({Image:Symbol("Image"),Video:Symbol("Video"),Canvas:Symbol("Canvas"),Bitmap:Symbol("Bitmap")}),o=Object.freeze({RGBA:Symbol("RGBA"),GREY:Symbol("GREY")}),s=Object.freeze({RED:1,GREEN:2,BLUE:4,ALPHA:8,ALL:15}),r=Object.freeze({[s.RED]:0,[s.GREEN]:1,[s.BLUE]:2,[s.ALPHA]:3})},5484:(e,t,n)=>{"use strict";n.d(t,{c:()=>s});var i=n(3841),o=n(4500);class s{static warning(e,...t){console.warn("[speedy-vision]",e,...t)}static log(e,...t){console.log("[speedy-vision]",e,...t)}static assert(e,t=""){if(!e)throw new i.ps(t)}static functionArguments(e){const t=e.toString(),n=t.startsWith("function")?"function\\s.*\\(([^)]*)\\)":t.startsWith("(")?"\\(([^)]*)\\).*=>":"([^=]+).*=>",o=new RegExp(n).exec(t);if(null!==o){return o[1].replace(/\/\*.*?\*\//g,"").split(",").map((e=>e.replace(/=.*$/,"").trim())).filter((e=>e))}throw new i.D3(`Can't detect function arguments of ${t}`)}static getAllPropertyDescriptors(e){if(e){const t=Object.getPrototypeOf(e);return{...s.getAllPropertyDescriptors(t),...Object.getOwnPropertyDescriptors(e)}}return Object.create(null)}static createCanvas(e,t){const n=document.createElement("canvas");return n.width=e,n.height=t,n}static gaussianNoise(e=0,t=1){const n=2*Math.PI;let i,o=Math.random();do{i=Math.random()}while(i<=Number.EPSILON);return Math.sqrt(-2*Math.log(i))*Math.sin(n*o)*t+e}static gaussianKernel(e,t=0,n=!0){if(0==t&&(t=0|Math.ceil(5*e),t+=1-t%2),(t|=0)<1||t%2==0)throw new i.mG(`Invalid kernel size given to gaussianKernel: ${t} x 1`);if(e<=0)throw new i.mG(`Invalid sigma given to gaussianKernel: ${e}`);const o=new Array(t),s=t>>1,r=1.4142135623730951*+e,A=.3275911,a=.254829592,c=-.284496736,l=1.421413741,d=-1.453152027,g=1.061405429;let h=0;for(let e=0;e<t;e++){let t=(e-s+.5)/r,n=(e-s-.5)/r,i=1,p=1;t<0&&(i=-1,t=-t),n<0&&(p=-1,n=-n);const u=1/(1+A*t),I=1/(1+A*n),f=((((g*I+d)*I+l)*I+c)*I+a)*I,m=(i*(1-((((g*u+d)*u+l)*u+c)*u+a)*u*Math.exp(-t*t))-p*(1-f*Math.exp(-n*n)))/(2*r);o[e]=m,h+=m}if(n)for(let e=0;e<t;e++)o[e]/=h;return o}static kernel2d(e,t=e){const n=e.length;s.assert(e.length==e.length),s.assert(n>=1&&n%2==1);let i=new Array(n*n),o=0;for(let s=0;s<n;s++)for(let r=0;r<n;r++)i[o++]=e[r]*t[s];return i}static cartesian(e,t){return[].concat(...e.map((e=>t.map((t=>[e,t])))))}static symmetricRange(e){if((e|=0)<0)throw new i.mG("Expected a non-negative integer as input");return[...Array(2*e+1).keys()].map((t=>t-e))}static range(e){if((e|=0)<=0)throw new i.mG("Expected a positive integer as input");return[...Array(e).keys()]}static shuffle(e){const t=e.length,n=t-1;for(let i=0;i<n;i++){const n=i+(Math.random()*(t-i)|0);if(i!==n){const t=e[i];e[i]=e[n],e[n]=t}}return e}static flatten(e){const t=[];for(let n=0,i=e.length;n<i;n++){const i=e[n];if(Array.isArray(i))for(let e=0,n=i.length;e<n;e++)t.push(i[e]);else t.push(i)}return t}static decodeFloat16(e){const t=(32767&e)>>10,n=1023&e,i=1-2*((65535&e)>>15);if(0==t)return 0==n?0*i:i*n*5.960464477539063e-8;if(31==t)return 0==n?i*Number.POSITIVE_INFINITY:Number.NaN;return i*(t>=15?1<<t-15:1/(1<<15-t))*(1+.0009765625*n)}static requestCameraStream(e={audio:!1,video:!0}){if(s.log("Accessing the webcam..."),!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new i.B8("Unsupported browser: no mediaDevices.getUserMedia()");return new o.s(((t,n)=>{navigator.mediaDevices.getUserMedia(e).then((e=>{const n=document.createElement("video");n.onloadedmetadata=()=>{n.play(),s.log(`The camera is on! Resolution: ${n.videoWidth} x ${n.videoHeight}`),t(n)},n.srcObject=e})).catch((e=>{n(new i.$y("Please give access to the camera and reload the page",e))}))}))}}},4645:e=>{e.exports="#if !defined(KERNEL_SIZE) || !defined(AXIS) || (AXIS != 0 && AXIS != 1)\n#error Undefined KERNEL_SIZE / AXIS\n#endif\nuniform sampler2D image;\nuniform float kernel[@KERNEL_SIZE@];\nconst ivec2 axis = ivec2(1-AXIS, AXIS);\n#define S(x,k) result += pixelAtShortOffset(image, ivec2((x),(x)) * axis) * kernel[k]\nvoid main()\n{\nvec4 result = vec4(0.0f);\n#if KERNEL_SIZE == 3\nS(-1, 2);\nS( 0, 1);\nS( 1, 0);\n#elif KERNEL_SIZE == 5\nS(-2, 4);\nS(-1, 3);\nS( 0, 2);\nS( 1, 1);\nS( 2, 0);\n#elif KERNEL_SIZE == 7\nS(-3, 6);\nS(-2, 5);\nS(-1, 4);\nS( 0, 3);\nS( 1, 2);\nS( 2, 1);\nS( 3, 0);\n#elif KERNEL_SIZE == 9\nS(-4, 8);\nS(-3, 7);\nS(-2, 6);\nS(-1, 5);\nS( 0, 4);\nS( 1, 3);\nS( 2, 2);\nS( 3, 1);\nS( 4, 0);\n#elif KERNEL_SIZE == 11\nS(-5, 10);\nS(-4, 9);\nS(-3, 8);\nS(-2, 7);\nS(-1, 6);\nS( 0, 5);\nS( 1, 4);\nS( 2, 3);\nS( 3, 2);\nS( 4, 1);\nS( 5, 0);\n#elif KERNEL_SIZE == 13\nS(-6, 12);\nS(-5, 11);\nS(-4, 10);\nS(-3, 9);\nS(-2, 8);\nS(-1, 7);\nS( 0, 6);\nS( 1, 5);\nS( 2, 4);\nS( 3, 3);\nS( 4, 2);\nS( 5, 1);\nS( 6, 0);\n#elif KERNEL_SIZE == 15\nS(-7, 14);\nS(-6, 13);\nS(-5, 12);\nS(-4, 11);\nS(-3, 10);\nS(-2, 9);\nS(-1, 8);\nS( 0, 7);\nS( 1, 6);\nS( 2, 5);\nS( 3, 4);\nS( 4, 3);\nS( 5, 2);\nS( 6, 1);\nS( 7, 0);\n#else\n#error Invalid parameters\n#endif\ncolor = vec4(result.rgb, 1.0f);\n}"},6942:e=>{e.exports="#ifndef KERNEL_SIZE_SQUARED\n#define Must define KERNEL_SIZE_SQUARED\n#endif\nuniform sampler2D image;\nuniform float kernel[@KERNEL_SIZE_SQUARED@];\n#define S(x,y,k) result += pixelAtShortOffset(image, ivec2((x),(y))) * kernel[k]\nvoid main()\n{\nvec4 result = vec4(0.0f);\n#if KERNEL_SIZE_SQUARED == 9\nS(-1,-1, 8);\nS(-1, 0, 7);\nS(-1, 1, 6);\nS( 0,-1, 5);\nS( 0, 0, 4);\nS( 0, 1, 3);\nS( 1,-1, 2);\nS( 1, 0, 1);\nS( 1, 1, 0);\n#elif KERNEL_SIZE_SQUARED == 25\nS(-2,-2, 24);\nS(-2,-1, 23);\nS(-2, 0, 22);\nS(-2, 1, 21);\nS(-2, 2, 20);\nS(-1,-2, 19);\nS(-1,-1, 18);\nS(-1, 0, 17);\nS(-1, 1, 16);\nS(-1, 2, 15);\nS( 0,-2, 14);\nS( 0,-1, 13);\nS( 0, 0, 12);\nS( 0, 1, 11);\nS( 0, 2, 10);\nS( 1,-2, 9);\nS( 1,-1, 8);\nS( 1, 0, 7);\nS( 1, 1, 6);\nS( 1, 2, 5);\nS( 2,-2, 4);\nS( 2,-1, 3);\nS( 2, 0, 2);\nS( 2, 1, 1);\nS( 2, 2, 0);\n#elif KERNEL_SIZE_SQUARED == 49\nS(-3,-3, 48);\nS(-3,-2, 47);\nS(-3,-1, 46);\nS(-3, 0, 45);\nS(-3, 1, 44);\nS(-3, 2, 43);\nS(-3, 3, 42);\nS(-2,-3, 41);\nS(-2,-2, 40);\nS(-2,-1, 39);\nS(-2, 0, 38);\nS(-2, 1, 37);\nS(-2, 2, 36);\nS(-2, 3, 35);\nS(-1,-3, 34);\nS(-1,-2, 33);\nS(-1,-1, 32);\nS(-1, 0, 31);\nS(-1, 1, 30);\nS(-1, 2, 29);\nS(-1, 3, 28);\nS( 0,-3, 27);\nS( 0,-2, 26);\nS( 0,-1, 25);\nS( 0, 0, 24);\nS( 0, 1, 23);\nS( 0, 2, 22);\nS( 0, 3, 21);\nS( 1,-3, 20);\nS( 1,-2, 19);\nS( 1,-1, 18);\nS( 1, 0, 17);\nS( 1, 1, 16);\nS( 1, 2, 15);\nS( 1, 3, 14);\nS( 2,-3, 13);\nS( 2,-2, 12);\nS( 2,-1, 11);\nS( 2, 0, 10);\nS( 2, 1, 9);\nS( 2, 2, 8);\nS( 2, 3, 7);\nS( 3,-3, 6);\nS( 3,-2, 5);\nS( 3,-1, 4);\nS( 3, 0, 3);\nS( 3, 1, 2);\nS( 3, 2, 1);\nS( 3, 3, 0);\n#else\n#error Invalid KERNEL_SIZE_SQUARED\n#endif\ncolor = vec4(result.rgb, 1.0f);\n}"},7054:e=>{e.exports="uniform sampler2D image;\n#define X(i,j) t = vec2(min(p[i], p[j]), max(p[i], p[j])); p[i] = t.x; p[j] = t.y;\n#define S(i,x,y) p[i] = pixelAtShortOffset(image, ivec2((x),(y))).g\nvoid main()\n{\nfloat median;\nvec2 t;\n#if !defined(KERNEL_SIZE)\n#error Must define KERNEL_SIZE\n#elif KERNEL_SIZE == 3\nfloat p[9];\nS(0,-1,-1);\nS(1, 0,-1);\nS(2, 1,-1);\nS(3,-1, 0);\nS(4, 0, 0);\nS(5, 1, 0);\nS(6,-1, 1);\nS(7, 0, 1);\nS(8, 1, 1);\nX(1,2);X(4,5);X(7,8);X(0,1);X(3,4);X(6,7);X(1,2);X(4,5);X(7,8);X(0,3);X(5,8);X(4,7);X(3,6);X(1,4);X(2,5);X(4,7);X(4,2);X(6,4);X(4,2);\nmedian = p[4];\n#elif KERNEL_SIZE == 5\nfloat p[25];\nS( 0,-2,-2);\nS( 1,-1,-2);\nS( 2, 0,-2);\nS( 3, 1,-2);\nS( 4, 2,-2);\nS( 5,-2,-1);\nS( 6,-1,-1);\nS( 7, 0,-1);\nS( 8, 1,-1);\nS( 9, 2,-1);\nS(10,-2, 0);\nS(11,-1, 0);\nS(12, 0, 0);\nS(13, 1, 0);\nS(14, 2, 0);\nS(15,-2, 1);\nS(16,-1, 1);\nS(17, 0, 1);\nS(18, 1, 1);\nS(19, 2, 1);\nS(20,-2, 2);\nS(21,-1, 2);\nS(22, 0, 2);\nS(23, 1, 2);\nS(24, 2, 2);\nX(0,1);X(3,4);X(2,4);X(2,3);X(6,7);X(5,7);X(5,6);X(9,10);X(8,10);X(8,9);X(12,13);X(11,13);X(11,12);X(15,16);X(14,16);X(14,15);X(18,19);X(17,19);X(17,18);X(21,22);X(20,22);X(20,21);X(23,24);X(2,5);X(3,6);X(0,6);X(0,3);X(4,7);X(1,7);X(1,4);X(11,14);X(8,14);X(8,11);X(12,15);X(9,15);X(9,12);X(13,16);X(10,16);X(10,13);X(20,23);X(17,23);X(17,20);X(21,24);X(18,24);X(18,21);X(19,22);X(8,17);X(9,18);X(0,18);X(0,9);X(10,19);X(1,19);X(1,10);X(11,20);X(2,20);X(2,11);X(12,21);X(3,21);X(3,12);X(13,22);X(4,22);X(4,13);X(14,23);X(5,23);X(5,14);X(15,24);X(6,24);X(6,15);X(7,16);X(7,19);X(13,21);X(15,23);X(7,13);X(7,15);X(1,9);X(3,11);X(5,17);X(11,17);X(9,17);X(4,10);X(6,12);X(7,14);X(4,6);X(4,7);X(12,14);X(10,14);X(6,7);X(10,12);X(6,10);X(6,17);X(12,17);X(7,17);X(7,10);X(12,18);X(7,12);X(10,18);X(12,20);X(10,20);X(10,12);\nmedian = p[12];\n#elif KERNEL_SIZE == 7\nfloat p[49];\nS( 0,-3,-3);\nS( 1,-2,-3);\nS( 2,-1,-3);\nS( 3, 0,-3);\nS( 4, 1,-3);\nS( 5, 2,-3);\nS( 6, 3,-3);\nS( 7,-3,-2);\nS( 8,-2,-2);\nS( 9,-1,-2);\nS(10, 0,-2);\nS(11, 1,-2);\nS(12, 2,-2);\nS(13, 3,-2);\nS(14,-3,-1);\nS(15,-2,-1);\nS(16,-1,-1);\nS(17, 0,-1);\nS(18, 1,-1);\nS(19, 2,-1);\nS(20, 3,-1);\nS(21,-3, 0);\nS(22,-2, 0);\nS(23,-1, 0);\nS(24, 0, 0);\nS(25, 1, 0);\nS(26, 2, 0);\nS(27, 3, 0);\nS(28,-3, 1);\nS(29,-2, 1);\nS(30,-1, 1);\nS(31, 0, 1);\nS(32, 1, 1);\nS(33, 2, 1);\nS(34, 3, 1);\nS(35,-3, 2);\nS(36,-2, 2);\nS(37,-1, 2);\nS(38, 0, 2);\nS(39, 1, 2);\nS(40, 2, 2);\nS(41, 3, 2);\nS(42,-3, 3);\nS(43,-2, 3);\nS(44,-1, 3);\nS(45, 0, 3);\nS(46, 1, 3);\nS(47, 2, 3);\nS(48, 3, 3);\nX(0,1);X(2,3);X(0,2);X(1,3);X(1,2);X(4,5);X(6,7);X(4,6);X(5,7);X(5,6);X(0,4);X(2,6);X(2,4);X(1,5);X(3,7);X(3,5);X(1,2);X(3,4);X(5,6);X(8,9);X(10,11);X(8,10);X(9,11);X(9,10);X(12,13);X(14,15);X(12,14);X(13,15);X(13,14);X(8,12);X(10,14);X(10,12);X(9,13);X(11,15);X(11,13);X(9,10);X(11,12);X(13,14);X(0,8);X(4,12);X(4,8);X(2,10);X(6,14);X(6,10);X(2,4);X(6,8);X(10,12);X(1,9);X(5,13);X(5,9);X(3,11);X(7,15);X(7,11);X(3,5);X(7,9);X(11,13);X(1,2);X(3,4);X(5,6);X(7,8);X(9,10);X(11,12);X(13,14);X(16,17);X(18,19);X(16,18);X(17,19);X(17,18);X(20,21);X(22,23);X(20,22);X(21,23);X(21,22);X(16,20);X(18,22);X(18,20);X(17,21);X(19,23);X(19,21);X(17,18);X(19,20);X(21,22);X(24,25);X(26,27);X(24,26);X(25,27);X(25,26);X(28,29);X(30,31);X(28,30);X(29,31);X(29,30);X(24,28);X(26,30);X(26,28);X(25,29);X(27,31);X(27,29);X(25,26);X(27,28);X(29,30);X(16,24);X(20,28);X(20,24);X(18,26);X(22,30);X(22,26);X(18,20);X(22,24);X(26,28);X(17,25);X(21,29);X(21,25);X(19,27);X(23,31);X(23,27);X(19,21);X(23,25);X(27,29);X(17,18);X(19,20);X(21,22);X(23,24);X(25,26);X(27,28);X(29,30);X(0,16);X(8,24);X(8,16);X(4,20);X(12,28);X(12,20);X(4,8);X(12,16);X(20,24);X(2,18);X(10,26);X(10,18);X(6,22);X(14,30);X(14,22);X(6,10);X(14,18);X(22,26);X(2,4);X(6,8);X(10,12);X(14,16);X(18,20);X(22,24);X(26,28);X(1,17);X(9,25);X(9,17);X(5,21);X(13,29);X(13,21);X(5,9);X(13,17);X(21,25);X(3,19);X(11,27);X(11,19);X(7,23);X(15,31);X(15,23);X(7,11);X(15,19);X(23,27);X(3,5);X(7,9);X(11,13);X(15,17);X(19,21);X(23,25);X(27,29);X(1,2);X(3,4);X(5,6);X(7,8);X(9,10);X(11,12);X(13,14);X(15,16);X(17,18);X(19,20);X(21,22);X(23,24);X(25,26);X(27,28);X(29,30);X(32,33);X(34,35);X(32,34);X(33,35);X(33,34);X(36,37);X(38,39);X(36,38);X(37,39);X(37,38);X(32,36);X(34,38);X(34,36);X(33,37);X(35,39);X(35,37);X(33,34);X(35,36);X(37,38);X(40,41);X(42,43);X(40,42);X(41,43);X(41,42);X(44,45);X(46,47);X(44,46);X(45,47);X(45,46);X(40,44);X(42,46);X(42,44);X(41,45);X(43,47);X(43,45);X(41,42);X(43,44);X(45,46);X(32,40);X(36,44);X(36,40);X(34,42);X(38,46);X(38,42);X(34,36);X(38,40);X(42,44);X(33,41);X(37,45);X(37,41);X(35,43);X(39,47);X(39,43);X(35,37);X(39,41);X(43,45);X(33,34);X(35,36);X(37,38);X(39,40);X(41,42);X(43,44);X(45,46);X(32,48);X(40,48);X(36,40);X(44,48);X(38,42);X(34,36);X(38,40);X(42,44);X(46,48);X(37,41);X(39,43);X(35,37);X(39,41);X(43,45);X(33,34);X(35,36);X(37,38);X(39,40);X(41,42);X(43,44);X(45,46);X(47,48);X(0,32);X(16,48);X(16,32);X(8,40);X(24,40);X(8,16);X(24,32);X(40,48);X(4,36);X(20,36);X(12,44);X(28,44);X(12,20);X(28,36);X(4,8);X(12,16);X(20,24);X(28,32);X(36,40);X(44,48);X(2,34);X(18,34);X(10,42);X(26,42);X(10,18);X(26,34);X(6,38);X(22,38);X(14,46);X(30,46);X(14,22);X(30,38);X(6,10);X(14,18);X(22,26);X(30,34);X(38,42);X(2,4);X(6,8);X(10,12);X(14,16);X(18,20);X(22,24);X(26,28);X(30,32);X(34,36);X(38,40);X(42,44);X(46,48);X(1,33);X(17,33);X(9,41);X(25,41);X(9,17);X(25,33);X(5,37);X(21,37);X(13,45);X(29,45);X(13,21);X(29,37);X(5,9);X(13,17);X(21,25);X(29,33);X(37,41);X(3,35);X(19,35);X(11,43);X(27,43);X(11,19);X(27,35);X(7,39);X(23,39);X(15,47);X(31,47);X(15,23);X(31,39);X(7,11);X(15,19);X(23,27);X(31,35);X(39,43);X(3,5);X(7,9);X(11,13);X(15,17);X(19,21);X(23,25);X(27,29);X(31,33);X(35,37);X(39,41);X(43,45);X(1,2);X(3,4);X(5,6);X(7,8);X(9,10);X(11,12);X(13,14);X(15,16);X(17,18);X(19,20);X(21,22);X(23,24);\nmedian = p[24];\n#else\n#error Unsupported kernel size\n#endif\ncolor = vec4(median, median, median, 1.0f);\n}"},8961:e=>{e.exports="uniform sampler2D image;\nuniform sampler2D illuminationMap;\nuniform float gain;\nuniform float offset;\nuniform float decay;\n#ifndef GREYSCALE\n#error Must define GREYSCALE\n#endif\n#if GREYSCALE == 0\nconst mat3 rgb2yuv = mat3(\n0.299f, -0.14713f, 0.615f,\n0.587f, -0.28886f, -0.51499f,\n0.114f, 0.436f, -0.10001f\n);\nconst mat3 yuv2rgb = mat3(\n1.0f, 1.0f, 1.0f,\n0.0f, -0.39465f, 2.03211f,\n1.13983f, -0.58060f, 0.0f\n);\n#endif\nconst float eps = 0.0001f;\nconst float sqrt2 = 1.4142135623730951f;\nconst float magic = 20.0f;\nconst vec2 center = vec2(0.5f);\nvoid main()\n{\nvec4 pixel = threadPixel(image);\nvec4 imapPixel = threadPixel(illuminationMap);\nfloat lambda = -sqrt2 * log(max(1.0f - decay, eps));\nfloat dist = length(texCoord - center);\nfloat vgain = gain * exp(-lambda * dist);\nfloat normalizedGain = 2.0f * vgain;\nfloat normalizedOffset = 2.0f * offset - 1.0f;\n#if GREYSCALE != 0\nfloat luma = 1.0 / (1.0 + exp(-normalizedGain * magic * (pixel.g - imapPixel.g)));\nluma = clamp(luma + normalizedOffset, 0.0f, 1.0f);\ncolor = vec4(luma, luma, luma, 1.0f);\n#else\nvec3 yuvPixel = rgb2yuv * pixel.rgb;\nvec3 yuvImapPixel = rgb2yuv * imapPixel.rgb;\nfloat luma = 1.0 / (1.0 + exp(-normalizedGain * magic * (yuvPixel.r - yuvImapPixel.r)));\nluma += normalizedOffset;\nvec3 rgbCorrectedPixel = yuv2rgb * vec3(luma, yuvPixel.gb);\nrgbCorrectedPixel = clamp(rgbCorrectedPixel, 0.0f, 1.0f);\ncolor = vec4(rgbCorrectedPixel, 1.0f);\n#endif\n}"},9571:e=>{e.exports="#ifndef GREYSCALE\n#error Must define GREYSCALE\n#endif\n#if GREYSCALE != 0\nuniform sampler2D minmax2d;\n#else\nuniform sampler2D minmax2dRGB[3];\n#endif\nuniform float minValue;\nuniform float maxValue;\nconst float eps = 1.0f / 255.0f;\nvoid main()\n{\nvec2 minmax = clamp(vec2(minValue, maxValue), 0.0f, 255.0f) / 255.0f;\nvec4 newMin = vec4(minmax.x);\nvec4 newRange = vec4(minmax.y - minmax.x);\nvec4 alpha = vec4(1.0f, newMin.x, newRange.x, 1.0f);\n#if GREYSCALE != 0\nvec4 pixel = threadPixel(minmax2d);\nmat4 channel = mat4(pixel, pixel, pixel, alpha);\n#else\nmat4 channel = mat4(\nthreadPixel(minmax2dRGB[0]),\nthreadPixel(minmax2dRGB[1]),\nthreadPixel(minmax2dRGB[2]),\nalpha\n);\n#endif\nvec4 oldMin = vec4(channel[0].g, channel[1].g, channel[2].g, channel[3].g);\nvec4 oldRange = max(vec4(channel[0].b, channel[1].b, channel[2].b, channel[3].b), eps);\nvec4 oldIntensity = vec4(channel[0].a, channel[1].a, channel[2].a, channel[3].a);\nvec4 newIntensity = (oldIntensity - oldMin) * newRange / oldRange + newMin;\ncolor = newIntensity;\n}"},8466:e=>{e.exports="const vec4 grey = vec4(0.299f, 0.587f, 0.114f, 0.0f);\nuniform sampler2D image;\nvoid main()\n{\nvec4 pixel = threadPixel(image);\nfloat g = dot(pixel, grey);\ncolor = vec4(g, g, g, 1.0f);\n}"},2545:e=>{e.exports="#ifndef _COLORS_GLSL\n#define _COLORS_GLSL\n#define PIXELCOMPONENT_RED @PIXELCOMPONENT_RED@\n#define PIXELCOMPONENT_GREEN @PIXELCOMPONENT_GREEN@\n#define PIXELCOMPONENT_BLUE @PIXELCOMPONENT_BLUE@\n#define PIXELCOMPONENT_ALPHA @PIXELCOMPONENT_ALPHA@\n#endif"},7373:e=>{e.exports="#ifndef _FILTERS_GLSL\n#define _FILTERS_GLSL\nfloat laplacian(sampler2D pyramid, vec2 position, float lod)\n{\nfloat pot = exp2(lod);\nivec2 pyrBaseSize = textureSize(pyramid, 0);\nconst vec3 ones = vec3(1.0f);\nconst mat3 kernel = mat3(\n0,-1, 0,\n-1, 4,-1,\n0,-1, 0\n);\n#define LPC(x,y) pyrSubpixelAtExOffset(pyramid, position, lod, pot, ivec2((x),(y)), pyrBaseSize).g\nmat3 neighborhood = mat3(\n0.0f, LPC(0,-1), 0.0f,\nLPC(-1,0), LPC(0,0), LPC(1,0),\n0.0f, LPC(0,1), 0.0f\n);\nmat3 m = matrixCompMult(neighborhood, kernel);\nreturn dot(ones, vec3(\ndot(m[0], ones),\ndot(m[1], ones),\ndot(m[2], ones)\n)) * (1.0f + lod);\n}\n#endif"},2229:e=>{e.exports="#ifndef _FIXEDPOINT_GLSL\n#define _FIXEDPOINT_GLSL\n#define fixed_t int\n#define fixed2_t ivec2\nconst int FIX_BITS = int(@FIX_BITS@);\nconst float FIX_RESOLUTION = float(@FIX_RESOLUTION@);\n#define itofix(x) fixed_t((x) << FIX_BITS)\n#define fixtoi(f) int((x) >> FIX_BITS)\n#define ftofix(x) fixed_t((x) * FIX_RESOLUTION + 0.5f)\n#define fixtof(f) (float(f) / FIX_RESOLUTION)\n#define ivec2tofix(x) fixed2_t((x) << FIX_BITS)\n#define fixtoivec2(f) ivec2((f) >> FIX_BITS)\n#define vec2tofix(v) fixed2_t((v) * FIX_RESOLUTION + vec2(0.5f))\n#define fixtovec2(f) (vec2(f) / FIX_RESOLUTION)\n#endif"},919:e=>{e.exports="#ifndef _FLOAT16_GLSL\n#define _FLOAT16_GLSL\n#define encodeFloat16(f) (vec2(packf16(f)) / 255.0f)\n#define decodeFloat16(v) unpackf16(uvec2((v) * 255.0f))\n#define encodePairOfFloat16(f) vec4(encodeFloat16((f).x), encodeFloat16((f).y))\n#define decodePairOfFloat16(v) vec2(decodeFloat16((v).rg), decodeFloat16((v).ba))\n#define encodeNullPairOfFloat16() vec4(1.0f)\n#define isNullPairOfFloat16(v) all(equal((v), encodeNullPairOfFloat16()))\n#define encodeDiscardedPairOfFloat16() vec4(0.0f, 1.0f, 0.0f, 1.0f)\n#define isDiscardedPairOfFloat16(v) all(equal((v), encodeDiscardedPairOfFloat16()))\n#define encodeFloat16NaN() vec2(0.5f, 1.0f)\n#define isEncodedFloat16NaN(v) all(equal((v), encodeFloat16NaN()))\nuvec2 packf16( float f)\n{\nuint y = packHalf2x16(vec2(f, 0.0f));\nreturn uvec2(y, y >> 8u) & 0xFFu;\n}\nfloat unpackf16(uvec2 v)\n{\nv &= 0xFFu;\nreturn unpackHalf2x16(v.x | (v.y << 8u)).x;\n}\nbool isEncodedFloat16Zero(vec2 v)\n{\nuvec2 w = uvec2(v * 255.0f);\nreturn 0u == w.x + w.y * (0x80u - w.y);\n}\n#endif"},3815:e=>{e.exports="#ifndef _GLOBAL_GLSL\n#define _GLOBAL_GLSL\n#define threadLocation() ivec2(texCoord * texSize)\n#define outputSize() ivec2(texSize)\n#define threadPixel(img) textureLod((img), texCoord, 0.0f)\n#define pixelAt(img, pos) texelFetch((img), (pos), 0)\n#define pixelAtShortOffset(img, offset) textureLodOffset((img), texCoord, 0.0f, (offset))\n#define pixelAtLongOffset(img, offset) textureLod((img), texCoord + vec2(offset) / texSize, 0.0f)\n#endif"},1830:e=>{e.exports="#ifndef _INT32_GLSL\n#define _INT32_GLSL\nuint decodeUint32(vec4 rgba)\n{\nuvec4 v = uvec4(rgba * 255.0f) & 255u;\nreturn v.x | (v.y << 8u) | (v.z << 16u) | (v.w << 24u);\n}\nvec4 encodeUint32(uint value)\n{\nuvec4 v = uvec4(value, value >> 8u, value >> 16u, value >> 24u) & 255u;\nreturn vec4(v) / 255.0f;\n}\n#endif"},1364:e=>{e.exports="#ifndef _KEYPOINT_DESCRIPTORS_GLSL\n#define _KEYPOINT_DESCRIPTORS_GLSL\n#if !defined(DESCRIPTOR_SIZE)\n#error Must define DESCRIPTOR_SIZE\n#elif !defined(_KEYPOINTS_GLSL)\n#error Must include keypoints.glsl\n#endif\nuint[DESCRIPTOR_SIZE] readKeypointDescriptor(sampler2D encodedKeypoints, int descriptorSize, int extraSize, int encoderLength, KeypointAddress address)\n{\nint descriptorOffset = sizeofEncodedKeypoint(0, extraSize) / 4;\nKeypointAddress descriptorAddress = KeypointAddress(address.base, descriptorOffset);\nuint[DESCRIPTOR_SIZE] descriptor;\nvec4 pixel; uvec4 bytes;\n@unroll\nfor(int i = 0; i < DESCRIPTOR_SIZE; i += 4) {\npixel = readKeypointData(encodedKeypoints, encoderLength, descriptorAddress);\nbytes = uvec4(pixel * 255.0f);\ndescriptor[i] = bytes.r;\ndescriptor[i+1] = bytes.g;\ndescriptor[i+2] = bytes.b;\ndescriptor[i+3] = bytes.a;\ndescriptorAddress.offset++;\n}\nreturn descriptor;\n}\nuint[DESCRIPTOR_SIZE] readKeypointDescriptorFromDB(sampler2D descriptorDB, int descriptorDBStride, int index)\n{\nuint[DESCRIPTOR_SIZE] descriptor;\nint rasterIndex = index * (DESCRIPTOR_SIZE / 4) * int(index >= 0);\nvec4 pixel; uvec4 bytes; ivec2 pos;\n@unroll\nfor(int i = 0; i < DESCRIPTOR_SIZE; i += 4) {\npos = ivec2(rasterIndex % descriptorDBStride, rasterIndex / descriptorDBStride);\npixel = (index >= 0) ? texelFetch(descriptorDB, pos, 0) : vec4(0.0f);\nbytes = uvec4(pixel * 255.0f);\ndescriptor[i] = bytes.r;\ndescriptor[i+1] = bytes.g;\ndescriptor[i+2] = bytes.b;\ndescriptor[i+3] = bytes.a;\nrasterIndex++;\n}\nreturn descriptor;\n}\nint distanceBetweenKeypointDescriptors(uint[DESCRIPTOR_SIZE] a, uint[DESCRIPTOR_SIZE] b)\n{\nconst int[256] POPCNT = int[256](0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8);\nuvec4 xor, u, v;\nint dist = 0;\nivec4 bits;\n@unroll\nfor(int i = 0; i < DESCRIPTOR_SIZE; i += 4) {\nu = uvec4(a[i], a[i+1], a[i+2], a[i+3]);\nv = uvec4(b[i], b[i+1], b[i+2], b[i+3]);\nxor = (u ^ v) & 255u;\nbits = ivec4(POPCNT[xor.x], POPCNT[xor.y], POPCNT[xor.z], POPCNT[xor.w]);\ndist += bits.x + bits.y + bits.z + bits.w;\n}\nreturn dist;\n}\n#endif"},4004:e=>{e.exports='#ifndef _KEYPOINT_MATCHES_GLSL\n#define _KEYPOINT_MATCHES_GLSL\n@include "int32.glsl"\nconst int MATCH_INDEX_BITS = int(@MATCH_INDEX_BITS@);\nconst int MATCH_INDEX_MASK = int(@MATCH_INDEX_MASK@);\nconst int MATCH_MAX_INDEX = int(@MATCH_MAX_INDEX@);\nconst int MATCH_MAX_DISTANCE = int(@MATCH_MAX_DISTANCE@);\nstruct KeypointMatch\n{\nint index;\nint dist;\n};\nvec4 encodeKeypointMatch(KeypointMatch candidate)\n{\nuint index = uint(candidate.index & MATCH_INDEX_MASK);\nuint dist = uint(clamp(candidate.dist, 0, MATCH_MAX_DISTANCE));\nuint u32 = index | (dist << MATCH_INDEX_BITS);\nreturn encodeUint32(u32);\n}\nKeypointMatch decodeKeypointMatch(vec4 rgba)\n{\nuint u32 = decodeUint32(rgba);\nint dist = int(u32 >> MATCH_INDEX_BITS);\nint index = int(u32 & uint(MATCH_INDEX_MASK));\nreturn KeypointMatch(index, dist);\n}\nconst KeypointMatch MATCH_NOT_FOUND = KeypointMatch(MATCH_MAX_INDEX, MATCH_MAX_DISTANCE);\n#endif'},8714:e=>{e.exports='#ifndef _KEYPOINTS_GLSL\n#define _KEYPOINTS_GLSL\n@include "math.glsl"\n@include "fixed-point.glsl"\n@include "float16.glsl"\n@include "pyramids.glsl"\nstruct Keypoint\n{\nvec2 position;\nfloat lod;\nfloat orientation;\nfloat score;\nuint flags;\n};\nstruct KeypointAddress\n{\nint base;\nint offset;\n};\nconst int MIN_KEYPOINT_SIZE = int(@MIN_KEYPOINT_SIZE@);\nconst int MAX_DESCRIPTOR_SIZE = int(@MAX_DESCRIPTOR_SIZE@);\nconst uint KPF_NONE = 0u;\nconst uint KPF_NULL = 1u;\nconst uint KPF_DISCARDED = 2u;\n#define encodeKeypointScore(score) encodeFloat16(score)\n#define decodeKeypointScore(encodedScore) decodeFloat16(encodedScore)\n#define encodeKeypointOrientation(angle) ((angle) * INV_PI_OVER_2 + 0.5f)\n#define decodeKeypointOrientation(value) ((value) * TWO_PI - PI)\n#define encodeNullKeypoint() (vec4(1.0f))\n#define encodeDiscardedKeypoint() (vec4(0.0f))\n#define is