(path)
| 23 | harvestFlatFaces: true, harvestTol: 0.005, snapSeamlessWrap: true, |
| 24 | cylinderCenterX: null, cylinderCenterY: null, cylinderRadius: null, |
| 25 | regularizeEnabled: true, regularizeAspectThreshold: 5, regularizeSlack: 3.0, |
| 26 | regularizeAggressiveSlack: 8.0, regularizeExtremeAspect: 8, |
| 27 | regularizeNormalDeg: 15, regularizeAggressiveNormalDeg: 25, regularizeSecondPassMul: 1.1, |
| 28 | }; |
| 29 | const _regOpts = () => ({ aspectThreshold: settings.regularizeAspectThreshold, slack: settings.regularizeSlack, aggressiveSlack: settings.regularizeAggressiveSlack, extremeSliverAspect: settings.regularizeExtremeAspect, maxNormalDeltaCos: Math.cos(settings.regularizeNormalDeg*Math.PI/180), aggressiveNormalDeltaCos: Math.cos(settings.regularizeAggressiveNormalDeg*Math.PI/180) }); |
| 30 | |
| 31 | function decodePNG(path){ |
| 32 | const d=readFileSync(path);let p=8;const idat=[];let w,h,ct,bd; |
| 33 | while(p<d.length){const len=d.readUInt32BE(p);const type=d.toString('ascii',p+4,p+8);const s=p+8; |
| 34 | if(type==='IHDR'){w=d.readUInt32BE(s);h=d.readUInt32BE(s+4);bd=d[s+8];ct=d[s+9];} |
| 35 | else if(type==='IDAT')idat.push(d.subarray(s,s+len)); else if(type==='IEND')break; p=s+len+4;} |
| 36 | const ch=ct===0?1:ct===2?3:ct===4?2:ct===6?4:null; |
| 37 | const raw=unzlibSync(Buffer.concat(idat));const stride=w*ch;const out=new Uint8ClampedArray(w*h*4); |
| 38 | const cur=new Uint8Array(stride),prev=new Uint8Array(stride);let rp=0; |
| 39 | const pa=(a,b,c)=>{const pp=a+b-c,pA=Math.abs(pp-a),pB=Math.abs(pp-b),pC=Math.abs(pp-c);return pA<=pB&&pA<=pC?a:pB<=pC?b:c;}; |
| 40 | for(let y=0;y<h;y++){const f=raw[rp++];for(let x=0;x<stride;x++){const rw=raw[rp++];const A=x>=ch?cur[x-ch]:0;const B=prev[x];const C=x>=ch?prev[x-ch]:0;let v;switch(f){case 0:v=rw;break;case 1:v=rw+A;break;case 2:v=rw+B;break;case 3:v=rw+((A+B)>>1);break;case 4:v=rw+pa(A,B,C);break;}cur[x]=v&255;} |
| 41 | for(let x=0;x<w;x++){const si=x*ch,di=(y*w+x)*4;let r,g,b,al;if(ch===1){r=g=b=cur[si];al=255;}else if(ch===2){r=g=b=cur[si];al=cur[si+1];}else if(ch===3){r=cur[si];g=cur[si+1];b=cur[si+2];al=255;}else{r=cur[si];g=cur[si+1];b=cur[si+2];al=cur[si+3];}out[di]=r;out[di+1]=g;out[di+2]=b;out[di+3]=al;} |
no test coverage detected