function JPEGEncoderThreaded(i){var f;var d=i||"jpeg_encoder_threaded_worker.js";var h=new Worker(d);var g=0;var e=[];var l=this;var b="json";var k=0;var j=(function(){var o=String.fromCharCode;var m=new Array(256);for(var n=0;n<256;n++){m[n]=o(n)}return m})();h.onmessage=function(o){var n;if(b=="json"){n=JSON.parse(o.data);k=n.cacheIndex;b="datauri"}else{n=e[k];var m=new Date().getTime()-f;console.log("Threaded encoding time: "+m+"ms");n.callback("data:image/jpeg;base64,"+btoa(o.data));if(!n._cache){e[k]=null}b="json"}};this.encode=function(n,p,o,m){f=new Date().getTime();return a(n,p,o,m,false)};this.prepareImage=function(m,o,n){return a(m,o,n,true,true)};function a(p,v,x,n,u){var y=new c(l,g,v,x,n);e[g]=y;g++;var o=u?"cache_only":"encode_new";h.postMessage(JSON.stringify({command:o,data:{cacheIndex:y._cachedImageIndex,quality:y.quality,cache:y._cache,width:p.width,height:p.height}}));var m=p.data;var t=m.length;var w=new Array((t/4)*3);var s=0;for(var r=0;r<t;r+=4){w[s++]=j[m[r]];w[s++]=j[m[r+1]];w[s++]=j[m[r+2]]}var q=w.join("");w=null;h.postMessage(q);q=null;if(n){return y}else{return true}}this._encodeCached=function(m,o,n){f=new Date().getTime();h.postMessage(JSON.stringify({command:"encode_cached",data:{cacheIndex:m,quality:o}}))};this.clearCaches=function(){g=0;e=[];h.postMessage(JSON.stringify({command:"clear_caches"}))};function c(n,o,q,p,m){var n=n;this._cachedImageIndex=o;this._cache=m;this.quality=q;this.callback=p;this.encode=function(r){if(r){this.quality=r}n._encodeCached(this._cachedImageIndex,this.quality,this.callback)}}}function getImageDataFromImage(b){var c=(typeof(b)=="string")?document.getElementById(b):b;var d=document.createElement("canvas");d.width=c.width;d.height=c.height;var a=d.getContext("2d");a.drawImage(c,0,0);return(a.getImageData(0,0,d.width,d.height))};