1234567891011121314151617181920 |
- /*!
- * encantar.js version 0.4.0
- * GPU-accelerated Augmented Reality for the web
- * Copyright 2022-2024 Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart)
- * https://github.com/alemart/encantar-js
- *
- * @license LGPL-3.0-or-later
- * Date: 2024-11-07T02:55:24.348Z
- */
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AR=t():e.AR=t()}(self,(()=>(()=>{var e={774:e=>{
- /*!
- * Speedy Vision version 0.9.1
- * GPU-accelerated Computer Vision for JavaScript
- * Copyright 2020-2024 Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart)
- * https://github.com/alemart/speedy-vision
- *
- * @license Apache-2.0
- * Date: 2024-07-03T02:16:25.769Z
- */
- var t;self,t=()=>(()=>{var e={2199:(e,t,n)=>{"use strict";n.d(t,{w:()=>c});var i=n(6634),s=n(1001),r=n(9037),o=n(8581);let a="raf",A="default";class c extends i.Q{static get powerPreference(){return s.c.powerPreference}static set powerPreference(e){s.c.powerPreference=e}static get gpuPollingMode(){return a}static set gpuPollingMode(e){if("raf"!==e&&"asap"!==e)throw new o.qw(`Invalid GPU polling mode: "${e}"`);a=e}static get logging(){return A}static set logging(e){if("default"!==e&&"none"!==e&&"diagnostic"!==e)throw new o.qw(`Invalid logging mode: "${e}"`);"diagnostic"===e&&r.A.log("%c DIAGNOSTIC MODE ","background:red;color:white;font-size:36pt;font-weight:bold"),A=e}}},6306:(e,t,n)=>{"use strict";n.d(t,{r:()=>a});var i=n(6465),s=n(9037),r=n(8581);const o=Object.freeze({float32:Float32Array});class a{constructor(e,t,n){s.A.assert(e>0&&t>0),s.A.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 o}plus(e){return new g(this,e)}minus(e){return new f(this,e)}times(e){return"number"==typeof e?new u(this,e):new I(this,e)}transpose(){return new h(this)}inverse(){return new p(this)}compMult(e){return new m(this,e)}ldiv(e){return new _(this,e)}toString(){return`SpeedyMatrixExpr(rows=${this.rows}, columns=${this.columns})`}_evaluate(e,t){throw new r.aQ}}const{SpeedyMatrix:A}=n(4188);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),s=this._tempMatrix,r=i.U.allocateMat32(e,t,s),o=i.U.allocateMat32(e,t,n);return i.U.copyToMat32(e,t,o,n),this._compute(e,t,r,o),i.U.copyFromMat32(e,t,r,s),i.U.deallocateMat32(e,t,o),i.U.deallocateMat32(e,t,r),s}_compute(e,t,n,i){throw new r.aQ}}class d extends c{constructor(e,t,n,i){s.A.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),s=this._right._evaluate(e,t),r=this._tempMatrix,o=i.U.allocateMat32(e,t,r),a=i.U.allocateMat32(e,t,n),A=i.U.allocateMat32(e,t,s);return i.U.copyToMat32(e,t,a,n),i.U.copyToMat32(e,t,A,s),this._compute(e,t,o,a,A),i.U.copyFromMat32(e,t,o,r),i.U.deallocateMat32(e,t,A),i.U.deallocateMat32(e,t,a),i.U.deallocateMat32(e,t,o),r}_compute(e,t,n,i,s){throw new r.aQ}}class h extends l{constructor(e){super(e.columns,e.rows,e)}_compute(e,t,n,i){e.exports.Mat32_transpose(n,i)}}class p extends l{constructor(e){s.A.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 u 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 g extends d{constructor(e,t){s.A.assert(e.rows===t.rows&&e.columns===t.columns),super(e.rows,e.columns,e,t)}_compute(e,t,n,i,s){e.exports.Mat32_add(n,i,s)}}class f extends d{constructor(e,t){s.A.assert(e.rows===t.rows&&e.columns===t.columns),super(e.rows,e.columns,e,t)}_compute(e,t,n,i,s){e.exports.Mat32_subtract(n,i,s)}}class I extends d{constructor(e,t){s.A.assert(e.columns===t.rows),super(e.rows,t.columns,e,t)}_compute(e,t,n,i,s){e.exports.Mat32_multiply(n,i,s)}}class m extends d{constructor(e,t){s.A.assert(e.rows===t.rows&&e.columns===t.columns),super(t.rows,t.columns,e,t)}_compute(e,t,n,i,s){e.exports.Mat32_compmult(n,i,s)}}class _ extends d{constructor(e,t){const n=e.rows,i=e.columns;s.A.assert(n>=i&&t.rows===n&&1===t.columns),super(i,1,e,t)}_compute(e,t,n,i,s){e.exports.Mat32_qr_ols(n,i,s,2)}}},6465:(e,t,n)=>{"use strict";n.d(t,{U:()=>p});var i=n(9192),s=n(8581),r=n(9037),o=n(3816);const a=n(3575);let A=null,c=null;const l={as:{object:d="undefined"==typeof WebAssembly?new Uint8Array(1024):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,h;class p{static ready(){return"undefined"==typeof WebAssembly?i.i.reject(new s.EM("This application requires WebAssembly. Please update your system.")):o.LITTLE_ENDIAN?new i.i(((e,t)=>{p._ready(e,t)})):i.i.reject(new s.EM("Can't run WebAssembly code: not in a little-endian machine!"))}static get handle(){if(!A||!c)throw new s.NO("Can't get WASM handle: routines not yet loaded");return{wasm:A,memory:l,module:c}}static imports(e){const t=new u(e);return Object.getOwnPropertyNames(u.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){r.A.assert(i.data.byteLength===e.exports.Mat32_dataSize(n));const s=e.exports.Mat32_data(n);return t.as.float32.set(i.data,s/Float32Array.BYTES_PER_ELEMENT),n}static copyFromMat32(e,t,n,i){r.A.assert(i.data.byteLength===e.exports.Mat32_dataSize(n));const s=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[s+e];return n}static _ready(e,t,n=1e3){null!==A&&null!==c?e({wasm:A,memory:l,module:c}):n<=0?t(new s.MU("Can't load WASM routines")):setTimeout(p._ready,0,e,t,n-1)}}class u{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 g(e),Object.freeze(this)}print(e){r.A.log(this.cstring.get(e))}fatal(e){throw new s.NO(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 g{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))}}h=l,"undefined"!=typeof WebAssembly&&i.i.resolve(a).then((e=>(e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))))(e))).then((e=>WebAssembly.instantiate(e,{env:Object.assign({memory:h.as.object},p.imports(h))}))).then((e=>{A=e.instance,c=e.module,e.instance.exports.srand(.001*Date.now()&4294967295),r.A.log("The WebAssembly routines have been loaded!")})).catch((e=>{throw new s.NO(`Can't load the WebAssembly routines: ${e}`,e)}))},4188:(e,t,n)=>{"use strict";n.r(t),n.d(t,{SpeedyMatrix:()=>a});var i=n(6306),s=n(6465),r=n(9192),o=n(9037);class a extends i.r{constructor(e,t,n,s,r){super(e,t,i.r.DEFAULT_DTYPE),o.A.assert(r.constructor===i.r.BUFFER_TYPE[this.dtype]),o.A.assert(n>0&&s>=n),o.A.assert(r.length+e*t===0||r.length===1+n*(e-1)+s*(t-1)),this._step0=0|n,this._step1=0|s,this._data=r}static Create(e,t,n,s=i.r.DEFAULT_DTYPE){return o.A.assert(e*t>0,"Can't create a matrix without a shape"),o.A.assert(e*t===n.length,`Can't create matrix: expected ${e*t} entries, but found ${n.length}`),o.A.assert(Object.prototype.hasOwnProperty.call(i.r.BUFFER_TYPE,s),`Invalid dtype: "${s}"`),new a(e,t,1,e,Reflect.construct(i.r.BUFFER_TYPE[s],[n]))}static Zeros(e,t=e,n=i.r.DEFAULT_DTYPE){return o.A.assert(e*t>0,"Can't create a matrix without a shape"),o.A.assert(Object.prototype.hasOwnProperty.call(i.r.BUFFER_TYPE,n),`Invalid dtype: "${n}"`),new a(e,t,1,e,Reflect.construct(i.r.BUFFER_TYPE[n],[e*t]))}static Ones(e,t=e,n=i.r.DEFAULT_DTYPE){return o.A.assert(e*t>0,"Can't create a matrix without a shape"),o.A.assert(Object.prototype.hasOwnProperty.call(i.r.BUFFER_TYPE,n),`Invalid dtype: "${n}"`),new a(e,t,1,e,Reflect.construct(i.r.BUFFER_TYPE[n],[e*t]).fill(1))}static Eye(e,t=e,n=i.r.DEFAULT_DTYPE){o.A.assert(e*t>0,"Can't create a matrix without a shape"),o.A.assert(Object.prototype.hasOwnProperty.call(i.r.BUFFER_TYPE,n),`Invalid dtype: "${n}"`);const s=Reflect.construct(i.r.BUFFER_TYPE[n],[e*t]);for(let n=Math.min(e,t)-1;n>=0;n--)s[n*e+n]=1;return new a(e,t,1,e,s)}static From(e){return a.Zeros(e.rows,e.columns,e.dtype).setToSync(e)}static ready(){return s.U.ready().then((e=>{}))}get data(){return this._data}get step0(){return this._step0}get step1(){return this._step1}block(e,t,n,i){o.A.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 s=t-e+1,r=(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(s,r,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 s=0;s<this._columns;s++)for(let r=0;r<this._rows;r++)e[i++]=this._data[r*t+s*n];return e}toString(){const e=this.rows,t=this.columns,n=this.read(),i=new Array(e);for(let s=0;s<e;s++){i[s]=new Array(t);for(let r=0;r<t;r++)i[s][r]=n[r*e+s]}const s=e=>e.toFixed(5);return`SpeedyMatrix(rows=${e}, columns=${t}, data=[\n${i.map((e=>" "+e.map(s).join(", "))).join(",\n")}\n])`}setTo(e){return s.U.ready().then((t=>this.setToSync(e)))}setToSync(e){const{wasm:t,memory:n}=s.U.handle,i=e._evaluate(t,n);o.A.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 r=this._step0,a=this._step1,A=i._step0,c=i._step1;if(r===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*r+e*a]=i._data[t*A+e*c];return this}fill(e){return this.fillSync(e),r.i.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}}},6634:(e,t,n)=>{"use strict";n.d(t,{Q:()=>s});var i=n(8581);class s{constructor(){throw new i.aQ("Namespaces can't be instantiated")}}},9192:(e,t,n)=>{"use strict";n.d(t,{i:()=>s});const i="undefined"!=typeof queueMicrotask&&queueMicrotask||"undefined"!=typeof process&&process.nextTick||(e=>Promise.resolve().then((()=>e())));class s{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 s(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 s(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 s(this._snop);return t._value=e,t._state=2,t}static all(e){return new s(((t,n)=>{const i=[];for(const t of e)i.push(t);const r=i.length;if(0==r)return void t([]);let o=r;const a=new Array(r),A=e=>n=>{a[e]=n,0==--o&&t(a)};for(let e=0;e<r;e++){const t=i[e];t.__proto__===s.prototype||t.__proto__===Promise.prototype?t.then(A(e),n):s.resolve(t).then(A(e),n)}}))}static race(e){return new s(((t,n)=>{const i=[];for(const t of e)i.push(t);const r=i.length;for(let e=0;e<r;e++){const r=i[e];r.__proto__===s.prototype||r.__proto__===Promise.prototype?r.then(t,n):s.resolve(r).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__!==s.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(){}}},9420:(e,t,n)=>{"use strict";n.d(t,{gx:()=>M,bf:()=>Q});var i=n(1001),s=n(9037),r=n(6049),o=n(8581);function a(){a=function(e,t){return new n(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function n(e,i,s){var r=RegExp(e,i);return t.set(r,s||t.get(e)),A(r,n.prototype)}function i(e,n){var i=t.get(n);return Object.keys(i).reduce((function(t,n){var s=i[n];if("number"==typeof s)t[n]=e[s];else{for(var r=0;void 0===e[s[r]]&&r+1<s.length;)r++;t[n]=e[s[r]]}return t}),Object.create(null))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&A(e,t)}(n,RegExp),n.prototype.exec=function(t){var n=e.exec.call(this,t);if(n){n.groups=i(n,this);var s=n.indices;s&&(s.groups=i(s,this))}return n},n.prototype[Symbol.replace]=function(n,s){if("string"==typeof s){var r=t.get(this);return e[Symbol.replace].call(this,n,s.replace(/\$<([^>]+)>/g,(function(e,t){var n=r[t];return"$"+(Array.isArray(n)?n.join("$"):n)})))}if("function"==typeof s){var o=this;return e[Symbol.replace].call(this,n,(function(){var e=arguments;return"object"!=typeof e[e.length-1]&&(e=[].slice.call(e)).push(i(e,o)),s.apply(this,e)}))}return e[Symbol.replace].call(this,n,s)},a.apply(this,arguments)}function A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}const c=n(3816),l=Object.keys(c).filter((e=>"number"==typeof c[e])).reduce(((e,t)=>(e[t]=c[t],e)),{}),d=Object.freeze(Object.assign(Object.assign({},l),{},{FS_USE_CUSTOM_PRECISION:0,FS_OUTPUT_TYPE:0,PIXELCOMPONENT_RED:r.kQ.RED,PIXELCOMPONENT_GREEN:r.kQ.GREEN,PIXELCOMPONENT_BLUE:r.kQ.BLUE,PIXELCOMPONENT_ALPHA:r.kQ.ALPHA})),h=[/\/\*(.|\s)*?\*\//g,/\/\/.*$/gm],p=/^\s*@\s*include\s+"(.*?)"/gm,u=/@(\w+)@/g,g=[a(/@\s*unroll\s+?for\s*\(\s*(int|)\s*(\w+)\s*=\s*(\x2D?\d+|\w+)\s*;\s*\2\s*(<=?)\s*(\x2D?\d+|\w+)\s*;\s*\2\s*\+\+()\s*\)\s*\{\s*([\s\S]+?)\s*\}/g,{counter:2}),a(/@\s*unroll\s+?for\s*\(\s*(int|)\s*(\w+)\s*=\s*(\x2D?\d+|\w+)\s*;\s*\2\s*(<=?)\s*(\x2D?\d+|\w+)\s*;\s*\2\s*\+=\s*(\x2D?\d+)\s*\)\s*\{\s*([\s\S]+?)\s*\}/g,{counter:2})];class f{static generateGLSL(e,t,n=null,r=null){const o=[],a=function(e){s.A.assert(i.c.isInitialized());const t=new Map,n=Object.assign(Object.create(null),d,(r=s.A.platformString(),o=i.c.instance.renderer,Object.freeze({APPLE:0|/(Mac|iOS|iPhone|iPad|iPod)/i.test(r),APPLE_GPU:0|/Apple/.test(o),INTEL_GRAPHICS:0|/Intel.*Graphics/.test(o)})));var r,o;for(const e in n)t.set(e,n[e]);for(const[n,i]of e)t.set(n,i);return t}(e),A=function(e,t,n=null,i=null){const s=[];null!==n&&s.push(n);for(const[t,n]of e)s.push(`#define ${t} ${Number(n)}`);return s.push(t),null!==i&&s.push(i),s.join("\n")}(e,t,n,r);return function(e,t){const n=m.bind(t),i=g.length;for(let t=0;t<i;t++)e=e.replace(g[t],n);return e}(A.replace(h[0],"").replace(h[1],"").replace(u,((e,t)=>String(a.has(t)?Number(a.get(t)):(o.push(`Undefined constant ${t}`),0)))).replace(p,((t,n)=>f.generateGLSL(e,I(n)))),e)+o.map((e=>`\n#error ${e}\n`)).join("")}}function I(e){if(String(e).match(/^[a-zA-Z0-9_-]+\.glsl$/))return n(5235)("./"+e);throw new o.kG(`Shader preprocessor: can't read file "${e}"`)}function m(e,t,n,i,r,a,A,c){const l=this,d=Number.isFinite(+i)||l.has(i),h=Number.isFinite(+a)||l.has(a);if(!d||!h){if(l.size>0)throw new o.mB(`Can't unroll loop: unknown limits (start=${i}, end=${a}). Code:\n\n${e}`);return e}let p=l.has(i)?l.get(i):parseInt(i),u=l.has(a)?l.get(a):parseInt(a),g=0==A.length?1:parseInt(A);s.A.assert(p<=u&&g>0);let f=null!==c.match(/\bbreak\s*;/)?"switch(1) { default:\n":"{\n";f+=`${t} ${n};\n`,u+="<="==r?1:0;for(let e=p;e<u;e+=g)f+=`{\n${n} = ${e};\n${c}\n}\n`;return f+="}\n",f}const _=Object.freeze({position:"a_position",texCoord:"a_texCoord"}),y=Object.freeze({position:0,texCoord:1}),x=`#version 300 es\nprecision highp float;\nprecision highp int;\n\nlayout (location=${y.position}) in vec2 ${_.position};\nlayout (location=${y.texCoord}) in vec2 ${_.texCoord};\nout highp vec2 texCoord;\nuniform highp vec2 texSize;\n\n#define vsinit() gl_Position = vec4(${_.position}, 0.0f, 1.0f); texCoord = ${_.texCoord};\n\n\n`,C="#define vsmain() ;",E=Symbol();class S{constructor(e,t,n,i,s){if(e!==E)throw new o.Er;this._arguments=[...t],this._defines=new Map(n),this._fragmentSource=f.generateGLSL(this._defines,i,'#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'),this._vertexSource=f.generateGLSL(this._defines,s,x,"\n\nvoid main() { vsinit(); vsmain(); }\n"),this._uniforms=this._autodetectUniforms(this._fragmentSource+"\n"+this._vertexSource),this._validateArguments(this._arguments,this._uniforms)}get fragmentSource(){return this._fragmentSource}get vertexSource(){return this._vertexSource}get attributes(){return _}get locationOfAttributes(){return y}get arguments(){return[].concat(this._arguments)}get uniforms(){return Array.from(this._uniforms.keys())}uniformType(e){if(!this._uniforms.has(e))throw new o.qw(`Unrecognized uniform variable: "${e}"`);return this._uniforms.get(e)}definedConstant(e){if(!this._defines.has(e))throw new o.qw(`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 s;for(;null!==(s=n.exec(t));){const e=s[2],t=s[3].split(",").map((e=>e.trim())).filter((e=>e));for(const n of t)if(n.endsWith("]")){if(!(s=n.match(/(\w+)\s*\[\s*(\d+)\s*\]$/)))throw new o.mB(`Unspecified array length for uniform "${n}" in the shader`);const[t,r]=[s[1],Number(s[2])];for(let n=0;n<r;n++)i.set(`${t}[${n}]`,e)}else{if(i.has(n)&&i.get(n)!==e)throw new o.Er(`Redefinition of uniform "${n}" in the shader`);i.set(n,e)}}return i}_validateArguments(e,t){for(const n of e)if(!t.has(n)&&!t.has(n+"[0]"))throw new o.qw(`Argument "${n}" has not been declared in the shader`)}}class P extends S{constructor(e,t,n,i,s=C){super(e,t,n,i,s),this._fsUnprocessedSource=String(i),this._vsUnprocessedSource=String(s)}}class v extends S{constructor(e,t,i,s,r=""){if(!String(s).match(/^[a-zA-Z0-9_\-/]+\.glsl$/))throw new o.kG(`Can't import fragment shader at "${s}"`);if(""!=r&&!String(r).match(/^[a-zA-Z0-9_\-/]+\.vs\.glsl$/))throw new o.kG(`Can't import vertex shader at "${r}"`);super(e,t,i,n(4606)("./"+String(s)),""!=r?n(4606)("./"+String(r)):C),this._fsFilepath=String(s),this._vsFilepath=String(r)}get fragmentSource(){return this._addHeader("// File: "+this._fsFilepath,super.fragmentSource)}get vertexSource(){return this._addHeader("// File: "+(""!=this._vsFilepath?this._vsFilepath:"(default-vs) "+this._fsFilepath),super.vertexSource)}_addHeader(e,t){s.A.assert(e.startsWith("//")&&!e.includes("\n"));const n=t.indexOf("\n"),i=t.substr(0,n),r=t.substr(n);return s.A.assert(i.startsWith("#version ")),i+"\n"+e+r}}class w{constructor(e){if(e!==E)throw new o.Er;this._arguments=[],this._defines=new Map}withArguments(...e){if(this._arguments.length>0)throw new o.Er("Redefinition of shader arguments");for(let t=0;t<e.length;t++)this._arguments.push(String(e[t]));return this}withDefines(e){if(this._defines.size>0)throw new o.Er("Redefinition of externally defined constants of a shader");const t=Object.keys(e);for(const n of t){const t=Number(e[n]);this._defines.set(n,t)}return this}build(){throw new o.aQ}}class B extends w{constructor(e,t,n){super(e),this._fsSource=String(t),this._vsSource=void 0!==n?String(n):void 0}build(){return new P(E,this._arguments,this._defines,this._fsSource,this._vsSource)}}class b extends w{constructor(e,t,n){super(e),this._fsFilepath=String(t),this._vsFilepath=void 0!==n?String(n):void 0}build(){return new v(E,this._arguments,this._defines,this._fsFilepath,this._vsFilepath)}}function Q(e,t=void 0){return new b(E,e,t)}function M(e,t=void 0){return new B(E,e,t)}},1672:(e,t,n)=>{"use strict";n.r(t),n.d(t,{conv2D:()=>o,convX:()=>a,convY:()=>A});var i=n(9420),s=n(9037),r=n(8581);function o(e,t=1){const n=new Float32Array(e.map((e=>+e*+t))),o=0|Math.sqrt(n.length),a=o>>1;if(o<1||o%2==0)throw new r.qw(`Can't perform a 2D convolution with an invalid kSize of ${o}`);if(o*o!=n.length)throw new r.qw(`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 `,s.A.cartesian(s.A.symmetricRange(a),s.A.symmetricRange(a)).map((e=>l(n[(e[0]+a)*o+(e[1]+a)],e[0],e[1]))).join("\n")}\n\n color = vec4(result.rgb, alpha);\n }\n `;var l;return(0,i.gx)(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 o=new Float32Array(t.map((e=>+e*+n))),a=o.length,A=a>>1;if(a<1||a%2==0)throw new r.qw(`Can't perform a 1D convolution with an invalid kSize of ${a}`);if("x"!=e&&"y"!=e)throw new r.qw(`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 `,s.A.symmetricRange(A).reduce(((e,t)=>e+d(o[t+A],t)),"")}\n\n color = vec4(pixel.rgb, alpha);\n }\n `;var d;return(0,i.gx)(l).withArguments("image")}},1001:(e,t,n)=>{"use strict";n.d(t,{c:()=>d});var i=n(9037),s=n(2199),r=n(3211),o=n(9192),a=n(8581);const A=Symbol();let c=null,l="default";class d extends r.c{constructor(e){i.A.assert(e===A),super(),this._reinitializeOnContextLoss=!0,this._canvas=this._createCanvas(this._reinitialize.bind(this)),this._gl=this._createContext(this._canvas),this._vendor="",this._renderer="",this._readDriverInfo(),"diagnostic"===s.w.logging&&this._logDriverInfo()}static get instance(){return c||(c=new d(A))}get gl(){return this._gl}get canvas(){return this._canvas}get renderer(){return this._renderer}get vendor(){return this._vendor}_createCanvas(e){const t=i.A.createCanvas(16,16);return t.addEventListener("webglcontextlost",(t=>{i.A.warning("Lost WebGL2 context"),setTimeout(e,0),t.preventDefault()}),!1),t}_createContext(e){if(i.A.log(`Creating a ${l} WebGL2 rendering context...`),"undefined"==typeof WebGL2RenderingContext)throw new a.EM("This application requires WebGL2. Please update your system.");const t=e.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!1,powerPreference:l,alpha:!0,antialias:!1,depth:!1,stencil:!1,desynchronized:!0});if(!t)throw new a.EM("Can't create a WebGL2 Rendering Context. Try a different browser!");return t}_reinitialize(){this._reinitializeOnContextLoss&&(i.A.warning("Reinitializing WebGL2..."),this._canvas.remove(),this._canvas=this._createCanvas(this._reinitialize.bind(this)),this._gl=this._createContext(this._canvas),this._readDriverInfo(),this._notify())}_readDriverInfo(){const e=this._gl;let t=null;navigator.userAgent.includes("Firefox")?(this._vendor="",this._renderer=e.getParameter(e.RENDERER)):null!=(t=e.getExtension("WEBGL_debug_renderer_info"))?(this._vendor=e.getParameter(t.UNMASKED_VENDOR_WEBGL),this._renderer=e.getParameter(t.UNMASKED_RENDERER_WEBGL)):(this._vendor="",this._renderer="")}_logDriverInfo(){i.A.log("Platform: "+i.A.platformString()),i.A.log("GL vendor: "+this.vendor),i.A.log("GL renderer: "+this.renderer)}loseContext(){const e=this._gl,t=e.getExtension("WEBGL_lose_context");if(!t)throw new a.EM("WEBGL_lose_context extension is unavailable");return e.isContextLost()||(this._reinitializeOnContextLoss=!1,t.loseContext()),t}loseAndRestoreContext(e=1){const t=1e3*Math.max(e,0),n=this.loseContext();return new o.i((e=>{setTimeout((()=>{this._reinitializeOnContextLoss=!0,this._reinitialize(),setTimeout((()=>e(n)),0)}),t)}))}static get powerPreference(){return l}static set powerPreference(e){if("default"!==e&&"low-power"!==e&&"high-performance"!==e)throw new a.qw(`Invalid powerPreference: "${e}"`);null!=c&&l===e||(l=e,null!=c&&c.loseAndRestoreContext())}static isInitialized(){return null!=c}}},8581:(e,t,n)=>{"use strict";n.d(t,{EM:()=>s,Er:()=>A,FJ:()=>d,MU:()=>h,NO:()=>f,Uk:()=>g,aQ:()=>o,kG:()=>l,l:()=>c,mB:()=>p,pf:()=>u,qw:()=>a,wB:()=>r,xB:()=>i});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 s extends i{constructor(e="",t=null){super(`Unsupported operation. ${e}`,t)}}class r 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 r(n)}}class o 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(`Resource not loaded. ${e}`,t)}}class h extends i{constructor(e="",t=null){super(`Timeout error. ${e}`,t)}}class p extends i{constructor(e="",t=null){super(`Parse error. ${e}`,t)}}class u extends i{constructor(e="",t=null){super(`Assertion failed. ${e}`,t)}}class g extends i{constructor(e="",t=null){super(`Access denied. ${e}`,t)}}class f extends i{constructor(e="",t=null){super(`WebAssembly error. ${e}`,t)}}},3816:(e,t,n)=>{"use strict";n.r(t),n.d(t,{DEFAULT_ENCODER_CAPACITY:()=>h,FIX_BITS:()=>o,FIX_RESOLUTION:()=>a,LITTLE_ENDIAN:()=>_,LOG2_MAX_DESCRIPTOR_SIZE:()=>p,LOG2_PYRAMID_MAX_SCALE:()=>s,MATCH_INDEX_BITS:()=>g,MATCH_INDEX_MASK:()=>f,MATCH_MAX_DISTANCE:()=>m,MATCH_MAX_INDEX:()=>I,MAX_DESCRIPTOR_SIZE:()=>u,MAX_ENCODER_CAPACITY:()=>d,MAX_TEXTURE_LENGTH:()=>A,MIN_ENCODER_LENGTH:()=>l,MIN_KEYPOINT_SIZE:()=>c,PYRAMID_MAX_LEVELS:()=>i,PYRAMID_MAX_SCALE:()=>r});const i=8,s=0,r=1<<s,o=3,a=1<<o,A=(1<<16-o)-1,c=8,l=2,d=8192,h=2048,p=6,u=1<<p,g=32-(p+3),f=(1<<g)-1,I=(1<<g)-1,m=(1<<32-g)-1,_=51966===new Uint16Array(new Uint8Array([254,202]).buffer)[0]},3211:(e,t,n)=>{"use strict";n.d(t,{c:()=>i});class i{constructor(){this._subscribers=[],this._thisptr=[],this._args=[]}subscribe(e,t,...n){this._subscribers.push(e),this._thisptr.push(t),this._args.push(n)}unsubscribe(e,t){for(let n=this._subscribers.length-1;n>=0;n--)if(this._subscribers[n]===e&&this._thisptr[n]===t){this._subscribers.splice(n,1),this._thisptr.splice(n,1),this._args.splice(n,1);break}}_notify(){for(let e=0;e<this._subscribers.length;e++)this._subscribers[e].apply(this._thisptr[e],this._args[e])}}},6049:(e,t,n)=>{"use strict";n.d(t,{f5:()=>s,kQ:()=>r,kg:()=>o,zu:()=>i});const i=Object.freeze({Image:Symbol("Image"),Video:Symbol("Video"),Canvas:Symbol("Canvas"),OffscreenCanvas:Symbol("OffscreenCanvas"),Bitmap:Symbol("Bitmap"),Data:Symbol("Data")}),s=Object.freeze({RGBA:Symbol("RGBA"),GREY:Symbol("GREY")}),r=Object.freeze({RED:1,GREEN:2,BLUE:4,ALPHA:8,ALL:15}),o=Object.freeze({[r.RED]:0,[r.GREEN]:1,[r.BLUE]:2,[r.ALPHA]:3})},9037:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var i=n(8581),s=n(9192),r=n(2199);class o{static warning(e,...t){"none"!==r.w.logging&&console.warn("[speedy-vision] "+e,...t)}static log(e,...t){"none"!==r.w.logging&&console.log("[speedy-vision] "+e,...t)}static assert(e,t=""){if(!e)throw new i.pf(t)}static functionArguments(e){const t=e.toString(),n=t.startsWith("function")?"function\\s.*\\(([^)]*)\\)":t.startsWith("(")?"\\(([^)]*)\\).*=>":"([^=]+).*=>",s=new RegExp(n).exec(t);if(null!==s)return s[1].replace(/\/\*.*?\*\//g,"").split(",").map((e=>e.replace(/=.*$/,"").trim())).filter((e=>e));throw new i.mB(`Can't detect function arguments of ${t}`)}static getAllPropertyDescriptors(e){if(e){const t=Object.getPrototypeOf(e);return Object.assign(Object.assign({},o.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 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.qw(`Invalid kernel size given to gaussianKernel: ${t} x 1`);if(e<=0)throw new i.qw(`Invalid sigma given to gaussianKernel: ${e}`);const s=new Array(t),r=t>>1,o=1.4142135623730951*+e,a=.3275911,A=.254829592,c=-.284496736,l=1.421413741,d=-1.453152027,h=1.061405429;let p=0;for(let e=0;e<t;e++){let t=(e-r+.5)/o,n=(e-r-.5)/o,i=1,u=1;t<0&&(i=-1,t=-t),n<0&&(u=-1,n=-n);const g=1/(1+a*t),f=1/(1+a*n),I=((((h*f+d)*f+l)*f+c)*f+A)*f,m=(i*(1-((((h*g+d)*g+l)*g+c)*g+A)*g*Math.exp(-t*t))-u*(1-I*Math.exp(-n*n)))/(2*o);s[e]=m,p+=m}if(n)for(let e=0;e<t;e++)s[e]/=p;return s}static kernel2d(e,t=e){const n=e.length;o.assert(e.length==e.length),o.assert(n>=1&&n%2==1);let i=new Array(n*n),s=0;for(let r=0;r<n;r++)for(let o=0;o<n;o++)i[s++]=e[o]*t[r];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.qw("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.qw("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);return 0==t?0==n?0*i:i*n*5.960464477539063e-8:31==t?0==n?i*Number.POSITIVE_INFINITY:Number.NaN:i*(t>=15?1<<t-15:1/(1<<15-t))*(1+.0009765625*n)}static requestCameraStream(e={audio:!1,video:!0}){if(o.log("Accessing the webcam..."),!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new i.EM("Unsupported browser: no mediaDevices.getUserMedia()");return new s.i(((t,n)=>{navigator.mediaDevices.getUserMedia(e).then((n=>{const i=document.createElement("video");i.onloadedmetadata=()=>{i.play(),o.log(`The camera is on! Resolution: ${i.videoWidth} x ${i.videoHeight}`),t(i)},i.setAttribute("playsinline",""),i.setAttribute("autoplay",""),!1!==e.audio&&void 0!==e.audio||i.setAttribute("muted",""),i.srcObject=n})).catch((t=>{"NotAllowedError"===t.name?n(new i.Uk("Please give access to the camera and reload the page.",t)):"OverconstrainedError"===t.name||"NotFoundError"===t.name?n(new i.EM(`Can't access the webcam with the requested constraints: ${JSON.stringify(e)}.`,t)):n(new i.xB("Can't access the webcam.",t))}))}))}static formatBinaryData(e){const t=new Uint8Array(e);return Array.from(t,(e=>e.toString(16).padStart(2,"0"))).join(" ")}static platformString(){return"object"==typeof navigator.userAgentData?navigator.userAgentData.platform:navigator.platform}}},5235:(e,t,n)=>{var i={"./colors.glsl":8609,"./filters.glsl":4672,"./fixed-point.glsl":9778,"./float16.glsl":8710,"./global.glsl":2434,"./int32.glsl":439,"./keypoint-descriptors.glsl":8545,"./keypoint-matches.glsl":6762,"./keypoints.glsl":7639,"./math.glsl":431,"./platform.glsl":6822,"./pyramids.glsl":2728,"./subpixel.glsl":6823};function s(e){var t=r(e);return n(t)}function r(e){if(!n.o(i,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return i[e]}s.keys=function(){return Object.keys(i)},s.resolve=r,e.exports=s,s.id=5235},4606:(e,t,n)=>{var i={"./filters/convolution":1672,"./filters/convolution.js":1672,"./filters/convolution1d.glsl":8211,"./filters/convolution2d.glsl":7360,"./filters/fast-median.glsl":8191,"./filters/nightvision.glsl":4438,"./filters/normalize-image.glsl":5867,"./filters/rgb2grey.glsl":9252,"./include/colors.glsl":8609,"./include/filters.glsl":4672,"./include/fixed-point.glsl":9778,"./include/float16.glsl":8710,"./include/global.glsl":2434,"./include/int32.glsl":439,"./include/keypoint-descriptors.glsl":8545,"./include/keypoint-matches.glsl":6762,"./include/keypoints.glsl":7639,"./include/math.glsl":431,"./include/platform.glsl":6822,"./include/pyramids.glsl":2728,"./include/subpixel.glsl":6823,"./keypoints/allocate-descriptors.glsl":1341,"./keypoints/allocate-extra.glsl":7833,"./keypoints/apply-homography.glsl":2352,"./keypoints/bf-knn.glsl":7541,"./keypoints/clip-border.glsl":4868,"./keypoints/clip.glsl":5591,"./keypoints/distance-filter.glsl":191,"./keypoints/encode-keypoint-long-offsets.glsl":5467,"./keypoints/encode-keypoint-offsets.glsl":336,"./keypoints/encode-keypoint-positions.glsl":8968,"./keypoints/encode-keypoint-properties.glsl":1733,"./keypoints/encode-keypoints.glsl":9674,"./keypoints/encode-null-keypoints.glsl":2090,"./keypoints/fast.glsl":1855,"./keypoints/fast.vs.glsl":4824,"./keypoints/hamming-distance-filter.glsl":2381,"./keypoints/harris-cutoff.glsl":6060,"./keypoints/harris.glsl":9974,"./keypoints/knn-init.glsl":3047,"./keypoints/knn-transfer.glsl":3266,"./keypoints/laplacian.glsl":8018,"./keypoints/lk.glsl":3168,"./keypoints/lookup-of-locations.glsl":3890,"./keypoints/lookup-of-locations.vs.glsl":8647,"./keypoints/lsh-knn.glsl":4776,"./keypoints/mix-keypoints.glsl":2648,"./keypoints/nonmax-scale.glsl":8825,"./keypoints/nonmax-space.glsl":5693,"./keypoints/nonmax-suppression.glsl":9280,"./keypoints/orb-descriptor.glsl":9108,"./keypoints/orb-orientation.glsl":7137,"./keypoints/refine-scale.glsl":9739,"./keypoints/score-findmax.glsl":8231,"./keypoints/shuffle.glsl":2518,"./keypoints/sort-keypoints.glsl":8096,"./keypoints/subpixel-refinement.glsl":5795,"./keypoints/transfer-flow.glsl":3169,"./keypoints/transfer-orientation.glsl":1337,"./keypoints/transfer-to-extra.glsl":6187,"./keypoints/upload-keypoints.glsl":477,"./pyramids/downsample2.glsl":4050,"./pyramids/upsample2.glsl":5545,"./transforms/additive-mix.glsl":7113,"./transforms/resize.glsl":1202,"./transforms/warp-perspective.glsl":7971,"./utils/copy-components.glsl":6122,"./utils/copy-raster.glsl":371,"./utils/copy.glsl":7307,"./utils/fill-components.glsl":8614,"./utils/fill.glsl":6271,"./utils/flip-y.vs.glsl":3016,"./utils/scan-minmax2d.glsl":3630,"./utils/sobel-derivatives.glsl":8508,"./utils/sobel-derivatives.vs.glsl":8073};function s(e){var t=r(e);return n(t)}function r(e){if(!n.o(i,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return i[e]}s.keys=function(){return Object.keys(i)},s.resolve=r,e.exports=s,s.id=4606},8211: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}"},7360:e=>{e.exports="#ifndef KERNEL_SIZE_SQUARED\n#error 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}"},8191: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}"},4438: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}"},5867: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}"},9252: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}"},8609: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"},4672: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"},9778: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"},8710: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"},2434: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"},439:e=>{e.exports='#ifndef _INT32_GLSL\n#define _INT32_GLSL\n@include "platform.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{\n#if defined(APPLE_GPU) || (defined(APPLE) && defined(INTEL_GRAPHICS))\nuvec4 v = uvec4(value, value / 256u, value / 65536u, value / 16777216u) % 256u;\nreturn vec4(v) / 255.0f;\n#else\nuvec4 v = uvec4(value, value >> 8u, value >> 16u, value >> 24u) & 255u;\nreturn vec4(v) / 255.0f;\n#endif\n}\n#endif'},8545: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"},6762: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) & uint(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'},7639: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 isNullKeypoint(keypoint) ((((keypoint).flags) & KPF_NULL) != 0u)\n#define isDiscardedKeypoint(keypoint) ((((keypoint).flags) & KPF_DISCARDED) != 0u)\n#define isBadKeypoint(keypoint) ((keypoint).score < 0.0f)\n#define sizeofEncodedKeypoint(descriptorSize, extraSize) (MIN_KEYPOINT_SIZE + (descriptorSize) + (extraSize))\n#define sizeofEncodedKeypointHeader() sizeofEncodedKeypoint(0,0)\n#define findKeypointIndex(address, descriptorSize, extraSize) ((address).base / ((sizeofEncodedKeypoint((descriptorSize), (extraSize))) / 4))\nvec4 readKeypointData(sampler2D encodedKeypoints, int encoderLength, KeypointAddress address)\n{\nint rasterIndex = address.base + address.offset;\nvec4 data = pixelAt(encodedKeypoints, ivec2(rasterIndex % encoderLength, rasterIndex / encoderLength));\nreturn rasterIndex < encoderLength * encoderLength ? data : encodeNullKeypoint();\n}\nKeypointAddress findKeypointAddress(ivec2 thread, int encoderLength, int descriptorSize, int extraSize)\n{\nint threadRaster = thread.y * encoderLength + thread.x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nint keypointIndex = int(threadRaster / pixelsPerKeypoint);\nKeypointAddress address = KeypointAddress(\nkeypointIndex * pixelsPerKeypoint,\nthreadRaster % pixelsPerKeypoint\n);\nreturn address;\n}\nKeypoint decodeKeypoint(sampler2D encodedKeypoints, int encoderLength, KeypointAddress address)\n{\nKeypoint keypoint;\nKeypointAddress positionAddress = KeypointAddress(address.base, 0);\nKeypointAddress propertiesAddress = KeypointAddress(address.base, 1);\nvec4 rawEncodedPosition = readKeypointData(encodedKeypoints, encoderLength, positionAddress);\nivec4 encodedPosition = ivec4(rawEncodedPosition * 255.0f);\nkeypoint.position = fixtovec2(fixed2_t(\nencodedPosition.r | (encodedPosition.g << 8),\nencodedPosition.b | (encodedPosition.a << 8)\n));\nvec4 rawEncodedProperties = readKeypointData(encodedKeypoints, encoderLength, propertiesAddress);\nkeypoint.lod = decodeLod(rawEncodedProperties.r);\nkeypoint.orientation = decodeKeypointOrientation(rawEncodedProperties.g);\nkeypoint.score = decodeKeypointScore(rawEncodedProperties.ba);\nbool isNull = all(equal(rawEncodedPosition, vec4(1)));\nbool isDiscarded = all(equal(rawEncodedPosition + rawEncodedProperties, vec4(0)));\nkeypoint.score = (isNull || isDiscarded) ? -1.0f : keypoint.score;\nkeypoint.flags = KPF_NONE;\nkeypoint.flags |= KPF_NULL * uint(isNull);\nkeypoint.flags |= KPF_DISCARDED * uint(isDiscarded);\nreturn keypoint;\n}\nvec4 encodeKeypointPosition(vec2 position)\n{\nconst vec2 zeros = vec2(0.0f);\nfixed2_t pos = vec2tofix(max(position, zeros));\nfixed2_t lo = pos & 255;\nfixed2_t hi = (pos >> 8) & 255;\nreturn vec4(lo.x, hi.x, lo.y, hi.y) / 255.0f;\n}\n#endif'},431:e=>{e.exports="#ifndef _MATH_GLSL\n#define _MATH_GLSL\n#define TWO_PI 6.28318530718f\n#define PI 3.14159265359f\n#define PI_OVER_2 1.57079632679f\n#define PI_OVER_4 0.78539816339f\n#define INV_PI 0.3183098861837907f\n#define INV_PI_OVER_2 0.15915494309189535f\nconst highp float INFINITY = 1.0f / 0.0f;\nfloat fastAtan(float x)\n{\nfloat w = 1.0f - abs(x);\nreturn (w >= 0.0f) ? ((PI_OVER_4 + 0.273f * w) * x) :\n(sign(x) * PI_OVER_2 - (PI_OVER_4 + 0.273f * (1.0f - abs(1.0f / x))) / x);\n}\nfloat fastAtan2(float y, float x)\n{\nreturn (x == 0.0f) ? PI_OVER_2 * sign(y) : fastAtan(y / x) + float(x < 0.0f) * PI * sign(y);\n}\n#endif"},6822:e=>{e.exports="#ifndef _PLATFORM_GLSL\n#define _PLATFORM_GLSL\n#if @APPLE@\n#define APPLE 1\n#endif\n#if @APPLE_GPU@\n#define APPLE_GPU 1\n#endif\n#if @INTEL_GRAPHICS@\n#define INTEL_GRAPHICS 1\n#endif\n#endif"},2728:e=>{e.exports="#ifndef _PYRAMIDS_GLSL\n#define _PYRAMIDS_GLSL\n#define pyrPixel(pyr, lod) textureLod((pyr), texCoord, (lod))\n#define pyrPixelAtOffset(pyr, lod, pot, offset) textureLod((pyr), texCoord + ((pot) * vec2(offset)) / texSize, (lod))\n#define pyrPixelAt(pyr, pos, lod) textureLod((pyr), (vec2(pos) + vec2(0.5f)) / texSize, (lod))\n#define pyrPixelAtEx(pyr, pos, lod, pyrBaseSize) textureLod((pyr), (vec2(pos) + vec2(0.5f)) / vec2(pyrBaseSize), (lod))\n#define pyrSubpixelAtEx(pyr, pos, lod, pyrBaseSize) textureLod((pyr), ((pos) + vec2(0.5f)) / vec2(pyrBaseSize), (lod))\n#define pyrSubpixelAtExOffset(pyr, pos, lod, pot, offset, pyrBaseSize) textureLod((pyr), (((pos) + vec2(0.5f)) + ((pot) * vec2(offset))) / vec2(pyrBaseSize), (lod))\nconst int PYRAMID_MAX_LEVELS = int(@PYRAMID_MAX_LEVELS@);\nconst float F_PYRAMID_MAX_LEVELS = float(@PYRAMID_MAX_LEVELS@);\nconst float LOG2_PYRAMID_MAX_SCALE = float(@LOG2_PYRAMID_MAX_SCALE@);\n#define encodeLod(lod) ((LOG2_PYRAMID_MAX_SCALE + (lod)) / (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS))\nfloat decodeLod(float encodedLod)\n{\nfloat lod = encodedLod * (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS) - LOG2_PYRAMID_MAX_SCALE;\nreturn lod - lod * step(1.0f, encodedLod);\n}\n#define LOD_EPS 0.0625f\nconst float ENCODED_LOD_EPS = (LOD_EPS / (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS));\n#define isSameLod(lod1, lod2) (abs((lod1) - (lod2)) < LOD_EPS)\n#define isSameEncodedLod(alpha1, alpha2) (abs((alpha1) - (alpha2)) < ENCODED_LOD_EPS)\n#endif"},6823:e=>{e.exports="#ifndef _SUBPIXEL_GLSL\n#define _SUBPIXEL_GLSL\n#define subpixelAt(image, pos) textureLod((image), ((pos) + vec2(0.5f)) / texSize, 0.0f)\nvec4 subpixelAtBI(sampler2D image, vec2 pos)\n{\nvec2 frc = fract(pos);\nvec2 ifrc = vec2(1.0f) - frc;\nvec2 p = (floor(pos) + vec2(0.5f)) / vec2(textureSize(image, 0));\nvec4 pix00 = textureLod(image, p, 0.0f);\nvec4 pix10 = textureLodOffset(image, p, 0.0f, ivec2(1,0));\nvec4 pix01 = textureLodOffset(image, p, 0.0f, ivec2(0,1));\nvec4 pix11 = textureLodOffset(image, p, 0.0f, ivec2(1,1));\nmat4 pix = mat4(pix00, pix10, pix01, pix11);\nvec4 mul = vec4(ifrc.x * ifrc.y, frc.x * ifrc.y, ifrc.x * frc.y, frc.x * frc.y);\nreturn pix * mul;\n}\n#endif"},1341:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D inputEncodedKeypoints;\nuniform int inputDescriptorSize;\nuniform int inputExtraSize;\nuniform int inputEncoderLength;\nuniform int outputDescriptorSize;\nuniform int outputExtraSize;\nuniform int outputEncoderLength;\nconst vec4 EMPTY_DESCRIPTOR = vec4(0.0f);\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress myAddress = findKeypointAddress(thread, outputEncoderLength, outputDescriptorSize, outputExtraSize);\nint myIndex = findKeypointIndex(myAddress, outputDescriptorSize, outputExtraSize);\nint headerSize = sizeofEncodedKeypointHeader();\nbool isDescriptor = (myAddress.offset >= (headerSize + outputExtraSize) / 4);\nint addressOffset = myAddress.offset;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(inputDescriptorSize, inputExtraSize) / 4;\nKeypointAddress otherAddress = KeypointAddress(myIndex * pixelsPerKeypoint, addressOffset);\ncolor = isDescriptor ? EMPTY_DESCRIPTOR : readKeypointData(inputEncodedKeypoints, inputEncoderLength, otherAddress);\n}'},7833:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D inputEncodedKeypoints;\nuniform int inputDescriptorSize;\nuniform int inputExtraSize;\nuniform int inputEncoderLength;\nuniform int outputDescriptorSize;\nuniform int outputExtraSize;\nuniform int outputEncoderLength;\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress myAddress = findKeypointAddress(thread, outputEncoderLength, outputDescriptorSize, outputExtraSize);\nint myIndex = findKeypointIndex(myAddress, outputDescriptorSize, outputExtraSize);\nint headerSize = sizeofEncodedKeypointHeader();\nbool isHead = (myAddress.offset < headerSize / 4);\nbool isDescriptor = (myAddress.offset >= (headerSize + outputExtraSize) / 4);\nbool isExtra = (!isHead && !isDescriptor);\nint numberOfExtraPixels = outputExtraSize / 4;\nint addressOffset = myAddress.offset - int(isDescriptor) * numberOfExtraPixels;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(inputDescriptorSize, inputExtraSize) / 4;\nKeypointAddress otherAddress = KeypointAddress(myIndex * pixelsPerKeypoint, addressOffset);\ncolor = isExtra ? vec4(0.0f) : readKeypointData(inputEncodedKeypoints, inputEncoderLength, otherAddress);\n}'},2352:e=>{e.exports='@include "keypoints.glsl"\nuniform mat3 homography;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nvoid main()\n{\nvec4 pixel = threadPixel(encodedKeypoints);\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\ncolor = pixel;\nif(address.offset != 0)\nreturn;\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\nif(isBadKeypoint(keypoint))\nreturn;\nvec3 pos3 = homography * vec3(keypoint.position, 1.0f);\ncolor = encodeKeypointPosition(pos3.xy / pos3.z);\n}'},7541:e=>{e.exports='@include "keypoints.glsl"\n@include "keypoint-descriptors.glsl"\n@include "keypoint-matches.glsl"\nuniform sampler2D encodedMatches;\nuniform sampler2D encodedFilters;\nuniform int matcherLength;\nuniform sampler2D dbEncodedKeypoints;\nuniform int dbDescriptorSize;\nuniform int dbExtraSize;\nuniform int dbEncoderLength;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform int passId;\n#ifndef NUMBER_OF_KEYPOINTS_PER_PASS\n#error Undefined NUMBER_OF_KEYPOINTS_PER_PASS\n#endif\nconst int INFINITE_DISTANCE = MATCH_MAX_DISTANCE + 1;\nvoid main()\n{\nivec2 thread = threadLocation();\nint keypointIndex = thread.x + thread.y * matcherLength;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\ncolor = encodeKeypointMatch(MATCH_NOT_FOUND);\nif(isBadKeypoint(keypoint))\nreturn;\nKeypointMatch bestMatch = decodeKeypointMatch(threadPixel(encodedMatches));\nKeypointMatch filterMatch = decodeKeypointMatch(threadPixel(encodedFilters));\nuint[DESCRIPTOR_SIZE] descriptor = readKeypointDescriptor(encodedKeypoints, descriptorSize, extraSize, encoderLength, address);\nuint[DESCRIPTOR_SIZE] dbDescriptor;\nint dbPixelsPerKeypoint = sizeofEncodedKeypoint(dbDescriptorSize, dbExtraSize) / 4;\nfor(int i = 0; i < NUMBER_OF_KEYPOINTS_PER_PASS; i++) {\nint dbKeypointIndex = passId * NUMBER_OF_KEYPOINTS_PER_PASS + i;\nKeypointAddress dbAddress = KeypointAddress(dbKeypointIndex * dbPixelsPerKeypoint, 0);\nKeypoint dbKeypoint = decodeKeypoint(dbEncodedKeypoints, dbEncoderLength, dbAddress);\ndbDescriptor = readKeypointDescriptor(dbEncodedKeypoints, dbDescriptorSize, dbExtraSize, dbEncoderLength, dbAddress);\nint dist = !isBadKeypoint(dbKeypoint) ? distanceBetweenKeypointDescriptors(descriptor, dbDescriptor) : INFINITE_DISTANCE;\nbestMatch.index = all(bvec2(\ndist < bestMatch.dist || (dist == bestMatch.dist && dbKeypointIndex > bestMatch.index),\ndist > filterMatch.dist || (dist == filterMatch.dist && dbKeypointIndex < filterMatch.index)\n)) ? dbKeypointIndex : bestMatch.index;\nbestMatch.dist = dbKeypointIndex == bestMatch.index ? dist : bestMatch.dist;\n}\ncolor = encodeKeypointMatch(bestMatch);\n}'},4868:e=>{e.exports='@include "keypoints.glsl"\nuniform int imageWidth;\nuniform int imageHeight;\nuniform int borderTop;\nuniform int borderRight;\nuniform int borderBottom;\nuniform int borderLeft;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress addr = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, addr);\nvec2 p = keypoint.position;\nbool withinBorder = any(lessThan(\nvec4(p.x, p.y, -p.x, -p.y),\nvec4(borderLeft, borderTop, borderRight - (imageWidth - 1), borderBottom - (imageHeight - 1))\n));\nvec4 pixel = threadPixel(encodedKeypoints);\nvec4 nullPixel = encodeNullKeypoint();\ncolor = withinBorder ? nullPixel : pixel;\n}'},5591:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform int maxKeypoints;\nvoid main()\n{\nivec2 thread = threadLocation();\nint newEncoderLength = outputSize().x;\nKeypointAddress address = findKeypointAddress(thread, newEncoderLength, descriptorSize, extraSize);\nint index = findKeypointIndex(address, descriptorSize, extraSize);\nvec4 pixel = readKeypointData(encodedKeypoints, encoderLength, address);\ncolor = index < maxKeypoints ? pixel : encodeNullKeypoint();\n}'},191:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedKeypointsA;\nuniform int encoderLengthA;\nuniform sampler2D encodedKeypointsB;\nuniform int encoderLengthB;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform float threshold;\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint index = findKeypointIndex(address, descriptorSize, extraSize);\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nvec4 data = readKeypointData(encodedKeypointsA, encoderLengthA, address);\ncolor = data;\nif(address.offset >= sizeofEncodedKeypointHeader() / 4)\nreturn;\nKeypoint keypointA = decodeKeypoint(encodedKeypointsA, encoderLengthA, address);\nKeypoint keypointB = decodeKeypoint(encodedKeypointsB, encoderLengthB, address);\ncolor = encodeNullKeypoint();\nif(isNullKeypoint(keypointA) && isNullKeypoint(keypointB))\nreturn;\ncolor = encodeDiscardedKeypoint();\nif(isDiscardedKeypoint(keypointA) || isDiscardedKeypoint(keypointB))\nreturn;\ncolor = encodeDiscardedKeypoint();\nif(isNullKeypoint(keypointA) || isNullKeypoint(keypointB))\nreturn;\nvec2 delta = keypointA.position - keypointB.position;\nbool shouldKeep = (dot(delta, delta) <= threshold * threshold);\ncolor = shouldKeep ? data : encodeDiscardedKeypoint();\n}'},5467:e=>{e.exports='@include "float16.glsl"\nuniform sampler2D offsetsImage;\nuniform ivec2 imageSize;\n#ifndef MAX_ITERATIONS\n#error Undefined MAX_ITERATIONS\n#endif\n#define decodeSkipOffset(pixel) (int((pixel).g * 255.0f) | (int((pixel).a * 255.0f) << 8))\n#define encodeSkipOffset(offset) (vec2((offset) & 255, (offset) >> 8) / 255.0f)\nvoid main()\n{\nvec4 pixel = threadPixel(offsetsImage);\nivec2 thread = threadLocation();\nint rasterIndex = thread.y * imageSize.x + thread.x;\nint offset = decodeSkipOffset(pixel);\nint totalOffset = offset;\nvec2 encodedScore = pixel.rb;\nivec2 pos = thread; int allow = 1;\n@unroll\nfor(int i = 0; i < MAX_ITERATIONS; i++) {\nallow *= int(pos.y < imageSize.y) * int(isEncodedFloat16Zero(pixel.rb));\nrasterIndex += allow * offset;\npos = ivec2(rasterIndex % imageSize.x, rasterIndex / imageSize.x);\npixel = pixelAt(offsetsImage, pos);\noffset = decodeSkipOffset(pixel);\ntotalOffset += allow * offset;\n}\ntotalOffset = min(totalOffset, 65535);\ncolor.rb = encodedScore;\ncolor.ga = encodeSkipOffset(totalOffset);\n}'},336:e=>{e.exports='@include "float16.glsl"\nuniform sampler2D corners;\nuniform ivec2 imageSize;\nvoid main()\n{\nvec4 pixel = threadPixel(corners);\nivec2 pos = threadLocation();\nvec2 encodedScore = pixel.rb;\nint offset = 0, allow = 1, jumped = 0;\n#define READ(j) ; \\\nallow *= int(pos.y < imageSize.y) * int(isEncodedFloat16Zero(pixel.rb)); \\\noffset += allow; \\\npos.x = (pos.x + 1) % imageSize.x; \\\npos.y += int(pos.x == 0); \\\npixel = (0 != (jumped |= int(pos.x == 0))) ? pixelAtShortOffset(corners, ivec2((j),1)) : pixelAtShortOffset(corners, ivec2((j),0))\nREAD(1); READ(2); READ(3); READ(4); READ(5); READ(6); READ(7);\ncolor.rb = encodedScore;\ncolor.ga = vec2(offset, 0) / 255.0f;\n}'},8968:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D offsetsImage;\nuniform ivec2 imageSize;\nuniform int passId;\nuniform int numPasses;\nuniform int keypointLimit;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#define decodeSkipOffset(pixel) (int((pixel).g * 255.0f) | (int((pixel).a * 255.0f) << 8))\nbool findQthKeypoint(int q, int p, inout ivec2 position, out vec4 pixel)\n{\nint notFirstPass = int(passId > 0);\nposition *= notFirstPass;\np |= -(1 - notFirstPass);\np -= notFirstPass;\nint rasterIndex = position.y * imageSize.x + position.x;\nwhile(position.y < imageSize.y && p != q) {\nposition = ivec2(rasterIndex % imageSize.x, rasterIndex / imageSize.x);\npixel = texelFetch(offsetsImage, position, 0);\np += int(!isEncodedFloat16Zero(pixel.rb));\nrasterIndex += max(1, decodeSkipOffset(pixel));\n}\nreturn (p == q);\n}\nvoid main()\n{\nivec2 thread = threadLocation();\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint q = findKeypointIndex(address, descriptorSize, extraSize);\ncolor = vec4(0.0f);\nif(address.offset != 0)\nreturn;\ncolor = threadPixel(encodedKeypoints);\nint numPixels = encoderLength * encoderLength;\nint maxKeypoints = numPixels / pixelsPerKeypoint;\nint maxKeypointsPerPass = maxKeypoints / numPasses + int(maxKeypoints % numPasses != 0);\nint targetPassId = q / maxKeypointsPerPass;\nif(passId != targetPassId)\nreturn;\nint lastIndexFromPrevPass = passId * maxKeypointsPerPass - 1;\nKeypointAddress lastAddressFromPrevPass = KeypointAddress(max(0, lastIndexFromPrevPass) * pixelsPerKeypoint, 0);\nKeypoint lastKeypointFromPrevPass = decodeKeypoint(encodedKeypoints, encoderLength, lastAddressFromPrevPass);\nivec2 position = passId > 0 ? ivec2(lastKeypointFromPrevPass.position) : ivec2(0);\nvec4 pixel;\ncolor = encodeNullKeypoint();\nif(q >= min(maxKeypoints, keypointLimit) || !findQthKeypoint(q, lastIndexFromPrevPass, position, pixel))\nreturn;\ncolor = encodeKeypointPosition(vec2(position));\n}'},1733:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D corners;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nvoid main()\n{\nivec2 thread = threadLocation();\nvec4 pixel = threadPixel(encodedKeypoints);\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint q = findKeypointIndex(address, descriptorSize, extraSize);\ncolor = pixel;\nif(address.offset != 1)\nreturn;\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\nvec4 kpix = pixelAt(corners, ivec2(keypoint.position));\nkeypoint.score = decodeFloat16(kpix.rb);\ncolor.r = kpix.a;\ncolor.g = encodeKeypointOrientation(0.0f);\ncolor.ba = encodeKeypointScore(keypoint.score);\n}'},9674:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D corners;\nuniform mediump usampler2D lookupTable;\nuniform int stride;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform int encoderCapacity;\nconst uvec2 NULL_ELEMENT = uvec2(0xFFFFu);\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint index = findKeypointIndex(address, descriptorSize, extraSize);\nivec2 pos = ivec2(index % stride, index / stride);\nuvec4 entry = texelFetch(lookupTable, pos, 0);\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nint rasterIndex = address.base + address.offset;\nint numberOfPixels = encoderLength * encoderLength;\nint numberOfValidPixels = numberOfPixels - (numberOfPixels % pixelsPerKeypoint);\nint maxEncoderCapacity = numberOfValidPixels / pixelsPerKeypoint;\ncolor = encodeNullKeypoint();\nif(all(equal(entry.xy, NULL_ELEMENT)) || index >= min(encoderCapacity, maxEncoderCapacity))\nreturn;\ncolor = encodeKeypointPosition(vec2(entry.xy));\nif(address.offset == 0)\nreturn;\ncolor = vec4(0.0f);\nif(address.offset >= sizeofEncodedKeypointHeader() / 4)\nreturn;\nvec4 pixel = texelFetch(corners, ivec2(entry.xy), 0);\nvec2 encodedScore = encodeKeypointScore(decodeFloat16(pixel.rb));\nfloat encodedOrientation = encodeKeypointOrientation(0.0f);\nfloat encodedLod = pixel.a;\ncolor = vec4(encodedLod, encodedOrientation, encodedScore);\n}'},2090:e=>{e.exports='@include "keypoints.glsl"\nvoid main()\n{\ncolor = encodeNullKeypoint();\n}'},1855:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\nuniform sampler2D corners;\nuniform sampler2D pyramid;\nuniform float lod;\nuniform int threshold;\n#define USE_VARYINGS 1\n#if !defined(FAST_TYPE)\n#error Undefined FAST_TYPE\n#elif FAST_TYPE == 916\nin vec2 v_pix0, v_pix1, v_pix2, v_pix3, v_pix4, v_pix5, v_pix6, v_pix7,\nv_pix8, v_pix9, v_pix10,v_pix11,v_pix12,v_pix13,v_pix14,v_pix15;\n#else\n#error Invalid FAST_TYPE\n#endif\n#define PIX(x,y) pyrPixelAtOffset(pyramid, lod, pot, ivec2((x),(y))).g\n#define XIP(v) textureLod(pyramid, (v), lod).g\nvoid main()\n{\nfloat pixel = threadPixel(pyramid).g;\nvec4 prev = threadPixel(corners);\nivec2 thread = threadLocation();\nivec2 size = outputSize();\nfloat pot = exp2(lod);\nfloat t = float(clamp(threshold, 0, 255)) / 255.0f;\nfloat ct = pixel + t, c_t = pixel - t;\ncolor = vec4(prev.r, pixel, prev.ba);\n#if FAST_TYPE == 916\nconst ivec4 margin = ivec4(3, 3, 4, 4);\nif(any(lessThan(ivec4(thread, size - thread), margin)))\nreturn;\n#if USE_VARYINGS\nfloat p0 = XIP(v_pix0), p4 = XIP(v_pix4), p8 = XIP(v_pix8), p12 = XIP(v_pix12);\n#else\nfloat p0 = PIX(0,3), p4 = PIX(3,0), p8 = PIX(0,-3), p12 = PIX(-3,0);\n#endif\nbvec4 brighter = bvec4(p0 > ct, p4 > ct, p8 > ct, p12 > ct);\nbvec4 darker = bvec4(p0 < c_t, p4 < c_t, p8 < c_t, p12 < c_t);\nbvec4 bpairs = bvec4(all(brighter.xy), all(brighter.yz), all(brighter.zw), all(brighter.wx));\nbvec4 dpairs = bvec4(all(darker.xy), all(darker.yz), all(darker.zw), all(darker.wx));\nif(!(any(bpairs) || any(dpairs)))\nreturn;\n#if USE_VARYINGS\nfloat p1 = XIP(v_pix1), p2 = XIP(v_pix2), p3 = XIP(v_pix3),\np5 = XIP(v_pix5), p6 = XIP(v_pix6), p7 = XIP(v_pix7),\np9 = XIP(v_pix9), p10 = XIP(v_pix10), p11 = XIP(v_pix11),\np13 = XIP(v_pix13), p14 = XIP(v_pix14), p15 = XIP(v_pix15);\n#else\nfloat p1 = PIX(1,3), p2 = PIX(2,2), p3 = PIX(3,1),\np5 = PIX(3,-1), p6 = PIX(2,-2), p7 = PIX(1,-3),\np9 = PIX(-1,-3), p10 = PIX(-2,-2), p11 = PIX(-3,-1),\np13 = PIX(-3,1), p14 = PIX(-2,2), p15 = PIX(-1,3);\n#endif\nbool A=(p0>ct),B=(p1>ct),C=(p2>ct),D=(p3>ct),E=(p4>ct),F=(p5>ct),G=(p6>ct),H=(p7>ct),I=(p8>ct),J=(p9>ct),K=(p10>ct),L=(p11>ct),M=(p12>ct),N=(p13>ct),O=(p14>ct),P=(p15>ct),a=(p0<c_t),b=(p1<c_t),c=(p2<c_t),d=(p3<c_t),e=(p4<c_t),f=(p5<c_t),g=(p6<c_t),h=(p7<c_t),i=(p8<c_t),j=(p9<c_t),k=(p10<c_t),l=(p11<c_t),m=(p12<c_t),n=(p13<c_t),o=(p14<c_t),p=(p15<c_t);\nbool isCorner=A&&(B&&(K&&L&&J&&(M&&N&&O&&P||G&&H&&I&&(M&&N&&O||F&&(M&&N||E&&(M||D))))||C&&(K&&L&&M&&(N&&O&&P||G&&H&&I&&J&&(N&&O||F&&(N||E)))||D&&(N&&(L&&M&&(K&&G&&H&&I&&J&&(O||F)||O&&P)||k&&l&&m&&e&&f&&g&&h&&i&&j)||E&&(O&&(M&&N&&(K&&L&&G&&H&&I&&J||P)||k&&l&&m&&n&&f&&g&&h&&i&&j)||F&&(P&&(N&&O||k&&l&&m&&n&&o&&g&&h&&i&&j)||G&&(O&&P||H&&(P||I)||k&&l&&m&&n&&o&&p&&h&&i&&j)||k&&l&&m&&n&&o&&h&&i&&j&&(p||g))||k&&l&&m&&n&&h&&i&&j&&(o&&(p||g)||f&&(o&&p||g)))||k&&l&&m&&h&&i&&j&&(n&&(o&&p||g&&(o||f))||e&&(n&&o&&p||g&&(n&&o||f))))||k&&l&&h&&i&&j&&(m&&(n&&o&&p||g&&(n&&o||f&&(n||e)))||d&&(m&&n&&o&&p||g&&(m&&n&&o||f&&(m&&n||e)))))||k&&h&&i&&j&&(l&&(m&&n&&o&&p||g&&(m&&n&&o||f&&(m&&n||e&&(m||d))))||c&&(l&&m&&n&&o&&p||g&&(l&&m&&n&&o||f&&(l&&m&&n||e&&(l&&m||d))))))||K&&I&&J&&(L&&M&&N&&O&&P||G&&H&&(L&&M&&N&&O||F&&(L&&M&&N||E&&(L&&M||D&&(L||C)))))||h&&i&&j&&(b&&(k&&l&&m&&n&&o&&p||g&&(k&&l&&m&&n&&o||f&&(k&&l&&m&&n||e&&(k&&l&&m||d&&(k&&l||c)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e&&(m&&n&&o&&(k&&l&&g&&h&&i&&j||p)||f&&(n&&o&&p||g&&(o&&p||h&&(p||i)))))))||k&&i&&j&&(l&&m&&n&&o&&p||g&&h&&(l&&m&&n&&o||f&&(l&&m&&n||e&&(l&&m||d&&(l||c))))))||h&&i&&j&&(k&&l&&m&&n&&o&&p||g&&(k&&l&&m&&n&&o||f&&(k&&l&&m&&n||e&&(k&&l&&m||d&&(k&&l||c&&(b||k))))));\nif(!isCorner)\nreturn;\nmat4 mp = mat4(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15);\nmat4 mct = mp - mat4(ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct);\nmat4 mc_t = mat4(c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t) - mp;\nconst vec4 zeros = vec4(0.0f), ones = vec4(1.0f);\nvec4 bs = max(mct[0], zeros), ds = max(mc_t[0], zeros);\nbs += max(mct[1], zeros); ds += max(mc_t[1], zeros);\nbs += max(mct[2], zeros); ds += max(mc_t[2], zeros);\nbs += max(mct[3], zeros); ds += max(mc_t[3], zeros);\nfloat thisScore = max(dot(bs, ones), dot(ds, ones)) / 16.0f;\nfloat prevScore = decodeFloat16(prev.rb);\nvec3 thisResult = vec3(encodeFloat16(thisScore), encodeLod(lod));\ncolor.rba = thisScore > prevScore ? thisResult : color.rba;\n#endif\n}'},4824:e=>{e.exports="uniform mediump float lod;\n#if !defined(FAST_TYPE)\n#error Undefined FAST_TYPE\n#elif FAST_TYPE == 916\nout vec2 v_pix0, v_pix1, v_pix2, v_pix3, v_pix4, v_pix5, v_pix6, v_pix7,\nv_pix8, v_pix9, v_pix10,v_pix11,v_pix12,v_pix13,v_pix14,v_pix15;\n#else\n#error Invalid FAST_TYPE\n#endif\n#define PIX(x,y) (texCoord + ((pot) * vec2((x),(y))) / texSize)\nvoid vsmain()\n{\nfloat pot = exp2(lod);\n#if FAST_TYPE == 916\nv_pix0 = PIX(0,3); v_pix1 = PIX(1,3), v_pix2 = PIX(2,2), v_pix3 = PIX(3,1);\nv_pix4 = PIX(3,0); v_pix5 = PIX(3,-1), v_pix6 = PIX(2,-2), v_pix7 = PIX(1,-3);\nv_pix8 = PIX(0,-3); v_pix9 = PIX(-1,-3), v_pix10 = PIX(-2,-2), v_pix11 = PIX(-3,-1);\nv_pix12 = PIX(-3,0); v_pix13 = PIX(-3,1), v_pix14 = PIX(-2,2), v_pix15 = PIX(-1,3);\n#endif\n}"},2381:e=>{e.exports='@include "keypoints.glsl"\n@include "keypoint-descriptors.glsl"\nuniform sampler2D encodedKeypointsA;\nuniform int encoderLengthA;\nuniform sampler2D encodedKeypointsB;\nuniform int encoderLengthB;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform int threshold;\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint index = findKeypointIndex(address, descriptorSize, extraSize);\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nvec4 data = readKeypointData(encodedKeypointsA, encoderLengthA, address);\ncolor = data;\nif(address.offset >= sizeofEncodedKeypointHeader() / 4)\nreturn;\nKeypoint keypointA = decodeKeypoint(encodedKeypointsA, encoderLengthA, address);\nKeypoint keypointB = decodeKeypoint(encodedKeypointsB, encoderLengthB, address);\ncolor = encodeNullKeypoint();\nif(isNullKeypoint(keypointA) && isNullKeypoint(keypointB))\nreturn;\ncolor = encodeDiscardedKeypoint();\nif(isDiscardedKeypoint(keypointA) || isDiscardedKeypoint(keypointB))\nreturn;\ncolor = encodeDiscardedKeypoint();\nif(isNullKeypoint(keypointA) || isNullKeypoint(keypointB))\nreturn;\nuint[DESCRIPTOR_SIZE] descriptorA, descriptorB;\ndescriptorA = readKeypointDescriptor(encodedKeypointsA, descriptorSize, extraSize, encoderLengthA, address);\ndescriptorB = readKeypointDescriptor(encodedKeypointsB, descriptorSize, extraSize, encoderLengthB, address);\nint dist = distanceBetweenKeypointDescriptors(descriptorA, descriptorB);\nbool shouldKeep = (dist <= threshold);\ncolor = shouldKeep ? data : encodeDiscardedKeypoint();\n}'},6060:e=>{e.exports='@include "float16.glsl"\nuniform sampler2D corners;\nuniform sampler2D maxScore;\nuniform float quality;\nvoid main()\n{\nvec4 pixel = threadPixel(corners);\nfloat score = decodeFloat16(pixel.rb);\nfloat maxval = decodeFloat16(threadPixel(maxScore).rb);\nfloat threshold = maxval * clamp(quality, 0.0f, 1.0f);\ncolor = pixel;\ncolor.rb = score >= threshold ? color.rb : encodeFloat16(0.0f);\n}'},9974:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\n@include "filters.glsl"\n#if !defined(WINDOW_SIZE)\n#error Undefined WINDOW_SIZE\n#endif\n#define WINDOW_RADIUS ((WINDOW_SIZE - 1) / 2)\nuniform sampler2D corners;\nuniform sampler2D pyramid;\nuniform sampler2D derivatives;\nuniform float lod;\nuniform float lodStep;\nuniform float gaussian[@WINDOW_SIZE@];\n#define G(x) gaussian[(x) + WINDOW_RADIUS]\n#define W(x,y) (G(x) * G(y))\n#define H(ox,oy) dpix = pixelAtShortOffset(derivatives, ivec2((ox),(oy))); \\\ndf = (1.0f + lod) * decodePairOfFloat16(dpix); \\\nh += vec3(df.x * df.x, df.x * df.y, df.y * df.y) * W((ox),(oy))\nvoid main()\n{\nfloat intensity = 0.0f;\nivec2 thread = threadLocation();\nvec4 pixel = threadPixel(corners);\nvec4 dpix = vec4(0.0f);\nvec2 df = vec2(0.0f);\nvec3 h = vec3(0.0f);\ncolor = pixel;\n#if WINDOW_SIZE == 1\nH(0,0);\n#elif WINDOW_SIZE == 3\nH(-1,-1); H(0,-1); H(1,-1);\nH(-1,0); H(0,0); H(1,0);\nH(-1,1); H(0,1); H(1,1);\n#elif WINDOW_SIZE == 5\nH(-2,-2); H(-1,-2); H(0,-2); H(1,-2); H(2,-2);\nH(-2,-1); H(-1,-1); H(0,-1); H(1,-1); H(2,-1);\nH(-2,0); H(-1,0); H(0,0); H(1,0); H(2,0);\nH(-2,1); H(-1,1); H(0,1); H(1,1); H(2,1);\nH(-2,2); H(-1,2); H(0,2); H(1,2); H(2,2);\n#elif WINDOW_SIZE == 7\nH(-3,-3); H(-2,-3); H(-1,-3); H(0,-3); H(1,-3); H(2,-3); H(3,-3);\nH(-3,-2); H(-2,-2); H(-1,-2); H(0,-2); H(1,-2); H(2,-2); H(3,-2);\nH(-3,-1); H(-2,-1); H(-1,-1); H(0,-1); H(1,-1); H(2,-1); H(3,-1);\nH(-3,0); H(-2,0); H(-1,0); H(0,0); H(1,0); H(2,0); H(3,0);\nH(-3,1); H(-2,1); H(-1,1); H(0,1); H(1,1); H(2,1); H(3,1);\nH(-3,2); H(-2,2); H(-1,2); H(0,2); H(1,2); H(2,2); H(3,2);\nH(-3,3); H(-2,3); H(-1,3); H(0,3); H(1,3); H(2,3); H(3,3);\n#else\n#error Invalid WINDOW_SIZE\n#endif\nfloat response = 0.5f * (h.x + h.z - sqrt((h.x - h.z) * (h.x - h.z) + 4.0f * h.y * h.y));\nresponse /= float(WINDOW_SIZE * WINDOW_SIZE);\nfloat lodPlus = min(float(PYRAMID_MAX_LEVELS - 1), lod + lodStep);\nfloat currentScaleStrength = abs(laplacian(pyramid, vec2(thread), lod));\nfloat previousScaleStrength = abs(laplacian(pyramid, vec2(thread), lodPlus));\nfloat previousResponse = decodeFloat16(pixel.rb);\nvec4 result = vec4(encodeFloat16(response), encodeLod(lod), intensity);\ncolor.rbag = (currentScaleStrength >= previousScaleStrength || previousResponse == 0.0f) ? result : pixel.rbag;\n}'},3047:e=>{e.exports='@include "keypoint-matches.glsl"\nvoid main()\n{\n#if ENCODE_FILTERS != 0\nKeypointMatch initial = KeypointMatch(MATCH_MAX_INDEX, 0);\n#else\nKeypointMatch initial = KeypointMatch(MATCH_MAX_INDEX, MATCH_MAX_DISTANCE);\n#endif\ncolor = encodeKeypointMatch(initial);\n}'},3266:e=>{e.exports='@include "keypoint-matches.glsl"\nuniform sampler2D encodedMatches;\nuniform sampler2D encodedKthMatches;\nuniform int numberOfMatchesPerKeypoint;\nuniform int kthMatch;\nvoid main()\n{\nivec2 thread = threadLocation();\nivec2 matcherSize = textureSize(encodedMatches, 0);\nivec2 kthMatcherSize = textureSize(encodedKthMatches, 0);\nint rasterIndex = thread.y * matcherSize.x + thread.x;\nint matchIndex = rasterIndex / numberOfMatchesPerKeypoint;\nint matchCell = rasterIndex % numberOfMatchesPerKeypoint;\ncolor = threadPixel(encodedMatches);\nif(matchCell != kthMatch)\nreturn;\ncolor = encodeKeypointMatch(MATCH_NOT_FOUND);\nif(matchIndex >= kthMatcherSize.x * kthMatcherSize.y)\nreturn;\nivec2 pos = ivec2(matchIndex % kthMatcherSize.x, matchIndex / kthMatcherSize.x);\ncolor = texelFetch(encodedKthMatches, pos, 0);\n}'},8018:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\n@include "filters.glsl"\nuniform sampler2D corners;\nuniform sampler2D pyramid;\nuniform float lodStep;\nuniform float lodOffset;\nvoid main()\n{\nivec2 thread = threadLocation();\nvec4 pixel = threadPixel(corners);\nfloat lod = decodeLod(pixel.a);\nfloat lodMinus = max(0.0f, lod - lodStep + lodOffset);\nfloat lodPlus = min(float(PYRAMID_MAX_LEVELS - 1), lod + lodStep + lodOffset);\nfloat lapMinus = laplacian(pyramid, vec2(thread), lodMinus);\nfloat lapPlus = abs(lodPlus - lodMinus) < 1e-5 ? lapMinus : laplacian(pyramid, vec2(thread), lodPlus);\ncolor = encodePairOfFloat16(vec2(lapMinus, lapPlus));\n}'},3168:e=>{e.exports='@include "keypoints.glsl"\n@include "float16.glsl"\nuniform sampler2D nextPyramid;\nuniform sampler2D prevPyramid;\nuniform sampler2D encodedFlow;\nuniform sampler2D prevKeypoints;\nuniform int level;\nuniform int depth;\nuniform int numberOfIterations;\nuniform float discardThreshold;\nuniform float epsilon;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#ifndef WINDOW_SIZE\n#error Undefined WINDOW_SIZE\n#endif\n#define NEXT_IMAGE 1\n#define PREV_IMAGE 0\nconst int WINDOW_RADIUS = (WINDOW_SIZE - 1) / 2;\nconst int WINDOW_SIZE_SQUARED = (WINDOW_SIZE) * (WINDOW_SIZE);\nconst int WINDOW_SIZE_PLUS = (WINDOW_SIZE) + 2;\nconst int WINDOW_SIZE_PLUS_SQUARED = WINDOW_SIZE_PLUS * WINDOW_SIZE_PLUS;\nconst int DBL_WINDOW_SIZE_PLUS_SQUARED = 2 * WINDOW_SIZE_PLUS_SQUARED;\nconst int WINDOW_RADIUS_PLUS = (WINDOW_SIZE_PLUS - 1) / 2;\nconst highp float FLT_SCALE = 9.5367431640625e-7;\nconst highp float FLT_EPSILON = 0.00000011920929f;\nint pixelBuffer[DBL_WINDOW_SIZE_PLUS_SQUARED];\n#define prevPixel(index) pixelBuffer[(index)]\n#define nextPixel(index) pixelBuffer[WINDOW_SIZE_PLUS_SQUARED + (index)]\n#define pixelIndex(i, j) (((j) + WINDOW_RADIUS_PLUS) * WINDOW_SIZE_PLUS + ((i) + WINDOW_RADIUS_PLUS))\nivec2 derivBuffer[WINDOW_SIZE_SQUARED];\n#define derivativesAt(x, y) derivBuffer[((y) + WINDOW_RADIUS) * WINDOW_SIZE + ((x) + WINDOW_RADIUS)]\nvoid readWindow(vec2 center, float lod)\n{\nconst int r = WINDOW_RADIUS;\nivec2 pyrBaseSize = textureSize(prevPyramid, 0);\nfloat pot = exp2(lod);\nivec2 offset; int idx;\n#define readPixelsAt(ox, oy) offset = ivec2((ox), (oy)); \\\nidx = pixelIndex(offset.x, offset.y); \\\nnextPixel(idx) = int(255.0f * pyrSubpixelAtExOffset(nextPyramid, center, lod, pot, offset, pyrBaseSize).g); \\\nprevPixel(idx) = int(255.0f * pyrSubpixelAtExOffset(prevPyramid, center, lod, pot, offset, pyrBaseSize).g)\nfor(int j = 0; j < WINDOW_SIZE; j++) {\nfor(int i = 0; i < WINDOW_SIZE; i++) {\nreadPixelsAt(i-r, j-r);\n}\n}\nint r1 = r+1;\nfor(int k = 0; k < WINDOW_SIZE; k++) {\nreadPixelsAt(-r1, k-r);\nreadPixelsAt( r1, k-r);\nreadPixelsAt(k-r,-r1);\nreadPixelsAt(k-r, r1);\n}\nreadPixelsAt(-r1,-r1);\nreadPixelsAt( r1,-r1);\nreadPixelsAt(-r1, r1);\nreadPixelsAt( r1, r1);\n}\nivec2 computeDerivatives(int imageCode, ivec2 offset)\n{\nconst mat3 dx = mat3(\n3, 0, -3,\n10, 0, -10,\n3, 0, -3\n);\nconst mat3 dy = mat3(\n3, 10, 3,\n0, 0, 0,\n-3, -10, -3\n);\nint indexOffset = imageCode * WINDOW_SIZE_PLUS_SQUARED;\nmat3 window = mat3(\npixelBuffer[indexOffset + pixelIndex(offset.x-1, offset.y-1)],\npixelBuffer[indexOffset + pixelIndex(offset.x+0, offset.y-1)],\npixelBuffer[indexOffset + pixelIndex(offset.x+1, offset.y-1)],\npixelBuffer[indexOffset + pixelIndex(offset.x-1, offset.y+0)],\n0.0f,\npixelBuffer[indexOffset + pixelIndex(offset.x+1, offset.y+0)],\npixelBuffer[indexOffset + pixelIndex(offset.x-1, offset.y+1)],\npixelBuffer[indexOffset + pixelIndex(offset.x+0, offset.y+1)],\npixelBuffer[indexOffset + pixelIndex(offset.x+1, offset.y+1)]\n);\nmat3 fx = matrixCompMult(dx, window);\nmat3 fy = matrixCompMult(dy, window);\nconst vec3 ones = vec3(1.0f);\nreturn ivec2(\ndot(fx[0], ones) + dot(fx[1], ones) + dot(fx[2], ones),\ndot(fy[0], ones) + dot(fy[1], ones) + dot(fy[2], ones)\n);\n}\nint readBufferedPixel(int imageCode, ivec2 offset)\n{\nconst int r = WINDOW_RADIUS;\noffset = clamp(offset, -r, r);\nint indexOffset = imageCode * WINDOW_SIZE_PLUS_SQUARED;\nreturn pixelBuffer[indexOffset + pixelIndex(offset.x, offset.y)];\n}\nint readBufferedSubpixel(int imageCode, vec2 offset)\n{\nivec2 p = ivec2(floor(offset));\nvec2 frc = fract(offset);\nvec2 ifrc = vec2(1.0f) - frc;\nvec4 pix = vec4(\nreadBufferedPixel(imageCode, p),\nreadBufferedPixel(imageCode, p + ivec2(1,0)),\nreadBufferedPixel(imageCode, p + ivec2(0,1)),\nreadBufferedPixel(imageCode, p + ivec2(1,1))\n);\nvec4 sub = vec4(\nifrc.x * ifrc.y,\nfrc.x * ifrc.y,\nifrc.x * frc.y,\nfrc.x * frc.y\n);\nreturn int(0.5f + dot(sub*pix, vec4(1.0f)));\n}\nvec2 computeMismatch(vec2 pyrGuess, vec2 localGuess)\n{\nconst int r = WINDOW_RADIUS;\nint timeDerivative;\nivec2 mismatch = ivec2(0);\nint x, y, _x, _y;\nvec2 d = pyrGuess + localGuess;\n#define innerLoop() \\\nfor(_x = 0; _x < WINDOW_SIZE; _x++) { \\\nx = _x - r; y = _y - r; \\\ntimeDerivative = ( \\\nreadBufferedSubpixel(NEXT_IMAGE, vec2(x, y) + d) - \\\nreadBufferedPixel(PREV_IMAGE, ivec2(x, y)) \\\n); \\\nmismatch += derivativesAt(x, y) * timeDerivative; \\\n}\n@unroll\nfor(_y = 0; _y < WINDOW_SIZE; _y++) {\ninnerLoop();\n}\nreturn vec2(mismatch) * FLT_SCALE;\n}\nbool isInsideImage(vec2 position)\n{\nvec2 imageSize = vec2(textureSize(nextPyramid, 0));\nvec2 border = vec2(WINDOW_SIZE);\nreturn all(bvec4(\ngreaterThanEqual(position, border),\nlessThan(position, imageSize - border)\n));\n}\nvoid main()\n{\nvec4 pixel = threadPixel(encodedFlow);\nivec2 thread = threadLocation();\nfloat windowArea = float(WINDOW_SIZE * WINDOW_SIZE);\nconst int r = WINDOW_RADIUS;\nint keypointIndex = thread.x + thread.y * outputSize().x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(prevKeypoints, encoderLength, address);\ncolor = encodeNullPairOfFloat16();\nif(isNullKeypoint(keypoint))\nreturn;\ncolor = encodeDiscardedPairOfFloat16();\nif(isBadKeypoint(keypoint))\nreturn;\nvec2 pyrGuess = (level < depth - 1) ? decodePairOfFloat16(pixel) : vec2(0.0f);\npyrGuess *= 2.0f;\nreadWindow(keypoint.position, float(level));\nivec2 derivatives;\nivec3 harris3i = ivec3(0);\nfor(int j = 0; j < WINDOW_SIZE; j++) {\nfor(int i = 0; i < WINDOW_SIZE; i++) {\nderivatives = computeDerivatives(PREV_IMAGE, ivec2(i-r, j-r));\nharris3i += ivec3(\nderivatives.x * derivatives.x,\nderivatives.x * derivatives.y,\nderivatives.y * derivatives.y\n);\nderivativesAt(i-r, j-r) = derivatives;\n}\n}\nhighp vec3 harris = vec3(harris3i) * FLT_SCALE;\nhighp mat2 invHarris = mat2(harris.z, -harris.y, -harris.y, harris.x);\nhighp float det = harris.x * harris.z - harris.y * harris.y;\nhighp float invDet = abs(det) >= FLT_EPSILON ? 1.0f / det : 0.0f;\nhighp float minEigenvalue = 0.5f * ((harris.x + harris.z) - sqrt(\n(harris.x - harris.z) * (harris.x - harris.z) + 4.0f * (harris.y * harris.y)\n));\nint niceNumbers = int(abs(det) >= FLT_EPSILON && minEigenvalue >= discardThreshold * windowArea);\nbool goodKeypoint = (level > 0) || (niceNumbers != 0);\nhighp float eps2 = epsilon * epsilon;\nhighp vec2 mismatch, delta, localGuess = vec2(0.0f);\nfor(int k = 0; k < numberOfIterations; k++) {\nmismatch = niceNumbers != 0 ? computeMismatch(pyrGuess, localGuess) : vec2(0.0f);\ndelta = mismatch * invHarris * invDet;\nniceNumbers *= int(eps2 <= dot(delta, delta));\nlocalGuess += float(niceNumbers) * delta;\n}\nvec2 opticalFlow = pyrGuess + localGuess;\nbool mustDiscard = (level == 0) && any(bvec2(\n!goodKeypoint,\n!isInsideImage(keypoint.position + opticalFlow)\n));\ncolor = !mustDiscard ? encodePairOfFloat16(opticalFlow) : encodeDiscardedPairOfFloat16();\n}'},3890:e=>{e.exports='#if @FS_USE_CUSTOM_PRECISION@\nprecision mediump int;\nprecision mediump float;\n#endif\n#if !defined(STAGE)\n#error Undefined STAGE\n#elif STAGE == 1\n@include "float16.glsl"\nuniform sampler2D corners;\n#elif STAGE < 1\nuniform mediump usampler2D lookupTable;\n#else\n#define SKIP_TEXTURE_READS 1\n#define DENSITY_FACTOR 0.10\nuniform mediump usampler2D lookupTable;\nuniform int blockSize;\nuniform int width;\nuniform int height;\nin vec2 v_topLeft, v_top, v_topRight,\nv_left, v_center, v_right,\nv_bottomLeft, v_bottom, v_bottomRight;\n#endif\nconst uvec2 NULL_ELEMENT = uvec2(0xFFFFu);\nvoid main()\n{\n#if STAGE == 1\nuvec2 outSize = uvec2(outputSize());\nuvec2 thread = uvec2(threadLocation());\nuvec2 size = uvec2(textureSize(corners, 0));\nuint location = thread.y * outSize.x + thread.x;\nivec2 pos = ivec2(location % size.x, location / size.x);\nvec4 pixel = location < size.x * size.y ? texelFetch(corners, pos, 0) : vec4(0.0f);\nbool isCorner = !isEncodedFloat16Zero(pixel.rb);\ncolor = isCorner ? uvec4(uvec2(pos), 1u, 0u) : uvec4(NULL_ELEMENT, 0u, 0u);\n#elif STAGE > 1\nint dblBlockSize = 2 * blockSize;\nivec2 thread = threadLocation();\nivec2 offset = thread % dblBlockSize;\nivec2 delta = thread - offset;\n#if SKIP_TEXTURE_READS\nif(blockSize >= 8) {\nuint sb = texture(lookupTable, texCoord).z;\nfloat p = max((float(sb) / float(blockSize)) / float(blockSize), DENSITY_FACTOR);\nfloat rowthr = float(dblBlockSize) * p + 3.0f * sqrt(p * (1.0f - p));\ncolor = uvec4(NULL_ELEMENT, 4u * sb, 0u);\nif(offset.y >= max(1, int(ceil(rowthr))))\nreturn;\n}\n#endif\n#define deltaCenter ivec2(0,0)\n#define deltaTop ivec2(0,-blockSize)\n#define deltaTopRight ivec2(blockSize,-blockSize)\n#define deltaRight ivec2(blockSize,0)\n#define deltaBottomRight ivec2(blockSize,blockSize)\n#define deltaBottom ivec2(0,blockSize)\n#define deltaBottomLeft ivec2(-blockSize,blockSize)\n#define deltaLeft ivec2(-blockSize,0)\n#define deltaTopLeft ivec2(-blockSize,-blockSize)\nivec2 boundary = ivec2(width - 1, height - 1) / blockSize;\nivec2 bottomRightPos = thread + deltaBottomRight;\nuvec2 valid = uvec2(\nbottomRightPos.x < width || bottomRightPos.x / blockSize == boundary.x,\nbottomRightPos.y < height || bottomRightPos.y / blockSize == boundary.y\n);\nuvec4 mask[4];\nmask[0] = uvec4(1u, valid.x, valid.y, valid.x * valid.y);\nmask[1] = uvec4(1u, 1u, valid.y, valid.y);\nmask[2] = uvec4(1u, valid.x, 1u, valid.x);\nmask[3] = uvec4(1u);\n#if SKIP_TEXTURE_READS\n#define calcSb(delta) texelFetch(lookupTable, blockSize * ((thread + (delta)) / blockSize), 0).z\nuint center = calcSb(deltaCenter);\nuint top = calcSb(deltaTop);\nuint topRight = calcSb(deltaTopRight);\nuint right = calcSb(deltaRight);\nuint bottomRight = calcSb(deltaBottomRight);\nuint bottom = calcSb(deltaBottom);\nuint bottomLeft = calcSb(deltaBottomLeft);\nuint left = calcSb(deltaLeft);\nuint topLeft = calcSb(deltaTopLeft);\n#else\n#define calcSb(pos) texture(lookupTable, (pos)).z\nuint center = calcSb(v_center);\nuint top = calcSb(v_top);\nuint topRight = calcSb(v_topRight);\nuint right = calcSb(v_right);\nuint bottomRight = calcSb(v_bottomRight);\nuint bottom = calcSb(v_bottom);\nuint bottomLeft = calcSb(v_bottomLeft);\nuint left = calcSb(v_left);\nuint topLeft = calcSb(v_topLeft);\n#endif\nuvec4 sums[4];\nsums[0] = uvec4(center, right, bottom, bottomRight);\nsums[1] = uvec4(left, center, bottomLeft, bottom);\nsums[2] = uvec4(top, topRight, center, right);\nsums[3] = uvec4(topLeft, top, left, center);\nivec2 cmp = ivec2(greaterThanEqual(offset, ivec2(blockSize)));\nint option = 2 * cmp.y + cmp.x;\nuvec4 cdef = sums[option] * mask[option];\nuint c2b = cdef.x, d2b = cdef.y, e2b = cdef.z, f2b = cdef.w;\nuint sb = center;\nuint s2b = c2b + d2b + e2b + f2b;\ns2b = s2b < sb ? 0xFFFFu : min(0xFFFFu, s2b);\nuint w2b = uint(min(dblBlockSize, width - delta.x));\nuvec2 uoffset = uvec2(offset);\nuint ceiling = s2b >= uoffset.x ? (s2b - uoffset.x) / w2b + uint((s2b - uoffset.x) % w2b > 0u) : 0u;\ncolor = uvec4(NULL_ELEMENT, s2b, 0u);\nif(uoffset.y >= ceiling)\nreturn;\nuint i2b = uoffset.y * w2b + uoffset.x;\nuint j2b = i2b >= c2b ? i2b - c2b : 0u;\nuint k2b = j2b >= d2b ? j2b - d2b : 0u;\nuint l2b = k2b >= e2b ? k2b - e2b : 0u;\nuint wl = uint(min(blockSize, width - delta.x));\nuint wr = uint(min(blockSize, width - delta.x - blockSize));\nivec2 magicOffset = (\n(i2b < c2b) ? ivec2(i2b % wl, i2b / wl) : (\n(j2b < d2b) ? ivec2(j2b % wr, j2b / wr) + ivec2(blockSize, 0) : (\n(k2b < e2b) ? ivec2(k2b % wl, k2b / wl) + ivec2(0, blockSize) : (\n(l2b < f2b) ? ivec2(l2b % wr, l2b / wr) + ivec2(blockSize) : ivec2(0)\n))));\nuvec2 a2b = texelFetch(lookupTable, delta + magicOffset, 0).xy;\ncolor = uvec4(a2b, s2b, 0u);\n#else\nuvec4 pix = texture(lookupTable, texCoord);\ncolor = all(equal(pix.xy, NULL_ELEMENT)) ? vec4(0,1,1,1) : vec4(1,0,0,1);\n#endif\n}'},8647:e=>{e.exports="#if !defined(STAGE) || STAGE < 1\n#error Invalid STAGE\n#else\nuniform mediump int blockSize;\nout vec2 v_topLeft, v_top, v_topRight,\nv_left, v_center, v_right,\nv_bottomLeft, v_bottom, v_bottomRight;\nvoid vsmain()\n{\nfloat b = float(blockSize);\n#define V(x,y) (texCoord + (vec2((x),(y)) * b) / texSize)\nv_topLeft = V(-1,-1); v_top = V(0,-1); v_topRight = V(1,-1);\nv_left = V(-1,0); v_center = V(0,0); v_right = V(1,0);\nv_bottomLeft = V(-1,1); v_bottom = V(0,1); v_bottomRight = V(1,1);\n}\n#endif"},4776:e=>{e.exports='@include "keypoints.glsl"\n@include "keypoint-matches.glsl"\n@include "keypoint-descriptors.glsl"\nuniform sampler2D candidates;\nuniform sampler2D filters;\nuniform int matcherLength;\nuniform sampler2D tables;\nuniform sampler2D descriptorDB;\nuniform int tableIndex;\nuniform int bucketCapacity;\nuniform int bucketsPerTable;\nuniform int tablesStride;\nuniform int descriptorDBStride;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#if HASH_SIZE > SEQUENCE_MAXLEN\n#error LSH: invalid HASH_SIZE\n#elif SEQUENCE_COUNT * SEQUENCE_MAXLEN * 4 > 16384\n#error LSH: sequences are too large!\n#elif (SEQUENCE_COUNT * SEQUENCE_MAXLEN) % 4 > 0\n#error LSH: sequences of invalid size!\n#endif\nlayout(std140) uniform LSHSequences\n{\nuvec4 sequences[(SEQUENCE_COUNT * SEQUENCE_MAXLEN) / 4];\n};\n#if HASH_SIZE == 10\nconst int SWAP_COUNT[3] = int[3](1, 11, 56);\nconst int[56] SWAP = int[56](0,1,2,4,8,16,32,64,128,256,512,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768);\n#elif HASH_SIZE == 11\nconst int SWAP_COUNT[3] = int[3](1, 12, 67);\nconst int[67] SWAP = int[67](0,1,2,4,8,16,32,64,128,256,512,1024,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536);\n#elif HASH_SIZE == 12\nconst int SWAP_COUNT[3] = int[3](1, 13, 79);\nconst int[79] SWAP = int[79](0,1,2,4,8,16,32,64,128,256,512,1024,2048,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072);\n#elif HASH_SIZE == 13\nconst int SWAP_COUNT[3] = int[3](1, 14, 92);\nconst int[92] SWAP = int[92](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144);\n#elif HASH_SIZE == 14\nconst int SWAP_COUNT[3] = int[3](1, 15, 106);\nconst int[106] SWAP = int[106](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288);\n#elif HASH_SIZE == 15\nconst int SWAP_COUNT[3] = int[3](1, 16, 121);\nconst int[121] SWAP = int[121](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288,16385,16386,16388,16392,16400,16416,16448,16512,16640,16896,17408,18432,20480,24576);\n#elif HASH_SIZE == 16\nconst int SWAP_COUNT[3] = int[3](1, 17, 137);\nconst int[137] SWAP = int[137](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288,16385,16386,16388,16392,16400,16416,16448,16512,16640,16896,17408,18432,20480,24576,32769,32770,32772,32776,32784,32800,32832,32896,33024,33280,33792,34816,36864,40960,49152);\n#elif HASH_SIZE == 17\nconst int SWAP_COUNT[3] = int[3](1, 18, 154);\nconst int[154] SWAP = int[154](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288,16385,16386,16388,16392,16400,16416,16448,16512,16640,16896,17408,18432,20480,24576,32769,32770,32772,32776,32784,32800,32832,32896,33024,33280,33792,34816,36864,40960,49152,65537,65538,65540,65544,65552,65568,65600,65664,65792,66048,66560,67584,69632,73728,81920,98304);\n#elif HASH_SIZE == 18\nconst int SWAP_COUNT[3] = int[3](1, 19, 172);\nconst int[172] SWAP = int[172](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288,16385,16386,16388,16392,16400,16416,16448,16512,16640,16896,17408,18432,20480,24576,32769,32770,32772,32776,32784,32800,32832,32896,33024,33280,33792,34816,36864,40960,49152,65537,65538,65540,65544,65552,65568,65600,65664,65792,66048,66560,67584,69632,73728,81920,98304,131073,131074,131076,131080,131088,131104,131136,131200,131328,131584,132096,133120,135168,139264,147456,163840,196608);\n#elif HASH_SIZE == 19\nconst int SWAP_COUNT[3] = int[3](1, 20, 191);\nconst int[191] SWAP = int[191](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288,16385,16386,16388,16392,16400,16416,16448,16512,16640,16896,17408,18432,20480,24576,32769,32770,32772,32776,32784,32800,32832,32896,33024,33280,33792,34816,36864,40960,49152,65537,65538,65540,65544,65552,65568,65600,65664,65792,66048,66560,67584,69632,73728,81920,98304,131073,131074,131076,131080,131088,131104,131136,131200,131328,131584,132096,133120,135168,139264,147456,163840,196608,262145,262146,262148,262152,262160,262176,262208,262272,262400,262656,263168,264192,266240,270336,278528,294912,327680,393216);\n#elif HASH_SIZE == 20\nconst int SWAP_COUNT[3] = int[3](1, 21, 211);\nconst int[211] SWAP = int[211](0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072,4097,4098,4100,4104,4112,4128,4160,4224,4352,4608,5120,6144,8193,8194,8196,8200,8208,8224,8256,8320,8448,8704,9216,10240,12288,16385,16386,16388,16392,16400,16416,16448,16512,16640,16896,17408,18432,20480,24576,32769,32770,32772,32776,32784,32800,32832,32896,33024,33280,33792,34816,36864,40960,49152,65537,65538,65540,65544,65552,65568,65600,65664,65792,66048,66560,67584,69632,73728,81920,98304,131073,131074,131076,131080,131088,131104,131136,131200,131328,131584,132096,133120,135168,139264,147456,163840,196608,262145,262146,262148,262152,262160,262176,262208,262272,262400,262656,263168,264192,266240,270336,278528,294912,327680,393216,524289,524290,524292,524296,524304,524320,524352,524416,524544,524800,525312,526336,528384,532480,540672,557056,589824,655360,786432);\n#else\n#error Invalid HASH_SIZE\n#endif\n#if LEVEL < 0 || LEVEL > 2\n#error Invalid LEVEL\n#endif\nconst uint END_OF_LIST = 0xFFFFFFFFu;\nconst int NUMBER_OF_HASHES = SWAP_COUNT[LEVEL];\nuint sequenceElement(int sequenceIndex, int elementIndex)\n{\nint offset = (SEQUENCE_MAXLEN) * sequenceIndex + elementIndex;\nuvec4 tuple = sequences[offset / 4];\nreturn tuple[offset & 3];\n}\nint descriptorHash(uint[DESCRIPTOR_SIZE] descriptor, int sequenceIndex)\n{\nuint bit, b, m;\nint hash = 0;\n@unroll\nfor(int i = 0; i < HASH_SIZE; i++) {\nbit = sequenceElement(sequenceIndex, i);\nb = bit >> 3u;\nm = 1u << (bit & 7u);\nhash = (hash << 1) | int((descriptor[b] & m) != 0u);\n}\nreturn hash;\n}\n#define readTableData(tables, tablesStride, rasterIndex) decodeUint32(texelFetch((tables), ivec2((rasterIndex) % (tablesStride), (rasterIndex) / (tablesStride)), 0))\nvoid main()\n{\nivec2 thread = threadLocation();\nint keypointIndex = thread.x + thread.y * matcherLength;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\ncolor = encodeKeypointMatch(MATCH_NOT_FOUND);\nif(isBadKeypoint(keypoint))\nreturn;\nKeypointMatch candidate = decodeKeypointMatch(threadPixel(candidates));\nKeypointMatch mfilter = decodeKeypointMatch(threadPixel(filters));\nuint[DESCRIPTOR_SIZE] candidateDescriptor;\nuint[DESCRIPTOR_SIZE] descriptor = readKeypointDescriptor(encodedKeypoints, descriptorSize, extraSize, encoderLength, address);\nint hash0 = descriptorHash(descriptor, tableIndex);\nfor(int h = 0; h < NUMBER_OF_HASHES; h++) {\nint hash = hash0 ^ SWAP[h];\nint tableAddress = tableIndex * bucketsPerTable * bucketCapacity;\nint bucketAddress = tableAddress + hash * bucketCapacity;\nbool validEntry = true;\nfor(int b = 0; b < bucketCapacity; b++) {\nint entryAddress = bucketAddress + b;\nuint entry = validEntry ? readTableData(tables, tablesStride, entryAddress) : END_OF_LIST;\nvalidEntry = (validEntry && entry != END_OF_LIST);\nint candidateIndex = int(entry);\ncandidateDescriptor = readKeypointDescriptorFromDB(descriptorDB, descriptorDBStride, validEntry ? candidateIndex : -1);\nint descriptorDistance = distanceBetweenKeypointDescriptors(descriptor, candidateDescriptor);\nKeypointMatch match = KeypointMatch(candidateIndex, descriptorDistance);\nbool betterThanCandidate = (match.dist < candidate.dist) || (match.dist == candidate.dist && match.index > candidate.index);\nbool worseThanFilter = (match.dist > mfilter.dist) || (match.dist == mfilter.dist && match.index < mfilter.index);\nbool nicerMatch = (validEntry && betterThanCandidate && worseThanFilter);\nivec2 v = nicerMatch ? ivec2(match.index, match.dist) : ivec2(candidate.index, candidate.dist);\ncandidate = KeypointMatch(v.x, v.y);\n}\n}\ncolor = encodeKeypointMatch(candidate);\n}'},2648:e=>{e.exports='@include "keypoints.glsl"\n@include "int32.glsl"\n#if !defined(STAGE)\n#error Undefined STAGE\n#elif STAGE == 1\nuniform sampler2D encodedKeypointsA;\nuniform sampler2D encodedKeypointsB;\nuniform int encoderLengthA;\nuniform int encoderLengthB;\nuniform int encoderCapacityA;\nuniform int encoderCapacityB;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#elif STAGE == 2\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform int maxKeypoints;\n#elif STAGE == 3\nuniform sampler2D array;\nuniform int blockSize;\n#elif STAGE == 4\nuniform sampler2D array;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#elif STAGE == 5\nuniform sampler2D array;\n#else\n#error Invalid STAGE\n#endif\n#define NULL_KEYPOINT_INDEX 0xFFFF\nconst highp uint UNIT = 0x10000u;\nvoid main()\n{\n#if STAGE == 1\nivec2 thread = threadLocation();\nKeypointAddress addr = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint keypointIndex = findKeypointIndex(addr, descriptorSize, extraSize);\nint newKeypointIndex = keypointIndex < encoderCapacityA ? keypointIndex : keypointIndex - encoderCapacityA;\ncolor = encodeNullKeypoint();\nif(newKeypointIndex >= max(encoderCapacityA, encoderCapacityB))\nreturn;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\naddr = KeypointAddress(newKeypointIndex * pixelsPerKeypoint, addr.offset);\nvec4 dataA = readKeypointData(encodedKeypointsA, encoderLengthA, addr);\nvec4 dataB = readKeypointData(encodedKeypointsB, encoderLengthB, addr);\ncolor = keypointIndex < encoderCapacityA ? dataA : dataB;\n#elif STAGE == 2\nivec2 thread = threadLocation();\nint keypointIndex = thread.y * outputSize().x + thread.x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress addr = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, addr);\nbool isValid = !isNullKeypoint(keypoint) && keypointIndex < maxKeypoints;\nkeypointIndex = isValid ? keypointIndex : NULL_KEYPOINT_INDEX;\ncolor = encodeUint32(uint(keypointIndex & 0xFFFF) | (isValid ? UNIT : 0u));\n#elif STAGE == 3\nivec2 thread = threadLocation();\nivec2 size = outputSize();\nint arrayLength = size.x * size.y;\nint arrayIndex = thread.y * size.x + thread.x;\nint arrayIndexLeft = arrayIndex - blockSize;\nint arrayIndexRight = arrayIndex + blockSize;\nint mask = int(arrayIndexRight < arrayLength || arrayIndexRight / blockSize == (arrayLength - 1) / blockSize);\narrayIndexLeft = max(0, arrayIndexLeft);\narrayIndexRight = min(arrayLength - 1, arrayIndexRight);\n#define raster2pos(k) ivec2((k) % size.x, (k) / size.x)\nuvec3 entries32 = uvec3(\ndecodeUint32(threadPixel(array)),\ndecodeUint32(texelFetch(array, raster2pos(arrayIndexLeft), 0)),\ndecodeUint32(texelFetch(array, raster2pos(arrayIndexRight), 0))\n);\nivec3 sb = ivec3((entries32 >> 16u) & 0xFFFFu);\nsb.z *= mask;\nint dblBlockSize = 2 * blockSize;\nint offset = arrayIndex % dblBlockSize;\nint s2b = sb.x + (offset < blockSize ? sb.z : sb.y);\nint l2b = offset < blockSize ? sb.x : sb.y;\nuint keypointIndex = entries32.x & 0xFFFFu;\nuint shiftedS2b = uint(s2b) << 16u;\ncolor = encodeUint32(uint(NULL_KEYPOINT_INDEX) | shiftedS2b);\nif(offset >= s2b)\nreturn;\ncolor = encodeUint32(keypointIndex | shiftedS2b);\nif(offset < l2b)\nreturn;\nvec4 entry = texelFetch(array, raster2pos(arrayIndex + blockSize - l2b), 0);\nkeypointIndex = decodeUint32(entry) & 0xFFFFu;\ncolor = encodeUint32(keypointIndex | shiftedS2b);\n#elif STAGE == 4\nivec2 thread = threadLocation();\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress addr = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint keypointIndex = findKeypointIndex(addr, descriptorSize, extraSize);\n#define raster2pos(k) ivec2((k) % size.x, (k) / size.x)\nivec2 size = textureSize(array, 0);\nuint sortedPair = decodeUint32(texelFetch(array, raster2pos(keypointIndex), 0));\nint newKeypointIndex = int(sortedPair & 0xFFFFu);\ncolor = encodeNullKeypoint();\nif(newKeypointIndex == NULL_KEYPOINT_INDEX || keypointIndex >= size.x * size.y)\nreturn;\nKeypointAddress newAddr = KeypointAddress(newKeypointIndex * pixelsPerKeypoint, addr.offset);\ncolor = readKeypointData(encodedKeypoints, encoderLength, newAddr);\n#elif STAGE == 5\nuint val = decodeUint32(threadPixel(array));\ncolor = (val & 0xFFFFu) == uint(NULL_KEYPOINT_INDEX) ? vec4(0,1,1,1) : vec4(1,0,0,1);\n#endif\n}'},8825:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\n@include "filters.glsl"\n#if !defined(USE_LAPLACIAN)\n#error Undefined USE_LAPLACIAN\n#endif\nuniform sampler2D corners;\nuniform sampler2D pyramid;\nuniform float lodStep;\n#if USE_LAPLACIAN\nuniform sampler2D pyrLaplacian;\n#endif\nvoid main()\n{\nivec2 thread = threadLocation();\nvec4 pixel = threadPixel(corners);\nfloat score = decodeFloat16(pixel.rb);\nfloat myEncodedLod = pixel.a;\nfloat lod = decodeLod(myEncodedLod);\nfloat lodPlus = lod + lodStep;\nfloat lodMinus = lod - lodStep;\nfloat pot = exp2(lod);\nfloat potPlus = exp2(lodPlus);\nfloat potMinus = exp2(lodMinus);\ncolor = pixel;\nif(score == 0.0f)\nreturn;\n#define P(p,u,v) textureLod(corners, texCoord + (p) * vec2((u),(v)) / texSize, 0.0f)\nvec4 pix[18];\n#define D(u,v) P(potMinus,(u),(v))\npix[0] = D(-1,-1); pix[1] = D(0,-1); pix[2] = D(1,-1);\npix[3] = D(-1,0); pix[4] = D(0,0); pix[5] = D(1,0);\npix[6] = D(-1,1); pix[7] = D(0,1); pix[8] = D(1,1);\n#define U(u,v) P(potPlus,(u),(v))\npix[9] = U(-1,-1); pix[10] = U(0,-1); pix[11] = U(1,-1);\npix[12] = U(-1,0); pix[13] = U(0,0); pix[14] = U(1,0);\npix[15] = U(-1,1); pix[16] = U(0,1); pix[17] = U(1,1);\nfloat scores[18];\n#define C(j) decodeFloat16(pix[j].rb)\nscores[0] = C(0); scores[1] = C(1); scores[2] = C(2);\nscores[3] = C(3); scores[4] = C(4); scores[5] = C(5);\nscores[6] = C(6); scores[7] = C(7); scores[8] = C(8);\nscores[9] = C(9); scores[10] = C(10); scores[11] = C(11);\nscores[12] = C(12); scores[13] = C(13); scores[14] = C(14);\nscores[15] = C(15); scores[16] = C(16); scores[17] = C(17);\nfloat lods[18];\n#define E(j) decodeLod(pix[j].a)\nlods[0] = E(0); lods[1] = E(1); lods[2] = E(2);\nlods[3] = E(3); lods[4] = E(4); lods[5] = E(5);\nlods[6] = E(6); lods[7] = E(7); lods[8] = E(8);\nlods[9] = E(9); lods[10] = E(10); lods[11] = E(11);\nlods[12] = E(12); lods[13] = E(13); lods[14] = E(14);\nlods[15] = E(15); lods[16] = E(16); lods[17] = E(17);\n#if USE_LAPLACIAN\n#define L(p,u,v) textureLod(pyrLaplacian, texCoord + (p) * vec2((u),(v)) / texSize, 0.0f)\nmat3 strengths[2];\nstrengths[0] = mat3(\n#define Lm(u,v) abs(decodeFloat16(L(potMinus,(u),(v)).xy))\nLm(-1,-1), Lm(0,-1), Lm(1,-1),\nLm(-1,0), Lm(0,0), Lm(1,0),\nLm(-1,1), Lm(0,1), Lm(1,1)\n);\nstrengths[1] = mat3(\n#define Lp(u,v) abs(decodeFloat16(L(potPlus,(u),(v)).zw))\nLp(-1,-1), Lp(0,-1), Lp(1,-1),\nLp(-1,0), Lp(0,0), Lp(1,0),\nLp(-1,1), Lp(0,1), Lp(1,1)\n);\nfloat myStrength = abs(laplacian(pyramid, vec2(thread), lod));\n#else\n#define L(u,v) (((v)+1)*3 + ((u)+1))\nmat3 strengths[2];\nstrengths[0] = mat3(\n#define Lm(u,v) scores[L((u),(v))]\nLm(-1,-1), Lm(0,-1), Lm(1,-1),\nLm(-1,0), Lm(0,0), Lm(1,0),\nLm(-1,1), Lm(0,1), Lm(1,1)\n);\nstrengths[1] = mat3(\n#define Lp(u,v) scores[9 + L((u),(v))]\nLp(-1,-1), Lp(0,-1), Lp(1,-1),\nLp(-1,0), Lp(0,0), Lp(1,0),\nLp(-1,1), Lp(0,1), Lp(1,1)\n);\nfloat myStrength = score;\n#endif\n#define B(j,lod) float(isSameLod(lods[j], (lod))) * float(scores[j] > 0.0f)\nmat3 nearLod[2];\nnearLod[0] = mat3(\n#define Bm(j) B((j), lodMinus)\nBm(0), Bm(1), Bm(2),\nBm(3), Bm(4), Bm(5),\nBm(6), Bm(7), Bm(8)\n);\nnearLod[1] = mat3(\n#define Bp(j) B((j), lodPlus)\nBp(9), Bp(10), Bp(11),\nBp(12), Bp(13), Bp(14),\nBp(15), Bp(16), Bp(17)\n);\nmat3 upStrengths = matrixCompMult(strengths[1], nearLod[1]);\nmat3 downStrengths = matrixCompMult(strengths[0], nearLod[0]);\nvec3 maxUpStrength3 = max(upStrengths[0], max(upStrengths[1], upStrengths[2]));\nvec3 maxDownStrength3 = max(downStrengths[0], max(downStrengths[1], downStrengths[2]));\nvec3 maxStrength3 = max(maxUpStrength3, maxDownStrength3);\nfloat maxStrength = max(maxStrength3.x, max(maxStrength3.y, maxStrength3.z));\ncolor.rb = encodeFloat16(score * step(maxStrength, myStrength));\n}'},5693:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\nuniform sampler2D corners;\nvoid main()\n{\nivec2 thread = threadLocation();\nvec4 pixel = threadPixel(corners);\nfloat encodedLod = pixel.a;\nfloat score = decodeFloat16(pixel.rb);\nfloat lod = decodeLod(encodedLod);\nfloat pot = exp2(lod);\ncolor = pixel;\nif(score == 0.0f)\nreturn;\n#if 1\nvec2 gridSize = vec2(pot);\nvec2 gridLocation = floor(mod(texCoord * texSize, gridSize));\nvec2 gridDelta = gridLocation / gridSize - vec2(0.5f);\nfloat gridStep = 1.0f / pot;\nconst float adjustment = 1.25f;\ncolor.rb = encodeFloat16(0.0f);\nif(max(abs(gridDelta.x), abs(gridDelta.y)) > adjustment * gridStep)\nreturn;\n#endif\n#define P(x,y) textureLod(corners, texCoord + pot * vec2((x), (y)) / texSize, 0.0f)\nvec4 pix[9];\npix[0] = P(-1,-1); pix[1] = P(0,-1); pix[2] = P(1,-1);\npix[3] = P(-1, 0); pix[4] = pixel; pix[5] = P(1, 0);\npix[6] = P(-1, 1); pix[7] = P(0, 1); pix[8] = P(1, 1);\n#define S(j) decodeFloat16(pix[j].rb)\nmat3 scores = mat3(\nS(0), S(1), S(2),\nS(3), S(4), S(5),\nS(6), S(7), S(8)\n);\n#define B(j) float(isSameLod(decodeLod(pix[j].a), lod))\nmat3 sameLod = mat3(\nB(0), B(1), B(2),\nB(3), B(4), B(5),\nB(6), B(7), B(8)\n);\nmat3 sameLodScores = matrixCompMult(scores, sameLod);\nvec3 maxScore3 = max(sameLodScores[0], max(sameLodScores[1], sameLodScores[2]));\nfloat maxScore = max(maxScore3.x, max(maxScore3.y, maxScore3.z));\ncolor.rb = encodeFloat16(score * step(maxScore, score));\n}'},9280:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\nuniform sampler2D image;\nuniform float lodStep;\n#if !defined(MULTISCALE)\n#error Must define MULTISCALE\n#elif MULTISCALE != 0\n#define LOD_STEP (lodStep)\n#define USE_MIDDLE_RING\n#else\n#define LOD_STEP (0.0f)\n#endif\n#define PIX(x,y) pixelAtShortOffset(image, ivec2((x),(y)))\n#define L2(v,i) bvec2(isSameEncodedLod(v[i].a, alphaMinus), isSameEncodedLod(v[i].a, alphaPlus))\n#define L3(v,i) bvec3(isSameEncodedLod(v[i].a, alpha), isSameEncodedLod(v[i].a, alphaMinus), isSameEncodedLod(v[i].a, alphaPlus))\n#define S3(v,i) decodeFloat16(v[i].rb) * float(any(L3(v,i)))\n#define S2(v,i) decodeFloat16(v[i].rb) * float(any(L2(v,i)))\n#define P(i) S3(p,i)\n#define Q(i) S2(q,i)\n#define R(i) S2(r,i)\nconst vec4 O = vec4(0.0f);\nvoid main()\n{\nvec4 pixel = threadPixel(image);\nfloat lod = decodeLod(pixel.a);\nfloat score = decodeFloat16(pixel.rb);\ncolor = pixel;\nif(score == 0.0f)\nreturn;\nvec4 p[8];\np[0] = PIX(0,1); p[1] = PIX(1,1); p[2] = PIX(1,0); p[3] = PIX(1,-1);\np[4] = PIX(0,-1); p[5] = PIX(-1,-1); p[6] = PIX(-1,0); p[7] = PIX(-1,1);\n#ifdef USE_MIDDLE_RING\nvec4 q[16];\nq[0] = PIX(0,2); q[1] = PIX(1,2); q[2] = PIX(2,2); q[3] = PIX(2,1);\nq[4] = PIX(2,0); q[5] = PIX(2,-1); q[6] = PIX(2,-2); q[7] = PIX(1,-2);\nq[8] = PIX(0,-2); q[9] = PIX(-1,-2); q[10] = PIX(-2,-2); q[11] = PIX(-2,-1);\nq[12] = PIX(-2,0); q[13] = PIX(-2,1); q[14] = PIX(-2,2); q[15] = PIX(-1,2);\n#else\nvec4 q[16];\nq[0] = O; q[1] = O; q[2] = O; q[3] = O;\nq[4] = O; q[5] = O; q[6] = O; q[7] = O;\nq[8] = O; q[9] = O; q[10] = O; q[11] = O;\nq[12] = O; q[13] = O; q[14] = O; q[15] = O;\n#endif\n#ifdef USE_OUTER_RING\nvec4 r[16];\nr[0] = PIX(0,3); r[1] = PIX(1,3); r[2] = PIX(3,1); r[3] = PIX(3,0);\nr[4] = PIX(3,-1); r[5] = PIX(1,-3); r[6] = PIX(0,-3); r[7] = PIX(-1,-3);\nr[8] = PIX(-3,-1); r[9] = PIX(-3,0); r[10] = PIX(-3,1); r[11] = PIX(-1,3);\nr[12] = PIX(0,4); r[13] = PIX(4,0); r[14] = PIX(0,-4); r[15] = PIX(-4,0);\n#else\nvec4 r[16];\nr[0] = O; r[1] = O; r[2] = O; r[3] = O;\nr[4] = O; r[5] = O; r[6] = O; r[7] = O;\nr[8] = O; r[9] = O; r[10] = O; r[11] = O;\nr[12] = O; r[13] = O; r[14] = O; r[15] = O;\n#endif\nfloat alphaPlus = encodeLod(lod + LOD_STEP);\nfloat alphaMinus = encodeLod(lod - LOD_STEP);\nfloat alpha = encodeLod(lod);\nmat3 innerScore = mat3(\nP(0), P(1), P(2), P(3),\nP(4), P(5), P(6), P(7),\n0.0f);\nmat4 middleScore = mat4(\nQ(0), Q(1), Q(2), Q(3),\nQ(4), Q(5), Q(6), Q(7),\nQ(8), Q(9), Q(10), Q(11),\nQ(12), Q(13), Q(14), Q(15)\n);\nmat4 outerScore = mat4(\nR(0), R(1), R(2), R(3),\nR(4), R(5), R(6), R(7),\nR(8), R(9), R(10), R(11),\nR(12), R(13), R(14), R(15)\n);\nvec3 maxInnerScore3 = max(innerScore[0], max(innerScore[1], innerScore[2]));\nvec4 maxMiddleScore4 = max(max(middleScore[0], middleScore[1]), max(middleScore[2], middleScore[3]));\nvec4 maxOuterScore4 = max(max(outerScore[0], outerScore[1]), max(outerScore[2], outerScore[3]));\nfloat maxInnerScore = max(maxInnerScore3.x, max(maxInnerScore3.y, maxInnerScore3.z));\nfloat maxMiddleScore = max(max(maxMiddleScore4.x, maxMiddleScore4.y), max(maxMiddleScore4.z, maxMiddleScore4.w));\nfloat maxOuterScore = max(max(maxOuterScore4.x, maxOuterScore4.y), max(maxOuterScore4.z, maxOuterScore4.w));\nfloat maxScore = max(maxInnerScore, max(maxMiddleScore, maxOuterScore));\nfloat finalScore = step(maxScore, score) * score;\ncolor.rb = encodeFloat16(finalScore);\n}'},9108:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedCorners;\nuniform int encoderLength;\nuniform sampler2D image;\nuniform int extraSize;\nconst int descriptorSize = 32;\n#define P(a,b,c,d) ivec4((a),(b),(c),(d))\nconst ivec4 pat31[256] = ivec4[256](\nP(8,-3,9,5),\nP(4,2,7,-12),\nP(-11,9,-8,2),\nP(7,-12,12,-13),\nP(2,-13,2,12),\nP(1,-7,1,6),\nP(-2,-10,-2,-4),\nP(-13,-13,-11,-8),\nP(-13,-3,-12,-9),\nP(10,4,11,9),\nP(-13,-8,-8,-9),\nP(-11,7,-9,12),\nP(7,7,12,6),\nP(-4,-5,-3,0),\nP(-13,2,-12,-3),\nP(-9,0,-7,5),\nP(12,-6,12,-1),\nP(-3,6,-2,12),\nP(-6,-13,-4,-8),\nP(11,-13,12,-8),\nP(4,7,5,1),\nP(5,-3,10,-3),\nP(3,-7,6,12),\nP(-8,-7,-6,-2),\nP(-2,11,-1,-10),\nP(-13,12,-8,10),\nP(-7,3,-5,-3),\nP(-4,2,-3,7),\nP(-10,-12,-6,11),\nP(5,-12,6,-7),\nP(5,-6,7,-1),\nP(1,0,4,-5),\nP(9,11,11,-13),\nP(4,7,4,12),\nP(2,-1,4,4),\nP(-4,-12,-2,7),\nP(-8,-5,-7,-10),\nP(4,11,9,12),\nP(0,-8,1,-13),\nP(-13,-2,-8,2),\nP(-3,-2,-2,3),\nP(-6,9,-4,-9),\nP(8,12,10,7),\nP(0,9,1,3),\nP(7,-5,11,-10),\nP(-13,-6,-11,0),\nP(10,7,12,1),\nP(-6,-3,-6,12),\nP(10,-9,12,-4),\nP(-13,8,-8,-12),\nP(-13,0,-8,-4),\nP(3,3,7,8),\nP(5,7,10,-7),\nP(-1,7,1,-12),\nP(3,-10,5,6),\nP(2,-4,3,-10),\nP(-13,0,-13,5),\nP(-13,-7,-12,12),\nP(-13,3,-11,8),\nP(-7,12,-4,7),\nP(6,-10,12,8),\nP(-9,-1,-7,-6),\nP(-2,-5,0,12),\nP(-12,5,-7,5),\nP(3,-10,8,-13),\nP(-7,-7,-4,5),\nP(-3,-2,-1,-7),\nP(2,9,5,-11),\nP(-11,-13,-5,-13),\nP(-1,6,0,-1),\nP(5,-3,5,2),\nP(-4,-13,-4,12),\nP(-9,-6,-9,6),\nP(-12,-10,-8,-4),\nP(10,2,12,-3),\nP(7,12,12,12),\nP(-7,-13,-6,5),\nP(-4,9,-3,4),\nP(7,-1,12,2),\nP(-7,6,-5,1),\nP(-13,11,-12,5),\nP(-3,7,-2,-6),\nP(7,-8,12,-7),\nP(-13,-7,-11,-12),\nP(1,-3,12,12),\nP(2,-6,3,0),\nP(-4,3,-2,-13),\nP(-1,-13,1,9),\nP(7,1,8,-6),\nP(1,-1,3,12),\nP(9,1,12,6),\nP(-1,-9,-1,3),\nP(-13,-13,-10,5),\nP(7,7,10,12),\nP(12,-5,12,9),\nP(6,3,7,11),\nP(5,-13,6,10),\nP(2,-12,2,3),\nP(3,8,4,-6),\nP(2,6,12,-13),\nP(9,-12,10,3),\nP(-8,4,-7,9),\nP(-11,12,-4,-6),\nP(1,12,2,-8),\nP(6,-9,7,-4),\nP(2,3,3,-2),\nP(6,3,11,0),\nP(3,-3,8,-8),\nP(7,8,9,3),\nP(-11,-5,-6,-4),\nP(-10,11,-5,10),\nP(-5,-8,-3,12),\nP(-10,5,-9,0),\nP(8,-1,12,-6),\nP(4,-6,6,-11),\nP(-10,12,-8,7),\nP(4,-2,6,7),\nP(-2,0,-2,12),\nP(-5,-8,-5,2),\nP(7,-6,10,12),\nP(-9,-13,-8,-8),\nP(-5,-13,-5,-2),\nP(8,-8,9,-13),\nP(-9,-11,-9,0),\nP(1,-8,1,-2),\nP(7,-4,9,1),\nP(-2,1,-1,-4),\nP(11,-6,12,-11),\nP(-12,-9,-6,4),\nP(3,7,7,12),\nP(5,5,10,8),\nP(0,-4,2,8),\nP(-9,12,-5,-13),\nP(0,7,2,12),\nP(-1,2,1,7),\nP(5,11,7,-9),\nP(3,5,6,-8),\nP(-13,-4,-8,9),\nP(-5,9,-3,-3),\nP(-4,-7,-3,-12),\nP(6,5,8,0),\nP(-7,6,-6,12),\nP(-13,6,-5,-2),\nP(1,-10,3,10),\nP(4,1,8,-4),\nP(-2,-2,2,-13),\nP(2,-12,12,12),\nP(-2,-13,0,-6),\nP(4,1,9,3),\nP(-6,-10,-3,-5),\nP(-3,-13,-1,1),\nP(7,5,12,-11),\nP(4,-2,5,-7),\nP(-13,9,-9,-5),\nP(7,1,8,6),\nP(7,-8,7,6),\nP(-7,-4,-7,1),\nP(-8,11,-7,-8),\nP(-13,6,-12,-8),\nP(2,4,3,9),\nP(10,-5,12,3),\nP(-6,-5,-6,7),\nP(8,-3,9,-8),\nP(2,-12,2,8),\nP(-11,-2,-10,3),\nP(-12,-13,-7,-9),\nP(-11,0,-10,-5),\nP(5,-3,11,8),\nP(-2,-13,-1,12),\nP(-1,-8,0,9),\nP(-13,-11,-12,-5),\nP(-10,-2,-10,11),\nP(-3,9,-2,-13),\nP(2,-3,3,2),\nP(-9,-13,-4,0),\nP(-4,6,-3,-10),\nP(-4,12,-2,-7),\nP(-6,-11,-4,9),\nP(6,-3,6,11),\nP(-13,11,-5,5),\nP(11,11,12,6),\nP(7,-5,12,-2),\nP(-1,12,0,7),\nP(-4,-8,-3,-2),\nP(-7,1,-6,7),\nP(-13,-12,-8,-13),\nP(-7,-2,-6,-8),\nP(-8,5,-6,-9),\nP(-5,-1,-4,5),\nP(-13,7,-8,10),\nP(1,5,5,-13),\nP(1,0,10,-13),\nP(9,12,10,-1),\nP(5,-8,10,-9),\nP(-1,11,1,-13),\nP(-9,-3,-6,2),\nP(-1,-10,1,12),\nP(-13,1,-8,-10),\nP(8,-11,10,-6),\nP(2,-13,3,-6),\nP(7,-13,12,-9),\nP(-10,-10,-5,-7),\nP(-10,-8,-8,-13),\nP(4,-6,8,5),\nP(3,12,8,-13),\nP(-4,2,-3,-3),\nP(5,-13,10,-12),\nP(4,-13,5,-1),\nP(-9,9,-4,3),\nP(0,3,3,-9),\nP(-12,1,-6,1),\nP(3,2,4,-8),\nP(-10,-10,-10,9),\nP(8,-13,12,12),\nP(-8,-12,-6,-5),\nP(2,2,3,7),\nP(10,6,11,-8),\nP(6,8,8,-12),\nP(-7,10,-6,5),\nP(-3,-9,-3,9),\nP(-1,-13,-1,5),\nP(-3,-7,-3,4),\nP(-8,-2,-8,3),\nP(4,2,12,12),\nP(2,-5,3,11),\nP(6,-9,11,-13),\nP(3,-1,7,12),\nP(11,-1,12,4),\nP(-3,0,-3,6),\nP(4,-11,4,12),\nP(2,-4,2,1),\nP(-10,-6,-8,1),\nP(-13,7,-11,1),\nP(-13,12,-11,-13),\nP(6,0,11,-13),\nP(0,-1,1,4),\nP(-13,3,-9,-2),\nP(-9,8,-6,-3),\nP(-13,-6,-8,-2),\nP(5,-9,8,10),\nP(2,7,3,-9),\nP(-1,-6,-1,-1),\nP(9,5,11,-2),\nP(11,-3,12,-8),\nP(3,0,3,5),\nP(-1,4,0,10),\nP(3,-6,4,5),\nP(-13,0,-10,5),\nP(5,8,12,11),\nP(8,9,9,-6),\nP(7,-4,8,-12),\nP(-10,4,-10,9),\nP(7,3,12,4),\nP(9,-7,10,-2),\nP(7,0,12,-2),\nP(-1,-6,0,-11)\n);\nvoid getPair(int index, mat2 rot, out vec2 p, out vec2 q)\n{\nivec4 data = pat31[index];\nvec2 op = vec2(data.xy);\nvec2 oq = vec2(data.zw);\np = rot * op;\nq = rot * oq;\n}\nvoid main()\n{\nvec4 pixel = threadPixel(encodedCorners);\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint descriptorCell = address.offset - sizeofEncodedKeypoint(0, extraSize) / 4;\ncolor = pixel;\nif(descriptorCell < 0)\nreturn;\nKeypoint keypoint = decodeKeypoint(encodedCorners, encoderLength, address);\nif(isBadKeypoint(keypoint))\nreturn;\nfloat degreesOrientation = round(360.0f + degrees(keypoint.orientation));\nfloat orientation = radians(degreesOrientation - mod(degreesOrientation, 12.0f));\nfloat kcos = cos(orientation);\nfloat ksin = sin(orientation);\nmat2 rot = mat2(kcos, ksin, -ksin, kcos);\nfloat pot = exp2(keypoint.lod);\nint patternStart = 32 * descriptorCell;\nuint test[4] = uint[4](0u, 0u, 0u, 0u);\nfor(int t = 0; t < 4; t++) {\nuint bits = 0u;\nvec2 p, q;\nvec4 a, b;\nint i = t * 8;\n@unroll\nfor(int j = 0; j < 8; j++) {\ngetPair(patternStart + i + j, rot, p, q);\na = texelFetch(image, ivec2(round(keypoint.position + pot * p)), 0);\nb = texelFetch(image, ivec2(round(keypoint.position + pot * q)), 0);\nbits |= uint(a.g < b.g) << j;\n}\ntest[t] = bits;\n}\ncolor = vec4(test[0], test[1], test[2], test[3]) / 255.0f;\n}'},7137:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D image;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#define P(x,y) ivec2((x),(y))\nconst int diskPointCount[16] = int[16](0, 4, 12, 28, 48, 80, 112, 148, 196, 252, 316, 376, 440, 528, 612, 708);\nconst ivec2 diskPoint[708] = ivec2[708](\nP(0,-1),P(-1,0),P(1,0),P(0,1),\nP(-1,-1),P(1,-1),P(-1,1),P(1,1),P(0,-2),P(-2,0),P(2,0),P(0,2),\nP(-1,-2),P(1,-2),P(-2,-1),P(2,-1),P(-2,1),P(2,1),P(-1,2),P(1,2),P(-2,-2),P(2,-2),P(-2,2),P(2,2),P(0,-3),P(-3,0),P(3,0),P(0,3),\nP(-1,-3),P(1,-3),P(-3,-1),P(3,-1),P(-3,1),P(3,1),P(-1,3),P(1,3),P(-2,-3),P(2,-3),P(-3,-2),P(3,-2),P(-3,2),P(3,2),P(-2,3),P(2,3),P(0,-4),P(-4,0),P(4,0),P(0,4),\nP(-1,-4),P(1,-4),P(-4,-1),P(4,-1),P(-4,1),P(4,1),P(-1,4),P(1,4),P(-3,-3),P(3,-3),P(-3,3),P(3,3),P(-2,-4),P(2,-4),P(-4,-2),P(4,-2),P(-4,2),P(4,2),P(-2,4),P(2,4),P(0,-5),P(-3,-4),P(3,-4),P(-4,-3),P(4,-3),P(-5,0),P(5,0),P(-4,3),P(4,3),P(-3,4),P(3,4),P(0,5),\nP(-1,-5),P(1,-5),P(-5,-1),P(5,-1),P(-5,1),P(5,1),P(-1,5),P(1,5),P(-2,-5),P(2,-5),P(-5,-2),P(5,-2),P(-5,2),P(5,2),P(-2,5),P(2,5),P(-4,-4),P(4,-4),P(-4,4),P(4,4),P(-3,-5),P(3,-5),P(-5,-3),P(5,-3),P(-5,3),P(5,3),P(-3,5),P(3,5),P(0,-6),P(-6,0),P(6,0),P(0,6),\nP(-1,-6),P(1,-6),P(-6,-1),P(6,-1),P(-6,1),P(6,1),P(-1,6),P(1,6),P(-2,-6),P(2,-6),P(-6,-2),P(6,-2),P(-6,2),P(6,2),P(-2,6),P(2,6),P(-4,-5),P(4,-5),P(-5,-4),P(5,-4),P(-5,4),P(5,4),P(-4,5),P(4,5),P(-3,-6),P(3,-6),P(-6,-3),P(6,-3),P(-6,3),P(6,3),P(-3,6),P(3,6),P(0,-7),P(-7,0),P(7,0),P(0,7),\nP(-1,-7),P(1,-7),P(-5,-5),P(5,-5),P(-7,-1),P(7,-1),P(-7,1),P(7,1),P(-5,5),P(5,5),P(-1,7),P(1,7),P(-4,-6),P(4,-6),P(-6,-4),P(6,-4),P(-6,4),P(6,4),P(-4,6),P(4,6),P(-2,-7),P(2,-7),P(-7,-2),P(7,-2),P(-7,2),P(7,2),P(-2,7),P(2,7),P(-3,-7),P(3,-7),P(-7,-3),P(7,-3),P(-7,3),P(7,3),P(-3,7),P(3,7),P(-5,-6),P(5,-6),P(-6,-5),P(6,-5),P(-6,5),P(6,5),P(-5,6),P(5,6),P(0,-8),P(-8,0),P(8,0),P(0,8),\nP(-1,-8),P(1,-8),P(-4,-7),P(4,-7),P(-7,-4),P(7,-4),P(-8,-1),P(8,-1),P(-8,1),P(8,1),P(-7,4),P(7,4),P(-4,7),P(4,7),P(-1,8),P(1,8),P(-2,-8),P(2,-8),P(-8,-2),P(8,-2),P(-8,2),P(8,2),P(-2,8),P(2,8),P(-6,-6),P(6,-6),P(-6,6),P(6,6),P(-3,-8),P(3,-8),P(-8,-3),P(8,-3),P(-8,3),P(8,3),P(-3,8),P(3,8),P(-5,-7),P(5,-7),P(-7,-5),P(7,-5),P(-7,5),P(7,5),P(-5,7),P(5,7),P(-4,-8),P(4,-8),P(-8,-4),P(8,-4),P(-8,4),P(8,4),P(-4,8),P(4,8),P(0,-9),P(-9,0),P(9,0),P(0,9),\nP(-1,-9),P(1,-9),P(-9,-1),P(9,-1),P(-9,1),P(9,1),P(-1,9),P(1,9),P(-2,-9),P(2,-9),P(-6,-7),P(6,-7),P(-7,-6),P(7,-6),P(-9,-2),P(9,-2),P(-9,2),P(9,2),P(-7,6),P(7,6),P(-6,7),P(6,7),P(-2,9),P(2,9),P(-5,-8),P(5,-8),P(-8,-5),P(8,-5),P(-8,5),P(8,5),P(-5,8),P(5,8),P(-3,-9),P(3,-9),P(-9,-3),P(9,-3),P(-9,3),P(9,3),P(-3,9),P(3,9),P(-4,-9),P(4,-9),P(-9,-4),P(9,-4),P(-9,4),P(9,4),P(-4,9),P(4,9),P(-7,-7),P(7,-7),P(-7,7),P(7,7),P(0,-10),P(-6,-8),P(6,-8),P(-8,-6),P(8,-6),P(-10,0),P(10,0),P(-8,6),P(8,6),P(-6,8),P(6,8),P(0,10),\nP(-1,-10),P(1,-10),P(-10,-1),P(10,-1),P(-10,1),P(10,1),P(-1,10),P(1,10),P(-2,-10),P(2,-10),P(-10,-2),P(10,-2),P(-10,2),P(10,2),P(-2,10),P(2,10),P(-5,-9),P(5,-9),P(-9,-5),P(9,-5),P(-9,5),P(9,5),P(-5,9),P(5,9),P(-3,-10),P(3,-10),P(-10,-3),P(10,-3),P(-10,3),P(10,3),P(-3,10),P(3,10),P(-7,-8),P(7,-8),P(-8,-7),P(8,-7),P(-8,7),P(8,7),P(-7,8),P(7,8),P(-4,-10),P(4,-10),P(-10,-4),P(10,-4),P(-10,4),P(10,4),P(-4,10),P(4,10),P(-6,-9),P(6,-9),P(-9,-6),P(9,-6),P(-9,6),P(9,6),P(-6,9),P(6,9),P(0,-11),P(-11,0),P(11,0),P(0,11),\nP(-1,-11),P(1,-11),P(-11,-1),P(11,-1),P(-11,1),P(11,1),P(-1,11),P(1,11),P(-2,-11),P(2,-11),P(-5,-10),P(5,-10),P(-10,-5),P(10,-5),P(-11,-2),P(11,-2),P(-11,2),P(11,2),P(-10,5),P(10,5),P(-5,10),P(5,10),P(-2,11),P(2,11),P(-8,-8),P(8,-8),P(-8,8),P(8,8),P(-3,-11),P(3,-11),P(-7,-9),P(7,-9),P(-9,-7),P(9,-7),P(-11,-3),P(11,-3),P(-11,3),P(11,3),P(-9,7),P(9,7),P(-7,9),P(7,9),P(-3,11),P(3,11),P(-6,-10),P(6,-10),P(-10,-6),P(10,-6),P(-10,6),P(10,6),P(-6,10),P(6,10),P(-4,-11),P(4,-11),P(-11,-4),P(11,-4),P(-11,4),P(11,4),P(-4,11),P(4,11),P(0,-12),P(-12,0),P(12,0),P(0,12),\nP(-1,-12),P(1,-12),P(-8,-9),P(8,-9),P(-9,-8),P(9,-8),P(-12,-1),P(12,-1),P(-12,1),P(12,1),P(-9,8),P(9,8),P(-8,9),P(8,9),P(-1,12),P(1,12),P(-5,-11),P(5,-11),P(-11,-5),P(11,-5),P(-11,5),P(11,5),P(-5,11),P(5,11),P(-2,-12),P(2,-12),P(-12,-2),P(12,-2),P(-12,2),P(12,2),P(-2,12),P(2,12),P(-7,-10),P(7,-10),P(-10,-7),P(10,-7),P(-10,7),P(10,7),P(-7,10),P(7,10),P(-3,-12),P(3,-12),P(-12,-3),P(12,-3),P(-12,3),P(12,3),P(-3,12),P(3,12),P(-6,-11),P(6,-11),P(-11,-6),P(11,-6),P(-11,6),P(11,6),P(-6,11),P(6,11),P(-4,-12),P(4,-12),P(-12,-4),P(12,-4),P(-12,4),P(12,4),P(-4,12),P(4,12),P(-9,-9),P(9,-9),P(-9,9),P(9,9),P(-8,-10),P(8,-10),P(-10,-8),P(10,-8),P(-10,8),P(10,8),P(-8,10),P(8,10),P(0,-13),P(-5,-12),P(5,-12),P(-12,-5),P(12,-5),P(-13,0),P(13,0),P(-12,5),P(12,5),P(-5,12),P(5,12),P(0,13),\nP(-1,-13),P(1,-13),P(-7,-11),P(7,-11),P(-11,-7),P(11,-7),P(-13,-1),P(13,-1),P(-13,1),P(13,1),P(-11,7),P(11,7),P(-7,11),P(7,11),P(-1,13),P(1,13),P(-2,-13),P(2,-13),P(-13,-2),P(13,-2),P(-13,2),P(13,2),P(-2,13),P(2,13),P(-3,-13),P(3,-13),P(-13,-3),P(13,-3),P(-13,3),P(13,3),P(-3,13),P(3,13),P(-6,-12),P(6,-12),P(-12,-6),P(12,-6),P(-12,6),P(12,6),P(-6,12),P(6,12),P(-9,-10),P(9,-10),P(-10,-9),P(10,-9),P(-10,9),P(10,9),P(-9,10),P(9,10),P(-4,-13),P(4,-13),P(-8,-11),P(8,-11),P(-11,-8),P(11,-8),P(-13,-4),P(13,-4),P(-13,4),P(13,4),P(-11,8),P(11,8),P(-8,11),P(8,11),P(-4,13),P(4,13),P(-7,-12),P(7,-12),P(-12,-7),P(12,-7),P(-12,7),P(12,7),P(-7,12),P(7,12),P(-5,-13),P(5,-13),P(-13,-5),P(13,-5),P(-13,5),P(13,5),P(-5,13),P(5,13),P(0,-14),P(-14,0),P(14,0),P(0,14),\nP(-1,-14),P(1,-14),P(-14,-1),P(14,-1),P(-14,1),P(14,1),P(-1,14),P(1,14),P(-2,-14),P(2,-14),P(-10,-10),P(10,-10),P(-14,-2),P(14,-2),P(-14,2),P(14,2),P(-10,10),P(10,10),P(-2,14),P(2,14),P(-9,-11),P(9,-11),P(-11,-9),P(11,-9),P(-11,9),P(11,9),P(-9,11),P(9,11),P(-3,-14),P(3,-14),P(-6,-13),P(6,-13),P(-13,-6),P(13,-6),P(-14,-3),P(14,-3),P(-14,3),P(14,3),P(-13,6),P(13,6),P(-6,13),P(6,13),P(-3,14),P(3,14),P(-8,-12),P(8,-12),P(-12,-8),P(12,-8),P(-12,8),P(12,8),P(-8,12),P(8,12),P(-4,-14),P(4,-14),P(-14,-4),P(14,-4),P(-14,4),P(14,4),P(-4,14),P(4,14),P(-7,-13),P(7,-13),P(-13,-7),P(13,-7),P(-13,7),P(13,7),P(-7,13),P(7,13),P(-5,-14),P(5,-14),P(-10,-11),P(10,-11),P(-11,-10),P(11,-10),P(-14,-5),P(14,-5),P(-14,5),P(14,5),P(-11,10),P(11,10),P(-10,11),P(10,11),P(-5,14),P(5,14),P(0,-15),P(-9,-12),P(9,-12),P(-12,-9),P(12,-9),P(-15,0),P(15,0),P(-12,9),P(12,9),P(-9,12),P(9,12),P(0,15)\n);\nconst int DEFAULT_PATCH_RADIUS = 15;\nconst int MIN_PATCH_RADIUS = 2;\nvoid main()\n{\nvec4 pixel = threadPixel(encodedKeypoints);\nivec2 thread = threadLocation();\nint keypointIndex = thread.x + thread.y * outputSize().x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\nvec2 m = vec2(0.0f);\nfloat pot = exp2(keypoint.lod);\nvec2 imageSize = vec2(textureSize(image, 0));\nint scaledRadius = int(ceil(float(DEFAULT_PATCH_RADIUS) / pot));\nint radius = max(scaledRadius, MIN_PATCH_RADIUS);\nint count = diskPointCount[radius];\nfor(int j = 0; j < count; j++) {\nvec2 offset = vec2(diskPoint[j]);\nvec2 position = keypoint.position + round(pot * offset);\nvec4 patchPixel = texture(image, (position + vec2(0.5f)) / imageSize);\nm += offset * patchPixel.g;\n}\nfloat angle = fastAtan2(m.y, m.x);\nfloat encodedOrientation = encodeKeypointOrientation(angle);\ncolor = vec4(0.0f, encodedOrientation, 0.0f, 0.0f);\n}'},9739:e=>{e.exports='@include "keypoints.glsl"\n@include "filters.glsl"\n#if !defined(METHOD)\n#error Undefined METHOD\n#endif\nuniform sampler2D pyramid;\nuniform float lodStep;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#if METHOD == 1\nuniform int threshold;\n#endif\nconst float eps = 1e-6;\nfloat cornerStrength(vec2 position, float lod)\n{\n#if METHOD == 0\nreturn laplacian(pyramid, position, lod);\n#elif METHOD == 1\nfloat pot = exp2(lod);\nfloat t = float(clamp(threshold, 0, 255)) / 255.0f;\n#define P(x,y) pyrPixelAtOffset(pyramid, lod, pot, ivec2((x),(y))).g\nmat4 mp = mat4(\nP(0,3),P(3,0),P(0,-3),P(-3,0),\nP(1,3),P(2,2),P(3,1),P(3,-1),\nP(2,-2),P(1,-3),P(-1,-3),P(-2,-2),\nP(-3,-1),P(-3,1),P(-2,2),P(-1,3)\n);\nfloat c = P(0,0);\nfloat ct = c + t, c_t = c - t;\nmat4 mct = mp - mat4(ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct,ct);\nmat4 mc_t = mat4(c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t,c_t) - mp;\nconst vec4 zeros = vec4(0.0f), ones = vec4(1.0f);\nvec4 bs = max(mct[0], zeros), ds = max(mc_t[0], zeros);\nbs += max(mct[1], zeros); ds += max(mc_t[1], zeros);\nbs += max(mct[2], zeros); ds += max(mc_t[2], zeros);\nbs += max(mct[3], zeros); ds += max(mc_t[3], zeros);\nreturn max(dot(bs, ones), dot(ds, ones)) / 16.0f;\n#else\n#error Invalid method\n#endif\n}\nvoid main()\n{\nvec4 pixel = threadPixel(encodedKeypoints);\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\ncolor = pixel;\nif(address.offset != 1)\nreturn;\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\nif(isBadKeypoint(keypoint))\nreturn;\nvec3 strength = vec3(\ncornerStrength(keypoint.position, max(0.0f, keypoint.lod - lodStep)),\ncornerStrength(keypoint.position, keypoint.lod),\ncornerStrength(keypoint.position, keypoint.lod + lodStep)\n);\nvec3 p = mat3(\n2, -3, 1,\n-4, 4, 0,\n2, -1, 0\n) * strength;\nfloat maxStrength = max(strength.x, max(strength.y, strength.z));\nvec3 diffStrength = abs(strength - vec3(maxStrength));\nvec3 strengthIndicators = vec3(lessThan(diffStrength, vec3(eps)));\nfloat maxPoint = min(1.0f, dot(vec3(0.0f, 0.5f, 1.0f), strengthIndicators));\nbool hasMax = p.x < -eps;\nfloat pmax = hasMax ? -0.5f * p.y / p.x : maxPoint;\nfloat alpha = abs(pmax - 0.5f) <= 0.5f ? pmax : maxPoint;\nfloat lodOffset = mix(-lodStep, lodStep, alpha);\nfloat lod = keypoint.lod + lodOffset;\ncolor.r = encodeLod(lod);\n}'},8231:e=>{e.exports='@include "float16.glsl"\nuniform sampler2D corners;\nuniform int iterationNumber;\nvoid main()\n{\nivec2 thread = threadLocation();\nivec2 bounds = outputSize();\nint jump = (1 << iterationNumber);\nint clusterLength = jump << 1;\nint clusterMask = clusterLength - 1;\nivec2 clusterPos = ivec2(thread >> (1 + iterationNumber)) << (1 + iterationNumber);\nivec2 next1 = clusterPos + ((thread - clusterPos + ivec2(jump, 0)) & clusterMask);\nivec2 next2 = clusterPos + ((thread - clusterPos + ivec2(0, jump)) & clusterMask);\nivec2 next3 = clusterPos + ((thread - clusterPos + ivec2(jump, jump)) & clusterMask);\nvec4 p0 = threadPixel(corners);\nvec4 p1 = texelFetch(corners, next1 % bounds, 0);\nvec4 p2 = texelFetch(corners, next2 % bounds, 0);\nvec4 p3 = texelFetch(corners, next3 % bounds, 0);\nfloat s0 = decodeFloat16(p0.rb);\nfloat s1 = decodeFloat16(p1.rb);\nfloat s2 = decodeFloat16(p2.rb);\nfloat s3 = decodeFloat16(p3.rb);\nbool b0 = s0 >= s1 && s0 >= s2 && s0 >= s3;\nbool b1 = s1 >= s0 && s1 >= s2 && s1 >= s3;\nbool b2 = s2 >= s0 && s2 >= s1 && s2 >= s3;\ncolor = vec4(0.0f);\ncolor.rb = b0 ? p0.rb : (\nb1 ? p1.rb : (\nb2 ? p2.rb : p3.rb\n)\n);\n}'},2518:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#if PERMUTATION_MAXLEN % 4 > 0 || PERMUTATION_MAXLEN * 4 > 16384\n#error Invalid PERMUTATION_MAXLEN\n#endif\nlayout(std140) uniform Permutation\n{\nivec4 permutation[PERMUTATION_MAXLEN / 4];\n};\nint permutationElement(int index)\n{\nint base = index - (index % PERMUTATION_MAXLEN);\nint offset = index - base;\nivec4 tuple = permutation[offset / 4];\nint newOffset = tuple[offset & 3];\nreturn base + newOffset;\n}\nvoid main()\n{\nivec2 thread = threadLocation();\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress myAddress = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint myIndex = findKeypointIndex(myAddress, descriptorSize, extraSize);\nint otherIndex = permutationElement(myIndex);\nKeypointAddress otherAddress = KeypointAddress(otherIndex * pixelsPerKeypoint, myAddress.offset);\nKeypoint myKeypoint = decodeKeypoint(encodedKeypoints, encoderLength, myAddress);\nKeypoint otherKeypoint = decodeKeypoint(encodedKeypoints, encoderLength, otherAddress);\ncolor = readKeypointData(encodedKeypoints, encoderLength, otherAddress);\n}'},8096:e=>{e.exports='@include "keypoints.glsl"\n#if !defined(STAGE)\n#error Undefined STAGE\n#elif STAGE == 1\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#elif STAGE == 2\nuniform sampler2D permutation;\nuniform int blockSize;\nuniform int dblLog2BlockSize;\n#elif STAGE == 3\nuniform sampler2D permutation;\nuniform int maxKeypoints;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\n#else\n#error Invalid STAGE\n#endif\nstruct PermutationElement\n{\nint keypointIndex;\nfloat score;\nbool valid;\n};\nvec4 encodePermutationElement(PermutationElement element)\n{\nconst vec2 ONES = vec2(1.0f);\nvec2 encodedScore = element.valid ? encodeFloat16(element.score) : ONES;\nvec2 encodedIndex = vec2(element.keypointIndex & 255, (element.keypointIndex >> 8) & 255) / 255.0f;\nreturn vec4(encodedIndex, encodedScore);\n}\nPermutationElement decodePermutationElement(vec4 pixel)\n{\nconst vec2 ONES = vec2(1.0f);\nPermutationElement element;\nelement.keypointIndex = int(pixel.r * 255.0f) | (int(pixel.g * 255.0f) << 8);\nelement.valid = !all(equal(pixel.ba, ONES));\nelement.score = element.valid ? decodeFloat16(pixel.ba) : -1.0f;\nreturn element;\n}\nPermutationElement readPermutationElement(sampler2D permutation, int elementIndex, int stride, int height)\n{\nconst vec4 INVALID_PIXEL = vec4(1.0f);\nivec2 pos = ivec2(elementIndex % stride, elementIndex / stride);\nvec4 pixel = pos.y < height ? pixelAt(permutation, pos) : INVALID_PIXEL;\nreturn decodePermutationElement(pixel);\n}\n#if STAGE == 2\nPermutationElement selectKth(sampler2D permutation, int k, int la, int ra, int lb, int rb)\n{\nfloat scoreA, scoreB;\nint ha, hb, ma, mb;\nbool discard1stHalf, altb;\nbool locked = false;\nint tmp, result = 0;\nint stride = outputSize().x;\nint height = outputSize().y;\nfor(int i = 0; i < dblLog2BlockSize; i++) {\ntmp = (lb > rb && !locked) ? (la+k) : result;\nresult = (la > ra && !locked) ? (lb+k) : tmp;\nlocked = locked || (la > ra) || (lb > rb);\nha = (ra - la + 1) / 2;\nhb = (rb - lb + 1) / 2;\nma = la + ha;\nmb = lb + hb;\nscoreA = readPermutationElement(permutation, ma, stride, height).score;\nscoreB = readPermutationElement(permutation, mb, stride, height).score;\ndiscard1stHalf = (k > ha + hb);\naltb = (-scoreA < -scoreB);\nk -= int(discard1stHalf && altb) * (ha + 1);\nk -= int(discard1stHalf && !altb) * (hb + 1);\nla += int(discard1stHalf && altb) * (ma + 1 - la);\nlb += int(discard1stHalf && !altb) * (mb + 1 - lb);\nra += int(!discard1stHalf && !altb) * (ma - 1 - ra);\nrb += int(!discard1stHalf && altb) * (mb - 1 - rb);\n}\nreturn readPermutationElement(permutation, result, stride, height);\n}\n#endif\nvoid main()\n{\n#if STAGE == 1\nivec2 thread = threadLocation();\nint stride = outputSize().x;\nint keypointIndex = thread.y * stride + thread.x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\nPermutationElement element;\nelement.keypointIndex = keypointIndex;\nelement.score = keypoint.score;\nelement.valid = !isBadKeypoint(keypoint);\ncolor = encodePermutationElement(element);\n#elif STAGE == 2\nivec2 thread = threadLocation();\nint stride = outputSize().x;\nint elementIndex = thread.y * stride + thread.x;\nint blockIndex = elementIndex / blockSize;\nint blockOffset = elementIndex % blockSize;\nint la = blockIndex * blockSize;\nint lb = la + blockSize / 2;\nint ra = lb - 1;\nint rb = (blockIndex + 1) * blockSize - 1;\nint k = blockOffset;\nPermutationElement element = selectKth(permutation, k, la, ra, lb, rb);\ncolor = encodePermutationElement(element);\n#elif STAGE == 3\nivec2 thread = threadLocation();\nint newEncoderLength = outputSize().x;\nKeypointAddress myAddress = findKeypointAddress(thread, newEncoderLength, descriptorSize, extraSize);\nint myKeypointIndex = findKeypointIndex(myAddress, descriptorSize, extraSize);\nivec2 psize = textureSize(permutation, 0);\nPermutationElement element = readPermutationElement(permutation, myKeypointIndex, psize.x, psize.y);\nint oldEncoderLength = textureSize(encodedKeypoints, 0).x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(element.keypointIndex * pixelsPerKeypoint, myAddress.offset);\nvec4 keypointData = readKeypointData(encodedKeypoints, oldEncoderLength, address);\ncolor = myKeypointIndex < maxKeypoints && element.valid ? keypointData : encodeNullKeypoint();\n#endif\n}'},5795:e=>{e.exports='@include "keypoints.glsl"\n@include "float16.glsl"\n#if !defined(METHOD)\n#error Must define METHOD\n#endif\nuniform sampler2D pyramid;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nuniform int maxIterations;\nuniform float epsilon;\nconst int PATCH_RADIUS = 1;\nconst int PATCH_SIZE = 2 * PATCH_RADIUS + 1;\nconst int PATCH_SIZE_SQUARED = PATCH_SIZE * PATCH_SIZE;\nconst int LARGE_PATCH_RADIUS = PATCH_RADIUS + 1;\nconst int LARGE_PATCH_SIZE = 2 * LARGE_PATCH_RADIUS + 1;\nconst int LARGE_PATCH_SIZE_SQUARED = LARGE_PATCH_SIZE * LARGE_PATCH_SIZE;\nconst int LARGER_PATCH_RADIUS = LARGE_PATCH_RADIUS + 1;\nconst int LARGER_PATCH_SIZE = 2 * LARGER_PATCH_RADIUS + 1;\nconst int LARGER_PATCH_SIZE_SQUARED = LARGER_PATCH_SIZE * LARGER_PATCH_SIZE;\nconst float EPS = 1e-5;\nfloat smoothPixelBuffer[LARGER_PATCH_SIZE_SQUARED];\nvec2 derivativesBuffer[LARGE_PATCH_SIZE_SQUARED];\nfloat responseBuffer[PATCH_SIZE_SQUARED];\n#define patchPixelAt(u,v) smoothPixelBuffer[((v) + LARGER_PATCH_RADIUS) * LARGER_PATCH_SIZE + ((u) + LARGER_PATCH_RADIUS)]\n#define derivativesAt(u,v) derivativesBuffer[((v) + LARGE_PATCH_RADIUS) * LARGE_PATCH_SIZE + ((u) + LARGE_PATCH_RADIUS)]\n#define responseAt(u,v) responseBuffer[((v) + PATCH_RADIUS) * PATCH_SIZE + ((u) + PATCH_RADIUS)]\nvoid readPixels(vec2 center, float lod)\n{\nivec2 pyrBaseSize = textureSize(pyramid, 0);\nfloat pot = exp2(lod);\nint u, v;\nfor(int j = 0; j < LARGER_PATCH_SIZE; j++) {\nfor(int i = 0; i < LARGER_PATCH_SIZE; i++) {\nu = i - LARGER_PATCH_RADIUS;\nv = j - LARGER_PATCH_RADIUS;\npatchPixelAt(u,v) = pyrSubpixelAtExOffset(pyramid, center, lod, pot, ivec2(u,v), pyrBaseSize).g;\n}\n}\n}\nvoid computeDerivatives()\n{\nconst mat3 dx = mat3(\n-1, 0, 1,\n-2, 0, 2,\n-1, 0, 1\n);\nconst mat3 dy = mat3(\n1, 2, 1,\n0, 0, 0,\n-1,-2,-1\n);\nint u, v;\nmat3 pix, convX, convY;\nconst vec3 ones = vec3(1.0f);\nfor(int j = 0; j < LARGE_PATCH_SIZE; j++) {\nfor(int i = 0; i < LARGE_PATCH_SIZE; i++) {\nu = i - LARGE_PATCH_RADIUS;\nv = j - LARGE_PATCH_RADIUS;\npix = mat3(\npatchPixelAt(u+1,v+1), patchPixelAt(u+0,v+1), patchPixelAt(u-1,v+1),\npatchPixelAt(u+1,v+0), patchPixelAt(u+0,v+0), patchPixelAt(u-1,v+0),\npatchPixelAt(u+1,v-1), patchPixelAt(u+0,v-1), patchPixelAt(u-1,v-1)\n);\nconvX = matrixCompMult(dx, pix);\nconvY = matrixCompMult(dy, pix);\nderivativesAt(u,v) = vec2(\ndot(ones, vec3(\ndot(convX[0], ones),\ndot(convX[1], ones),\ndot(convX[2], ones)\n)),\ndot(ones, vec3(\ndot(convY[0], ones),\ndot(convY[1], ones),\ndot(convY[2], ones)\n))\n);\n}\n}\n}\nvec2 computeResponseMap()\n{\nfloat patchArea = float(PATCH_SIZE * PATCH_SIZE);\nvec3 h; vec2 d, c = vec2(0.0f);\nconst vec3 ones = vec3(1.0f);\nfloat response, sum = 0.0f;\nint u, v;\n#define H(r,s) d = derivativesAt((r),(s)); h += vec3(d.x * d.x, d.x * d.y, d.y * d.y)\nfor(int j = 0; j < PATCH_SIZE; j++) {\nfor(int i = 0; i < PATCH_SIZE; i++) {\nu = i - PATCH_RADIUS;\nv = j - PATCH_RADIUS;\nh = vec3(0.0f);\nH(u-1,v-1); H(u+0,v-1); H(u+1,v-1);\nH(u-1,v+0); H(u+0,v+0); H(u+1,v+0);\nH(u-1,v+1); H(u+0,v+1); H(u+1,v+1);\nresponse = 0.5f * (h.x + h.z - sqrt((h.x - h.z) * (h.x - h.z) + 4.0f * h.y * h.y));\nresponse /= patchArea;\nresponseAt(u,v) = response;\nc += vec2(u,v) * response;\nsum += response;\n}\n}\nreturn abs(sum) > EPS ? c / sum : vec2(0.0f);\n}\n#if METHOD == 0\nvec2 quadratic1d()\n{\nfloat a = 0.5f * (responseAt(-1,0) - 2.0f * responseAt(0,0) + responseAt(1,0));\nfloat b = 0.5f * (responseAt(1,0) - responseAt(-1,0));\nfloat c = responseAt(0,0);\nfloat d = 0.5f * (responseAt(0,-1) - 2.0f * responseAt(0,0) + responseAt(0,1));\nfloat e = 0.5f * (responseAt(0,1) - responseAt(0,-1));\nfloat f = responseAt(0,0);\nbool hasMax = a < -EPS && d < -EPS;\nreturn hasMax ? -0.5f * vec2(b / a, e / d) : vec2(0.0f);\n}\n#endif\n#if METHOD == 1\nvec2 taylor2d()\n{\nfloat dx = (-responseAt(-1,0) + responseAt(1,0)) * 0.5f;\nfloat dy = (-responseAt(0,-1) + responseAt(0,1)) * 0.5f;\nfloat dxx = responseAt(-1,0) - 2.0f * responseAt(0,0) + responseAt(1,0);\nfloat dyy = responseAt(0,-1) - 2.0f * responseAt(0,0) + responseAt(0,1);\nfloat dxy = (responseAt(-1,-1) + responseAt(1,1) - responseAt(1,-1) - responseAt(-1,1)) * 0.25f;\nfloat det = dxx * dyy - dxy * dxy;\nmat2 inv = mat2(dyy, -dxy, -dxy, dxx);\nbool hasMax = det > EPS && dxx < 0.0f;\nreturn hasMax ? inv * vec2(dx, dy) / (-det) : vec2(0.0f);\n}\n#endif\n#if METHOD == 2\nvoid bilinearUpsample(ivec2 patchOffset, vec4 pixelsOfPatch)\n{\nint u, v, i, j;\nvec2 frc, ifrc; vec4 sub;\nconst vec4 ones = vec4(1.0f);\nfloat s = 1.0f / float(PATCH_SIZE - 1);\nint xoff = 2 * patchOffset.x;\nint yoff = 2 * patchOffset.y;\nfor(j = 0; j < PATCH_SIZE; j++) {\nfor(i = 0; i < PATCH_SIZE; i++) {\nu = i - PATCH_RADIUS;\nv = j - PATCH_RADIUS;\nfrc = vec2(i, j) * s;\nifrc = vec2(1.0f) - frc;\nsub = vec4(\nifrc.x * ifrc.y,\nfrc.x * ifrc.y,\nifrc.x * frc.y,\nfrc.x * frc.y\n);\npatchPixelAt(u+xoff,v+yoff) = dot(sub*pixelsOfPatch, ones);\n}\n}\n}\n#endif\n#if METHOD == 3\nvoid bicubicUpsample(ivec2 patchOffset, vec4 pixelsOfPatch, vec4 dx, vec4 dy, vec4 dxy)\n{\nfloat x, y, s = 1.0f / float(PATCH_SIZE - 1);\nint u, v, i, j;\nfloat f00 = pixelsOfPatch.x;\nfloat f10 = pixelsOfPatch.y;\nfloat f01 = pixelsOfPatch.z;\nfloat f11 = pixelsOfPatch.w;\nfloat fx00 = dx.x;\nfloat fx10 = dx.y;\nfloat fx01 = dx.z;\nfloat fx11 = dx.w;\nfloat fy00 = dy.x;\nfloat fy10 = dy.y;\nfloat fy01 = dy.z;\nfloat fy11 = dy.w;\nfloat fxy00 = dxy.x;\nfloat fxy10 = dxy.y;\nfloat fxy01 = dxy.z;\nfloat fxy11 = dxy.w;\nmat4 bicubic = mat4(\n1, 0, -3, 2,\n0, 0, 3, -2,\n0, 1, -2, 1,\n0, 0, -1, 1\n) * mat4(\nf00, f10, fx00, fx10,\nf01, f11, fx01, fx11,\nfy00, fy10, fxy00, fxy10,\nfy01, fy11, fxy01, fxy11\n) * mat4(\n1, 0, 0, 0,\n0, 0, 1, 0,\n-3, 3, -2, -1,\n2, -2, 1, 1\n);\nint xoff = 2 * patchOffset.x;\nint yoff = 2 * patchOffset.y;\nfor(j = 0; j < PATCH_SIZE; j++) {\nfor(i = 0; i < PATCH_SIZE; i++) {\nu = i - PATCH_RADIUS;\nv = j - PATCH_RADIUS;\nx = float(i) * s;\ny = float(j) * s;\npatchPixelAt(u+xoff,v+yoff) = dot(\nvec4(1, x, x*x, x*x*x),\nbicubic * vec4(1, y, y*y, y*y*y)\n);\n}\n}\n}\n#endif\n#if METHOD == 2 || METHOD == 3\nvoid upsamplePatch(int left, int top, int right, int bottom)\n{\nint x, y, k;\nvec4 ptch[9];\nvec2 d00, d10, d01, d11;\nfor(k = 0; k < 9; k++) {\nx = -1 + (k % 3);\ny = -1 + (k / 3);\nptch[k] = vec4(\npatchPixelAt(left+x, top+y),\npatchPixelAt(right+x, top+y),\npatchPixelAt(left+x, bottom+y),\npatchPixelAt(right+x, bottom+y)\n);\n}\nfor(k = 0; k < 9; k++) {\nx = -1 + (k % 3);\ny = -1 + (k / 3);\n#if METHOD == 2\nbilinearUpsample(ivec2(x, y), ptch[k]);\n#elif METHOD == 3\nd00 = derivativesAt(left+x, top+y);\nd10 = derivativesAt(right+x, top+y);\nd01 = derivativesAt(left+x, bottom+y);\nd11 = derivativesAt(right+x, bottom+y);\nbicubicUpsample(ivec2(x, y), ptch[k],\nvec4(d00.x, d10.x, d01.x, d11.x),\nvec4(d00.y, d10.y, d01.y, d11.y),\n0.25f * vec4(\n(patchPixelAt(left+x + 1,top+y + 1) + patchPixelAt(left+x - 1, top+y - 1)) - (patchPixelAt(left+x + 1, top+y - 1) + patchPixelAt(left+x - 1, top+y + 1)),\n(patchPixelAt(right+x + 1,top+y + 1) + patchPixelAt(right+x - 1, top+y - 1)) - (patchPixelAt(right+x + 1, top+y - 1) + patchPixelAt(right+x - 1, top+y + 1)),\n(patchPixelAt(left+x + 1,bottom+y + 1) + patchPixelAt(left+x - 1, bottom+y - 1)) - (patchPixelAt(left+x + 1, bottom+y - 1) + patchPixelAt(left+x - 1, bottom+y + 1)),\n(patchPixelAt(right+x + 1,bottom+y + 1) + patchPixelAt(right+x - 1, bottom+y - 1)) - (patchPixelAt(right+x + 1, bottom+y - 1) + patchPixelAt(right+x - 1, bottom+y + 1))\n)\n);\n#endif\n}\n}\nvec2 upsampleResponseMap(int left, int top, int right, int bottom)\n{\nupsamplePatch(left, top, right, bottom);\ncomputeDerivatives();\nreturn computeResponseMap();\n}\nvec2 iterativeUpsample(vec2 initialGuess)\n{\nint refine = 1;\nfloat scale = 0.5f;\nfloat eps2 = epsilon * epsilon;\nvec2 guess = initialGuess, localGuess = initialGuess;\nfor(int k = 0; k < maxIterations; k++) {\nivec4 quad = ivec4(floor(localGuess.x), floor(localGuess.y), ceil(localGuess.x), ceil(localGuess.y));\nvec2 response = (refine != 0) ? upsampleResponseMap(quad.x, quad.y, quad.z, quad.w) : vec2(0.0f);\nlocalGuess = response * scale;\nguess += localGuess;\nscale *= 0.5f;\nrefine *= int(dot(localGuess, localGuess) >= eps2);\n}\nreturn guess;\n}\n#endif\nvoid main()\n{\nivec2 thread = threadLocation();\nint keypointIndex = thread.x + thread.y * outputSize().x;\nint pixelsPerKeypoint = sizeofEncodedKeypoint(descriptorSize, extraSize) / 4;\nKeypointAddress address = KeypointAddress(keypointIndex * pixelsPerKeypoint, 0);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, address);\ncolor = encodeNullPairOfFloat16();\nif(isNullKeypoint(keypoint))\nreturn;\ncolor = encodeDiscardedPairOfFloat16();\nif(isBadKeypoint(keypoint))\nreturn;\nreadPixels(keypoint.position, keypoint.lod);\ncomputeDerivatives();\nvec2 offset = computeResponseMap();\n#if METHOD == 0\noffset = quadratic1d();\n#elif METHOD == 1\noffset = taylor2d();\n#elif METHOD == 2 || METHOD == 3\noffset = iterativeUpsample(offset);\n#else\n#error Unknown METHOD\n#endif\nfloat pot = exp2(keypoint.lod);\ncolor = encodePairOfFloat16(offset * pot);\n}'},3169:e=>{e.exports='@include "keypoints.glsl"\n@include "float16.glsl"\nuniform sampler2D encodedFlow;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nvoid main()\n{\nvec4 pixel = threadPixel(encodedKeypoints);\nivec2 thread = threadLocation();\nint len = textureSize(encodedFlow, 0).x;\nKeypointAddress myAddress = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, myAddress);\nint myIndex = findKeypointIndex(myAddress, descriptorSize, extraSize);\ncolor = pixel;\nif(isBadKeypoint(keypoint))\nreturn;\nivec2 location = ivec2(myIndex % len, myIndex / len);\nvec4 encodedFlow = myIndex < len * len ? pixelAt(encodedFlow, location) : encodeDiscardedKeypoint();\nbool discardFlow = isDiscardedPairOfFloat16(encodedFlow);\nvec2 flow = !discardFlow ? decodePairOfFloat16(encodedFlow) : vec2(0.0f);\nvec4 newPosition = encodeKeypointPosition(keypoint.position + flow);\nvec4 newPixel = myAddress.offset == 0 ? newPosition : pixel;\ncolor = !discardFlow ? newPixel : encodeDiscardedKeypoint();\n}'},1337:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedOrientations;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nvoid main()\n{\nvec4 pixel = threadPixel(encodedKeypoints);\nivec2 thread = threadLocation();\nKeypointAddress myAddress = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint myIndex = findKeypointIndex(myAddress, descriptorSize, extraSize);\nint orientationEncoderLength = textureSize(encodedOrientations, 0).x;\nivec2 location = ivec2(myIndex % orientationEncoderLength, myIndex / orientationEncoderLength);\nvec4 targetPixel = pixelAt(encodedOrientations, location);\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, myAddress);\nbool isValid = !isBadKeypoint(keypoint);\nfloat encodedOrientation = targetPixel.g;\ncolor = isValid && myAddress.offset == 1 ? vec4(pixel.r, encodedOrientation, pixel.ba) : pixel;\n}'},6187:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedData;\nuniform int strideOfEncodedData;\nuniform sampler2D encodedKeypoints;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\nvec4 readEncodedData(sampler2D encodedData, int strideOfEncodedData, int elementId, int pixelsPerElement, int pixelOffset)\n{\nint rasterIndex = elementId * pixelsPerElement + pixelOffset;\nivec2 pos = ivec2(rasterIndex % strideOfEncodedData, rasterIndex / strideOfEncodedData);\nreturn texelFetch(encodedData, pos, 0);\n}\nvoid main()\n{\nivec2 thread = threadLocation();\nKeypointAddress myAddress = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint myIndex = findKeypointIndex(myAddress, descriptorSize, extraSize);\nint headerSize = sizeofEncodedKeypointHeader();\nint extraCell = myAddress.offset - headerSize / 4;\nint numberOfExtraCells = extraSize / 4;\ncolor = threadPixel(encodedKeypoints);\nif(extraCell < 0 || extraCell >= numberOfExtraCells)\nreturn;\nKeypoint keypoint = decodeKeypoint(encodedKeypoints, encoderLength, myAddress);\nif(isBadKeypoint(keypoint))\nreturn;\ncolor = readEncodedData(encodedData, strideOfEncodedData, myIndex, numberOfExtraCells, extraCell);\n}'},477:e=>{e.exports='@include "keypoints.glsl"\nuniform sampler2D encodedKeypoints;\nuniform int startIndex;\nuniform int endIndex;\nuniform int descriptorSize;\nuniform int extraSize;\nuniform int encoderLength;\n#ifndef BUFFER_SIZE\n#error Undefined BUFFER_SIZE\n#endif\nlayout(std140) uniform KeypointBuffer\n{\nvec4 keypointBuffer[BUFFER_SIZE];\n};\nvoid main()\n{\nvec4 pixel = threadPixel(encodedKeypoints);\nivec2 thread = threadLocation();\nKeypointAddress address = findKeypointAddress(thread, encoderLength, descriptorSize, extraSize);\nint index = findKeypointIndex(address, descriptorSize, extraSize);\ncolor = pixel;\nif(index < startIndex)\nreturn;\ncolor = encodeNullKeypoint();\nif(index >= endIndex)\nreturn;\nvec4 data = keypointBuffer[index - startIndex];\nswitch(address.offset) {\ncase 0: {\ncolor = encodeKeypointPosition(data.xy);\nbreak;\n}\ncase 1: {\nvec2 score = encodeKeypointScore(max(data.w, 0.0f));\nfloat scale = encodeLod(data.z);\nfloat rotation = encodeKeypointOrientation(0.0f);\ncolor = vec4(scale, rotation, score);\nbreak;\n}\ndefault: {\ncolor = vec4(0.0f);\nbreak;\n}\n}\n}'},4050:e=>{e.exports="uniform sampler2D image;\nvoid main()\n{\n#if 1\ncolor = texture(image, texCoord);\n#else\nivec2 thread = threadLocation();\nivec2 pos = min(thread * 2, textureSize(image, 0) - ivec2(1));\ncolor = pixelAt(image, pos);\n#endif\n}"},5545:e=>{e.exports="uniform sampler2D image;\nvoid main()\n{\nivec2 thread = threadLocation();\nvec4 pixel = pixelAt(image, thread / 2);\ncolor = (((thread.x + thread.y) & 1) == 0) ? pixel : vec4(0.0f, 0.0f, 0.0f, pixel.a);\n}"},7113:e=>{e.exports='@include "subpixel.glsl"\nuniform sampler2D image0;\nuniform sampler2D image1;\nuniform float alpha;\nuniform float beta;\nuniform float gamma;\nconst vec4 BACKGROUND = vec4(0.0f);\nvoid main()\n{\nivec2 location = threadLocation();\nivec2 size0 = textureSize(image0, 0);\nivec2 size1 = textureSize(image1, 0);\nvec4 pix0 = all(lessThan(location, size0)) ? pixelAt(image0, location) : BACKGROUND;\nvec4 pix1 = all(lessThan(location, size1)) ? pixelAt(image1, location) : BACKGROUND;\nvec4 pix = clamp(alpha * pix0 + beta * pix1 + vec4(gamma), 0.0f, 1.0f);\ncolor = vec4(pix.rgb, 1.0f);\n}'},1202:e=>{e.exports='@include "subpixel.glsl"\nuniform sampler2D image;\nvoid main()\n{\nvec2 imageSize = vec2(textureSize(image, 0));\n#if !defined(INTERPOLATION_METHOD)\n#error Must define INTERPOLATION_METHOD\n#elif INTERPOLATION_METHOD == 0\nvec2 pos = texCoord * imageSize;\ncolor = textureLod(image, (round(pos) + vec2(0.5f)) / imageSize, 0.0f);\n#elif INTERPOLATION_METHOD == 1\ncolor = subpixelAtBI(image, texCoord * imageSize);\n#else\n#error Invalid INTERPOLATION_METHOD\n#endif\n}'},7971:e=>{e.exports='@include "subpixel.glsl"\nuniform sampler2D image;\nuniform mat3 inverseHomography;\nconst vec4 emptyColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);\nvec2 perspectiveWarp(mat3 homography, vec2 p)\n{\nvec3 q = homography * vec3(p, 1.0f);\nreturn q.xy / q.z;\n}\nvoid main()\n{\nivec2 location = threadLocation();\nivec2 size = outputSize();\nconst vec2 zero = vec2(0.0f);\nvec2 target = perspectiveWarp(inverseHomography, vec2(location));\nbool withinBounds = all(bvec4(greaterThanEqual(target, zero), lessThan(target, vec2(size))));\ncolor = withinBounds ? subpixelAtBI(image, target) : emptyColor;\n}'},6122:e=>{e.exports='@include "colors.glsl"\nuniform sampler2D dest, src;\nuniform int destComponents;\nuniform int srcComponentId;\nvoid main()\n{\nvec4 destPixel = threadPixel(dest);\nvec4 srcPixel = threadPixel(src);\nbvec4 flags = bvec4(\n(destComponents & PIXELCOMPONENT_RED) != 0,\n(destComponents & PIXELCOMPONENT_GREEN) != 0,\n(destComponents & PIXELCOMPONENT_BLUE) != 0,\n(destComponents & PIXELCOMPONENT_ALPHA) != 0\n);\ncolor = mix(destPixel, vec4(srcPixel[srcComponentId]), flags);\n}'},371:e=>{e.exports='#if !defined(TYPE)\n#error Undefined TYPE\n#elif TYPE == 1\n@include "keypoints.glsl"\n#define nullPixel() encodeNullKeypoint()\n#elif TYPE == 2\n@include "float16.glsl"\n#define nullPixel() encodeNullPairOfFloat16()\n#else\n#error Invalid TYPE\n#endif\nuniform sampler2D image;\nvoid main()\n{\nivec2 thread = threadLocation();\nivec2 imageSize = textureSize(image, 0);\nint rasterIndex = thread.y * outputSize().x + thread.x;\nbool isValidPixel = rasterIndex < imageSize.x * imageSize.y;\nivec2 pos = ivec2(rasterIndex % imageSize.x, rasterIndex / imageSize.x);\nvec4 nullpix = nullPixel();\ncolor = isValidPixel ? texelFetch(image, pos, 0) : nullpix;\n}'},7307:e=>{e.exports="uniform sampler2D image;\nvoid main()\n{\ncolor = threadPixel(image);\n}"},8614:e=>{e.exports='@include "colors.glsl"\nuniform sampler2D image;\nuniform int pixelComponents;\nuniform float value;\nvoid main()\n{\nvec4 pixel = threadPixel(image);\nbvec4 flags = bvec4(\n(pixelComponents & PIXELCOMPONENT_RED) != 0,\n(pixelComponents & PIXELCOMPONENT_GREEN) != 0,\n(pixelComponents & PIXELCOMPONENT_BLUE) != 0,\n(pixelComponents & PIXELCOMPONENT_ALPHA) != 0\n);\ncolor = mix(pixel, vec4(value), flags);\n}'},6271:e=>{e.exports="uniform float value;\nvoid main()\n{\ncolor = vec4(value);\n}"},3016:e=>{e.exports="void vsmain()\n{\ngl_Position *= vec4(1,-1,1,1);\n}"},3630:e=>{e.exports="uniform sampler2D image;\nuniform int iterationNumber;\nvoid main()\n{\nivec2 thread = threadLocation();\nivec2 last = outputSize() - ivec2(1);\nint jump = (1 << iterationNumber);\nint clusterLength = jump << 1;\nint clusterMask = clusterLength - 1;\nivec2 clusterPos = ivec2(thread >> (1 + iterationNumber)) << (1 + iterationNumber);\nivec2 next1 = clusterPos + ((thread - clusterPos + ivec2(jump, 0)) & clusterMask);\nivec2 next2 = clusterPos + ((thread - clusterPos + ivec2(0, jump)) & clusterMask);\nivec2 next3 = clusterPos + ((thread - clusterPos + ivec2(jump, jump)) & clusterMask);\nvec4 p0 = texelFetch(image, thread, 0);\nvec4 p1 = texelFetch(image, min(next1, last), 0);\nvec4 p2 = texelFetch(image, min(next2, last), 0);\nvec4 p3 = texelFetch(image, min(next3, last), 0);\nvec4 pmax = max(max(p0, p1), max(p2, p3));\nvec4 pmin = min(min(p0, p1), min(p2, p3));\ncolor = vec4(pmax.r, pmin.g, pmax.r - pmin.g, p0.a);\n}"},8508:e=>{e.exports='@include "pyramids.glsl"\n@include "float16.glsl"\nuniform sampler2D pyramid;\nuniform float lod;\n#define USE_VARYINGS 1\nin vec2 v_pix0, v_pix1, v_pix2,\nv_pix3, v_pix4, v_pix5,\nv_pix6, v_pix7, v_pix8;\nconst mat3 hkern = mat3(\n1.0f, 0.0f,-1.0f,\n2.0f, 0.0f,-2.0f,\n1.0f, 0.0f,-1.0f\n), vkern = mat3(\n1.0f, 2.0f, 1.0f,\n0.0f, 0.0f, 0.0f,\n-1.0f,-2.0f,-1.0f\n);\n#define PIX(x,y) pyrPixelAtOffset(pyramid, lod, pot, ivec2((x),(y))).g\n#define XIP(v) textureLod(pyramid, (v), lod).g\nvoid main()\n{\nconst vec3 ones = vec3(1.0f);\nfloat pot = exp2(lod);\nmat3 win = mat3(\n#if USE_VARYINGS\nXIP(v_pix0), XIP(v_pix1), XIP(v_pix2),\nXIP(v_pix3), XIP(v_pix4), XIP(v_pix5),\nXIP(v_pix6), XIP(v_pix7), XIP(v_pix8)\n#else\nPIX(-1,-1), PIX(0,-1), PIX(1,-1),\nPIX(-1,0), PIX(0,0), PIX(1,0),\nPIX(-1,1), PIX(0,1), PIX(1,1)\n#endif\n);\nmat3 dx = matrixCompMult(hkern, win);\nmat3 dy = matrixCompMult(vkern, win);\nvec2 df = vec2(\ndot(dx[0] + dx[1] + dx[2], ones),\ndot(dy[0] + dy[1] + dy[2], ones)\n);\ncolor = encodePairOfFloat16(df);\n}'},8073:e=>{e.exports="uniform mediump float lod;\nout vec2 v_pix0, v_pix1, v_pix2,\nv_pix3, v_pix4, v_pix5,\nv_pix6, v_pix7, v_pix8;\n#define PIX(x,y) (texCoord + ((pot) * vec2((x),(y))) / texSize)\nvoid vsmain()\n{\nfloat pot = exp2(lod);\nv_pix0 = PIX(-1,-1); v_pix1 = PIX(0,-1); v_pix2 = PIX(1,-1);\nv_pix3 = PIX(-1,0); v_pix4 = PIX(0,0);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BEECdEGfkYCA\nABCFgICAACEFAkACQCAEQQFIDQBBACEGIAUhBwNAIAcgAyAGakEBEJKAgIAANgIAIAdBBGohByAE\nIAZBf2oiBmoNAAsgAyAEIAUgASACEK2AgIAAIAMgBCAFIAAQroCAgAAgBEEBaiEHIARBAnQgBWpB\nfGohBgNAIAYoAgAQl4CAgAAaIAZBfGohBiAHQX9qIgdBAUoNAAwCCwsgAyAEIAUgASACEK2AgIAA\nIAMgBCAFIAAQroCAgAALIAVBlZKAgAAQh4CAgAAaC5AEAgl/An0CQCAAIAFODQBBupGAgAAQgICA\ngAALAkACQCAEKAIIIABHDQAgBCgCDCABRw0AIAMoAgggAEcNACADKAIMIAFGDQELQdiRgIAAEICA\ngIAACxCWgICAACEFEJaAgIAAIQYQloCAgAAhBxCWgICAACEIIABBAWoiCSABQQFqIgoQkoCAgAAh\nCyAJIAoQkoCAgAAhDCADIAQQlYCAgAAaAkAgAUEBSA0AIAFBf2ohDSAAQX9qIQpBACEAA0AgBSAD\nIAAgCiAAIAAQmoCAgAAiBCgCACoCACEOIAIoAgAgBBCVgICAABogBBCrgICAACEPIAIoAgAiBCgC\nACIJIA8gDkMAAAAAYCAOQwAAAABda7KUIAkqAgCSOAIAAkAgBBCrgICAACIOi7tEje21oPfGsD5j\nDQAgAigCACIEIARDAACAPyAOlRCggICAABogBiADIAAgCiAAIA0QmoCAgAAhBCAHIAtBASACKAIA\nKAIMQQEgBCgCDBCagICAACACKAIAIAQQpoCAgAAhCSAEIAggDEEBIAIoAgAoAghBASAEKAIMEJqA\ngIAAIAIoAgAgCRCpgICAAEMAAADAEKiAgIAAGgsgAkEEaiECIAEgAEEBaiIARw0ACwsgDBCXgICA\nABogCxCXgICAABogCBCXgICAABogBxCXgICAABogBhCXgICAABogBRCXgICAABoL8gICCH8BfQJA\nAkAgAygCCCAARw0AIAMoAgwiBCAARg0BIAQgAUYNAQtB9pGAgAAQgICAgAALEJaAgIAAIQUQloCA\ngAAhBiADEJyAgIAAGgJAIA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.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";n.d(i,{default:()=>Vi});var e=n(1001),t=n(9037),s=n(2199),r=n(9192);const o=[],a=[],A="asap"+Math.random().toString(36).substr(1);function c(e,...t){o.unshift(e),a.unshift(t),window.postMessage(A,"*")}window.addEventListener("message",(e=>{if(e.source!==window||e.data!==A)return;if(e.stopPropagation(),0==o.length)return;const t=o.pop(),n=a.pop();t.apply(void 0,n)}),!0);var l=n(8581);const d=navigator.userAgent.includes("Firefox")?(e,...t)=>setTimeout(e,10,...t):(e,...t)=>requestAnimationFrame((()=>e.apply(void 0,t)));class h{constructor(e=2){t.A.assert(e>0),this._initialized=!1,this._pixelBuffer=new Array(e).fill(null).map((()=>new Uint8Array(0))),this._pbo=new Array(e).fill(null),this._consumerIndex=0,this._producerIndex=e-1,this._promise=Array.from({length:e},(()=>r.i.resolve())),this._busy=new Array(e).fill(!1),this._ready=new Array(e).fill(!0)}init(e){this._allocatePBOs(e),e.subscribe(this._allocatePBOs,this,e),this._initialized=!0}release(e){return e.unsubscribe(this._allocatePBOs,this),this._deallocatePBOs(e),this._initialized=!1,null}readPixelsSync(e,n=0,i=0,s=e.width,r=e.height){t.A.assert(this._initialized);const o=e.gl,a=e.glFbo;s=Math.max(0,Math.min(s,e.width)),r=Math.max(0,Math.min(r,e.height)),n=Math.max(0,Math.min(n,e.width-s)),i=Math.max(0,Math.min(i,e.height-r));const A=s*r*4;return this._reallocate(A),o.isContextLost()||(o.bindFramebuffer(o.FRAMEBUFFER,a),o.readPixels(n,i,s,r,o.RGBA,o.UNSIGNED_BYTE,this._pixelBuffer[0]),o.bindFramebuffer(o.FRAMEBUFFER,null)),this._pixelBuffer[0].subarray(0,A)}readPixelsAsync(e,n=0,i=0,s=e.width,o=e.height,a=!1){t.A.assert(this._initialized);const A=e.gl,c=e.glFbo;s=Math.max(0,Math.min(s,e.width)),o=Math.max(0,Math.min(o,e.height)),n=Math.max(0,Math.min(n,e.width-s)),i=Math.max(0,Math.min(i,e.height-o));const l=s*o*4;if(this._reallocate(l),A.isContextLost())return r.i.resolve(this._pixelBuffer[0].subarray(0,l));if(!a){const e=this._pixelBuffer[0].subarray(0,l);return h._readPixelsViaPBO(A,this._pbo[0],e,c,n,i,s,o).then((()=>e))}const d=this._pixelBuffer.length,p=this._producerIndex;if(!this._busy[p]){const e=this._pbo[p],t=this._pixelBuffer[p].subarray(0,l);this._producerIndex=(p+1)%d,this._ready[p]=!1,this._busy[p]=!0,this._promise[p]=h._readPixelsViaPBO(A,e,t,c,n,i,s,o).then((()=>{this._busy[p]=!1,this._ready[p]=!0}))}const u=this._consumerIndex;return this._consumerIndex=(u+1)%d,this._ready[u]?(this._ready[u]=!1,r.i.resolve(this._pixelBuffer[u])):this._promise[u].then((()=>(this._ready[u]=!1,this._pixelBuffer[u])))}_reallocate(e){if(!(e<=this._pixelBuffer[0].byteLength))for(let t=0;t<this._pixelBuffer.length;t++){const n=new Uint8Array(e);this._pixelBuffer[t]=n}}_allocatePBOs(e){const t=e.gl;for(let e=0;e<this._pbo.length;e++)this._pbo[e]=t.createBuffer()}_deallocatePBOs(e){const t=e.gl;for(let e=this._pbo.length-1;e>=0;e--)t.deleteBuffer(this._pbo[e]),this._pbo[e]=null}static _readPixelsViaPBO(e,n,i,o,a,A,p,u){const g=p*u*4;t.A.assert(i.byteLength>=g,"Invalid buffer size"),e.bindBuffer(e.PIXEL_PACK_BUFFER,n),e.bufferData(e.PIXEL_PACK_BUFFER,g,e.DYNAMIC_READ),e.bindFramebuffer(e.FRAMEBUFFER,o),e.readPixels(a,A,p,u,e.RGBA,e.UNSIGNED_BYTE,0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindBuffer(e.PIXEL_PACK_BUFFER,null);const f=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new r.i(((t,n)=>{"asap"!=s.w.gpuPollingMode?d(h._clientWaitAsync,e,f,0,t,n):c(h._clientWaitAsync,e,f,0,t,n)})).then((()=>{e.bindBuffer(e.PIXEL_PACK_BUFFER,n),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)})).catch((e=>{throw new l.Er("Can't getBufferSubDataAsync(): error in clientWaitAsync()",e)})).finally((()=>{e.deleteSync(f)}))}static _clientWaitAsync(e,t,n,i,r,o=10,a=1e3){!function o(){const A=e.clientWaitSync(t,n,0);a--<=0?r(new l.MU("GPU polling timeout",l.wB.from(e))):A===e.CONDITION_SATISFIED||A===e.ALREADY_SIGNALED?i():"asap"!=s.w.gpuPollingMode?requestAnimationFrame(o):c(o)}()}}var p=n(3816);class u{constructor(e,t,n,i=e.RGBA,s=e.RGBA8,r=e.UNSIGNED_BYTE,o=e.NEAREST,a=e.MIRRORED_REPEAT){this._gl=e,this._width=Math.max(1,0|t),this._height=Math.max(1,0|n),this._hasMipmaps=!1,this._format=i,this._internalFormat=s,this._dataType=r,this._filter=o,this._wrap=a,this._glTexture=u._createTexture(this._gl,this._width,this._height,this._format,this._internalFormat,this._dataType,this._filter,this._wrap)}release(){const e=this._gl;if(null==this._glTexture)throw new l.Er("The SpeedyTexture has already been released");return this.discardMipmaps(),e.deleteTexture(this._glTexture),this._glTexture=null,this._width=this._height=0,null}upload(e,n=this._width,i=this._height){const s=this._gl;return e instanceof HTMLVideoElement&&e.readyState<2||(t.A.assert(n>0&&i>0),this.discardMipmaps(),this._width=n,this._height=i,this._internalFormat=s.RGBA8,this._format=s.RGBA,this._dataType=s.UNSIGNED_BYTE,u._upload(s,this._glTexture,this._width,this._height,e,0,this._format,this._internalFormat,this._dataType)),this}clear(){const e=this._gl;return e.isContextLost()||(e.bindTexture(e.TEXTURE_2D,this._glTexture),e.texImage2D(e.TEXTURE_2D,0,this._internalFormat,this._width,this._height,0,this._format,this._dataType,null),e.bindTexture(e.TEXTURE_2D,null),this.discardMipmaps()),this}resize(e,t){const n=this._gl;if(this._width===e&&this._height===t)return this;if(t|=0,(e|=0)>p.MAX_TEXTURE_LENGTH||t>p.MAX_TEXTURE_LENGTH)throw new l.EM(`Maximum texture size exceeded. Using ${e} x ${t}, expected up to ${p.MAX_TEXTURE_LENGTH} x ${p.MAX_TEXTURE_LENGTH}.`);if(e<1||t<1)throw new l.qw(`Invalid texture size: ${e} x ${t}`);return n.isContextLost()||(this._width=e,this._height=t,n.bindTexture(n.TEXTURE_2D,this._glTexture),n.texImage2D(n.TEXTURE_2D,0,this._internalFormat,this._width,this._height,0,this._format,this._dataType,null),n.bindTexture(n.TEXTURE_2D,null),this.discardMipmaps()),this}generateMipmaps(e=[]){const n=this._gl;if(this._hasMipmaps)return this;if(n.bindTexture(n.TEXTURE_2D,this._glTexture),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST_MIPMAP_LINEAR),n.generateMipmap(n.TEXTURE_2D),n.bindTexture(n.TEXTURE_2D,null),e.length>0){const n=this.width,i=this.height,s=1+Math.floor(Math.log2(Math.max(n,i)));t.A.assert(e.length<=s);for(let s=1;s<e.length;s++){const r=Math.max(1,n>>>s),o=Math.max(1,i>>>s);t.A.assert(e[s].width===r&&e[s].height===o),e[s].copyTo(this,s)}}return this._hasMipmaps=!0,this}discardMipmaps(){const e=this._gl;this._hasMipmaps&&(e.bindTexture(e.TEXTURE_2D,this._glTexture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,this._filter),e.bindTexture(e.TEXTURE_2D,null),this._hasMipmaps=!1)}hasMipmaps(){return this._hasMipmaps}isReleased(){return null==this._glTexture}get glTexture(){return this._glTexture}get width(){return this._width}get height(){return this._height}get gl(){return this._gl}static _createTexture(e,n,i,s,r,o,a,A){t.A.assert(n>0&&i>0);const c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,A),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,A),e.texImage2D(e.TEXTURE_2D,0,r,n,i,0,s,o,null),e.bindTexture(e.TEXTURE_2D,null),c}static _upload(e,t,n,i,s,r,o,a,A){return e.bindTexture(e.TEXTURE_2D,t),e.texImage2D(e.TEXTURE_2D,r,a,n,i,0,o,A,s),e.bindTexture(e.TEXTURE_2D,null),t}}class g extends u{constructor(e,t,n,i=void 0,s=void 0,r=void 0,o=void 0,a=void 0){super(e,t,n,i,s,r,o,a),this._glFbo=g._createFramebuffer(e,this._glTexture)}release(){const e=this._gl;if(null==this._glFbo)throw new l.Er("The SpeedyDrawableTexture has already been released");return e.deleteFramebuffer(this._glFbo),this._glFbo=null,super.release()}get glFbo(){return this._glFbo}copyTo(e,n=0){const i=this._gl;if(i.isContextLost())return;const s=1<<(n|=0),r=Math.max(1,Math.floor(e.width/s)),o=Math.max(1,Math.floor(e.height/s));t.A.assert(this._width===r&&this._height===o),g._copyToTexture(i,this._glFbo,e.glTexture,0,0,this._width,this._height,n)}clear(){return this.clearToColor(0,0,0,0)}clearToColor(e,t,n,i){const s=this._gl;return s.isContextLost()||(e=Math.max(0,Math.min(+e,1)),t=Math.max(0,Math.min(+t,1)),n=Math.max(0,Math.min(+n,1)),i=Math.max(0,Math.min(+i,1)),this.discardMipmaps(),s.bindFramebuffer(s.FRAMEBUFFER,this._glFbo),s.viewport(0,0,this._width,this._height),s.clearColor(e,t,n,i),s.clear(s.COLOR_BUFFER_BIT),s.bindFramebuffer(s.FRAMEBUFFER,null)),this}inspect(e,t){if(void 0===t){(t=new h).init(e);const n=t.readPixelsSync(this);return t.release(e),new Uint8Array(n)}{const e=t.readPixelsSync(this);return new Uint8Array(e)}}inspect32(e,n){return t.A.assert(p.LITTLE_ENDIAN),new Uint32Array(this.inspect(e,n).buffer)}static _createFramebuffer(e,t){const n=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0);const i=e.checkFramebufferStatus(e.FRAMEBUFFER);if(i!=e.FRAMEBUFFER_COMPLETE){const t=["FRAMEBUFFER_UNSUPPORTED","FRAMEBUFFER_INCOMPLETE_ATTACHMENT","FRAMEBUFFER_INCOMPLETE_DIMENSIONS","FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT","FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"].filter((t=>e[t]===i))[0]||"unknown error";throw new l.wB(`Can't create framebuffer: ${t} (${i})`)}return e.bindFramebuffer(e.FRAMEBUFFER,null),n}static _copyToTexture(e,t,n,i,s,r,o,a=0){return e.bindTexture(e.TEXTURE_2D,n),e.bindFramebuffer(e.FRAMEBUFFER,t),e.copyTexSubImage2D(e.TEXTURE_2D,a,0,0,i,s,r,o),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),n}}var f=n(9420);const I=Object.freeze({sampler2D:"uniform1i",isampler2D:"uniform1i",usampler2D:"uniform1i",float:"uniform1f",int:"uniform1i",uint:"uniform1ui",bool:"uniform1i",vec2:"uniform2f",vec3:"uniform3f",vec4:"uniform4f",ivec2:"uniform2i",ivec3:"uniform3i",ivec4:"uniform4i",uvec2:"uniform2ui",uvec3:"uniform3ui",uvec4:"uniform4ui",bvec2:"uniform2i",bvec3:"uniform3i",bvec4:"uniform4i",mat2:"uniformMatrix2fv",mat3:"uniformMatrix3fv",mat4:"uniformMatrix4fv"});class m extends Function{constructor(e,t,n={}){return super("...args","return this._self._call(...args)"),this._self=this.bind(this),this._self._init(e,t,n),this._self}_init(e,t,n){if(e.isContextLost())throw new l.Er("Can't initialize SpeedyProgram: lost context");n=Object.assign({renderToTexture:!0,pingpong:!1},n),this._gl=e,this._program=m._compile(e,t.vertexSource,t.fragmentSource),this._geometry=new _(e,{position:t.locationOfAttributes.position,texCoord:t.locationOfAttributes.texCoord}),this._argnames=t.arguments,this._argIsArray=new Array(this._argnames.length).fill(!1),this._ubo=null,this._renderToTexture=Boolean(n.renderToTexture),this._width=1,this._height=1,this._size=[1,1],this._texture=new Array(n.pingpong?2:1).fill(null),this._textureIndex=0,this._uniform=new Map,this._shaderdecl=t,e.useProgram(this._program);for(const n of t.uniforms){const i=t.uniformType(n),s=e.getUniformLocation(this._program,n);this._uniform.set(n,new y(i,s))}for(let e=0;e<this._argnames.length;e++){const t=this._argnames[e];if(!this._uniform.has(t)&&(this._argIsArray[e]=this._uniform.has(C(t,0)),!this._argIsArray[e]))throw new l.Er(`Expected uniform "${t}", as declared in the argument list`)}}_call(...e){const t=this._gl,n=this._argnames,i=this._texture[this._textureIndex];if(e.length!=n.length)throw new l.qw(`Can't run shader: incorrect number of arguments (expected ${n.length}, got ${e.length})`);for(let t=e.length-1;t>=0;t--)if(e[t]===i)throw new l.EM("Can't run shader: don't use its output texture as an input to itself. Consider using pingpong rendering!");if(t.isContextLost())return i;t.useProgram(this._program),t.bindVertexArray(this._geometry.vao);const s=this._renderToTexture?i.glFbo:null,r=this._uniform.get("texSize");this._size[0]=this._width,this._size[1]=this._height,r.setValue(t,this._size);for(let i=0,s=0;i<e.length;i++){const r=n[i];if(this._argIsArray[i]){const n=e[i];if(!Array.isArray(n))throw new l.qw(`Can't run shader: expected an array for "${r}"`);if(this._uniform.has(C(r,n.length)))throw new l.qw(`Can't run shader: too few elements in the "${r}" array`);for(let e,i=0;void 0!==(e=this._uniform.get(C(r,i)));i++)s=e.setValue(t,n[i],s)}else s=this._uniform.get(r).setValue(t,e[i],s)}return null!==this._ubo&&this._ubo.update(),t.bindFramebuffer(t.FRAMEBUFFER,s),t.viewport(0,0,this._width,this._height),t.drawArrays(t.TRIANGLES,0,6),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindVertexArray(null),null!=i&&i.discardMipmaps(),this._pingpong(),i}outputs(e,t,...n){return this._setOutputTexture(...n),this._setOutputSize(e,t),this}_setOutputSize(e,n){t.A.assert(e>0&&n>0),this._width=0|e,this._height=0|n;for(let e=0;e<this._texture.length;e++)null!=this._texture[e]&&this._texture[e].resize(this._width,this._height);return this}_setOutputTexture(...e){t.A.assert(e.length===this._texture.length,`Incorrect number of textures (expected ${this._texture.length})`);for(let t=0;t<this._texture.length;t++)this._texture[t]=e[t];return this._textureIndex=0,this}clear(){const e=this._texture[this._textureIndex];for(let e=0;e<this._texture.length;e++)this._texture[e].clear();return this._pingpong(),e}setUBO(e,t){return null===this._ubo&&(this._ubo=new x(this._gl,this._program)),this._ubo.set(e,t),this}release(){const e=this._gl;return null!=this._ubo&&(this._ubo=this._ubo.release()),this._texture.fill(null),this._geometry=this._geometry.release(),e.deleteProgram(this._program),this._program=null,null}definedConstant(e){return this._shaderdecl.definedConstant(e)}_pingpong(){this._texture.length>1&&(this._textureIndex=1-this._textureIndex)}static _compile(e,t,n){const i=e.createProgram(),s=e.createShader(e.VERTEX_SHADER),r=e.createShader(e.FRAGMENT_SHADER);if(e.shaderSource(s,t),e.compileShader(s),e.attachShader(i,s),e.shaderSource(r,n),e.compileShader(r),e.attachShader(i,r),e.linkProgram(i),e.validateProgram(i),e.getProgramParameter(i,e.LINK_STATUS))return i;const o=[e.getShaderInfoLog(r),e.getShaderInfoLog(s),e.getProgramInfoLog(i)];e.deleteProgram(i),e.deleteShader(r),e.deleteShader(s);const a=e=>{return new Array((t=e,Math.max(0,2-Math.floor(Math.log10(t))))).fill(" ").join("")+e+". ";var t},A=(o[0]?n:t).split("\n").map(((e,t)=>a(1+t)+e)).join("\n");throw new l.wB("\n\n---------- ERROR ----------\n\n"+o.filter((e=>e)).join("\n")+"\n\n---------- SOURCE CODE ----------\n\n"+A+"\n")}}function _(e,t){return this.vao=e.createVertexArray(),this.vbo=Object.freeze({position:e.createBuffer(),texCoord:e.createBuffer()}),this._gl=e,e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vbo.position),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(t.position),e.vertexAttribPointer(t.position,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.vbo.texCoord),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(t.texCoord),e.vertexAttribPointer(t.texCoord,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindVertexArray(null),Object.freeze(this)}function y(e,t){if(this.type=String(e),!Object.prototype.hasOwnProperty.call(I,this.type))throw new l.EM(`Unsupported uniform type: ${this.type}`);this.location=t,this.setter=I[this.type];const n=0|Number(this.setter.match(/^uniform(Matrix)?(\d)/)[2]);this.dim=this.type.startsWith("mat")?2:this.type.indexOf("vec")>=0?1:0,this.length=2==this.dim?n*n:n,this._value=null}function x(e,t){this._gl=e,this._program=t,this._nextIndex=0,this._ubo=Object.create(null)}function C(e,t){const n=C.cache;let i=n.get(e);return void 0===i&&n.set(e,i=[]),void 0===i[t]&&(i[t]=`${e}[${t}]`),i[t]}_.prototype.release=function(){const e=this._gl;return e.deleteVertexArray(this.vao),e.deleteBuffer(this.vbo.position),e.deleteBuffer(this.vbo.texCoord),null},y.prototype.setValue=function(e,t,n=-1){const i=e[this.setter];if("object"==typeof t&&this.type.endsWith("sampler2D")){if(n>=e.MAX_COMBINED_TEXTURE_IMAGE_UNITS)throw new l.EM(`Can't activate texture unit ${n}: max is ${e.MAX_COMBINED_TEXTURE_IMAGE_UNITS}`);if(Array.isArray(t))throw new l.EM("Can't pass arrays of textures to shaders");if(null==t)throw new l.qw(`Can't run shader: cannot use ${t} as an input texture`);if(n<0)throw new l.qw("Missing texNo");const i=t;e.activeTexture(e.TEXTURE0+n),e.bindTexture(e.TEXTURE_2D,i.glTexture),e.uniform1i(this.location,n),n++}else if(t===this._value&&"object"!=typeof t);else if("number"==typeof t||"boolean"==typeof t)i.call(e,this.location,t);else{if(!Array.isArray(t))throw new l.qw(`Can't run shader: unrecognized argument "${t}"`);if(t.length!==this.length)throw new l.qw(`Can't run shader: incorrect number of values for ${this.type}: "${t}"`);2==this.dim?i.call(e,this.location,!1,t):i.call(e,this.location,...t)}return this._value=t,n},x.prototype.set=function(e,t){const n=this._gl;void 0===this._ubo[e]&&(this._ubo[e]={buffer:n.createBuffer(),blockBindingIndex:this._nextIndex++,blockIndex:-1,data:null});const i=this._ubo[e];if(i.blockIndex<0){const t=n.getUniformBlockIndex(this._program,e);n.uniformBlockBinding(this._program,t,i.blockBindingIndex),i.blockIndex=t}i.data=t},x.prototype.update=function(){const e=this._gl;for(const t in this._ubo){const n=this._ubo[t];e.bindBuffer(e.UNIFORM_BUFFER,n.buffer),e.bufferData(e.UNIFORM_BUFFER,n.data,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,n.blockBindingIndex,n.buffer),e.bindBuffer(e.UNIFORM_BUFFER,null)}},x.prototype.release=function(){const e=this._gl;for(const t in this._ubo){const n=this._ubo[t];e.deleteBuffer(n.buffer),n.data=null}return null},C.cache=new Map;const E=Object.freeze({usesPingpongRendering:()=>({pingpong:!0}),rendersToCanvas:()=>({renderToTexture:!1})});class S{constructor(e){this._gpu=e,this._programs=[]}declare(e,t,n={}){return Object.defineProperty(this,e,{get:(()=>{const i=Symbol(e);return()=>this[i]||(this[i]=this._createProgram(t.build(),n))})()}),this}get program(){return E}release(){for(let e=0;e<this._programs.length;e++)this._programs[e].release();return null}_createProgram(e,t={}){const n=new m(this._gpu.gl,e,t);return this._programs.push(n),n}}const P=(0,f.bf)("utils/copy.glsl").withArguments("image"),v=(0,f.bf)("utils/copy-raster.glsl").withDefines({TYPE:1}).withArguments("image"),w=(0,f.bf)("utils/copy-raster.glsl").withDefines({TYPE:2}).withArguments("image"),B=(0,f.bf)("utils/copy.glsl","utils/flip-y.vs.glsl").withArguments("image"),b=(0,f.bf)("utils/fill.glsl").withArguments("value"),Q=(0,f.bf)("utils/fill-components.glsl").withArguments("image","pixelComponents","value"),M=(0,f.bf)("utils/copy-components.glsl").withArguments("dest","src","destComponents","srcComponentId"),D=(0,f.bf)("utils/scan-minmax2d.glsl").withArguments("image","iterationNumber"),k=(0,f.bf)("utils/sobel-derivatives.glsl","utils/sobel-derivatives.vs.glsl").withArguments("pyramid","lod");class K extends S{constructor(e){super(e),this.declare("renderToCanvas",B,Object.assign({},this.program.rendersToCanvas())).declare("copy",P).declare("copyKeypoints",v).declare("copy2DVectors",w).declare("fill",b).declare("fillComponents",Q).declare("copyComponents",M).declare("scanMinMax2D",D,Object.assign({},this.program.usesPingpongRendering())).declare("sobelDerivatives",k)}}var z=n(1672);const L=(0,f.bf)("filters/rgb2grey.glsl").withArguments("image"),T=[3,5,7].reduce(((e,t)=>(e[t]=(0,f.bf)("filters/convolution2d.glsl").withDefines({KERNEL_SIZE_SQUARED:t*t}).withArguments("image","kernel"),e)),{}),R=[3,5,7,9,11,13,15].reduce(((e,t)=>(e[t]=(0,f.bf)("filters/convolution1d.glsl").withDefines({KERNEL_SIZE:t,AXIS:0}).withArguments("image","kernel"),e)),{}),N=[3,5,7,9,11,13,15].reduce(((e,t)=>(e[t]=(0,f.bf)("filters/convolution1d.glsl").withDefines({KERNEL_SIZE:t,AXIS:1}).withArguments("image","kernel"),e)),{}),O=[3,5,7].reduce(((e,t)=>(e[t]=(0,f.bf)("filters/fast-median.glsl").withDefines({KERNEL_SIZE:t}).withArguments("image"),e)),{}),F=(0,f.bf)("filters/normalize-image.glsl").withDefines({GREYSCALE:1}).withArguments("minmax2d","minValue","maxValue"),X=(0,f.bf)("filters/normalize-image.glsl").withDefines({GREYSCALE:0}).withArguments("minmax2dRGB","minValue","maxValue"),U=(0,f.bf)("filters/nightvision.glsl").withDefines({GREYSCALE:0}).withArguments("image","illuminationMap","gain","offset","decay"),G=(0,f.bf)("filters/nightvision.glsl").withDefines({GREYSCALE:1}).withArguments("image","illuminationMap","gain","offset","decay"),q=e=>t.A.gaussianKernel((e=>Math.max(1,e/6))(e),e),H=e=>new Array(e).fill(1/e);class Y extends S{constructor(e){super(e),this.declare("rgb2grey",L).declare("median3",O[3]).declare("median5",O[5]).declare("median7",O[7]).declare("convolution3",T[3]).declare("convolution5",T[5]).declare("convolution7",T[7]).declare("convolution3x",R[3]).declare("convolution3y",N[3]).declare("convolution5x",R[5]).declare("convolution5y",N[5]).declare("convolution7x",R[7]).declare("convolution7y",N[7]).declare("convolution9x",R[9]).declare("convolution9y",N[9]).declare("convolution11x",R[11]).declare("convolution11y",N[11]).declare("convolution13x",R[13]).declare("convolution13y",N[13]).declare("convolution15x",R[15]).declare("convolution15y",N[15]).declare("normalizeGreyscale",F).declare("normalizeColored",X).declare("nightvision",U).declare("nightvisionGreyscale",G).declare("illuminationMapLoX",(0,z.convX)(t.A.gaussianKernel(80,31))).declare("illuminationMapLoY",(0,z.convY)(t.A.gaussianKernel(80,31))).declare("illuminationMapX",(0,z.convX)(t.A.gaussianKernel(80,63))).declare("illuminationMapY",(0,z.convY)(t.A.gaussianKernel(80,63))).declare("illuminationMapHiX",(0,z.convX)(t.A.gaussianKernel(80,255))).declare("illuminationMapHiY",(0,z.convY)(t.A.gaussianKernel(80,255))).declare("gaussian3x",(0,z.convX)([.25,.5,.25])).declare("gaussian3y",(0,z.convY)([.25,.5,.25])).declare("gaussian5x",(0,z.convX)([.05,.25,.4,.25,.05])).declare("gaussian5y",(0,z.convY)([.05,.25,.4,.25,.05])).declare("gaussian7x",(0,z.convX)(q(7))).declare("gaussian7y",(0,z.convY)(q(7))).declare("gaussian9x",(0,z.convX)(q(9))).declare("gaussian9y",(0,z.convY)(q(9))).declare("gaussian11x",(0,z.convX)(q(11))).declare("gaussian11y",(0,z.convY)(q(11))).declare("box3x",(0,z.convX)(H(3))).declare("box3y",(0,z.convY)(H(3))).declare("box5x",(0,z.convX)(H(5))).declare("box5y",(0,z.convY)(H(5))).declare("box7x",(0,z.convX)(H(7))).declare("box7y",(0,z.convY)(H(7))).declare("box9x",(0,z.convX)(H(9))).declare("box9y",(0,z.convY)(H(9))).declare("box11x",(0,z.convX)(H(11))).declare("box11y",(0,z.convY)(H(11)))}}var J=n(6634);class W extends J.Q{static create(e,n,i){t.A.assert(i%4==0,`Invalid descriptorSize: ${i}`);const s=n.length,r=i/4,o=Math.log2(r*Math.max(s,1))/2,a=1<<Math.min(11,Math.ceil(o)),A=a,c=a,d=A*c/r;if(s>d)throw new l.EM(`The capacity of the descriptorDB (${d} for ${8*i}-bit descriptors) has been exceeded`);const h=new Uint8Array(A*c*4);for(let e=0;e<s;e++){const s=e*i,r=n[e];t.A.assert(r.byteLength===i),t.A.assert(s+i<=h.byteLength),h.set(r,s)}const p=s*i;return t.A.log(`Creating a ${A}x${c} database of ${s} `+8*i+"-bit descriptors "+`(total size: ${(p/1048576).toFixed(2)} MB)`),e.resize(A,c),e.upload(h),e}}const j=[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],Z=[10,11,12,13,14,15,16,17,18,19,20],$=[32,64],V=Math.max(...Z),ee=Math.max(...j),te=e=>(t.A.range(ee).forEach((t=>e.subarray(t*V,(t+1)*V).sort())),e),ne=(e,n)=>(t.A.range(ee).forEach((t=>n.subarray((t+1)*V-e,(t+1)*V).fill(195939070))),n),ie=Z.reduce(((e,n)=>{return e[n]={32:te(ne(V-(i=n),new Uint32Array([...t.A.shuffle(t.A.range(256)),...t.A.shuffle(t.A.range(256)),...t.A.shuffle(t.A.range(256))].slice(0,ee*V)))),64:te(ne(V-i,new Uint32Array([...t.A.shuffle(t.A.range(512)),...t.A.shuffle(t.A.range(512))].slice(0,ee*V))))},e;var i}),{});class se{constructor(e,n,i,s=8,r=15,o=.95){const a=i.length,A=a>0?i[0].byteLength:0,c=(l=s,d=r,h=o,Z.includes(d)&&j.includes(l)?[{name:"x-small",bucketCapacity:1,tableCount:l,hashSize:d,capacity:oe(d,1,h)},{name:"small",bucketCapacity:2,tableCount:l,hashSize:d,capacity:oe(d,2,h)},{name:"small-plus",bucketCapacity:3,tableCount:l,hashSize:d,capacity:oe(d,3,h)},{name:"medium",bucketCapacity:4,tableCount:l,hashSize:d,capacity:oe(d,4,h)},{name:"medium-plus",bucketCapacity:5,tableCount:l,hashSize:d,capacity:oe(d,5,h)},{name:"large",bucketCapacity:6,tableCount:l,hashSize:d,capacity:oe(d,6,h)},{name:"x-large",bucketCapacity:8,tableCount:l,hashSize:d,capacity:oe(d,8,h)}]:null);var l,d,h;t.A.assert(a>0,"Can't build LSH tables without descriptors!"),t.A.assert($.includes(A),`Can't build LSH tables: unacceptable descriptor size of ${A} bytes`),t.A.assert(i.findIndex((e=>e.byteLength!==A))<0,`Can't build LSH tables: incorrectly sized descriptors. Expected ${A} bytes for each`),t.A.assert(a<p.MATCH_MAX_INDEX,`Can't build LSH tables: too many descriptors (${i.length})`),t.A.assert(null!=c,`Can't build LSH tables: unacceptable number of tables (${s}) x hash size (${r})`),this._profile=c.find((e=>a<=e.capacity))||c[c.length-1],this._descriptorSize=A,this._descriptorCount=a,this._sequences=this._pickSequences(this._descriptorSize),this._tables=this._createStaticTables(e,this._sequences,i,A),this._descriptorDB=W.create(n,i,A)}get descriptorSize(){return this._descriptorSize}get descriptorCount(){return this._descriptorCount}get sequences(){return this._sequences}get hashSize(){return this._profile.hashSize}get bucketCapacity(){return this._profile.bucketCapacity}get bucketsPerTable(){return 1<<this._profile.hashSize}get tableCount(){return this._profile.tableCount}get tableSize(){return this.bucketsPerTable*this.bucketCapacity*4}get totalSize(){return this.tableCount*this.tableSize}get tables(){return this._tables}get descriptorDB(){return this._descriptorDB}_pickSequences(e){return t.A.assert(Object.prototype.hasOwnProperty.call(ie,this.hashSize)),t.A.assert(Object.prototype.hasOwnProperty.call(ie[this.hashSize],e)),ie[this.hashSize][e]}_createStaticTables(e,n,i,s){const r=4294967295,o=this._profile.name,a=this._profile.capacity,A=this.tableCount,c=this.bucketsPerTable,l=4*this.bucketCapacity,d=this.hashSize,h=this.tableCount*this.bucketsPerTable*this.bucketCapacity,p=Math.min((u=Math.sqrt(h))>1?1<<Math.ceil(Math.log2(u)):1,4096);var u;const g=Math.ceil(h/p),f=i.length;t.A.assert(d<=V),t.A.assert(A<=ee),t.A.assert(h<=p*g);const I=1048576;if(t.A.log(`Building ${A} ${o} LSH tables with ${f} ${8*s}-bit descriptors each and hashSize = ${d} bits (${p}x${g}, with ${(this.tableSize/I).toFixed(2)} MB per table and total size = ${(this.totalSize/I).toFixed(2)} MB), `),f>a){const e=100*f/a;t.A.warning(`There are too many descriptors (${f}) for a ${o} LSH table. That's ${e.toFixed(2)}% of its theoretical capacity. Consider increasing the hashSize (currently set to ${d}) or reducing the number of descriptors to avoid degradation.`)}const m=new ArrayBuffer(p*g*4),_=new Uint8Array(m).fill(255),y=new DataView(m),x=t.A.shuffle(t.A.range(f)),C=new Array(A).fill(0);for(let e=0;e<f;e++){const t=x[e],s=this._hashCodes(i[t],n);for(let e=0;e<A;e++){const n=e*c*l+s[e]*l;let i=r;for(let e=0;e<l;e+=4){const s=n+e;if(i=y.getUint32(s,!0),i==r){y.setUint32(s,t,!0);break}}i!=r&&C[e]++}}const E=C.reduce(((e,t)=>e+t),0),S=C.map((e=>100*e/f));return t.A.log(`When building ${A} ${o} LSH tables with ${f} ${8*s}-bit descriptors each and hashSize = ${d} bits, I got the following discard profile: `+S.map((e=>e.toFixed(2)+"%")).join(", ")+". "+`Average: ${(100*E/(A*f)).toFixed(2)}%. `+`Minimum: ${Math.min(...S).toFixed(2)}%. `+`Table capacity: ${a}.`),e.resize(p,g),e.upload(_),e}_hashCodes(e,n){const i=this.tableCount,s=this.hashSize,r=this.bucketsPerTable,o=new Array(i);t.A.assert(s<=V&&n.length>=V*i);for(let a=0;a<i;a++){const i=V*a;let A=0;for(let t=0;t<s;t++){let s=n[i+t],r=1<<(7&s);A=A<<1|!!(e[s>>>3]&r)}t.A.assert(A>=0&&A<r),o[a]=A}return o}}function re(e,t){const n=Math.exp(-e);let i=1,s=1,r=1;for(let n=1;n<=t;n++)i+=(r*=e)/(s*=n);return i*n}function oe(e,t,n=.99){const i=1<<e,s=t,r=n;let o=1,a=i*s,A=0,c=0;for(;o<a;)A=Math.floor((o+a)/2),c=re(A/i,s),c>r?o=A+1:a=A;return A}const ae=(0,f.bf)("keypoints/fast.glsl","keypoints/fast.vs.glsl").withDefines({FAST_TYPE:916}).withArguments("corners","pyramid","lod","threshold"),Ae=[1,3,5,7].reduce(((e,t)=>(e[t]=(0,f.bf)("keypoints/harris.glsl").withDefines({WINDOW_SIZE:t}).withArguments("corners","pyramid","derivatives","lod","lodStep","gaussian"),e)),{}),ce=(0,f.bf)("keypoints/score-findmax.glsl").withArguments("corners","iterationNumber"),le=(0,f.bf)("keypoints/harris-cutoff.glsl").withArguments("corners","maxScore","quality"),de=(0,f.bf)("keypoints/subpixel-refinement.glsl").withDefines({METHOD:0}).withArguments("pyramid","encodedKeypoints","descriptorSize","extraSize","encoderLength","maxIterations","epsilon"),he=(0,f.bf)("keypoints/subpixel-refinement.glsl").withDefines({METHOD:1}).withArguments("pyramid","encodedKeypoints","descriptorSize","extraSize","encoderLength","maxIterations","epsilon"),pe=(0,f.bf)("keypoints/subpixel-refinement.glsl").withDefines({METHOD:2}).withArguments("pyramid","encodedKeypoints","descriptorSize","extraSize","encoderLength","maxIterations","epsilon"),ue=(0,f.bf)("keypoints/subpixel-refinement.glsl").withDefines({METHOD:3}).withArguments("pyramid","encodedKeypoints","descriptorSize","extraSize","encoderLength","maxIterations","epsilon"),ge=(0,f.bf)("keypoints/refine-scale.glsl").withDefines({METHOD:0}).withArguments("pyramid","lodStep","encodedKeypoints","descriptorSize","extraSize","encoderLength"),fe=(0,f.bf)("keypoints/refine-scale.glsl").withDefines({METHOD:1}).withArguments("pyramid","lodStep","encodedKeypoints","descriptorSize","extraSize","encoderLength","threshold"),Ie=(0,f.bf)("keypoints/allocate-descriptors.glsl").withArguments("inputEncodedKeypoints","inputDescriptorSize","inputExtraSize","inputEncoderLength","outputDescriptorSize","outputExtraSize","outputEncoderLength"),me=(0,f.bf)("keypoints/allocate-extra.glsl").withArguments("inputEncodedKeypoints","inputDescriptorSize","inputExtraSize","inputEncoderLength","outputDescriptorSize","outputExtraSize","outputEncoderLength"),_e=(0,f.bf)("keypoints/transfer-to-extra.glsl").withArguments("encodedData","strideOfEncodedData","encodedKeypoints","descriptorSize","extraSize","encoderLength"),ye=(0,f.bf)("keypoints/orb-descriptor.glsl").withArguments("image","encodedCorners","extraSize","encoderLength"),xe=(0,f.bf)("keypoints/orb-orientation.glsl").withArguments("image","encodedKeypoints","descriptorSize","extraSize","encoderLength"),Ce=(0,f.bf)("keypoints/nonmax-suppression.glsl").withDefines({MULTISCALE:0}).withArguments("image","lodStep"),Ee=(0,f.bf)("keypoints/nonmax-suppression.glsl").withDefines({MULTISCALE:1}).withArguments("image","lodStep"),Se=(0,f.bf)("keypoints/nonmax-space.glsl").withArguments("corners"),Pe=(0,f.bf)("keypoints/nonmax-scale.glsl").withDefines({USE_LAPLACIAN:1}).withArguments("corners","pyramid","pyrLaplacian","lodStep"),ve=(0,f.bf)("keypoints/nonmax-scale.glsl").withDefines({USE_LAPLACIAN:0}).withArguments("corners","pyramid","lodStep"),we=(0,f.bf)("keypoints/laplacian.glsl").withArguments("corners","pyramid","lodStep","lodOffset"),Be=[3,5,7,9,11,13,15,17,19,21].reduce(((e,t)=>(e[t]=(0,f.bf)("keypoints/lk.glsl").withDefines({WINDOW_SIZE:t}).withArguments("encodedFlow","prevKeypoints","nextPyramid","prevPyramid","level","depth","numberOfIterations","discardThreshold","epsilon","descriptorSize","extraSize","encoderLength"),e)),{}),be=(0,f.bf)("keypoints/transfer-flow.glsl").withArguments("encodedFlow","encodedKeypoints","descriptorSize","extraSize","encoderLength"),Qe=(0,f.bf)("keypoints/knn-init.glsl").withDefines({ENCODE_FILTERS:0}),Me=(0,f.bf)("keypoints/knn-init.glsl").withDefines({ENCODE_FILTERS:1}),De=(0,f.bf)("keypoints/knn-transfer.glsl").withArguments("encodedMatches","encodedKthMatches","numberOfMatchesPerKeypoint","kthMatch"),ke=(0,f.bf)("keypoints/bf-knn.glsl").withDefines({DESCRIPTOR_SIZE:32,NUMBER_OF_KEYPOINTS_PER_PASS:16}).withArguments("encodedMatches","encodedFilters","matcherLength","dbEncodedKeypoints","dbDescriptorSize","dbExtraSize","dbEncoderLength","encodedKeypoints","descriptorSize","extraSize","encoderLength","passId"),Ke=(0,f.bf)("keypoints/bf-knn.glsl").withDefines({DESCRIPTOR_SIZE:64,NUMBER_OF_KEYPOINTS_PER_PASS:8}).withArguments("encodedMatches","encodedFilters","matcherLength","dbEncodedKeypoints","dbDescriptorSize","dbExtraSize","dbEncoderLength","encodedKeypoints","descriptorSize","extraSize","encoderLength","passId"),ze=(0,f.bf)("keypoints/knn-init.glsl").withDefines({ENCODE_FILTERS:0}),Le=(0,f.bf)("keypoints/knn-init.glsl").withDefines({ENCODE_FILTERS:1}),Te=$.reduce(((e,t)=>(e[t]=Z.reduce(((e,n)=>(e[n]=[0,1,2].reduce(((e,i)=>(e[i]=(0,f.bf)("keypoints/lsh-knn.glsl").withDefines({DESCRIPTOR_SIZE:t,HASH_SIZE:n,LEVEL:i,SEQUENCE_MAXLEN:V,SEQUENCE_COUNT:ee}).withArguments("candidates","filters","matcherLength","tables","descriptorDB","tableIndex","bucketCapacity","bucketsPerTable","tablesStride","descriptorDBStride","encodedKeypoints","descriptorSize","extraSize","encoderLength"),e)),{}),e)),{}),e)),{}),Re=(0,f.bf)("keypoints/knn-transfer.glsl").withArguments("encodedMatches","encodedKthMatches","numberOfMatchesPerKeypoint","kthMatch"),Ne=(0,f.bf)("keypoints/sort-keypoints.glsl").withDefines({STAGE:1}).withArguments("encodedKeypoints","descriptorSize","extraSize","encoderLength"),Oe=(0,f.bf)("keypoints/sort-keypoints.glsl").withDefines({STAGE:2}).withArguments("permutation","blockSize","dblLog2BlockSize"),Fe=(0,f.bf)("keypoints/sort-keypoints.glsl").withDefines({STAGE:3}).withArguments("permutation","maxKeypoints","encodedKeypoints","descriptorSize","extraSize"),Xe=(0,f.bf)("keypoints/mix-keypoints.glsl").withDefines({STAGE:1}).withArguments("encodedKeypointsA","encodedKeypointsB","encoderLengthA","encoderLengthB","encoderCapacityA","encoderCapacityB","descriptorSize","extraSize","encoderLength"),Ue=(0,f.bf)("keypoints/mix-keypoints.glsl").withDefines({STAGE:2}).withArguments("encodedKeypoints","descriptorSize","extraSize","encoderLength","maxKeypoints"),Ge=(0,f.bf)("keypoints/mix-keypoints.glsl").withDefines({STAGE:3}).withArguments("array","blockSize"),qe=(0,f.bf)("keypoints/mix-keypoints.glsl").withDefines({STAGE:5}).withArguments("array"),He=(0,f.bf)("keypoints/mix-keypoints.glsl").withDefines({STAGE:4}).withArguments("array","encodedKeypoints","descriptorSize","extraSize","encoderLength"),Ye=(0,f.bf)("keypoints/lookup-of-locations.glsl").withDefines({FS_OUTPUT_TYPE:2,STAGE:1}).withArguments("corners"),Je=(0,f.bf)("keypoints/lookup-of-locations.glsl","keypoints/lookup-of-locations.vs.glsl").withDefines({FS_OUTPUT_TYPE:2,FS_USE_CUSTOM_PRECISION:1,STAGE:2}).withArguments("lookupTable","blockSize","width","height"),We=(0,f.bf)("keypoints/lookup-of-locations.glsl").withDefines({STAGE:-1}).withArguments("lookupTable"),je=(0,f.bf)("keypoints/encode-keypoints.glsl").withArguments("corners","lookupTable","stride","descriptorSize","extraSize","encoderLength","encoderCapacity"),Ze=(0,f.bf)("keypoints/encode-keypoint-offsets.glsl").withArguments("corners","imageSize"),$e=(0,f.bf)("keypoints/encode-keypoint-long-offsets.glsl").withDefines({MAX_ITERATIONS:6}).withArguments("offsetsImage","imageSize"),Ve=(0,f.bf)("keypoints/encode-keypoint-positions.glsl").withArguments("offsetsImage","imageSize","passId","numPasses","keypointLimit","encodedKeypoints","descriptorSize","extraSize","encoderLength"),et=(0,f.bf)("keypoints/encode-keypoint-properties.glsl").withArguments("corners","encodedKeypoints","descriptorSize","extraSize","encoderLength"),tt=(0,f.bf)("keypoints/encode-null-keypoints.glsl").withArguments(),nt=(0,f.bf)("keypoints/transfer-orientation.glsl").withArguments("encodedOrientations","encodedKeypoints","descriptorSize","extraSize","encoderLength"),it=(0,f.bf)("keypoints/upload-keypoints.glsl").withDefines({BUFFER_SIZE:1024}).withArguments("encodedKeypoints","startIndex","endIndex","descriptorSize","extraSize","encoderLength"),st=(0,f.bf)("keypoints/apply-homography.glsl").withArguments("homography","encodedKeypoints","descriptorSize","extraSize","encoderLength"),rt=(0,f.bf)("keypoints/clip-border.glsl").withArguments("imageWidth","imageHeight","borderTop","borderRight","borderBottom","borderLeft","encodedKeypoints","descriptorSize","extraSize","encoderLength"),ot=(0,f.bf)("keypoints/distance-filter.glsl").withArguments("encodedKeypointsA","encoderLengthA","encodedKeypointsB","encoderLengthB","descriptorSize","extraSize","encoderLength","threshold"),at=(0,f.bf)("keypoints/hamming-distance-filter.glsl").withDefines({DESCRIPTOR_SIZE:32}).withArguments("encodedKeypointsA","encoderLengthA","encodedKeypointsB","encoderLengthB","descriptorSize","extraSize","encoderLength","threshold"),At=(0,f.bf)("keypoints/hamming-distance-filter.glsl").withDefines({DESCRIPTOR_SIZE:64}).withArguments("encodedKeypointsA","encoderLengthA","encodedKeypointsB","encoderLengthB","descriptorSize","extraSize","encoderLength","threshold"),ct=(0,f.bf)("keypoints/shuffle.glsl").withDefines({PERMUTATION_MAXLEN:2048}).withArguments("encodedKeypoints","descriptorSize","extraSize","encoderLength"),lt=(0,f.bf)("keypoints/clip.glsl").withArguments("encodedKeypoints","descriptorSize","extraSize","encoderLength","maxKeypoints");class dt extends S{constructor(e){super(e),this.declare("fast9_16",ae,Object.assign({},this.program.usesPingpongRendering())).declare("harris1",Ae[1],Object.assign({},this.program.usesPingpongRendering())).declare("harris3",Ae[3],Object.assign({},this.program.usesPingpongRendering())).declare("harris5",Ae[5],Object.assign({},this.program.usesPingpongRendering())).declare("harris7",Ae[7],Object.assign({},this.program.usesPingpongRendering())).declare("harrisScoreFindMax",ce,Object.assign({},this.program.usesPingpongRendering())).declare("harrisScoreCutoff",le).declare("subpixelQuadratic1d",de).declare("subpixelTaylor2d",he).declare("subpixelBicubic",ue).declare("subpixelBilinear",pe).declare("refineScaleLoG",ge).declare("refineScaleFAST916",fe).declare("allocateDescriptors",Ie).declare("allocateExtra",me).declare("transferToExtra",_e).declare("orbDescriptor",ye).declare("orbOrientation",xe).declare("nonmax",Ce).declare("pyrnonmax",Ee).declare("nonmaxSpace",Se).declare("nonmaxScale",Pe).declare("nonmaxScaleSimple",ve).declare("laplacian",we).declare("lk21",Be[21],Object.assign({},this.program.usesPingpongRendering())).declare("lk19",Be[19],Object.assign({},this.program.usesPingpongRendering())).declare("lk17",Be[17],Object.assign({},this.program.usesPingpongRendering())).declare("lk15",Be[15],Object.assign({},this.program.usesPingpongRendering())).declare("lk13",Be[13],Object.assign({},this.program.usesPingpongRendering())).declare("lk11",Be[11],Object.assign({},this.program.usesPingpongRendering())).declare("lk9",Be[9],Object.assign({},this.program.usesPingpongRendering())).declare("lk7",Be[7],Object.assign({},this.program.usesPingpongRendering())).declare("lk5",Be[5],Object.assign({},this.program.usesPingpongRendering())).declare("lk3",Be[3],Object.assign({},this.program.usesPingpongRendering())).declare("transferFlow",be).declare("bfMatcherInitCandidates",Qe).declare("bfMatcherInitFilters",Me).declare("bfMatcherTransfer",De,Object.assign({},this.program.usesPingpongRendering())).declare("bfMatcher32",ke,Object.assign({},this.program.usesPingpongRendering())).declare("bfMatcher64",Ke,Object.assign({},this.program.usesPingpongRendering())).declare("lshKnnInitCandidates",ze).declare("lshKnnInitFilters",Le).declare("lshKnnTransfer",Re,Object.assign({},this.program.usesPingpongRendering())).declare("sortCreatePermutation",Ne).declare("sortMergePermutation",Oe,Object.assign({},this.program.usesPingpongRendering())).declare("sortApplyPermutation",Fe).declare("mixKeypointsPreInit",Xe).declare("mixKeypointsInit",Ue).declare("mixKeypointsSort",Ge,Object.assign({},this.program.usesPingpongRendering())).declare("mixKeypointsView",qe).declare("mixKeypointsApply",He).declare("encodeNullKeypoints",tt).declare("encodeKeypoints",je).declare("initLookupTable",Ye).declare("sortLookupTable",Je,Object.assign({},this.program.usesPingpongRendering())).declare("viewLookupTable",We).declare("encodeKeypointSkipOffsets",Ze).declare("encodeKeypointLongSkipOffsets",$e,Object.assign({},this.program.usesPingpongRendering())).declare("encodeKeypointPositions",Ve,Object.assign({},this.program.usesPingpongRendering())).declare("encodeKeypointProperties",et).declare("transferOrientation",nt).declare("uploadKeypoints",it,Object.assign({},this.program.usesPingpongRendering())).declare("applyHomography",st).declare("clipBorder",rt).declare("distanceFilter",ot).declare("hammingDistanceFilter32",at).declare("hammingDistanceFilter64",At).declare("shuffle",ct).declare("clip",lt);for(const e of Object.keys(Te))for(const t of Object.keys(Te[e]))for(const n of Object.keys(Te[e][t])){const i=`lshKnn${e}h${t}lv${n}`;this.declare(i,Te[e][t][n],Object.assign({},this.program.usesPingpongRendering()))}}}const ht=(0,f.bf)("pyramids/upsample2.glsl").withArguments("image"),pt=(0,f.bf)("pyramids/downsample2.glsl").withArguments("image");class ut extends S{constructor(e){super(e),this.declare("upsample2",ht).declare("downsample2",pt).declare("smoothX",(0,z.convX)([.05,.25,.4,.25,.05])).declare("smoothY",(0,z.convY)([.05,.25,.4,.25,.05])).declare("smoothX2",(0,z.convX)([.1,.5,.8,.5,.1])).declare("smoothY2",(0,z.convY)([.1,.5,.8,.5,.1],.5))}}const gt=(0,f.bf)("transforms/warp-perspective.glsl").withArguments("image","inverseHomography"),ft=(0,f.bf)("transforms/resize.glsl").withDefines({INTERPOLATION_METHOD:0}).withArguments("image"),It=(0,f.bf)("transforms/resize.glsl").withDefines({INTERPOLATION_METHOD:1}).withArguments("image"),mt=(0,f.bf)("transforms/additive-mix.glsl").withArguments("image0","image1","alpha","beta","gamma");class _t extends S{constructor(e){super(e),this.declare("warpPerspective",gt).declare("resizeNearest",ft).declare("resizeBilinear",It).declare("additiveMix",mt)}}class yt{constructor(e){this._gpu=e,this._filters=null,this._transforms=null,this._pyramids=null,this._keypoints=null,this._utils=null}get filters(){return this._filters||(this._filters=new Y(this._gpu))}get transforms(){return this._transforms||(this._transforms=new _t(this._gpu))}get pyramids(){return this._pyramids||(this._pyramids=new ut(this._gpu))}get keypoints(){return this._keypoints||(this._keypoints=new dt(this._gpu))}get utils(){return this._utils||(this._utils=new K(this._gpu))}release(){for(const e in this)if(Object.prototype.hasOwnProperty.call(this,e)&&null!=this[e]){const t=this[e];t instanceof S&&t.release()}return null}}const xt=Symbol("Bucket");class Ct{constructor(e,t,n){this.texture=e,this.index=t,this.next=n,this.free=!0}}class Et{constructor(e,n=1024){t.A.assert(n>0),this._bucket=Array.from({length:n},((e,t)=>new Ct(null,t,t-1))),this._head=n-1,this._gpu=e}allocate(){if(this._head<0)throw new l.l(`Exhausted pool (capacity: ${this._bucket.length})`);const e=this._bucket[this._head];return e.free=!1,this._head=e.next,null==e.texture&&(e.texture=Et._createManagedTexture(this._gpu.gl,e)),e.texture}free(e){const n=e[xt];return t.A.assert(void 0!==n&&!n.free,"Unmanaged texture or double free"),n.next=this._head,n.free=!0,this._head=n.index,null}release(){for(let e=0;e<this._bucket.length;e++)null!=this._bucket[e].texture&&(this._bucket[e].texture=this._bucket[e].texture.release());return null}static _createManagedTexture(e,t){const n=new g(e,1,1);return Object.defineProperty(n,xt,{configurable:!1,enumerable:!1,writable:!1,value:t})}}var St=n(6049);const Pt=Symbol();class vt{constructor(e){if(e!==Pt)throw new l.Er;this._data=null}static load(e){if(e instanceof HTMLImageElement)return wt.load(e);if(e instanceof HTMLVideoElement)return Bt.load(e);if(e instanceof HTMLCanvasElement)return bt.load(e);if("undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return Qt.load(e);if(e instanceof ImageBitmap)return Mt.load(e);if(e instanceof ImageData)return Dt.load(e);throw new l.qw(`Unsupported media type: ${e}`)}get data(){return this._data}isLoaded(){return null!==this._data}get type(){throw new l.aQ}get width(){throw new l.aQ}get height(){throw new l.aQ}clone(){throw new l.aQ}release(){return this._data=null}_load(e){throw new l.aQ}static _waitUntil(e,n,i=3e4){return new r.i(((s,r)=>{t.A.log(`Waiting for ${n} to be triggered in ${e}...`);const o=setTimeout((()=>{a(),r(new l.MU(`${n} has not been triggered in ${e}: timeout (${i}ms)`))}),i);function a(){clearTimeout(o),e.removeEventListener("error",A,!1),e.removeEventListener(n,c,!1)}function A(){const t=null!==e.error&&"object"==typeof e.error?e.error:{code:-1,message:""},n=`${t.message} (error code ${t.code})`;a(),r(new l.FJ(`Can't load ${e}. ${n}`))}function c(){a(),s(e)}e.addEventListener("error",A,!1),e.addEventListener(n,c,!1)}))}}class wt extends vt{constructor(e){super(e),this._data=null}get data(){return this._data}get type(){return St.zu.Image}get width(){return this._data?this._data.naturalWidth:0}get height(){return this._data?this._data.naturalHeight:0}clone(){if(null==this._data)throw new l.Er("Media not loaded");const e=this._data.cloneNode(!0);return wt.load(e)}_load(e){return this.isLoaded()&&this.release(),e.complete&&0!==e.naturalWidth?new r.i((t=>{this._data=e,t(this)})):vt._waitUntil(e,"load").then((()=>(this._data=e,this)))}static load(e){return new wt(Pt)._load(e)}}class Bt extends vt{constructor(e){super(e),this._data=null}get data(){return this._data}get type(){return St.zu.Video}get width(){return this._data?this._data.videoWidth:0}get height(){return this._data?this._data.videoHeight:0}clone(){if(null==this._data)throw new l.Er("Media not loaded");const e=this._data.cloneNode(!0);return Bt.load(e)}_load(e){return this.isLoaded()&&this.release(),t.A.log("Loading a video..."),e.load(),Bt._waitUntilPlayable(e).then((()=>Bt._handleAutoplay(e).then((()=>(this._data=e,this)))))}static load(e){return new Bt(Pt)._load(e)}static _handleAutoplay(e){return e.autoplay?new r.i(((t,n)=>{const i=e.play();void 0!==i?i.then(t,n):t()})):r.i.resolve()}static _waitUntilPlayable(e){return e.readyState>=3?r.i.resolve(e):new r.i(((t,n)=>{let i=0,s=setInterval((()=>{e.readyState>=3?(clearInterval(s),t(e)):(i+=500)>=3e4&&(clearInterval(s),n(new l.MU("The video took too long to load")))}),500)}))}}class bt extends vt{constructor(e){super(e),this._data=null}get data(){return this._data}get type(){return St.zu.Canvas}get width(){return this._data?this._data.width:0}get height(){return this._data?this._data.height:0}clone(){if(null==this._data)throw new l.Er("Media not loaded");const e=t.A.createCanvas(this.width,this.height);return e.getContext("2d").drawImage(this._data,0,0),bt.load(e)}_load(e){return this.isLoaded()&&this.release(),new r.i((t=>{this._data=e,t(this)}))}static load(e){return new bt(Pt)._load(e)}}class Qt extends vt{constructor(e){super(e),this._data=null}get data(){return this._data}get type(){return St.zu.OffscreenCanvas}get width(){return this._data?this._data.width:0}get height(){return this._data?this._data.height:0}clone(){if(null==this._data)throw new l.Er("Media not loaded");const e=new OffscreenCanvas(this.width,this.height);return e.getContext("2d").drawImage(this._data,0,0),Qt.load(e)}_load(e){return this.isLoaded()&&this.release(),new r.i((t=>{this._data=e,t(this)}))}static load(e){return new Qt(Pt)._load(e)}}class Mt extends vt{constructor(e){super(e),this._data=null}get data(){return this._data}get type(){return St.zu.Bitmap}get width(){return this._data?this._data.width:0}get height(){return this._data?this._data.height:0}clone(){if(null==this._data)throw new l.Er("Media not loaded");return new r.i(((e,t)=>{createImageBitmap(this._data).then((n=>{new Mt(Pt)._load(n).then(e,t)}),t)}))}release(){return null!=this._data&&this._data.close(),super.release()}_load(e){return this.isLoaded()&&this.release(),new r.i((t=>{this._data=e,t(this)}))}static load(e){return new Mt(Pt)._load(e)}}class Dt extends vt{constructor(e){super(e),this._data=null}get data(){return this._data}get type(){return St.zu.Data}get width(){return this._data?this._data.width:0}get height(){return this._data?this._data.height:0}clone(){if(null==this._data)throw new l.Er("Media not loaded");const e=new ImageData(new Uint8ClampedArray(this._data.data),this._data.width,this._data.height);return Dt.load(e)}_load(e){return this.isLoaded()&&this.release(),new r.i((t=>{this._data=e,t(this)}))}static load(e){return new Dt(Pt)._load(e)}}var kt=n(3211);class Kt extends kt.c{constructor(){super(),this._speedyGL=e.c.instance,this._programs=new yt(this),this._texturePool=new Et(this),this._speedyGL.subscribe(this._reset,this)}get programs(){return this._programs}get gl(){return this._speedyGL.gl}get canvas(){return this._speedyGL.canvas}get texturePool(){return this._texturePool}renderToCanvas(e){const n=e.width,i=e.height,s=this.canvas;return(n>s.width||i>s.height)&&(t.A.warning(`Resizing the canvas to ${n} x ${i}`),s.width=n,s.height=i),this.programs.utils.renderToCanvas.outputs(n,i,null),this.programs.utils.renderToCanvas(e),s}upload(e,t){return t.upload(e.data,e.width,e.height)}release(){return t.A.assert(!this.isReleased()),this._programs=this._programs.release(),this._texturePool=this._texturePool.release(),this._speedyGL.unsubscribe(this._reset),null}isReleased(){return null==this._programs}loseAndRestoreWebGLContext(){return this._speedyGL.loseAndRestoreContext().then((()=>{}))}_reset(){this.isReleased()||(this._programs=new yt(this),this._texturePool=new Et(this),this._notify())}}class zt{constructor(e,t){this._width=Math.max(0,+e),this._height=Math.max(0,+t)}get width(){return this._width}set width(e){this._width=Math.max(0,+e)}get height(){return this._height}set height(e){this._height=Math.max(0,+e)}toString(){return`SpeedySize(${this.width}, ${this.height})`}equals(e){return this.width===e.width&&this.height===e.height}area(){return this.width*this.height}}const Lt=Symbol();class Tt{constructor(e,t,n={}){if(e!==Lt)throw new l.Er;if(this._source=t,this._format=void 0!==n.format?n.format:St.f5.RGBA,this._options=Object.freeze(Object.assign(Object.assign({},n),{},{format:this._format})),!t.isLoaded())throw new l.Er(`Source not loaded: ${t}`);if(this._format!==St.f5.RGBA&&this._format!==St.f5.GREY)throw new l.qw(`Invalid format: ${this._format}`)}static load(e,n={},i=!0){return vt.load(e).then((s=>{t.A.assert(0!==s.width&&0!==s.height);const r=new Tt(Lt,s,n);return i&&t.A.log(`Loaded SpeedyMedia with a ${e}.`),r}))}get source(){return this._source?this._source.data:null}get type(){if(this.isReleased())return"unknown";switch(this._source.type){case St.zu.Image:return"image";case St.zu.Video:return"video";case St.zu.Canvas:return"canvas";case St.zu.OffscreenCanvas:return"offscreen-canvas";case St.zu.Bitmap:return"bitmap";case St.zu.Data:return"data";default:return"unknown"}}get width(){return this._source?this._source.width:0}get height(){return this._source?this._source.height:0}get size(){return this._source?new zt(this._source.width,this._source.height):new zt(0,0)}get options(){return this._options}release(){return this.isReleased()||(t.A.log("Releasing SpeedyMedia object..."),this._source=this._source.release()),null}isReleased(){return null==this._source}clone(){if(this.isReleased())throw new l.Er("Can't clone a SpeedyMedia that has been released");const e=new Tt(Lt,this._source,this._options);return r.i.resolve(e)}toBitmap(){if(this.isReleased())throw new l.Er("Can't convert SpeedyMedia to ImageBitmap: the media has been released");if(this._source.isLoaded())return this._source.type==St.zu.Bitmap?r.i.resolve(this._source.data):new r.i(((e,t)=>createImageBitmap(this._source.data).then(e,t)));throw new l.Er("Can't convert SpeedyMedia to bitmap: the media hasn't been loaded")}}class Rt extends J.Q{static get renderer(){return e.c.instance.renderer}static get vendor(){return e.c.instance.vendor}}class Nt{constructor(e,t){this._x=+e,this._y=+t}get x(){return this._x}set x(e){this._x=+e}get y(){return this._y}set y(e){this._y=+e}toString(){return`SpeedyVector2(${this.x.toFixed(5)}, ${this.y.toFixed(5)})`}equals(e){return this.x===e.x&&this.y===e.y}dot(e){return this.x*e.x+this.y*e.y}distanceTo(e){const t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalized(){const e=this.length();return e>0?new Nt(this.x/e,this.y/e):new Nt(0,0)}plus(e){return new Nt(this.x+e.x,this.y+e.y)}minus(e){return new Nt(this.x-e.x,this.y-e.y)}times(e){return new Nt(this.x*e,this.y*e)}}class Ot{constructor(e,t){this._x=+e,this._y=+t}get x(){return this._x}set x(e){this._x=+e}get y(){return this._y}set y(e){this._y=+e}toString(){return`SpeedyPoint2(${this.x.toFixed(5)}, ${this.y.toFixed(5)})`}plus(e){return new Ot(this.x+e.x,this.y+e.y)}minus(e){return new Nt(this.x-e.x,this.y-e.y)}equals(e){return this.x===e.x&&this.y===e.y}}n(6306);var Ft=n(6465),Xt=n(4188);const Ut=Object.freeze({Nothing:Symbol("Nothing"),Image:Symbol("Image"),Keypoints:Symbol("Keypoints"),Vector2:Symbol("Vector2"),LSHTables:Symbol("LSHTables"),KeypointMatches:Symbol("KeypointMatches")});class Gt{constructor(e){this._type=e}get type(){return this._type}hasType(e){return this._type===e}isEmpty(){return this.hasType(Ut.Nothing)}toString(){return`message of type ${Object.keys(Ut).find((e=>Ut[e]===this.type))}`}inspect(e){throw new l.aQ}set(...e){throw new l.aQ}static create(e){return function(e){return new Ht[e]}(e)}}class qt extends Gt{constructor(){super(Ut.Nothing)}set(){return this}inspect(e){return{type:this.constructor.name}}}const Ht=Object.freeze({[Ut.Nothing]:qt,[Ut.Image]:class extends Gt{constructor(){super(Ut.Image),this._image=null,this._format=St.f5.RGBA}set(e,t=St.f5.RGBA){return this._image=e,this._format=t,this}inspect(e){const t=Object.keys(St.f5).find((e=>St.f5[e]===this.format));return{type:this.constructor.name,format:String(t),imageSize:this.image?`${this.image.width}x${this.image.height}`:"0x0",image:this.image?"<image data>":"",hasMipmaps:this.image&&this.image.hasMipmaps()?"yes":"no"}}get image(){return this._image}get format(){return this._format}},[Ut.Keypoints]:class extends Gt{constructor(){super(Ut.Keypoints),this._encodedKeypoints=null,this._descriptorSize=0,this._extraSize=0,this._encoderLength=1}set(e,n,i,s){return this._encodedKeypoints=e,this._descriptorSize=0|n,this._extraSize=0|i,this._encoderLength=0|s,t.A.assert(this._descriptorSize>=0&&this._extraSize>=0),t.A.assert(this._encoderLength===this._encodedKeypoints.width,"Invalid encoderLength"),t.A.assert(this._encodedKeypoints.width===this._encodedKeypoints.height,"Invalid encodedKeypoints texture"),this}inspect(e){return{type:this.constructor.name,descriptorSize:this.descriptorSize,extraSize:this.extraSize,encoderLength:this.encoderLength,encodedKeypointsSize:this.encodedKeypoints?`${this.encodedKeypoints.width}x${this.encodedKeypoints.height}`:"0x0",encodedKeypoints:this.encodedKeypoints?t.A.formatBinaryData(this.encodedKeypoints.inspect(e).buffer):""}}get encodedKeypoints(){return this._encodedKeypoints}get descriptorSize(){return this._descriptorSize}get extraSize(){return this._extraSize}get encoderLength(){return this._encoderLength}},[Ut.Vector2]:class extends Gt{constructor(){super(Ut.Vector2),this._vectors=null}set(e){return this._vectors=e,this}inspect(e){return{type:this.constructor.name,vectorsSize:this.vectors?`${this.vectors.width}x${this.vectors.height}`:"0x0",vectors:this.vectors?t.A.formatBinaryData(this.vectors.inspect(e).buffer):""}}get vectors(){return this._vectors}},[Ut.LSHTables]:class extends Gt{constructor(){super(Ut.LSHTables),this._lsh=null}set(e){return this._lsh=e,this}inspect(e){return{type:this.constructor.name,lsh:"<LSH tables>"}}get lsh(){return this._lsh}},[Ut.KeypointMatches]:class extends Gt{constructor(){super(Ut.KeypointMatches),this._encodedMatches=null,this._matchesPerKeypoint=1}set(e,n){return this._encodedMatches=e,this._matchesPerKeypoint=0|n,t.A.assert(this._matchesPerKeypoint>0),this}inspect(e){return{type:this.constructor.name,matchesPerKeypoint:this.matchesPerKeypoint,encodedMatchesSize:this.encodedMatches?`${this.encodedMatches.width}x${this.encodedMatches.height}`:"0x0",encodedMatches:this.encodedMatches?t.A.formatBinaryData(this.encodedMatches.inspect(e).buffer):""}}get encodedMatches(){return this._encodedMatches}get matchesPerKeypoint(){return this._matchesPerKeypoint}}}),Yt=e=>!0;class Jt{constructor(e,n=Yt){this._expectedMessageType=e,this._isValidMessage="function"==typeof n?n:Yt,t.A.assert(this._expectedMessageType!=Ut.Nothing)}isCompatibleWith(e){return this._expectedMessageType==e._expectedMessageType}accepts(e){return e.hasType(this._expectedMessageType)&&this._isValidMessage(e)}toString(){return`Port expects ${Object.keys(Ut).find((e=>Ut[e]===this._expectedMessageType))} satisfying ${this._isValidMessage}`}get expectedMessageType(){return this._expectedMessageType}}const Wt=/^[a-z][a-zA-Z0-9]*$/,jt=new qt;class Zt{constructor(e,n,i){this._name=String(e),this._spec=n,this._node=i,this._message=jt,t.A.assert(Wt.test(this._name),`Port name "${this._name}" is not acceptable`)}get name(){return this._name}get node(){return this._node}connectTo(e){throw new l.aQ}isInputPort(){throw new l.aQ}isOutputPort(){return!this.isInputPort()}clearMessage(){this._message=jt}hasMessage(){return!this._message.isEmpty()}read(){if(this._message.isEmpty())throw new l.Er(`Can't read from port ${this.name}: nothing to read`);return this._message}write(e){throw new l.EM(`Can't write ${e} to port ${this.name}: unsupported operation`)}inspect(e){return this._message.inspect(e)}static get DEFAULT_NAME(){throw new l.aQ}}class $t extends Zt{constructor(e,t,n){super(e,t,n),this._cachedMessage=null}connectTo(e){if(!e.isInputPort())throw new l.qw(`Can't connect output port ${this.name} to port ${e.name}: expected an input port`);e.connectTo(this)}isInputPort(){return!1}write(e){if(!this._spec.accepts(e))throw new l.qw(`Can't write ${e} to port ${this.name}. ${this._spec}`);this._message=e}swrite(...e){null==this._cachedMessage&&(this._cachedMessage=Gt.create(this._spec.expectedMessageType)),this.write(this._cachedMessage.set(...e))}static get DEFAULT_NAME(){return"out"}}class Vt extends Zt{constructor(e,t,n){super(e,t,n),this._incomingLink=null}get incomingLink(){return this._incomingLink}connectTo(e){if(!e.isOutputPort())throw new l.qw(`Can't connect input port ${this.name} of "${this.node.fullName}" to input port ${e.name} of "${e.node.fullName}": expected an output port`);if(!this._spec.isCompatibleWith(e._spec))throw new l.qw(`Can't connect port ${this.name} of "${this.node.fullName}" to port ${e.name} of "${e.node.fullName}": incompatible types`);this._incomingLink=e}disconnect(){this._incomingLink=null}isInputPort(){return!0}pullMessage(e=""){const t=e.length>0?`${this.name} of ${e}`:this.name;if(null==this._incomingLink)throw new l.Er(`No incoming link for input port ${t}`);const n=this._incomingLink.read();if(!this._spec.accepts(n))throw new l.qw(`Can't receive ${n} at port ${t}: ${this._spec}`);return this._message=n}static get DEFAULT_NAME(){return"in"}}class en{constructor(e,t){this._class=e,this._name=String(t),this._type=Ut.Nothing,this._messageConstraint=void 0}expects(e){return t.A.assert(this._type==Ut.Nothing),t.A.assert(e!=Ut.Nothing),this._type=e,this}satisfying(e){return t.A.assert(this._type!=Ut.Nothing,"You must first declare what type of message this port expects"),t.A.assert(void 0===this._messageConstraint),t.A.assert("function"==typeof e),this._messageConstraint=e,this}build(e){const t=new Jt(this._type,this._messageConstraint);return Reflect.construct(this._class,[this._name,t,e])}}function tn(e=Vt.DEFAULT_NAME){return new en(Vt,e)}function nn(e=$t.DEFAULT_NAME){return new en($t,e)}function sn(e){return e.reduce(((e,t)=>(e[t.name]=t,e)),Object.create(null))}function rn(e){return e.reduce(((e,t)=>(e[t.name]=t,e)),Object.create(null))}let on=!1;class an{constructor(e=(()=>Math.random().toString(16).substr(2))(),t=0,n=[]){this._name=String(e),this._tex=new Array(t).fill(null);const i=n.map((e=>e.build(this))),s=i.filter((e=>e.isInputPort())),r=i.filter((e=>e.isOutputPort()));if(this._inputPorts=sn(s),this._outputPorts=rn(r),0==this._name.length)throw new l.qw(`Invalid name "${this._name}" for node ${this.fullName}`);if(0==n.length)throw new l.qw(`No ports have been found in node ${this.fullName}`)}get name(){return this._name}get fullName(){return`${this.constructor.name}[${this.name}]`}input(e=Vt.DEFAULT_NAME){if(e in this._inputPorts)return this._inputPorts[e];throw new l.qw(`Can't find input port ${e} in node ${this.fullName}`)}output(e=$t.DEFAULT_NAME){if(e in this._outputPorts)return this._outputPorts[e];throw new l.qw(`Can't find output port ${e} in node ${this.fullName}`)}execute(e){let t;for(t in this._outputPorts)this._outputPorts[t].clearMessage();for(t in this._inputPorts)this._inputPorts[t].pullMessage(this.fullName);const n=this._run(e);return void 0===n?void this._finishExecution(e):n.then((()=>this._finishExecution(e)))}_finishExecution(e){for(const e in this._outputPorts)t.A.assert(this._outputPorts[e].hasMessage(),`Did you forget to write data to the output port ${e} of ${this.fullName}?`);if("diagnostic"===s.w.logging){t.A.log(`%c ${this.fullName} `,"font-size:12pt;font-weight:bold;color:white;background:blue");for(const n in this._inputPorts)t.A.log(`%c-> ${n}:`,"font-size:10pt;font-weight:bold",this._inputPorts[n].inspect(e));for(const n in this._outputPorts)t.A.log(`%c<- ${n}:`,"font-size:10pt;font-weight:bold",this._outputPorts[n].inspect(e))}}_run(e){throw new l.aQ}init(e){e.subscribe(this._allocateWorkTextures,this,e),this._allocateWorkTextures(e)}release(e){this._deallocateWorkTextures(e),e.unsubscribe(this._allocateWorkTextures,this)}clearPorts(){let e;for(e in this._inputPorts)this._inputPorts[e].clearMessage();for(e in this._outputPorts)this._outputPorts[e].clearMessage()}inputNodes(){const e=[];for(const t in this._inputPorts){const n=this._inputPorts[t];null!=n.incomingLink&&e.push(n.incomingLink.node)}return e}isSource(){return!1}isSink(){return!1}_allocateWorkTextures(e){for(let t=0;t<this._tex.length;t++)this._tex[t]=e.texturePool.allocate()}_deallocateWorkTextures(e){for(let t=this._tex.length-1;t>=0;t--)this._tex[t]=e.texturePool.free(this._tex[t])}_visualize(e,t){const n=e.renderToCanvas(t);on||(document.body.appendChild(n),on=!0)}}class An extends an{constructor(e=void 0,n=void 0,i=void 0){super(e,n,i),t.A.assert(0==Object.keys(this._inputPorts).length)}isSource(){return!0}}class cn extends an{constructor(e=void 0,n=void 0,i=void 0){super(e,n,i),t.A.assert(0==Object.keys(this._outputPorts).length)}export(){throw new l.aQ}isSink(){return!0}}class ln{constructor(e,t){const n=t<p.MATCH_MAX_DISTANCE;return this._index=n?0|e:-1,this._distance=n?+t:Number.POSITIVE_INFINITY,Object.freeze(this)}get index(){return this._index}get distance(){return this._distance}toString(){return`SpeedyKeypointMatch(${this.index},${this.distance})`}}class dn{constructor(e,t,n=0,i=0,s=0,r=null){this._position=new Ot(+e,+t),this._lod=+n,this._rotation=+i,this._score=+s,this._descriptor=r}toString(){return`SpeedyKeypoint(${this.x},${this.y})`}get position(){return this._position}get x(){return this._position.x}set x(e){this._position.x=+e}get y(){return this._position.y}set y(e){this._position.y=+e}get lod(){return this._lod}get scale(){return Math.pow(2,this._lod)}get rotation(){return this._rotation}get score(){return this._score}get descriptor(){return this._descriptor}}class hn extends dn{constructor(e,t,n=0,i=0,s=0,r=null,o=new Nt(0,0)){super(e,t,n,i,s,r),this._flow=o}get flow(){return this._flow}}class pn extends dn{constructor(e,t,n=0,i=0,s=0,r=null,o=[]){super(e,t,n,i,s,r),this._matches=o}get matches(){return this._matches}}let un=null,gn=0;class fn{constructor(){this._nodes=[],this._sequence=[],this._busy=!1}node(e){for(let t=0,n=this._nodes.length;t<n;t++)if(this._nodes[t].name===e)return this._nodes[t];return null}init(...e){if(this._nodes.length>0)throw new l.Er("The pipeline has already been initialized");if(0==e.length)throw new l.qw("Can't initialize the pipeline. Please specify its nodes");0==gn++&&(t.A.assert(!un,"Duplicate SpeedyGPU instance"),un=new Kt);for(let t=0;t<e.length;t++){const n=e[t];this._nodes.includes(n)||this._nodes.push(n)}this._sequence=fn._tsort(this._nodes),fn._validateSequence(this._sequence);for(let e=0;e<this._sequence.length;e++)this._sequence[e].init(un);return this}release(){if(0==this._nodes.length)throw new l.Er("The pipeline has already been released or has never been initialized");for(let e=this._sequence.length-1;e>=0;e--)this._sequence[e].release(un);return this._sequence.length=0,this._nodes.length=0,0==--gn&&(un=un.release()),null}run(){if(t.A.assert(this._sequence.length>0,"The pipeline has not been initialized or has been released"),this._busy)return new r.i(((e,t)=>{setTimeout((()=>this.run().then(e,t)),0)}));this._busy=!0;const e=this._sequence.filter((e=>e.isSink())),n=fn._createOutputTemplate(e);return"diagnostic"===s.w.logging&&t.A.log("%c RUNNING PIPELINE ","background:red;color:white;font-size:28pt;font-weight:bold"),fn._runSequence(this._sequence).then((()=>r.i.all(e.map((e=>e.export().turbocharge()))).then((t=>t.reduce(((t,n,i)=>(t[e[i].name]=n,t)),n))))).finally((()=>{for(let e=this._sequence.length-1;e>=0;e--)this._sequence[e].clearPorts();this._busy=!1,"diagnostic"===s.w.logging&&(t.A.log("%c PIPELINE OUTPUT \n","background:green;color:white;font-size:16pt;font-weight:bold"),Object.keys(n).forEach((e=>{t.A.log("%c"+e+":","font-size:10pt;font-weight:bold",n[e])})))})).turbocharge()}get _gpu(){return un}static _runSequence(e,t=0,n=e.length){for(;t<n;t++){const i=e[t].execute(un);if(un.gl.flush(),void 0!==i)return i.then((()=>fn._runSequence(e,t+1,n)))}return r.i.resolve()}static _tsort(e){const t=fn._outlinks(e),n=e.map((e=>[e,!1])),i=new Set,s=new Array(e.length);let r=s.length;for(;n.length>0;){const[e,o]=n.pop();if(o)s[--r]=e;else if(!i.has(e)){const r=t.get(e);if(i.add(e),n.push([e,!0]),n.push(...r.map((e=>[e,!1]))),r.some((e=>i.has(e)&&!s.includes(e))))throw new l.Er("Pipeline networks cannot have cycles!")}}return s}static _outlinks(e){const t=new Map;for(let n=0;n<e.length;n++)t.set(e[n],[]);for(let n=0;n<e.length;n++){const i=e[n],s=i.inputNodes();for(let e=0;e<s.length;e++){const n=s[e],r=t.get(n);if(!r)throw new l.Er(`Can't initialize the pipeline. Missing node: ${n.fullName}. Did you forget to add it to the initialization list?`);r.includes(i)||r.push(i)}}return t}static _createOutputTemplate(e=[]){const t=Object.create(null);for(let n=e.length-1;n>=0;n--)t[e[n].name]=null;return t}static _validateSequence(e){if(0==e.length)throw new l.Er("Pipeline doesn't have nodes");if(!e[0].isSource())throw new l.Er("Pipeline doesn't have a source");if(!e.find((e=>e.isSink())))throw new l.Er("Pipeline doesn't have a sink")}}class In extends An{constructor(e=void 0){super(e,2,[nn().expects(Ut.Image)]),this._media=null,this._textureIndex=0}get media(){return this._media}set media(e){if(null!==e&&!(e instanceof Tt))throw new l.qw(`Not a SpeedyMedia: ${e}`);this._media=e}_run(e){if(null==this._media)throw new l.Er(`Did you forget to set the media of ${this.fullName}?`);this._textureIndex=(this._textureIndex+1)%this._tex.length;const t=this._tex[this._textureIndex];e.upload(this._media._source,t),this.output().swrite(t,this._media._format)}}class mn extends cn{constructor(e="image"){super(e,0,[tn().expects(Ut.Image)]),this._mediaType="bitmap",this._bitmap=null,this._data=null,this._format=St.f5.RGBA,this._textureReader=new h(1)}get mediaType(){return this._mediaType}set mediaType(e){if("bitmap"!=e&&"data"!=e)throw new l.qw(`Invalid mediaType for ${this.fullName}: "${e}"`);this._mediaType=e}init(e){super.init(e),this._textureReader.init(e)}release(e){this._textureReader.release(e),super.release(e)}export(){const e="data"!=this._mediaType?this._bitmap:this._data;return t.A.assert(null!=e),Tt.load(e,{format:this._format},!1)}_run(e){const{image:t,format:n}=this.input().read();return"data"!=this._mediaType?new r.i((i=>{const s=e.renderToCanvas(t);createImageBitmap(s,0,s.height-t.height,t.width,t.height).then((e=>{this._bitmap=e,this._format=n,this._data=null,i()}))})):this._textureReader.readPixelsAsync(t,0,0,t.width,t.height,!1).then((e=>{const i=new Uint8ClampedArray(e.buffer);this._data=new ImageData(i,t.width,t.height),this._format=n,this._bitmap=null}))}}const _n=["in0","in1"];class yn extends an{constructor(e=void 0){super(e,0,[..._n.map((e=>tn(e).expects(Ut.Image))),nn().expects(Ut.Image)]),this._port=0}get port(){return this._port}set port(e){if(e<0||e>=_n.length)throw new l.qw(`Invalid port: ${e}`);this._port=0|e}_run(e){const t=this.input(_n[this._port]).read();this.output().write(t)}}class xn extends an{constructor(e=void 0){super(e,2,[tn().expects(Ut.Image),nn().expects(Ut.Image)]),this._pageIndex=0,this._initialized=!1,this._previousFormat=St.f5.RGBA,this._frozen=!1}get frozen(){return this._frozen}set frozen(e){this._frozen=Boolean(e)}release(e){this._initialized=!1,super.release(e)}_run(e){const{image:t,format:n}=this.input().read(),i=this._previousFormat,s=this._tex,r=s[1-this._pageIndex],o=s[this._pageIndex];if(t.hasMipmaps())throw new l.EM(`${this.fullName} can't bufferize a pyramid`);if(this._frozen&&this._initialized||(this._previousFormat=n,r.resize(t.width,t.height),t.copyTo(r),this._pageIndex=1-this._pageIndex),!this._initialized)return this._initialized=!0,void this.output().swrite(r,n);this.output().swrite(o,i)}}const Cn=p.PYRAMID_MAX_LEVELS,En=2*Cn;class Sn extends an{constructor(e=void 0){super(e,En+1,[tn().expects(Ut.Image),nn().expects(Ut.Image)])}_run(e){const{image:t,format:n}=this.input().read(),i=this._tex[0],s=e.programs.pyramids;let r=t.width,o=t.height;const a=1+Math.floor(Math.log2(Math.max(r,o))),A=new Array(En+1);for(let e=En;e>=1;e--)A[e-1]=this._tex[e];A[0].resize(r,o),t.copyTo(A[0]);const c=Math.min(a,Cn);for(let t=1;t<c;t++){const n=Math.max(1,r>>>1),i=Math.max(1,o>>>1),a=t-1+Cn;s.smoothX.outputs(r,o,A[a])(A[t-1]),s.smoothY.outputs(r,o,A[t-1])(A[a]),s.downsample2.outputs(n,i,A[t])(A[t-1]),e.gl.flush(),r=n,o=i}i.resize(t.width,t.height),i.clear(),t.copyTo(i),i.generateMipmaps(A.slice(0,c)),this.output().swrite(i,n)}}class Pn extends an{constructor(e=void 0){super(e,1,[tn("in0").expects(Ut.Image),tn("in1").expects(Ut.Image),nn().expects(Ut.Image)]),this._alpha=.5,this._beta=.5,this._gamma=0}get alpha(){return this._alpha}set alpha(e){this._alpha=+e}get beta(){return this._beta}set beta(e){this._beta=+e}get gamma(){return this._gamma}set gamma(e){this._gamma=+e}_run(e){const t=this.input("in0").read(),n=this.input("in1").read(),i=t.image,s=n.image,r=t.format,o=n.format,a=Math.max(i.width,s.width),A=Math.max(i.height,s.height),c=this._alpha,d=this._beta,h=this._gamma,p=this._tex[0];if(r!=o)throw new l.EM("Can't mix images of different formats");e.programs.transforms.additiveMix.outputs(a,A,p),e.programs.transforms.additiveMix(i,s,c,d,h),this.output().swrite(p,r)}}class vn extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Image)]),this._format=St.f5.RGBA,this._initialized=!1}get image(){if(!this._initialized)throw new l.Er(`Portal error: ${this.fullName} holds no data`);return this._tex[0]}get format(){if(!this._initialized)throw new l.Er(`Portal error: ${this.fullName} holds no data`);return this._format}init(e){super.init(e),this._tex[0].resize(1,1).clear(),this._format=St.f5.RGBA,this._initialized=!0}release(e){this._initialized=!1,super.release(e)}_run(e){const{image:t,format:n}=this.input().read(),i=this._tex[0];if(t.hasMipmaps())throw new l.EM(`${this.fullName} can't store a pyramid`);this._format=n,i.resize(t.width,t.height),t.copyTo(i)}}class wn extends An{constructor(e=void 0){super(e,0,[nn().expects(Ut.Image)]),this._source=null}get source(){return this._source}set source(e){if(null!==e&&!(e instanceof vn))throw new l.qw(`Incompatible source for ${this.fullName}`);this._source=e}_run(e){if(null==this._source)throw new l.Er(`${this.fullName} has no source`);this.output().swrite(this._source.image,this._source.format)}}class Bn extends J.Q{static Source(e=void 0){return new wn(e)}static Sink(e=void 0){return new vn(e)}}class bn extends J.Q{static Source(e=void 0){return new In(e)}static Sink(e=void 0){return new mn(e)}static Multiplexer(e=void 0){return new yn(e)}static Buffer(e=void 0){return new xn(e)}static Pyramid(e=void 0){return new Sn(e)}static Mixer(e=void 0){return new Pn(e)}static get Portal(){return Bn}}class Qn extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Image),nn().expects(Ut.Image)])}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._tex[0],o=e.programs.filters;o.rgb2grey.outputs(i,s,r),o.rgb2grey(t),this.output().swrite(r,St.f5.GREY)}}const Mn=Object.freeze({3:[.27901008925473514,.44197982149052983,.27901008925473514],5:[.06135959781344021,.2447701955296099,.3877404133138998,.2447701955296099,.06135959781344021],7:[.03873542500847274,.11308485700794121,.2150068609928349,.26634571398150225,.2150068609928349,.11308485700794121,.03873542500847274],9:[.028532262603370988,.067234535494912,.12400932997922749,.17904386461741617,.20236001461014655,.17904386461741617,.12400932997922749,.067234535494912,.028532262603370988],11:[.022656882730580346,.04610857898527292,.08012661469398517,.11890414969751599,.15067709325491124,.16305336127546846,.15067709325491124,.11890414969751599,.08012661469398517,.04610857898527292,.022656882730580346],13:[.018815730430644363,.03447396964662016,.05657737457255748,.08317258170844948,.10952340502389682,.12918787500405662,.13649812722755,.12918787500405662,.10952340502389682,.08317258170844948,.05657737457255748,.03447396964662016,.018815730430644363],15:[.016100340991695383,.027272329212157102,.042598338587449644,.06135478775568558,.08148767614129326,.09979838342934616,.11270444144735056,.11736740487004466,.11270444144735056,.09979838342934616,.08148767614129326,.06135478775568558,.042598338587449644,.027272329212157102,.016100340991695383]}),Dn=new Nt(0,0),kn=Object.freeze({3:"convolution3x",5:"convolution5x",7:"convolution7x",9:"convolution9x",11:"convolution11x",13:"convolution13x",15:"convolution15x"}),Kn=Object.freeze({3:"convolution3y",5:"convolution5y",7:"convolution7y",9:"convolution9y",11:"convolution11y",13:"convolution13y",15:"convolution15y"});class zn extends an{constructor(e=void 0){super(e,2,[tn().expects(Ut.Image),nn().expects(Ut.Image)]),this._kernelSize=new zt(5,5),this._sigma=Dn,this._kernel={x:Mn[this._kernelSize.width],y:Mn[this._kernelSize.height]}}get kernelSize(){return this._kernelSize}set kernelSize(e){t.A.assert(e instanceof zt);const n=e.width,i=e.height;if(n<3||i<3||n>15||i>15||n%2==0||i%2==0)throw new l.EM(`Unsupported kernel size: ${n}x${i}`);this._kernelSize=e,this._updateKernel()}get sigma(){return this._sigma}set sigma(e){t.A.assert(e instanceof Nt,"Sigma must be a SpeedyVector2"),t.A.assert(e.x>=0&&e.y>=0),this._sigma=e,this._updateKernel()}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._kernel.x,o=this._kernel.y,a=kn[this._kernelSize.width],A=Kn[this._kernelSize.height],c=this._tex[0],l=this._tex[1];e.programs.filters[a].outputs(i,s,c)(t,r),e.programs.filters[A].outputs(i,s,l)(c,o),this.output().swrite(l,n)}_updateKernel(){this._sigma.x==Dn.x?this._kernel.x=Mn[this._kernelSize.width]:this._kernel.x=t.A.gaussianKernel(this._sigma.x,this._kernelSize.width,!0),this._sigma.y==Dn.y?this._kernel.y=Mn[this._kernelSize.height]:this._kernel.y=t.A.gaussianKernel(this._sigma.y,this._kernelSize.height,!0)}}const Ln=Object.freeze({3:new Array(3).fill(1/3),5:new Array(5).fill(.2),7:new Array(7).fill(1/7),9:new Array(9).fill(1/9),11:new Array(11).fill(1/11),13:new Array(13).fill(1/13),15:new Array(15).fill(1/15)}),Tn=Object.freeze({3:"convolution3x",5:"convolution5x",7:"convolution7x",9:"convolution9x",11:"convolution11x",13:"convolution13x",15:"convolution15x"}),Rn=Object.freeze({3:"convolution3y",5:"convolution5y",7:"convolution7y",9:"convolution9y",11:"convolution11y",13:"convolution13y",15:"convolution15y"});class Nn extends an{constructor(e=void 0){super(e,2,[tn().expects(Ut.Image),nn().expects(Ut.Image)]),this._kernelSize=new zt(5,5),this._kernel={x:Ln[this._kernelSize.width],y:Ln[this._kernelSize.height]}}get kernelSize(){return this._kernelSize}set kernelSize(e){t.A.assert(e instanceof zt);const n=e.width,i=e.height;if(n<3||i<3||n>15||i>15||n%2==0||i%2==0)throw new l.EM(`Unsupported kernel size: ${n}x${i}`);this._kernelSize=e,this._kernel.x=Ln[this._kernelSize.width],this._kernel.y=Ln[this._kernelSize.height]}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._kernel.x,o=this._kernel.y,a=Tn[this._kernelSize.width],A=Rn[this._kernelSize.height],c=this._tex[0],l=this._tex[1];e.programs.filters[a].outputs(i,s,c)(t,r),e.programs.filters[A].outputs(i,s,l)(c,o),this.output().swrite(l,n)}}const On={3:"median3",5:"median5",7:"median7"};class Fn extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),nn().expects(Ut.Image)]),this._kernelSize=new zt(5,5)}get kernelSize(){return this._kernelSize}set kernelSize(e){t.A.assert(e instanceof zt);const n=e.width;if(3!=n&&5!=n&&7!=n)throw new l.EM("Supported kernel sizes: 3x3, 5x5, 7x7");if(e.width!=e.height)throw new l.EM("Use a square kernel");this._kernelSize=e}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._kernelSize.width,o=On[r],a=this._tex[0];e.programs.filters[o].outputs(i,s,a)(t),this.output().swrite(a,n)}}const Xn={3:"convolution3",5:"convolution5",7:"convolution7"};class Un extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Image),nn().expects(Ut.Image)]),this._kernel=Xt.SpeedyMatrix.Create(3,3,[0,0,0,0,1,0,0,0,0])}get kernel(){return this._kernel}set kernel(e){if(e.rows!=e.columns)throw new l.EM("Use a square kernel");if(3!=e.rows&&5!=e.rows&&7!=e.rows)throw new l.EM("Invalid kernel size. Supported sizes: 3x3, 5x5, 7x7");this._kernel=e}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._tex[0],o=this._kernel.rows,a=Xn[o],A=this._kernel.read();e.programs.filters[a].outputs(i,s,r)(t,A),this.output().swrite(r,n)}}class Gn extends an{constructor(e=void 0){super(e,3,[tn().expects(Ut.Image).satisfying((e=>e.format===St.f5.RGBA||e.format===St.f5.GREY)),nn().expects(Ut.Image)]),this._gain=.5,this._offset=.5,this._decay=0,this._quality="medium"}get gain(){return this._gain}set gain(e){this._gain=+e}get offset(){return this._offset}set offset(e){this._offset=+e}get decay(){return this._decay}set decay(e){this._decay=Math.max(0,Math.min(+e,1))}get quality(){return this._quality}set quality(e){if("high"!==e&&"medium"!==e&&"low"!==e)throw new l.qw(`Invalid quality level for the Nightvision filter: "${e}"`);this._quality=e}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._gain,o=this._offset,a=this._decay,A=this._quality,c=e.programs.filters,l=this._tex[0],d=this._tex[1],h=this._tex[2];"medium"==A?(c.illuminationMapX.outputs(i,s,l),c.illuminationMapY.outputs(i,s,d),c.illuminationMapX(t),c.illuminationMapY(l)):"high"==A?(c.illuminationMapHiX.outputs(i,s,l),c.illuminationMapHiY.outputs(i,s,d),c.illuminationMapHiX(t),c.illuminationMapHiY(l)):"low"==A&&(c.illuminationMapLoX.outputs(i,s,l),c.illuminationMapLoY.outputs(i,s,d),c.illuminationMapLoX(t),c.illuminationMapLoY(l)),n===St.f5.GREY?(c.nightvisionGreyscale.outputs(i,s,h),c.nightvisionGreyscale(t,d,r,o,a)):n===St.f5.RGBA&&(c.nightvision.outputs(i,s,h),c.nightvision(t,d,r,o,a)),this.output().swrite(h,n)}}class qn extends an{constructor(e=void 0){super(e,4,[tn().expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),nn().expects(Ut.Image)]),this._minValue=0,this._maxValue=255}get minValue(){return this._minValue}set minValue(e){this._minValue=Math.max(0,Math.min(+e,255))}get maxValue(){return this._maxValue}set maxValue(e){this._maxValue=Math.max(0,Math.min(+e,255))}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._tex[3];let o=this._minValue,a=this._maxValue;o>a&&(o=a=(o+a)/2);const A=this._scanMinMax(e,t,St.kQ.GREEN);e.programs.filters.normalizeGreyscale.outputs(i,s,r),e.programs.filters.normalizeGreyscale(A,o,a),this.output().swrite(r,n)}_scanMinMax(e,n,i){const s=this._tex,r=e.programs.utils,o=n.width,a=n.height,A=0|Math.ceil(Math.log2(Math.max(o,a)));t.A.assert(void 0!==St.kg[i]),r.copyComponents.outputs(o,a,s[2]),r.scanMinMax2D.outputs(o,a,s[0],s[1]);let c=r.copyComponents(n,n,St.kQ.ALL,St.kg[i]);for(let e=0;e<A;e++)c=r.scanMinMax2D(c,e);return c}}class Hn extends J.Q{static Greyscale(e=void 0){return new Qn(e)}static GaussianBlur(e=void 0){return new zn(e)}static SimpleBlur(e=void 0){return new Nn(e)}static MedianBlur(e=void 0){return new Fn(e)}static Convolution(e=void 0){return new Un(e)}static Nightvision(e=void 0){return new Gn(e)}static Normalize(e=void 0){return new qn(e)}}const Yn=[0,0,0,0,0,0,0,0,1];class Jn extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Image),nn().expects(Ut.Image)]),this._transform=Xt.SpeedyMatrix.Create(3,3,[1,0,0,0,1,0,0,0,1])}get transform(){return this._transform}set transform(e){if(3!=e.rows||3!=e.columns)throw new l.qw(`Not a 3x3 transformation matrix: ${e}`);this._transform=e}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._tex[0],o=this._transform.read(),a=this._inverse3(o),A=!Number.isNaN(a[0]);e.programs.transforms.warpPerspective.outputs(i,s,r),e.programs.transforms.warpPerspective(t,A?a:Yn),this.output().swrite(r,n)}_inverse3(e,t=1e-6){const n=e[0],i=e[1],s=e[2],r=e[3],o=e[4],a=e[5],A=e[6],c=e[7],l=e[8],d=l*o-a*c,h=l*r-a*A,p=c*r-o*A,u=n*d-i*h+s*p;if(Math.abs(u)<t)e.fill(Number.NaN,0,9);else{const t=1/u;e[0]=d*t,e[1]=-(l*i-s*c)*t,e[2]=(a*i-s*o)*t,e[3]=-h*t,e[4]=(l*n-s*A)*t,e[5]=-(a*n-s*r)*t,e[6]=p*t,e[7]=-(c*n-i*A)*t,e[8]=(o*n-i*r)*t}return e}}class Wn extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Image),nn().expects(Ut.Image)]),this._size=new zt(0,0),this._scale=new Nt(1,1),this._method="bilinear"}get size(){return this._size}set size(e){this._size=e}get scale(){return this._scale}set scale(e){this._scale=e}get method(){return this._method}set method(e){if("nearest"!==e&&"bilinear"!==e)throw new l.qw(`Invalid method method: "${e}"`);this._method=e}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._tex[0],o=this._method,a=this._size.width||Math.max(1,this._scale.x*i),A=this._size.height||Math.max(1,this._scale.y*s);"bilinear"==o?e.programs.transforms.resizeBilinear.outputs(a,A,r)(t):"nearest"==o&&e.programs.transforms.resizeNearest.outputs(a,A,r)(t),this.output().swrite(r,n)}}class jn extends J.Q{static Resize(e=void 0){return new Wn(e)}static PerspectiveWarp(e=void 0){return new Jn(e)}}const Zn=p.MAX_ENCODER_CAPACITY,$n=p.DEFAULT_ENCODER_CAPACITY;class Vn extends an{constructor(e=void 0,t=0,n=void 0){super(e,t+0,n),this._capacity=$n,this._oldWrapS=0,this._tex16=new Array(2).fill(null)}init(e){super.init(e),this._oldWrapS=this._setupSpecialTexture(e.gl.TEXTURE_WRAP_S,e.gl.REPEAT),this._allocateTex16(e),e.subscribe(this._allocateTex16,this,e)}release(e){e.unsubscribe(this._allocateTex16,this),this._deallocateTex16(e),this._setupSpecialTexture(e.gl.TEXTURE_WRAP_S,this._oldWrapS),super.release(e)}_setupSpecialTexture(e,t){}get capacity(){return this._capacity}set capacity(e){this._capacity=Math.min(Math.max(0,0|e),Zn)}_encodeKeypoints(e,t,n,i=0,s=0){const r=this._capacity,o=Vn.encoderLength(r,i,s),a=1<<(Math.ceil(Math.log2(t.width*t.height))>>>1),A=Math.ceil(t.width*t.height/a),c=Math.max(a,A),l=e.programs.keypoints;l.initLookupTable.outputs(a,A,this._tex16[1]),l.sortLookupTable.outputs(a,A,this._tex16[0],this._tex16[1]),l.encodeKeypoints.outputs(o,o,n);let d=l.initLookupTable(t);for(let e=1;e<c;e*=2)d=l.sortLookupTable(d,e,a,A);return l.encodeKeypoints(t,d,a,i,s,o,r)}_encodeKeypointsOLD(e,t,n,i=0,s=0){const r=this._capacity,o=Vn.encoderLength(r,i,s),a=t.width,A=t.height,c=[a,A],l=this._tex.slice(this._tex.length-0),d=e.programs.keypoints,h=l.pop();d.encodeKeypointSkipOffsets.outputs(a,A,l[0]),d.encodeKeypointLongSkipOffsets.outputs(a,A,l[1],l[0]),d.encodeKeypointPositions.outputs(o,o,l[2],l[3]),d.encodeKeypointProperties.outputs(o,o,n),t=e.programs.utils.copy.outputs(a,A,h)(t);let p=d.encodeKeypointSkipOffsets(t,c);for(let e=0;e<2;e++)p=d.encodeKeypointLongSkipOffsets(p,c);let u=l[3].clear();for(let e=0;e<4;e++)u=d.encodeKeypointPositions(p,c,e,4,r,u,i,s,o);return d.encodeKeypointProperties(t,u,i,s,o)}_encodeZeroKeypoints(e,t,n=0,i=0){const s=Vn.encoderLength(0,n,i),r=e.programs.keypoints;return r.encodeNullKeypoints.outputs(s,s,t),r.encodeNullKeypoints()}_allocateTex16(e){const t=e.gl;for(let e=0;e<this._tex16.length;e++)this._tex16[e]=new g(t,1,1,t.RGBA_INTEGER,t.RGBA16UI,t.UNSIGNED_SHORT,t.NEAREST,t.CLAMP_TO_EDGE)}_deallocateTex16(e){for(let e=0;e<this._tex16.length;e++)this._tex16[e]=this._tex16[e].release()}static encoderLength(e,t,n){const i=e*Math.ceil((p.MIN_KEYPOINT_SIZE+t+n)/4);return Math.max(p.MIN_ENCODER_LENGTH,Math.ceil(Math.sqrt(i)))}static encoderCapacity(e,t,n){const i=Math.ceil((p.MIN_KEYPOINT_SIZE+e+t)/4),s=n*n;return Math.floor(s/i)}}class ei extends Vn{constructor(e=void 0,t=void 0,n=void 0){super(e,t,n),this._levels=1,this._scaleFactor=1.4142135623730951}get levels(){return this._levels}set levels(e){this._levels=Math.max(1,0|e)}get scaleFactor(){return this._scaleFactor}set scaleFactor(e){this._scaleFactor=Math.max(1,Math.min(+e,2))}}const ti=1024,ni=4*Float32Array.BYTES_PER_ELEMENT;class ii extends An{constructor(e=void 0){super(e,2,[nn().expects(Ut.Keypoints)]),this._keypoints=[],this._buffer=ii._createUploadBuffer(ti),this._capacity=p.DEFAULT_ENCODER_CAPACITY}get keypoints(){return this._keypoints}set keypoints(e){if(!Array.isArray(e))throw new l.qw("Not an array of keypoints");this._keypoints=e}get capacity(){return this._capacity}set capacity(e){this._capacity=Math.min(Math.max(0,0|e),p.MAX_ENCODER_CAPACITY)}_run(e){const t=this._keypoints,n=this._capacity,i=Math.min(t.length,n),s=Math.max(1,Math.ceil(i/ti)),r=this._buffer,o=e.programs.keypoints.uploadKeypoints,a=Vn.encoderLength(n,0,0);o.outputs(a,a,this._tex[0],this._tex[1]);let A=0,c=o.clear();for(let e=0;e<s;e++){const e=A+Math.min(ti,i-A);o.setUBO("KeypointBuffer",ii._fillUploadBuffer(r,t,A,e)),c=o(c,A,e,0,0,a),A=e}this.output().swrite(c,0,0,a)}static _createUploadBuffer(e){const n=new ArrayBuffer(ni*e);return t.A.assert(n.byteLength<=16384),new Float32Array(n)}static _fillUploadBuffer(e,t,n,i){const s=i-n;for(let i=0;i<s;i++){const s=t[n+i],r=void 0!==s.position,o=4*i;e[o]=+(r?s.position.x:s.x)||0,e[o+1]=+(r?s.position.y:s.y)||0,e[o+2]=+s.lod||0,e[o+3]=+s.score||0}return e}}class si{constructor(e){return this._data=e,Object.freeze(this)}get data(){return this._data}get size(){return this._data.byteLength}toString(){return`SpeedyKeypointDescriptor(${this._data.join(",")})`}}const ri=new Uint8Array([]);class oi extends cn{constructor(e="keypoints",t=0,n=[]){super(e,t+2,n),this._keypoints=[],this._textureReader=new h,this._page=0,this._turbo=!1,this._includeDiscarded=!1}get turbo(){return this._turbo}set turbo(e){this._turbo=Boolean(e)}get includeDiscarded(){return this._includeDiscarded}set includeDiscarded(e){this._includeDiscarded=Boolean(e)}init(e){super.init(e),this._textureReader.init(e)}release(e){this._textureReader.release(e),super.release(e)}export(){return r.i.resolve(this._keypoints)}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read();return this._download(e,t,n,i,s)}_download(e,t,n,i,s){const r=this._turbo,o=(a=s)>1?1<<Math.ceil(Math.log2(a)):1;var a;const A=Math.ceil(s*s/o),c=this._tex[this._tex.length-1-this._page];return e.programs.utils.copyKeypoints.outputs(o,A,c)(t),this._page=1-this._page,this._textureReader.readPixelsAsync(c,0,0,c.width,c.height,r).then((e=>{this._keypoints=this._decode(e,n,i,o,A)}))}_decode(e,n,i,s,r){const o=p.MIN_KEYPOINT_SIZE+n+i,a=p.LOG2_PYRAMID_MAX_SCALE,A=p.PYRAMID_MAX_LEVELS,c=Math.PI/255,d=[],h=this._includeDiscarded;let u,g,f,I,m,_,y,x,C=ri,E=ri;if(n%4!=0||i%4!=0)throw new l.qw(`Invalid descriptorSize (${n}) / extraSize (${i})`);const S=s*r*4,P=e.byteLength;P!=S&&t.A.warning(`Expected ${S} bytes when decoding a set of keypoints, found ${P}`),n+i>0&&(e=new Uint8Array(e));for(let s=0;s<P&&(u=e[s+1]<<8|e[s],g=e[s+3]<<8|e[s+2],f=e[s+5]<<8|e[s+4],I=e[s+7]<<8|e[s+6],65535!=u||65535!=g);s+=o)u+g+f+I!=0?i>0&&(E=e.subarray(8+s,8+s+i),E.byteLength<i)?t.A.warning(`KeypointSink: expected ${i} extra bytes when decoding the ${s/o}-th keypoint, found ${E.byteLength} instead`):n>0&&(C=e.subarray(8+s+i,8+s+i+n),C.byteLength<n)?t.A.warning(`KeypointSink: expected ${n} descriptor bytes when decoding the ${s/o}-th keypoint, found ${C.byteLength} instead`):(u/=p.FIX_RESOLUTION,g/=p.FIX_RESOLUTION,m=e[s+4]<255?-a+(a+A)*e[s+4]/255:0,_=(2*e[s+5]-255)*c,y=t.A.decodeFloat16(I),x=this._createKeypoint(u,g,m,_,y,C,E),d.push(x)):h&&d.push(null);return d}_createKeypoint(e,t,n,i,s,r,o){throw new l.aQ}_allocateExtra(e,n,i,s,r,o,a){t.A.assert(0===r),t.A.assert(o===s&&a>0&&a%4==0);const A=i.width,c=Vn.encoderCapacity(s,r,A),l=Vn.encoderLength(c,o,a);return e.programs.keypoints.allocateExtra.outputs(l,l,n)(i,s,r,A,o,a,l)}}class ai extends oi{constructor(e="keypoints"){super(e,0,[tn().expects(Ut.Keypoints)])}_createKeypoint(e,t,n,i,s,r,o){const a=r.byteLength>0?new si(r):null;return new dn(e,t,n,i,s,a)}}class Ai extends oi{constructor(e="keypoints"){super(e,2,[tn().expects(Ut.Keypoints).satisfying((e=>0==e.extraSize)),tn("flow").expects(Ut.Vector2)])}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),{vectors:r}=this.input("flow").read(),o=n,a=this._allocateExtra(e,this._tex[0],t,n,i,o,4),A=a.width,c=e.programs.keypoints.transferToExtra.outputs(A,A,this._tex[1])(r,r.width,a,o,4,A);return this._download(e,c,o,4,A)}_createKeypoint(e,n,i,s,r,o,a){const A=o.byteLength,c=(a.byteLength,A>0?new si(o):null),l=t.A.decodeFloat16(a[1]<<8|a[0]),d=t.A.decodeFloat16(a[3]<<8|a[2]),h=new Nt(l,d);return new hn(e,n,i,s,r,c,h)}}class ci extends oi{constructor(e="keypoints"){super(e,2,[tn().expects(Ut.Keypoints).satisfying((e=>0==e.extraSize)),tn("matches").expects(Ut.KeypointMatches)])}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),{encodedMatches:r,matchesPerKeypoint:o}=this.input("matches").read(),a=n,A=4*o,c=this._allocateExtra(e,this._tex[0],t,n,i,a,A),l=c.width,d=e.programs.keypoints.transferToExtra.outputs(l,l,this._tex[1])(r,r.width,c,a,A,l);return this._download(e,d,a,A,l)}_createKeypoint(e,t,n,i,s,r,o){const a=r.byteLength,A=o.byteLength,c=a>0?new si(r):null,l=A/4,d=new Array(l);for(let e=0;e<l;e++){const t=4*e,n=o[t]|o[t+1]<<8|o[t+2]<<16|o[t+3]<<24,i=new ln(n&p.MATCH_INDEX_MASK,n>>>p.MATCH_INDEX_BITS);d[e]=i}return new pn(e,t,n,i,s,c,d)}}const li=p.MAX_ENCODER_CAPACITY;class di extends an{constructor(e=void 0){super(e,4,[tn().expects(Ut.Keypoints),nn().expects(Ut.Keypoints)]),this._size=li}get size(){return this._size}set size(e){this._size=Math.max(0,Math.min(0|e,li))}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),r=e.programs.keypoints,o=this._size,a=this._tex,A=this._tex[3],c=Vn.encoderCapacity(n,i,s),l=Math.ceil(c/32),d=32*l,h=Math.min(c,o),p=Vn.encoderLength(h,n,i);r.sortCreatePermutation.outputs(32,l,a[0]);let u=r.sortCreatePermutation(t,n,i,s);const g=Math.ceil(Math.log2(d));r.sortMergePermutation.outputs(32,l,a[1],a[2]);for(let e=1;e<=g;e++){const t=1<<e,n=e<<1;u=r.sortMergePermutation(u,t,n)}r.sortApplyPermutation.outputs(p,p,A),r.sortApplyPermutation(u,h,t,n,i),this.output().swrite(A,n,i,p)}}class hi extends an{constructor(e=void 0){super(e,5,[tn().expects(Ut.Keypoints),nn().expects(Ut.Keypoints)]),this._imageSize=new zt(0,0),this._borderSize=new Nt(0,0)}get imageSize(){return this._imageSize}set imageSize(e){this._imageSize=e}get borderSize(){return this._borderSize}set borderSize(e){this._borderSize=e}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),r=e.programs.keypoints,o=this._imageSize,a=this._borderSize,A=o.width,c=o.height,d=a.x,h=a.x,p=a.y,u=a.y,g=this._tex;if(0==A||0==c)throw new l.Er("BorderClipper: did you forget to set the image size?");const f=Vn.encoderCapacity(n,i,s),I=Math.max(1,Math.ceil(Math.sqrt(f)));r.clipBorder.outputs(s,s,g[0]),r.mixKeypointsInit.outputs(I,I,g[1]),r.mixKeypointsSort.outputs(I,I,g[2],g[3]),r.mixKeypointsApply.outputs(s,s,g[4]);let m=r.clipBorder(A,c,p,h,u,d,t,n,i,s),_=r.mixKeypointsInit(m,n,i,s,f);for(let e=1;e<f;e*=2)_=r.mixKeypointsSort(_,e);m=r.mixKeypointsApply(_,m,n,i,s),this.output().swrite(m,n,i,s)}}class pi extends an{constructor(e=void 0){super(e,2,[tn().expects(Ut.Keypoints),nn().expects(Ut.Keypoints)]),this._pageIndex=0,this._initialized=!1,this._previousDescriptorSize=0,this._previousExtraSize=0,this._previousEncoderLength=0,this._frozen=!1}get frozen(){return this._frozen}set frozen(e){this._frozen=Boolean(e)}release(e){this._initialized=!1,super.release(e)}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),r=this._previousDescriptorSize,o=this._previousExtraSize,a=this._previousEncoderLength,A=this._tex,c=A[1-this._pageIndex],l=A[this._pageIndex];if(this._frozen&&this._initialized||(this._previousDescriptorSize=n,this._previousExtraSize=i,this._previousEncoderLength=s,c.resize(s,s),t.copyTo(c),this._pageIndex=1-this._pageIndex),!this._initialized)return this._initialized=!0,void this.output().swrite(c,n,i,s);this.output().swrite(l,r,o,a)}}class ui extends an{constructor(e=void 0){super(e,5,[tn("in0").expects(Ut.Keypoints),tn("in1").expects(Ut.Keypoints),nn().expects(Ut.Keypoints)])}_run(e){const t=this.input("in0").read(),n=this.input("in1").read(),i=t.descriptorSize,s=t.extraSize,r=e.programs.keypoints,o=this._tex;if(t.descriptorSize!==n.descriptorSize||t.extraSize!=t.extraSize)throw new l.Er("Can't merge two sets of keypoints that have different formats");const a=Vn.encoderCapacity(t.descriptorSize,t.extraSize,t.encoderLength),A=Vn.encoderCapacity(n.descriptorSize,n.extraSize,n.encoderLength),c=a+A,d=Vn.encoderLength(c,i,s),h=Math.max(1,Math.ceil(Math.sqrt(c)));r.mixKeypointsPreInit.outputs(d,d,o[0]),r.mixKeypointsInit.outputs(h,h,o[1]),r.mixKeypointsSort.outputs(h,h,o[2],o[3]),r.mixKeypointsApply.outputs(d,d,o[4]);let p=r.mixKeypointsPreInit(t.encodedKeypoints,n.encodedKeypoints,t.encoderLength,n.encoderLength,a,A,i,s,d),u=r.mixKeypointsInit(p,i,s,d,c);for(let e=1;e<c;e*=2)u=r.mixKeypointsSort(u,e);p=r.mixKeypointsApply(u,p,i,s,d),this.output().swrite(p,i,s,d)}}class gi extends an{constructor(e=void 0){super(e,6,[tn().expects(Ut.Keypoints),nn().expects(Ut.Keypoints)]),this._maxKeypoints=Number.NaN}get maxKeypoints(){return this._maxKeypoints}set maxKeypoints(e){Number.isNaN(e)?this._maxKeypoints=Number.NaN:this._maxKeypoints=Math.max(0,0|e)}_run(e){let{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read();const r=Vn.encoderCapacity(n,i,s),o=this._maxKeypoints,a=e.programs.keypoints.shuffle.definedConstant("PERMUTATION_MAXLEN"),A=Math.min(a,r),c=this._generatePermutation(A,a);t=e.programs.keypoints.shuffle.setUBO("Permutation",c).outputs(s,s,this._tex[0])(t,n,i,s),e.programs.keypoints.mixKeypointsInit.outputs(s,s,this._tex[1]),e.programs.keypoints.mixKeypointsSort.outputs(s,s,this._tex[2],this._tex[3]),e.programs.keypoints.mixKeypointsApply.outputs(s,s,this._tex[4]);let l=e.programs.keypoints.mixKeypointsInit(t,n,i,s,r);for(let t=1;t<r;t*=2)l=e.programs.keypoints.mixKeypointsSort(l,t);if(t=e.programs.keypoints.mixKeypointsApply(l,t,n,i,s),!Number.isNaN(o)&&o<r){const r=Vn.encoderLength(o,n,i);t=e.programs.keypoints.clip.outputs(r,r,this._tex[5])(t,n,i,s,o),s=r}this.output().swrite(t,n,i,s)}_generatePermutation(e,n=e){const i=new Int32Array(n),s=i.subarray(0,e).fill(-1),r=t.A.shuffle(t.A.range(e));for(let t=0,n=0;t<e;t++)if(s[t]<0){do{s[t]=r[n++]}while(s[t]<t);s[s[t]]=t}return i}}const fi=["in0","in1"];class Ii extends an{constructor(e=void 0){super(e,0,[...fi.map((e=>tn(e).expects(Ut.Keypoints))),nn().expects(Ut.Keypoints)]),this._port=0}get port(){return this._port}set port(e){if(e<0||e>=fi.length)throw new l.qw(`Invalid port: ${e}`);this._port=0|e}_run(e){const t=this.input(fi[this._port]).read();this.output().write(t)}}class mi extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Keypoints),nn().expects(Ut.Keypoints)]),this._transform=Xt.SpeedyMatrix.Create(3,3,[1,0,0,0,1,0,0,0,1])}get transform(){return this._transform}set transform(e){if(3!=e.rows||3!=e.columns)throw new l.qw(`Not a 3x3 transformation matrix: ${e}`);this._transform=e}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),r=this._tex[0],o=this._transform.read();e.programs.keypoints.applyHomography.outputs(t.width,t.height,r)(o,t,n,i,s),this.output().swrite(r,n,i,s)}}const _i=Object.freeze({quadratic1d:"subpixelQuadratic1d",taylor2d:"subpixelTaylor2d","bicubic-upsample":"subpixelBicubic","bilinear-upsample":"subpixelBilinear"});class yi extends an{constructor(e=void 0){super(e,2,[tn("image").expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),tn("keypoints").expects(Ut.Keypoints),nn().expects(Ut.Keypoints),nn("displacements").expects(Ut.Vector2)]),this._method="quadratic1d",this._maxIterations=6,this._epsilon=.1}get method(){return this._method}set method(e){if(!Object.prototype.hasOwnProperty.call(_i,e))throw new l.qw(`Invalid method: "${e}"`);this._method=e}get maxIterations(){return this._maxIterations}set maxIterations(e){this._maxIterations=Math.max(0,+e)}get epsilon(){return this._epsilon}set epsilon(e){this._epsilon=Math.max(0,+e)}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input("keypoints").read(),{image:r,format:o}=this.input("image").read(),a=this._tex,A=_i[this._method],c=this._maxIterations,l=this._epsilon,d=Vn.encoderCapacity(n,i,s),h=Math.max(1,Math.ceil(Math.sqrt(d))),p=e.programs.keypoints[A].outputs(h,h,a[0])(r,t,n,i,s,c,l),u=e.programs.keypoints.transferFlow.outputs(s,s,a[1])(p,t,n,i,s);this.output().swrite(u,n,i,s),this.output("displacements").swrite(p)}}class xi extends ei{constructor(e=void 0){super(e,5,[tn().expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),nn().expects(Ut.Keypoints)]),this._threshold=20}get threshold(){return this._threshold}set threshold(e){this._threshold=Math.max(0,Math.min(0|e,255))}_run(e){const{image:t,format:n}=this.input().read(),i=t.width,s=t.height,r=this._tex,o=this._capacity,a=this._threshold,A=Math.log2(this.scaleFactor),c=this.levels;if(1!=c&&!t.hasMipmaps())throw new l.Er(`Expected a pyramid in ${this.fullName}`);if(0==o){const t=this._encodeZeroKeypoints(e,r[4]),n=t.width;return void this.output().swrite(t,0,0,n)}e.programs.keypoints.fast9_16.outputs(i,s,r[0],r[1]),e.programs.keypoints.nonmaxSpace.outputs(i,s,r[2]);let d=r[1].clear(),h=Math.max(1,Math.min(c,p.PYRAMID_MAX_LEVELS/A|0));for(let n=A*(h-1);h-- >0;n-=A)d=e.programs.keypoints.fast9_16(d,t,n,a);d=e.programs.keypoints.nonmaxSpace(d),c>1&&(d=e.programs.keypoints.nonmaxScaleSimple.outputs(i,s,r[1])(d,t,A));let u=this._encodeKeypoints(e,d,r[3]);const g=u.width;c>1&&(u=e.programs.keypoints.refineScaleFAST916.outputs(g,g,r[4])(t,A,u,0,0,g,a)),this.output().swrite(u,0,0,g)}}const Ci=Object.freeze({1:"harris1",3:"harris3",5:"harris5",7:"harris7"});class Ei extends ei{constructor(e=void 0){super(e,6,[tn().expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),nn().expects(Ut.Keypoints)]),this._windowSize=new zt(3,3),this._quality=.1}get quality(){return this._quality}set quality(e){this._quality=Math.max(0,Math.min(+e,1))}get windowSize(){return this._windowSize}set windowSize(e){const t=e.width;if(t!=e.height||1!=t&&3!=t&&5!=t&&7!=t)throw new l.qw(`Invalid window: ${e}. Acceptable sizes: 1x1, 3x3, 5x5, 7x7`);this._windowSize=e}_run(e){const{image:n,format:i}=this.input().read(),s=n.width,r=n.height,o=this._capacity,a=this._quality,A=this._windowSize.width,c=this.levels,d=Math.log2(this.scaleFactor),h=c>1?this.scaleFactor:1,u=e.programs.keypoints[Ci[A]],g=this._tex;if(1!=c&&!n.hasMipmaps())throw new l.Er(`Expected a pyramid in ${this.fullName}`);if(0==o){const t=this._encodeZeroKeypoints(e,g[5]),n=t.width;return void this.output().swrite(t,0,0,n)}u.outputs(s,r,g[0],g[1]),e.programs.utils.sobelDerivatives.outputs(s,r,g[2]),e.programs.keypoints.nonmaxSpace.outputs(s,r,g[3]);let f=g[1].clear(),I=Math.max(1,Math.min(c,p.PYRAMID_MAX_LEVELS/d|0));for(let i=d*(I-1);I-- >0;i-=d){const s=t.A.gaussianKernel(h*(1+i),A);f=u(f,n,e.programs.utils.sobelDerivatives(n,i),i,d,s),f=e.programs.keypoints.nonmaxSpace(f)}if(c>1){const t=e.programs.keypoints.laplacian.outputs(s,r,g[0])(f,n,d,0);f=e.programs.keypoints.nonmaxScale.outputs(s,r,g[2])(f,n,t,d)}e.programs.keypoints.harrisScoreFindMax.outputs(s,r,g[0],g[1]),I=Math.ceil(Math.log2(Math.max(s,r)));let m=f;for(let t=0;t<I;t++)m=e.programs.keypoints.harrisScoreFindMax(m,t);f=e.programs.keypoints.harrisScoreCutoff.outputs(s,r,m==g[0]?g[1]:g[0])(f,m,a);let _=this._encodeKeypoints(e,f,g[4]);const y=_.width;c>1&&(_=e.programs.keypoints.refineScaleLoG.outputs(y,y,g[5])(n,d,_,0,0,y)),this.output().swrite(_,0,0,y)}}class Si extends an{constructor(e=void 0,t=0,n=void 0){super(e,t+1,n)}_allocateDescriptors(e,n,i,s,r,o){t.A.assert(n>=0&&i>=0),t.A.assert(s>=0&&s%4==0&&r===i);const a=o.width,A=Vn.encoderCapacity(n,i,a),c=Vn.encoderLength(A,s,r),l=this._tex[this._tex.length-1];return e.programs.keypoints.allocateDescriptors.outputs(c,c,l)(o,n,i,a,s,r,c)}}class Pi extends Si{constructor(e=void 0){super(e,3,[tn("image").expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),tn("keypoints").expects(Ut.Keypoints),nn().expects(Ut.Keypoints)])}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input("keypoints").read(),r=this.input("image").read().image,o=this._tex,a=this._tex[2],A=Vn.encoderCapacity(n,i,s),c=Math.max(1,Math.ceil(Math.sqrt(A))),l=e.programs.keypoints.orbOrientation.outputs(c,c,o[0])(r,t,n,i,s),d=e.programs.keypoints.transferOrientation.outputs(s,s,o[1])(l,t,n,i,s),h=this._allocateDescriptors(e,n,i,32,i,d),p=h.width,u=e.programs.keypoints.orbDescriptor.outputs(p,p,a)(r,h,i,p);this.output().swrite(u,32,i,p)}}const vi=new zt(11,11),wi=Math.min(3,p.PYRAMID_MAX_LEVELS),Bi={3:"lk3",5:"lk5",7:"lk7",9:"lk9",11:"lk11",13:"lk13",15:"lk15",17:"lk17",19:"lk19",21:"lk21"};class bi extends an{constructor(e=void 0){super(e,3,[tn("previousImage").expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),tn("nextImage").expects(Ut.Image).satisfying((e=>e.format===St.f5.GREY)),tn("previousKeypoints").expects(Ut.Keypoints),nn().expects(Ut.Keypoints),nn("flow").expects(Ut.Vector2)]),this._windowSize=vi,this._levels=wi,this._discardThreshold=1e-4,this._numberOfIterations=30,this._epsilon=.01}get windowSize(){return this._windowSize}set windowSize(e){if(e.width!=e.height)throw new l.EM(`LK: window ${this._windowSize.toString()} is not square!`);if(!Object.prototype.hasOwnProperty.call(Bi,e.width)){const e=Object.keys(Bi).sort(((e,t)=>e-t)).map((e=>e+"x"+e)).join(", ");throw new l.EM(`LK: window of size ${this._windowSize.toString()} is not supported! Supported sizes: ${e}`)}this._windowSize=e}get levels(){return this._levels}set levels(e){t.A.assert(e>=1&&e<=p.PYRAMID_MAX_LEVELS),this._levels=0|e}get discardThreshold(){return this._discardThreshold}set discardThreshold(e){t.A.assert(e>=0),this._discardThreshold=+e}get numberOfIterations(){return this._numberOfIterations}set numberOfIterations(e){t.A.assert(e>=1),this._numberOfIterations=0|e}get epsilon(){return this._epsilon}set epsilon(e){t.A.assert(e>=0),this._epsilon=+e}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input("previousKeypoints").read(),r=this.input("previousImage").read().image,o=this.input("nextImage").read().image,a=t,A=this._levels,c=this._windowSize.width,d=this._numberOfIterations,h=this._discardThreshold,p=this._epsilon,u=e.programs.keypoints,g=this._tex;if(!(1==A||r.hasMipmaps()&&o.hasMipmaps()))throw new l.Er("LK: a pyramid is required if levels > 1");if(r.width!==o.width||r.height!==o.height)throw new l.Er("LK: can't use input images of different size");const f=u[Bi[c]],I=Vn.encoderCapacity(n,i,s),m=Math.max(1,Math.ceil(Math.sqrt(I)));f.outputs(m,m,g[0],g[1]);let _=f.clear();for(let e=A-1;e>=0;e--)_=f(_,a,o,r,e,A,d,h,p,n,i,s);u.transferFlow.outputs(s,s,g[2]);const y=u.transferFlow(_,a,n,i,s);this.output().swrite(y,n,i,s),this.output("flow").swrite(_)}}class Qi extends An{constructor(e=void 0){super(e,2,[nn().expects(Ut.LSHTables)]),this._keypoints=[],this._keypointsCopy=[],this._numberOfTables=8,this._hashSize=15,this._lsh=null}get keypoints(){return this._keypoints}set keypoints(e){if(!Array.isArray(e)||e.find((e=>!(e instanceof dn))))throw new l.qw("Static LSH tables: an invalid set of keypoints has been provided");this._keypoints!==e&&(this._keypoints=e,this._keypointsCopy=e.slice(0),this._lsh=null)}get numberOfTables(){return this._numberOfTables}set numberOfTables(e){if(!j.includes(e))throw new l.qw(`Invalid number of tables: ${e}. Acceptable values: ${j.join(", ")}`);e!==this._numberOfTables&&(this._numberOfTables=0|e,this._lsh=null)}get hashSize(){return this._hashSize}set hashSize(e){if(!Z.includes(e))throw new l.qw(`Invalid hash size: ${e}. Acceptable values: ${Z.join(", ")}`);e!==this._hashSize&&(this._hashSize=0|e,this._lsh=null)}_run(e){null==this._lsh&&(this._lsh=this._train()),this.output().swrite(this._lsh)}_train(){const e=this._keypointsCopy,t=this._numberOfTables,n=this._hashSize;if(e.find((e=>null==e.descriptor)))throw new l.Er("Static LSH tables: can't train the model with no keypoint descriptors!");const i=e.map((e=>e.descriptor.data)),s=this._tex[0],r=this._tex[1];return new se(s,r,i,t,n)}}const Mi={fastest:0,default:1,demanding:2},Di=$.reduce(((e,t)=>(e[t]=(e=>{return t=t=>{return n=n=>`lshKnn${e}h${t}lv${n}`,[0,1,2].reduce(((e,t)=>(e[t]=n(t),e)),{});var n},Z.reduce(((e,n)=>(e[n]=t(n),e)),{});var t})(t),e)),{});class ki extends an{constructor(e=void 0){super(e,6,[tn("keypoints").expects(Ut.Keypoints).satisfying((e=>e.descriptorSize>0)),tn("lsh").expects(Ut.LSHTables),nn().expects(Ut.KeypointMatches)]),this._k=1,this._quality="default"}get k(){return this._k}set k(e){this._k=Math.max(1,0|e)}get quality(){return this._quality}set quality(e){if(!Object.prototype.hasOwnProperty.call(Mi,e))throw new l.qw(`Invalid quality level: "${e}"`);this._quality=e}_run(e){const{encodedKeypoints:n,descriptorSize:i,extraSize:s,encoderLength:r}=this.input("keypoints").read(),o=this.input("lsh").read().lsh,a=e.programs.keypoints,A=o.tables,c=o.descriptorDB,d=A.width,h=c.width,p=o.tableCount,u=o.hashSize,g=o.bucketCapacity,f=o.bucketsPerTable,I=o.sequences,m=this._tex[0],_=this._tex[1],y=this._tex[2],x=this._tex[3],C=this._tex[4],E=this._tex[5],S=Mi[this._quality],P=this._k;if(i!==o.descriptorSize)throw new l.qw(`Can't match different types of descriptors in ${this.fullName}`);t.A.assert(null!=Di[i]),t.A.assert(null!=Di[i][u]),t.A.assert(null!=Di[i][u][S]);const v=Vn.encoderCapacity(i,s,r),w=Math.max(1,Math.ceil(Math.sqrt(v*P)));let B=E;a.lshKnnTransfer.outputs(w,w,C,E);const b=Math.max(1,Math.ceil(Math.sqrt(v)));a.lshKnnInitCandidates.outputs(b,b,m),a.lshKnnInitFilters.outputs(b,b,x);const Q=a[Di[i][u][S]];Q.outputs(b,b,_,y),Q.setUBO("LSHSequences",I),B.clear(),a.lshKnnInitFilters();for(let t=0;t<P;t++){let o=a.lshKnnInitCandidates();for(let t=0;t<p;t++)o=Q(o,x,b,A,c,t,g,f,d,h,n,i,s,r),e.gl.flush();o.copyTo(x),B=a.lshKnnTransfer(B,o,P,t)}this.output().swrite(B,P)}}const Ki={32:"bfMatcher32",64:"bfMatcher64"};class zi extends an{constructor(e=void 0){super(e,6,[tn("keypoints").expects(Ut.Keypoints).satisfying((e=>e.descriptorSize>0)),tn("database").expects(Ut.Keypoints).satisfying((e=>e.descriptorSize>0)),nn().expects(Ut.KeypointMatches)]),this._matchesPerKeypoint=1}get k(){return this._matchesPerKeypoint}set k(e){this._matchesPerKeypoint=Math.max(1,0|e)}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input("keypoints").read(),r=this.input("database").read(),o=this._tex[0],a=this._tex[1],A=this._tex[2],c=this._tex[3],d=this._tex[4],h=this._tex[5],p=this._matchesPerKeypoint,u=e.programs.keypoints;if(n!==r.descriptorSize)throw new l.qw(`Incompatible descriptors in ${this.fullName}`);if(!Object.prototype.hasOwnProperty.call(Ki,n))throw new l.EM(`Unsupported descriptor size (${n}) in ${this.fullName}`);const g=u[Ki[n]],f=Vn.encoderCapacity(n,i,s),I=Vn.encoderCapacity(r.descriptorSize,r.extraSize,r.encoderLength),m=g.definedConstant("NUMBER_OF_KEYPOINTS_PER_PASS"),_=Math.ceil(I/m),y=Math.max(1,Math.ceil(Math.sqrt(f))),x=Math.max(1,Math.ceil(Math.sqrt(f*p)));u.bfMatcherTransfer.outputs(x,x,d,h),u.bfMatcherInitCandidates.outputs(y,y,A),u.bfMatcherInitFilters.outputs(y,y,c),g.outputs(y,y,o,a);let C=h.clear(),E=u.bfMatcherInitFilters();for(let o=0;o<p;o++){let a=u.bfMatcherInitCandidates();for(let o=0;o<_;o++)a=g(a,E,y,r.encodedKeypoints,r.descriptorSize,r.extraSize,r.encoderLength,t,n,i,s,o),e.gl.flush();p>1&&a.copyTo(E),C=u.bfMatcherTransfer(C,a,p,o)}this.output().swrite(C,p)}}class Li extends an{constructor(e=void 0){super(e,1,[tn("in").expects(Ut.Keypoints),tn("reference").expects(Ut.Keypoints),nn().expects(Ut.Keypoints)]),this._threshold=p.MAX_TEXTURE_LENGTH+1}get threshold(){return this._threshold}set threshold(e){this._threshold=Math.max(0,+e)}_run(e){const t=this.input("in").read(),n=this.input("reference").read(),i=this._threshold;if(t.descriptorSize!=n.descriptorSize||t.extraSize!=n.extraSize)throw new l.Er("The distance filter requires two compatible shapes of keypoint streams");const s=this._tex[0],r=Math.max(t.encoderLength,n.encoderLength),o=t.descriptorSize,a=t.extraSize;e.programs.keypoints.distanceFilter.outputs(r,r,s)(t.encodedKeypoints,t.encoderLength,n.encodedKeypoints,n.encoderLength,o,a,r,i),this.output().swrite(s,o,a,r)}}const Ti={32:"hammingDistanceFilter32",64:"hammingDistanceFilter64"};class Ri extends an{constructor(e=void 0){super(e,1,[tn("in").expects(Ut.Keypoints).satisfying((e=>e.descriptorSize>0)),tn("reference").expects(Ut.Keypoints).satisfying((e=>e.descriptorSize>0)),nn().expects(Ut.Keypoints)]),this._threshold=8*p.MAX_DESCRIPTOR_SIZE}get threshold(){return this._threshold}set threshold(e){this._threshold=Math.max(0,0|e)}_run(e){const t=this.input("in").read(),n=this.input("reference").read(),i=this._threshold;if(t.descriptorSize!=n.descriptorSize||t.extraSize!=n.extraSize)throw new l.Er("The Hamming distance filter requires two compatible shapes of keypoint streams");if(!Object.prototype.hasOwnProperty.call(Ti,t.descriptorSize))throw new l.EM(`Hamming distance filter - invalid descriptor size: ${t.descriptorSize}`);const s=this._tex[0],r=Math.max(t.encoderLength,n.encoderLength),o=t.descriptorSize,a=t.extraSize,A=Ti[t.descriptorSize];e.programs.keypoints[A].outputs(r,r,s)(t.encodedKeypoints,t.encoderLength,n.encodedKeypoints,n.encoderLength,o,a,r,i),this.output().swrite(s,o,a,r)}}class Ni extends an{constructor(e=void 0){super(e,1,[tn().expects(Ut.Keypoints)]),this._descriptorSize=0,this._extraSize=0,this._encoderLength=0,this._initialized=!1}get encodedKeypoints(){if(!this._initialized)throw new l.Er(`Portal error: ${this.fullName} holds no data`);return this._tex[0]}get descriptorSize(){if(!this._initialized)throw new l.Er(`Portal error: ${this.fullName} holds no data`);return this._descriptorSize}get extraSize(){if(!this._initialized)throw new l.Er(`Portal error: ${this.fullName} holds no data`);return this._extraSize}get encoderLength(){if(!this._initialized)throw new l.Er(`Portal error: ${this.fullName} holds no data`);return this._encoderLength}init(e){super.init(e);const t=Vn.encoderLength(0,0,0);this._tex[0].resize(t,t).clearToColor(1,1,1,1),this._descriptorSize=this._extraSize=0,this._encoderLength=t,this._initialized=!0}release(e){this._initialized=!1,super.release(e)}_run(e){const{encodedKeypoints:t,descriptorSize:n,extraSize:i,encoderLength:s}=this.input().read(),r=this._tex[0];r.resize(t.width,t.height),t.copyTo(r),this._descriptorSize=n,this._extraSize=i,this._encoderLength=s}}class Oi extends An{constructor(e=void 0){super(e,0,[nn().expects(Ut.Keypoints)]),this._source=null}get source(){return this._source}set source(e){if(null!==e&&!(e instanceof Ni))throw new l.qw(`Incompatible source for ${this.fullName}`);this._source=e}_run(e){if(null==this._source)throw new l.Er(`${this.fullName} has no source`);this.output().swrite(this._source.encodedKeypoints,this._source.descriptorSize,this._source.extraSize,this._source.encoderLength)}}class Fi extends J.Q{static FAST(e=void 0){return new xi(e)}static Harris(e=void 0){return new Ei(e)}}class Xi extends J.Q{static ORB(e=void 0){return new Pi(e)}}class Ui extends J.Q{static LK(e=void 0){return new bi(e)}}class Gi extends J.Q{static StaticLSHTables(e=void 0){return new Qi(e)}static LSHKNN(e=void 0){return new ki(e)}static BFKNN(e=void 0){return new zi(e)}}class qi extends J.Q{static Source(e=void 0){return new Oi(e)}static Sink(e=void 0){return new Ni(e)}}class Hi extends J.Q{static get Detector(){return Fi}static get Descriptor(){return Xi}static get Tracker(){return Ui}static get Matcher(){return Gi}static get Portal(){return qi}static Source(e=void 0){return new ii(e)}static Sink(e=void 0){return new ai(e)}static SinkOfTrackedKeypoints(e=void 0){return new Ai(e)}static SinkOfMatchedKeypoints(e=void 0){return new ci(e)}static Clipper(e=void 0){return new di(e)}static BorderClipper(e=void 0){return new hi(e)}static Buffer(e=void 0){return new pi(e)}static Mixer(e=void 0){return new ui(e)}static Shuffler(e=void 0){return new gi(e)}static Multiplexer(e=void 0){return new Ii(e)}static Transformer(e=void 0){return new mi(e)}static SubpixelRefiner(e=void 0){return new yi(e)}static DistanceFilter(e=void 0){return new Li(e)}static HammingDistanceFilter(e=void 0){return new Ri(e)}}const Yi=e=>e>1?1<<Math.ceil(Math.log2(e)):1;class Ji extends cn{constructor(e="vec2"){super(e,2,[tn().expects(Ut.Vector2)]),this._vectors=[],this._textureReader=new h,this._page=0,this._turbo=!1}get turbo(){return this._turbo}set turbo(e){this._turbo=Boolean(e)}init(e){super.init(e),this._textureReader.init(e)}release(e){this._textureReader.release(e),super.release(e)}export(){return r.i.resolve(this._vectors)}_run(e){const{vectors:t}=this.input().read(),n=this._turbo,i=t.width,s=Yi(i),r=Yi(Math.ceil(i*i/s)),o=this._tex[this._page];return e.programs.utils.copy2DVectors.outputs(s,r,o)(t),this._page=1-this._page,this._textureReader.readPixelsAsync(o,0,0,o.width,o.height,n).then((e=>{this._vectors=Ji._decode(e,s,r)}))}static _decode(e,n,i){const s=[];let r=0,o=0,a=0,A=0;const c=n*i*4,l=Math.min(e.length,c);for(let n=0;n<l&&(o=e[n+1]<<8|e[n],r=e[n+3]<<8|e[n+2],65535!=o||65535!=r);n+=4)65280==o&&65280==r||(a=t.A.decodeFloat16(o),A=t.A.decodeFloat16(r),s.push(new Nt(a,A)));return s}}let Wi=null;class ji{constructor(){if(this._fps=60,this._frames=0,this._updateInterval=500,this._lastUpdate=performance.now(),this._boundUpdate=this._update.bind(this),null!==Wi)throw new l.Er("Can't have multiple instances of FPSCounter");this._boundUpdate()}static get instance(){return null===Wi&&(Wi=new ji),Wi}get fps(){return this._fps}_update(){const e=performance.now(),t=e-this._lastUpdate;t>=this._updateInterval&&(this._fps=Math.round(this._frames/(.001*t)),this._frames=0,this._lastUpdate=e),this._frames++,requestAnimationFrame(this._boundUpdate)}}const Zi=new class extends Function{constructor(){return super("...args","return args.length > 1 ? this._create(...args) : this._from(args[0])"),this.bind(this)}_create(e,t=e,n=[]){return Xt.SpeedyMatrix.Create(e,t,n)}_from(e){return Xt.SpeedyMatrix.From(e)}Zeros(e,t=e){return Xt.SpeedyMatrix.Zeros(e,t)}Ones(e,t=e){return Xt.SpeedyMatrix.Ones(e,t)}Eye(e,t=e){return Xt.SpeedyMatrix.Eye(e,t)}ready(){return Xt.SpeedyMatrix.ready()}qr(e,t,n,{mode:i="reduced"}={}){const s=n,r=n.rows,o=n.columns;if("reduced"==i){if(e.rows!=r||e.columns!=o||t.rows!=o||t.columns!=o)throw new l.qw("Invalid shape for reduced QR")}else{if("full"!=i)throw new l.qw(`Invalid mode for QR: "${i}"`);if(e.rows!=r||e.columns!=r||t.rows!=r||t.columns!=o)throw new l.qw("Invalid shape for full QR")}return Ft.U.ready().then((({wasm:n,memory:r})=>{const o=Ft.U.allocateMat32(n,r,e),a=Ft.U.allocateMat32(n,r,t),A=Ft.U.allocateMat32(n,r,s);return Ft.U.copyToMat32(n,r,A,s),"reduced"==i?n.exports.Mat32_qr_reduced(o,a,A):n.exports.Mat32_qr_full(o,a,A),Ft.U.copyFromMat32(n,r,o,e),Ft.U.copyFromMat32(n,r,a,t),Ft.U.deallocateMat32(n,r,A),Ft.U.deallocateMat32(n,r,a),Ft.U.deallocateMat32(n,r,o),[e,t]}))}ols(e,t,n,{method:i="qr"}={}){const s=t.rows,r=t.columns,o=e;if(s<r||0==r)throw new l.qw("Can't solve an underdetermined system of equations");if(n.rows!=s||1!=n.columns||o.rows!=r||1!=o.columns)throw new l.qw("Invalid shapes");return Ft.U.ready().then((({wasm:s,memory:r})=>{const a=Ft.U.allocateMat32(s,r,t),A=Ft.U.allocateMat32(s,r,n),c=Ft.U.allocateMat32(s,r,o);if(Ft.U.copyToMat32(s,r,a,t),Ft.U.copyToMat32(s,r,A,n),"qr"!==i)throw new l.qw(`Invalid method: "${i}"`);return s.exports.Mat32_qr_ols(c,a,A,2),Ft.U.copyFromMat32(s,r,c,o),Ft.U.deallocateMat32(s,r,c),Ft.U.deallocateMat32(s,r,A),Ft.U.deallocateMat32(s,r,a),e}))}solve(e,t,n,{method:i="qr"}={}){const s=t.rows,r=t.columns,o=e;if(s!=r)throw new l.qw("Can't solve an over or underdetermined system of equations");if(n.rows!=s||1!=n.columns||o.rows!=s||1!=o.columns)throw new l.qw("Invalid shapes");return Ft.U.ready().then((({wasm:e,memory:s})=>{if("qr"===i)return this.ols(o,t,n,{method:i});throw new l.qw(`Invalid method: "${i}"`)}))}perspective(e,t,n){if(2!=t.rows||4!=t.columns||2!=n.rows||4!=n.columns)throw new l.qw("You need two 2x4 input matrices to compute a perspective transformation");if(3!=e.rows||3!=e.columns)throw new l.qw("The output of perspective() is a 3x3 homography");return Ft.U.ready().then((({wasm:i,memory:s})=>{const r=Ft.U.allocateMat32(i,s,e),o=Ft.U.allocateMat32(i,s,t),a=Ft.U.allocateMat32(i,s,n);return Ft.U.copyToMat32(i,s,o,t),Ft.U.copyToMat32(i,s,a,n),i.exports.Mat32_homography_ndlt4(r,o,a),Ft.U.copyFromMat32(i,s,r,e),Ft.U.deallocateMat32(i,s,a),Ft.U.deallocateMat32(i,s,o),Ft.U.deallocateMat32(i,s,r),e}))}findHomography(e,n,i,{method:s="default",mask:r=null,reprojectionError:o=3,numberOfHypotheses:a=512,bundleSize:A=128}={}){if(2!=n.rows||n.columns<4||2!=i.rows||i.columns!=n.columns)throw new l.qw("You need two 2 x n (n >= 4) input matrices to compute a homography");if(3!=e.rows||3!=e.columns)throw new l.qw("The output of findHomography() is a 3x3 homography");if(null!=r&&(1!=r.rows||r.columns!=n.columns))throw new l.qw("Invalid shape of the inliers mask");return Ft.U.ready().then((({wasm:c,memory:d})=>{const h=Ft.U.allocateMat32(c,d,e),p=Ft.U.allocateMat32(c,d,n),u=Ft.U.allocateMat32(c,d,i),g=null!=r?Ft.U.allocateMat32(c,d,r):0;switch(Ft.U.copyToMat32(c,d,p,n),Ft.U.copyToMat32(c,d,u,i),s){case"pransac":t.A.assert(o>=0&&a>0&&A>0),c.exports.Mat32_pransac_homography(h,g,p,u,a,A,o);break;case"default":case"dlt":c.exports.Mat32_homography_ndlt(h,p,u);break;default:throw new l.qw(`Illegal method for findHomography(): "${s}"`)}return Ft.U.copyFromMat32(c,d,h,e),null!=r&&Ft.U.copyFromMat32(c,d,g,r),null!=r&&Ft.U.deallocateMat32(c,d,g),Ft.U.deallocateMat32(c,d,u),Ft.U.deallocateMat32(c,d,p),Ft.U.deallocateMat32(c,d,h),e}))}applyPerspectiveTransform(e,t,n){if(2!=t.rows||2!=e.rows||t.columns!=e.columns)throw new l.qw("Invalid shapes");if(3!=n.rows||3!=n.columns)throw new l.qw("The perspective transformation must be a 3x3 matrix");return Ft.U.ready().then((({wasm:i,memory:s})=>{const r=Ft.U.allocateMat32(i,s,n),o=Ft.U.allocateMat32(i,s,t),a=Ft.U.allocateMat32(i,s,e);return Ft.U.copyToMat32(i,s,o,t),Ft.U.copyToMat32(i,s,r,n),i.exports.Mat32_transform_perspective(a,o,r),Ft.U.copyFromMat32(i,s,a,e),Ft.U.deallocateMat32(i,s,a),Ft.U.deallocateMat32(i,s,o),Ft.U.deallocateMat32(i,s,r),e}))}affine(e,t,n){if(2!=t.rows||3!=t.columns||2!=n.rows||3!=n.columns)throw new l.qw("You need two 2x3 input matrices to compute an affine transform");if(2!=e.rows||3!=e.columns)throw new l.qw("The output of affine() is a 2x3 matrix");return Ft.U.ready().then((({wasm:i,memory:s})=>{const r=Ft.U.allocateMat32(i,s,e),o=Ft.U.allocateMat32(i,s,t),a=Ft.U.allocateMat32(i,s,n);return Ft.U.copyToMat32(i,s,o,t),Ft.U.copyToMat32(i,s,a,n),i.exports.Mat32_affine_direct3(r,o,a),Ft.U.copyFromMat32(i,s,r,e),Ft.U.deallocateMat32(i,s,a),Ft.U.deallocateMat32(i,s,o),Ft.U.deallocateMat32(i,s,r),e}))}findAffineTransform(e,n,i,{method:s="default",mask:r=null,reprojectionError:o=3,numberOfHypotheses:a=512,bundleSize:A=128}={}){if(2!=n.rows||n.columns<3||2!=i.rows||i.columns!=n.columns)throw new l.qw("You need two 2 x n (n >= 3) input matrices to compute an affine transform");if(2!=e.rows||3!=e.columns)throw new l.qw("The output of findAffineTransform() is a 2x3 matrix");if(null!=r&&(1!=r.rows||r.columns!=n.columns))throw new l.qw("Invalid shape of the inliers mask");return Ft.U.ready().then((({wasm:c,memory:d})=>{const h=Ft.U.allocateMat32(c,d,e),p=Ft.U.allocateMat32(c,d,n),u=Ft.U.allocateMat32(c,d,i),g=null!=r?Ft.U.allocateMat32(c,d,r):0;switch(Ft.U.copyToMat32(c,d,p,n),Ft.U.copyToMat32(c,d,u,i),s){case"pransac":t.A.assert(o>=0&&a>0&&A>0),c.exports.Mat32_pransac_affine(h,g,p,u,a,A,o);break;case"default":c.exports.Mat32_affine_direct(h,p,u);break;default:throw new l.qw(`Illegal method for findAffineTransform(): "${s}"`)}return Ft.U.copyFromMat32(c,d,h,e),null!=r&&Ft.U.copyFromMat32(c,d,g,r),null!=r&&Ft.U.deallocateMat32(c,d,g),Ft.U.deallocateMat32(c,d,u),Ft.U.deallocateMat32(c,d,p),Ft.U.deallocateMat32(c,d,h),e}))}applyAffineTransform(e,t,n){if(2!=t.rows||2!=e.rows||t.columns!=e.columns)throw new l.qw("Invalid shapes");if(2!=n.rows||3!=n.columns)throw new l.qw("The affine transformation must be a 2x3 matrix");return Ft.U.ready().then((({wasm:i,memory:s})=>{const r=Ft.U.allocateMat32(i,s,n),o=Ft.U.allocateMat32(i,s,t),a=Ft.U.allocateMat32(i,s,e);return Ft.U.copyToMat32(i,s,o,t),Ft.U.copyToMat32(i,s,r,n),i.exports.Mat32_transform_affine(a,o,r),Ft.U.copyFromMat32(i,s,a,e),Ft.U.deallocateMat32(i,s,a),Ft.U.deallocateMat32(i,s,o),Ft.U.deallocateMat32(i,s,r),e}))}},$i=new class extends Function{constructor(){return super("...args","return this._create(...args)"),this.bind(this)}_create(e,t){return new Nt(e,t)}Sink(e=void 0){return new Ji(e)}};class Vi{static get version(){return"0.9.1"}static isSupported(){return"undefined"!=typeof WebAssembly&&"undefined"!=typeof WebGL2RenderingContext&&null!=e.c.instance.gl}static get Settings(){return s.w}static get Vector2(){return $i}static Point2(e,t){return new Ot(e,t)}static Size(e,t){return new zt(e,t)}static get Matrix(){return Zi}static get Promise(){return r.i}static Pipeline(){return new fn}static get Image(){return bn}static get Filter(){return Hn}static get Transform(){return jn}static get Keypoint(){return Hi}static load(e,t={}){return Tt.load(e,t)}static camera(e=640,n=360){const i="object"==typeof e?e:{audio:!1,video:{width:0|e,height:0|n}};return t.A.requestCameraStream(i).then((e=>Tt.load(e)))}static get Platform(){return Rt}static get fps(){return ji.instance.fps}}Object.freeze(Vi),t.A.log(`Speedy Vision version ${Vi.version}. GPU-accelerated Computer Vision for JavaScript by Alexandre Martins. https://github.com/alemart/speedy-vision`),p.LITTLE_ENDIAN||t.A.warning("Running on a big-endian machine")})(),i=i.default})(),e.exports=t()}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";n.d(i,{default:()=>Re});var e=n(774),t=n.n(e);class s extends Error{constructor(e="",t=null){super(e),this.cause=t}toString(){const e=this.cause?"\n-> "+this.cause.toString():"";return""!=this.message?this.name+": "+this.message+e:this.name+e}}class r extends s{get name(){return"IllegalArgumentError"}}class o extends s{get name(){return"IllegalOperationError"}}class a extends s{get name(){return"NotSupportedError"}}class A extends s{get name(){return"AccessDeniedError"}}class c extends s{get name(){return"TimeoutError"}}class l extends s{get name(){return"AssertionError"}}class d extends s{get name(){return"TrackingError"}}class h extends s{get name(){return"DetectionError"}}class p extends s{get name(){return"TrainingError"}}const u={xs:120,"xs+":144,sm:240,"sm+":288,md:320,"md+":360,lg:480,"lg+":600,xl:720,"xl+":900,xxl:1080};function g(e,n){const i=function(e){if(u.hasOwnProperty(e))return u[e];if(e.endsWith("p")){const t=e[0];if(t>="1"&&t<="9")return parseInt(e)}return Number.NaN}(e);let s=0,o=0;if(Number.isNaN(i))throw new r("Invalid resolution: "+e);if(n<=0)throw new r("Invalid aspect ratio: "+n);return n>=1?(o=i,s=Math.floor(o*n),s+=s%2):(s=i,o=Math.floor(s/n),o+=o%2),t().Size(s,o)}class f{static log(e,...t){console.log("[encantar-js]",e,...t)}static warning(e,...t){console.warn("[encantar-js]",e,...t)}static error(e,...t){console.error("[encantar-js]",e,...t)}static assert(e,t=""){if(!e)throw new l(t)}static range(e){if((e|=0)<0)throw new r;return Array.from({length:e},((e,t)=>t))}static wait(e){return new(t().Promise)((t=>{setTimeout(t,e)}))}static runInSequence(e){return e.reduce(((e,t)=>e.then((()=>t))),t().Promise.resolve())}static resolution(e,t){return g(e,t)}static platformString(){return(e=>"object"==typeof e.userAgentData?e.userAgentData.platform:e.platform)(navigator)}static isIOS(){return!!/(iOS|iPhone|iPad|iPod)/i.test(navigator.platform)||!(!/Mac/i.test(navigator.platform)||void 0===navigator.maxTouchPoints)&&navigator.maxTouchPoints>2}static isWebKit(){return!!/Apple/.test(navigator.vendor)||(!!/AppleWebKit\/.* Version\//.test(navigator.userAgent)||!!/(CriOS\/|FxiOS\/|EdgiOS\/)/.test(navigator.userAgent))}static deviceInfo(){return"Device info: "+JSON.stringify({isIOS:f.isIOS(),isWebKit:f.isWebKit(),renderer:t().Platform.renderer,vendor:t().Platform.vendor,screen:[screen.width,screen.height].join("x"),platform:[navigator.platform,navigator.vendor].join("; "),userAgent:navigator.userAgent,userAgentData:navigator.userAgentData||null},null,2)}}class I extends Event{constructor(e){super(e)}get type(){return super.type}}class m{constructor(){this._delegate=new EventTarget}addEventListener(e,t){this._delegate.addEventListener(e,t)}removeEventListener(e,t){this._delegate.removeEventListener(e,t)}dispatchEvent(e){return this._delegate.dispatchEvent(e)}}class _{constructor(){this._timeOfLastUpdate=this._now(),this._partialCycleCount=0,this._cyclesPerSecond=0}update(){const e=this._now();++this._partialCycleCount,e>=this._timeOfLastUpdate+500&&(this._cyclesPerSecond=this._partialCycleCount/.5,this._partialCycleCount=0,this._timeOfLastUpdate=e)}reset(){this._timeOfLastUpdate=this._now(),this._partialCycleCount=0,this._cyclesPerSecond=0}get cyclesPerSecond(){return this._cyclesPerSecond}_now(){return performance.now()}}const y=Object.freeze({default:"","low-power":"🔋","high-performance":"⚡"});class x{constructor(e){this._viewport=e,this._lastUpdate=0,this._container=this._createContainer(),e.hud.container.appendChild(this._container)}release(){this._container.remove()}update(e,t,n,i,s){e>=this._lastUpdate+500&&(this._lastUpdate=e,this._update(t,n,s,i))}get visible(){return!this._container.hidden}set visible(e){this._container.hidden=!e}_update(e,t,n,i){const s=this._label("_ar_fps");null!==s&&(s.style.color=this._color(n),s.innerText=String(n));const r=this._label("_ar_gpu");null!==r&&(r.style.color=this._color(i),r.innerText=String(i));const o=this._label("_ar_power");null!==o&&(o.innerHTML=y[D.powerPreference]);const a=this._label("_ar_in");if(null!==a){const e=t.map((e=>e._stats)).join(", ");a.innerText=e}const A=this._label("_ar_out");if(null!==A){const t=e.map((e=>e._stats)).join(", ");A.innerText=t}}_label(e){return this._container.getElementsByClassName(e).item(0)}_color(e){const t="#0f0",n="#f33",i=e>=50?t:e>=30?"#ff0":n,s=e>=30?t:n;return"low-power"!=D.powerPreference?i:s}_createContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.left=e.style.top="0px",e.style.zIndex="1000000",e.style.padding="0px",e.appendChild(this._createTitle()),e.appendChild(this._createContent()),e}_createTitle(){const e=document.createElement("div");return e.style.backgroundColor="#7e56c2",e.style.color="white",e.style.fontFamily="monospace",e.style.fontSize="14px",e.style.fontWeight="bold",e.style.padding="2px",e.innerText="encantar.js "+Re.version,e}_createContent(){const e=document.createElement("div"),t=t=>e.insertAdjacentHTML("beforeend",t);return e.style.backgroundColor="rgba(0,0,0,0.5)",e.style.color="white",e.style.fontFamily="monospace",e.style.fontSize="14px",e.style.padding="2px",e.style.whiteSpace="pre-line",t('FPS: <span class="_ar_fps"></span> | '),t('GPU: <span class="_ar_gpu"></span> '),t('<span class="_ar_power"></span>'),t("<br>"),t('IN: <span class="_ar_in"></span>'),t("<br>"),t('OUT: <span class="_ar_out"></span>'),e}}class C{constructor(){this._visible=!1,this._imageTrackerGizmos=new E}get visible(){return this._visible}set visible(e){this._visible=e}_render(e,t){if(this._visible)for(let n=0;n<t.length;n++)if("image-tracker"==t[n].type){const i=t[n]._output;this._imageTrackerGizmos.render(e,i)}}}class E{render(e,t){const n=e._backgroundCanvas.getContext("2d",{alpha:!1});if(!n)return;const i=e._realSize,s=t.screenSize,r=t.keypoints,o=t.polyline,a=t.cameraMatrix;void 0!==r&&void 0!==s&&this._splitAndRenderKeypoints(n,r,s,i),void 0!==o&&void 0!==s&&this._renderPolyline(n,o,s,i),void 0!==a&&void 0!==s&&this._renderAxes(n,a,s,i)}_splitAndRenderKeypoints(e,t,n,i,s=1){if(0==t.length)return;if(!Object.prototype.hasOwnProperty.call(t[0],"_matches"))return void this._renderKeypoints(e,t,n,i,"#f00",s);const r=t,o=r.filter((e=>this._isGoodMatch(e))),a=r.filter((e=>!this._isGoodMatch(e)));this._renderKeypoints(e,a,n,i,"#f00",s),this._renderKeypoints(e,o,n,i,"#0f0",s)}_isGoodMatch(e){const t=e.matches.length;return t>1?e.matches[0].index>=0&&e.matches[1].index>=0&&e.matches[0].distance<=.7*e.matches[1].distance:1==t&&e.matches[0].index>=0}_renderKeypoints(e,t,n,i,s="red",r=1){const o=i.width/n.width,a=i.height/n.height;e.beginPath();for(let n=t.length-1;n>=0;n--){const i=t[n],s=i.x*o+.5|0,A=i.y*a+.5|0,c=r*i.scale+.5|0;e.rect(s-c,A-c,2*c,2*c)}e.strokeStyle=s,e.lineWidth=1,e.stroke()}_renderPolyline(e,t,n,i,s="#0f0",r=2){if(0==t.length)return;const o=t.length,a=i.width/n.width,A=i.height/n.height;e.beginPath(),e.moveTo(t[o-1].x*a,t[o-1].y*A);for(let n=0;n<o;n++)e.lineTo(t[n].x*a,t[n].y*A);e.strokeStyle=s,e.lineWidth=r,e.stroke()}_renderAxes(e,t,n,i,s=4){const r=["#f00","#0f0","#00f"],o=i.width/n.width,a=i.height/n.height,A=t.read(),c=[A[9],A[10],A[11]],l=[[1*A[0]+A[9],1*A[1]+A[10],1*A[2]+A[11]],[1*A[3]+A[9],1*A[4]+A[10],1*A[5]+A[11]],[1*A[6]+A[9],1*A[7]+A[10],1*A[8]+A[11]]],d=c[0]/c[2],h=c[1]/c[2];for(let t=0;t<3;t++){const n=l[t],i=n[0]/n[2],A=n[1]/n[2];e.beginPath(),e.moveTo(d*o,h*a),e.lineTo(i*o,A*a),e.strokeStyle=r[t],e.lineWidth=s,e.stroke()}}}class S{constructor(e,t){this._session=e,this._results=t}get session(){return this._session}get results(){return this._results[Symbol.iterator]()}}class P{constructor(){this._scale=1,this._time=0,this._unscaledTime=0,this._delta=0,this._firstUpdate=0,this._lastUpdate=Number.POSITIVE_INFINITY}_update(e){e<this._lastUpdate?this._firstUpdate=this._lastUpdate=e:(this._delta=(e-this._lastUpdate)*this._scale,this._time+=this._delta,this._unscaledTime=e-this._firstUpdate,this._lastUpdate=e)}get elapsed(){return.001*this._time}get delta(){return.001*this._delta}get scale(){return this._scale}set scale(e){this._scale=Math.max(0,+e)}get unscaled(){return.001*this._unscaledTime}}const v=[],w=[],B="asap"+Math.random().toString(36).substr(1);window.addEventListener("message",(e=>{if(e.source!==window||e.data!==B)return;if(e.stopPropagation(),0==v.length)return;const t=v.pop(),n=w.pop();t.apply(void 0,n)}),!0);class b extends I{}const Q={mode:"immersive",trackers:[],sources:[],viewport:null,stats:!1,gizmos:!1};class M extends m{constructor(e,t,n,i,s){if(super(),this._mode=t,this._trackers=[],this._sources=e,this._updateStats=new _,this._renderStats=new _,this._active=!0,this._frameReady=!0,this._rafQueue=[],this._time=new P,this._gizmos=new C,this._gizmos.visible=s,"immersive"!=t&&"inline"!=t)throw new r(`Invalid session mode "${t}"`);this._primarySource=this._findPrimarySource(e),this._viewport=n,null!==this._primarySource?this._viewport._init((()=>this._primarySource._internalMedia.size),t):this._viewport._init((()=>f.resolution("sm",window.innerWidth/window.innerHeight)),t),this._setupUpdateLoop(),this._setupRenderLoop(),this._statsPanel=new x(this._viewport),this._statsPanel.visible=i,M._count++,f.log(`The ${t} session is now active!`)}static isSupported(){if(/(Mac|iOS|iPhone|iPad|iPod)/i.test(f.platformString())){const e=/(iPhone|iPad|iPod).* (CPU[\s\w]* OS|CPU iPhone|iOS) ([\d\._]+)/.exec(navigator.userAgent),t=/(AppleWebKit)\/.* (Version)\/([\d\.]+)/.exec(navigator.userAgent),n=t||e;if(null!==n){const e=n[3]||"0.0",[i,s]=e.split(/[\._]/).map((e=>0|parseInt(e)));if(i<15||15==i&&s<2)return f.error(`${n===t?"Safari":"iOS"} version ${e} is not supported! User agent: ${navigator.userAgent}`),!1}else f.warning(`Unrecognized user agent: ${navigator.userAgent}`)}return t().isSupported()}static instantiate(e=Q){const{mode:n=Q.mode,sources:i=Q.sources,trackers:s=Q.trackers,viewport:A=Q.viewport,stats:c=Q.stats,gizmos:l=Q.gizmos}=e;return f.log(`Starting a new ${n} session...`),t().Promise.resolve().then((()=>{if(!M.isSupported())throw new a("You need a browser/device compatible with WebGL2 and WebAssembly in order to experience Augmented Reality with encantar.js");if("inline"!==n&&M.count>0)throw new o("Can't start more than one immersive session");return t().Matrix.ready()})).then((()=>{for(let e=i.length-1;e>=0;e--)if(i.indexOf(i[e])<e)throw new r("Found repeated sources of data");return t().Promise.all(i.map((e=>e._init())))})).then((()=>{if(!A)throw new r("Can't create a session without a viewport");return new M(i,n,A,c,l)})).then((e=>{0==s.length&&f.warning("No trackers have been attached to the session!");for(let e=s.length-1;e>=0;e--)if(s.indexOf(s[e])<e)throw new r("Found repeated trackers");return t().Promise.all(s.map((t=>e._attachTracker(t)))).then((()=>e)).catch((e=>{throw e}))})).catch((e=>{throw f.error(`Can't start session: ${e.message}`),e}))}static get count(){return this._count}end(){return this._active?(f.log("Shutting down the session..."),this._active=!1,f.wait(100).then((()=>t().Promise.all(this._trackers.map((e=>e._release()))))).then((()=>t().Promise.all(this._sources.map((e=>e._release()))))).then((()=>{this._sources.length=0,this._trackers.length=0,this._updateStats.reset(),this._renderStats.reset(),this._statsPanel.release(),this._viewport._release(),M._count--;const e=new b("end");this.dispatchEvent(e),f.log("Session ended.")}))):t().Promise.resolve()}requestAnimationFrame(e){const t=Symbol("raf-handle");return this._active&&this._rafQueue.push([t,e]),t}cancelAnimationFrame(e){for(let t=this._rafQueue.length-1;t>=0;t--)if(this._rafQueue[t][0]===e){this._rafQueue.splice(t,1);break}}get mode(){return this._mode}get ended(){return!this._active}get time(){return this._time}get gizmos(){return this._gizmos}get viewport(){return this._viewport}get trackers(){return this._trackers[Symbol.iterator]()}get sources(){return this._sources[Symbol.iterator]()}_findPrimarySource(e){for(let t=0;t<e.length;t++)if("video"==e[t]._type)return e[t];for(let t=0;t<e.length;t++)if("canvas"==e[t]._type)return e[t];return f.warning("No primary source of data was found!"),null}_attachTracker(e){return this._trackers.indexOf(e)>=0?t().Promise.reject(new r("Duplicate tracker attached to the session")):this._active?(this._trackers.push(e),e._init(this)):t().Promise.reject(new o("Inactive session"))}_renderBackground(){const e=this._viewport._backgroundCanvas.getContext("2d",{alpha:!1});if(e){if(e.imageSmoothingEnabled=!1,null!==this._primarySource){const t=this._primarySource._internalMedia;this._renderMedia(e,t)}for(let t=0;t<this._trackers.length;t++){const n=this._trackers[t]._output.image;void 0!==n&&this._renderMedia(e,n)}this._gizmos._render(this._viewport,this._trackers)}}_renderMedia(e,t){const n=e.canvas;if("data"!=t.type){const i=t.source;e.drawImage(i,0,0,n.width,n.height)}else{const i=t.source;e.putImageData(i,0,0,0,0,n.width,n.height)}}_setupUpdateLoop(){const e=()=>{this._active&&("high-performance"==D.powerPreference?function(e,...t){v.unshift(e),w.unshift(t),window.postMessage(B,"*")}(n):window.requestAnimationFrame(n))},t=()=>{this._update().then(e).turbocharge()};function n(){"low-power"==D.powerPreference?window.requestAnimationFrame(t):t()}window.requestAnimationFrame(t)}_update(){return this._active?t().Promise.all(this._trackers.map((e=>e._update().turbocharge()))).then((()=>{this._updateStats.update(),this._frameReady=!0})).catch((e=>{f.error("Tracking error: "+e.toString(),e);const t=e.cause;if("GLError"==e.name)throw alert(e.message),alert(f.deviceInfo()),e;if("object"==typeof t&&"GLError"==t.name)throw alert(e.message),alert(t.message),alert(f.deviceInfo()),e})):(this._updateStats.reset(),t().Promise.resolve())}_setupRenderLoop(){let e=!1;const t=n=>{const i="low-power"==D.powerPreference;D.powerPreference;this._time._update(n),i&&(e=!e)||this._render(n,!1),this._active&&window.requestAnimationFrame(t)};window.requestAnimationFrame(t)}_render(e,t){if(this._active)if(this._frameReady){const n=this._trackers.map((e=>e._output.exports||{tracker:e,trackables:[]})),i=new S(this,n),s=this._rafQueue.slice(0);this._rafQueue.length=0,t||this._renderBackground();for(let t=0;t<s.length;t++)s[t][1].call(void 0,e,i);this._renderStats.update(),this._statsPanel.update(e,this._trackers,this._sources,this._updateStats.cyclesPerSecond,this._renderStats.cyclesPerSecond),this._frameReady=!1}else this._renderStats.update();else this._renderStats.reset()}}M._count=0;class D{static get powerPreference(){return this._powerPreference}static set powerPreference(e){if(M.count>0)throw new o("Can't change the powerPreference while there are active sessions going on");if("low-power"!=e&&"default"!=e&&"high-performance"!=e)throw new r(`Invalid powerPreference: "${e}"`);t().Settings.gpuPollingMode="high-performance"==e?"asap":"raf",this._powerPreference=e,f.log(`Changed the powerPreference to "${this._powerPreference}"`)}}D._powerPreference="default";class k{constructor(){this._capacity=100,this._database=[],this._locked=!1,this._busy=!1}get count(){return this._database.length}get capacity(){return this._capacity}set capacity(e){const t=Math.max(0,0|e);if(this.count>t)throw new r(`Can't set the capacity of the database to ${t}: it currently stores ${this.count} entries`);this._capacity=t}*[Symbol.iterator](){const e=this._database.map((e=>e.referenceImage));yield*e}add(e){if(0==e.length)return t().Promise.resolve();if(e.length>1){const t=e.map((e=>this.add([e])));return f.runInSequence(t)}const n=e[0];if(this._locked)throw new o(`Can't add reference image "${n.name}" to the database: it's locked`);if(this._busy)return f.wait(4).then((()=>this.add(e)));if(this.count>=this.capacity)throw new o(`Can't add reference image "${n.name}" to the database: the capacity of ${this.capacity} images has been exceeded.`);if(!(n.image instanceof HTMLImageElement||n.image instanceof HTMLCanvasElement||n.image instanceof ImageBitmap))throw new r(`Can't add reference image "${n.name}" to the database: invalid image`);if(void 0!==this._database.find((e=>e.referenceImage.name===n.name)))throw new r(`Can't add reference image "${n.name}" to the database: found duplicated name`);return this._busy=!0,t().load(n.image).then((e=>{this._busy=!1,this._database.push({referenceImage:Object.freeze(Object.assign(Object.assign({},n),{name:n.name||"target-"+Math.random().toString(16).substr(2)})),media:e})}))}_lock(){if(this._busy)throw new o("Can't lock the reference image database: we're busy loading an image");this._locked=!0}_findMedia(e){for(let t=0;t<this._database.length;t++)if(this._database[t].referenceImage.name===e)return this._database[t].media;throw new r(`Can't find reference image "${e}"`)}}const K=1024,z=.3,L=.5,T="low",R="bilinear-upsample",N=.18;class O{constructor(e,t){this._name=e,this._imageTracker=t,this._pipeline=this._createPipeline()}get name(){return this._name}get screenSize(){const e=this._pipeline.node("screen");if(!e)throw new o;return e.size}init(){}release(){return this._pipeline.release()}update(e,t){const n=this._pipeline.node("source"),i=this._pipeline.node("screen");if(!n||!i)throw new o;return n.media=e,i.size=t,this._beforeUpdate().then((()=>this._gpuUpdate())).then((e=>this._afterUpdate(e)))}onEnterState(e){}onLeaveState(){}_beforeUpdate(){return t().Promise.resolve()}_gpuUpdate(){return this._pipeline.run()}_findPolylineCoordinates(e,n){const i=n.width,s=n.height,r=t().Matrix(2,4,[0,0,i,0,i,s,0,s]),o=t().Matrix.Zeros(2,4);return t().Matrix.applyPerspectiveTransform(o,r,e)}_findPolyline(e,n){return this._findPolylineCoordinates(e,n).then((e=>{const n=e.read();return Array.from({length:4},((e,i)=>t().Point2(n[2*i],n[2*i+1])))}))}_mustRotateWarpedImage(e,t){const n=t.width/t.height,i=e.width/e.height;return i>=1.1&&n<.9||i<.9&&n>=1.1}_findRectificationMatrixOfFullscreenImage(e,n){const i=.15,s=n.width,r=n.height,o=e.width/e.height,a=this._mustRotateWarpedImage(e,n),A=a?1/o:o,c=s>=r?i*r:(r-.7*s/A)/2,l=s>=r?(s-.7*r*A)/2:i*s,d=s-l,h=r-c,p=t().Matrix(2,4,[l,c,d,c,d,h,l,h]),u=t().Matrix(2,4,[0,0,s,0,s,r,0,r]),g=t().Matrix.Eye(3),f=t().Matrix.Zeros(3),I=t().Matrix.Zeros(3);return(a?t().Matrix.perspective(g,u,t().Matrix(2,4,[0,r,0,0,s,0,s,r])):t().Promise.resolve(g)).then((e=>t().Matrix.perspective(f,u,p))).then((e=>I.setTo(f.times(g))))}_findRectificationMatrixOfCameraImage(e,n,i,s){const r=s.width,o=s.height,a=t().Matrix(2,4,[0,0,r,0,r,o,0,o]),A=t().Matrix.Zeros(3);return this._findPolylineCoordinates(e,n).then((e=>t().Matrix.perspective(A,e,a))).then((e=>this._findRectificationMatrixOfFullscreenImage(i,s))).then((e=>A.setTo(e.times(A))))}}class F extends O{constructor(e){super("initial",e)}_beforeUpdate(){return this._pipeline.node("source").media.size.area()<this.screenSize.area()&&f.warning("The resolution of the tracker is larger than the resolution of the video. This is inefficient."),t().Promise.resolve()}_afterUpdate(e){return t().Promise.resolve({nextState:"training",trackerOutput:{}})}_createPipeline(){const e=t().Pipeline(),n=t().Image.Source("source"),i=t().Transform.Resize("screen"),s=t().Filter.Greyscale(),r=t().Transform.PerspectiveWarp(),o=t().Filter.Nightvision(),a=t().Image.Multiplexer(),A=t().Keypoint.Detector.Harris(),c=t().Keypoint.Descriptor.ORB(),l=t().Filter.GaussianBlur(),d=t().Keypoint.Clipper(),h=t().Keypoint.BorderClipper(),p=t().Filter.GaussianBlur(),u=t().Keypoint.SubpixelRefiner(),g=t().Keypoint.Matcher.BFKNN(),f=t().Keypoint.Transformer(),I=t().Keypoint.Portal.Sink(),m=t().Keypoint.Portal.Source(),_=t().Keypoint.Multiplexer(),y=t().Keypoint.Buffer(),x=t().Keypoint.Multiplexer(),C=t().Keypoint.SinkOfMatchedKeypoints();return n.media=null,i.size=t().Size(0,0),r.transform=t().Matrix.Eye(3),o.quality=T,u.method=R,h.imageSize=t().Size(100,100),h.borderSize=t().Vector2(0,0),g.k=1,f.transform=t().Matrix.Eye(3),m.source=I,_.port=0,x.port=0,y.frozen=!1,C.turbo=!1,n.output().connectTo(i.input()),i.output().connectTo(s.input()),s.output().connectTo(r.input()),r.output().connectTo(a.input("in0")),r.output().connectTo(o.input()),o.output().connectTo(a.input("in1")),a.output().connectTo(l.input()),a.output().connectTo(A.input()),A.output().connectTo(h.input()),h.output().connectTo(d.input()),r.output().connectTo(p.input()),p.output().connectTo(u.input("image")),d.output().connectTo(u.input("keypoints")),l.output().connectTo(c.input("image")),u.output().connectTo(c.input("keypoints")),c.output().connectTo(_.input("in0")),x.output().connectTo(_.input("in1")),_.output().connectTo(g.input("database")),c.output().connectTo(g.input("keypoints")),m.output().connectTo(x.input("in0")),y.output().connectTo(x.input("in1")),m.output().connectTo(y.input()),c.output().connectTo(I.input()),c.output().connectTo(f.input()),f.output().connectTo(C.input()),g.output().connectTo(C.input("matches")),e.init(n,i,s,r,o,a,l,A,u,d,h,p,c,m,_,g,y,x,f,C,I),e}}class X extends O{constructor(e){super("training",e),this._currentImageIndex=0,this._image=[],this._trainingMap={referenceImageIndex:[],referenceImage:[],keypoints:[]}}onEnterState(e){const t=this._imageTracker.database;if(0==t.count)throw new p("Can't train the Image Tracker: the Reference Image Database is empty");this._currentImageIndex=0,this._image.length=0,this._trainingMap.referenceImageIndex.length=0,this._trainingMap.referenceImage.length=0,this._trainingMap.keypoints.length=0,f.log(`Image Tracker: training using ${t.count} reference image${1!=t.count?"s":""}`),t._lock();for(const e of t)this._image.push(e)}_beforeUpdate(){this.screenSize;const e=this._pipeline.node("source"),n=this._pipeline.node("screen"),i=this._pipeline.node("keypointScaler");if(this._currentImageIndex>=this._image.length)return t().Promise.reject(new o);const s=this._imageTracker.database,r=this._image[this._currentImageIndex],a=s._findMedia(r.name);e.media=a;const A=this._imageTracker.resolution,c=a.width/a.height;n.size=f.resolution(A,c),n.size.width=Math.round(.8*n.size.width),n.size.height=Math.round(.8*n.size.height);const l=K/n.size.width,d=K/n.size.height;return i.transform=t().Matrix(3,3,[l,0,0,0,d,0,0,0,1]),f.log(`Image Tracker: training using reference image "${r.name}" at ${n.size.width}x${n.size.height}...`),t().Promise.resolve()}_afterUpdate(e){const n=this._image[this._currentImageIndex],i=e.keypoints;e.image;f.log(`Image Tracker: found ${i.length} keypoints in reference image "${n.name}"`),this._trainingMap.referenceImage.push(n);for(let e=0;e<i.length;e++)this._trainingMap.keypoints.push(i[e]),this._trainingMap.referenceImageIndex.push(this._currentImageIndex);return++this._currentImageIndex,this._currentImageIndex>=this._image.length?t().Promise.resolve({nextState:"scanning",nextStateSettings:{keypoints:this._trainingMap.keypoints},trackerOutput:{}}):t().Promise.resolve({nextState:"training",trackerOutput:{}})}_createPipeline(){const e=t().Pipeline(),n=t().Image.Source("source"),i=t().Transform.Resize("screen"),s=t().Filter.Greyscale(),r=t().Filter.GaussianBlur(),o=t().Filter.Nightvision(),a=t().Image.Multiplexer("nightvisionMux"),A=t().Image.Pyramid(),c=t().Keypoint.Detector.FAST("fast"),l=t().Keypoint.Descriptor.ORB(),d=t().Keypoint.SubpixelRefiner(),h=t().Image.Pyramid(),p=t().Filter.GaussianBlur(),u=t().Keypoint.Clipper(),g=t().Keypoint.Transformer("keypointScaler"),f=t().Keypoint.Sink("keypoints"),I=t().Image.Sink("image");return n.media=null,i.size=t().Size(0,0),r.kernelSize=t().Size(9,9),r.sigma=t().Vector2(2,2),o.gain=z,o.offset=L,o.decay=0,o.quality=T,a.port=1,c.levels=4,c.scaleFactor=1.19,c.threshold=60,c.capacity=8192,d.method=R,p.kernelSize=t().Size(5,5),p.sigma=t().Vector2(1,1),u.size=1024,g.transform=t().Matrix.Eye(3),f.turbo=!1,n.output().connectTo(i.input()),i.output().connectTo(s.input()),s.output().connectTo(a.input("in0")),s.output().connectTo(o.input()),o.output().connectTo(a.input("in1")),a.output().connectTo(A.input()),A.output().connectTo(c.input()),c.output().connectTo(u.input()),s.output().connectTo(p.input()),p.output().connectTo(h.input()),u.output().connectTo(d.input("keypoints")),h.output().connectTo(d.input("image")),s.output().connectTo(r.input()),r.output().connectTo(l.input("image")),u.output().connectTo(l.input("keypoints")),l.output().connectTo(g.input()),g.output().connectTo(f.input()),a.output().connectTo(I.input()),e.init(n,i,s,o,a,A,c,r,l,u,p,h,d,g,f,I),e}referenceImageOfKeypoint(e){const t=this.referenceImageIndexOfKeypoint(e);return t<0?null:this._trainingMap.referenceImage[t]}referenceImageIndexOfKeypoint(e){const t=this._trainingMap.referenceImageIndex.length;if(e<0||e>=t)return-1;const n=this._trainingMap.referenceImageIndex[e];return n<0||n>=this._trainingMap.referenceImage.length?-1:n}referenceKeypoint(e){return e<0||e>=this._trainingMap.keypoints.length?null:this._trainingMap.keypoints[e]}}const U=t().Size(K,K);class G extends O{constructor(e){super("scanning",e),this._counter=0,this._bestScore=0,this._bestHomography=t().Matrix.Eye(3)}onEnterState(e){const t=this._pipeline.node("imagePortalMux"),n=this._pipeline.node("lshTables"),i=e.keypoints;this._counter=0,this._bestScore=0,t.port=0,void 0!==i&&(n.keypoints=i)}_afterUpdate(e){const n=this._pipeline.node("imagePortalMux"),i=e.keypoints,s=this._goodMatches(i),r={keypoints:i,screenSize:this.screenSize};return n.port=1,s.length>=20?this._findHomography(s).then((([e,t])=>(t>=this._bestScore&&this._counter<29&&(this._bestScore=t,this._bestHomography=e,n.port=0),this._findPolyline(e,U)))).then((e=>{if(++this._counter<30)return{nextState:this.name,trackerOutput:Object.assign({polyline:e},r)};const t=this._pipeline.node("imagePortalSink"),n=this._imageTracker._referenceImageOfKeypoint(s[0].matches[0].index);return{nextState:"pre-tracking",nextStateSettings:{homography:this._bestHomography,snapshot:t,referenceImage:n},trackerOutput:Object.assign({polyline:e},r)}})).catch((()=>({nextState:this.name,trackerOutput:r}))):(this._counter=0,this._bestScore=0,t().Promise.resolve({nextState:this.name,trackerOutput:r}))}_goodMatches(e){const t=Object.create(null);for(let n=e.length-1;n>=0;n--){const i=e[n];if(i.matches[0].index>=0&&i.matches[1].index>=0){if(i.matches[0].distance<=.7*i.matches[1].distance){const e=this._imageTracker._referenceImageIndexOfKeypoint(i.matches[0].index);e>=0&&(Object.prototype.hasOwnProperty.call(t,e)||(t[e]=[]),t[e].push(i))}}}let n=[];for(const e in t)t[e].length>n.length&&(n=t[e]);return n}_findHomography(e){const n=[],i=[];for(let s=e.length-1;s>=0;s--){const r=e[s],o=this._imageTracker._referenceKeypoint(r.matches[0].index);if(null==o)return t().Promise.reject(new h(`Invalid keypoint match index: ${r.matches[0].index} from ${r.toString()}`));n.push(o.x),n.push(o.y),i.push(r.x),i.push(r.y)}const s=n.length/2;if(s<4)return t().Promise.reject(new h("Too few points to compute a homography"));const r=t().Matrix(2,s,n),o=t().Matrix(2,s,i),a=t().Matrix.Zeros(1,s),A=t().Matrix.Zeros(3);return t().Matrix.findHomography(A,r,o,{method:"pransac",reprojectionError:5,numberOfHypotheses:512,bundleSize:128,mask:a}).then((e=>{const t=e.at(0,0);if(Number.isNaN(t))throw new h("Can't compute homography");const n=a.read();let i=0;for(let e=n.length-1;e>=0;e--)i+=n[e];return[e,i/n.length]}))}_createPipeline(){const e=t().Pipeline(),n=t().Image.Source("source"),i=t().Transform.Resize("screen"),s=t().Filter.Greyscale(),r=t().Filter.GaussianBlur(),o=t().Filter.Nightvision(),a=t().Image.Multiplexer("nightvisionMux"),A=t().Image.Pyramid(),c=t().Keypoint.Detector.FAST(),l=t().Keypoint.Descriptor.ORB(),d=t().Keypoint.Clipper(),h=t().Keypoint.Matcher.StaticLSHTables("lshTables"),p=t().Keypoint.Matcher.LSHKNN(),u=t().Keypoint.SinkOfMatchedKeypoints("keypoints"),g=t().Image.Portal.Sink("imagePortalSink"),f=t().Image.Portal.Source("imagePortalSource"),I=t().Image.Multiplexer("imagePortalMux"),m=t().Image.Buffer(),_=t().Transform.Resize();return n.media=null,i.size=t().Size(0,0),r.kernelSize=t().Size(9,9),r.sigma=t().Vector2(2,2),o.gain=z,o.offset=L,o.decay=0,o.quality=T,a.port=1,c.levels=4,c.scaleFactor=1.19,c.threshold=60,c.capacity=2048,d.size=512,h.keypoints=[],h.numberOfTables=8,h.hashSize=15,p.k=2,p.quality="default",f.source=g,I.port=0,_.size=t().Size(0,0),_.scale=t().Vector2(1,1),u.turbo=!0,n.output().connectTo(i.input()),i.output().connectTo(s.input()),s.output().connectTo(r.input()),s.output().connectTo(a.input("in0")),s.output().connectTo(o.input()),o.output().connectTo(a.input("in1")),a.output().connectTo(A.input()),A.output().connectTo(c.input()),c.output().connectTo(d.input()),r.output().connectTo(l.input("image")),d.output().connectTo(l.input("keypoints")),l.output().connectTo(p.input("keypoints")),h.output().connectTo(p.input("lsh")),d.output().connectTo(u.input()),p.output().connectTo(u.input("matches")),n.output().connectTo(m.input()),m.output().connectTo(I.input("in0")),f.output().connectTo(_.input()),_.output().connectTo(I.input("in1")),I.output().connectTo(g.input()),e.init(n,i,s,r,o,a,A,c,l,d,h,p,u,g,f,I,m,_),e}}const q=t().Size(K,K);class H extends O{constructor(e){super("pre-tracking",e),this._homography=t().Matrix.Eye(3),this._referenceImage=null,this._step="read-reference-image",this._referenceKeypoints=[],this._iterations=0}onEnterState(e){const t=this._pipeline.node("imagePortalSource"),n=this._pipeline.node("muxOfReferenceKeypoints"),i=this._pipeline.node("muxOfBufferOfReferenceKeypoints"),s=this._pipeline.node("bufferOfReferenceKeypoints"),r=e.homography,o=e.referenceImage,a=e.snapshot;if(!o)throw new d("Can't track a null reference image");this._homography=r,this._referenceImage=o,this._step="read-reference-image",this._referenceKeypoints=[],this._iterations=0,t.source=a,n.port=0,i.port=0,s.frozen=!1}_beforeUpdate(){const e=this._referenceImage,n=this._pipeline.node("source"),i=this._pipeline.node("sourceMux"),s=this._pipeline.node("imageRectifier"),r=(this._pipeline.node("keypointRectifier"),this._pipeline.node("borderClipper")),o=this.screenSize,a=this._imageTracker.database._findMedia(e.name);n.media=a,"read-reference-image"==this._step?i.port=0:i.port=1,r.imageSize=o,r.borderSize=t().Vector2(o.width*N,o.height*N);return("read-reference-image"==this._step?this._findRectificationMatrixOfFullscreenImage(a,o):this._findRectificationMatrixOfCameraImage(this._homography,q,a,o)).then((e=>{s.transform=e}))}_afterUpdate(e){const n=this._referenceImage,i=this._pipeline.node("imagePortal"),s=this._pipeline.node("keypointPortalSink"),r=this._pipeline.node("muxOfReferenceKeypoints"),o=this._pipeline.node("muxOfBufferOfReferenceKeypoints"),a=this._pipeline.node("bufferOfReferenceKeypoints"),A=e.keypoints,c=e.image,l={keypoints:void 0!==c?A:void 0,image:c,screenSize:this.screenSize};switch(this._step){case"read-reference-image":return r.port=1,this._referenceKeypoints=A,this._step="warp-camera-image",t().Promise.resolve({nextState:"pre-tracking",trackerOutput:l});case"warp-camera-image":return a.frozen=!0,o.port=1,++this._iterations<3?this._step="warp-camera-image":this._step="train-camera-image",this._findWarp(A,this._referenceKeypoints).then((e=>this._homography.setTo(this._homography.times(e)))).then((e=>({nextState:"pre-tracking",trackerOutput:l}))).catch((e=>(f.warning(`Can't pre-track target image "${n.name}". ${e.toString()}`),{nextState:"scanning",trackerOutput:l})));case"train-camera-image":return f.log(`Took a snapshot of target image "${n.name}". Found ${A.length} keypoints.`),this._changeSpace(this._homography,this.screenSize).then((e=>t().Promise.resolve({nextState:"tracking",trackerOutput:l,nextStateSettings:{homography:e,referenceImage:n,templateKeypoints:A,keypointPortalSink:s,imagePortalSink:i,screenSize:this.screenSize}})))}}_findWarp(e,n){const i=[],s=[];for(let t=0;t<e.length;t++){const r=e[t];if(r.matches[0].index>=0&&r.matches[1].index>=0){if(r.matches[0].distance<=.75*r.matches[1].distance){const e=n[r.matches[0].index];i.push(e.x),i.push(e.y),s.push(r.x),s.push(r.y)}}}const r=i.length/2;if(r<4)return t().Promise.reject(new d("Too few points to compute a warp"));const o=t().Matrix.Eye(3);return this._findKeypointWarp().then((e=>t().Matrix.applyAffineTransform(t().Matrix.Zeros(2,2*r),t().Matrix(2,2*r,i.concat(s)),e.block(0,1,0,2)))).then((e=>t().Matrix.findAffineTransform(o.block(0,1,0,2),e.block(0,1,0,r-1),e.block(0,1,r,2*r-1),{method:"pransac",reprojectionError:3,numberOfHypotheses:2048,bundleSize:128}))).then((e=>{const t=o.at(0,0);if(Number.isNaN(t))throw new d("Can't compute warp: bad keypoints");return o}))}_findKeypointWarp(){const e=this._referenceImage,n=this._imageTracker.database._findMedia(e.name),i=this.screenSize;if(!this._mustRotateWarpedImage(n,i))return t().Promise.resolve(t().Matrix.Eye(3));const s=i.width/2,r=i.height/2;return t().Promise.resolve(t().Matrix(3,3,[0,1,0,-1,0,0,r+s,r-s,1]))}_changeSpace(e,n){const i=n.width,s=n.height,r=t().Matrix(2,4,[0,0,i,0,i,s,0,s]),o=t().Matrix.Zeros(3);return this._findPolylineCoordinates(e,q).then((e=>t().Matrix.perspective(o,r,e)))}_createPipeline(){const e=t().Pipeline(),n=t().Image.Source("source"),i=t().Image.Portal.Source("imagePortalSource"),s=t().Image.Multiplexer("sourceMux"),r=t().Transform.Resize("screen"),o=t().Filter.Greyscale(),a=t().Transform.PerspectiveWarp("imageRectifier"),A=t().Filter.Nightvision(),c=t().Image.Multiplexer(),l=t().Keypoint.Detector.Harris(),d=t().Keypoint.Descriptor.ORB(),h=t().Filter.GaussianBlur(),p=t().Keypoint.Clipper(),u=t().Keypoint.BorderClipper("borderClipper"),g=t().Filter.GaussianBlur(),f=t().Keypoint.SubpixelRefiner(),I=t().Keypoint.Matcher.BFKNN(),m=t().Keypoint.Transformer("keypointRectifier"),_=t().Keypoint.Portal.Sink("keypointPortalSink"),y=t().Keypoint.Portal.Source("keypointPortalSource"),x=t().Keypoint.Multiplexer("muxOfReferenceKeypoints"),C=t().Keypoint.Buffer("bufferOfReferenceKeypoints"),E=t().Keypoint.Multiplexer("muxOfBufferOfReferenceKeypoints"),S=t().Keypoint.SinkOfMatchedKeypoints("keypoints");t().Image.Sink("image");return n.media=null,r.size=t().Size(0,0),i.source=null,a.transform=t().Matrix.Eye(3),s.port=0,A.gain=z,A.offset=L,A.decay=0,A.quality=T,c.port=0,h.kernelSize=t().Size(9,9),h.sigma=t().Vector2(2,2),g.kernelSize=t().Size(5,5),g.sigma=t().Vector2(1,1),l.quality=.005,l.capacity=2048,f.method=R,p.size=200,u.imageSize=r.size,u.borderSize=t().Vector2(0,0),I.k=2,m.transform=t().Matrix.Eye(3),y.source=_,x.port=0,E.port=0,C.frozen=!1,S.turbo=!1,n.output().connectTo(s.input("in0")),i.output().connectTo(s.input("in1")),s.output().connectTo(r.input()),r.output().connectTo(o.input()),o.output().connectTo(a.input()),a.output().connectTo(c.input("in0")),a.output().connectTo(A.input()),A.output().connectTo(c.input("in1")),c.output().connectTo(h.input()),c.output().connectTo(l.input()),l.output().connectTo(u.input()),u.output().connectTo(p.input()),a.output().connectTo(g.input()),g.output().connectTo(f.input("image")),p.output().connectTo(f.input("keypoints")),h.output().connectTo(d.input("image")),f.output().connectTo(d.input("keypoints")),d.output().connectTo(x.input("in0")),E.output().connectTo(x.input("in1")),x.output().connectTo(I.input("database")),d.output().connectTo(I.input("keypoints")),y.output().connectTo(E.input("in0")),C.output().connectTo(E.input("in1")),y.output().connectTo(C.input()),d.output().connectTo(_.input()),d.output().connectTo(m.input()),m.output().connectTo(S.input()),I.output().connectTo(S.input("matches")),e.init(n,i,s,r,o,a,A,c,h,l,f,p,u,g,d,y,x,I,C,E,m,S,_),e}}class Y extends I{constructor(e,t){super(e),this._referenceImage=t}get referenceImage(){return this._referenceImage}}const J=1e-6;class W{constructor(e=0,t=0,n=0,i=1){this.x=+e,this.y=+t,this.z=+n,this.w=+i}static Identity(){return new W(0,0,0,1)}length(){const e=this.x,t=this.y,n=this.z,i=this.w;return Math.sqrt(e*e+t*t+n*n+i*i)}equals(e){return this.w===e.w&&this.x===e.x&&this.y===e.y&&this.z===e.z}toString(){return`Quaternion(${this.x.toFixed(4)},${this.y.toFixed(4)},${this.z.toFixed(4)},${this.w.toFixed(4)})`}_normalize(){const e=this.length();return e<J||(this.x/=e,this.y/=e,this.z/=e,this.w/=e),this}_conjugate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}_copyFrom(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}_toRotationMatrix(){const e=this.length();if(e<J)return t().Matrix.Eye(3);const n=this.x/e,i=this.y/e,s=this.z/e,r=this.w/e,o=n*n,a=i*i,A=s*s,c=2*n*i,l=2*n*s,d=2*i*s,h=2*r*n,p=2*r*i,u=2*r*s;return t().Matrix(3,3,[1-2*(a+A),c+u,l-p,c-u,1-2*(o+A),d+h,l+p,d-h,1-2*(o+a)])}_fromRotationMatrix(e){if(3!=e.rows||3!=e.columns)throw new r;const t=e.read(),n=t[0],i=t[1],s=t[2],o=t[3],a=t[4],A=t[5],c=t[6],l=t[7],d=t[8],h=1+n+a+d,p=+(A>=l)-+(A<l),u=+(c>=s)-+(c<s),g=+(i>=o)-+(i<o),f=.5*Math.sqrt(Math.max(0,h)),I=.5*Math.sqrt(Math.max(0,h-2*(a+d))),m=.5*Math.sqrt(Math.max(0,h-2*(n+d))),_=.5*Math.sqrt(Math.max(0,h-2*(n+a))),y=Math.sqrt(I*I+m*m+_*_+f*f);return this.x=I*p/y,this.y=m*u/y,this.z=_*g/y,this.w=f/y,this}}class j{constructor(e=0,t=0,n=0){this.x=+e,this.y=+t,this.z=+n}static Zero(){return new j(0,0,0)}length(){const e=this.x,t=this.y,n=this.z;return Math.sqrt(e*e+t*t+n*n)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return Math.sqrt(t*t+n*n+i*i)}directionTo(e){return e._clone()._subtract(this)._normalize()}cross(e){const t=this.y*e.z-this.z*e.y,n=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return new j(t,n,i)}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}toString(){return`Vector3(${this.x.toFixed(5)},${this.y.toFixed(5)},${this.z.toFixed(5)})`}_clone(){return new j(this.x,this.y,this.z)}_set(e,t,n){return this.x=+e,this.y=+t,this.z=+n,this}_copyFrom(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}_normalize(){const e=this.length();return e<1e-6||(this.x/=e,this.y/=e,this.z/=e),this}_add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}_subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}_scale(e){return this.x*=e,this.y*=e,this.z*=e,this}}const Z=j.Zero(),$=W.Identity(),V=new W(0,0,0,0);class ee{constructor(){this._smoothRotation=W.Identity(),this._smoothTranslation=j.Zero(),this._rotationSample=Array.from({length:12},(()=>W.Identity())),this._translationSample=Array.from({length:5},(()=>j.Zero())),this._isEmpty=!0}reset(){this._rotationSample.forEach((e=>e._copyFrom($))),this._translationSample.forEach((e=>e._copyFrom(Z))),this._isEmpty=!0}feed(e){const t=e.read();if(3!=e.rows||4!=e.columns)throw new r;if(Number.isNaN(t[0]*t[9]))return!1;const n=this._rotationSample[11];for(let e=11;e>0;e--)this._rotationSample[e]=this._rotationSample[e-1];this._rotationSample[0]=n._fromRotationMatrix(e.block(0,2,0,2));const i=this._translationSample[4];for(let e=4;e>0;e--)this._translationSample[e]=this._translationSample[e-1];return this._translationSample[0]=i._set(t[9],t[10],t[11]),this._isEmpty&&(this._rotationSample.forEach(((e,t)=>t>0&&e._copyFrom(this._rotationSample[0]))),this._translationSample.forEach(((e,t)=>t>0&&e._copyFrom(this._translationSample[0]))),this._isEmpty=!1),!0}output(){const e="low-power"==D.powerPreference?1.5:1,n=Math.ceil(5/e),i=Math.ceil(12/e),s=this._smoothTranslation._copyFrom(Z),r=this._smoothRotation._copyFrom(V);for(let e=0,t=2/(n*n+n);e<n;e++){const i=this._translationSample[e],r=(n-e)*t;s.x+=i.x*r,s.y+=i.y*r,s.z+=i.z*r}for(let e=0;e<i;e++){const t=this._rotationSample[e],n=1/i;t.w<0&&(t.x=-t.x,t.y=-t.y,t.z=-t.z,t.w=-t.w),r.x+=t.x*n,r.y+=t.y*n,r.z+=t.z*n,r.w+=t.w*n}const o=r._toRotationMatrix().read();return o.push(s.x,s.y,s.z),t().Matrix(3,4,o)}}class te{constructor(){this._screenSize=t().Size(0,0),this._matrix=t().Matrix.Eye(3,4),this._intrinsics=[1,0,0,0,1,0,0,0,1],this._extrinsics=[1,0,0,0,1,0,0,0,1,0,0,0],this._filter=new ee}init(e){if(0==e.area())throw new r(`Can't initialize the camera model with screenSize = ${e.toString()}`);this._screenSize.width=e.width,this._screenSize.height=e.height,this.reset(),f.log("Initializing the camera model...")}release(){return this.reset(),null}update(e,n){if(3!=e.rows||3!=e.columns)throw new r("Camera model: provide a homography matrix");if(0==n.area())throw new r(`Camera model: invalid screenSize = ${n.toString()}`);this._screenSize.equals(n)||(f.log("Camera model: detected a change in screen size..."),this._screenSize.width=n.width,this._screenSize.height=n.height,this.reset());const i=e.read(),s=i[0],o=i[3],a=i[6],A=i[1],c=i[4],l=i[7],d=i[2],h=i[5],p=a*(A*h-c*d)-l*(s*h-o*d)+i[8]*(s*c-o*A);if(Math.abs(p)<1e-6)return f.warning("Can't update the camera model using an invalid homography matrix"),t().Promise.resolve(this._matrix);const u=this._estimatePose(e);this._filter.feed(u)&&(this._extrinsics=this._filter.output().read());const g=this.denormalizer(),I=t().Matrix(3,3,this._intrinsics),m=t().Matrix(3,4,this._extrinsics);return this._matrix.setToSync(I.times(m).times(g)),t().Promise.resolve(this._matrix)}reset(){this._resetIntrinsics(),this._resetExtrinsics()}get matrix(){return this._matrix}get intrinsics(){return this._intrinsics}get extrinsics(){return this._extrinsics}denormalizer(){const e=this._screenSize.width/2,n=this._screenSize.height/2,i=Math.min(e,n);return t().Matrix(4,4,[i,0,0,0,0,-i,0,0,0,0,-i,0,e,n,0,1])}get screenSize(){return this._screenSize}get focalLength(){return this._intrinsics[4]}get fovx(){return 2*Math.atan(this._intrinsics[6]/this._intrinsics[0])}get fovy(){return 2*Math.atan(this._intrinsics[7]/this._intrinsics[4])}principalPoint(){return t().Point2(this._intrinsics[6],this._intrinsics[7])}_resetExtrinsics(){this._extrinsics.fill(0),this._extrinsics[0]=this._extrinsics[4]=this._extrinsics[8]=1,this._filter.reset()}_resetIntrinsics(){const e=Math.max(this._screenSize.width,this._screenSize.height),t=this._screenSize.width/2,n=this._screenSize.height/2,i=e/2/Math.tan(.5235987755982988),s=i;this._intrinsics[0]=i,this._intrinsics[4]=s,this._intrinsics[6]=t,this._intrinsics[7]=n}_normalizeHomography(e){const n=e.read(),i=this._intrinsics[6],s=this._intrinsics[7],r=this._intrinsics[0],o=this._intrinsics[4],a=i/r,A=s/o,c=n[0]/r-a*n[2],l=n[3]/r-a*n[5],d=n[6]/r-a*n[8],h=n[1]/o-A*n[2],p=n[4]/o-A*n[5],u=n[7]/o-A*n[8],g=n[2],f=n[5],I=n[8];return t().Matrix(3,3,[c,h,g,l,p,f,d,u,I])}_estimatePartialPose(e){const n=e.read(),i=n[0],s=n[3],r=n[6],o=n[1],a=n[4],A=n[7],c=n[2],l=n[5],d=n[8],h=i*i+o*o+c*c,p=s*s+a*a+l*l,u=Math.sqrt(h),g=Math.sqrt(p);let f=(d>=0?1:-1)/Math.max(u,g);if(Number.isNaN(f))return t().Matrix(3,3,new Array(9).fill(Number.NaN));let I=new Array(6);I[0]=f*i,I[1]=f*o,I[2]=f*c,I[3]=f*s,I[4]=f*a,I[5]=f*l,I=this._refineRotation(I),f=I[0]*i+I[1]*o+I[2]*c,f+=I[3]*s+I[4]*a+I[5]*l,f/=h+p;let m=new Array(3);return m[0]=f*r,m[1]=f*A,m[2]=f*d,t().Matrix(3,3,I.concat(m))}_refineRotation(e){const[n,i,s,r,o,a]=e,A=n*n+i*i+s*s,c=r*r+o*o+a*a,l=n*r+i*o+s*a,d=(A-c)*(A-c)+4*l*l,h=Math.sqrt(d),p=(A+c+h)/2,u=(A+c-h)/2,g=c-p-l*(1+l)/(A-p),f=Math.sqrt(g*g/(1+g*g)),I=f/g,m=c-u-l*(1+l)/(A-u),_=Math.sqrt(m*m/(1+m*m)),y=_/m,x=Math.sqrt(p),C=Math.sqrt(u),E=t().Matrix(2,2,[1/x,0,0,1/C]),S=t().Matrix(2,2,[f,I,_,y]),P=t().Matrix(2,2,[f,_,I,y]),v=S.times(E).times(P),w=t().Matrix(3,2,[n,i,s,r,o,a]);return t().Matrix(w.times(v)).read()}_refineTranslation(e,t,n){const i=e.read(),s=i[0],r=i[3],o=i[6],a=i[1],A=i[4],c=i[7],l=i[2],d=i[5],h=i[8],p=t[0],u=t[3],g=t[1],f=t[4],I=t[2],m=t[5],_=[.5,0,1,1,0],y=[.5,0,0,1,1],x=_.length,C=3*x,E=this._screenSize.width,S=this._screenSize.height;for(let e=0;e<x;e++)_[e]*=E,y[e]*=S;const P=new Array(x),v=new Array(x),w=new Array(x);for(let e=0;e<x;e++)P[e]=_[e]*s+y[e]*r+o,v[e]=_[e]*a+y[e]*A+c,w[e]=_[e]*l+y[e]*d+h;const B=new Array(3*x*3),b=new Array(3*x);for(let e=0,t=0;t<x;e+=3,t++)B[e]=B[e+C+1]=B[e+C+C+2]=0,B[e+C]=-(B[e+1]=w[t]),B[e+2]=-(B[e+C+C]=v[t]),B[e+C+C+1]=-(B[e+C+2]=P[t]),b[e]=w[t]*(_[t]*g+y[t]*f)-v[t]*(_[t]*I+y[t]*m),b[e+1]=-w[t]*(_[t]*p+y[t]*u)+P[t]*(_[t]*I+y[t]*m),b[e+2]=v[t]*(_[t]*p+y[t]*u)-P[t]*(_[t]*g+y[t]*f);const Q=new Array(3*x),M=new Array(3),D=new Array(3*x),k=new Array(3);k[0]=n[0],k[1]=n[1],k[2]=n[2];for(let e=0;e<15;e++){for(let e=0;e<C;e++){Q[e]=0;for(let t=0;t<3;t++)Q[e]+=B[t*C+e]*k[t];Q[e]-=b[e]}for(let e=0;e<3;e++){M[e]=0;for(let t=0;t<C;t++)M[e]+=B[e*C+t]*Q[t]}for(let e=0;e<C;e++){D[e]=0;for(let t=0;t<3;t++)D[e]+=B[t*C+e]*M[t]}let e=0;for(let t=0;t<3;t++)e+=M[t]*M[t];if(e<1)break;let t=0;for(let e=0;e<C;e++)t+=D[e]*D[e];const n=e/t;if(Number.isNaN(n))break;for(let e=0;e<3;e++)k[e]-=n*M[e]}return k}_computeFullRotation(e){const t=e[0],n=e[3],i=e[1],s=e[4],r=e[2],o=e[5];let a=i*o-r*s,A=r*n-t*o,c=t*s-i*n;return t*(s*c-A*o)-i*(n*c-a*o)+r*(n*A-a*s)<0&&(a=-a,A=-A,c=-c),[t,i,r,n,s,o,a,A,c]}_estimatePose(e){const n=this._normalizeHomography(e),i=t().Matrix.Eye(3),s=t().Matrix(n);for(let e=0;e<30;e++){const e=this._estimatePartialPose(s);i.setToSync(e.times(i)),s.setToSync(s.times(e.inverse()))}const r=i.read(),o=r.slice(0,6),a=r.slice(6,9),A=this._refineTranslation(n,o,a),c=this._computeFullRotation(o);return t().Matrix(3,4,c.concat(A))}}class ne{constructor(e){this._transform=e}get transform(){return this._transform}}const ie=1e-6;class se{constructor(e){if(4!=e.rows||4!=e.columns)throw new r("A Transform expects a 4x4 transformation matrix");this._matrix=e,this._inverse=null,this._position=j.Zero(),this._orientation=W.Identity(),this._scale=new j(1,1,1),this._isDecomposed=!1}get matrix(){return this._matrix}get inverse(){return null===this._inverse&&(this._inverse=new se(this._inverseMatrix())),this._inverse}get position(){return this._isDecomposed||this._decompose(),this._position}get orientation(){return this._isDecomposed||this._decompose(),this._orientation}get scale(){return this._isDecomposed||this._decompose(),this._scale}_decompose(){const e=this._matrix.read(),n=Math.abs(e[15])<ie?Number.NaN:1/e[15],i=e[12]*n,s=e[13]*n,r=e[14]*n,o=e[0]*n,a=e[1]*n,A=e[2]*n,c=e[4]*n,l=e[5]*n,d=e[6]*n,h=e[8]*n,p=e[9]*n,u=e[10]*n,g=h*(a*d-l*A)+u*(o*l-c*a)-p*(o*d-c*A),f=+(g>=0)-+(g<0),I=Math.sqrt(o*o+c*c+h*h),m=Math.sqrt(a*a+l*l+p*p),_=Math.sqrt(A*A+d*d+u*u)*f;if(I<ie||m<ie||_*f<ie)return this._position._set(i,s,r),this._scale._set(I,m,_),this._orientation._copyFrom(W.Identity()),void(this._isDecomposed=!0);const y=1/I,x=1/m,C=1/_,E=o*y,S=a*y,P=A*y,v=c*x,w=l*x,B=d*x,b=h*C,Q=p*C,M=u*C;this._position._set(i,s,r),this._scale._set(I,m,_),this._orientation._fromRotationMatrix(t().Matrix(3,3,[E,S,P,v,w,B,b,Q,M])),this._isDecomposed=!0}_inverseMatrix(){return t().Matrix(this._matrix.inverse())}}class re extends ne{constructor(e){const t=re._computeViewMatrix(e);super(new se(t).inverse),this._viewMatrix=t}get viewMatrix(){return this._viewMatrix}static _computeViewMatrix(e){const n=e.extrinsics;return t().Matrix(4,4,[n[0],-n[1],-n[2],0,n[3],-n[4],-n[5],0,n[6],-n[7],-n[8],0,n[9],-n[10],-n[11],1])}}class oe{constructor(e,t=1,n=2e4){const i=e.intrinsics,s=e.screenSize;if(this._near=Math.max(0,+t),this._far=Math.max(0,+n),this._near>=this._far)throw new r(`View expects near < far (found near = ${this._near} and far = ${this._far})`);this._aspect=s.width/s.height,this._tanOfHalfFovx=i[6]/i[0],this._tanOfHalfFovy=i[7]/i[4],this._projectionMatrix=oe._computeProjectionMatrix(i,this._near,this._far)}get projectionMatrix(){return this._projectionMatrix}get aspect(){return this._aspect}get fovx(){return 2*Math.atan(this._tanOfHalfFovx)}get fovy(){return 2*Math.atan(this._tanOfHalfFovy)}get near(){return this._near}get far(){return this._far}static _computeProjectionMatrix(e,n,i){const s=n*(e[7]/e[4]),r=n*(e[6]/e[0]),o=-s,a=-r;return t().Matrix(4,4,[2*n/(r-a),0,0,0,0,2*n/(s-o),0,0,(r+a)/(r-a),(s+o)/(s-o),-(i+n)/(i-n),-1,0,0,-2*i*n/(i-n),0])}}class ae{constructor(e){this._pose=new re(e),this._views=[new oe(e)]}get pose(){return this._pose}get view(){return this._views[0]}convertToViewerSpace(e){const n=e.transform.matrix,i=this._pose.viewMatrix,s=t().Matrix(i.times(n)),r=new se(s);return new ne(r)}}const Ae=!0;class ce extends O{constructor(e){super("tracking",e),this._referenceImage=null,this._warpHomography=t().Matrix.Eye(3),this._poseHomography=t().Matrix.Eye(3),this._initialHomography=t().Matrix.Eye(3),this._initialKeypoints=[],this._counter=0,this._camera=new te,this._predictedKeypoints=[],this._lastPipelineOutput={keypoints:[]},this._pipelineCounter=0,this._lastOutput={},this._lostCounter=0,f.assert(!0)}onEnterState(e){const n=e.homography,i=e.referenceImage,s=e.templateKeypoints,r=e.keypointPortalSink,a=e.screenSize,A=this._pipeline.node("keypointPortalSource");if(!i)throw new o("Can't track a null reference image");this._referenceImage=i,this._warpHomography=t().Matrix(n),this._poseHomography=t().Matrix(n),this._initialHomography=t().Matrix(n),this._initialKeypoints=s,this._counter=0,this._predictedKeypoints=[],this._lastPipelineOutput={keypoints:[]},this._pipelineCounter=0,this._lastOutput={},this._lostCounter=0,A.source=r,this._camera.init(a);const c=new Y("targetfound",i);this._imageTracker.dispatchEvent(c),f.log(`Tracking image "${i.name}"...`)}onLeaveState(){const e=this._referenceImage;this._camera.release();const t=new Y("targetlost",e);this._imageTracker.dispatchEvent(t)}_beforeUpdate(){const e=this._pipeline.node("imageRectifier"),n=this._pipeline.node("borderClipper"),i=(this._pipeline.node("keypointRectifier"),this.screenSize);return n.imageSize=i,n.borderSize=t().Vector2(i.width*N,i.height*N),this._findImageWarp(this._warpHomography,i).then((t=>{e.transform=t}))}_gpuUpdate(){if("low-power"==D.powerPreference)return super._gpuUpdate();const e=this._pipelineCounter;return this._pipelineCounter=(this._pipelineCounter+1)%2,0!=e?(void 0!==this._lastPipelineOutput.keypoints?this._predictedKeypoints=this._predictKeypoints(this._lastPipelineOutput.keypoints,this._initialKeypoints):this._predictedKeypoints.length=0,this._lastPipelineOutput.keypoints=this._predictedKeypoints,t().Promise.resolve(this._lastPipelineOutput)):super._gpuUpdate().then((e=>(this._lastPipelineOutput=e,e)))}_afterUpdate(e){const n=this._pipeline.node("imageRectifier"),i=e.keypoints,s=e.image,r=this._referenceImage;return this._preprocessMatches(i,this._initialKeypoints).then((e=>t().Promise.all([this._findAffineMotion(e),this._findPerspectiveMotion(e)]))).then((([e,t])=>{const n="low-power"==D.powerPreference,i=!(n||this._counter%2==0),s=2*(n?1:2),r=s>>>1;return this._counter%s==r&&this._warpHomography.setToSync(this._warpHomography.times(e)),i||this._poseHomography.setToSync(this._warpHomography.times(t)),this._counter=(this._counter+1)%s,i?this._camera.matrix:this._camera.update(this._poseHomography,this.screenSize)})).then((e=>{const s=n.transform,r=t().Matrix(s.inverse()),o=i.length,a=new Array(2*o);for(let e=0,t=0;e<o;e++,t+=2)a[t]=i[e].position.x,a[t+1]=i[e].position.y;return t().Matrix.applyPerspectiveTransform(t().Matrix.Zeros(2,o),t().Matrix(2,o,a),r)})).then((e=>this._findPolyline(this._poseHomography,this.screenSize))).then((e=>{const t=this._camera.denormalizer(),n=new se(t),i=new ne(n),o=new ae(this._camera),a={pose:i,referenceImage:r},A={tracker:this._imageTracker,trackables:[a],viewer:o};return this._lastOutput={exports:A,cameraMatrix:this._camera.matrix,homography:this._warpHomography,screenSize:this.screenSize,image:s,polyline:e},this._lostCounter=0,{nextState:"tracking",trackerOutput:this._lastOutput}})).catch((e=>e instanceof d&&++this._lostCounter<=10?{nextState:"tracking",trackerOutput:this._lastOutput}:(f.warning(`The target has been lost! ${e.toString()}`),this._camera.reset(),{nextState:"scanning",trackerOutput:{image:s,screenSize:this.screenSize}})))}_findQualityMatches(e,t){const n=[[],[]],i=e.length;for(let s=0;s<i;s++){const i=e[s];if(i.matches[0].index>=0&&i.matches[1].index>=0){if(i.matches[0].distance<=.75*i.matches[1].distance){const e=t[i.matches[0].index];n[0].push(i),n[1].push(e)}}}return n}_refineQualityMatches(e){const t=e[0],n=e[1],i=this._distributeKeypoints(t,10),s=i.length,r=[new Array(s),new Array(s)];for(let e=0;e<s;e++)r[0][e]=t[i[e]],r[1][e]=n[i[e]];return r}_distributeKeypoints(e,t){const n=e.length,i=new Array(2*n);for(let t=0,s=0;t<n;t++,s+=2)i[s]=e[t].x,i[s+1]=e[t].y;this._normalizePoints(i);const s=t*t,r=new Array(s).fill(-1);for(let e=0,s=0;e<n;e++,s+=2){const n=Math.floor(i[s]*t);r[Math.floor(i[s+1]*t)*t+n]=e}const o=[];for(let e=0;e<s;e++)if(r[e]>=0){const t=r[e];o.push(t)}return o}_normalizePoints(e){f.assert(e.length%2==0);const t=e.length/2;if(0==t)return e;let n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(let o=0,a=0;o<t;o++,a+=2){const t=e[a],o=e[a+1];n=t<n?t:n,s=o<s?o:s,i=t>i?t:i,r=o>r?o:r}const o=i-n+1,a=r-s+1;for(let i=0,r=0;i<t;i++,r+=2)e[r]=(e[r]-n)/o,e[r+1]=(e[r+1]-s)/a;return e}_findMatrixOfMatches(e){const n=e[0].length;f.assert(n>0);const i=e[0],s=e[1],r=new Array(2*n),o=new Array(2*n);for(let e=0,t=0;e<n;e++,t+=2)r[t]=s[e].x,r[t+1]=s[e].y,o[t]=i[e].x,o[t+1]=i[e].y;return t().Matrix(2,2*n,r.concat(o))}_preprocessMatches(e,n){const i=this._findQualityMatches(e,n),s=this._refineQualityMatches(i),r=s[0].length;if(r<4)return t().Promise.reject(new d("Not enough data to compute a motion model"));const o=this._findMatrixOfMatches(s),a=t().Matrix.Zeros(2,2*r);return this._findKeypointWarp().then((e=>t().Matrix.applyAffineTransform(a,o,e.block(0,1,0,2))))}_findAffineMotion(e){const n=t().Matrix.Eye(3),i=e.columns/2;return t().Matrix.findAffineTransform(n.block(0,1,0,2),e.block(0,1,0,i-1),e.block(0,1,i,2*i-1),{method:"pransac",reprojectionError:3,numberOfHypotheses:512,bundleSize:128}).then((e=>{const t=n.at(0,0);if(Number.isNaN(t))throw new d("Can't compute affine motion model: bad keypoints");return n}))}_findPerspectiveMotion(e){const n=t().Matrix.Zeros(3),i=e.columns/2;return t().Matrix.findHomography(n,e.block(0,1,0,i-1),e.block(0,1,i,2*i-1),{method:"pransac",reprojectionError:3,numberOfHypotheses:1024,bundleSize:512}).then((e=>{const t=n.at(0,0);if(Number.isNaN(t))throw new d("Can't compute perspective motion model: bad keypoints");return n}))}_findImageWarp(e,n){const i=this._referenceImage,s=this._imageTracker.database._findMedia(i.name),r=t().Matrix.Zeros(3);return this._findRectificationMatrixOfFullscreenImage(s,n).then((t=>r.setTo(t.times(e.inverse()))))}_findKeypointWarp(){const e=this._referenceImage,n=this._imageTracker.database._findMedia(e.name),i=this.screenSize,s=i.width,r=i.height,o=t().Matrix.Eye(3,3);return this._mustRotateWarpedImage(n,i)?t().Matrix.affine(o.block(0,1,0,2),t().Matrix(2,3,[0,r,0,0,s,0]),t().Matrix(2,3,[0,0,s,0,s,r])).then((e=>o)):t().Promise.resolve(o)}_predictKeypoints(e,t){const n=[],i=e.length;for(let s=0;s<i;s++){const i=e[s];if(i.matches[0].index<0||i.matches[1].index<0)continue;const r=t[i.matches[0].index],o=i.position.x-r.position.x,a=i.position.y-r.position.y,A=.8;i.position.x=r.position.x+A*o,i.position.y=r.position.y+A*a,n.push(i)}return n}_createPipeline(){const e=t().Pipeline(),n=t().Image.Source("source"),i=t().Transform.Resize("screen"),s=t().Filter.Greyscale(),r=t().Transform.PerspectiveWarp("imageRectifier"),o=t().Filter.Nightvision(),a=t().Image.Multiplexer(),A=t().Filter.GaussianBlur(),c=t().Keypoint.Detector.Harris(),l=t().Keypoint.Descriptor.ORB(),d=t().Keypoint.Matcher.BFKNN(),h=t().Keypoint.SubpixelRefiner(),p=t().Filter.GaussianBlur(),u=t().Keypoint.BorderClipper("borderClipper"),g=t().Keypoint.Clipper(),f=t().Keypoint.Transformer("keypointRectifier"),I=t().Keypoint.Portal.Source("keypointPortalSource"),m=t().Keypoint.SinkOfMatchedKeypoints("keypoints");t().Image.Sink("image");return n.media=null,i.size=t().Size(0,0),r.transform=t().Matrix.Eye(3),o.gain=z,o.offset=L,o.decay=0,o.quality=T,a.port=0,A.kernelSize=t().Size(9,9),A.sigma=t().Vector2(2,2),p.kernelSize=t().Size(5,5),p.sigma=t().Vector2(1,1),c.quality=.005,c.capacity=2048,h.method=R,g.size=200,u.imageSize=i.size,u.borderSize=t().Vector2(0,0),f.transform=t().Matrix.Eye(3),d.k=2,I.source=null,m.turbo=Ae,n.output().connectTo(i.input()),i.output().connectTo(s.input()),s.output().connectTo(r.input()),r.output().connectTo(a.input("in0")),r.output().connectTo(o.input()),o.output().connectTo(a.input("in1")),a.output().connectTo(c.input()),c.output().connectTo(u.input()),u.output().connectTo(g.input()),r.output().connectTo(p.input()),p.output().connectTo(h.input("image")),g.output().connectTo(h.input("keypoints")),r.output().connectTo(A.input()),A.output().connectTo(l.input("image")),h.output().connectTo(l.input("keypoints")),I.output().connectTo(d.input("database")),l.output().connectTo(d.input("keypoints")),l.output().connectTo(f.input()),f.output().connectTo(m.input()),d.output().connectTo(m.input("matches")),e.init(n,i,s,r,o,a,A,c,h,u,g,p,l,d,I,f,m),e}}class le extends m{constructor(){super(),this._state={initial:new F(this),training:new X(this),scanning:new G(this),"pre-tracking":new H(this),tracking:new ce(this)},this._session=null,this._source=null,this._activeStateName="initial",this._lastOutput={},this._database=new k,this._resolution="sm"}get type(){return"image-tracker"}get state(){return this._activeStateName}get database(){return this._database}get resolution(){return this._resolution}set resolution(e){this._resolution=e}get screenSize(){return this._state[this._activeStateName].screenSize}get _output(){return this._lastOutput}get _stats(){return`${e=this.screenSize,`${e.width}x${e.height}`} ${this.state}`;var e}_init(e){this._session=e;for(const t of e.sources){if("video"==t._type){this._source=t;break}"canvas"==t._type&&(this._source=t)}if(null===this._source)throw new o("The image tracker requires a suitable source of data");for(const e of Object.values(this._state))e.init();return t().Promise.resolve()}_release(){for(const e of Object.values(this._state))e.release();return this._session=null,t().Promise.resolve()}_update(){if(null==this._session)return t().Promise.reject(new o("Uninitialized tracker"));const e=this._source._internalMedia,n=e.width/e.height,i=f.resolution(this._resolution,n),s=this._state[this._activeStateName];return s.update(e,i).then((({trackerOutput:e,nextState:t,nextStateSettings:n})=>{this._lastOutput=e,this._activeStateName!=t&&(s.onLeaveState(),this._activeStateName=t,this._state[t].onEnterState(n||{}))}))}_referenceImageOfKeypoint(e){return this._state.training.referenceImageOfKeypoint(e)}_referenceImageIndexOfKeypoint(e){return this._state.training.referenceImageIndexOfKeypoint(e)}_referenceKeypoint(e){return this._state.training.referenceKeypoint(e)}}class de{constructor(e=0,t=0){this.x=+e,this.y=+t}static Zero(){return new de(0,0)}length(){const e=this.x,t=this.y;return Math.sqrt(e*e+t*t)}dot(e){return this.x*e.x+this.y*e.y}distanceTo(e){const t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)}directionTo(e){return e._clone()._subtract(this)._normalize()}equals(e){return this.x===e.x&&this.y===e.y}toString(){return`Vector2(${this.x.toFixed(5)},${this.y.toFixed(5)})`}_clone(){return new de(this.x,this.y)}_set(e,t){return this.x=+e,this.y=+t,this}_copyFrom(e){return this.x=e.x,this.y=e.y,this}_normalize(){const e=this.length();return e<1e-6||(this.x/=e,this.y/=e),this}_add(e){return this.x+=e.x,this.y+=e.y,this}_subtract(e){return this.x-=e.x,this.y-=e.y,this}_scale(e){return this.x*=e,this.y*=e,this}}const he={pointerdown:"began",pointerup:"ended",pointermove:"moved",pointercancel:"canceled",pointerleave:"ended",pointerenter:"began"};class pe{constructor(){this._source=null,this._viewport=null,this._activePointers=new Map,this._newPointers=new Map,this._previousOutput=this._generateOutput(),this._previousUpdateTime=Number.POSITIVE_INFINITY,this._wantToReset=!1,this._resetInTheNextUpdate=this._resetInTheNextUpdate.bind(this)}get type(){return"pointer-tracker"}_init(e){f.log("Initializing PointerTracker..."),this._viewport=e.viewport;for(const t of e.sources)if("pointer-source"==t._type){this._source=t;break}return null===this._source?t().Promise.reject(new o("A PointerTracker expects a PointerSource")):(this._source._setViewport(this._viewport),document.addEventListener("visibilitychange",this._resetInTheNextUpdate),t().Promise.resolve())}_release(){return this._source=null,this._viewport=null,this._activePointers.clear(),this._newPointers.clear(),document.removeEventListener("visibilitychange",this._resetInTheNextUpdate),t().Promise.resolve()}_update(){const e=this._viewport.canvas,n=e.getBoundingClientRect(),i=this._updateTime(),s=i>1e-5?1/i:60,r=this._findInactiveTrackables();for(let e=r.length-1;e>=0;e--)this._activePointers.delete(r[e].id);let a;for(this._updateAllTrackables({phase:"stationary",velocity:de.Zero(),deltaPosition:de.Zero()}),this._wantToReset&&(this._reset(),this._wantToReset=!1);null!==(a=this._source._consume());){if(a.target!==e)return t().Promise.reject(new o("Invalid PointerEvent target "+a.target));if(!he.hasOwnProperty(a.type))return t().Promise.reject(new o("Invalid PointerEvent type "+a.type));const r=a.pointerId,A=this._activePointers.get(r),c=this._newPointers.get(r),l=he[a.type];if("pointerdown"==a.type||"pointerenter"==a.type&&a.buttons>0){if(A)continue;if(0!=a.button&&"mouse"==a.pointerType)continue}else if(!A&&!c)continue;if(A){if("began"==l&&c&&("ended"==c.phase||"canceled"==c.phase)){this._newPointers.delete(r);continue}}else if("ended"==l||"canceled"==l){this._newPointers.delete(r);continue}if("canceled"==(null==A?void 0:A.phase))continue;switch(a.type){case"pointermove":if(0==a.buttons||"began"==(null==c?void 0:c.phase))continue;break;case"pointerenter":if(0==a.buttons||"began"==(null==A?void 0:A.phase)||"began"==(null==c?void 0:c.phase))continue;break;case"pointercancel":this._reset(),this._newPointers.clear();continue}const d=a.pageX-(n.left+window.scrollX),h=a.pageY-(n.top+window.scrollY),p=2*d/n.width-1,u=-(2*h/n.height-1),g=new de(p,u),f=A?g._clone()._subtract(A.position):de.Zero(),I=A?A.initialPosition:Object.freeze(g._clone()),m=f._clone()._scale(s),_=A?A.elapsedTime+i:0,y=a.isPrimary,x=a.pointerType;this._newPointers.set(r,{id:r,phase:l,position:g,deltaPosition:f,initialPosition:I,velocity:m,elapsedTime:_,isPrimary:y,kind:x})}return this._newPointers.forEach(((e,t)=>this._activePointers.set(t,e))),this._newPointers.clear(),this._advanceAllStationaryTrackables(i),this._previousOutput=this._generateOutput(),t().Promise.resolve()}get _output(){return this._previousOutput}get _stats(){const e=this._activePointers.size;return e+" pointer"+(1!=e?"s":"")}_generateOutput(){const e=[];return this._activePointers.forEach((t=>e.push(t))),{exports:{tracker:this,trackables:this._sortTrackables(e)}}}_updateAllTrackables(e){this._activePointers.forEach(((t,n)=>{this._activePointers.set(n,Object.assign({},t,e))}))}_advanceAllStationaryTrackables(e){this._activePointers.forEach(((t,n)=>{"stationary"==t.phase&&(t.elapsedTime+=e)}))}_reset(){for(this._updateAllTrackables({phase:"canceled",deltaPosition:de.Zero(),velocity:de.Zero()});null!==this._source._consume(););}_resetInTheNextUpdate(){this._wantToReset=!0}_sortTrackables(e){if(e.length<=1||e[0].isPrimary)return e;for(let t=1;t<e.length;t++)if(e[t].isPrimary){const n=e[t];e[t]=e[0],e[0]=n;break}return e}_findInactiveTrackables(){const e=[];return this._activePointers.forEach((t=>{"ended"!=t.phase&&"canceled"!=t.phase||e.push(t)})),e}_updateTime(){const e=.001*performance.now();this._previousUpdateTime>e&&(this._previousUpdateTime=e);const t=this._previousUpdateTime;return this._previousUpdateTime=e,e-t}}class ue{static ImageTracker(){return new le}static Pointer(){return new pe}}let ge=!1;class fe{constructor(e){f.assert(e instanceof HTMLVideoElement,"Expected a video element"),this._video=e,this._media=null}get _type(){return"video"}get _internalMedia(){if(null==this._media)throw new o("The media of the source of data isn't loaded");return this._media}get _stats(){const e=this._media;return null!=e?`${e.width}x${e.height} video`:"uninitialized video"}_init(){return f.log(`Initializing ${this._type} source...`),this._prepareVideo(this._video).then((e=>(f.log("The video is prepared"),t().load(e).then((e=>{f.log(`Source of data is a ${e.width}x${e.height} ${this._type}`),this._media=e})))))}_release(){return this._media&&this._media.release(),this._media=null,t().Promise.resolve()}_prepareVideo(e){return e.setAttribute("playsinline",""),this._handleAutoPlay(e).then((e=>(f.isWebKit()&&e.hidden&&(e.hidden=!1,e.style.setProperty("opacity","0"),e.style.setProperty("position","fixed"),e.style.setProperty("left","0"),e.style.setProperty("top","0")),e)))}_handleAutoPlay(e){return e.autoplay?(e.muted||(f.warning("Videos marked with autoplay should be muted",e),e.muted=!0),this._waitUntilPlayable(e).then((e=>{const n=e.play();return void 0===n?e:new(t().Promise)(((t,i)=>{n.then((()=>t(e)),(n=>{if(f.error("Can't autoplay video!",n,e),"NotAllowedError"==n.name)f.warning("Tip: allow manual playback"),f.isIOS()&&f.warning("Is low power mode on?"),!e.hidden&&e.controls&&null!==e.parentNode||(document.body.addEventListener("pointerdown",(()=>e.play())),ge||(alert("Tap on the screen to start"),ge=!0));else if("NotSupportedError"==n.name)return void i(new a("Unsupported video format",n));t(e)}))}))}))):t().Promise.resolve(e)}_waitUntilPlayable(e){return e.readyState>=3?t().Promise.resolve(e):new(t().Promise)(((t,n)=>{let i=0,s=setInterval((()=>{e.readyState>=3?(clearInterval(s),t(e)):(i+=500)>=15e3&&(clearInterval(s),n(new c("The video took too long to load")))}),500)}))}}class Ie{constructor(e){f.assert(e instanceof HTMLCanvasElement,"Expected a canvas element"),this._canvas=e,this._media=null}get _type(){return"canvas"}get _internalMedia(){if(null==this._media)throw new o("The media of the source of data isn't loaded");return this._media}get _stats(){const e=this._media;return null!=e?`${e.width}x${e.height} canvas`:"uninitialized canvas"}_init(){return t().load(this._canvas).then((e=>{f.log(`Source of data is a ${e.width}x${e.height} ${this._type}`),this._media=e}))}_release(){return this._media&&this._media.release(),this._media=null,t().Promise.resolve()}}const me={resolution:"md",aspectRatio:16/9,constraints:{facingMode:"environment"}};class _e extends fe{constructor(e){const t=document.createElement("video");super(t),this._cameraVideo=t,this._options=Object.assign({},me,e)}get resolution(){return this._options.resolution}_init(){if(f.log("Accessing the webcam..."),!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new a("Unsupported browser: no navigator.mediaDevices.getUserMedia()");const e=this._options,n=f.resolution(e.resolution,e.aspectRatio),i={audio:!1,video:Object.assign({width:n.width,height:n.height},e.constraints)};return new(t().Promise)(((e,t)=>{navigator.mediaDevices.getUserMedia(i).then((n=>{const i=this._cameraVideo;i.onloadedmetadata=()=>{const n=i.play(),s="Access to the webcam has been granted.";if(void 0===n)return f.log(s),void e(i);n.then((()=>{f.log(s),e(i)})).catch((e=>{t(new o("Webcam error!",e))}))},i.setAttribute("playsinline",""),i.setAttribute("autoplay",""),i.setAttribute("muted",""),i.srcObject=n})).catch((e=>{t(new A("Please give access to the webcam and reload the page.",e))}))})).then((e=>super._init()))}_release(){return this._cameraVideo.srcObject.getTracks().forEach((e=>e.stop())),this._cameraVideo.onloadedmetadata=null,this._cameraVideo.srcObject=null,super._release()}}class ye{constructor(){this._queue=[],this._viewport=null,this._onPointerEvent=this._onPointerEvent.bind(this),this._cancelEvent=this._cancelEvent.bind(this)}get _type(){return"pointer-source"}_consume(){return this._queue.shift()||null}get _stats(){return"pointer input"}_init(){return f.log("Initializing PointerSource..."),t().Promise.resolve()}_release(){return this._setViewport(null),t().Promise.resolve()}_setViewport(e){if(null!==this._viewport&&(this._viewport.hud.container.style.removeProperty("pointer-events"),this._viewport._subContainer.style.removeProperty("pointer-events"),this._viewport.container.style.removeProperty("pointer-events"),this._viewport.canvas.style.removeProperty("pointer-events"),this._removeEventListeners(this._viewport.canvas)),null!==(this._viewport=e)){this._addEventListeners(this._viewport.canvas),this._viewport.canvas.style.pointerEvents="auto",this._viewport.container.style.pointerEvents="none",this._viewport._subContainer.style.pointerEvents="none",this._viewport.hud.container.style.pointerEvents="none";for(const e of this._viewport.hud.container.children){const t=e;""==t.style.getPropertyValue("pointer-events")&&(t.style.pointerEvents="auto")}}}_onPointerEvent(e){this._queue.push(e),e.preventDefault()}_cancelEvent(e){e.cancelable&&e.preventDefault()}_addEventListeners(e){e.addEventListener("pointerdown",this._onPointerEvent),e.addEventListener("pointerup",this._onPointerEvent),e.addEventListener("pointermove",this._onPointerEvent),e.addEventListener("pointercancel",this._onPointerEvent),e.addEventListener("pointerleave",this._onPointerEvent),e.addEventListener("pointerenter",this._onPointerEvent),e.addEventListener("touchstart",this._cancelEvent,{passive:!1})}_removeEventListeners(e){e.removeEventListener("touchstart",this._cancelEvent),e.removeEventListener("pointerenter",this._onPointerEvent),e.removeEventListener("pointerleave",this._onPointerEvent),e.removeEventListener("pointercancel",this._onPointerEvent),e.removeEventListener("pointermove",this._onPointerEvent),e.removeEventListener("pointerup",this._onPointerEvent),e.removeEventListener("pointerdown",this._onPointerEvent)}}class xe{static Video(e){return new fe(e)}static Canvas(e){return new Ie(e)}static Camera(e={}){return new _e(e)}static Pointer(){return new ye}}class Ce{constructor(e,t){this._container=t||this._createContainer(e),this._isOwnContainer=null==t,this._container.parentElement!==e&&(this._container.remove(),e.insertAdjacentElement("afterbegin",this._container)),this._container.hidden||(f.warning("The container of the HUD should have the hidden attribute"),this._container.hidden=!0)}get container(){return this._container}get visible(){return!this._container.hidden}set visible(e){this._container.hidden=!e}_init(e){const t=this._container;t.style.position="absolute",t.style.left=t.style.top="0px",t.style.right=t.style.bottom="0px",t.style.padding=t.style.margin="0px",t.style.zIndex=String(e),t.style.userSelect="none",this.visible=!0}_release(){this.visible=!1,this._isOwnContainer&&(this._isOwnContainer=!1,this._container.remove())}_createContainer(e){const t=document.createElement("div");return t.hidden=!0,e.insertAdjacentElement("afterbegin",t),t}}const Ee="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAbUlEQVRYR+2WOQ4AIAgE5f+PVhobDZANBZAsraAwXMoqFil+f9GBj8BW8dIiKt45at/XgShStHgvmfdekwAdIIEyAmh1Z/U5ikmABPoRsLZWtt+5DUlgHgGr6qM1Pf9XnO131L7fJEQjyOqXEzjP1YAhNmUTrgAAAABJRU5ErkJggg==";class Se{constructor(e){this._viewport=e,this._button=this._createButton(),this._boundEventHandler=this._handleFullscreenEvent.bind(this)}init(){this._viewport.hud.container.appendChild(this._button),this._viewport.addEventListener("fullscreenchange",this._boundEventHandler)}release(){this._viewport.removeEventListener("fullscreenchange",this._boundEventHandler),this._button.remove()}_createButton(){const e=document.createElement("button");e.style.position="absolute",e.style.bottom="24px",e.style.right="24px",e.style.width="64px",e.style.height="64px",e.style.display="flex",e.style.alignItems="center",e.style.padding="2px",e.style.opacity="0.5",e.style.cursor="pointer",e.style.outline="none",e.style["-webkit-tap-highlight-color"]="transparent",e.draggable=!1,e.style.backgroundColor="transparent",e.style.backgroundImage="url("+Ee+")",e.style.backgroundSize="cover",e.style.imageRendering="pixelated",e.style.borderColor="white",e.style.borderStyle="solid",e.style.borderWidth="2px",e.style.borderRadius="8px";const t=()=>{e.style.backgroundColor="transparent",e.style.borderColor="white",e.style.opacity="0.5"};return e.addEventListener("pointerdown",(()=>{e.style.backgroundColor="#ffd500",e.style.borderColor="#ffd500",e.style.opacity="1.0"})),e.addEventListener("pointerup",t),e.addEventListener("pointerleave",t),e.addEventListener("click",(()=>{this._viewport.fullscreen?this._viewport.exitFullscreen():this._viewport.requestFullscreen().catch((e=>{alert("Can't enable the fullscreen mode. "+e.toString())}))})),e}_handleFullscreenEvent(e){const t=this._viewport.fullscreen?"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAZElEQVRYR+2WwRIAEAhE9f8fTQ5OhtkLxbzOyc5rJSvBYcH3FwTIBKpHb5d57Nqm5o0aCIBAPgLDxSunq69APT8RCBdwezTLHjglDAEQgEC+QZR2EqqbjprHRgSB9wjwHX9LoAHP1YAhXF4Z/QAAAABJRU5ErkJggg==":Ee;this._button.style.backgroundImage="url("+t+")"}}class Pe extends I{}class ve extends m{}const we={container:null,hudContainer:null,resolution:"lg",style:"best-fit",canvas:null,fullscreenUI:!0};class Be{constructor(e){if(null==e)throw new r("Unspecified viewport container");if(!(e instanceof HTMLElement))throw new r("Invalid viewport container");this._container=e,this._subContainer=document.createElement("div"),e.appendChild(this._subContainer)}get container(){return this._container}get subContainer(){return this._subContainer}init(){this._container.style.touchAction="none",this._container.style.backgroundColor="black"}release(){this._container.style.removeProperty("background-color"),this._container.style.removeProperty("touch-action")}}class be{constructor(e,t,n=null){if(null!==n&&!(n instanceof HTMLCanvasElement))throw new r("Not a canvas: "+n);this._originalCSSTextOfForegroundCanvas=n?n.style.cssText:"",this._foregroundCanvas=this._styleCanvas(n||this._createCanvas(t),1),this._foregroundCanvas.style.background="transparent",this._backgroundCanvas=this._styleCanvas(this._createCanvas(t),0),this._backgroundCanvas.hidden=!0,this._foregroundCanvas.hidden=!0;const i="encantar.js "+Re.version;this._backgroundCanvas.dataset.arEngine=i,this._foregroundCanvas.dataset.arEngine=i,e.appendChild(this._backgroundCanvas),e.appendChild(this._foregroundCanvas)}get backgroundCanvas(){return this._backgroundCanvas}get foregroundCanvas(){return this._foregroundCanvas}init(){this._backgroundCanvas.hidden=!1,this._foregroundCanvas.hidden=!1}release(){this._backgroundCanvas.hidden=!0,this._foregroundCanvas.hidden=!0,this._backgroundCanvas.style.cssText="",this._foregroundCanvas.style.cssText=this._originalCSSTextOfForegroundCanvas}_createCanvas(e){const t=document.createElement("canvas");return t.width=e.width,t.height=e.height,t}_styleCanvas(e,t){return e.style.position="absolute",e.style.left="0px",e.style.top="0px",e.style.width="100%",e.style.height="100%",e.style.zIndex=String(t),e}}class Qe{constructor(e){this._viewport=e,this._container=e.container,this._boundEventHandler=this._triggerEvent.bind(this)}init(){this._container.addEventListener("fullscreenchange",this._boundEventHandler)}release(){this._container.removeEventListener("fullscreenchange",this._boundEventHandler)}request(){const e=this._container;return void 0===e.requestFullscreen?void 0===e.webkitRequestFullscreen?t().Promise.reject(new a):document.webkitFullscreenEnabled?(e.webkitRequestFullscreen(),new(t().Promise)(((t,n)=>{setTimeout((()=>{e===document.webkitFullscreenElement?(f.log("Entering fullscreen mode..."),t()):n(new TypeError)}),100)}))):t().Promise.reject(new A):document.fullscreenEnabled?new(t().Promise)(((t,n)=>{e.requestFullscreen({navigationUI:"hide"}).then((()=>{f.log("Entering fullscreen mode..."),t()}),n)})):t().Promise.reject(new A)}exit(){if(void 0===document.exitFullscreen){const e=document;return void 0===e.webkitExitFullscreen?t().Promise.reject(new a):null===e.webkitFullscreenElement?t().Promise.reject(new o("Not in fullscreen mode")):(e.webkitExitFullscreen(),new(t().Promise)(((t,n)=>{setTimeout((()=>{null===e.webkitFullscreenElement?(f.log("Exiting fullscreen mode..."),t()):n(new TypeError)}),100)})))}return null===document.fullscreenElement?t().Promise.reject(new o("Not in fullscreen mode")):new(t().Promise)(((e,t)=>{document.exitFullscreen().then((()=>{f.log("Exiting fullscreen mode..."),e()}),t)}))}isAvailable(){return document.fullscreenEnabled||!!document.webkitFullscreenEnabled}isActivated(){return void 0!==document.fullscreenElement?document.fullscreenElement===this._container:void 0!==document.webkitFullscreenElement&&document.webkitFullscreenElement===this._container}_triggerEvent(){const e=new Pe("fullscreenchange");this._viewport.dispatchEvent(e)}}class Me{constructor(e){this._viewport=e,this._timeout=null,this._resize=this._onResize.bind(this),this._triggerResize=this.triggerResize.bind(this),this._resizeStrategy=new ke,this._viewport.addEventListener("resize",this._resize),this.triggerResize(0)}init(){window.addEventListener("resize",this._triggerResize),void 0!==screen.orientation?screen.orientation.addEventListener("change",this._triggerResize):window.addEventListener("orientationchange",this._triggerResize),this.triggerResize(0)}release(){void 0!==screen.orientation?screen.orientation.removeEventListener("change",this._triggerResize):window.removeEventListener("orientationchange",this._triggerResize),window.removeEventListener("resize",this._triggerResize),this._viewport.removeEventListener("resize",this._resize),this._resizeStrategy.clear(this._viewport)}triggerResize(e=100){const t=new Pe("resize");e<=0?this._viewport.dispatchEvent(t):(null!==this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>{this._timeout=null,this._viewport.dispatchEvent(t)}),e))}setStrategy(e){this._resizeStrategy.clear(this._viewport),this._resizeStrategy=e,this.triggerResize(0)}setStrategyByName(e){switch(e){case"best-fit":this.setStrategy(new ze);break;case"stretch":this.setStrategy(new Le);break;case"inline":this.setStrategy(new ke);break;default:throw new r("Invalid viewport style: "+e)}}_onResize(){const e=this._viewport,t=e.canvas,n=e.virtualSize;t.width=n.width,t.height=n.height;const i=e._backgroundCanvas,s=e._realSize;i.width=s.width,i.height=s.height,this._resizeStrategy.resize(e)}}class De{clear(e){e.container.style.cssText="",e._subContainer.style.cssText=""}}class ke extends De{resize(e){const t=e.container,n=e._subContainer,i=e.virtualSize;t.style.display="inline-block",t.style.position="relative",t.style.left="0px",t.style.top="0px",t.style.width=i.width+"px",t.style.height=i.height+"px",n.style.position="absolute",n.style.left="0px",n.style.top="0px",n.style.width="100%",n.style.height="100%"}}class Ke extends De{resize(e){const t=e.container;t.style.position="fixed",t.style.left="0px",t.style.top="0px",t.style.width="100vw",t.style.height="100vh",t.style.zIndex=String(1e9)}}class ze extends Ke{resize(e){const t=e._subContainer,n=window.innerWidth/window.innerHeight,i=e._realSize.width/e._realSize.height;let s=1,r=1,o="0px",a="0px";i<=n?(r=window.innerHeight,s=Math.round(r*i),s-=s%2,o=`calc(50% - ${s>>>1}px)`):(s=window.innerWidth,r=Math.round(s/i),r-=r%2,a=`calc(50% - ${r>>>1}px)`),t.style.position="absolute",t.style.left=o,t.style.top=a,t.style.width=s+"px",t.style.height=r+"px",super.resize(e)}}class Le extends Ke{resize(e){const t=e._subContainer;t.style.position="absolute",t.style.left="0px",t.style.top="0px",t.style.width=window.innerWidth+"px",t.style.height=window.innerHeight+"px",super.resize(e)}}class Te extends ve{constructor(e){const t=Object.assign({},we,e);super();const n=window.innerWidth/window.innerHeight,i=f.resolution(t.resolution,n);this._mediaSize=()=>i,this._resolution=t.resolution,this._style=t.style,this._containers=new Be(t.container),this._hud=new Ce(this._subContainer,t.hudContainer),this._canvases=new be(this._subContainer,i,t.canvas),this._resizer=new Me(this),this._resizer.setStrategyByName(this._style),this._fullscreen=new Qe(this),this._fullscreenButton=null,t.fullscreenUI&&this.fullscreenAvailable&&(this._fullscreenButton=new Se(this))}get container(){return this._containers.container}get style(){return this._style}get hud(){return this._hud}get resolution(){return this._resolution}get virtualSize(){const e=this._realSize,t=e.width/e.height;return f.resolution(this._resolution,t)}get fullscreen(){return this._fullscreen.isActivated()}get fullscreenAvailable(){return this._fullscreen.isAvailable()}get canvas(){return this._canvases.foregroundCanvas}get _backgroundCanvas(){return this._canvases.backgroundCanvas}get _realSize(){return this._mediaSize()}get _subContainer(){return this._containers.subContainer}requestFullscreen(){return this._fullscreen.request()}exitFullscreen(){return this._fullscreen.exit()}convertToPixels(e){const t=this.canvas,n=.5*(1+e.x)*t.width,i=.5*(1-e.y)*t.height;return new de(n,i)}_init(e,t){var n;"immersive"==t?"best-fit"!=this._style&&"stretch"!=this._style&&(f.warning(`Invalid viewport style "${this._style}" for the "${t}" mode`),this._style="best-fit",this._resizer.setStrategyByName(this._style)):"inline"==t&&"inline"!=this._style&&(f.warning(`Invalid viewport style "${this._style}" for the "${t}" mode`),this._style="inline",this._resizer.setStrategyByName(this._style)),this._mediaSize=e,this._containers.init(),this._hud._init(2),this._canvases.init(),this._resizer.init(),this._fullscreen.init(),null===(n=this._fullscreenButton)||void 0===n||n.init()}_release(){var e;null===(e=this._fullscreenButton)||void 0===e||e.release(),this._fullscreen.release(),this._resizer.release(),this._canvases.release(),this._hud._release(),this._containers.release()}}class Re{static startSession(e){return M.instantiate(e)}static isSupported(){return M.isSupported()}static get version(){return"0.4.0"}static get Speedy(){return t()}static get Tracker(){return ue}static get Source(){return xe}static Viewport(e){return new Te(e)}static get Settings(){return D}}Object.freeze(Re),(e=>{e.Speedy=e.Speedy||t()})(window),f.log(`encantar.js version ${Re.version}. GPU-accelerated Augmented Reality for the web by Alexandre Martins. https://github.com/alemart/encantar-js`)})(),i=i.default})()));
|