From cd1917c66d6f812b7973928aa4efe24c3ee848ed Mon Sep 17 00:00:00 2001 From: Vilius Date: Fri, 11 Aug 2017 20:12:35 +0300 Subject: [PATCH] #6 - fixed on_finish param handling - it must be optional --- dist/hermite.js | 4 ++-- src/hermite.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dist/hermite.js b/dist/hermite.js index 7a6cfe4..f0f3ccd 100644 --- a/dist/hermite.js +++ b/dist/hermite.js @@ -1,6 +1,6 @@ //Hermite resize - fast image resize/resample using Hermite filter. -//Version: 2.2 +//Version: 2.2.1 //Author: ViliusL //https://github.com/viliusle/Hermite-resize //http://viliusle.github.io/miniPaint/ -function Hermite_class(){var a,c,b=[];this.init=function(){a=navigator.hardwareConcurrency||4}(),this.getCores=function(){return a},this.resample_auto=function(a,b,c,d,e){var f=this.getCores();window.Worker&&f>1?this.resample(a,b,c,d,e):(this.resample_single(a,b,c,!0),e())},this.resize_image=function(a,b,c,d,e){var f=document.getElementById(a),g=document.createElement("canvas");g.width=f.width,g.height=f.height;var h=g.getContext("2d");if(h.drawImage(f,0,0),void 0==b&&void 0==c&&void 0!=d&&(b=f.width/100*d,c=f.height/100*d),void 0==c){var i=f.width/b;c=f.height/i}b=Math.round(b),c=Math.round(c);var j=function(){var a=g.toDataURL();f.width=b,f.height=c,f.src=a,delete a,delete g};void 0==e||1==e?this.resample(g,b,c,!0,j):(this.resample_single(g,b,c,!0),j())},this.resample=function(d,e,f,g,h){var i=d.width,j=d.height;e=Math.round(e),f=Math.round(f);var k=j/f;if(b.length>0)for(var l=0;lj)){p=q+o-1,p=Math.min(p,j-1);var r=o;r=Math.min(o,j-q),n[l]={},n[l].source=m.getImageData(0,q,i,o),n[l].target=!0,n[l].start_y=Math.ceil(q/k),n[l].height=r}}g===!0?(d.width=e,d.height=f):m.clearRect(0,0,i,j);for(var s=0,l=0;l=1)){s=2*K*K*K-3*K*K+1;var L=4*(I+E*c);y+=s*k[L+3],u+=s,k[L+3]<255&&(s=s*k[L+3]/250),v+=s*k[L],w+=s*k[L+1],x+=s*k[L+2],t+=s}}o[r]=v/t,o[r+1]=w/t,o[r+2]=x/t,o[r+3]=y/u}var M={core:b,target:o};postMessage(M,[o.buffer])}}.toString(),")()"],{type:"application/javascript"})),this.resample_single=function(a,b,c,d){var e=a.width,f=a.height;b=Math.round(b),c=Math.round(c);for(var g=e/b,h=f/c,i=Math.ceil(g/2),j=Math.ceil(h/2),k=a.getContext("2d"),l=k.getImageData(0,0,e,f),m=k.createImageData(b,c),n=l.data,o=m.data,p=0;p=1)){s=2*K*K*K-3*K*K+1;var L=4*(I+E*e);y+=s*n[L+3],u+=s,n[L+3]<255&&(s=s*n[L+3]/250),v+=s*n[L],w+=s*n[L+1],x+=s*n[L+2],t+=s}}o[r]=v/t,o[r+1]=w/t,o[r+2]=x/t,o[r+3]=y/u}d===!0?(a.width=b,a.height=c):k.clearRect(0,0,e,f),k.putImageData(m,0,0)}} \ No newline at end of file +function Hermite_class(){var t,a,e=[];this.init=void(t=navigator.hardwareConcurrency||4),this.getCores=function(){return t},this.resample_auto=function(t,a,e,r,i){var h=this.getCores();window.Worker&&h>1?this.resample(t,a,e,r,i):(this.resample_single(t,a,e,!0),void 0!=i&&i())},this.resize_image=function(t,a,e,r,i){var h=document.getElementById(t),o=document.createElement("canvas");if(o.width=h.width,o.height=h.height,o.getContext("2d").drawImage(h,0,0),void 0==a&&void 0==e&&void 0!=r&&(a=h.width/100*r,e=h.height/100*r),void 0==e){var n=h.width/a;e=h.height/n}a=Math.round(a),e=Math.round(e);var s=function(){var t=o.toDataURL();h.width=a,h.height=e,h.src=t,delete t,delete o};void 0==i||1==i?this.resample(o,a,e,!0,s):(this.resample_single(o,a,e,!0),s())},this.resample=function(r,i,h,o,n){var s=r.width,d=r.height;i=Math.round(i);var c=d/(h=Math.round(h));if(e.length>0)for(M=0;Md)){f=u+l-1,f=Math.min(f,d-1);var m=l;m=Math.min(l,d-u),v[M]={},v[M].source=g.getImageData(0,u,s,l),v[M].target=!0,v[M].start_y=Math.ceil(u/c),v[M].height=m}}!0===o?(r.width=i,r.height=h):g.clearRect(0,0,s,d);for(var w=0,M=0;M=1)){var W=4*(k+x*e);C+=(m=2*E*E*E-3*E*E+1)*c[W+3],p+=m,c[W+3]<255&&(m=m*c[W+3]/250),_+=m*c[W],y+=m*c[W+1],b+=m*c[W+2],w+=m}}l[u]=_/w,l[u+1]=y/w,l[u+2]=b/w,l[u+3]=C/p}var z={core:a,target:l};postMessage(z,[l.buffer])}}.toString(),")()"],{type:"application/javascript"})),this.resample_single=function(t,a,e,r){for(var i=t.width,h=t.height,o=i/(a=Math.round(a)),n=h/(e=Math.round(e)),s=Math.ceil(o/2),d=Math.ceil(n/2),c=t.getContext("2d"),g=c.getImageData(0,0,i,h),v=c.createImageData(a,e),l=g.data,f=v.data,M=0;M=1)){var z=4*(q+B*i);I+=(w=2*W*W*W-3*W*W+1)*l[z+3],_+=w,l[z+3]<255&&(w=w*l[z+3]/250),y+=w*l[z],b+=w*l[z+1],C+=w*l[z+2],p+=w}}f[m]=y/p,f[m+1]=b/p,f[m+2]=C/p,f[m+3]=I/_}!0===r?(t.width=a,t.height=e):c.clearRect(0,0,i,h),c.putImageData(v,0,0)}} diff --git a/src/hermite.js b/src/hermite.js index 3340eb9..85feeed 100644 --- a/src/hermite.js +++ b/src/hermite.js @@ -1,6 +1,6 @@ /* * Hermite resize - fast image resize/resample using Hermite filter. - * Version: 2.2 + * Version: 2.2.1 * Author: ViliusL * demo: http://viliusle.github.io/miniPaint/ */ @@ -43,7 +43,9 @@ function Hermite_class() { } else { //1 cpu version this.resample_single(canvas, width, height, true); - on_finish(); + if(on_finish != undefined) { + on_finish(); + } } }; @@ -188,7 +190,9 @@ function Hermite_class() { if (workers_in_use <= 0) { //finish - on_finish(); + if(on_finish != undefined) { + on_finish(); + } } }; var objData = {