/*! * ONNX Runtime Common v1.14.0 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ort=e():t.ort=e()}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{InferenceSession:()=>c,Tensor:()=>g,env:()=>i,registerBackend:()=>o});const r={},n=[],o=(t,e,o)=>{if(!e||"function"!=typeof e.init||"function"!=typeof e.createSessionHandler)throw new TypeError("not a valid backend");{const i=r[t];if(void 0===i)r[t]={backend:e,priority:o};else{if(i.priority>o)return;if(i.priority===o&&i.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${o}`)}if(o>=0){const e=n.indexOf(t);-1!==e&&n.splice(e,1);for(let e=0;e{let e=1;for(let r=0;r{const o=document.createElement("canvas"),i=o.getContext("2d");if(!t||!i)return n();const a=new Image;a.crossOrigin="Anonymous",a.src=t,a.onload=()=>{o.width=a.width,o.height=a.height,i.drawImage(a,0,0,o.width,o.height);const t=i.getImageData(0,0,o.width,o.height);if(void 0!==e){if(void 0!==e.height&&e.height!==o.height)throw new Error("Image input config height doesn't match ImageBitmap height");if(s.height=o.height,void 0!==e.width&&e.width!==o.width)throw new Error("Image input config width doesn't match ImageBitmap width");s.width=o.width}else s.height=o.height,s.width=o.width;r(h.bufferToTensor(t.data,s))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{const r="RGBA";let n,o;if(void 0!==e&&void 0!==e.resizedWidth&&void 0!==e.resizedHeight?(n=e.resizedHeight,o=e.resizedWidth):(n=t.height,o=t.width),void 0!==e){if(s=e,void 0!==e.bitmapFormat&&e.bitmapFormat!==r)throw new Error("Image input config format must be RGBA for ImageData");s.bitmapFormat="RGBA"}else s.bitmapFormat="RGBA";if(s.height=n,s.width=o,void 0!==e){const e=document.createElement("canvas");e.width=o,e.height=n;const r=e.getContext("2d");if(null==r)throw new Error("Can not access image data");r.putImageData(t,0,0),a=r.getImageData(0,0,o,n).data}else a=t.data}}if(void 0!==a)return h.bufferToTensor(a,s);throw new Error("Input data provided is not supported - aborted tensor creation")}toImageData(t){var e,r;const n=document.createElement("canvas").getContext("2d");let o;if(null==n)throw new Error("Can not access image data");{const i=this.dims[3],a=this.dims[2],s=this.dims[1],f=void 0!==t&&void 0!==t.format?t.format:"RGB",d=void 0!==t&&void 0!==(null===(e=t.norm)||void 0===e?void 0:e.mean)?t.norm.mean:255,h=void 0!==t&&void 0!==(null===(r=t.norm)||void 0===r?void 0:r.bias)?t.norm.bias:0,g=a*i;if(void 0!==t){if(void 0!==t.height&&t.height!==a)throw new Error("Image output config height doesn't match tensor height");if(void 0!==t.width&&t.width!==i)throw new Error("Image output config width doesn't match tensor width");if(void 0!==t.format&&4===s&&"RGBA"!==t.format||3===s&&"RGB"!==t.format&&"BGR"!==t.format)throw new Error("Tensor format doesn't match input tensor dims")}const m=4;let c=0,l=1,u=2,w=3,p=0,y=g,b=2*g,v=-1;"RGBA"===f?(p=0,y=g,b=2*g,v=3*g):"RGB"===f?(p=0,y=g,b=2*g):"RBG"===f&&(p=0,b=g,y=2*g),o=n.createImageData(i,a);for(let t=0;t=r.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${r.byteLength}).`);if(f=t.byteLength-n,"number"==typeof o){if(f=o,!Number.isSafeInteger(f))throw new RangeError("'byteLength' must be an integer.");if(f<=0||n+f>r.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${r.byteLength-n}].`);if("object"==typeof i&&null!==i)s=i;else if(void 0!==i)throw new TypeError("'options' must be an object.")}else if(void 0!==o)throw new TypeError("'byteLength' must be a number.")}else if(void 0!==e)throw new TypeError("'options' must be an object.");a=new Uint8Array(r,n,f)}}const f=(s.executionProviders||[]).map((t=>"string"==typeof t?t:t.name)),d=await(async t=>{const e=0===t.length?n:t,o=[];for(const t of e){const e=r[t];if(e){if(e.initialized)return e.backend;if(e.aborted)continue;const r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init()),await e.initPromise,e.initialized=!0,e.backend}catch(n){r||o.push({name:t,err:n}),e.aborted=!0}finally{delete e.initPromise}}}throw new Error(`no available backend found. ERR: ${o.map((t=>`[${t.name}] ${t.err}`)).join(", ")}`)})(f),h=await d.createSessionHandler(a,s);return new m(h)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}const c=m;return e})())); //# sourceMappingURL=ort-common.min.js.map