'use strict';Object.defineProperty(exports,'__esModule',{value:true});function g(n,r,t,e,o,{threshold:f=.1,alpha:c=.1,aaColor:s=[255,255,0],diffColor:a=[255,0,0],includeAA:U,diffColorAlt:O,diffMask:b,fastBufferCheck:y=true}={}){if(!_(n)||!_(r)||t&&!_(t))throw new Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");if(n.length!==r.length||t&&t.length!==n.length)throw new Error(`Image sizes do not match. Image 1 size: ${n.length}, image 2 size: ${r.length}`);if(n.length!==e*o*4)throw new Error(`Image data size does not match width/height. Expecting ${e*o*4}. Got ${n.length}`);if(y&&typeof Buffer<"u"&&Buffer.compare&&n instanceof Uint8Array&&r instanceof Uint8Array&&Buffer.compare(n,r)===0){if(t&&!b)for(let A=0;A<e*o;A++)L(n,A*4,c,t);return 0}let m=e*o,u=new Uint32Array(n.buffer,n.byteOffset,m),d=new Uint32Array(r.buffer,r.byteOffset,m),l=tn(e,o),i=Math.ceil(e/l),I=Math.ceil(o/l),z=i*I,x=new Uint16Array(z),M=35215*f*f,B=0;for(let A=0;A<I;A++)for(let R=0;R<i;R++){let p=R*l,v=A*l,D=Math.min(p+l,e),P=Math.min(v+l,o),$=false;n:for(let C=v;C<P;C++){let Y=C*e;for(let G=p;G<D;G++){let E=Y+G;if(u[E]===d[E])continue;let S=E*4,X=N(n,r,S,S);if(Math.abs(X)>M){$=true;break n}}}if($)x[B++]=A*i+R;else if(t&&!b)for(let C=v;C<P;C++){let Y=C*e;for(let G=p;G<D;G++){let E=Y+G;L(n,E*4,c,t);}}}if(B===0)return 0;let[F,J,K]=s,[Q,W,Z]=a,[k,w,h]=O||a,T=0;for(let A=0;A<B;A++){let R=x[A],p=R%i,v=R/i|0,D=p*l,P=v*l,$=Math.min(D+l,e),C=Math.min(P+l,o);for(let Y=P;Y<C;Y++){let G=Y*e;for(let E=D;E<$;E++){let S=G+E,X=S*4;if(u[S]===d[S]){t&&!b&&L(n,X,c,t);continue}let H=N(n,r,X,X);Math.abs(H)>M?!U&&(j(n,E,Y,e,o,u,d)||j(r,E,Y,e,o,d,u))?t&&!b&&V(t,X,F,J,K):(t&&(H<0?V(t,X,k,w,h):V(t,X,Q,W,Z)),T++):t&&!b&&L(n,X,c,t);}}}return T}function _(n){return ArrayBuffer.isView(n)&&n.BYTES_PER_ELEMENT===1}var nn=Math.LOG2E;function tn(n,r){let t=n*r,e=Math.sqrt(t)/100,o=16*Math.sqrt(e),f=Math.log(o)*nn;return 1<<Math.round(f)}function N(n,r,t,e){let o=n[t],f=n[t+1],c=n[t+2],s=n[t+3],a=r[e],U=r[e+1],O=r[e+2],b=r[e+3],y=o-a,m=f-U,u=c-O,d=s-b;if(!y&&!m&&!u&&!d)return 0;if(s<255||b<255){let x=48+159*(t%2),M=48+159*((t/1.618033988749895|0)&1),B=48+159*((t/2.618033988749895|0)&1);y=(o*s-a*b-x*d)/255,m=(f*s-U*b-M*d)/255,u=(c*s-O*b-B*d)/255;}let l=y*.29889531+m*.58662247+u*.11448223,i=y*.59597799-m*.2741761-u*.32180189,I=y*.21147017-m*.52261711+u*.31114694,z=.5053*l*l+.299*i*i+.1957*I*I;return l>0?-z:z}function rn(n,r,t,e){let o=n[t],f=n[t+1],c=n[t+2],s=n[t+3],a=r[e],U=r[e+1],O=r[e+2],b=r[e+3],y=o-a,m=f-U,u=c-O,d=s-b;if(!y&&!m&&!u&&!d)return 0;if(s<255||b<255){let i=48+159*(t%2),I=48+159*((t/1.618033988749895|0)&1),z=48+159*((t/2.618033988749895|0)&1);y=(o*s-a*b-i*d)/255,m=(f*s-U*b-I*d)/255,u=(c*s-O*b-z*d)/255;}return y*.29889531+m*.58662247+u*.11448223}function j(n,r,t,e,o,f,c){let s=Math.max(r-1,0),a=Math.max(t-1,0),U=Math.min(r+1,e-1),O=Math.min(t+1,o-1),y=(t*e+r)*4,m=r===s||r===U||t===a||t===O?1:0,u=0,d=0,l=0,i=0,I=0,z=0;for(let x=s;x<=U;x++)for(let M=a;M<=O;M++){if(x===r&&M===t)continue;let B=rn(n,n,y,(M*e+x)*4);if(B===0){if(m++,m>2)return  false}else B<u?(u=B,l=x,i=M):B>d&&(d=B,I=x,z=M);}return u===0||d===0?false:q(f,l,i,e,o)&&q(c,l,i,e,o)||q(f,I,z,e,o)&&q(c,I,z,e,o)}function q(n,r,t,e,o){let f=t*e+r,c=n[f],s=r===0||r===e-1||t===0||t===o-1?1:0;if(t>0){let a=f-e;r>0&&n[a-1]===c&&s++,n[a]===c&&s++,r<e-1&&n[a+1]===c&&s++;}if(r>0&&n[f-1]===c&&s++,r<e-1&&n[f+1]===c&&s++,t<o-1){let a=f+e;r>0&&n[a-1]===c&&s++,n[a]===c&&s++,r<e-1&&n[a+1]===c&&s++;}return s>2}function L(n,r,t,e){let o=255+(n[r]*.29889531+n[r+1]*.58662247+n[r+2]*.11448223-255)*t*n[r+3]/255;V(e,r,o,o,o);}function V(n,r,t,e,o){n[r+0]=t,n[r+1]=e,n[r+2]=o,n[r+3]=255;}var on=g;exports.antialiased=j;exports.brightnessDelta=rn;exports.calculateOptimalBlockSize=tn;exports.colorDelta=N;exports.default=on;exports.diff=g;exports.drawGrayPixel=L;exports.drawPixel=V;exports.isValidImage=_;