diff --git a/README.md b/README.md index d853145..6e22c8b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ An html canvas implementation in pure JavaScript -**version: 0.9.92** (71 kB minified) +**version: 0.9.92r2** (71 kB minified) **Uses:** diff --git a/beeld.config b/beeld.config index 5e12152..b807755 100644 --- a/beeld.config +++ b/beeld.config @@ -34,7 +34,7 @@ tasks =[{}] header = ./src/header.js replace =[{}] - "@@VERSION@@" = "0.9.92" + "@@VERSION@@" = "0.9.92r2" "@@DATE@@" = Xpresion::date("Y-m-d H:i:s") @ diff --git a/build/CanvasLite.js b/build/CanvasLite.js index e61219e..0af3de5 100644 --- a/build/CanvasLite.js +++ b/build/CanvasLite.js @@ -2,14 +2,14 @@ * CanvasLite * an html canvas implementation in pure JavaScript * -* @version 0.9.92 (2023-07-31 22:54:20) +* @version 0.9.92r2 (2023-08-02 12:05:01) * https://github.com/foo123/CanvasLite * **//** * CanvasLite * an html canvas implementation in pure JavaScript * -* @version 0.9.92 (2023-07-31 22:54:20) +* @version 0.9.92r2 (2023-08-02 12:05:01) * https://github.com/foo123/CanvasLite * **/ @@ -277,7 +277,7 @@ function RenderingContext2D(width, height, set_rgba_at, get_rgba_from) set: function(c) { if (c instanceof Gradient || c instanceof Pattern) { - get_stroke_at = c.getColorAt.bind(c); + get_stroke_at = Rasterizer.getRGBAFrom(c.getColorAt.bind(c)); } else { @@ -292,7 +292,7 @@ function RenderingContext2D(width, height, set_rgba_at, get_rgba_from) set: function(c) { if (c instanceof Gradient || c instanceof Pattern) { - get_fill_at = c.getColorAt.bind(c); + get_fill_at = Rasterizer.getRGBAFrom(c.getColorAt.bind(c)); } else { @@ -6644,7 +6644,7 @@ function CanvasLite(width, height) }; self.toPNG = async function() { // only PNG output format - return await imagepng('binary', imageData.data, imageData.width, imageData.height/*, encoderOptions*/); + return await imagepng('binary', imageData.data, imageData.width, imageData.height/*, {deflateLevel: 0}*/); }; reset(); } @@ -6657,6 +6657,7 @@ CanvasLite[PROTO] = { toBlob: null, toPNG: null }; +CanvasLite.VERSION = "0.9.92r2"; CanvasLite.Image = Image; CanvasLite.RenderingContext2D = Rasterizer.RenderingContext2D; diff --git a/build/CanvasLite.min.js b/build/CanvasLite.min.js index 3a9abae..1247aeb 100644 --- a/build/CanvasLite.min.js +++ b/build/CanvasLite.min.js @@ -2,7 +2,7 @@ * CanvasLite * an html canvas implementation in pure JavaScript * -* @version 0.9.92 (2023-07-31 22:54:20) +* @version 0.9.92r2 (2023-08-02 12:05:01) * https://github.com/foo123/CanvasLite * -**/!function(e,n,t){"use strict";"object"==typeof module&&module.exports?module.exports=t.call(e):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return t.call(e)}):n in e||(e[n]=t.call(e)||1)&&"function"==typeof define&&define.amd&&define(function(){return e[n]})}("undefined"!=typeof self?self:this,"CanvasLite",function(e){"use strict";var n="prototype",P=Object.defineProperty,c=Object[n].hasOwnProperty,t=Object[n].toString,f="undefined"!=typeof global&&"[object global]"===t.call(global),o="undefined"!=typeof window&&"[object Window]"===t.call(window),Q=Math,q=1/0,r=Q.sqrt(2),A=isNaN,B=isFinite,d=Q.PI,x=2*d,l=6,p=r,m=.5,z="undefined"!=typeof Uint8ClampedArray?Uint8ClampedArray:"undefined"!=typeof Uint8Array?Uint8Array:Array,E=[0,0,0,0],a=/[MLHVCSQTAZ]/gi,S=/-?(?:(?:\d+\.\d+)|(?:\.\d+)|(?:\d+))/g;function F(n,e,t,r){var a,o=this;if(!(o instanceof F))return new F(n,e,t,r);r=r||(t&&t.$target?F.getRGBAFrom(t.$target):function(n,e){return E}),a=new G(n,e,t,r),P(o,"width",{get:function(){return n},set:function(n){}}),P(o,"height",{get:function(){return e},set:function(n){}}),o.getContext=function(n){if("2d"===n)return a;V('Unsupported context "'+n+'"')},o.dispose=function(){a&&a.dispose(),a=null}}function G(D,S,m,d){var o,i,e,t,g,v,r,a,l,u,s,c,f,h,p,C,y=this,b=null,w=null,x=function(){b={}},k=function(n){for(var e in b){var t=b[e],e=e.split(",");n(+e[0],+e[1],t)}b=null},L=function(n,e,t){var r;0<=n&&nI)I=Q.floor(f[1]);else{for(y=f[0],b=f[2],d=f[1],p=f[3],v=J(d,p)?(w=!1,g=Q.min(y,b),Q.max(y,b)):g=w=(b-y)*(I-d)/(p-d)+y,f[8]=w,f[9]=0,T[0]=f,s=A+(c=1);s=I&&(y=f[0],b=f[2],d=f[1],p=f[3],v=J(d,p)?(w=!1,g=Q.min(g,y,b),Q.max(v,y,b)):(w=(b-y)*(I-d)/(p-d)+y,g=Q.min(g,w),Q.max(v,w)),f[8]=w,f[9]=0,T[c++]=f);if(h=sn(T,c),!(ci.ymax)){for(var l,u,s,c,f,h,d,p,m,g,v,y,b,w=i.length,x=new Array(w),k=0,t="evenodd"===e;ko)){for(m=s[0],g=s[2],f=s[1],h=s[3],p=J(f,h)?(v=!1,d=Q.min(m,g),Q.max(m,g)):d=v=(g-m)*(o-f)/(h-f)+m,s[8]=v,s[9]=0,x[0]=s,l=k+(u=1);l=o&&(m=s[0],g=s[2],f=s[1],h=s[3],p=J(f,h)?(v=!1,d=Q.min(d,m,g),Q.max(p,m,g)):(v=(g-m)*(o-f)/(h-f)+m,d=Q.min(d,v),Q.max(p,v)),s[8]=v,s[9]=0,x[u++]=s);if(c=sn(x,u),us||Q.max(t,a,i)c)){if(ah)h=Q.floor(A[1]);else{for(m=-(p=q),t<=h&&h<=a&&(m=R?(p=Q.min(p,e,r),Q.max(m,e,r)):(p=Q.min(p,g=k*(h-t)/C+e),Q.max(m,g))),I=T;I=h&&(v=A[0],y=A[2],m=J(b=A[1],w=A[3])?(p=Q.min(p,v,y),Q.max(m,v,y)):(p=Q.min(p,g=(y-v)*(h-b)/(w-b)+v),Q.max(m,g)));for(p=Q.round(p+.5),m=Q.round(m-.5),U&&(p=Q.max(p,u),m=Q.min(m,c));p<=m;++p)n(p,h,1)}}}function X(n,e,t,r,a,o,i,l,u,s,c,f,h,d){var p=Q.min(e,r),m=Q.max(e,r),g=Q.min(t,a),v=Q.max(t,a);if(!(ma[t+3]?o.push([+a[t+2],a[t+3],+a[t],a[t+1],-1,s,c,c,0,0]):o.push([+a[t],a[t+1],+a[t+2],a[t+3],1,s,c,c,0,0]),++c;l=Q.min(l,a[1+e]),u=Q.max(u,a[1+e])}return(o=o.sort(y)).ymin=l,o.ymax=u,o}function sn(n,e){for(var t,r,a,o=0,i=0;i=n)return a;e[r=a+o>>>1][0]t[o][0]?(n-t[o][0])/(t[i][0]-t[o][0]):n)})},$.createRadialGradient=function(d,p,m,g,v,n){var y=(m=m||0)*m-2*m*(n=n||0)+n*n-(d=d||0)*d+2*d*(g=g||0)-g*g-(p=p||0)*p+2*p*(v=v||0)-v*v,b=-2*m*m+2*m*n+2*d*d-2*d*g+2*p*p-2*p*v,w=-d*d-p*p+m*m;return new $(function(n,e,t,r,a){var o,i,l,u,s,c,f,h=t.length;return u=b-2*n*d+2*n*g-2*e*p+2*e*v,s=w-n*n+2*n*d-e*e+2*e*p,(u=(s=J(l=y,0)?(f=s,!J(c=u,0)&&[-f/c]):Y(f=u*u-4*l*s,c=0,1e-6)?[-u/(2*l)]:!(f<0)&&(c=Q.sqrt(f),[(-u-c)/(2*l),(-u+c)/(2*l)]))?1t[o][0]?(u-t[o][0])/(t[i][0]-t[o][0]):u)})},$.createConicGradient=function(i,l,u){return i=i||0,l=l||0,u=u||0,new $(function(n,e,t,r,a){var o=t.length,e=Q.atan2(e-u,n-l)-i;return e<0&&(e+=x),xt[r][0]?(e-t[r][0])/(t[n][0]-t[r][0]):e)})},Z[n]={constructor:Z,transform:null,getColorAt:null,getBitmap:null},Z.createPattern=function(a,n){if(!((a=a&&"function"==typeof a.getImageData?a.getImageData():a)&&a.data&&a.width&&a.height&&a.data.length===4*a.width*a.height))throw new Error("Pattern: invalid image data");var o=a.width,i=a.height;switch(n){case"no-repeat":return new Z(function(n,e,t,r){return n=Q.round(n),e=Q.round(e),0<=n&&n>3)&1<<(7&a)&&(e|=1<=this.data.length)throw new Error("Attempted to read past end of stream.");return n instanceof Uint8Array?n[this.pos++]:255&n.charCodeAt(this.pos++)},e.readBytes=function(n){for(var e=[],t=0;t>--f&1;if(255==(l=e[t++])){var n=e[t++];if(n)throw"unexpected marker: "+(l<<8|n).toString(16)}return l>>>(f=7)}function d(n){for(var e,t=n;null!=(e=h());){if("number"==typeof(t=t[e]))return t;if("object"!=typeof t)throw"invalid huffman sequence"}return null}function p(n){for(var e=0;0>4;if(0==o){if(a<15){g=p(a)+(1<>4;if(0==l)y=a<15?(g=p(a)+(1<>4;if(0==o){if(a<15)break;r+=16}else e[Ln[r+=a]]=m(o),r++}},F=0,G=1==E?r[0].blocksPerLine*r[0].blocksPerColumn:i*n.mcusPerColumn;for(a=a||G;F>10,T[0+P]=b,T[1+P]=b,T[2+P]=b,T[3+P]=b,T[4+P]=b,T[5+P]=b,T[6+P]=b,T[7+P]=b):(f=K*T[0+P]+128>>8,h=K*T[4+P]+128>>8,d=T[2+P],p=T[6+P],m=2896*(T[1+P]-T[7+P])+128>>8,y=2896*(T[1+P]+T[7+P])+128>>8,g=T[3+P]<<4,b=f-h+1>>1,f=f+h+1>>1,h=b,b=3784*d+1567*p+128>>8,d=1567*d-3784*p+128>>8,p=b,b=m-(v=T[5+P]<<4)+1>>1,m=m+v+1>>1,v=b,b=y+g+1>>1,g=y-g+1>>1,y=b,b=f-p+1>>1,f=f+p+1>>1,p=b,b=h-d+1>>1,h=h+d+1>>1,d=b,b=2276*m+3406*y+2048>>12,m=3406*m-2276*y+2048>>12,y=b,b=799*g+4017*v+2048>>12,g=4017*g-799*v+2048>>12,v=b,T[0+P]=f+y,T[7+P]=f-y,T[1+P]=h+v,T[6+P]=h-v,T[2+P]=d+g,T[5+P]=d-g,T[3+P]=p+m,T[4+P]=p-m)}for(I=0;I<8;++I){var A=I;0==T[8+A]&&0==T[16+A]&&0==T[24+A]&&0==T[32+A]&&0==T[40+A]&&0==T[48+A]&&0==T[56+A]?(b=K*k[I+0]+8192>>14,T[0+A]=b,T[8+A]=b,T[16+A]=b,T[24+A]=b,T[32+A]=b,T[40+A]=b,T[48+A]=b,T[56+A]=b):(f=K*T[0+A]+2048>>12,h=K*T[32+A]+2048>>12,d=T[16+A],p=T[48+A],m=2896*(T[8+A]-T[56+A])+2048>>12,y=2896*(T[8+A]+T[56+A])+2048>>12,g=T[24+A],b=f-h+1>>1,f=f+h+1>>1,h=b,b=3784*d+1567*p+2048>>12,d=1567*d-3784*p+2048>>12,p=b,b=m-(v=T[40+A])+1>>1,m=m+v+1>>1,v=b,b=y+g+1>>1,g=y-g+1>>1,y=b,b=f-p+1>>1,f=f+p+1>>1,p=b,b=h-d+1>>1,h=h+d+1>>1,d=b,b=2276*m+3406*y+2048>>12,m=3406*m-2276*y+2048>>12,y=b,b=799*g+4017*v+2048>>12,g=4017*g-799*v+2048>>12,v=b,T[0+A]=f+y,T[56+A]=f-y,T[8+A]=h+v,T[48+A]=h-v,T[16+A]=d+g,T[40+A]=d-g,T[24+A]=p+m,T[32+A]=p-m)}for(I=0;I<64;++I){var B=128+(T[I]+8>>4);x[I]=B<0?0:255>4==0)for(E=0;E<64;++E)d[Ln[E]]=e[t++];else{if(h>>4!=1)throw"DQT: invalid table spec";for(E=0;E<64;++E)d[Ln[E]]=n()}l[15&h]=d}break;case 65472:case 65473:case 65474:n(),(r={}).extended=65473===f,r.progressive=65474===f,r.precision=e[t++],r.scanLines=n(),r.samplesPerLine=n(),r.components={},r.componentsOrder=[];var U=e[t++];for(z=0;z>4,_=15&e[t+1],O=e[t+2];r.componentsOrder.push(p),r.components[p]={h:q,v:_,quantizationIdx:O},t+=3}D=B=A=P=I=T=C=k=w=b=m=x=y=v=g=void 0;var m,g=r,v=0,y=0;for(m in g.components)g.components.hasOwnProperty(m)&&(v<(x=g.components[m]).h&&(v=x.h),y>4==0?c:s)[15&X]=function(n,e){for(var t,r=0,a=[],o=16;0>4],G.huffmanTableAC=s[15&H],j.push(G)}var L=e[t++],V=e[t++],W=e[t++],V=En(e,t,r,j,a,L,V,W>>4,15&W);t+=V;break;default:if(255==e[t-3]&&192<=e[t-2]&&e[t-2]<=254){t-=3;break}throw"unknown JPEG marker "+f.toString(16)}f=n()}if(1!=u.length)throw"only single frame JPEGs supported";for(var z=0;zf.data.length)throw new Error("Incomplete or corrupt PNG file")}},decodePixels:async function(n){var e,t,r,a,o,i,l,u,s,c,f,h,d,p,m,g,v,y,b,w,x,k,C,T;if(0===(n=null==n?this.imgData:n).length)return new Uint8Array(0);for(k=n,T={chunkSize:null==C?16384:C},n=await new Promise(function(t){require("zlib").inflate(k instanceof Buffer?k:Buffer.from(k),T,function(n,e){t(n?null:e)})}),p=(c=this.pixelBitlength/8)*this.width,f=new Uint8Array(p*this.height),i=n.length,t=h=d=0;h>1);r[a+i]=255&l}}function Qn(n,e,t,r){for(var a=0,o=0;o>1);a+=Q.abs(i)}return a}function $n(n,e,t,r,a,o){for(var i=0;i>>1:t>>>1;Kn[n]=t}return Kn}(),t=-1,r=0,a=n.length;r>>8;return-1^t}function ee(n,e=null,t=0){(e=null==e?Buffer.alloc(1):e)[t=null==t?0:t]=255&n}function te(n,e=null,t=0){return(e=null==e?Buffer.alloc(4):e).writeUInt32BE(4294967295&n,t=null==t?0:t),e}function re(n){if((n=n||{}).deflateChunkSize=Q.max(1024,parseInt(n.deflateChunkSize||32768)),n.deflateLevel=Q.min(9,Q.max(0,parseInt(null!=n.deflateLevel?n.deflateLevel:9))),n.deflateStrategy=Q.min(3,Q.max(0,parseInt(null!=n.deflateStrategy?n.deflateStrategy:3))),n.inputHasAlpha=!(null!=n.inputHasAlpha&&!n.inputHasAlpha),n.bitDepth=8,n.colorType=Q.min(6,Q.max(0,parseInt("number"==typeof n.colorType?n.colorType:On))),n.colorType!==_n&&n.colorType!==On)throw new Error("option color type:"+n.colorType+" is not supported at present");this._options=n}async function ae(n,e,t,r,a){return a=a||{},"base64"!==n?new re(a).toPNG(e,t,r):f?"data:image/png;base64,"+(await new re(a).toPNG(e,t,r)).toString("base64"):o?(a=(n=document.createElement("canvas")).getContext("2d"),n.width=t,n.height=r,a.createImageData(t,r),(t=a.getImageData(0,0,t,r)).data.set(e,0),a.putImageData(t,0,0),n.toDataURL("image/png")):""}function u(){var t=this,e="",r=0,a=0,o=null,i=function(n){if(!n instanceof Error&&(n=new Error(String(n))),!t.onerror)throw n;t.onerror(n)},l=function(n){var e;if(n)return(e=u.Reader[u.detectImageType(n)])?void e(n).then(function(n){r=(o=n).width,a=n.height,t.onload&&t.onload()}).catch(i):i("Image file type is not supported!")};P(t,"width",{get:function(){return r},set:function(n){}}),P(t,"height",{get:function(){return a},set:function(n){}}),P(t,"naturalWidth",{get:function(){return r},set:function(n){}}),P(t,"naturalHeight",{get:function(){return a},set:function(n){}}),P(t,"src",{get:function(){return e},set:function(n){"undefined"!=typeof ArrayBuffer&&n instanceof ArrayBuffer||"undefined"!=typeof Buffer&&n instanceof Buffer?l(e=n):"undefined"!=typeof Blob&&n instanceof Blob||"undefined"!=typeof Buffer&&Buffer.Blob&&n instanceof Buffer.Blob?(e=n).arrayBuffer().then(l).catch(i):("string"==typeof n||n instanceof String)&&(/^data:image\/[a-z]+;base64,/.test(n)?l(function(n){if("undefined"!=typeof Buffer)return Buffer.from(n,"base64");if("function"==typeof atob){for(var e=atob(n),t=e.length,r=new Uint8Array(t),a=0;aI)I=Q.floor(f[1]);else{for(y=f[0],b=f[2],d=f[1],p=f[3],v=J(d,p)?(w=!1,g=Q.min(y,b),Q.max(y,b)):g=w=(b-y)*(I-d)/(p-d)+y,f[8]=w,f[9]=0,T[0]=f,s=A+(c=1);s=I&&(y=f[0],b=f[2],d=f[1],p=f[3],v=J(d,p)?(w=!1,g=Q.min(g,y,b),Q.max(v,y,b)):(w=(b-y)*(I-d)/(p-d)+y,g=Q.min(g,w),Q.max(v,w)),f[8]=w,f[9]=0,T[c++]=f);if(h=sn(T,c),!(ci.ymax)){for(var l,u,s,c,f,h,d,p,m,g,v,y,b,w=i.length,x=new Array(w),k=0,t="evenodd"===e;ko)){for(m=s[0],g=s[2],f=s[1],h=s[3],p=J(f,h)?(v=!1,d=Q.min(m,g),Q.max(m,g)):d=v=(g-m)*(o-f)/(h-f)+m,s[8]=v,s[9]=0,x[0]=s,l=k+(u=1);l=o&&(m=s[0],g=s[2],f=s[1],h=s[3],p=J(f,h)?(v=!1,d=Q.min(d,m,g),Q.max(p,m,g)):(v=(g-m)*(o-f)/(h-f)+m,d=Q.min(d,v),Q.max(p,v)),s[8]=v,s[9]=0,x[u++]=s);if(c=sn(x,u),us||Q.max(t,a,i)c)){if(ah)h=Q.floor(A[1]);else{for(m=-(p=q),t<=h&&h<=a&&(m=R?(p=Q.min(p,e,r),Q.max(m,e,r)):(p=Q.min(p,g=k*(h-t)/C+e),Q.max(m,g))),I=T;I=h&&(v=A[0],y=A[2],m=J(b=A[1],w=A[3])?(p=Q.min(p,v,y),Q.max(m,v,y)):(p=Q.min(p,g=(y-v)*(h-b)/(w-b)+v),Q.max(m,g)));for(p=Q.round(p+.5),m=Q.round(m-.5),U&&(p=Q.max(p,u),m=Q.min(m,c));p<=m;++p)n(p,h,1)}}}function X(n,e,t,r,a,o,i,l,u,s,c,f,h,d){var p=Q.min(e,r),m=Q.max(e,r),g=Q.min(t,a),v=Q.max(t,a);if(!(ma[t+3]?o.push([+a[t+2],a[t+3],+a[t],a[t+1],-1,s,c,c,0,0]):o.push([+a[t],a[t+1],+a[t+2],a[t+3],1,s,c,c,0,0]),++c;l=Q.min(l,a[1+e]),u=Q.max(u,a[1+e])}return(o=o.sort(y)).ymin=l,o.ymax=u,o}function sn(n,e){for(var t,r,a,o=0,i=0;i=n)return a;e[r=a+o>>>1][0]t[o][0]?(n-t[o][0])/(t[i][0]-t[o][0]):n)})},$.createRadialGradient=function(d,p,m,g,v,n){var y=(m=m||0)*m-2*m*(n=n||0)+n*n-(d=d||0)*d+2*d*(g=g||0)-g*g-(p=p||0)*p+2*p*(v=v||0)-v*v,b=-2*m*m+2*m*n+2*d*d-2*d*g+2*p*p-2*p*v,w=-d*d-p*p+m*m;return new $(function(n,e,t,r,a){var o,i,l,u,s,c,f,h=t.length;return u=b-2*n*d+2*n*g-2*e*p+2*e*v,s=w-n*n+2*n*d-e*e+2*e*p,(u=(s=J(l=y,0)?(f=s,!J(c=u,0)&&[-f/c]):Y(f=u*u-4*l*s,c=0,1e-6)?[-u/(2*l)]:!(f<0)&&(c=Q.sqrt(f),[(-u-c)/(2*l),(-u+c)/(2*l)]))?1t[o][0]?(u-t[o][0])/(t[i][0]-t[o][0]):u)})},$.createConicGradient=function(i,l,u){return i=i||0,l=l||0,u=u||0,new $(function(n,e,t,r,a){var o=t.length,e=Q.atan2(e-u,n-l)-i;return e<0&&(e+=x),xt[r][0]?(e-t[r][0])/(t[n][0]-t[r][0]):e)})},Z[n]={constructor:Z,transform:null,getColorAt:null,getBitmap:null},Z.createPattern=function(a,n){if(!((a=a&&"function"==typeof a.getImageData?a.getImageData():a)&&a.data&&a.width&&a.height&&a.data.length===4*a.width*a.height))throw new Error("Pattern: invalid image data");var o=a.width,i=a.height;switch(n){case"no-repeat":return new Z(function(n,e,t,r){return n=Q.round(n),e=Q.round(e),0<=n&&n>3)&1<<(7&a)&&(e|=1<=this.data.length)throw new Error("Attempted to read past end of stream.");return n instanceof Uint8Array?n[this.pos++]:255&n.charCodeAt(this.pos++)},e.readBytes=function(n){for(var e=[],t=0;t>--f&1;if(255==(l=e[t++])){var n=e[t++];if(n)throw"unexpected marker: "+(l<<8|n).toString(16)}return l>>>(f=7)}function d(n){for(var e,t=n;null!=(e=h());){if("number"==typeof(t=t[e]))return t;if("object"!=typeof t)throw"invalid huffman sequence"}return null}function p(n){for(var e=0;0>4;if(0==o){if(a<15){g=p(a)+(1<>4;if(0==l)y=a<15?(g=p(a)+(1<>4;if(0==o){if(a<15)break;r+=16}else e[Ln[r+=a]]=m(o),r++}},F=0,G=1==z?r[0].blocksPerLine*r[0].blocksPerColumn:i*n.mcusPerColumn;for(a=a||G;F>10,T[0+P]=b,T[1+P]=b,T[2+P]=b,T[3+P]=b,T[4+P]=b,T[5+P]=b,T[6+P]=b,T[7+P]=b):(f=K*T[0+P]+128>>8,h=K*T[4+P]+128>>8,d=T[2+P],p=T[6+P],m=2896*(T[1+P]-T[7+P])+128>>8,y=2896*(T[1+P]+T[7+P])+128>>8,g=T[3+P]<<4,b=f-h+1>>1,f=f+h+1>>1,h=b,b=3784*d+1567*p+128>>8,d=1567*d-3784*p+128>>8,p=b,b=m-(v=T[5+P]<<4)+1>>1,m=m+v+1>>1,v=b,b=y+g+1>>1,g=y-g+1>>1,y=b,b=f-p+1>>1,f=f+p+1>>1,p=b,b=h-d+1>>1,h=h+d+1>>1,d=b,b=2276*m+3406*y+2048>>12,m=3406*m-2276*y+2048>>12,y=b,b=799*g+4017*v+2048>>12,g=4017*g-799*v+2048>>12,v=b,T[0+P]=f+y,T[7+P]=f-y,T[1+P]=h+v,T[6+P]=h-v,T[2+P]=d+g,T[5+P]=d-g,T[3+P]=p+m,T[4+P]=p-m)}for(I=0;I<8;++I){var A=I;0==T[8+A]&&0==T[16+A]&&0==T[24+A]&&0==T[32+A]&&0==T[40+A]&&0==T[48+A]&&0==T[56+A]?(b=K*k[I+0]+8192>>14,T[0+A]=b,T[8+A]=b,T[16+A]=b,T[24+A]=b,T[32+A]=b,T[40+A]=b,T[48+A]=b,T[56+A]=b):(f=K*T[0+A]+2048>>12,h=K*T[32+A]+2048>>12,d=T[16+A],p=T[48+A],m=2896*(T[8+A]-T[56+A])+2048>>12,y=2896*(T[8+A]+T[56+A])+2048>>12,g=T[24+A],b=f-h+1>>1,f=f+h+1>>1,h=b,b=3784*d+1567*p+2048>>12,d=1567*d-3784*p+2048>>12,p=b,b=m-(v=T[40+A])+1>>1,m=m+v+1>>1,v=b,b=y+g+1>>1,g=y-g+1>>1,y=b,b=f-p+1>>1,f=f+p+1>>1,p=b,b=h-d+1>>1,h=h+d+1>>1,d=b,b=2276*m+3406*y+2048>>12,m=3406*m-2276*y+2048>>12,y=b,b=799*g+4017*v+2048>>12,g=4017*g-799*v+2048>>12,v=b,T[0+A]=f+y,T[56+A]=f-y,T[8+A]=h+v,T[48+A]=h-v,T[16+A]=d+g,T[40+A]=d-g,T[24+A]=p+m,T[32+A]=p-m)}for(I=0;I<64;++I){var B=128+(T[I]+8>>4);x[I]=B<0?0:255>4==0)for(z=0;z<64;++z)d[Ln[z]]=e[t++];else{if(h>>4!=1)throw"DQT: invalid table spec";for(z=0;z<64;++z)d[Ln[z]]=n()}l[15&h]=d}break;case 65472:case 65473:case 65474:n(),(r={}).extended=65473===f,r.progressive=65474===f,r.precision=e[t++],r.scanLines=n(),r.samplesPerLine=n(),r.components={},r.componentsOrder=[];var U=e[t++];for(E=0;E>4,O=15&e[t+1],_=e[t+2];r.componentsOrder.push(p),r.components[p]={h:q,v:O,quantizationIdx:_},t+=3}D=B=A=P=I=T=C=k=w=b=m=x=y=v=g=void 0;var m,g=r,v=0,y=0;for(m in g.components)g.components.hasOwnProperty(m)&&(v<(x=g.components[m]).h&&(v=x.h),y>4==0?c:s)[15&X]=function(n,e){for(var t,r=0,a=[],o=16;0>4],G.huffmanTableAC=s[15&H],j.push(G)}var L=e[t++],V=e[t++],W=e[t++],V=zn(e,t,r,j,a,L,V,W>>4,15&W);t+=V;break;default:if(255==e[t-3]&&192<=e[t-2]&&e[t-2]<=254){t-=3;break}throw"unknown JPEG marker "+f.toString(16)}f=n()}if(1!=u.length)throw"only single frame JPEGs supported";for(var E=0;Ef.data.length)throw new Error("Incomplete or corrupt PNG file")}},decodePixels:async function(n){var e,t,r,a,o,i,l,u,s,c,f,h,d,p,m,g,v,y,b,w,x,k,C,T;if(0===(n=null==n?this.imgData:n).length)return new Uint8Array(0);for(k=n,T={chunkSize:null==C?16384:C},n=await new Promise(function(t){require("zlib").inflate(k instanceof Buffer?k:Buffer.from(k),T,function(n,e){t(n?null:e)})}),p=(c=this.pixelBitlength/8)*this.width,f=new Uint8Array(p*this.height),i=n.length,t=h=d=0;h>1);r[a+i]=255&l}}function Qn(n,e,t,r){for(var a=0,o=0;o>1);a+=Q.abs(i)}return a}function $n(n,e,t,r,a,o){for(var i=0;i>>1:t>>>1;Kn[n]=t}return Kn}(),t=-1,r=0,a=n.length;r>>8;return-1^t}function ee(n,e=null,t=0){(e=null==e?Buffer.alloc(1):e)[t=null==t?0:t]=255&n}function te(n,e=null,t=0){return(e=null==e?Buffer.alloc(4):e).writeUInt32BE(4294967295&n,t=null==t?0:t),e}function re(n){if((n=n||{}).deflateChunkSize=Q.max(1024,parseInt(n.deflateChunkSize||32768)),n.deflateLevel=Q.min(9,Q.max(0,parseInt(null!=n.deflateLevel?n.deflateLevel:9))),n.deflateStrategy=Q.min(3,Q.max(0,parseInt(null!=n.deflateStrategy?n.deflateStrategy:3))),n.inputHasAlpha=!(null!=n.inputHasAlpha&&!n.inputHasAlpha),n.bitDepth=8,n.colorType=Q.min(6,Q.max(0,parseInt("number"==typeof n.colorType?n.colorType:_n))),n.colorType!==On&&n.colorType!==_n)throw new Error("option color type:"+n.colorType+" is not supported at present");this._options=n}async function ae(n,e,t,r,a){return a=a||{},"base64"!==n?new re(a).toPNG(e,t,r):f?"data:image/png;base64,"+(await new re(a).toPNG(e,t,r)).toString("base64"):o?(a=(n=document.createElement("canvas")).getContext("2d"),n.width=t,n.height=r,a.createImageData(t,r),(t=a.getImageData(0,0,t,r)).data.set(e,0),a.putImageData(t,0,0),n.toDataURL("image/png")):""}function u(){var t=this,e="",r=0,a=0,o=null,i=function(n){if(!n instanceof Error&&(n=new Error(String(n))),!t.onerror)throw n;t.onerror(n)},l=function(n){var e;if(n)return(e=u.Reader[u.detectImageType(n)])?void e(n).then(function(n){r=(o=n).width,a=n.height,t.onload&&t.onload()}).catch(i):i("Image file type is not supported!")};P(t,"width",{get:function(){return r},set:function(n){}}),P(t,"height",{get:function(){return a},set:function(n){}}),P(t,"naturalWidth",{get:function(){return r},set:function(n){}}),P(t,"naturalHeight",{get:function(){return a},set:function(n){}}),P(t,"src",{get:function(){return e},set:function(n){"undefined"!=typeof ArrayBuffer&&n instanceof ArrayBuffer||"undefined"!=typeof Buffer&&n instanceof Buffer?l(e=n):"undefined"!=typeof Blob&&n instanceof Blob||"undefined"!=typeof Buffer&&Buffer.Blob&&n instanceof Buffer.Blob?(e=n).arrayBuffer().then(l).catch(i):("string"==typeof n||n instanceof String)&&(/^data:image\/[a-z]+;base64,/.test(n)?l(function(n){if("undefined"!=typeof Buffer)return Buffer.from(n,"base64");if("function"==typeof atob){for(var e=atob(n),t=e.length,r=new Uint8Array(t),a=0;a