UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.4 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ class t{applyColorSubstitution(t,a){if(!a)return t;this._rasterizationCanvas||(this._rasterizationCanvas=document.createElement("canvas"));const{width:e,height:n}=t,o=this._rasterizationCanvas,r=o.getContext("2d",{willReadFrequently:!0});t!==o&&(o.width=e,o.height=n,r.drawImage(t,0,0,e,n));const i=r.getImageData(0,0,e,n).data;if(a)for(const l of a)if(l&&l.oldColor&&4===l.oldColor.length&&l.newColor&&4===l.newColor.length){const[t,a,e,n]=l.oldColor,[o,r,s,h]=l.newColor;if(t===o&&a===r&&e===s&&n===h)continue;for(let l=0;l<i.length;l+=4)t===i[l]&&a===i[l+1]&&e===i[l+2]&&n===i[l+3]&&(i[l]=o,i[l+1]=r,i[l+2]=s,i[l+3]=h)}const s=new ImageData(i,e,n);return r.putImageData(s,0,0),o}tintImageData(t,a){if(!a||a.length<4)return t;this._rasterizationCanvas||(this._rasterizationCanvas=document.createElement("canvas"));const{width:e,height:n}=t,o=this._rasterizationCanvas,r=o.getContext("2d",{willReadFrequently:!0});t!==o&&(o.width=e,o.height=n,r.drawImage(t,0,0,e,n));const i=r.getImageData(0,0,e,n),s=new Uint8Array(i.data),l=[a[0]/255,a[1]/255,a[2]/255,a[3]/255];for(let g=0;g<s.length;g+=4)s[g]*=l[0],s[g+1]*=l[1],s[g+2]*=l[2],s[g+3]*=l[3];const h=new ImageData(new Uint8ClampedArray(s.buffer),e,n);return r.putImageData(h,0,0),o}}export{t as default};