Caman=(function(_super){__extends(Caman,_super);Caman.version={release:"4.1.2",date:"7/27/2013"};Caman.DEBUG=false;Caman.allowRevert=true;Caman.crossOrigin="anonymous";Caman.remoteProxy="";Caman.proxyParam="camanProxyUrl";Caman.NodeJS=typeofexports!=="undefined"&&exports!==null;Caman.autoload=!Caman.NodeJS;Caman.toString=function(){return"Version "+Caman.version.release+", Released "+Caman.version.date;};Caman.getAttrId=function(canvas){if(Caman.NodeJS){returntrue;}
if(this.initObj==null){throw"Could not find image or canvas for initialization.";}
returnthis.initType=this.initObj.nodeName.toLowerCase();};Caman.prototype.setup=function(){switch(this.initType){case"node":returnthis.initNode();case"img":returnthis.initImage();case"canvas":returnthis.initCanvas();}};Caman.prototype.initNode=function(){Log.debug("Initializing for NodeJS");if(typeofthis.initObj==="string"&&this.initObj.match(/^https?:\/\//)){returnthis.readFromHttp(this.initObj,this.nodeFileReady);}elseif(typeofthis.initObj==="string"){returnfs.readFile(this.initObj,this.nodeFileReady);}else{returnthis.nodeFileReady(null,this.initObj);}};Caman.prototype.readFromHttp=function(url,callback){varreq;Log.debug("Fetching image from "+url);req=http.get(url,function(res){varbuf;buf='';res.setEncoding('binary');res.on('data',function(chunk){returnbuf+=chunk;});returnres.on('end',function(){returncallback(null,newBuffer(buf,'binary'));});});returnreq.on('error',callback);};Caman.prototype.nodeFileReady=function(err,data){if(err){throwerr;}
ratio=this.hiDPIRatio();if(ratio!==1){Log.debug("HiDPI ratio = "+ratio);this.scaled=true;this.preScaledWidth=this.canvas.width;this.preScaledHeight=this.canvas.height;this.canvas.width=this.preScaledWidth*ratio;this.canvas.height=this.preScaledHeight*ratio;this.canvas.style.width=""+this.preScaledWidth+"px";this.canvas.style.height=""+this.preScaledHeight+"px";this.context.scale(ratio,ratio);this.width=this.originalWidth=this.canvas.width;returnthis.height=this.originalHeight=this.canvas.height;}};Caman.prototype.hiDPIRatio=function(){varbackingStoreRatio,devicePixelRatio;devicePixelRatio=window.devicePixelRatio||1;backingStoreRatio=this.context.webkitBackingStorePixelRatio||this.context.mozBackingStorePixelRatio||this.context.msBackingStorePixelRatio||this.context.oBackingStorePixelRatio||this.context.backingStorePixelRatio||1;returndevicePixelRatio/backingStoreRatio;};Caman.prototype.hiDPICapable=function(){return(window.devicePixelRatio!=null)&&window.devicePixelRatio!==1;};Caman.prototype.needsHiDPISwap=function(){if(this.hiDPIDisabled()||!this.hiDPICapable()){returnfalse;}
returnbezier;};Calculate.hermite=function(controlPoints,lowBound,highBound){varadd,clamp,count,endX,fac0,fac1,fac2,fac3,i,j,lerp,m0,m1,mul,p,p0,p1,pointsPerSegment,pointsPerStep,pos,ret,sub,t,_i,_j,_ref,_this=this;if(controlPoints.length<2){throw"Invalid number of arguments to hermite";}
returnthis.isURLRemote(img.src);};IO.corsEnabled=function(img){var_ref;return(img.crossOrigin!=null)&&((_ref=img.crossOrigin.toLowerCase())==='anonymous'||_ref==='use-credentials');};IO.isURLRemote=function(url){varmatches;matches=url.match(this.domainRegex);if(matches){returnmatches[1]!==document.domain;}else{returnfalse;}};IO.remoteCheck=function(src){if(this.isURLRemote(src)){if(!Caman.remoteProxy.length){Log.info("Attempting to load a remote image without a configured proxy. URL: "+src);}else{if(Caman.isURLRemote(Caman.remoteProxy)){Log.info("Cannot use a remote proxy for loading images.");return;}
returnfs.writeFile(file,this.canvas.toBuffer(),function(err){Log.debug("Finished writing to "+file);if(callback){returncallback.call(this,err);}});};Caman.prototype.toImage=function(type){varimg;img=newImage();img.src=this.toBase64(type);img.width=this.dimensions.width;img.height=this.dimensions.height;if(window.devicePixelRatio){img.width/=window.devicePixelRatio;img.height/=window.devicePixelRatio;}
Pixel.prototype.setContext=function(c){returnthis.c=c;};Pixel.prototype.locationXY=function(){varx,y;if(this.c==null){throw"Requires a CamanJS context";}
y=this.c.dimensions.height-Math.floor(this.loc/(this.c.dimensions.width*4));x=(this.loc%(this.c.dimensions.width*4))/4;return{x:x,y:y};};Pixel.prototype.pixelAtLocation=function(loc){if(this.c==null){throw"Requires a CamanJS context";}
returnnewPixel(this.c.pixelData[loc],this.c.pixelData[loc+1],this.c.pixelData[loc+2],this.c.pixelData[loc+3],this.c);};Pixel.prototype.getPixelRelative=function(horiz,vert){varnewLoc;if(this.c==null){throw"Requires a CamanJS context";}
returnthis.pixelAtLocation(newLoc);};Pixel.prototype.putPixelRelative=function(horiz,vert,rgba){varnowLoc;if(this.c==null){throw"Requires a CamanJS context";}
this.c.pixelData[newLoc]=rgba.r;this.c.pixelData[newLoc+1]=rgba.g;this.c.pixelData[newLoc+2]=rgba.b;this.c.pixelData[newLoc+3]=rgba.a;returntrue;};Pixel.prototype.getPixel=function(x,y){varloc;if(this.c==null){throw"Requires a CamanJS context";}
loc=this.coordinatesToLocation(x,y,this.width);returnthis.pixelAtLocation(loc);};Pixel.prototype.putPixel=function(x,y,rgba){varloc;if(this.c==null){throw"Requires a CamanJS context";}