// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/utils/ImageUtil",["dojo/_base/lang","dojo/Deferred","dojo/dom-construct","dojo/when"],function(n,l,g,m){var e={base64DataToDataURL:function(a,b){if(/^data:image/.test(a))return a;if(!b){var c=atob(a.substr(0,16));b=e.getImageContentType(c)}return"data:"+(b||"image/png")+";base64,"+a},getImageContentType:function(a){if("\u00ff\u00d8\u00ff"==a.substr(0,3)&&"JFIF"==a.substr(6,4))return"image/jpeg";if("\u0089PNG\r\n\u001a\n"==a.substr(0,8))return"image/png";if("GIF89a"==
a.substr(0,6)||"GIF87a"==a.substr(0,6))return"image/gif"},base64DataFromDataURL:function(a){0==a.indexOf("data:")&&(a=a.substr(a.indexOf(",")+1));return a},getBase64DataIndex:function(a){a=0==a.indexOf("data:")?a.indexOf(";base64,"):-1;return 0<a?a+8:0},getContentType:function(a){var b=e.getBase64DataIndex(a);return b?a.substring(5,b-8):null},checkBase64FileSize:function(a,b){return e.getBase64FileSize(a)<=b},getBase64FileSize:function(a){return.75*a.length},imageToDataURL:function(a,b){b=b||{};var c=
document.createElement("canvas"),e=c.getContext("2d");c.width=b.width||a.width;c.height=b.height||a.height;var d=b.opacity;null!=d&&!isNaN(d)&&0<=d&&1>d&&(e.globalAlpha=+d,b.format="image/png");(d=b.pos)?e.drawImage(a,d.x||0,d.y||0):e.drawImage(a,0,0,c.width,c.height);return c.toDataURL(b.format)},imageFromUrl:function(a){var b=new l,c=new Image;0!==a.indexOf("data:")&&c.setAttribute("crossOrigin","anonymous");c.onload=function(){c.width&&c.height?b.resolve(c):b.reject(Error("Error of reading an image from URL."));
g.destroy(c)};c.onerror=function(a){b.reject(a);g.destroy(c)};c.src=require.toUrl(a);return b.promise},scaleImage:function(a,b){if("string"===typeof a)var c=e.base64DataToDataURL(a),g=e.getContentType(c),c=e.imageFromUrl(c);return m(c||a).then(function(a){var c=1,d=a.width,f=a.height;if(b.factor)c=b.factor;else if(b.maxDim)c=b.maxDim/Math.max(d,f);else if(b.imageDim){var h=b.imageDim.w,k=b.imageDim.h;b.imageDim.preserveRatio?(c=Math.min(h/d,k/f),b.imageDim.reduceOnly&&1<c&&(c=1)):b.imageDim.reduceOnly?
(d=Math.min(d,h),f=Math.min(f,k)):(d=h,f=k)}return e.imageToDataURL(a,{width:d*c,height:f*c,format:b.format||g,opacity:b.opacity})})}};return e});