Ingår i temat
Hjärnkoll
Läs senare

De dansar loss sin kreativitet

Det kunde vara ett disko för mellanstadieelever. Men det är ett hjärnexperiment.

16 Maj 2012

Foto: Ciprian Gorga
Strålkastarna spelar över dansgolvet. Några hundra elever strömmar ut och in i lokalen, pratar, fnissar och dansar lite grand till musiken som spelas på upplevelsecentret Brewhouse i Göteborg.

Uppe på scenen står Peter Österberg, doktorand i psykologi, med mikrofon i hand. Han ska berätta för eleverna att det händer något med människors känslor, eller emotioner som han säger, när man dansar.

— Om man är ledsen eller arg när man börjar dansa så blir man ofta glad när man dansat ett tag. Och är man glad kan det bli lättare att lära sig.

Bredvid honom improviserar elever från Svenska Balettskolan. De ska försöka uttrycka de emotioner Peter Österberg pratar om för att inspirera eleverna på golvet.

I nära 30 minuter ska eleverna skaka loss precis på det sätt de själva vill.

— Efter 20—30 minuter börjar det hända grejor när man dansar. Man börjar känna välbehag. Musiken och den sociala gemenskapen bidrar också till de positiva känslorna, berättar han vidare.

Danshavet böljar i gång igen. Några småkillar tränar på streetdansens elektriska rörelser. Tre tjejer studsar upp och ner. Några hoppar förbi i en lång rad med händerna på varandras axlar.

När tiden har gått stoppar musiken och Peter Österberg berättar för eleverna att de ska få göra ett test. Varje elev får ett papper med bokstäverna D och J på.

— Nu ska ni kombinera bokstäverna på så många sätt ni kan komma på. Känner ni er osäkra så chansa bara!

Casper Bech, 11 år, från Surte skola, sätter sig på knä på golvet och har snart pappret fullt med olika DJ-krumelurer.

— Jag bara ritade. Jag vet inte var idéerna kom ifrån. Kanske får man fler när man har dansat först?

Hans klasskamrat Julia Brundin kände sig lite osäker först men kollade på kompisen bredvid.

— Då kom jag loss och satte ihop bokstäverna på nytt. Jag både tror och inte tror att man blir mer kreativ av att dansa först, säger hon lite skeptiskt.

Efter fem minuter samlas papprena in. Tidigare har Peter Österberg låtit en grupp elever göra samma test, fast denna gång satt eleverna stilla innan testet gjordes. Efter en liten stund kommer resultaten upp på skärmen. Stillasittande elever producerar i genomsnitt 1,55 idéer medan de som dansat kommit på 2,43 i genomsnitt, visar det sig.

— Det verkar som det behövs mer dans i skolan. Efter 25 minuters dans är ni nästan dubbelt så kreativa som de som suttit stilla, säger Peter Österberg.

Men varför blir det så här? Jo, hjärnans belöningssystem tycks samspela med hjärnans inlärningsprocesser, förklarar Peter Österberg.

Dansen verkar påverka den här relationen. När man får en ny uppgift som innebär en utmaning triggas kommunikationen mellan dessa båda instanser: belöning och inlärning.

— Det var det som hände i testsituationen som eleverna var med om. Då börjar belöningssystem och inlärningsprocesser prata med varandra och nya kreativa idéer uppstår.

Men det gäller att dansen är improviserad. En koreograferad dans har inte samma effekter. Det beror på att den improviserade dansen, precis som vilken annan icke-styrd process som helst, ger dansaren ett mycket större utrymme att skapa själv. En koreograferad dans får dansaren att känna sig styrd. Och styrda människor blir mindre kreativa.

]*"|true|false|null|-?d+(?:.d*)?(?:[eE][+-]?d+)?/g, "]").replace(/(?:^|:|,)(?:s*[)+/g,"")))return e=eval("("+a+")"),typeof b==="function"?c({"":e},""):e;throw new SyntaxError("AV.JSON.parse");}})();typeof AV=="undefined"&&(AV={});AV.getCanvasPixelData=function(a){return a.getContext("2d").getImageData(0,0,a.width,a.height)};AV.clearCanvas=function(a){a.width=a.width};AV.sqrDist=function(a,b,c,d){a=c-a;b=d-b;return a*a+b*b};AV.sign=function(a){return a<0?-1:1};AV.drawImageCopy=function(a,b,c,d){var e=a.globalCompositeOperation;a.save();a.beginPath();a.rect(c,d,b.width,b.height);a.clip();a.closePath();a.globalCompositeOperation="copy";a.drawImage(b,c,d);a.globalCompositeOperation=e;a.restore()}; AV.getImageDataRegion=function(a,b,c,d,e,f){var g,h=a.width,i=a.height;if(b<0||c<0||b+d>h||c+e>i){if(g=document.createElement("canvas"),g.width=d,g.height=e,g=g.getContext("2d"),g.drawImage(a,-b,-c),g=g.getImageData(0,0,d,e),f)for(var j=a.getContext("2d"),a=j.getImageData(0,0,h,1).data,f=j.getImageData(0,i-1,h,1).data,k=j.getImageData(0,0,1,i).data,j=j.getImageData(h-1,0,1,i).data,p=g.data,m=0;m<e;m++){var l=null,n=m+c;n<0&&(n=0,l=a);n>=i&&(n=i-1,l=f);for(var q=0;q<d;q++){var o=null,r=q+b;r<0&&(r= 0,o=k);r>=h&&(r=h-1,o=j);var s=(q+m*d)*4;o?(r=n*4,p[s++]=o[r++],p[s++]=o[r++],p[s++]=o[r++],p[s]=o[r]):l?(o=r*4,p[s++]=l[o++],p[s++]=l[o++],p[s++]=l[o++],p[s]=l[o]):q=h-b-1}}}else g=a.getContext("2d"),g=g.getImageData(b,c,d,e);return g}; AV.putImageDataRegion=function(a,b,c,d){var e=a.getContext("2d"),f;f=a.width;var g=a.height,a=b.width,h=b.height;c<0||d<0||c+a>=f||d+h>=g?(f=document.createElement("canvas"),f.width=a,f.height=h,a=f.getContext("2d"),a.putImageData(b,0,0),e.drawImage(f,c,d)):e.putImageData(b,c,d)}; AV.copyCanvas=function(a,b,c,d,e){var f=document.createElement("canvas");e===void 0?(f.width=a.width,f.height=a.height,d=f.getContext("2d"),d.drawImage(a,0,0)):(f.width=d,f.height=e,d=f.getContext("2d"),d.drawImage(a,-b,-c));return f};AV.Bbox=function(a,b,c,d,e){d!==void 0?(this.x0=a,this.y0=b,this.x1=c,this.y1=d,this.w=this.x1-this.x0,this.h=this.y1-this.y0,this.margin=e!==void 0?e:0):this.reset()}; AV.Bbox.prototype.include=function(a,b){var c=a-this.margin,d=b-this.margin,e=a+this.margin,f=b+this.margin;if(this.x0>c)this.x0=c;if(this.y0>d)this.y0=d;if(this.x1<e)this.x1=e;if(this.y1<f)this.y1=f;this.w=this.x1-this.x0;this.h=this.y1-this.y0};AV.Bbox.prototype.reset=function(){this.y0=this.x0=999999999;this.y1=this.x1=-999999999;this.margin=this.h=this.w=0};AV.Bbox.prototype.contains=function(a,b){var c=b>=this.y0&&b<=this.y1;return a>=this.x0&&a<=this.x1&&c}; AV.Layer=function(a){this.image=this.canvas=this.drawable=null;if(a.image!==void 0)this.image=this.drawable=a.image,this.type="image";else if(a.canvas!==void 0)this.canvas=this.drawable=a.canvas,this.type="canvas";this.name=a.name;this.translateX=this.translateY=this.rotate=0;this.scaleX=this.scaleY=1};AV.Layer.prototype.worldToLocal=function(a){a.x-=this.translateX;a.y-=this.translateY;var b=Math.cos(-this.rotate),c=Math.sin(-this.rotate),d=a.x;a.x=d*b-a.y*c;a.y=d*c+a.y*b;a.x/=this.scaleX;a.y/=this.scaleY}; AV.Layer.prototype.localToWorld=function(a){this.centerX&&(a.x-=this.centerX);this.centerY&&(a.y-=this.centerY);a.x*=this.scaleX;a.y*=this.scaleY;var b=Math.cos(this.rotate),c=Math.sin(this.rotate),d=a.x;a.x=d*b-a.y*c;a.y=d*c+a.y*b;a.x+=this.translateX;a.y+=this.translateY};AV.Layer.prototype.localPointIn=function(a){var b=0,c=0;this.centerX&&(b-=this.centerX);this.centerY&&(c-=this.centerY);return a.x>=b&&a.y>=c&&a.x<b+this.drawable.width&&a.y<c+this.drawable.height}; AV.PaintWidget=function(a,b){this.imageElementClean=null;this.busy=!1;this.moduleLoadedCallback={};this.active=null;this.layers=[];this.dirtyRect={bbox:new AV.Bbox,dirty:!1};this.canvas=document.createElement("canvas");this.setDimensions(a,b);avpw$(this.canvas).click(this.canvasClicked.AV_bindInst(this));this._mouseMoveHandler=this.canvasMouseMove.AV_bindInst(this);avpw$(window).mousemove(this._mouseMoveHandler);avpw$(this.canvas).mousedown(this.canvasMouseDown.AV_bindInst(this));this._mouseUpHandler= this.canvasMouseUp.AV_bindInst(this);avpw$(window).mouseup(this._mouseUpHandler);avpw$(this.canvas).mouseleave(this.canvasMouseOut.AV_bindInst(this));avpw$(this.canvas).css("display","block");avpw$(this.canvas).droppable({drop:this.canvasMouseDrop.AV_bindInst(this)});this.actionStack=[];this.actionStackIndex=-1;this.dirty=!1;this.actionListScaleFactor=this.prevActionListScaleFactor=1;this.setMouseCursor();this.closeXImg=document.createElement("img");this.closeXImg.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAnRJREFUeNpi1KzexoAHcACxLRDbALEREDNDxf8C8TkgPgLEh4H4Bz5DWHCIcwNxChCnQdnYgC4QxwPxVyCeBcRzoGwMwIRFTB+IdwNxIR4L0B0EUrsXqpegJa5AvBKIpRhIBxJQvU74LAF5fzI0HsgFIL3ToGZhWALy8kwKLUC2aCZyUMMsSSQziHABKaiZcEtANmfiUp1qp8TnqSvJhSzGz8nKVOSmzq8jzc+Gx6JMWMiwQPMB1lRkrSLCUeimLghif/r+++XRO2/A+WFarLGooZwgh7GCIEf0rBMv8aQ6kNm7QT7xxOUUkKHnH70HG9wfaSgK8wHIApBY+9br7wkEmzssuFTxqcpafPb1y08//vCwszBtyLWRTLFTEgBbuuvm+ytPP/4iYIk6zBJhfKo+fv/9L3fpudcgtjgfB7iE2Hbp+ZfZh+59IiIBCOPK8QQBLwcLSfpAit8SUtQWrAd2ESjYQLStmigXeorDAd7CLLmNT1W9n7agihgP25eff/7Fzz35cuWpR+BgagzQEQYlBAKW3IZZshOXClASDjeT4wOxZx+8+/HR229/Juy+9RGWELpC9YUJWLITZslBXEW0lhQfOLOBkjEsokEJoWbdZXAwGMoL4iuGvkLNBmfGH9D6oBBdFcjga88+/UJPqqD8Ezb92PNPP37/w2PJLFhlxgitGbmhdQi1yq9n0GrjK3IS/gota35QwYIfULO+YqtPLgJxPoUWgfTmQs3CWTOCUkM4EL8gw4IXUL27ianjQa5wBhVPuFIdllTUD9VzkZTWCkjjRGgLBNQcsodWqchNosvQJHqEkGNYiHDlTnwZlhgAEGAAhDXCxwG4D58AAAAASUVORK5CYII="; this.overlayRegistry=function(){var a={};return{add:function(b,e){a=e},getClean:function(b){if(!a)return null;return a}}}()};AV.PaintWidget.prototype.setOrigSize=function(a,b){this._origWidth=Math.floor(a);this._origHeight=Math.floor(b)};AV.PaintWidget.prototype.c2a=function(a,b){var c=a*this.actionListScaleFactor;b&&(c=Math.floor(c));return c};AV.PaintWidget.prototype.a2c=function(a,b){var c=a/this.actionListScaleFactor;b&&(c=Math.floor(c));return c}; AV.PaintWidget.prototype.setBackground=function(a){var b,c,d;this.imgElementClean=a;b=document.createElement("canvas");b.width=this.width;b.height=this.height;d=b.getContext("2d");d.drawImage(a,0,0,this.width,this.height);this.addLayer(new AV.Layer({canvas:b,name:"background"}));this.recomposite();this.currentLayerIndex=0;this.currentLayer=this.layers[this.currentLayerIndex];for(d in this.moduleLoadedCallback){c=this.moduleLoadedCallback[d];b=c.length;for(a=0;a<b;a++)c[a](d);this.moduleLoadedCallback[d]= null}};AV.PaintWidget.prototype.shutdown=function(){this.setMode(null);avpw$(this.canvas).unbind("click");avpw$(window).unbind("mousemove",this._mouseMoveHandler);this._mouseMoveHandler=null;avpw$(this.canvas).unbind("mousedown");avpw$(window).unbind("mouseup",this._mouseUpHandler);this._mouseUpHandler=null;avpw$(this.canvas).unbind("mouseleave");avpw$(this.canvas).unbind("drop");this.waitThrobberShow=this.moduleLoadedCallback=this.canvas=this.currentLayer=this.layers=null}; AV.PaintWidget.prototype.moduleLoaded=function(a,b){if(this.imgElementClean)return b&&b(a),!0;b&&(typeof this.moduleLoadedCallback[a]=="undefined"&&(this.moduleLoadedCallback[a]=[]),this.moduleLoadedCallback[a].push(b));return!1};AV.PaintWidget.prototype.setDimensions=function(a,b){this.canvas.width=this.width=a;this.canvas.height=this.height=b};AV.PaintWidget.prototype.getScaledSize=function(){return{width:this.c2a(this.width,!0),height:this.c2a(this.height,!0)}}; AV.PaintWidget.prototype.setActionListScaleFactor=function(a){this.prevActionListScaleFactor=this.actionListScaleFactor;this.actionListScaleFactor=a};AV.PaintWidget.prototype.setMouseCursor=function(a){a===void 0&&(a="default");avpw$(this.canvas).css("cursor",a)};AV.PaintWidget.prototype.showWaitThrobber=function(a,b){b&&setTimeout(b,5)};AV.PaintWidget.prototype.getBackgroundLayerIndex=function(){return 0}; AV.PaintWidget.prototype.findLayerIndexByName=function(a){var b;for(b=0;b<this.layers.length;b++)if(this.layers.name===a)return b;return-1};AV.PaintWidget.prototype.getLayerByName=function(a){a=this.findLayerIndexByName(a);if(a===-1)return null;return this.layers[a]};AV.PaintWidget.prototype.moveLayerByName=function(a,b,c){a=this.getLayerByName(a);if(a!==null)a.translateX=b,a.translateY=c}; AV.PaintWidget.prototype.setCurrentLayerByName=function(a){a=this.findLayerIndexByName(a);if(a===-1)return!1;this.currentLayerIndex=a;this.currentLayer=this.layers[a];return!0};AV.PaintWidget.prototype.layerToTop=function(a){for(var b=this.layers[a];a<this.layers.length-1;){var c=parseInt(a,10)+1;this.layers[a]=this.layers[c];a++}this.layers[a]=b}; AV.PaintWidget.prototype.layerDelete=function(a){for(;a<this.layers.length-1;){var b=parseInt(a,10)+1;this.layers[a]=this.layers;a++}this.layers.length-=1}; AV.PaintWidget.prototype.getLayerByMouseClickWithTag=function(a,b,c,d,e,f){var g,h,i,j,k,p,m;for(g=this.layers.length-1;g>=0;g--){var l=this.layers[g];if(!l.hidden&&!(c!==void 0&&l[c]!==d)){var n={x:a,y:b};l.worldToLocal(n);if(e!=null)e.x=n.x,e.y=n.y;if(e.thumbWidth&&e.thumbWidth>0)if(j=e.thumbOutset/l.scaleX,k=e.thumbOutset/l.scaleY,p=e.thumbWidth/l.scaleX,m=e.thumbWidth/l.scaleY,this.thumbHit=-1,f){if(f==1){k=j=2;h=0-j+p;i=l.drawable.height+k-m;l.centerX&&(h-=l.centerX);l.centerY&&(i-=l.centerY); if(n.x>=h-p*2&&n.x<=h&&n.y>=i&&n.y<=i+m*2&&!(n.x>=h-(p-j)&&n.x<=h&&n.y>=i&&n.y<=i+(m-k)))return e.thumbHit=2,l;h=l.drawable.width;i=0;l.centerX&&(h-=l.centerX);l.centerY&&(i-=l.centerY);h+=this.closeXImg.width*0.25/l.scaleX;i-=this.closeXImg.height*0.25/l.scaleY;j=this.closeXImg.width/2/l.scaleX;k=this.closeXImg.height/2/l.scaleY;if(n.x>=h-j&&n.x<=h+j&&n.y>=i-k&&n.y<=i+k)return e.thumbHit=1,l}}else{if(n.x>=l.drawable.width-p&&n.x<=l.drawable.width+j&&n.y<=l.drawable.height+k&&n.y>=l.drawable.height- m)return e.thumbHit=3,l;if(n.x>=0-j&&n.x<=p&&n.y>=0-k&&n.y<=m)return e.thumbHit=0,l;if(n.x>=0-j&&n.x<=p&&n.y<=l.drawable.height+k&&n.y>=l.drawable.height-m)return e.thumbHit=2,l;h=l.drawable.width+j;i=0-4/l.scaleX;j=l.drawable.width*l.scaleX/100;k=l.drawable.height*l.scaleY/100;j=j<k?j:k;j>1&&(j=1);k=1*j;k<0.6&&(k=0.6);k>1&&(k=1);j=this.closeXImg.width*k/l.scaleX/2;k=this.closeXImg.height*k/l.scaleY/2;if(n.x>=h-j&&n.x<=h+j&&n.y>=i-k&&n.y<=i+k)return e.thumbHit=1,l}if(l.localPointIn(n))return l}}return null}; AV.PaintWidget.prototype.uiLayerReset=function(){var a=this.findLayerIndexByName("_ui");a==-1?(a=document.createElement("canvas"),a.width=this.canvas.width,a.height=this.canvas.height,a=new AV.Layer({canvas:a,name:"_ui"}),a.hidden=!0,this.layers.push(a)):(this.layers[a].hidden=!0,this.layers[a].canvas.width=this.canvas.width,this.layers[a].canvas.height=this.canvas.height,this.layerToTop(a))}; AV.PaintWidget.prototype.uiLayerShow=function(a){var b=this.findLayerIndexByName("_ui");if(b!=-1)this.layers.hidden=!a,a||this.recomposite()}; AV.PaintWidget.prototype.uiLayerDrawRectSelection=function(a,b){var c=20,d=7,e=4,f=1,g,h,i,j,k;h={x:i,y:h};j=a.drawable.width;k=a.drawable.height;g=h=0;i=j;var p=this.getLayerByName("_ui"),m=p.canvas.getContext("2d");m.globalCompositeOperation="copy";m.clearRect(0,0,p.canvas.width,p.canvas.height);m.globalCompositeOperation="source-over";m.setTransform(1,0,0,1,0,0);m.translate(a.translateX,a.translateY);m.rotate(a.rotate);m.scale(a.scaleX,a.scaleY);a.centerX!=null&&a.centerY!=null&&m.translate(-a.centerX, -a.centerY);m.globalAlpha=0.5;m.strokeStyle="#ffffff";m.lineWidth=2/a.scaleX;m.lineCap="round";m.lineJoin="round";m.strokeRect(0,0,a.drawable.width,a.drawable.height);m.closePath();b||(j=j*a.scaleX/100,p=k*a.scaleY/100,j=j<p?j:p,j>1&&(j=1),c=parseInt(c*j),c<5&&(c=5),e=parseInt(e*j),e<1&&(e=1),f*=j,f<0.6&&(f=0.6),f>1&&(f=1));c/=a.scaleX;e/=a.scaleX;d/=a.scaleX;g-=d;j=i+d;p=h-d;d=k+d;m.strokeStyle="#297bb6";m.globalAlpha=1;m.lineWidth=e;m.lineCap="square";m.beginPath();b!=1&&(m.moveTo(g,p+c),m.lineTo(g, p),m.lineTo(g+c,p),m.stroke());m.save();m.setTransform(1,0,0,1,0,0);h={x:i,y:h};a.localToWorld(h);m.translate(h.x,h.y);m.rotate(a.rotate);m.translate(-this.closeXImg.width/2,-this.closeXImg.height/2);m.translate(this.closeXImg.width/4,-this.closeXImg.height/4);b||m.scale(f,f);m.drawImage(this.closeXImg,0,0);m.restore();b!=1&&(m.moveTo(j,d-c),m.lineTo(j,d),m.lineTo(j-c,d),m.stroke());m.moveTo(g+c,d);m.lineTo(g,d);m.lineTo(g,d-c);m.stroke();m.closePath();m.setTransform(1,0,0,1,0,0)}; AV.PaintWidget.prototype.uiLayerClear=function(){var a=this.getLayerByName("_ui"),b=a.canvas.getContext("2d");b.globalCompositeOperation="copy";b.clearRect(0,0,a.canvas.width,a.canvas.height);b.globalCompositeOperation="source-over"}; AV.PaintWidget.prototype.uiLayerDrawCircleSelection=function(a,b,c,d){var e=this.getLayerByName("_ui"),f=e.canvas.getContext("2d");if(!d)f.globalCompositeOperation="copy",f.clearRect(0,0,e.canvas.width,e.canvas.height);f.globalCompositeOperation="source-over";f.beginPath();f.globalAlpha=0.5;f.strokeStyle="#ffffff";f.lineWidth=3;f.arc(a,b,c,0,6.2831852,!1);f.closePath();f.stroke();f.globalAlpha=1};AV.PaintWidget.prototype.dirtyRectEnable=function(a){this.dirtyRect.dirty=a}; AV.PaintWidget.prototype.recomposite=function(a){var b;AV.clearCanvas(this.canvas);var c=this.canvas.getContext("2d");a==null?a=0:(a--,a<0&&(a=0));for(c.setTransform(1,0,0,1,0,0);a<this.layers.length;a++)if(b=this.layers[a],!b.hidden)c.save(),this.dirtyRect.dirty&&(c.beginPath(),c.rect(this.dirtyRect.bbox.x0,this.dirtyRect.bbox.y0,this.dirtyRect.bbox.w,this.dirtyRect.bbox.h),c.clip(),c.closePath()),c.translate(b.translateX,b.translateY),c.rotate(b.rotate),c.scale(b.scaleX,b.scaleY),b.centerX!=null&& b.centerY!=null&&c.translate(-b.centerX,-b.centerY),c.globalAlpha=b.alpha!=null?b.alpha:1,c.drawImage(b.drawable,0,0),c.restore();if(this.debugPoint!=null)c.setTransform(1,0,0,1,0,0),c.strokeStyle="#00ffff",c.lineWidth=1,c.lineCap="round",c.lineJoin="round",c.strokeRect(this.debugPoint.x-2,this.debugPoint.y-2,4,4)}; AV.PaintWidget.prototype.makeThumbFlat=function(a,b){this.recomposite();var c=a.width,d=a.height,e=a.getContext("2d");e.globalCompositeOperation="copy";e.clearRect(0,0,a.width,a.height);e.globalCompositeOperation="source-over";var f=c/this.canvas.width,g=d/this.canvas.height;b?f>g?(f=this.canvas.width*g,e.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,(c-f)/2,0,f,d)):(f*=this.canvas.height,e.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,(d-f)/2,c,f)):f<g?(f=this.canvas.width* g,e.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,-(f-c)/2,0,f,d)):(f*=this.canvas.height,e.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,-(f-d)/2,c,f));return a};AV.PaintWidget.prototype.exportImage=function(a){a=a||"image/png";this.uiLayerShow(!1);this.recomposite();var a=this.canvas.toDataURL(a),b=a.indexOf(";",0),c=a.indexOf(",",b);return{mimeType:a.slice(5,b),base64data:a.slice(c+1)}}; AV.PaintWidget.prototype.addLayer=function(a){this.layers.push(a);return this.layers.length-1};AV.PaintWidget.prototype.setMode=function(a){this.setMouseCursor();this.active!==null&&this.active.deactivate!==void 0&&this.active.deactivate();if(a!==null&&a!==void 0&&a!==""){if(a=this["module_"+a],a!==void 0)this.active=a,this.active.activate!==void 0&&this.active.activate(this)}else this.active=null}; AV.PaintWidget.prototype.canvasClicked=function(a){if(!(this.active==void 0||this.active.clickEvent==void 0)){var b=avpw$(this.canvas).offset();this.active.clickEvent(Math.floor(a.pageX-b.left),Math.floor(a.pageY-b.top))}};AV.PaintWidget.prototype.canvasMouseOut=function(){this.active==void 0||this.active.mouseOutEvent==void 0||this.active.mouseOutEvent()}; AV.PaintWidget.prototype.canvasMouseMove=function(a){if(!(this.active==void 0||this.active.mouseMoveEvent==void 0)){var b=avpw$(this.canvas).offset();return this.active.mouseMoveEvent(Math.floor(a.pageX-b.left),Math.floor(a.pageY-b.top))}};AV.PaintWidget.prototype.canvasMouseDown=function(a){if(!(this.active==void 0||this.active.mouseDownEvent==void 0)){var b=avpw$(this.canvas).offset();return this.active.mouseDownEvent(Math.floor(a.pageX-b.left),Math.floor(a.pageY-b.top),a.button)}}; AV.PaintWidget.prototype.canvasMouseUp=function(a){if(!(this.active==void 0||this.active.mouseUpEvent==void 0)){var b=avpw$(this.canvas).offset();this.active.mouseUpEvent(Math.floor(a.pageX-b.left),Math.floor(a.pageY-b.top),a.button)}};AV.PaintWidget.prototype.canvasMouseDrop=function(a,b){if(!(this.active==void 0||this.active.mouseDropEvent==void 0)){var c=avpw$(this.canvas).offset();this.active.mouseDropEvent(Math.floor(a.pageX-c.left),Math.floor(a.pageY-c.top),0,0,b)}}; AV.PaintWidget.prototype.undo=function(){this.active!=void 0&&this.active.userUndo!=void 0&&this.active.userUndo();this.actionUndo();this.active!=void 0&&this.active.userPostUndo!=void 0&&this.active.userPostUndo()};AV.PaintWidget.prototype.redo=function(){this.active!=void 0&&this.active.userRedo!=void 0&&this.active.userRedo();this.actionRedo();this.active!=void 0&&this.active.userPostRedo!=void 0&&this.active.userPostRedo()}; AV.PaintWidget.prototype.undoImplicitActions=function(){for(;this.actionStackIndex>=0&&this.actionStack[this.actionStackIndex][2].implicit===!0&&this.actionStack[this.actionStackIndex][2].checkpoint!==!0;){var a=this.actionStack[this.actionStackIndex][0];a[0].apply(a[1],a[2]);this.actionStackIndex--}}; AV.PaintWidget.prototype.actionUndo=function(){var a,b,c;if(!(this.actionStackIndex<0||this.actionStack[this.actionStackIndex][2].checkpoint===!0)){do{this.dirty=!0;if(a=this.actionStack[this.actionStackIndex][0])b=a[0],c=a[1],a=a[2],b.apply(c,a);this.actionStackIndex--}while(this.actionStackIndex>=0&&this.actionStack[this.actionStackIndex][2].checkpoint!==!0&&this.actionStack[this.actionStackIndex][2].implicit===!0)}}; AV.PaintWidget.prototype.actionUndoFake=function(){if(!(this.actionStackIndex<0||this.actionStack[this.actionStackIndex][2].checkpoint===!0))this.dirty=!0,this.actionStackIndex--}; AV.PaintWidget.prototype.actionRedo=function(){var a,b,c;if(!(this.actionStackIndex>=this.actionStack.length-1)){do if(this.dirty=!0,this.actionStackIndex++,a=this.actionStack[this.actionStackIndex][1])b=a[0],c=a[1],a=a[2],b.apply(c,a);while(this.actionStackIndex<this.actionStack.length-1&&this.actionStack[this.actionStackIndex][2].implicit===!0)}};AV.PaintWidget.prototype.actionRedoFake=function(){if(!(this.actionStackIndex>=this.actionStack.length-1))this.dirty=!0,this.actionStackIndex++}; AV.PaintWidget.prototype.actionPush=function(a,b,c){this.actionStack.length=this.actionStackIndex+1;this.actionStack.push([a,b,{},c])};AV.PaintWidget.prototype.actionCheckpoint=function(a){if(!(this.actionStackIndex<0))this.actionStack[this.actionStackIndex][2].checkpoint=a};AV.PaintWidget.prototype.actionImplicit=function(a){if(!(this.actionStackIndex<0))this.actionStack[this.actionStackIndex][2].implicit=a}; AV.PaintWidget.prototype.actionExportJSON=function(a){var b={metadata:{imageorigsize:[this._origWidth,this._origHeight]}},c=[],d,e,f,g,h;AV.isRelaunched&&AV.prevActionList?(e=JSON.parse(AV.prevActionList))&&(c=e.actionlist.slice()):actionList=[];c.push({action:"setfeathereditsize",width:this._origWidth,height:this._origHeight});for(e=0;e<this.actionStackIndex+1;e++)if(d=this.actionStack[e],d=d[3])if(d.length==void 0)c.push(d);else for(f=0;f<d.length;f++)c.push(d[f]);if(a){f={};a=[];a.length=c.length; for(e=0;e<c.length;e++)switch(d=c[e],g=d.action,g){case "addsticker":case "addtext":actionLayerId=d.id;f[actionLayerId]=e;a[e]=c[e];break;case "setsticker":actionLayerId=d.id;g=c[f[actionLayerId]];h={};h.action=g.action;h.url=g.url;h.id=g.id;h.center=d.center;h.scale=d.scale;h.rotation=d.rotation;a[e]=h;break;case "settext":actionLayerId=d.id;g=c[f[actionLayerId]];h={};h.action=g.action;h.id=g.id;h.text=g.text;h.font=g.font;h.size=g.size;h.color=g.color;h.shadowcolor=g.shadowcolor;h.center=d.center; h.scale=d.scale;h.rotation=d.rotation;a[e]=h;break;default:a[e]=c[e]}c={};for(e=a.length-1;e>=0;e--)switch(d=a[e],g=d.action,g){case "deletetext":case "deletesticker":actionLayerId=d.id;c[actionLayerId]=!0;a.splice(e,1);break;case "addtext":case "addsticker":actionLayerId=d.id,c[actionLayerId]?a.splice(e,1):c[actionLayerId]=!0}b.actionlist=a}else b.actionlist=c;return AV.JSON.stringify(b)}; AV.PaintWidget.prototype.getBacking=function(a,b,c,d){return this.canvas.getContext("2d").getImageData(a,b,c,d)};AV.PaintWidget.prototype.getBackingAll=function(){return this.canvas.getContext("2d").getImageData(0,0,this.canvas.width,this.canvas.height)};AV.PaintWidget.prototype.putBacking=function(a,b,c,d){a.canvas.getContext("2d").putImageData(b,c,d)}; AV.PaintWidget.prototype._rotateOverlay90=function(a,b){var c;a.rotate+=b*3.1415926/180;if(b==90)c=a.translateX,a.translateX=this.canvas.width-a.translateY,a.translateY=c;else if(b==270)c=a.translateX,a.translateX=a.translateY,a.translateY=this.canvas.height-c;else if(b==180)a.translateX=this.canvas.width-a.translateX,a.translateY=this.canvas.height-a.translateY}; AV.PaintWidget.prototype.rotate90=function(a){var b,c;a%=360;a<0&&(a+=360);a=parseInt(a/90,10)*90;if(a!=0){if(a%180!=0)b=this.canvas.width,this.canvas.width=this.canvas.height,this.canvas.height=b,this.width=this.canvas.width,this.height=this.canvas.height;for(b=0;b<this.layers.length;b++){var d=this.layers;if(d.canvas!=null)if(d.tag=="module_text")this._rotateOverlay90(d,a);else{var e=document.createElement("canvas");e.width=this.canvas.width;e.height=this.canvas.height;c=e.getContext("2d");c.setTransform(1, 0,0,1,0,0);c.translate(e.width/2,e.height/2);c.rotate(a*3.14159265358979/180);c.translate(-d.canvas.width/2,-d.canvas.height/2);c.globalCompositeOperation="copy";c.drawImage(d.canvas,0,0);c.globalCompositeOperation="source-over";c.setTransform(1,0,0,1,0,0);d.canvas=d.drawable=e}else d.image!=null&&this._rotateOverlay90(d,a)}this.recomposite()}}; AV.PaintWidget.prototype._dupLayerAttrs=function(a,b){if(b.hidden==!0)a.hidden=!0;if(b.alpha!=void 0)a.alpha=b.alpha;a.rotate=b.rotate;a.scaleX=b.scaleX;a.scaleY=b.scaleY;a.translateX=b.translateX;a.translateY=b.translateY;if(b.centerX!=null)a.centerX=b.centerX;if(b.centerY!=null)a.centerY=b.centerY;if(b.tag!=null)a.tag=b.tag;if(b.module_data!=null)a.module_data=b.module_data}; AV.PaintWidget.prototype.duplicateAllLayers=function(){var a=[],b,c;for(b=0;b<this.layers.length;b++)if(this.layers.name!="_ui")if(this.layers.canvas!=null){var d=document.createElement("canvas");d.width=this.layers.canvas.width;d.height=this.layers.canvas.height;c=d.getContext("2d");c.drawImage(this.layers.canvas,0,0,d.width,d.height);c=new AV.Layer({canvas:d,name:this.layers.name});this._dupLayerAttrs(c,this.layers);a.push(c)}else this.layers.image!=null&&(c=new AV.Layer({image:this.layers.image, name:this.layers.name}),this._dupLayerAttrs(c,this.layers),a.push(c));return a}; AV.PaintWidget.prototype.duplicateAllLayersFrom=function(a){var b,c;for(b=0;b<a.length;b++)if(a.name!="_ui"){var d=this.getLayerByName(a.name);d===null&&(d=new AV.Layer({name:a.name}),this.layers.push(d));if(a.canvas!=null){if(d.canvas==null)d.canvas=document.createElement("canvas");d.drawable=d.canvas;d.canvas.width=a.canvas.width;d.canvas.height=a.canvas.height;c=d.canvas.getContext("2d");c.drawImage(a.canvas,0,0,a.canvas.width,a.canvas.height);this._dupLayerAttrs(d,a)}else if(a.image!= null)d.image=a.image,d.drawable=d.image,this._dupLayerAttrs(d,a)}}; AV.PaintWidget.prototype.resizeAllLayers=function(a,b,c){var d,e,f=[],g=this.width,h;this.setDimensions(a,b);for(d=0;d<this.layers.length;d++)this.layers[d].canvas!=null?(h=document.createElement("canvas"),h.width=a,h.height=b,e=h.getContext("2d"),e.drawImage(this.layers[d].canvas,0,0,a,b),e=new AV.Layer({canvas:h,name:this.layers[d].name}),this._dupLayerAttrs(e,this.layers[d]),f.push(e)):this.layers[d].image!=null&&(c?(h=a/g,e=new AV.Layer({image:this.layers[d].image,name:this.layers[d].name}),this._dupLayerAttrs(e, this.layers[d]),e.translateX*=h,e.translateY*=h,e.scaleX*=h,e.scaleY*=h):(e=new AV.Layer({image:this.layers[d].image,name:this.layers[d].name}),this._dupLayerAttrs(e,this.layers[d])),f.push(e));this.layers=f;this.recomposite()};AV.PaintWidget.prototype.resizeAllLayersQnD=function(a,b){var c;this.setDimensions(a,b);for(c=0;c<this.layers.length;c++)if(this.layers[c].canvas!=null)this.layers[c].canvas.width=a,this.layers[c].canvas.height=b}; AV.PaintWidget.prototype.flattenAllLayers=function(){var a=this.getLayerByName("_ui");this.uiLayerShow(!1);this.recomposite();this.layers.length=0;var b=document.createElement("canvas");b.width=this.canvas.width;b.height=this.canvas.height;this.layers.push(new AV.Layer({canvas:b,name:"background"}));a&&this.layers.push(a);b.getContext("2d").drawImage(this.canvas,0,0)}; AV.PaintWidget.prototype.cropAllLayers=function(a,b,c,d){var e,f,g,h=[];this.setDimensions(c,d);for(e=0;e<this.layers.length;e++){g=this.layers[e];if(g.canvas!=null)f=g.tag=="module_text"?"textcanvas":"canvas";else if(g.image!=null)f="image";else continue;switch(f){case "canvas":var i=document.createElement("canvas");i.width=c;i.height=d;f=i.getContext("2d");f.drawImage(this.layers[e].canvas,-a,-b,this.layers[e].canvas.width,this.layers[e].canvas.height);g=new AV.Layer({canvas:i,name:this.layers[e].name}); this._dupLayerAttrs(g,this.layers[e]);h.push(g);break;case "image":g=new AV.Layer({image:this.layers[e].image,name:this.layers[e].name});this._dupLayerAttrs(g,this.layers[e]);g.translateX-=a;g.translateY-=b;h.push(g);break;case "textcanvas":i=document.createElement("canvas"),f=i.getContext("2d"),i.width=g.canvas.width,i.height=g.canvas.height,f.drawImage(this.layers[e].canvas,0,0),g=new AV.Layer({canvas:i,name:this.layers[e].name}),this._dupLayerAttrs(g,this.layers[e]),g.translateX-=a,g.translateY-= b,h.push(g)}}this.layers=h;this.recomposite()}; AV.PaintWidget.prototype.module_bulge={activate:function(a){this.paintWidget=a;this.paintWidget.setMouseCursor("crosshair");this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0)},deactivate:function(){this.paintWidget.uiLayerShow(!1)},userUndo:function(){this.paintWidget.uiLayerShow(!1)},userRedo:function(){this.paintWidget.uiLayerShow(!1)},radius:100,power:0,_bulgeUndo:function(a,b,c,d){a=this.paintWidget.getLayerByName(a).canvas.getContext("2d");a.globalCompositeOperation="copy";a.drawImage(b, c,d);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()},_doDistort:function(a,b,c,d,e,f){var g=e*e,h;h=f>=0?-f/120:-f/200;f=1-h;h/=e;for(var i=0,j=0;j<d;j++)for(var k=j-e,p=k*k,m=0;m<c;m++){var l=m-e,n=l*l+p;if(n<g){var n=0.999999/(f+h*Math.sqrt(n)),l=l*n+e,n=k*n+e,q=Math.floor(l),o=Math.floor(n);l-=q;n-=o;var r=1-l,s=1-n,t=(q+o*c)*4,q=b[t]*r+b[t+4]*l,o=b[t+1]*r+b[t+5]*l,v=b[t+2]*r+b[t+6]*l,u=b[t+3]*r+b[t+7]*l;t+=c*4;var y=b[t]*r+b[t+4]*l,x=b[t+1]*r+b[t+5]*l,w=b[t+2]*r+b[t+6]* l,l=b[t+3]*r+b[t+7]*l;a[i++]=q*s+y*n;a[i++]=o*s+x*n;a[i++]=v*s+w*n;a[i++]=u*s+l*n}else a[i]=b[i],i++,a[i]=b[i],i++,a[i]=b[i],i++,a[i]=b[i],i++}},_getDistortedPixels:function(a,b,c,d,e){var f=d*2+1,g=d*2+1,b=AV.getImageDataRegion(a,b-d,c-d,f,g,!0),a=a.getContext("2d").createImageData(f,g);this._doDistort(a.data,b.data,f,g,d,e);return a},_bulgeRedo:function(a,b,c,d,e){a=this.paintWidget.getLayerByName(a).canvas;e=this._getDistortedPixels(a,b,c,d,e);AV.putImageDataRegion(a,e,b-d,c-d);this.paintWidget.recomposite()}, mouseDownEvent:function(){return!1},mouseMoveEvent:function(a,b){var c=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas;if(c!=null&&!(a<0||a>=c.width||b<0||b>=c.height)){var d=this.radius,c=this._getDistortedPixels(c,a,b,d,this.power);this.paintWidget.uiLayerShow(!0);this.paintWidget.uiLayerClear();AV.putImageDataRegion(this.paintWidget.getLayerByName("_ui").canvas,c,a-d,b-d);this.paintWidget.uiLayerDrawCircleSelection(a,b,d,!0);this.paintWidget.recomposite();return!1}},mouseOutEvent:function(){this.paintWidget.uiLayerShow(!1)}, clickEvent:function(a,b){var c=this.paintWidget.layers[this.paintWidget.currentLayerIndex],d=c.canvas;if(d!=null&&!(a<0||a>=d.width||b<0||b>=d.height)){var e=a-this.radius,f=b-this.radius,g=this.radius*2+1,d=AV.copyCanvas(d,e,f,g,g);this.paintWidget.actionPush([this._bulgeUndo,this,[c.name,d,e,f]],[this._bulgeRedo,this,[c.name,a,b,this.radius,this.power]],{action:"bulge",center:[a,b],radius:this.radius,power:this.power});this.paintWidget.actionRedo();this.mouseMoveEvent(a,b);return!1}}}; AV.PaintWidget.prototype.module_whiten={activate:function(a){this.paintWidget=a;this.paintWidget.setMouseCursor("crosshair");this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0)},deactivate:function(){this.paintWidget.uiLayerShow(!1)},userUndo:function(){this.paintWidget.uiLayerShow(!1)},userRedo:function(){this.paintWidget.uiLayerShow(!1)},radius:10,_whitenUndo:function(a,b,c,d){a=this.paintWidget.getLayerByName(a).canvas.getContext("2d");a.globalCompositeOperation="copy";a.drawImage(b, c,d);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()},_whitenRedo:function(a,b,c,d){var a=this.paintWidget.getLayerByName(a),e=d*d,f=d*2,g,h,i,j,k,p,m,l,n,q,f=AV.getImageDataRegion(a.canvas,b-d,c-d,f,f);i=f.data.length;var o=[];AV.convertRgbToHsv(o,f.data,i);for(h=0;h<i;h+=4)p=o[h],g=o[h+1],j=o[h+2],k=0,p>=25&&p<80&&(k=Math.min((p-25)/5,(80-p)/10),k>1&&(k=1)),p=0,j>128&&(p=Math.min((j-128)/20,1)),j=k*p,j>0&&(o[h+1]=g*(1-0.4*j));AV.convertHsvToRgb(o,o,i);i=0;for(h=-d;h<d;h++)for(g= -d;g<d;g++,i+=4)j=g*g+h*h,j>e||(j=Math.sqrt(j),q=j/d,q=q*2-1,q<0&&(q=0),j=f.data[i],k=f.data[i+1],p=f.data[i+2],m=o[i],l=o[i+1],n=o[i+2],f.data[i]=m*(1-q)+j*q,f.data[i+1]=l*(1-q)+k*q,f.data[i+2]=n*(1-q)+p*q);AV.putImageDataRegion(a.canvas,f,b-d,c-d);this.paintWidget.recomposite()},_drawUICircle:function(a,b){this.paintWidget.uiLayerDrawCircleSelection(a,b,this.radius)},mouseDownEvent:function(){return!1},mouseMoveEvent:function(a,b){this.paintWidget.uiLayerShow(!0);this._drawUICircle(a,b);this.paintWidget.recomposite(); return!1},mouseOutEvent:function(){this.paintWidget.uiLayerShow(!1)},clickEvent:function(a,b){var c=this.paintWidget.layers[this.paintWidget.currentLayerIndex];if(c.canvas!=null){var d=a-this.radius,e=b-this.radius,f=this.radius*2,f=AV.copyCanvas(c.canvas,d,e,f,f);this.paintWidget.actionPush([this._whitenUndo,this,[c.name,f,d,e]],[this._whitenRedo,this,[c.name,a,b,this.radius]],{action:"whiten",center:[Math.floor(a),Math.floor(b)],radius:Math.floor(this.radius)});this.paintWidget.actionRedo();return!1}}}; AV.convertRgbToHsv=function(a,b,c){var d,e,f,g,h,i;for(d=0;d<c;d+=4){e=b[d];f=b[d+1];g=b[d+2];var j=Math.max(e,Math.max(f,g));h=Math.min(e,Math.min(f,g));i=j;if(j==0)h=e=0;else{var k=j-h;h=k/j;e=e==j?(f-g)/k:f==j?2+(g-e)/k:4+(e-f)/k;e<0&&(e+=6);e*=60}a[d]=e;a[d+1]=h;a[d+2]=i;a[d+3]=b[d+3]}}; AV.convertHsvToRgb=function(a,b,c){var d,e,f,g,h,i;for(d=0;d<c;d+=4){h=b[d];i=b[d+1];e=f=g=e=b[d+2];if(i!=0){h/=60;var j=Math.floor(h),k=h-j;h=1-i;var p=1-i*k;i=1-i*(1-k);switch(j){case 0:g*=h;f*=i;break;case 1:g*=h;e*=p;break;case 2:e*=h;g*=i;break;case 3:e*=h;f*=p;break;case 4:f*=h;e*=i;break;default:f*=h,g*=p}}e<0&&(e=0);e>255&&(e=255);f<0&&(f=0);f>255&&(f=255);g<0&&(g=0);g>255&&(g=255);a[d]=e;a[d+1]=f;a[d+2]=g;a[d+3]=b[d+3]}}; AV.PaintWidget.prototype.module_redeye={activate:function(a){this.paintWidget=a;this.paintWidget.setMouseCursor("crosshair");this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0)},deactivate:function(){this.paintWidget.uiLayerShow(!1)},userUndo:function(){this.paintWidget.uiLayerShow(!1)},userRedo:function(){this.paintWidget.uiLayerShow(!1)},radius:10,mode:"redeye",setRadius:function(a){this.radius=a},_redeyeUndo:function(a,b,c,d){this.paintWidget.getLayerByName(a).canvas.getContext("2d").drawImage(b, c,d);this.paintWidget.recomposite()},_redeyeRedo:function(a,b,c,d){var a=this.paintWidget.getLayerByName(a),e=d*d,f=d*2,g,h,i,j,k,p,m=AV.getImageDataRegion(a.canvas,b-d,c-d,f,f);h=0;for(g=-d;g<d;g++)for(f=-d;f<d;f++,h+=4)i=f*f+g*g,i>e||(i=Math.sqrt(i),p=i/d,p=p*2-1,p<0&&(p=0),i=m.data[h],j=m.data[h+1],k=m.data[h+2],j=(j+k)/2,j>0?(k=i/j,j=k>2?j:i):j=0,m.data[h]=j*(1-p)+i*p);AV.putImageDataRegion(a.canvas,m,b-d,c-d);this.paintWidget.recomposite()},_greeneyeRedo:function(a,b,c,d){var a=this.paintWidget.getLayerByName(a), e=d*d,f=d*2,g,h,i,j,k,p,m,l,n,q=AV.getImageDataRegion(a.canvas,b-d,c-d,f,f);h=0;for(g=-d;g<d;g++)for(f=-d;f<d;f++,h+=4)i=f*f+g*g,i>e||(i=Math.sqrt(i),n=i/d,n=n*2-1,n<0&&(n=0),i=q.data[h],j=q.data[h+1],k=q.data[h+2],i>128||j>128||k>128?(p=i*0.8,m=j*0.8,l=k*0.8):(p=i,m=j,l=k),q.data[h]=p*(1-n)+i*n,q.data[h+1]=m*(1-n)+j*n,q.data[h+2]=l*(1-n)+k*n);AV.putImageDataRegion(a.canvas,q,b-d,c-d);this.paintWidget.recomposite()},_drawUICircle:function(a,b){this.paintWidget.uiLayerDrawCircleSelection(a,b,this.radius)}, mouseDownEvent:function(){return!1},mouseMoveEvent:function(a,b){this.paintWidget.uiLayerShow(!0);this._drawUICircle(a,b);this.paintWidget.recomposite();return!1},mouseOutEvent:function(){this.paintWidget.uiLayerShow(!1)},clickEvent:function(a,b){var c=this.paintWidget.layers[this.paintWidget.currentLayerIndex];if(c.canvas!=null){var a=parseInt(a),b=parseInt(b),d=a-this.radius,e=b-this.radius,f=this.radius*2,f=AV.copyCanvas(c.canvas,d,e,f,f);this.mode=="greeneye"?this.paintWidget.actionPush([this._redeyeUndo, this,[c.name,f,d,e]],[this._greeneyeRedo,this,[c.name,a,b,this.radius]],{action:"greeneye",center:[a,b],radius:this.radius}):this.paintWidget.actionPush([this._redeyeUndo,this,[c.name,f,d,e]],[this._redeyeRedo,this,[c.name,a,b,this.radius]],{action:"redeye",center:[a,b],radius:this.radius});this.paintWidget.actionRedo();return!1}}}; AV.PaintWidget.prototype.module_blemish={activate:function(a){this.paintWidget=a;this.paintWidget.setMouseCursor("crosshair");this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0)},deactivate:function(){this.paintWidget.uiLayerShow(!1)},userUndo:function(){this.paintWidget.uiLayerShow(!1)},userRedo:function(){this.paintWidget.uiLayerShow(!1)},setRadius:function(a){this.radius=a},radius:5,_blemishUndo:function(a,b,c,d){this.paintWidget.getLayerByName(a).canvas.getContext("2d").drawImage(b, c,d);this.paintWidget.recomposite()},_blemishRedo:function(a,b,c,d){var a=this.paintWidget.getLayerByName(a),e=d*d,f=2*d,g,h,i,j,k,p,m,l,n,q,o,r,s,t;a.canvas.getContext("2d");m=g=f+8;var v=AV.getImageDataRegion(a.drawable,b-d-4,c-d-4,m,g);i=parseInt(f/2,10);j=parseInt(f/2,10);var u=AV.getImageDataRegion(a.drawable,b-d,c-d,f,f);for(o=h=0;h<f;h++)for(g=0;g<f;g++,o+=4)if(q=(g-i)*(g-i)+(h-j)*(h-j),!(q>e)){q=Math.sqrt(q);q/=d;q=q*2-1;q<0&&(q=0);q=1-q;r=gtotal=s=t=0;for(n=-4;n<4;n++){p=h+4+n;for(l=-4;l< 4;l++)k=g+4+l,k=(k+p*m)*4,v.data[k+3]>0&&(r+=v.data[k],gtotal+=v.data[k+1],s+=v.data[k+2],t++)}r/=t;gtotal/=t;s/=t;k=g+4;p=h+4;k=(k+p*m)*4;p=parseInt(v.data[k]*(1-q)+r*q,10);l=parseInt(v.data[k+1]*(1-q)+gtotal*q,10);q=parseInt(v.data[k+2]*(1-q)+s*q,10);u.data[o]=p;u.data[o+1]=l;u.data[o+2]=q;u.data[o+3]=v.data[k+3]}AV.putImageDataRegion(a.canvas,u,b-d,c-d);this.paintWidget.recomposite()},_drawUICircle:function(a,b){this.paintWidget.uiLayerDrawCircleSelection(a,b,this.radius)},mouseDownEvent:function(){return!1}, mouseMoveEvent:function(a,b){this.paintWidget.uiLayerShow(!0);this._drawUICircle(a,b);this.paintWidget.recomposite();return!1},mouseOutEvent:function(){this.paintWidget.uiLayerShow(!1)},clickEvent:function(a,b){var c=this.paintWidget.layers[this.paintWidget.currentLayerIndex];if(c.canvas!=null){var a=parseInt(a),b=parseInt(b),d=a-this.radius,e=b-this.radius,f=this.radius*2,f=AV.copyCanvas(c.canvas,d,e,f,f);this.paintWidget.actionPush([this._blemishUndo,this,[c.name,f,d,e]],[this._blemishRedo,this, [c.name,a,b,this.radius]],{action:"blemish",center:[Math.floor(a),Math.floor(b)],radius:Math.floor(this.radius)});this.paintWidget.actionRedo()}}}; AV.PaintWidget.prototype.module_flip={activate:function(a){this.paintWidget=a},makeThumb:function(a,b,c){this.paintWidget.makeThumbFlat(a,!0);b&&this._flipRun(a,!0,!1);c&&this._flipRun(a,!1,!0)},_flipUndo:function(a){this.paintWidget.duplicateAllLayersFrom(a);this.paintWidget.recomposite()},_flipRun:function(a,b,c){var d=a.getContext("2d");if(b)b=AV.copyCanvas(a),d.setTransform(-1,0,0,1,a.width,0),d.globalCompositeOperation="copy",d.drawImage(b,0,0),d.globalCompositeOperation="source-over";if(c)b= AV.copyCanvas(a),d.setTransform(1,0,0,-1,0,a.height),d.globalCompositeOperation="copy",d.drawImage(b,0,0),d.globalCompositeOperation="source-over";d.setTransform(1,0,0,1,0,0)},_flipRedo:function(a,b,c,d){d&&this.paintWidget.flattenAllLayers();this._flipRun(this.paintWidget.getLayerByName(a).canvas,b,c);this.paintWidget.recomposite()},_flipHV:function(a,b,c){var d=this.paintWidget.layers[this.paintWidget.currentLayerIndex],e;d.canvas!=null&&(c?(e=this.paintWidget.duplicateAllLayers(),this.paintWidget.actionPush([this._flipUndo, this,[e]],[this._flipRedo,this,[d.name,a,b,c]],{action:"flip",horizontal:a,vertical:b,flatten:c})):this.paintWidget.actionPush([this._flipRedo,this,[d.name,a,b,c]],[this._flipRedo,this,[d.name,a,b,c]],{action:"flip",horizontal:a,vertical:b,flatten:c}),this.paintWidget.actionRedo())},flip:function(a,b,c){this._flipHV(a,b,c)},hflip:function(a){this._flipHV(!0,!1,a)},vflip:function(a){this._flipHV(!1,!0,a)},hvflip:function(a){this._flipHV(!0,!0,a)}}; AV.PaintWidget.prototype.module_desaturate={activate:function(a){this.paintWidget=a},makeThumb:function(a){this.paintWidget.makeThumbFlat(a);var b=a.getContext("2d"),a=b.getImageData(0,0,a.width,a.height);this._desaturationRun(a.data);b.putImageData(a,0,0)},_desaturationRun:function(a){for(var b=0;b<a.length;b+=4)a=a=a=~~((a+a+a)/3)},_desaturateUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"), a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},_desaturateRedo:function(a,b){b&&this.paintWidget.flattenAllLayers();var c=this.paintWidget.getLayerByName(a),d=c.canvas.getContext("2d"),e=d.getImageData(0,0,c.canvas.width,c.canvas.height);this.paintWidget.showWaitThrobber(!0,function(){this._desaturationRun(e.data);d.putImageData(e,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}, desaturate:function(a){var b=this.paintWidget.layers[this.paintWidget.currentLayerIndex];if(b.canvas!=null){var c=null,d=null;a?d=this.paintWidget.duplicateAllLayers():c=AV.copyCanvas(b.canvas);this.paintWidget.actionPush([this._desaturateUndo,this,],[this._desaturateRedo,this,],{action:"desaturate",flatten:a});this.paintWidget.actionRedo()}}}; AV.PaintWidget.prototype.module_saturation={satchange:0,activate:function(a){this.paintWidget=a;this.oldLayers=this.newCanvasData=this.origBacking=null;this.satchange=0;this.flatten=!1},deactivate:function(){this.reset()},_saturationUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},_saturationRedo:function(a, b,c){this._saturation(a,b,c);this.oldLayers=this.origBacking=null},set:function(a,b){this.paintWidget.dirty=!0;this._saturation(this.paintWidget.layers[this.paintWidget.currentLayerIndex].name,a,b)},makeThumb:function(a,b){this.paintWidget.makeThumbFlat(a);var c=a.getContext("2d"),d=c.getImageData(0,0,a.width,a.height);this._saturationRun(d.data,d.data,b);c.putImageData(d,0,0)},_saturationRun:function(a,b,c){var d;for(d=0;d<b.length;){var e=b[d],f=b[d+1],g=b[d+2],h=b[d+3],i=Math.sqrt(e*e*0.241+f* f*0.691+g*g*0.068),e=i+(e-i)*c,f=i+(f-i)*c,g=i+(g-i)*c;e>255&&(e=255);f>255&&(f=255);g>255&&(g=255);a[d++]=e;a[d++]=f;a[d++]=g;a[d++]=h}},_saturation:function(a,b,c){var d=this.paintWidget.getLayerByName(a);if(d.canvas!=null){var e;e=d.canvas.getContext("2d");if(this.origBacking==null){if(c)this.oldLayers=this.paintWidget.duplicateAllLayers(),this.paintWidget.flattenAllLayers(),d=this.paintWidget.getLayerByName(a),e=d.canvas.getContext("2d");this.origBackingPixels=AV.getCanvasPixelData(d.canvas); this.origBacking=AV.copyCanvas(d.canvas);this.newCanvasData=e.createImageData(d.canvas.width,d.canvas.height)}this.satchange=b;this.flatten=c;this.paintWidget.showWaitThrobber(!0,function(){this._saturationRun(this.newCanvasData.data,this.origBackingPixels.data,b);e.putImageData(this.newCanvasData,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}},reset:function(){if(this.oldLayers)this.paintWidget.duplicateAllLayersFrom(this.oldLayers),this.paintWidget.recomposite(); else if(this.origBacking){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas.getContext("2d");a.globalCompositeOperation="copy";a.drawImage(this.origBacking,0,0);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()}this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null},commit:function(){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex];this.paintWidget.actionPush([this._saturationUndo,this,[a.name,this.origBacking,this.oldLayers]], [this._saturationRedo,this,[a.name,this.satchange,this.flatten]],{action:"saturation",value:this.satchange,flatten:this.flatten});this.paintWidget.actionRedoFake();this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null}}; AV.PaintWidget.prototype.module_brightness={activate:function(a){this.paintWidget=a;this.oldLayers=this.newCanvasData=this.origBacking=null;this.con=this.bri=1;this.flatten=!1},deactivate:function(){this.reset()},_brightnessUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},_brightnessRedo:function(a, b,c,d){this._brightness(a,b,c,d);this.oldLayers=this.origBacking=null},set:function(a,b,c){this._brightness(this.paintWidget.layers[this.paintWidget.currentLayerIndex].name,a,b,c);this.paintWidget.dirty=!0},makeThumb:function(a,b,c){this.paintWidget.makeThumbFlat(a);var d=a.getContext("2d"),a=d.getImageData(0,0,a.width,a.height);this._brightnessRun(a.data,a.data,b,c);d.putImageData(a,0,0)},_brightnessRun:function(a,b,c,d){c*=d;for(var e=-d*128+128,d=0;d<b.length;)a[d]=~~(b[d]*c+e),d++,a[d]=~~(b[d]* c+e),d++,a[d]=~~(b[d]*c+e),d++,a[d]=b[d],d++},_brightness:function(a,b,c,d){var e=this.paintWidget.getLayerByName(a);if(e.canvas!=null){var f;f=e.canvas.getContext("2d");if(this.origBacking==null){if(d)this.oldLayers=this.paintWidget.duplicateAllLayers(),this.paintWidget.flattenAllLayers(),e=this.paintWidget.getLayerByName(a),f=e.canvas.getContext("2d");this.origBackingPixels=AV.getCanvasPixelData(e.canvas);this.origBacking=AV.copyCanvas(e.canvas);this.newCanvasData=f.createImageData(e.canvas.width, e.canvas.height)}this.bri=b;this.con=c;this.flatten=d;this.paintWidget.showWaitThrobber(!0,function(){this._brightnessRun(this.newCanvasData.data,this.origBackingPixels.data,b,c);f.putImageData(this.newCanvasData,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}},reset:function(){if(this.oldLayers)this.paintWidget.duplicateAllLayersFrom(this.oldLayers),this.paintWidget.recomposite();else if(this.origBacking){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas.getContext("2d"); a.globalCompositeOperation="copy";a.drawImage(this.origBacking,0,0);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()}this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null},commit:function(){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex];this.paintWidget.actionPush([this._brightnessUndo,this,[a.name,this.origBacking,this.oldLayers]],[this._brightnessRedo,this,[a.name,this.bri,this.con,this.flatten]],{action:"brightnesscontrast",brightnessvalue:this.bri, contrastvalue:this.con,flatten:this.flatten});this.paintWidget.actionRedoFake();this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null}};AV.PaintWidget.prototype.module_contrast=AV.PaintWidget.prototype.module_brightness; AV.PaintWidget.prototype.module_colors={r:0,g:0,b:0,activate:function(a){this.paintWidget=a;this.oldLayers=this.newCanvasData=this.origBacking=null;this.r=this.g=this.b=0;this.flatten=!1},deactivate:function(){this.reset()},_calcmult:function(a){a+=100;return(a*0.75+50)/100},_colorsUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over"); this.paintWidget.recomposite()},_colorsRedo:function(a,b,c,d,e){this._set(a,b,c,d,e);this.oldLayers=this.origBacking=null},set:function(a,b,c,d){this.paintWidget.dirty=!0;this._set(this.paintWidget.layers[this.paintWidget.currentLayerIndex].name,a,b,c,d)},_set:function(a,b,c,d,e){var f=this.paintWidget.getLayerByName(a);if(f.canvas!=null){var g,h,i,j,k;h=f.canvas.getContext("2d");if(this.origBacking==null){if(e)this.oldLayers=this.paintWidget.duplicateAllLayers(),this.paintWidget.flattenAllLayers(), f=this.paintWidget.getLayerByName(a),h=f.canvas.getContext("2d");this.origBackingPixels=AV.getCanvasPixelData(f.canvas);this.origBacking=AV.copyCanvas(f.canvas);this.newCanvasData=h.createImageData(f.canvas.width,f.canvas.height)}this.r=b;this.b=d;this.g=c;this.flatten=e;i=this._calcmult(b);j=this._calcmult(c);k=this._calcmult(d);this.paintWidget.showWaitThrobber(!0,function(){for(g=0;g<this.origBackingPixels.data.length;)this.newCanvasData.data[g]=~~(this.origBackingPixels.data[g]*i),g++,this.newCanvasData.data[g]= ~~(this.origBackingPixels.data[g]*j),g++,this.newCanvasData.data[g]=~~(this.origBackingPixels.data[g]*k),g++,this.newCanvasData.data[g]=this.origBackingPixels.data[g],g++;h.putImageData(this.newCanvasData,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}},reset:function(){if(this.oldLayers)this.paintWidget.duplicateAllLayersFrom(this.oldLayers),this.paintWidget.recomposite();else if(this.origBacking){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas.getContext("2d"); a.globalCompositeOperation="copy";a.drawImage(this.origBacking,0,0);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()}this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null},commit:function(){if(this.origBacking!=null){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex];this.paintWidget.actionPush([this._colorsUndo,this,[a.name,this.origBacking,this.oldLayers]],[this._colorsRedo,this,[a.name,this.r,this.g,this.b,this.flatten]],{action:"colors", red:this.r,green:this.g,blue:this.b,flatten:this.flatten});this.paintWidget.actionRedoFake();this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null}}}; AV.PaintWidget.prototype.module_serverfilter=function(){var a={toycamera:{params:{stampmode:"resize"}},polaroid:{params:{stampmode:"resize"}},autocorrection:{params:{stampmode:"normal"}},oldphoto:{params:{stampmode:"normal"}},colorgrading:{params:{stampmode:"normal"}},vignetteblur:{params:{stampmode:"normal"}},colormatrix:{params:{stampmode:"normal"}},filmgrain:{params:{stampmode:"normal"}},retro:{params:{stampmode:"normal"}}},b=null,c=!1,d=null,e=null,f=null,g=null,h=function(a,c){AV.simpleXHRPost(AV_filterServer, {b64data:a,actionlist:AV.JSON.stringify(c)},function(d){d=avpw$(d).find("data");if(d.length>0)b.module_serverfilter.onComplete(d.text());else i(a,c)})||i(a,c)},i=function(a,b){d=d||avpw$("#avpw_filter_form");var c="avpw_img_filter_target_"+Math.floor(Math.random()*4294967295).toString(16);avpw$("#avpw_img_filter_target_holder").html(AV.buildHiddenFrame("avpw_img_filter_target",c));d.attr("target",c);avpw$("#avpw_img_filter_target").load(function(){window.avpw_img_filter_target_announcer.postMessage("avpw_load:"+ c,"*")});avpw$("#avpw_filter_form_data").val(a);avpw$("#avpw_filter_form_actionlist").val(AV.JSON.stringify(b));d.submit()},j=function(a,c,d,e,f){b.setDimensions(e,f);d?b.duplicateAllLayersFrom(d):(a=b.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(c,0,0),a.globalCompositeOperation="source-over");b.recomposite()},k=function(a,c,d,k,q){b.busy=!0;k&&b.flattenAllLayers();var a=b.getLayerByName(a),d=a.canvas.toDataURL("image/png"),o=d.substr(d.indexOf(",")+1), r={metadata:{imageorigsize:},actionlist:[{action:c,flatten:k}]};e=a;f=c;g=q;b.showWaitThrobber(!0,function(){avpw$.support.cors&&(!AV.firefox||AV.firefox>=4)?h(o,r):i(o,r)})};return{activate:function(a){c=!1;b=a},deactivate:function(){if(b.busy)c=!0,b.actionUndoFake(),typeof g=="function"&&g(),g=null,b.busy=!1},applyFilter:function(a,c,d,e){var f=b.layers;if(f.canvas!=null){var g=null,h=null,i=b.canvas.width,t=b.canvas.height;d?h=b.duplicateAllLayers(): g=AV.copyCanvas(f.canvas);b.actionPush([j,this,[f.name,g,h,i,t]],[k,this,[f.name,a,c.server,d,e]],{action:a,params:c.server,flatten:d});b.actionRedo()}},onComplete:function(d){if(c)c=!1;else{var h=e,i,k=document.createElement("img"),q,o,r,j=a[f].params;r=j?j.stampmode:"normal";avpw$(k).load(function(){avpw$(k).unbind("load");q=avpw$(k).attr("width");o=avpw$(k).attr("height");i=h.drawable.getContext("2d");switch(r){case "resize":b.resizeAllLayersQnD(q,o);i.drawImage(k,0,0);break;default:i.drawImage(k, 0,0)}b.recomposite();b.showWaitThrobber(!1);b.busy=!1;avpw$("#avpw_img_filter_target").unbind("load");avpw$("#avpw_img_filter_target_holder").empty();typeof g=="function"&&g()}).attr("src","data:image/png;base64,"+d)}}}}(); AV.PaintWidget.prototype.module_flashfilter=function(){var a={toycamera:{url:AV_feather_baseURL+"ostrich/filters/ToyCamera_v02.swf",params:{stampmode:"resize"}},polaroid:{url:AV_feather_baseURL+"ostrich/filters/Polaroid_v02.swf",params:{stampmode:"resize"}},autocorrection:{url:AV_feather_baseURL+"ostrich/filters/AutoCorrection_v01.swf",params:{stampmode:"normal"}},oldphoto:{url:AV_feather_baseURL+"ostrich/filters/OldPhoto_v02.swf",params:{stampmode:"normal"}},colorgrading:{url:AV_feather_baseURL+ "ostrich/filters/ColorGrading_v02.swf",params:{stampmode:"normal"}},vignetteblur:{url:AV_feather_baseURL+"ostrich/filters/VignetteBlur_v02.swf",params:{stampmode:"normal"}},colormatrix:{url:AV_feather_baseURL+"ostrich/filters/ColorMatrix_v02.swf",params:{stampmode:"normal"}},filmgrain:{url:AV_feather_baseURL+"ostrich/filters/FilmGrain_v02.swf",params:{stampmode:"normal"}},retro:{url:AV_feather_baseURL+"ostrich/filters/Retro_v01.swf",params:{stampmode:"normal"}}},b=!1,c=null,d=null,e=null,f=null,g= null,h=function(a,b,c,d,e,h,i,j){j||(j="");if(f==null){f=document.getElementById("avpw_OstrichFeather");g=[];for(var s=0;s<256;s++)g[s]=String.fromCharCode(s);g[0]=String.fromCharCode(1)+String.fromCharCode(1);g[1]=String.fromCharCode(1)+String.fromCharCode(2)}try{var t=b.toDataURL("image/png");f.setPNG(a,t.substr(t.indexOf(",")+1))}catch(v){var s=b.getContext("2d"),u;try{try{u=s.getImageData(c,d,e,h)}catch(y){netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"),u=s.getImageData(c, d,e,h)}}catch(x){throw Error("unable to access image data: "+x);}u=u.data;s="";for(t=0;t<u.length;t+=4)s+=g[u[t+3]],s+=g[u[t]],s+=g[u[t+1]],s+=g[u[t+2]];f.setBitmap(a,e,h,s)}f.runFilter(a,b.id,c,d,i,j)},i=function(a,b,c,d,e){this.paintWidget.setDimensions(d,e);c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},j=function(b, f,g,i,j){this.paintWidget.busy=!0;i&&this.paintWidget.flattenAllLayers();var q=this.paintWidget.getLayerByName(b);c=q;d=f;e=j;this.paintWidget.showWaitThrobber(!0,function(){this.callback=this.paintWidget.module_flashfilter.flashFilterResult;h("ostrich_"+q.name,q.drawable,0,0,q.drawable.width,q.drawable.height,a[f].url,g)}.AV_bindInst(this))};return{activate:function(a){b=!1;this.paintWidget=a},deactivate:function(){if(this.paintWidget.busy)b=!0,this.paintWidget.actionUndoFake(),typeof e=="function"&& e(),e=null,this.paintWidget.busy=!1},makeThumb:function(b,c,d){this.paintWidget.makeThumbFlat(b);this.callback=this.paintWidget.module_flashfilter._makeThumbCallback;h("ostrich_"+b.id,b,0,0,b.width,b.height,a[c].url,d)},applyFilter:function(a,b,c,d){var e=this.paintWidget.layers[this.paintWidget.currentLayerIndex];if(e.canvas!=null){var f=null,g=null,h=this.paintWidget.canvas.width,s=this.paintWidget.canvas.height;c?g=this.paintWidget.duplicateAllLayers():f=AV.copyCanvas(e.canvas);this.paintWidget.actionPush([i, this,[e.name,f,g,h,s]],[j,this,[e.name,a,b.flash,c,d]],{action:a,params:b.server,flatten:c});this.paintWidget.actionRedo()}},flashFilterResult:function(f,g,h,i){b?b=!1:(this.flashFilterResultProcessData(c.canvas,g,h,i,a[d].params),this.paintWidget.recomposite(),this.paintWidget.showWaitThrobber(!1),this.paintWidget.busy=!1,typeof e=="function"&&e())},flashFilterResultProcessData:function(a,b,c,d,e){var f,g=0,h=0,i=[0,0,1],j=a.getContext("2d"),v,u;u=e?e.stampmode:"normal";v=j.createImageData(c,d); for(j=v.data;h<b.length;)j[g++]=(f=b.charCodeAt(h++))!=1?f:i;switch(u){case "resize":this.paintWidget.resizeAllLayersQnD(c,d);j=a.getContext("2d");j.putImageData(v,0,0);break;case "maxspect":b=document.createElement("canvas");b.width=c;b.height=d;j=b.getContext("2d");j.putImageData(v,0,0);j=a.getContext("2d");j.fillStyle=e.fill?e.fill:"#000";j.fillRect(0,0,a.width,a.height);c>d?(swidth=a.width,sheight=d*(a.width/c)):(swidth=c*(a.height/d),sheight=a.height);j.drawImage(b,(a.width- swidth)/2,(a.height-sheight)/2,swidth,sheight);break;case "max":b=document.createElement("canvas");b.width=c;b.height=d;j=b.getContext("2d");j.putImageData(v,0,0);j=a.getContext("2d");j.drawImage(b,0,0,a.width,a.height);break;default:j=a.getContext("2d"),j.putImageData(v,0,0)}return a}}}(); function AV_paintWidget_module_flashfilter_onFilterComplete(a,b,c,d,e,f,g){a.substr(a.lastIndexOf("_"))=="_thumb"?AV_paintWidget.module_flashfilter._makeThumbCallback(a,g,d,e):AV_paintWidget.module_flashfilter.flashFilterResult(a,g,d,e)} AV.PaintWidget.prototype.module_drawing={activate:function(a){this.paintWidget=a;this.mouseDown=!1;this.bbox=new AV.Bbox;this.paintWidget.setMouseCursor("pointer");this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0);this.oldX=this.oldY=0},softness:0,setSoftness:function(a){this.softness=a},setWidth:function(a){this.width=a},setColor:function(a){this.color=a},setErase:function(a){this.erase=a},deactivate:function(){this.origBacking=null;this.paintWidget.uiLayerShow(!1)},userUndo:function(){this.paintWidget.uiLayerShow(!1)}, userRedo:function(){this.paintWidget.uiLayerShow(!1)},width:10,color:"#ffffff",erase:!1,getHardFactor:function(){var a=1-this.softness/100;a*=0.4;a+=0.6;return a},_drawUICircle:function(a,b){this.paintWidget.uiLayerDrawCircleSelection(a,b,this.width/2)},_drawingUndo:function(a,b,c,d){a=this.paintWidget.getLayerByName(a).canvas.getContext("2d");AV.drawImageCopy(a,b,c,d);this.paintWidget.recomposite()},_drawingRedo:function(a,b,c,d){a=this._createLayerIfNecessary().canvas.getContext("2d");AV.drawImageCopy(a, b,c,d);this.paintWidget.recomposite()},_createLayerIfNecessary:function(){var a=this.paintWidget.getLayerByName("drawing");if(a==null)a=document.createElement("canvas"),a.width=this.paintWidget.width,a.height=this.paintWidget.height,a=new AV.Layer({canvas:a,name:"drawing"}),this.paintWidget.addLayer(a),this.paintWidget.uiLayerReset();if(a.canvas.width!=this.paintWidget.width)a.canvas.width=this.paintWidget.width;if(a.canvas.height!=this.paintWidget.height)a.canvas.height=this.paintWidget.height;return a}, _drawLine:function(a,b,c,d){if(d)this._drawLineSegment(a,b,c,d);else{var e=this.oldX,f=this.oldY;b-=e;c-=f;for(var g=Math.sqrt(b*b+c*c),h=g/this.width,i,j,h=Math.max(parseInt(g/2),h),g=0;g<=h;g++)i=h>0?g/h:0,j=e+b*i,i=f+c*i,this._drawLineSegment(a,j,i,d)}},_drawLineSegment:function(a,b,c,d){a.strokeStyle=this.erase?"rgba(0,0,0,0.0)":this.color;a.lineCap="round";a.lineJoin="round";a.shadowColor=a.strokeStyle;a.shadowOffsetX=0;a.shadowOffsetY=0;a.globalCompositeOperation=this.erase?"destination-out": "source-over";if(d)this.oldX=b-0.02,this.oldY=c;d=this.getHardFactor();this.erase?(a.strokeStyle="#fff",a.lineWidth=this.width,a.shadowBlur=0,a.beginPath(),a.moveTo(this.oldX,this.oldY),a.lineTo(b,c)):(d=Math.max(1,this.width*d),a.lineWidth=d,a.shadowBlur=this.width-d,a.shadowOffsetX=-15E3,a.shadowOffsetY=-15E3,a.beginPath(),a.moveTo(this.oldX+15E3,this.oldY+15E3),a.lineTo(b+15E3,c+15E3));a.stroke();a.closePath();this.oldX=b;this.oldY=c},mouseDownEvent:function(a,b){if(!this.mouseDown){var c=this._createLayerIfNecessary(); this.paintWidget.currentLayer=c;this.paintWidget.uiLayerShow(!0);this.pointlist=[[Math.floor(a),Math.floor(b)]];this.mouseDown=!0;this.bbox.reset();this.bbox.margin=parseInt(this.width/2)+10;var d=c.canvas.getContext("2d");this.origBacking=AV.copyCanvas(c.canvas);this._drawLine(d,a,b,!0);this.bbox.include(a,b);this.paintWidget.recomposite();return!1}},mouseMoveEvent:function(a,b){if(this.mouseDown){var c=this.paintWidget.currentLayer.canvas.getContext("2d");this.pointlist.push([Math.floor(a),Math.floor(b)]); this._drawLine(c,a,b,!1);this.bbox.include(a,b);this.paintWidget.uiLayerShow(!0);this._drawUICircle(a,b);this.paintWidget.recomposite();return!1}else this.paintWidget.uiLayerShow(!0),this._drawUICircle(a,b),this.paintWidget.recomposite()},mouseUpEvent:function(a,b){if(this.mouseDown){this.paintWidget.uiLayerShow(!1);this.mouseDown=!1;this.pointlist.push([a,b]);var c=this.paintWidget.currentLayer;c.canvas.getContext("2d").closePath();var d=AV.copyCanvas(c.canvas,this.bbox.x0,this.bbox.y0,this.bbox.w, this.bbox.h),e=AV.copyCanvas(this.origBacking,this.bbox.x0,this.bbox.y0,this.bbox.w,this.bbox.h);this.paintWidget.actionPush([this._drawingUndo,this,[c.name,e,this.bbox.x0,this.bbox.y0]],[this._drawingRedo,this,[c.name,d,this.bbox.x0,this.bbox.y0]],{action:"drawing",erase:this.erase,radius:Math.floor(this.width),softness:Math.floor(this.softness),color:AV__color_to_rgb(this.color),pointlist:this.pointlist});this.paintWidget.actionRedoFake();this.pointlist=this.origBacking=null}},mouseOutEvent:function(){this.paintWidget.uiLayerShow(!1)}}; AV.PaintWidget.prototype.module_rotate90={activate:function(a){this.paintWidget=a},makeThumb:function(a,b){var c,d;b%=360;b<0&&(b+=360);b=parseInt(b/90,10)*90;b%180!=0?(c=a.height,d=a.width):(c=a.width,d=a.height);var e=document.createElement("canvas");e.width=a.width;e.height=a.height;this.paintWidget.makeThumbFlat(e,!0);a.width=c;a.height=d;c=a.getContext("2d");c.setTransform(1,0,0,1,0,0);c.translate(a.width/2,a.height/2);c.rotate(b*3.14159265358979/180);c.translate(-e.width/2,-e.height/2);c.globalCompositeOperation= "copy";c.drawImage(e,0,0);c.globalCompositeOperation="source-over";c.setTransform(1,0,0,1,0,0)},_rotate90Undo:function(a,b,c){this.paintWidget.width=this.paintWidget.canvas.width=b;this.paintWidget.height=this.paintWidget.canvas.height=c;this.paintWidget.duplicateAllLayersFrom(a);this.paintWidget.recomposite()},_rotate90Redo:function(a,b){b&&this.paintWidget.flattenAllLayers();this.paintWidget.rotate90(a)},rotate90:function(a,b){var c,d,e;b?(c=this.paintWidget.duplicateAllLayers(),d=this.paintWidget.width, e=this.paintWidget.height,this.paintWidget.actionPush([this._rotate90Undo,this,[c,d,e]],[this._rotate90Redo,this,[a,b]],{action:"rotate90",angle:a,flatten:b})):this.paintWidget.actionPush([this._rotate90Redo,this,[-a,b]],[this._rotate90Redo,this,[a,b]],{action:"rotate90",angle:a,flatten:b});this.paintWidget.actionRedo()}}; AV.PaintWidget.prototype.module_resize={activate:function(a){this.paintWidget=a},_resizeUndo:function(a,b,c,d){this.paintWidget.actionListScaleFactor=d;this.paintWidget.setDimensions(b,c);this.paintWidget.duplicateAllLayersFrom(a);this.paintWidget.recomposite()},_resizeRedo:function(a,b,c){this.paintWidget.actionListScaleFactor=c;this.paintWidget.resizeAllLayers(a,b);this.paintWidget.recomposite()},resize:function(a,b,c){var d=this.paintWidget.duplicateAllLayers();c&&this.paintWidget.flattenAllLayers(); a=Math.floor(a);b=Math.floor(b);this.paintWidget.actionPush([this._resizeUndo,this,[d,this.paintWidget.canvas.width,this.paintWidget.canvas.height,this.paintWidget.prevActionListScaleFactor]],[this._resizeRedo,this,[a,b,this.paintWidget.actionListScaleFactor]],[{action:"resize",size:[this.paintWidget.c2a(a,!0),this.paintWidget.c2a(b,!0)]},{action:"setfeathereditsize",width:a,height:b}]);this.paintWidget.actionRedo()}}; AV.PaintWidget.prototype.module_crop=function(){var a,b,c=1,d=!1,e=-1,f=0,g=!1,h=!1,i=null,j=null,k={},p=function(){c=b?Math.abs((b.x1-b.x0)/(b.y1-b.y0)):0},m=function(b,c,d,e){a.actionListScaleFactor=e;a.setDimensions(c,d);a.duplicateAllLayersFrom(b);a.recomposite()},l=function(b,c,d,e){var f=a.actionListScaleFactor;a.cropAllLayers(b,c,d,e);f>1&&(b=d*f,e*=f,f=Math.max(b,e),f<=AV_launchData.maxSize?f=1:(f=Math.max(1,f/AV_launchData.maxSize),b/=f,e/=f,b=Math.floor(b),e=Math.floor(e),a.resizeAllLayers(b, e,!0),a.actionPush(null,null,{action:"setfeathereditsize",width:b,height:e}),a.actionImplicit(!0)),a.setActionListScaleFactor(f));a.recomposite();p()},n=function(){var c,d,e,h,i=20,j=a.getLayerByName("_ui");b.x0<b.x1?(c=b.x0,e=b.x1):(c=b.x1,e=b.x0);b.y0<b.y1?(d=b.y0,h=b.y1):(d=b.y1,h=b.y0);var k=(e-c)/320,n=(h-d)/240,k=k<n?k:n;k>1&&(k=1);i=parseInt(i*k);i<5&&(i=5);var n=c-4,l=e+4,m=d-4,p=h+4,k=j.canvas.getContext("2d");k.globalCompositeOperation="copy";k.clearRect(0,0,j.canvas.width,j.canvas.height); k.globalCompositeOperation="source-over";k.fillStyle="#000000";k.globalAlpha=0.6;k.fillRect(0,0,c,j.canvas.height);k.fillRect(e,0,j.canvas.width,j.canvas.height);k.fillRect(c,0,e-c,d-0);k.fillRect(c,h,e-c,j.canvas.height-h);k.strokeStyle="#297bb6";k.globalAlpha=1;k.lineWidth=4;k.lineCap="square";k.beginPath();k.moveTo(n,m+i);k.lineTo(n,m);k.lineTo(n+i,m);k.stroke();k.moveTo(l-i,m);k.lineTo(l,m);k.lineTo(l,m+i);k.stroke();k.moveTo(l,p-i);k.lineTo(l,p);k.lineTo(l-i,p);k.stroke();k.moveTo(n+i,p);k.lineTo(n, p);k.lineTo(n,p-i);k.stroke();k.closePath();if(!g)k.fillStyle="#ffffff",k.font="1212 px, sans-serif",k.textAlign="center",c=k.measureText("Drag corners to resize crop area").width,c<j.canvas.width&&b.y0>23&&k.fillText("Drag corners to resize crop area",j.canvas.width/2,b.y0-9);f=i};return{activate:function(c){a=c;b=new AV.Bbox;d=g=_mouseDownn=!1;a.uiLayerReset();a.uiLayerShow(!0)},deactivate:function(){a.uiLayerShow(!1)},userPostUndo:function(){this.setInitialSelection()},userPostRedo:function(){this.setInitialSelection()}, forceAspect:function(a){a&&p();d=a},setInitialSelectionTo:function(c,d){b.x0=parseInt((a.canvas.width-c)/2);b.x1=parseInt(b.x0+c);b.y0=parseInt((a.canvas.height-d)/2);b.y1=parseInt(b.y0+d);a.uiLayerReset();a.uiLayerShow(!0);n();a.recomposite()},setInitialSelectionByRatio:function(b){var c=a.canvas.width,d=a.canvas.height;c-=2*Math.floor(c*0);var e=d-2*Math.floor(d*0),d=e*b;d>c&&(d=c,e=c/b);return this.setInitialSelectionTo(d,e)},setInitialSelection:function(){var c,e,f,g;d?c=f=0.12:(c=0.09,f=0.18); e=1-c;g=1-f;b.x0=parseInt(a.canvas.width*c);b.x1=parseInt(a.canvas.width*e);b.y0=parseInt(a.canvas.height*f);b.y1=parseInt(a.canvas.height*g);a.uiLayerReset();a.uiLayerShow(!0);n();a.recomposite()},hideSelection:function(){a.uiLayerShow(!1)},setMouseDownCallback:function(a){i=a},mouseDownEvent:function(c,d){var l=99999999,m,p=f*f;j=null;a.uiLayerReset();a.uiLayerShow(!0);e=-1;m=AV.sqrDist(b.x0,b.y0,c,d);m<l&&m<p&&(e=0,l=m);m=AV.sqrDist(b.x1,b.y0,c,d);m<l&&m<p&&(e=1,l=m);m=AV.sqrDist(b.x0,b.y1,c,d); m<l&&m<p&&(e=2,l=m);m=AV.sqrDist(b.x1,b.y1,c,d);m<l&&m<p&&(e=3);i&&i(c,d,e>-1);switch(e){case 0:k={x:c-b.x0,y:d-b.y0};break;case 3:k={x:b.x1-c,y:b.y1-d};break;case 1:k={x:b.x1-c,y:d-b.y0};break;case 2:k={x:c-b.x0,y:b.y1-d};break;default:if(b.contains(c,d))j={x:c,y:d};else return}n();a.setMouseCursor("move");h=g=!0;a.recomposite();return!1},mouseMoveEvent:function(f,i){var l,m;if(h){if(j!=null)l=f-j.x,m=i-j.y,b.x0+=l,b.x1+=l,b.y0+=m,b.y1+=m,j.x=f,j.y=i;else{switch(e){case 1:b.x1=f+k.x;b.y0=i-k.y;break; case 2:b.x0=f-k.x;b.y1=i+k.y;break;case 3:b.x1=f+k.x;b.y1=i+k.y;break;default:b.x0=f-k.x,b.y0=i-k.y}if(d&&c!=0)if(l=1/c,Math.abs((b.x1-b.x0)/(b.y1-b.y0))<c)switch(e){case 1:case 3:b.x1=parseInt(b.x0+AV.sign(b.x1-b.x0)*Math.abs(b.y1-b.y0)*c);break;default:b.x0=parseInt(b.x1-AV.sign(b.x1-b.x0)*Math.abs(b.y1-b.y0)*c)}else switch(e){case 2:case 3:b.y1=parseInt(b.y0+AV.sign(b.y1-b.y0)*Math.abs(b.x1-b.x0)*l);break;default:b.y0=parseInt(b.y1-AV.sign(b.y1-b.y0)*Math.abs(b.x1-b.x0)*l)}}n();g=!0;a.recomposite(0); return!1}},mouseUpEvent:function(){var c;if(h){if(b.x0>b.x1)c=b.x0,b.x0=b.x1,b.x1=c;if(b.y0>b.y1)c=b.y0,b.y0=b.y1,b.y1=c;h=!1;a.setMouseCursor("default");return!1}},crop:function(){a.uiLayerShow(!1);var c,d,e,f;b.x0<b.x1?(c=b.x0,e=b.x1):(c=b.x1,e=b.x0);b.y0<b.y1?(d=b.y0,f=b.y1):(d=b.y1,f=b.y0);var g=a.getLayerByName("_ui");c<0&&(c=0);d<0&&(d=0);if(e>g.canvas.width)e=g.canvas.width;if(f>g.canvas.height)f=g.canvas.height;e-=c;f-=d;g=a.duplicateAllLayers();a.actionPush([m,this,[g,a.canvas.width,a.canvas.height, a.actionListScaleFactor]],[l,this,[c,d,e,f]],{action:"crop",upperleftpoint:[Math.floor(c),Math.floor(d)],size:[Math.floor(e),Math.floor(f)]});a.actionRedo();this.setInitialSelection()}}}(); AV.PaintWidget.prototype.module_overlay=function(){var a,b=null,c=null,d=!1,e=null,f=null,g=0,h=0,i=0,j=1,k=1,p=0,m=0,l=0,n=0,q=function(c){c=a.findLayerIndexByName(c);c!=-1&&(a.layers[c]===b&&(b=null,a.uiLayerShow(!1)),a.layerDelete(c));a.recomposite()},o=function(b,c,d,e,f,g,h){b=new AV.Layer({name:b,image:c});b.tag="module_overlay";b.centerX=parseInt(b.drawable.width/2);b.centerY=parseInt(b.drawable.height/2);h!=null?(b.translateX=d,b.translateY=e,b.rotate=h,b.scaleX=f,b.scaleY=g):(b.translateX= parseInt(a.width/2),b.translateY=parseInt(a.height/2));a.layers.push(b);a.recomposite()},r=function(b,c,d){a.moveLayerByName(b,c,d);a.recomposite()},s=function(b,c,d,e){b=a.getLayerByName(b);if(b!=null)b.rotate=c,b.scaleX=d,b.scaleY=e;a.recomposite()};return{activate:function(f){a=f;b=c=null;d=!1;e={x:0,y:0}},deactivate:function(){b=c=null;a.uiLayerShow(!1)},userUndo:function(){b=null;a.uiLayerShow(!1)},userRedo:function(){b=null;a.uiLayerShow(!1)},newOverlay:function(d,e,f,g,h,i){var j=a.overlayRegistry.getClean(d), k="_module_overlay-"+Math.floor(Math.random()*4294967295).toString(16);i!=null?j=[k,j,e,f,g,h,i]:f!=null?(j=[k,j,e,f,1,1,0],g=h=1,i=0):(j=[k,j],g=h=1,i=0,e=parseInt(a.width/2),f=parseInt(a.height/2));a.actionPush([q,this,[k]],[o,this,j],{action:"addsticker",url:d,id:k,center:[e,f],scale:[g,h],rotation:i});a.actionRedo();a.uiLayerReset();a.uiLayerShow(!0);c=b=a.getLayerByName(k);a.uiLayerDrawRectSelection(c,1);a.recomposite();return k},deleteSelectedOverlay:function(){if(b!=null){var c=b.name;a.actionPush([o, this,[c,b.image,b.translateX,b.translateY,b.scaleX,b.scaleY,b.rotate]],[q,this,[c]],{action:"deletesticker",id:c});a.actionRedo()}},mouseDownEvent:function(o,r){if(!d){e={x:0,y:0};if(b!=null)e.thumbWidth=20,e.thumbOutset=7;var q=a.getLayerByMouseClickWithTag(o,r,"tag","module_overlay",e,1);if(q==null)a.uiLayerShow(!1),b=null;else{var s=a.findLayerIndexByName(q.name);a.layerToTop(s);e.thumbHit==1||e.thumbHit==2?(f="rotate",a.setMouseCursor("pointer")):(f="translate",a.setMouseCursor("move"));a.uiLayerReset(); a.uiLayerShow(!0);switch(f){case "rotate":g=q.rotate;switch(e.thumbHit){case 0:h=Math.atan2(q.translateX-o,r-q.translateY);break;case 1:return b=q,this.deleteSelectedOverlay(),!1;case 2:h=Math.atan2(q.translateX-o,q.translateY-r);break;case 3:h=Math.atan2(o-q.translateX,q.translateY-r)}i=q.rotate;j=q.scaleX;k=q.scaleY;break;case "translate":p=q.translateX,m=q.translateY,l=q.translateX-o,n=q.translateY-r}c=b=q;d=!0;this.mouseMoveEvent(o,r);return!1}}},mouseMoveEvent:function(b,g){var j;if(d){switch(f){case "rotate":switch(e.thumbHit){case 0:j= Math.atan2(c.translateX-b,g-c.translateY);j=h-j;break;case 1:return!1;case 2:j=Math.atan2(c.translateX-b,c.translateY-g);j-=h;break;case 3:j=Math.atan2(b-c.translateX,c.translateY-g),j=h-j}c.rotate=i-j;var k=b-c.translateX,m=g-c.translateY;j=Math.sqrt(k*k+m*m);k=c.centerX!=null?c.drawable.width-c.centerX:c.drawable.width;m=c.centerY!=null?c.drawable.height-c.centerY:c.drawable.height;j/=Math.sqrt(k*k+m*m);j<1.0E-4&&(j=1.0E-4);c.scaleX=j;c.scaleY=j;break;case "translate":a.moveLayerByName(c.name,b+ l,g+n)}a.uiLayerDrawRectSelection(c,1);a.recomposite();return!1}},mouseUpEvent:function(){a.setMouseCursor();if(d){switch(f){case "rotate":a.actionPush([s,this,[c.name,g,j,k]],[s,this,[c.name,c.rotate,c.scaleX,c.scaleY]],{action:"setsticker",id:c.name,center:[c.translateX,c.translateY],scale:[c.scaleX,c.scaleY],rotation:c.rotate});break;case "translate":a.actionPush([r,this,[c.name,p,m]],[r,this,[c.name,c.translateX,c.translateY]],{action:"setsticker",id:c.name,center:[c.translateX,c.translateY], scale:[c.scaleX,c.scaleY],rotation:c.rotate})}a.actionRedoFake();c=null;d=!1}},mouseDropEvent:function(b,c,d,e,f){(d=a.overlayRegistry.getClean(f.draggable[0].id))&&this.newOverlay(d.fullimageurl,b,c)}}}(); AV.PaintWidget.prototype.module_flatten={activate:function(a){this.paintWidget=a},_flattenUndo:function(a){this.paintWidget.duplicateAllLayersFrom(a);this.paintWidget.recomposite()},_flattenRedo:function(){this.paintWidget.flattenAllLayers();this.paintWidget.recomposite()},flatten:function(){this.paintWidget.actionPush([this._flattenUndo,this,[this.paintWidget.duplicateAllLayers()]],[this._flattenRedo,this,[]],{action:"flatten"});this.paintWidget.actionRedo()}}; AV.PaintWidget.prototype.module_text={activate:function(a){this.selectedLayer=this.draggedLayer=null;this.paintWidget=a;this.localPoint={x:0,y:0}},deactivate:function(){this.selectedLayer=this.draggedLayer=null;this.paintWidget.uiLayerShow(!1)},userUndo:function(){this.selectedLayer=null;this.paintWidget.uiLayerShow(!1)},userRedo:function(){this.selectedLayer=null;this.paintWidget.uiLayerShow(!1)},_textWidth:function(a,b){var c=a.split(" "),d=this.paintWidget.canvas.getContext("2d"),e=d.font;d.font= b;var f=0,g,h;for(h=0;h<c.length;h++)if(g=d.measureText(c[h]),g.width>f)f=g.width;d.font=e;return f},_textHeight:function(a,b){var c=a.split(" ");return b*c.length+b/2},_textUndo:function(a){a=this.paintWidget.findLayerIndexByName(a);a>=0&&(this.paintWidget.layerDelete(a),this.paintWidget.recomposite())},_textRedo:function(a,b,c,d,e,f,g,h,i,j,k){var p=""+d+"px "+c,m=this._textWidth(b,p),l=this._textHeight(b,d),n=document.createElement("canvas");n.width=m;n.height=l;a=new AV.Layer({canvas:n,name:a}); a.tag="module_text";a.centerX=parseInt(a.drawable.width/2,10);a.centerY=parseInt(a.drawable.height/2,10);a.module_data={str:b,fontName:c,fontSizePx:d,fontColor:e,shadowColor:f};a.rotate=k==null?0:k;i==null?(a.scaleX=1,a.scaleY=1):(a.scaleX=i,a.scaleY=j);g==null?(a.translateX=parseInt(this.paintWidget.width/2,10),a.translateY=parseInt(this.paintWidget.height/2,10)):(a.translateX=g,a.translateY=h);this.paintWidget.layers.push(a);c=n.getContext("2d");c.font=p;b=b.split(" ");f=d;for(p=0;p<b.length;p++)c.fillStyle= e,c.fillText(b[p],0,f),f+=d;this.paintWidget.recomposite()},_moveLayer:function(a,b,c){this.paintWidget.moveLayerByName(a,b,c);this.paintWidget.recomposite()},_rotScaleLayer:function(a,b,c,d){a=this.paintWidget.getLayerByName(a);if(a!=null)a.rotate=b,a.scaleX=c,a.scaleY=d;this.paintWidget.recomposite()},newText:function(a,b,c,d,e,f,g,h,i,j){if(a!=""){var k="_module_text-"+Math.floor(Math.random()*4294967295).toString(16),p;p=j!=null?[k,a,b,c,d,e,f,g,h,i,j]:g!=null?[k,a,b,c,d,e,f,g,1,1,0]:[k,a,b,c, d,e,a];h||(h=i=1);j||(j=0);f||(f=parseInt(this.paintWidget.width/2,10),g=parseInt(this.paintWidget.height/2,10));this.paintWidget.actionPush([this._textUndo,this,[k]],[this._textRedo,this,p],{action:"addtext",id:k,text:a,font:b,size:c,color:AV__color_to_rgb(d),shadowcolor:AV__color_to_rgb(e),center:[f,g],scale:[h,i],rotation:j});this.paintWidget.actionRedo();this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0);this.draggedLayer=this.selectedLayer=this.paintWidget.getLayerByName(k);this._drawSelection(); this.paintWidget.recomposite()}},deleteSelectedText:function(){if(this.selectedLayer!=null){var a=this.selectedLayer.name;this.paintWidget.actionPush([this._textRedo,this,[a,this.selectedLayer.module_data.str,this.selectedLayer.module_data.fontName,this.selectedLayer.module_data.fontSizePx,this.selectedLayer.module_data.fontColor,this.selectedLayer.module_data.shadowColor,this.selectedLayer.translateX,this.selectedLayer.translateY,this.selectedLayer.scaleX,this.selectedLayer.scaleY,this.selectedLayer.rotate]], [this._textUndo,this,[a]],{action:"deletetext",id:a});this.paintWidget.uiLayerShow(!1);this.paintWidget.actionRedo()}},_drawSelection:function(){this.paintWidget.uiLayerDrawRectSelection(this.draggedLayer,1)},mouseDownEvent:function(a,b){if(!this.mouseDown){this.localPoint={x:0,y:0};if(this.selectedLayer!=null)this.localPoint.thumbWidth=20,this.localPoint.thumbOutset=7;var c=this.paintWidget.getLayerByMouseClickWithTag(a,b,"tag","module_text",this.localPoint,1);if(c==null)this.paintWidget.uiLayerShow(!1), this.selectedLayer=null;else{this.paintWidget.layerToTop(this.paintWidget.findLayerIndexByName(c.name));this.localPoint.thumbHit==1||this.localPoint.thumbHit==2?(this.mode="rotate",this.paintWidget.setMouseCursor("pointer")):(this.mode="translate",this.paintWidget.setMouseCursor("move"));this.paintWidget.uiLayerReset();this.paintWidget.uiLayerShow(!0);switch(this.mode){case "rotate":this.undoRotate=c.rotate;switch(this.localPoint.thumbHit){case 0:this.originalAngle=Math.atan2(c.translateX-a,b-c.translateY); break;case 1:return this.selectedLayer=c,this.deleteSelectedText(),!1;case 2:this.originalAngle=Math.atan2(c.translateX-a,c.translateY-b);break;case 3:this.originalAngle=Math.atan2(a-c.translateX,c.translateY-b)}this.originalRotate=c.rotate;this.originalScaleX=c.scaleX;this.originalScaleY=c.scaleY;break;case "translate":this.originalX=c.translateX,this.originalY=c.translateY,this.offsetX=c.translateX-a,this.offsetY=c.translateY-b}this.draggedLayer=this.selectedLayer=c;this.mouseDown=!0;this._drawSelection(); this.paintWidget.recomposite();return!1}}},mouseMoveEvent:function(a,b){var c;if(this.mouseDown){switch(this.mode){case "rotate":switch(this.localPoint.thumbHit){case 0:c=Math.atan2(this.draggedLayer.translateX-a,b-this.draggedLayer.translateY);c=this.originalAngle-c;break;case 1:return!1;case 2:c=Math.atan2(this.draggedLayer.translateX-a,this.draggedLayer.translateY-b);c-=this.originalAngle;break;case 3:c=Math.atan2(a-this.draggedLayer.translateX,this.draggedLayer.translateY-b),c=this.originalAngle- c}this.draggedLayer.rotate=this.originalRotate-c;var d=a-this.draggedLayer.translateX,e=b-this.draggedLayer.translateY;c=Math.sqrt(d*d+e*e);d=this.draggedLayer.centerX!=null?this.draggedLayer.drawable.width-this.draggedLayer.centerX:this.draggedLayer.drawable.width;e=this.draggedLayer.centerY!=null?this.draggedLayer.drawable.height-this.draggedLayer.centerY:this.draggedLayer.drawable.height;c/=Math.sqrt(d*d+e*e);c<1.0E-4&&(c=1.0E-4);this.draggedLayer.scaleX=c;this.draggedLayer.scaleY=c;break;case "translate":this.paintWidget.moveLayerByName(this.draggedLayer.name, a+this.offsetX,b+this.offsetY)}this._drawSelection();this.paintWidget.recomposite();return!1}},mouseUpEvent:function(){this.paintWidget.setMouseCursor();if(this.mouseDown){switch(this.mode){case "rotate":this.paintWidget.actionPush([this._rotScaleLayer,this,[this.draggedLayer.name,this.undoRotate,this.originalScaleX,this.originalScaleY]],[this._rotScaleLayer,this,[this.draggedLayer.name,this.draggedLayer.rotate,this.draggedLayer.scaleX,this.draggedLayer.scaleY]],{action:"settext",id:this.draggedLayer.name, center:[this.draggedLayer.translateX,this.draggedLayer.translateY],scale:[this.draggedLayer.scaleX,this.draggedLayer.scaleY],rotation:this.draggedLayer.rotate});break;case "translate":this.paintWidget.actionPush([this._moveLayer,this,[this.draggedLayer.name,this.originalX,this.originalY]],[this._moveLayer,this,[this.draggedLayer.name,this.draggedLayer.translateX,this.draggedLayer.translateY]],{action:"settext",id:this.draggedLayer.name,center:[this.draggedLayer.translateX,this.draggedLayer.translateY], scale:[this.draggedLayer.scaleX,this.draggedLayer.scaleY],rotation:this.draggedLayer.rotate})}this.paintWidget.actionRedoFake();this.draggedLayer=null;this.mouseDown=!1}}}; AV.PaintWidget.prototype.module_blur={radius:0,activate:function(a){this.paintWidget=a;this.oldLayers=this.newCanvasData=this.origBacking=null;this.r=this.g=this.b=0;this.flatten=!1},deactivate:function(){this.reset()},makeThumb:function(a,b){this.paintWidget.makeThumbFlat(a);var c=a.width,d=a.height,e=a.getContext("2d"),f=e.getImageData(0,0,c,d),g=e.createImageData(c,d);this._blurRun(f.data,g.data,c,d,b);e.putImageData(g,0,0)},_blurUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c): (a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},_blurRedo:function(a,b,c){this._set(a,b,c);this.oldLayers=this.origBacking=null},set:function(a,b){this.paintWidget.dirty=!0;this._set(this.paintWidget.layers[this.paintWidget.currentLayerIndex].name,a,b)},_set:function(a,b,c){var d=this.paintWidget.getLayerByName(a);if(d.canvas!=null){var e=d.canvas.getContext("2d"); if(this.origBacking==null){if(c)this.oldLayers=this.paintWidget.duplicateAllLayers(),this.paintWidget.flattenAllLayers(),d=this.paintWidget.getLayerByName(a),e=d.canvas.getContext("2d");this.origBackingPixels=AV.getCanvasPixelData(d.canvas);this.origBacking=AV.copyCanvas(d.canvas);this.newCanvasData=e.createImageData(d.canvas.width,d.canvas.height)}this.radius=b;this.flatten=c;this.paintWidget.showWaitThrobber(!0,function(){this._blurRun(this.origBackingPixels.data,this.newCanvasData.data,d.canvas.width, d.canvas.height,b);e.putImageData(this.newCanvasData,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}},_blurRun:function(a,b,c,d,e){var f=c-1,g=d-1,h=c*d,i=e+e+1,j=[];j.length=h;var k=[];k.length=h;var p=[];p.length=h;var m,l,n,q,o,r,s,h=[];h.length=Math.max(c,d);var t=[];t.length=Math.max(c,d);var v=[];v.length=256*i;var u;for(o=0;o<256*i;o++)v[o]=~~(o/i);for(q=s=r=0;q<d;q++){i=m=l=0;for(o=-e;o<=e;o++)u=(r+Math.min(f,Math.max(o,0)))*4,i+=a[u],m+=a[u+ 1],l+=a[u+2];for(n=0;n<c;n++)j[r]=v[i],k[r]=v[m],p[r]=v[l],q==0&&(h[n]=Math.min(n+e+1,f),t[n]=Math.max(n-e,0)),o=(s+h[n])*4,u=(s+t[n])*4,i+=a[o]-a[u],m+=a[o+1]-a[u+1],l+=a[o+2]-a[u+2],r++;s+=c}for(n=0;n<c;n++){i=m=l=0;f=-e*c;for(o=-e;o<=e;o++)r=Math.max(0,f)+n,i+=j[r],m+=k[r],l+=p[r],f+=c;r=n;for(q=0;q<d;q++)i=parseInt(i,10),m=parseInt(m,10),l=parseInt(l,10),u=r*4,b[u]=v[i],b[u+1]=v[m],b[u+2]=v[l],b[u+3]=a[u+3],n==0&&(h[q]=Math.min(q+e+1,g)*c,t[q]=Math.max(q-e,0)*c),f=n+h[q],o=n+t[q],i+=j[f]-j[o], m+=k[f]-k[o],l+=p[f]-p[o],r+=c}},reset:function(){if(this.oldLayers)this.paintWidget.duplicateAllLayersFrom(this.oldLayers),this.paintWidget.recomposite();else if(this.origBacking){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas.getContext("2d");a.globalCompositeOperation="copy";a.drawImage(this.origBacking,0,0);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()}this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null},commit:function(){if(this.origBacking!= null){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex];this.paintWidget.actionPush([this._blurUndo,this,[a.name,this.origBacking,this.oldLayers]],[this._blurRedo,this,[a.name,this.radius,this.flatten]],{action:"blur",radius:this.radius,flatten:this.flatten});this.paintWidget.actionRedoFake();this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null}}}; AV.PaintWidget.prototype.module_barrel={barrelchange:0,activate:function(a){this.paintWidget=a;this.oldLayers=this.newCanvasData=this.origBacking=null;this.barrelchange=0;this.flatten=!1},deactivate:function(){this.reset()},_barrelUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},_barrelRedo:function(a, b,c){this._barrel(a,b,c);this.oldLayers=this.origBacking=null},set:function(a,b){this.paintWidget.dirty=!0;this._barrel(this.paintWidget.layers[this.paintWidget.currentLayerIndex].name,a,b)},makeThumb:function(a,b){this.paintWidget.makeThumbFlat(a);var c=a.getContext("2d"),d=c.getImageData(0,0,a.width,a.height),e=c.createImageData(a.width,a.height);this._barrelRun(e.data,d.data,d.width,d.height,b);c.putImageData(e,0,0)},_barrelRun:function(a,b,c,d,e){if(e==0)for(c=0;c<b.length;c++)a[c]=b[c];else{var f= (c-1)/2,g=(d-1)/2,h=Math.sqrt(f*f+g*g),i;e>0?(e=Math.pow(e/100,2)*8,i=h):(e=-Math.sqrt(-e/100)*0.34,i=Math.min(g,f));i=AV.lowestPositiveQuadratic(e/h,1,-i)/i*0.999999;var j,k;for(k=0;k<d;k++){var p=i*(k-g);for(j=0;j<c;j++){var m=i*(j-f),l=1+e*Math.sqrt(m*m+p*p)/h,m=m*l+f,l=p*l+g,n=Math.floor(m),q=Math.floor(l);m-=n;l-=q;var o=1-m,r=1-l,n=(n+q*c)*4,q=b[n]*o+b[n+4]*m,s=b[n+1]*o+b[n+5]*m,t=b[n+2]*o+b[n+6]*m,v=b[n+3]*o+b[n+7]*m;n+=c*4;var u=b[n+1]*o+b[n+5]*m,y=b[n+2]*o+b[n+6]*m,x=b[n+3]*o+b[n+7]*m,w= (j+k*c)*4;a[w]=q*r+(b[n]*o+b[n+4]*m)*l;a[w+1]=s*r+u*l;a[w+2]=t*r+y*l;a[w+3]=v*r+x*l}}}},_barrel:function(a,b,c){var d=this.paintWidget.getLayerByName(a);if(d.canvas!=null){var e;e=d.canvas.getContext("2d");if(this.origBacking==null){if(c)this.oldLayers=this.paintWidget.duplicateAllLayers(),this.paintWidget.flattenAllLayers(),d=this.paintWidget.getLayerByName(a),e=d.canvas.getContext("2d");this.origBackingPixels=AV.getCanvasPixelData(d.canvas);this.origBacking=AV.copyCanvas(d.canvas);this.newCanvasData= e.createImageData(d.canvas.width,d.canvas.height)}this.barrelchange=b;this.flatten=c;this.paintWidget.showWaitThrobber(!0,function(){this._barrelRun(this.newCanvasData.data,this.origBackingPixels.data,this.origBackingPixels.width,this.origBackingPixels.height,b);e.putImageData(this.newCanvasData,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}},reset:function(){if(this.oldLayers)this.paintWidget.duplicateAllLayersFrom(this.oldLayers),this.paintWidget.recomposite(); else if(this.origBacking){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas.getContext("2d");a.globalCompositeOperation="copy";a.drawImage(this.origBacking,0,0);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()}this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null},commit:function(){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex];this.paintWidget.actionPush([this._barrelUndo,this,[a.name,this.origBacking,this.oldLayers]], [this._barrelRedo,this,[a.name,this.barrelchange,this.flatten]],{action:"barrel",value:this.barrelchange,flatten:this.flatten});this.paintWidget.actionRedoFake();this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null}};AV.lowestPositiveQuadratic=function(a,b,c){b=AV.solveQuadratic(a,b,c);a=b[0];b=b[1];if(b<=0&&a>0)return a;if(a<=0&&b>0)return b;return Math.max(Math.min(a,b),0)}; AV.solveQuadratic=function(a,b,c){var d=-b,b=b*b-4*a*c;a*=2;if(b<0)return[0,0];return[(d-Math.sqrt(b))/a,(d+Math.sqrt(b))/a]}; AV.PaintWidget.prototype.module_sharpen={sharpenchange:0,activate:function(a){this.paintWidget=a;this.oldLayers=this.newCanvasData=this.origBacking=null;this.sharpenchange=0;this.flatten=!1},deactivate:function(){this.reset()},_sharpenUndo:function(a,b,c){c?this.paintWidget.duplicateAllLayersFrom(c):(a=this.paintWidget.getLayerByName(a).canvas.getContext("2d"),a.globalCompositeOperation="copy",a.drawImage(b,0,0),a.globalCompositeOperation="source-over");this.paintWidget.recomposite()},_sharpenRedo:function(a, b,c){this._sharpen(a,b,c);this.oldLayers=this.origBacking=null},set:function(a,b){this.paintWidget.dirty=!0;this._sharpen(this.paintWidget.layers[this.paintWidget.currentLayerIndex].name,a,b)},makeThumb:function(a,b){this.paintWidget.makeThumbFlat(a);var c=a.getContext("2d"),d=c.getImageData(0,0,a.width,a.height),e=c.createImageData(a.width,a.height);this._sharpenRun(e.data,d.data,d.width,d.height,b);c.putImageData(e,0,0)},_sharpenRun:function(a,b,c,d,e){if(e==0){var f;for(f=0;f<b.length;f++)a[f]= b[f]}else{var g=0.3+3*(e/100),e=Math.ceil(2.5*g),h=e*2+1,i=[],j;for(f=0;f<h;f++){j=f-e;var k=g;i[f]=1/(Math.sqrt(2*Math.PI)*k)*Math.exp(-(j*j)/(2*k*k));i[f]*=Math.sqrt(1)}for(f=g=0;f<h;f++)for(j=0;j<h;j++)g+=i[f]*i[j];f=[];for(j=0;j<d;j++)h=j*c*4,k=4,AV.applyKernel1D(i,e,f,h,k,b,h,k,c);for(j=0;j<c;j++)h=j*4,k=c*4,AV.applyKernel1D(i,e,a,h,k,f,h,k,d);c=1+g;for(f=0;f<a.length;)a[f]=~~(c*b[f]-a[f]),f++,a[f]=~~(c*b[f]-a[f]),f++,a[f]=~~(c*b[f]-a[f]),f++,a[f]=b[f],f++;for(f=0;f<a.length;f++)b=a[f],b>255&& (a[f]=255),b<0&&(a[f]=0)}},_sharpen:function(a,b,c){var d=this.paintWidget.getLayerByName(a);if(d.canvas!=null){var e;e=d.canvas.getContext("2d");if(this.origBacking==null){if(c)this.oldLayers=this.paintWidget.duplicateAllLayers(),this.paintWidget.flattenAllLayers(),d=this.paintWidget.getLayerByName(a),e=d.canvas.getContext("2d");this.origBackingPixels=AV.getCanvasPixelData(d.canvas);this.origBacking=AV.copyCanvas(d.canvas);this.newCanvasData=e.createImageData(d.canvas.width,d.canvas.height)}this.sharpenchange= b;this.flatten=c;this.paintWidget.showWaitThrobber(!0,function(){this._sharpenRun(this.newCanvasData.data,this.origBackingPixels.data,this.origBackingPixels.width,this.origBackingPixels.height,b);e.putImageData(this.newCanvasData,0,0);this.paintWidget.recomposite();this.paintWidget.showWaitThrobber(!1)}.AV_bindInst(this))}},reset:function(){if(this.oldLayers)this.paintWidget.duplicateAllLayersFrom(this.oldLayers),this.paintWidget.recomposite();else if(this.origBacking){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex].canvas.getContext("2d"); a.globalCompositeOperation="copy";a.drawImage(this.origBacking,0,0);a.globalCompositeOperation="source-over";this.paintWidget.recomposite()}this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null},commit:function(){var a=this.paintWidget.layers[this.paintWidget.currentLayerIndex];this.paintWidget.actionPush([this._sharpenUndo,this,[a.name,this.origBacking,this.oldLayers]],[this._sharpenRedo,this,[a.name,this.sharpenchange,this.flatten]],{action:"sharpen",value:this.sharpenchange, flatten:this.flatten});this.paintWidget.actionRedoFake();this.oldLayers=this.newCanvasData=this.origBackingPixels=this.origBacking=null}}; AV.applyKernel1D=function(a,b,c,d,e,f,g,h,i){var j=a.length,k,p,m=i-1-(j-b);for(k=0;k<i;k++){var l=0,n=0,q=0;if(k>=b&&k<=m){var o=g+(k+(j-b)-1)*h,r;for(p=j-1;p>=3;)r=a[p--],l+=r*f[o],n+=r*f[o+1],q+=r*f[o+2],o-=h,r=a[p--],l+=r*f[o],n+=r*f[o+1],q+=r*f[o+2],o-=h,r=a[p--],l+=r*f[o],n+=r*f[o+1],q+=r*f[o+2],o-=h,r=a[p--],l+=r*f[o],n+=r*f[o+1],q+=r*f[o+2],o-=h;for(;p>=0;)r=a[p--],l+=r*f[o],n+=r*f[o+1],q+=r*f[o+2],o-=h}else for(p=0;p<j;p++)o=k+(p-b),o<0&&(o=0),o>=i&&(o=i-1),o=g+o*h,r=a[p],l+=r*f[o],n+=r* f[o+1],q+=r*f[o+2];p=d+k*e;c[p]=l;c[p+1]=n;c[p+2]=q}}; </script>

Alla artiklar i temat Hjärnkoll (10)

ur Lärarförbundets Magasin