@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.17 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import t from"../../../../core/Error.js";const e=16;function n(t){return Math.ceil(t/e)*e}function i(t){return Math.floor(t/e)*e}function r(t,e){const n=1048576,i=4096,r=2;let h=t.width*t.height;if(h<i)return t instanceof ImageData?a(t):t;let c=t.width,u=t.height;do{c=Math.ceil(c/r),u=Math.ceil(u/r),h=c*u}while(h>n||null!=e&&(c>e||u>e));return o(t,c,u)}function h(t,e){const n=Math.max(t.width,t.height);if(n<=e)return t;const i=e/n;return o(t,Math.round(t.width*i),Math.round(t.height*i))}function o(t,e,n){if(t instanceof ImageData)return o(a(t),e,n);const i=document.createElement("canvas");i.width=e,i.height=n;return i.getContext("2d").drawImage(t,0,0,i.width,i.height),i}function a(e){const n=document.createElement("canvas");n.width=e.width,n.height=e.height;const i=n.getContext("2d");if(null==i)throw new t("Failed to create 2d context from HTMLCanvasElement");return i.putImageData(e,0,0),n}export{i as applyTextureResizeFloorModulo,n as applyTextureResizeModulo,r as downsampleImage,h as ensureImageMaxSize};