From ddab4dc3a1ff644841229f249acc793bbd5cf82d Mon Sep 17 00:00:00 2001 From: Jens Ochsenmeier Date: Thu, 28 Mar 2024 08:43:22 +0100 Subject: [PATCH 1/3] compile as es module --- .gitignore | 1 + release/lossless-min.js | 2 +- release/lossless.js | 35 +++-------------------------------- tsup.config.ts | 4 ++++ 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 52fe5d1..2afa2cf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules/ release.sh .DS_Store *.d.cts +*.d.ts *.js.map \ No newline at end of file diff --git a/release/lossless-min.js b/release/lossless-min.js index 524b794..d2304d3 100644 --- a/release/lossless-min.js +++ b/release/lossless-min.js @@ -1,2 +1,2 @@ -"use strict";var y=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var k=(a,t)=>{for(var e in t)y(a,e,{get:t[e],enumerable:!0})},I=(a,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of B(t))!C.call(a,s)&&s!==e&&y(a,s,{get:()=>t[s],enumerable:!(r=L(t,s))||r.enumerable});return a};var v=a=>I(y({},"__esModule",{value:!0}),a);var H={};k(H,{ComponentSpec:()=>w,DataStream:()=>b,Decoder:()=>E,FrameHeader:()=>x,HuffmanTable:()=>p,QuantizationTable:()=>d,ScanComponent:()=>R,ScanHeader:()=>g,Utils:()=>T});module.exports=v(H);var w={hSamp:0,quantTableSel:0,vSamp:0};var b=class{buffer;index;constructor(t,e,r){this.buffer=new Uint8Array(t,e,r),this.index=0}get16(){let t=(this.buffer[this.index]<<8)+this.buffer[this.index+1];return this.index+=2,t}get8(){let t=this.buffer[this.index];return this.index+=1,t}};var x=class{dimX=0;dimY=0;numComp=0;precision=0;components=[];read(t){let e=0,r,s=t.get16();e+=2,this.precision=t.get8(),e+=1,this.dimY=t.get16(),e+=2,this.dimX=t.get16(),e+=2,this.numComp=t.get8(),e+=1;for(let i=1;i<=this.numComp;i+=1){if(e>s)throw new Error("ERROR: frame format error");let n=t.get8();if(e+=1,e>=s)throw new Error("ERROR: frame format error [c>=Lf]");r=t.get8(),e+=1,this.components[n]||(this.components[n]={...w}),this.components[n].hSamp=r>>4,this.components[n].vSamp=r&15,this.components[n].quantTableSel=t.get8(),e+=1}if(e!==s)throw new Error("ERROR: frame format error [Lf!=count]");return 1}};var T={};k(T,{crc32:()=>P,crcTable:()=>S,createArray:()=>c,makeCRCTable:()=>D});var c=(...a)=>{if(a.length>1){let t=a[0],e=a.slice(1),r=[];for(let s=0;s>>1:a>>>1;t[e]=a}return t},S=D(),P=function(a){let t=new Uint8Array(a),e=-1;for(let r=0;r>>8^S[(e^t[r])&255];return(e^-1)>>>0};var p=class a{static MSB=2147483648;l;th;v;tc;constructor(){this.l=c(4,2,16),this.th=[0,0,0,0],this.v=c(4,2,16,200),this.tc=[[0,0],[0,0],[0,0],[0,0]]}read(t,e){let r=0,s,i,n,o,f,u=t.get16();for(r+=2;r3)throw new Error("ERROR: Huffman table ID > 3");if(n=s>>4,n>2)throw new Error("ERROR: Huffman table [Table class > 2 ]");for(this.th[i]=1,this.tc[i][n]=1,o=0;o<16;o+=1)this.l[i][n][o]=t.get8(),r+=1;for(o=0;o<16;o+=1)for(f=0;fu)throw new Error("ERROR: Huffman table format error [count>Lh]");this.v[i][n][o][f]=t.get8(),r+=1}}if(r!==u)throw new Error("ERROR: Huffman table format error [count!=Lf]");for(o=0;o<4;o+=1)for(f=0;f<2;f+=1)this.tc[o][f]!==0&&this.buildHuffTable(e[o][f],this.l[o][f],this.v[o][f]);return 1}buildHuffTable(t,e,r){let s,i,n,o,f;for(i=0,n=0;n<8;n+=1)for(o=0;o>n+1;f+=1)t[i]=r[n][o]|n+1<<8,i+=1;for(n=1;i<256;n+=1,i+=1)t[i]=n|a.MSB;for(s=1,i=0,n=8;n<16;n+=1)for(o=0;o>n-7;f+=1)t[s*256+i]=r[n][o]|n+1<<8,i+=1;if(i>=256){if(i>256)throw new Error("ERROR: Huffman table error(1)!");i=0,s+=1}}}};var d=class a{precision=[];tq=[0,0,0,0];quantTables=c(4,64);static enhanceQuantizationTable=function(t,e){for(let r=0;r<8;r+=1)t[e[0*8+r]]*=90,t[e[4*8+r]]*=90,t[e[2*8+r]]*=118,t[e[6*8+r]]*=49,t[e[5*8+r]]*=71,t[e[1*8+r]]*=126,t[e[7*8+r]]*=25,t[e[3*8+r]]*=106;for(let r=0;r<8;r+=1)t[e[0+8*r]]*=90,t[e[4+8*r]]*=90,t[e[2+8*r]]*=118,t[e[6+8*r]]*=49,t[e[5+8*r]]*=71,t[e[1+8*r]]*=126,t[e[7+8*r]]*=25,t[e[3+8*r]]*=106;for(let r=0;r<64;r+=1)t[r]>>=6};read(t,e){let r=0,s,i,n,o=t.get16();for(r+=2;r3)throw new Error("ERROR: Quantization table ID > 3");if(this.precision[i]=s>>4,this.precision[i]===0)this.precision[i]=8;else if(this.precision[i]===1)this.precision[i]=16;else throw new Error("ERROR: Quantization table precision error");if(this.tq[i]=1,this.precision[i]===8){for(n=0;n<64;n+=1){if(r>o)throw new Error("ERROR: Quantization table format error");this.quantTables[i][n]=t.get8(),r+=1}a.enhanceQuantizationTable(this.quantTables[i],e)}else{for(n=0;n<64;n+=1){if(r>o)throw new Error("ERROR: Quantization table format error");this.quantTables[i][n]=t.get16(),r+=2}a.enhanceQuantizationTable(this.quantTables[i],e)}}if(r!==o)throw new Error("ERROR: Quantization table error [count!=Lq]");return 1}};var R={acTabSel:0,dcTabSel:0,scanCompSel:0};var g=class{ah=0;al=0;numComp=0;selection=0;spectralEnd=0;components=[];read(t){let e=0,r,s,i=t.get16();for(e+=2,this.numComp=t.get8(),e+=1,r=0;ri)throw new Error("ERROR: scan header format error");this.components[r].scanCompSel=t.get8(),e+=1,s=t.get8(),e+=1,this.components[r].dcTabSel=s>>4,this.components[r].acTabSel=s&15}if(this.selection=t.get8(),e+=1,this.spectralEnd=t.get8(),e+=1,s=t.get8(),this.ah=s>>4,this.al=s&15,e+=1,e!==i)throw new Error("ERROR: scan header format error [count!=Ns]");return 1}};var A=function(){let a=new ArrayBuffer(2);return new DataView(a).setInt16(0,256,!0),new Int16Array(a)[0]===256}(),E=class a{static IDCT_P=[0,5,40,16,45,2,7,42,21,56,8,61,18,47,1,4,41,23,58,13,32,24,37,10,63,17,44,3,6,43,20,57,15,34,29,48,53,26,39,9,60,19,46,22,59,12,33,31,50,55,25,36,11,62,14,35,28,49,52,27,38,30,51,54];static TABLE=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63];static MAX_HUFFMAN_SUBTREE=50;static MSB=2147483648;static RESTART_MARKER_BEGIN=65488;static RESTART_MARKER_END=65495;buffer=null;stream=null;frame=new x;huffTable=new p;quantTable=new d;scan=new g;DU=c(10,4,64);HuffTab=c(4,2,50*256);IDCT_Source=[];nBlock=[];acTab=c(10,1);dcTab=c(10,1);qTab=c(10,1);marker=0;markerIndex=0;numComp=0;restartInterval=0;selection=0;xDim=0;yDim=0;xLoc=0;yLoc=0;outputData=null;restarting=!1;mask=0;numBytes=0;precision=void 0;components=[];getter=null;setter=null;output=null;selector=null;constructor(t,e){this.buffer=t??null,this.numBytes=e??0}decompress(t,e,r){return this.decode(t,e,r).buffer}decode(t,e,r,s){let i=0,n=[],o,f,u=[],l=[],m;t&&(this.buffer=t),s!==void 0&&(this.numBytes=s),this.stream=new b(this.buffer,e,r),this.buffer=null,this.xLoc=0,this.yLoc=0;let h=this.stream.get16();if(h!==65496)throw new Error("Not a JPEG file");for(h=this.stream.get16();h>>4!==4092||h===65476;){switch(h){case 65476:this.huffTable.read(this.stream,this.HuffTab);break;case 65484:throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");case 65499:this.quantTable.read(this.stream,a.TABLE);break;case 65501:this.restartInterval=this.readNumber()??0;break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:this.readApp();break;case 65534:this.readComment();break;default:if(h>>8!==255)throw new Error("ERROR: format throw new IOException! (decode)")}h=this.stream.get16()}if(h<65472||h>65479)throw new Error("ERROR: could not handle arithmetic code!");this.frame.read(this.stream),h=this.stream.get16();do{for(;h!==65498;){switch(h){case 65476:this.huffTable.read(this.stream,this.HuffTab);break;case 65484:throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");case 65499:this.quantTable.read(this.stream,a.TABLE);break;case 65501:this.restartInterval=this.readNumber()??0;break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:this.readApp();break;case 65534:this.readComment();break;default:if(h>>8!==255)throw new Error("ERROR: format throw new IOException! (Parser.decode)")}h=this.stream.get16()}switch(this.precision=this.frame.precision,this.components=this.frame.components,this.numBytes||(this.numBytes=Math.round(Math.ceil(this.precision/8))),this.numBytes===1?this.mask=255:this.mask=65535,this.scan.read(this.stream),this.numComp=this.scan.numComp,this.selection=this.scan.selection,this.numBytes===1?this.numComp===3?(this.getter=this.getValueRGB,this.setter=this.setValueRGB,this.output=this.outputRGB):(this.getter=this.getValue8,this.setter=this.setValue8,this.output=this.outputSingle):(this.getter=this.getValue8,this.setter=this.setValue8,this.output=this.outputSingle),this.selection){case 2:this.selector=this.select2;break;case 3:this.selector=this.select3;break;case 4:this.selector=this.select4;break;case 5:this.selector=this.select5;break;case 6:this.selector=this.select6;break;case 7:this.selector=this.select7;break;default:this.selector=this.select1;break}for(o=0;o=a.RESTART_MARKER_BEGIN&&h<=a.RESTART_MARKER_END))break}h===65500&&i===1&&(this.readNumber(),h=this.stream.get16())}while(h!==65497&&this.xLoc>1)}select6(t){return this.getPreviousY(t)+(this.getPreviousX(t)-this.getPreviousXY(t)>>1)}select7(t){return(this.getPreviousX(t)+this.getPreviousY(t))/2}decodeRGB(t,e,r){if(this.selector===null)throw new Error("decode hasn't run yet");let s,i,n,o,f,u,l;for(t[0]=this.selector(0),t[1]=this.selector(1),t[2]=this.selector(2),o=0;o=65280)return m;for(t[o]=this.IDCT_Source[0]=t[o]+this.getn(r,m,e,r),this.IDCT_Source[0]*=n[0],l=1;l<64;l+=1){if(m=this.getHuffmanValue(s,e,r),m>=65280)return m;if(l+=m>>4,m&15)this.IDCT_Source[a.IDCT_P[l]]=this.getn(r,m&15,e,r)*n[l];else if(!(m>>4))break}}return 0}decodeSingle(t,e,r){if(this.selector===null)throw new Error("decode hasn't run yet");let s,i,n,o;for(this.restarting?(this.restarting=!1,t[0]=1<=65280)return s;if(n=this.getn(t,s,e,r),o=n>>8,o>=a.RESTART_MARKER_BEGIN&&o<=a.RESTART_MARKER_END)return o;t[0]+=n}return 0}getHuffmanValue(t,e,r){let s,i;if(!this.stream)throw new Error("stream not initialized");if(r[0]<8?(e[0]<<=8,i=this.stream.get8(),i===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),e[0]|=i):r[0]-=8,s=t[e[0]>>r[0]],s&a.MSB){if(this.markerIndex!==0)return this.markerIndex=0,65280|this.marker;e[0]&=65535>>16-r[0],e[0]<<=8,i=this.stream.get8(),i===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),e[0]|=i,s=t[(s&255)*256+(e[0]>>r[0])],r[0]+=8}if(r[0]+=8-(s>>8),r[0]<0)throw new Error("index="+r[0]+" temp="+e[0]+" code="+s+" in HuffmanValue()");return r[0]>16-r[0],s&255)}getn(t,e,r,s){let i,n;if(this.stream===null)throw new Error("stream not initialized");if(e===0)return 0;if(e===16)return t[0]>=0?-32768:32768;if(s[0]-=e,s[0]>=0){if(s[0]>s[0],r[0]&=65535>>16-s[0]}else{if(r[0]<<=8,n=this.stream.get8(),n===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),r[0]|=n,s[0]+=8,s[0]<0){if(this.markerIndex!==0)return this.markerIndex=0,(65280|this.marker)<<8;r[0]<<=8,n=this.stream.get8(),n===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),r[0]|=n,s[0]+=8}if(s[0]<0)throw new Error("index="+s[0]+" in getn()");if(s[0]>s[0],r[0]&=65535>>16-s[0]}return i<1<0?this.getter(this.yLoc*this.xDim+this.xLoc-1,t):this.yLoc>0?this.getPreviousY(t):1<0&&this.yLoc>0?this.getter((this.yLoc-1)*this.xDim+this.xLoc-1,t):this.getPreviousY(t)}getPreviousY(t=0){if(this.getter===null)throw new Error("decode hasn't run yet");return this.yLoc>0?this.getter((this.yLoc-1)*this.xDim+this.xLoc,t):this.getPreviousX(t)}isLastPixel(){return this.xLoc===this.xDim-1&&this.yLoc===this.yDim-1}outputSingle(t){if(this.setter===null)throw new Error("decode hasn't run yet");this.xLoc=this.xDim&&(this.yLoc+=1,this.xLoc=0))}outputRGB(t){if(this.setter===null)throw new Error("decode hasn't run yet");let e=this.yLoc*this.xDim+this.xLoc;this.xLoc=this.xDim&&(this.yLoc+=1,this.xLoc=0))}setValue8(t,e){if(!this.outputData)throw new Error("output data not ready");A?this.outputData[t]=e:this.outputData[t]=(e&255)<<8|e>>8&255}getValue8(t){if(this.outputData===null)throw new Error("output data not ready");if(A)return this.outputData[t];{let e=this.outputData[t];return(e&255)<<8|e>>8&255}}setValueRGB(t,e,r=0){this.outputData!==null&&(this.outputData[t*3+r]=e)}getValueRGB(t,e){if(this.outputData===null)throw new Error("output data not ready");return this.outputData[t*3+e]}readApp(){if(this.stream===null)return null;let t=0,e=this.stream.get16();for(t+=2;t{for(var e in t)S(a,e,{get:t[e],enumerable:!0})};var w={hSamp:0,quantTableSel:0,vSamp:0};var b=class{buffer;index;constructor(t,e,r){this.buffer=new Uint8Array(t,e,r),this.index=0}get16(){let t=(this.buffer[this.index]<<8)+this.buffer[this.index+1];return this.index+=2,t}get8(){let t=this.buffer[this.index];return this.index+=1,t}};var x=class{dimX=0;dimY=0;numComp=0;precision=0;components=[];read(t){let e=0,r,o=t.get16();e+=2,this.precision=t.get8(),e+=1,this.dimY=t.get16(),e+=2,this.dimX=t.get16(),e+=2,this.numComp=t.get8(),e+=1;for(let s=1;s<=this.numComp;s+=1){if(e>o)throw new Error("ERROR: frame format error");let i=t.get8();if(e+=1,e>=o)throw new Error("ERROR: frame format error [c>=Lf]");r=t.get8(),e+=1,this.components[i]||(this.components[i]={...w}),this.components[i].hSamp=r>>4,this.components[i].vSamp=r&15,this.components[i].quantTableSel=t.get8(),e+=1}if(e!==o)throw new Error("ERROR: frame format error [Lf!=count]");return 1}};var k={};A(k,{crc32:()=>L,crcTable:()=>T,createArray:()=>c,makeCRCTable:()=>y});var c=(...a)=>{if(a.length>1){let t=a[0],e=a.slice(1),r=[];for(let o=0;o>>1:a>>>1;t[e]=a}return t},T=y(),L=function(a){let t=new Uint8Array(a),e=-1;for(let r=0;r>>8^T[(e^t[r])&255];return(e^-1)>>>0};var p=class a{static MSB=2147483648;l;th;v;tc;constructor(){this.l=c(4,2,16),this.th=[0,0,0,0],this.v=c(4,2,16,200),this.tc=[[0,0],[0,0],[0,0],[0,0]]}read(t,e){let r=0,o,s,i,n,f,u=t.get16();for(r+=2;r3)throw new Error("ERROR: Huffman table ID > 3");if(i=o>>4,i>2)throw new Error("ERROR: Huffman table [Table class > 2 ]");for(this.th[s]=1,this.tc[s][i]=1,n=0;n<16;n+=1)this.l[s][i][n]=t.get8(),r+=1;for(n=0;n<16;n+=1)for(f=0;fu)throw new Error("ERROR: Huffman table format error [count>Lh]");this.v[s][i][n][f]=t.get8(),r+=1}}if(r!==u)throw new Error("ERROR: Huffman table format error [count!=Lf]");for(n=0;n<4;n+=1)for(f=0;f<2;f+=1)this.tc[n][f]!==0&&this.buildHuffTable(e[n][f],this.l[n][f],this.v[n][f]);return 1}buildHuffTable(t,e,r){let o,s,i,n,f;for(s=0,i=0;i<8;i+=1)for(n=0;n>i+1;f+=1)t[s]=r[i][n]|i+1<<8,s+=1;for(i=1;s<256;i+=1,s+=1)t[s]=i|a.MSB;for(o=1,s=0,i=8;i<16;i+=1)for(n=0;n>i-7;f+=1)t[o*256+s]=r[i][n]|i+1<<8,s+=1;if(s>=256){if(s>256)throw new Error("ERROR: Huffman table error(1)!");s=0,o+=1}}}};var d=class a{precision=[];tq=[0,0,0,0];quantTables=c(4,64);static enhanceQuantizationTable=function(t,e){for(let r=0;r<8;r+=1)t[e[0*8+r]]*=90,t[e[4*8+r]]*=90,t[e[2*8+r]]*=118,t[e[6*8+r]]*=49,t[e[5*8+r]]*=71,t[e[1*8+r]]*=126,t[e[7*8+r]]*=25,t[e[3*8+r]]*=106;for(let r=0;r<8;r+=1)t[e[0+8*r]]*=90,t[e[4+8*r]]*=90,t[e[2+8*r]]*=118,t[e[6+8*r]]*=49,t[e[5+8*r]]*=71,t[e[1+8*r]]*=126,t[e[7+8*r]]*=25,t[e[3+8*r]]*=106;for(let r=0;r<64;r+=1)t[r]>>=6};read(t,e){let r=0,o,s,i,n=t.get16();for(r+=2;r3)throw new Error("ERROR: Quantization table ID > 3");if(this.precision[s]=o>>4,this.precision[s]===0)this.precision[s]=8;else if(this.precision[s]===1)this.precision[s]=16;else throw new Error("ERROR: Quantization table precision error");if(this.tq[s]=1,this.precision[s]===8){for(i=0;i<64;i+=1){if(r>n)throw new Error("ERROR: Quantization table format error");this.quantTables[s][i]=t.get8(),r+=1}a.enhanceQuantizationTable(this.quantTables[s],e)}else{for(i=0;i<64;i+=1){if(r>n)throw new Error("ERROR: Quantization table format error");this.quantTables[s][i]=t.get16(),r+=2}a.enhanceQuantizationTable(this.quantTables[s],e)}}if(r!==n)throw new Error("ERROR: Quantization table error [count!=Lq]");return 1}};var R={acTabSel:0,dcTabSel:0,scanCompSel:0};var g=class{ah=0;al=0;numComp=0;selection=0;spectralEnd=0;components=[];read(t){let e=0,r,o,s=t.get16();for(e+=2,this.numComp=t.get8(),e+=1,r=0;rs)throw new Error("ERROR: scan header format error");this.components[r].scanCompSel=t.get8(),e+=1,o=t.get8(),e+=1,this.components[r].dcTabSel=o>>4,this.components[r].acTabSel=o&15}if(this.selection=t.get8(),e+=1,this.spectralEnd=t.get8(),e+=1,o=t.get8(),this.ah=o>>4,this.al=o&15,e+=1,e!==s)throw new Error("ERROR: scan header format error [count!=Ns]");return 1}};var D=function(){let a=new ArrayBuffer(2);return new DataView(a).setInt16(0,256,!0),new Int16Array(a)[0]===256}(),E=class a{static IDCT_P=[0,5,40,16,45,2,7,42,21,56,8,61,18,47,1,4,41,23,58,13,32,24,37,10,63,17,44,3,6,43,20,57,15,34,29,48,53,26,39,9,60,19,46,22,59,12,33,31,50,55,25,36,11,62,14,35,28,49,52,27,38,30,51,54];static TABLE=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63];static MAX_HUFFMAN_SUBTREE=50;static MSB=2147483648;static RESTART_MARKER_BEGIN=65488;static RESTART_MARKER_END=65495;buffer=null;stream=null;frame=new x;huffTable=new p;quantTable=new d;scan=new g;DU=c(10,4,64);HuffTab=c(4,2,50*256);IDCT_Source=[];nBlock=[];acTab=c(10,1);dcTab=c(10,1);qTab=c(10,1);marker=0;markerIndex=0;numComp=0;restartInterval=0;selection=0;xDim=0;yDim=0;xLoc=0;yLoc=0;outputData=null;restarting=!1;mask=0;numBytes=0;precision=void 0;components=[];getter=null;setter=null;output=null;selector=null;constructor(t,e){this.buffer=t??null,this.numBytes=e??0}decompress(t,e,r){return this.decode(t,e,r).buffer}decode(t,e,r,o){let s=0,i=[],n,f,u=[],l=[],m;t&&(this.buffer=t),o!==void 0&&(this.numBytes=o),this.stream=new b(this.buffer,e,r),this.buffer=null,this.xLoc=0,this.yLoc=0;let h=this.stream.get16();if(h!==65496)throw new Error("Not a JPEG file");for(h=this.stream.get16();h>>4!==4092||h===65476;){switch(h){case 65476:this.huffTable.read(this.stream,this.HuffTab);break;case 65484:throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");case 65499:this.quantTable.read(this.stream,a.TABLE);break;case 65501:this.restartInterval=this.readNumber()??0;break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:this.readApp();break;case 65534:this.readComment();break;default:if(h>>8!==255)throw new Error("ERROR: format throw new IOException! (decode)")}h=this.stream.get16()}if(h<65472||h>65479)throw new Error("ERROR: could not handle arithmetic code!");this.frame.read(this.stream),h=this.stream.get16();do{for(;h!==65498;){switch(h){case 65476:this.huffTable.read(this.stream,this.HuffTab);break;case 65484:throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");case 65499:this.quantTable.read(this.stream,a.TABLE);break;case 65501:this.restartInterval=this.readNumber()??0;break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:this.readApp();break;case 65534:this.readComment();break;default:if(h>>8!==255)throw new Error("ERROR: format throw new IOException! (Parser.decode)")}h=this.stream.get16()}switch(this.precision=this.frame.precision,this.components=this.frame.components,this.numBytes||(this.numBytes=Math.round(Math.ceil(this.precision/8))),this.numBytes===1?this.mask=255:this.mask=65535,this.scan.read(this.stream),this.numComp=this.scan.numComp,this.selection=this.scan.selection,this.numBytes===1?this.numComp===3?(this.getter=this.getValueRGB,this.setter=this.setValueRGB,this.output=this.outputRGB):(this.getter=this.getValue8,this.setter=this.setValue8,this.output=this.outputSingle):(this.getter=this.getValue8,this.setter=this.setValue8,this.output=this.outputSingle),this.selection){case 2:this.selector=this.select2;break;case 3:this.selector=this.select3;break;case 4:this.selector=this.select4;break;case 5:this.selector=this.select5;break;case 6:this.selector=this.select6;break;case 7:this.selector=this.select7;break;default:this.selector=this.select1;break}for(n=0;n=a.RESTART_MARKER_BEGIN&&h<=a.RESTART_MARKER_END))break}h===65500&&s===1&&(this.readNumber(),h=this.stream.get16())}while(h!==65497&&this.xLoc>1)}select6(t){return this.getPreviousY(t)+(this.getPreviousX(t)-this.getPreviousXY(t)>>1)}select7(t){return(this.getPreviousX(t)+this.getPreviousY(t))/2}decodeRGB(t,e,r){if(this.selector===null)throw new Error("decode hasn't run yet");let o,s,i,n,f,u,l;for(t[0]=this.selector(0),t[1]=this.selector(1),t[2]=this.selector(2),n=0;n=65280)return m;for(t[n]=this.IDCT_Source[0]=t[n]+this.getn(r,m,e,r),this.IDCT_Source[0]*=i[0],l=1;l<64;l+=1){if(m=this.getHuffmanValue(o,e,r),m>=65280)return m;if(l+=m>>4,m&15)this.IDCT_Source[a.IDCT_P[l]]=this.getn(r,m&15,e,r)*i[l];else if(!(m>>4))break}}return 0}decodeSingle(t,e,r){if(this.selector===null)throw new Error("decode hasn't run yet");let o,s,i,n;for(this.restarting?(this.restarting=!1,t[0]=1<=65280)return o;if(i=this.getn(t,o,e,r),n=i>>8,n>=a.RESTART_MARKER_BEGIN&&n<=a.RESTART_MARKER_END)return n;t[0]+=i}return 0}getHuffmanValue(t,e,r){let o,s;if(!this.stream)throw new Error("stream not initialized");if(r[0]<8?(e[0]<<=8,s=this.stream.get8(),s===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),e[0]|=s):r[0]-=8,o=t[e[0]>>r[0]],o&a.MSB){if(this.markerIndex!==0)return this.markerIndex=0,65280|this.marker;e[0]&=65535>>16-r[0],e[0]<<=8,s=this.stream.get8(),s===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),e[0]|=s,o=t[(o&255)*256+(e[0]>>r[0])],r[0]+=8}if(r[0]+=8-(o>>8),r[0]<0)throw new Error("index="+r[0]+" temp="+e[0]+" code="+o+" in HuffmanValue()");return r[0]>16-r[0],o&255)}getn(t,e,r,o){let s,i;if(this.stream===null)throw new Error("stream not initialized");if(e===0)return 0;if(e===16)return t[0]>=0?-32768:32768;if(o[0]-=e,o[0]>=0){if(o[0]>o[0],r[0]&=65535>>16-o[0]}else{if(r[0]<<=8,i=this.stream.get8(),i===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),r[0]|=i,o[0]+=8,o[0]<0){if(this.markerIndex!==0)return this.markerIndex=0,(65280|this.marker)<<8;r[0]<<=8,i=this.stream.get8(),i===255&&(this.marker=this.stream.get8(),this.marker!==0&&(this.markerIndex=9)),r[0]|=i,o[0]+=8}if(o[0]<0)throw new Error("index="+o[0]+" in getn()");if(o[0]>o[0],r[0]&=65535>>16-o[0]}return s<1<0?this.getter(this.yLoc*this.xDim+this.xLoc-1,t):this.yLoc>0?this.getPreviousY(t):1<0&&this.yLoc>0?this.getter((this.yLoc-1)*this.xDim+this.xLoc-1,t):this.getPreviousY(t)}getPreviousY(t=0){if(this.getter===null)throw new Error("decode hasn't run yet");return this.yLoc>0?this.getter((this.yLoc-1)*this.xDim+this.xLoc,t):this.getPreviousX(t)}isLastPixel(){return this.xLoc===this.xDim-1&&this.yLoc===this.yDim-1}outputSingle(t){if(this.setter===null)throw new Error("decode hasn't run yet");this.xLoc=this.xDim&&(this.yLoc+=1,this.xLoc=0))}outputRGB(t){if(this.setter===null)throw new Error("decode hasn't run yet");let e=this.yLoc*this.xDim+this.xLoc;this.xLoc=this.xDim&&(this.yLoc+=1,this.xLoc=0))}setValue8(t,e){if(!this.outputData)throw new Error("output data not ready");D?this.outputData[t]=e:this.outputData[t]=(e&255)<<8|e>>8&255}getValue8(t){if(this.outputData===null)throw new Error("output data not ready");if(D)return this.outputData[t];{let e=this.outputData[t];return(e&255)<<8|e>>8&255}}setValueRGB(t,e,r=0){this.outputData!==null&&(this.outputData[t*3+r]=e)}getValueRGB(t,e){if(this.outputData===null)throw new Error("output data not ready");return this.outputData[t*3+e]}readApp(){if(this.stream===null)return null;let t=0,e=this.stream.get16();for(t+=2;t { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/main.ts -var main_exports = {}; -__export(main_exports, { - ComponentSpec: () => ComponentSpec, - DataStream: () => DataStream, - Decoder: () => Decoder, - FrameHeader: () => FrameHeader, - HuffmanTable: () => HuffmanTable, - QuantizationTable: () => QuantizationTable, - ScanComponent: () => ScanComponent, - ScanHeader: () => ScanHeader, - Utils: () => utils_exports -}); -module.exports = __toCommonJS(main_exports); // src/component-spec.ts var ComponentSpec = { @@ -1176,8 +1148,7 @@ var Decoder = class _Decoder { return this.stream.get16(); } }; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { +export { ComponentSpec, DataStream, Decoder, @@ -1186,6 +1157,6 @@ var Decoder = class _Decoder { QuantizationTable, ScanComponent, ScanHeader, - Utils -}); + utils_exports as Utils +}; //# sourceMappingURL=lossless.js.map \ No newline at end of file diff --git a/tsup.config.ts b/tsup.config.ts index 2bc5638..f6da970 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -8,6 +8,8 @@ export default defineConfig([ outExtension: () => ({ js: '.js' }), + target: 'esnext', + format: 'esm', outDir: 'release', splitting: false, sourcemap: true, @@ -21,6 +23,8 @@ export default defineConfig([ outExtension: () => ({ js: '.js' }), + target: 'esnext', + format: 'esm', outDir: 'release', splitting: false, sourcemap: true, From 36255fb96eb5f4216aea22797a804813bdc57ce9 Mon Sep 17 00:00:00 2001 From: Jens Ochsenmeier Date: Thu, 28 Mar 2024 10:59:20 +0100 Subject: [PATCH 2/3] compile to both cjs and esm --- package.json | 5 +- release/cjs/lossless.cjs | 1191 ++++++++++++++++++++++++++++++++++ release/cjs/lossless.cjs.map | 1 + tests/bundle.test.ts | 17 + tsup.config.ts | 12 + 5 files changed, 1224 insertions(+), 2 deletions(-) create mode 100644 release/cjs/lossless.cjs create mode 100644 release/cjs/lossless.cjs.map create mode 100644 tests/bundle.test.ts diff --git a/package.json b/package.json index 5d5bcbe..6c26836 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,10 @@ "name": "jpeg-lossless-decoder-js", "version": "2.1.0", "description": "A JavaScript JPEG Lossless decoder.", - "main": "release/lossless.js", - "types": "release/lossless.d.cts", "type": "module", + "main": "release/cjs/lossless.cjs", + "module": "release/lossless.js", + "types": "release/lossless.d.ts", "directories": { "test": "tests" }, diff --git a/release/cjs/lossless.cjs b/release/cjs/lossless.cjs new file mode 100644 index 0000000..457302a --- /dev/null +++ b/release/cjs/lossless.cjs @@ -0,0 +1,1191 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/main.ts +var main_exports = {}; +__export(main_exports, { + ComponentSpec: () => ComponentSpec, + DataStream: () => DataStream, + Decoder: () => Decoder, + FrameHeader: () => FrameHeader, + HuffmanTable: () => HuffmanTable, + QuantizationTable: () => QuantizationTable, + ScanComponent: () => ScanComponent, + ScanHeader: () => ScanHeader, + Utils: () => utils_exports +}); +module.exports = __toCommonJS(main_exports); + +// src/component-spec.ts +var ComponentSpec = { + hSamp: 0, + quantTableSel: 0, + vSamp: 0 +}; + +// src/data-stream.ts +var DataStream = class { + buffer; + index; + constructor(data, offset, length) { + this.buffer = new Uint8Array(data, offset, length); + this.index = 0; + } + get16() { + const value = (this.buffer[this.index] << 8) + this.buffer[this.index + 1]; + this.index += 2; + return value; + } + get8() { + const value = this.buffer[this.index]; + this.index += 1; + return value; + } +}; + +// src/frame-header.ts +var FrameHeader = class { + dimX = 0; + dimY = 0; + numComp = 0; + precision = 0; + components = []; + read(data) { + let count = 0; + let temp; + const length = data.get16(); + count += 2; + this.precision = data.get8(); + count += 1; + this.dimY = data.get16(); + count += 2; + this.dimX = data.get16(); + count += 2; + this.numComp = data.get8(); + count += 1; + for (let i = 1; i <= this.numComp; i += 1) { + if (count > length) { + throw new Error("ERROR: frame format error"); + } + const c = data.get8(); + count += 1; + if (count >= length) { + throw new Error("ERROR: frame format error [c>=Lf]"); + } + temp = data.get8(); + count += 1; + if (!this.components[c]) { + this.components[c] = { ...ComponentSpec }; + } + this.components[c].hSamp = temp >> 4; + this.components[c].vSamp = temp & 15; + this.components[c].quantTableSel = data.get8(); + count += 1; + } + if (count !== length) { + throw new Error("ERROR: frame format error [Lf!=count]"); + } + return 1; + } +}; + +// src/utils.ts +var utils_exports = {}; +__export(utils_exports, { + crc32: () => crc32, + crcTable: () => crcTable, + createArray: () => createArray, + makeCRCTable: () => makeCRCTable +}); +var createArray = (...dimensions) => { + if (dimensions.length > 1) { + const dim = dimensions[0]; + const rest = dimensions.slice(1); + const newArray = []; + for (let i = 0; i < dim; i++) { + newArray[i] = createArray(...rest); + } + return newArray; + } else { + return Array(dimensions[0]).fill(void 0); + } +}; +var makeCRCTable = function() { + let c; + const crcTable2 = []; + for (let n = 0; n < 256; n++) { + c = n; + for (let k = 0; k < 8; k++) { + c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1; + } + crcTable2[n] = c; + } + return crcTable2; +}; +var crcTable = makeCRCTable(); +var crc32 = function(buffer) { + const uint8view = new Uint8Array(buffer); + let crc = 0 ^ -1; + for (let i = 0; i < uint8view.length; i++) { + crc = crc >>> 8 ^ crcTable[(crc ^ uint8view[i]) & 255]; + } + return (crc ^ -1) >>> 0; +}; + +// src/huffman-table.ts +var HuffmanTable = class _HuffmanTable { + static MSB = 2147483648; + l; + th; + v; + tc; + constructor() { + this.l = createArray(4, 2, 16); + this.th = [0, 0, 0, 0]; + this.v = createArray(4, 2, 16, 200); + this.tc = [ + [0, 0], + [0, 0], + [0, 0], + [0, 0] + ]; + } + read(data, HuffTab) { + let count = 0; + let temp; + let t; + let c; + let i; + let j; + const length = data.get16(); + count += 2; + while (count < length) { + temp = data.get8(); + count += 1; + t = temp & 15; + if (t > 3) { + throw new Error("ERROR: Huffman table ID > 3"); + } + c = temp >> 4; + if (c > 2) { + throw new Error("ERROR: Huffman table [Table class > 2 ]"); + } + this.th[t] = 1; + this.tc[t][c] = 1; + for (i = 0; i < 16; i += 1) { + this.l[t][c][i] = data.get8(); + count += 1; + } + for (i = 0; i < 16; i += 1) { + for (j = 0; j < this.l[t][c][i]; j += 1) { + if (count > length) { + throw new Error("ERROR: Huffman table format error [count>Lh]"); + } + this.v[t][c][i][j] = data.get8(); + count += 1; + } + } + } + if (count !== length) { + throw new Error("ERROR: Huffman table format error [count!=Lf]"); + } + for (i = 0; i < 4; i += 1) { + for (j = 0; j < 2; j += 1) { + if (this.tc[i][j] !== 0) { + this.buildHuffTable(HuffTab[i][j], this.l[i][j], this.v[i][j]); + } + } + } + return 1; + } + // Build_HuffTab() + // Parameter: t table ID + // c table class ( 0 for DC, 1 for AC ) + // L[i] # of codewords which length is i + // V[i][j] Huffman Value (length=i) + // Effect: + // build up HuffTab[t][c] using L and V. + buildHuffTable(tab, L, V) { + let currentTable, k, i, j, n; + const temp = 256; + k = 0; + for (i = 0; i < 8; i += 1) { + for (j = 0; j < L[i]; j += 1) { + for (n = 0; n < temp >> i + 1; n += 1) { + tab[k] = V[i][j] | i + 1 << 8; + k += 1; + } + } + } + for (i = 1; k < 256; i += 1, k += 1) { + tab[k] = i | _HuffmanTable.MSB; + } + currentTable = 1; + k = 0; + for (i = 8; i < 16; i += 1) { + for (j = 0; j < L[i]; j += 1) { + for (n = 0; n < temp >> i - 7; n += 1) { + tab[currentTable * 256 + k] = V[i][j] | i + 1 << 8; + k += 1; + } + if (k >= 256) { + if (k > 256) { + throw new Error("ERROR: Huffman table error(1)!"); + } + k = 0; + currentTable += 1; + } + } + } + } +}; + +// src/quantization-table.ts +var QuantizationTable = class _QuantizationTable { + precision = []; + // Quantization precision 8 or 16 + tq = [0, 0, 0, 0]; + // 1: this table is presented + quantTables = createArray(4, 64); + // Tables + static enhanceQuantizationTable = function(qtab, table) { + for (let i = 0; i < 8; i += 1) { + qtab[table[0 * 8 + i]] *= 90; + qtab[table[4 * 8 + i]] *= 90; + qtab[table[2 * 8 + i]] *= 118; + qtab[table[6 * 8 + i]] *= 49; + qtab[table[5 * 8 + i]] *= 71; + qtab[table[1 * 8 + i]] *= 126; + qtab[table[7 * 8 + i]] *= 25; + qtab[table[3 * 8 + i]] *= 106; + } + for (let i = 0; i < 8; i += 1) { + qtab[table[0 + 8 * i]] *= 90; + qtab[table[4 + 8 * i]] *= 90; + qtab[table[2 + 8 * i]] *= 118; + qtab[table[6 + 8 * i]] *= 49; + qtab[table[5 + 8 * i]] *= 71; + qtab[table[1 + 8 * i]] *= 126; + qtab[table[7 + 8 * i]] *= 25; + qtab[table[3 + 8 * i]] *= 106; + } + for (let i = 0; i < 64; i += 1) { + qtab[i] >>= 6; + } + }; + read(data, table) { + let count = 0; + let temp; + let t; + let i; + const length = data.get16(); + count += 2; + while (count < length) { + temp = data.get8(); + count += 1; + t = temp & 15; + if (t > 3) { + throw new Error("ERROR: Quantization table ID > 3"); + } + this.precision[t] = temp >> 4; + if (this.precision[t] === 0) { + this.precision[t] = 8; + } else if (this.precision[t] === 1) { + this.precision[t] = 16; + } else { + throw new Error("ERROR: Quantization table precision error"); + } + this.tq[t] = 1; + if (this.precision[t] === 8) { + for (i = 0; i < 64; i += 1) { + if (count > length) { + throw new Error("ERROR: Quantization table format error"); + } + this.quantTables[t][i] = data.get8(); + count += 1; + } + _QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table); + } else { + for (i = 0; i < 64; i += 1) { + if (count > length) { + throw new Error("ERROR: Quantization table format error"); + } + this.quantTables[t][i] = data.get16(); + count += 2; + } + _QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table); + } + } + if (count !== length) { + throw new Error("ERROR: Quantization table error [count!=Lq]"); + } + return 1; + } +}; + +// src/scan-component.ts +var ScanComponent = { + acTabSel: 0, + // AC table selector + dcTabSel: 0, + // DC table selector + scanCompSel: 0 + // Scan component selector +}; + +// src/scan-header.ts +var ScanHeader = class { + ah = 0; + al = 0; + numComp = 0; + // Number of components in the scan + selection = 0; + // Start of spectral or predictor selection + spectralEnd = 0; + // End of spectral selection + components = []; + read(data) { + let count = 0; + let i; + let temp; + const length = data.get16(); + count += 2; + this.numComp = data.get8(); + count += 1; + for (i = 0; i < this.numComp; i += 1) { + this.components[i] = { ...ScanComponent }; + if (count > length) { + throw new Error("ERROR: scan header format error"); + } + this.components[i].scanCompSel = data.get8(); + count += 1; + temp = data.get8(); + count += 1; + this.components[i].dcTabSel = temp >> 4; + this.components[i].acTabSel = temp & 15; + } + this.selection = data.get8(); + count += 1; + this.spectralEnd = data.get8(); + count += 1; + temp = data.get8(); + this.ah = temp >> 4; + this.al = temp & 15; + count += 1; + if (count !== length) { + throw new Error("ERROR: scan header format error [count!=Ns]"); + } + return 1; + } +}; + +// src/decoder.ts +var littleEndian = function() { + const buffer = new ArrayBuffer(2); + new DataView(buffer).setInt16( + 0, + 256, + true + /* littleEndian */ + ); + return new Int16Array(buffer)[0] === 256; +}(); +var Decoder = class _Decoder { + static IDCT_P = [ + 0, + 5, + 40, + 16, + 45, + 2, + 7, + 42, + 21, + 56, + 8, + 61, + 18, + 47, + 1, + 4, + 41, + 23, + 58, + 13, + 32, + 24, + 37, + 10, + 63, + 17, + 44, + 3, + 6, + 43, + 20, + 57, + 15, + 34, + 29, + 48, + 53, + 26, + 39, + 9, + 60, + 19, + 46, + 22, + 59, + 12, + 33, + 31, + 50, + 55, + 25, + 36, + 11, + 62, + 14, + 35, + 28, + 49, + 52, + 27, + 38, + 30, + 51, + 54 + ]; + static TABLE = [ + 0, + 1, + 5, + 6, + 14, + 15, + 27, + 28, + 2, + 4, + 7, + 13, + 16, + 26, + 29, + 42, + 3, + 8, + 12, + 17, + 25, + 30, + 41, + 43, + 9, + 11, + 18, + 24, + 31, + 40, + 44, + 53, + 10, + 19, + 23, + 32, + 39, + 45, + 52, + 54, + 20, + 22, + 33, + 38, + 46, + 51, + 55, + 60, + 21, + 34, + 37, + 47, + 50, + 56, + 59, + 61, + 35, + 36, + 48, + 49, + 57, + 58, + 62, + 63 + ]; + static MAX_HUFFMAN_SUBTREE = 50; + static MSB = 2147483648; + static RESTART_MARKER_BEGIN = 65488; + static RESTART_MARKER_END = 65495; + buffer = null; + stream = null; + frame = new FrameHeader(); + huffTable = new HuffmanTable(); + quantTable = new QuantizationTable(); + scan = new ScanHeader(); + DU = createArray(10, 4, 64); + // at most 10 data units in a MCU, at most 4 data units in one component + HuffTab = createArray(4, 2, 50 * 256); + IDCT_Source = []; + nBlock = []; + // number of blocks in the i-th Comp in a scan + acTab = createArray(10, 1); + // ac HuffTab for the i-th Comp in a scan + dcTab = createArray(10, 1); + // dc HuffTab for the i-th Comp in a scan + qTab = createArray(10, 1); + // quantization table for the i-th Comp in a scan + marker = 0; + markerIndex = 0; + numComp = 0; + restartInterval = 0; + selection = 0; + xDim = 0; + yDim = 0; + xLoc = 0; + yLoc = 0; + outputData = null; + restarting = false; + mask = 0; + numBytes = 0; + precision = void 0; + components = []; + getter = null; + setter = null; + output = null; + selector = null; + /** + * The Decoder constructor. + * @property {number} numBytes - number of bytes per component + * @type {Function} + */ + constructor(buffer, numBytes) { + this.buffer = buffer ?? null; + this.numBytes = numBytes ?? 0; + } + /** + * Returns decompressed data. + */ + decompress(buffer, offset, length) { + const result = this.decode(buffer, offset, length); + return result.buffer; + } + decode(buffer, offset, length, numBytes) { + let scanNum = 0; + const pred = []; + let i; + let compN; + const temp = []; + const index = []; + let mcuNum; + if (buffer) { + this.buffer = buffer; + } + if (numBytes !== void 0) { + this.numBytes = numBytes; + } + this.stream = new DataStream(this.buffer, offset, length); + this.buffer = null; + this.xLoc = 0; + this.yLoc = 0; + let current = this.stream.get16(); + if (current !== 65496) { + throw new Error("Not a JPEG file"); + } + current = this.stream.get16(); + while (current >> 4 !== 4092 || current === 65476) { + switch (current) { + case 65476: + this.huffTable.read(this.stream, this.HuffTab); + break; + case 65484: + throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)"); + case 65499: + this.quantTable.read(this.stream, _Decoder.TABLE); + break; + case 65501: + this.restartInterval = this.readNumber() ?? 0; + break; + case 65504: + case 65505: + case 65506: + case 65507: + case 65508: + case 65509: + case 65510: + case 65511: + case 65512: + case 65513: + case 65514: + case 65515: + case 65516: + case 65517: + case 65518: + case 65519: + this.readApp(); + break; + case 65534: + this.readComment(); + break; + default: + if (current >> 8 !== 255) { + throw new Error("ERROR: format throw new IOException! (decode)"); + } + } + current = this.stream.get16(); + } + if (current < 65472 || current > 65479) { + throw new Error("ERROR: could not handle arithmetic code!"); + } + this.frame.read(this.stream); + current = this.stream.get16(); + do { + while (current !== 65498) { + switch (current) { + case 65476: + this.huffTable.read(this.stream, this.HuffTab); + break; + case 65484: + throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)"); + case 65499: + this.quantTable.read(this.stream, _Decoder.TABLE); + break; + case 65501: + this.restartInterval = this.readNumber() ?? 0; + break; + case 65504: + case 65505: + case 65506: + case 65507: + case 65508: + case 65509: + case 65510: + case 65511: + case 65512: + case 65513: + case 65514: + case 65515: + case 65516: + case 65517: + case 65518: + case 65519: + this.readApp(); + break; + case 65534: + this.readComment(); + break; + default: + if (current >> 8 !== 255) { + throw new Error("ERROR: format throw new IOException! (Parser.decode)"); + } + } + current = this.stream.get16(); + } + this.precision = this.frame.precision; + this.components = this.frame.components; + if (!this.numBytes) { + this.numBytes = Math.round(Math.ceil(this.precision / 8)); + } + if (this.numBytes === 1) { + this.mask = 255; + } else { + this.mask = 65535; + } + this.scan.read(this.stream); + this.numComp = this.scan.numComp; + this.selection = this.scan.selection; + if (this.numBytes === 1) { + if (this.numComp === 3) { + this.getter = this.getValueRGB; + this.setter = this.setValueRGB; + this.output = this.outputRGB; + } else { + this.getter = this.getValue8; + this.setter = this.setValue8; + this.output = this.outputSingle; + } + } else { + this.getter = this.getValue8; + this.setter = this.setValue8; + this.output = this.outputSingle; + } + switch (this.selection) { + case 2: + this.selector = this.select2; + break; + case 3: + this.selector = this.select3; + break; + case 4: + this.selector = this.select4; + break; + case 5: + this.selector = this.select5; + break; + case 6: + this.selector = this.select6; + break; + case 7: + this.selector = this.select7; + break; + default: + this.selector = this.select1; + break; + } + for (i = 0; i < this.numComp; i += 1) { + compN = this.scan.components[i].scanCompSel; + this.qTab[i] = this.quantTable.quantTables[this.components[compN].quantTableSel]; + this.nBlock[i] = this.components[compN].vSamp * this.components[compN].hSamp; + this.dcTab[i] = this.HuffTab[this.scan.components[i].dcTabSel][0]; + this.acTab[i] = this.HuffTab[this.scan.components[i].acTabSel][1]; + } + this.xDim = this.frame.dimX; + this.yDim = this.frame.dimY; + if (this.numBytes === 1) { + this.outputData = new Uint8Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp)); + } else { + this.outputData = new Uint16Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp)); + } + scanNum += 1; + while (true) { + temp[0] = 0; + index[0] = 0; + for (i = 0; i < 10; i += 1) { + pred[i] = 1 << this.precision - 1; + } + if (this.restartInterval === 0) { + current = this.decodeUnit(pred, temp, index); + while (current === 0 && this.xLoc < this.xDim && this.yLoc < this.yDim) { + this.output(pred); + current = this.decodeUnit(pred, temp, index); + } + break; + } + for (mcuNum = 0; mcuNum < this.restartInterval; mcuNum += 1) { + this.restarting = mcuNum === 0; + current = this.decodeUnit(pred, temp, index); + this.output(pred); + if (current !== 0) { + break; + } + } + if (current === 0) { + if (this.markerIndex !== 0) { + current = 65280 | this.marker; + this.markerIndex = 0; + } else { + current = this.stream.get16(); + } + } + if (!(current >= _Decoder.RESTART_MARKER_BEGIN && current <= _Decoder.RESTART_MARKER_END)) { + break; + } + } + if (current === 65500 && scanNum === 1) { + this.readNumber(); + current = this.stream.get16(); + } + } while (current !== 65497 && this.xLoc < this.xDim && this.yLoc < this.yDim && scanNum === 0); + return this.outputData; + } + decodeUnit(prev, temp, index) { + if (this.numComp === 1) { + return this.decodeSingle(prev, temp, index); + } else if (this.numComp === 3) { + return this.decodeRGB(prev, temp, index); + } else { + return -1; + } + } + select1(compOffset) { + return this.getPreviousX(compOffset); + } + select2(compOffset) { + return this.getPreviousY(compOffset); + } + select3(compOffset) { + return this.getPreviousXY(compOffset); + } + select4(compOffset) { + return this.getPreviousX(compOffset) + this.getPreviousY(compOffset) - this.getPreviousXY(compOffset); + } + select5(compOffset) { + return this.getPreviousX(compOffset) + (this.getPreviousY(compOffset) - this.getPreviousXY(compOffset) >> 1); + } + select6(compOffset) { + return this.getPreviousY(compOffset) + (this.getPreviousX(compOffset) - this.getPreviousXY(compOffset) >> 1); + } + select7(compOffset) { + return (this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) / 2; + } + decodeRGB(prev, temp, index) { + if (this.selector === null) + throw new Error("decode hasn't run yet"); + let actab, dctab, qtab, ctrC, i, k, j; + prev[0] = this.selector(0); + prev[1] = this.selector(1); + prev[2] = this.selector(2); + for (ctrC = 0; ctrC < this.numComp; ctrC += 1) { + qtab = this.qTab[ctrC]; + actab = this.acTab[ctrC]; + dctab = this.dcTab[ctrC]; + for (i = 0; i < this.nBlock[ctrC]; i += 1) { + for (k = 0; k < this.IDCT_Source.length; k += 1) { + this.IDCT_Source[k] = 0; + } + let value = this.getHuffmanValue(dctab, temp, index); + if (value >= 65280) { + return value; + } + prev[ctrC] = this.IDCT_Source[0] = prev[ctrC] + this.getn(index, value, temp, index); + this.IDCT_Source[0] *= qtab[0]; + for (j = 1; j < 64; j += 1) { + value = this.getHuffmanValue(actab, temp, index); + if (value >= 65280) { + return value; + } + j += value >> 4; + if ((value & 15) === 0) { + if (value >> 4 === 0) { + break; + } + } else { + this.IDCT_Source[_Decoder.IDCT_P[j]] = this.getn(index, value & 15, temp, index) * qtab[j]; + } + } + } + } + return 0; + } + decodeSingle(prev, temp, index) { + if (this.selector === null) + throw new Error("decode hasn't run yet"); + let value, i, n, nRestart; + if (this.restarting) { + this.restarting = false; + prev[0] = 1 << this.frame.precision - 1; + } else { + prev[0] = this.selector(); + } + for (i = 0; i < this.nBlock[0]; i += 1) { + value = this.getHuffmanValue(this.dcTab[0], temp, index); + if (value >= 65280) { + return value; + } + n = this.getn(prev, value, temp, index); + nRestart = n >> 8; + if (nRestart >= _Decoder.RESTART_MARKER_BEGIN && nRestart <= _Decoder.RESTART_MARKER_END) { + return nRestart; + } + prev[0] += n; + } + return 0; + } + // Huffman table for fast search: (HuffTab) 8-bit Look up table 2-layer search architecture, 1st-layer represent 256 node (8 bits) if codeword-length > 8 + // bits, then the entry of 1st-layer = (# of 2nd-layer table) | MSB and it is stored in the 2nd-layer Size of tables in each layer are 256. + // HuffTab[*][*][0-256] is always the only 1st-layer table. + // + // An entry can be: (1) (# of 2nd-layer table) | MSB , for code length > 8 in 1st-layer (2) (Code length) << 8 | HuffVal + // + // HuffmanValue(table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...) + // ): + // return: Huffman Value of table + // 0xFF?? if it receives a MARKER + // Parameter: table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...) + // temp temp storage for remainded bits + // index index to bit of temp + // in FILE pointer + // Effect: + // temp store new remainded bits + // index change to new index + // in change to new position + // NOTE: + // Initial by temp=0; index=0; + // NOTE: (explain temp and index) + // temp: is always in the form at calling time or returning time + // | byte 4 | byte 3 | byte 2 | byte 1 | + // | 0 | 0 | 00000000 | 00000??? | if not a MARKER + // ^index=3 (from 0 to 15) + // 321 + // NOTE (marker and marker_index): + // If get a MARKER from 'in', marker=the low-byte of the MARKER + // and marker_index=9 + // If marker_index=9 then index is always > 8, or HuffmanValue() + // will not be called + getHuffmanValue(table, temp, index) { + let code, input; + const mask = 65535; + if (!this.stream) + throw new Error("stream not initialized"); + if (index[0] < 8) { + temp[0] <<= 8; + input = this.stream.get8(); + if (input === 255) { + this.marker = this.stream.get8(); + if (this.marker !== 0) { + this.markerIndex = 9; + } + } + temp[0] |= input; + } else { + index[0] -= 8; + } + code = table[temp[0] >> index[0]]; + if ((code & _Decoder.MSB) !== 0) { + if (this.markerIndex !== 0) { + this.markerIndex = 0; + return 65280 | this.marker; + } + temp[0] &= mask >> 16 - index[0]; + temp[0] <<= 8; + input = this.stream.get8(); + if (input === 255) { + this.marker = this.stream.get8(); + if (this.marker !== 0) { + this.markerIndex = 9; + } + } + temp[0] |= input; + code = table[(code & 255) * 256 + (temp[0] >> index[0])]; + index[0] += 8; + } + index[0] += 8 - (code >> 8); + if (index[0] < 0) { + throw new Error("index=" + index[0] + " temp=" + temp[0] + " code=" + code + " in HuffmanValue()"); + } + if (index[0] < this.markerIndex) { + this.markerIndex = 0; + return 65280 | this.marker; + } + temp[0] &= mask >> 16 - index[0]; + return code & 255; + } + getn(PRED, n, temp, index) { + let result, input; + const one = 1; + const n_one = -1; + const mask = 65535; + if (this.stream === null) + throw new Error("stream not initialized"); + if (n === 0) { + return 0; + } + if (n === 16) { + if (PRED[0] >= 0) { + return -32768; + } else { + return 32768; + } + } + index[0] -= n; + if (index[0] >= 0) { + if (index[0] < this.markerIndex && !this.isLastPixel()) { + this.markerIndex = 0; + return (65280 | this.marker) << 8; + } + result = temp[0] >> index[0]; + temp[0] &= mask >> 16 - index[0]; + } else { + temp[0] <<= 8; + input = this.stream.get8(); + if (input === 255) { + this.marker = this.stream.get8(); + if (this.marker !== 0) { + this.markerIndex = 9; + } + } + temp[0] |= input; + index[0] += 8; + if (index[0] < 0) { + if (this.markerIndex !== 0) { + this.markerIndex = 0; + return (65280 | this.marker) << 8; + } + temp[0] <<= 8; + input = this.stream.get8(); + if (input === 255) { + this.marker = this.stream.get8(); + if (this.marker !== 0) { + this.markerIndex = 9; + } + } + temp[0] |= input; + index[0] += 8; + } + if (index[0] < 0) { + throw new Error("index=" + index[0] + " in getn()"); + } + if (index[0] < this.markerIndex) { + this.markerIndex = 0; + return (65280 | this.marker) << 8; + } + result = temp[0] >> index[0]; + temp[0] &= mask >> 16 - index[0]; + } + if (result < one << n - 1) { + result += (n_one << n) + 1; + } + return result; + } + getPreviousX(compOffset = 0) { + if (this.getter === null) + throw new Error("decode hasn't run yet"); + if (this.xLoc > 0) { + return this.getter(this.yLoc * this.xDim + this.xLoc - 1, compOffset); + } else if (this.yLoc > 0) { + return this.getPreviousY(compOffset); + } else { + return 1 << this.frame.precision - 1; + } + } + getPreviousXY(compOffset = 0) { + if (this.getter === null) + throw new Error("decode hasn't run yet"); + if (this.xLoc > 0 && this.yLoc > 0) { + return this.getter((this.yLoc - 1) * this.xDim + this.xLoc - 1, compOffset); + } else { + return this.getPreviousY(compOffset); + } + } + getPreviousY(compOffset = 0) { + if (this.getter === null) + throw new Error("decode hasn't run yet"); + if (this.yLoc > 0) { + return this.getter((this.yLoc - 1) * this.xDim + this.xLoc, compOffset); + } else { + return this.getPreviousX(compOffset); + } + } + isLastPixel() { + return this.xLoc === this.xDim - 1 && this.yLoc === this.yDim - 1; + } + outputSingle(PRED) { + if (this.setter === null) + throw new Error("decode hasn't run yet"); + if (this.xLoc < this.xDim && this.yLoc < this.yDim) { + this.setter(this.yLoc * this.xDim + this.xLoc, this.mask & PRED[0]); + this.xLoc += 1; + if (this.xLoc >= this.xDim) { + this.yLoc += 1; + this.xLoc = 0; + } + } + } + outputRGB(PRED) { + if (this.setter === null) + throw new Error("decode hasn't run yet"); + const offset = this.yLoc * this.xDim + this.xLoc; + if (this.xLoc < this.xDim && this.yLoc < this.yDim) { + this.setter(offset, PRED[0], 0); + this.setter(offset, PRED[1], 1); + this.setter(offset, PRED[2], 2); + this.xLoc += 1; + if (this.xLoc >= this.xDim) { + this.yLoc += 1; + this.xLoc = 0; + } + } + } + setValue8(index, val) { + if (!this.outputData) + throw new Error("output data not ready"); + if (littleEndian) { + this.outputData[index] = val; + } else { + this.outputData[index] = (val & 255) << 8 | val >> 8 & 255; + } + } + getValue8(index) { + if (this.outputData === null) + throw new Error("output data not ready"); + if (littleEndian) { + return this.outputData[index]; + } else { + const val = this.outputData[index]; + return (val & 255) << 8 | val >> 8 & 255; + } + } + setValueRGB(index, val, compOffset = 0) { + if (this.outputData === null) + return; + this.outputData[index * 3 + compOffset] = val; + } + getValueRGB(index, compOffset) { + if (this.outputData === null) + throw new Error("output data not ready"); + return this.outputData[index * 3 + compOffset]; + } + readApp() { + if (this.stream === null) + return null; + let count = 0; + const length = this.stream.get16(); + count += 2; + while (count < length) { + this.stream.get8(); + count += 1; + } + return length; + } + readComment() { + if (this.stream === null) + return null; + let sb = ""; + let count = 0; + const length = this.stream.get16(); + count += 2; + while (count < length) { + sb += this.stream.get8(); + count += 1; + } + return sb; + } + readNumber() { + if (this.stream === null) + return null; + const Ld = this.stream.get16(); + if (Ld !== 4) { + throw new Error("ERROR: Define number format throw new IOException [Ld!=4]"); + } + return this.stream.get16(); + } +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + ComponentSpec, + DataStream, + Decoder, + FrameHeader, + HuffmanTable, + QuantizationTable, + ScanComponent, + ScanHeader, + Utils +}); +//# sourceMappingURL=lossless.cjs.map \ No newline at end of file diff --git a/release/cjs/lossless.cjs.map b/release/cjs/lossless.cjs.map new file mode 100644 index 0000000..3e27acb --- /dev/null +++ b/release/cjs/lossless.cjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/main.ts","../../src/component-spec.ts","../../src/data-stream.ts","../../src/frame-header.ts","../../src/utils.ts","../../src/huffman-table.ts","../../src/quantization-table.ts","../../src/scan-component.ts","../../src/scan-header.ts","../../src/decoder.ts"],"sourcesContent":["export { ComponentSpec } from './component-spec.js'\nexport { DataStream } from './data-stream.js'\nexport { Decoder } from './decoder.js'\nexport { FrameHeader } from './frame-header.js'\nexport { HuffmanTable } from './huffman-table.js'\nexport { QuantizationTable } from './quantization-table.js'\nexport { ScanComponent } from './scan-component.js'\nexport { ScanHeader } from './scan-header.js'\nexport * as Utils from './utils.js'\n","export const ComponentSpec = {\n hSamp: 0,\n quantTableSel: 0,\n vSamp: 0\n}\n","export class DataStream {\n buffer: Uint8Array\n index: number\n\n constructor(data: ArrayBuffer, offset?: number, length?: number) {\n this.buffer = new Uint8Array(data, offset, length)\n this.index = 0\n }\n\n get16() {\n // var value = this.buffer.getUint16(this.index, false);\n const value = (this.buffer[this.index] << 8) + this.buffer[this.index + 1] // DataView is big-endian by default\n this.index += 2\n return value\n }\n\n get8() {\n // var value = this.buffer.getUint8(this.index);\n const value = this.buffer[this.index]\n this.index += 1\n return value\n }\n}\n","import { ComponentSpec } from './component-spec.js'\nimport { DataStream } from './data-stream.js'\n\nexport class FrameHeader {\n dimX = 0\n dimY = 0\n numComp = 0\n precision = 0\n components: Array = []\n\n read(data: DataStream) {\n let count = 0\n let temp\n\n const length = data.get16()\n count += 2\n\n this.precision = data.get8()\n count += 1\n\n this.dimY = data.get16()\n count += 2\n\n this.dimX = data.get16()\n count += 2\n\n this.numComp = data.get8()\n count += 1\n for (let i = 1; i <= this.numComp; i += 1) {\n if (count > length) {\n throw new Error('ERROR: frame format error')\n }\n\n const c = data.get8()\n count += 1\n\n if (count >= length) {\n throw new Error('ERROR: frame format error [c>=Lf]')\n }\n\n temp = data.get8()\n count += 1\n\n if (!this.components[c]) {\n this.components[c] = { ...ComponentSpec }\n }\n\n this.components[c].hSamp = temp >> 4\n this.components[c].vSamp = temp & 0x0f\n this.components[c].quantTableSel = data.get8()\n count += 1\n }\n\n if (count !== length) {\n throw new Error('ERROR: frame format error [Lf!=count]')\n }\n\n return 1\n }\n}\n","type NestedArray = Array>\n\n// https://stackoverflow.com/a/12588826\nexport const createArray = (...dimensions: number[]): NestedArray => {\n if (dimensions.length > 1) {\n const dim = dimensions[0]\n const rest = dimensions.slice(1)\n const newArray = []\n for (let i = 0; i < dim; i++) {\n newArray[i] = createArray(...rest)\n }\n return newArray\n } else {\n return Array(dimensions[0]).fill(undefined)\n }\n}\n\n// http://stackoverflow.com/questions/18638900/javascript-crc32\nexport const makeCRCTable = function () {\n let c\n const crcTable = []\n for (let n = 0; n < 256; n++) {\n c = n\n for (let k = 0; k < 8; k++) {\n c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1\n }\n crcTable[n] = c\n }\n return crcTable\n}\n\nexport const crcTable = makeCRCTable()\n\nexport const crc32 = function (buffer: ArrayBuffer) {\n const uint8view = new Uint8Array(buffer)\n let crc = 0 ^ -1\n\n for (let i = 0; i < uint8view.length; i++) {\n crc = (crc >>> 8) ^ crcTable[(crc ^ uint8view[i]) & 0xff]\n }\n\n return (crc ^ -1) >>> 0\n}\n","import { DataStream } from './data-stream.js'\nimport { createArray } from './utils.js'\n\nexport class HuffmanTable {\n static MSB = 0x80000000\n\n l: number[][][]\n th: number[]\n v: number[][][][]\n tc: number[][]\n\n constructor() {\n this.l = createArray(4, 2, 16) as number[][][]\n this.th = [0, 0, 0, 0]\n this.v = createArray(4, 2, 16, 200) as number[][][][]\n this.tc = [\n [0, 0],\n [0, 0],\n [0, 0],\n [0, 0]\n ]\n }\n\n read(data: DataStream, HuffTab: number[][][]) {\n let count = 0\n let temp\n let t\n let c\n let i\n let j\n\n const length = data.get16()\n count += 2\n\n while (count < length) {\n temp = data.get8()\n count += 1\n t = temp & 0x0f\n if (t > 3) {\n throw new Error('ERROR: Huffman table ID > 3')\n }\n\n c = temp >> 4\n if (c > 2) {\n throw new Error('ERROR: Huffman table [Table class > 2 ]')\n }\n\n this.th[t] = 1\n this.tc[t][c] = 1\n\n for (i = 0; i < 16; i += 1) {\n this.l[t][c][i] = data.get8()\n count += 1\n }\n\n for (i = 0; i < 16; i += 1) {\n for (j = 0; j < this.l[t][c][i]; j += 1) {\n if (count > length) {\n throw new Error('ERROR: Huffman table format error [count>Lh]')\n }\n\n this.v[t][c][i][j] = data.get8()\n count += 1\n }\n }\n }\n\n if (count !== length) {\n throw new Error('ERROR: Huffman table format error [count!=Lf]')\n }\n\n for (i = 0; i < 4; i += 1) {\n for (j = 0; j < 2; j += 1) {\n if (this.tc[i][j] !== 0) {\n this.buildHuffTable(HuffTab[i][j], this.l[i][j], this.v[i][j])\n }\n }\n }\n\n return 1\n }\n\n //\tBuild_HuffTab()\n //\tParameter: t table ID\n //\t c table class ( 0 for DC, 1 for AC )\n //\t L[i] # of codewords which length is i\n //\t V[i][j] Huffman Value (length=i)\n //\tEffect:\n //\t build up HuffTab[t][c] using L and V.\n buildHuffTable(tab: number[], L: number[], V: number[][]) {\n let currentTable, k, i, j, n\n const temp = 256\n k = 0\n\n for (i = 0; i < 8; i += 1) {\n // i+1 is Code length\n for (j = 0; j < L[i]; j += 1) {\n for (n = 0; n < temp >> (i + 1); n += 1) {\n tab[k] = V[i][j] | ((i + 1) << 8)\n k += 1\n }\n }\n }\n\n for (i = 1; k < 256; i += 1, k += 1) {\n tab[k] = i | HuffmanTable.MSB\n }\n\n currentTable = 1\n k = 0\n\n for (i = 8; i < 16; i += 1) {\n // i+1 is Code length\n for (j = 0; j < L[i]; j += 1) {\n for (n = 0; n < temp >> (i - 7); n += 1) {\n tab[currentTable * 256 + k] = V[i][j] | ((i + 1) << 8)\n k += 1\n }\n\n if (k >= 256) {\n if (k > 256) {\n throw new Error('ERROR: Huffman table error(1)!')\n }\n\n k = 0\n currentTable += 1\n }\n }\n }\n }\n}\n","import { DataStream } from './data-stream.js'\nimport { createArray } from './utils.js'\n\nexport class QuantizationTable {\n precision: number[] = [] // Quantization precision 8 or 16\n tq = [0, 0, 0, 0] // 1: this table is presented\n quantTables: number[][] = createArray(4, 64) as number[][] // Tables\n\n static enhanceQuantizationTable = function (qtab: number[], table: number[]) {\n for (let i = 0; i < 8; i += 1) {\n qtab[table[0 * 8 + i]] *= 90\n qtab[table[4 * 8 + i]] *= 90\n qtab[table[2 * 8 + i]] *= 118\n qtab[table[6 * 8 + i]] *= 49\n qtab[table[5 * 8 + i]] *= 71\n qtab[table[1 * 8 + i]] *= 126\n qtab[table[7 * 8 + i]] *= 25\n qtab[table[3 * 8 + i]] *= 106\n }\n\n for (let i = 0; i < 8; i += 1) {\n qtab[table[0 + 8 * i]] *= 90\n qtab[table[4 + 8 * i]] *= 90\n qtab[table[2 + 8 * i]] *= 118\n qtab[table[6 + 8 * i]] *= 49\n qtab[table[5 + 8 * i]] *= 71\n qtab[table[1 + 8 * i]] *= 126\n qtab[table[7 + 8 * i]] *= 25\n qtab[table[3 + 8 * i]] *= 106\n }\n\n for (let i = 0; i < 64; i += 1) {\n qtab[i] >>= 6\n }\n }\n\n read(data: DataStream, table: number[]) {\n let count = 0\n let temp\n let t\n let i\n\n const length = data.get16()\n count += 2\n\n while (count < length) {\n temp = data.get8()\n count += 1\n t = temp & 0x0f\n\n if (t > 3) {\n throw new Error('ERROR: Quantization table ID > 3')\n }\n\n this.precision[t] = temp >> 4\n\n if (this.precision[t] === 0) {\n this.precision[t] = 8\n } else if (this.precision[t] === 1) {\n this.precision[t] = 16\n } else {\n throw new Error('ERROR: Quantization table precision error')\n }\n\n this.tq[t] = 1\n\n if (this.precision[t] === 8) {\n for (i = 0; i < 64; i += 1) {\n if (count > length) {\n throw new Error('ERROR: Quantization table format error')\n }\n\n this.quantTables[t][i] = data.get8()\n count += 1\n }\n\n QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table)\n } else {\n for (i = 0; i < 64; i += 1) {\n if (count > length) {\n throw new Error('ERROR: Quantization table format error')\n }\n\n this.quantTables[t][i] = data.get16()\n count += 2\n }\n\n QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table)\n }\n }\n\n if (count !== length) {\n throw new Error('ERROR: Quantization table error [count!=Lq]')\n }\n\n return 1\n }\n}\n","export const ScanComponent = {\n acTabSel: 0, // AC table selector\n dcTabSel: 0, // DC table selector\n scanCompSel: 0 // Scan component selector\n}\n","import { DataStream } from './data-stream.js'\nimport { ScanComponent } from './scan-component.js'\n\nexport class ScanHeader {\n ah = 0\n al = 0\n numComp = 0 // Number of components in the scan\n selection = 0 // Start of spectral or predictor selection\n spectralEnd = 0 // End of spectral selection\n components: Array = []\n\n read(data: DataStream) {\n let count = 0\n let i\n let temp\n\n const length = data.get16()\n count += 2\n\n this.numComp = data.get8()\n count += 1\n\n for (i = 0; i < this.numComp; i += 1) {\n this.components[i] = { ...ScanComponent }\n\n if (count > length) {\n throw new Error('ERROR: scan header format error')\n }\n\n this.components[i].scanCompSel = data.get8()\n count += 1\n\n temp = data.get8()\n count += 1\n\n this.components[i].dcTabSel = temp >> 4\n this.components[i].acTabSel = temp & 0x0f\n }\n\n this.selection = data.get8()\n count += 1\n\n this.spectralEnd = data.get8()\n count += 1\n\n temp = data.get8()\n this.ah = temp >> 4\n this.al = temp & 0x0f\n count += 1\n\n if (count !== length) {\n throw new Error('ERROR: scan header format error [count!=Ns]')\n }\n\n return 1\n }\n}\n","import { ComponentSpec } from './component-spec.js'\nimport { DataStream } from './data-stream.js'\nimport { FrameHeader } from './frame-header.js'\nimport { HuffmanTable } from './huffman-table.js'\nimport { QuantizationTable } from './quantization-table.js'\nimport { ScanHeader } from './scan-header.js'\nimport { createArray } from './utils.js'\n\nconst littleEndian = (function () {\n const buffer = new ArrayBuffer(2)\n new DataView(buffer).setInt16(0, 256, true /* littleEndian */)\n // Int16Array uses the platform's endianness.\n return new Int16Array(buffer)[0] === 256\n})()\n\nexport class Decoder {\n static IDCT_P = [\n 0, 5, 40, 16, 45, 2, 7, 42, 21, 56, 8, 61, 18, 47, 1, 4, 41, 23, 58, 13, 32, 24, 37, 10, 63, 17, 44, 3, 6, 43, 20,\n 57, 15, 34, 29, 48, 53, 26, 39, 9, 60, 19, 46, 22, 59, 12, 33, 31, 50, 55, 25, 36, 11, 62, 14, 35, 28, 49, 52, 27,\n 38, 30, 51, 54\n ]\n\n static TABLE = [\n 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44,\n 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49,\n 57, 58, 62, 63\n ]\n\n static MAX_HUFFMAN_SUBTREE = 50\n static MSB = 0x80000000\n static RESTART_MARKER_BEGIN = 0xffd0\n static RESTART_MARKER_END = 0xffd7\n\n buffer: ArrayBuffer | null = null\n stream: DataStream | null = null\n frame = new FrameHeader()\n huffTable = new HuffmanTable()\n quantTable = new QuantizationTable()\n scan = new ScanHeader()\n DU: number[][][] = createArray(10, 4, 64) as number[][][] // at most 10 data units in a MCU, at most 4 data units in one component\n HuffTab: number[][][] = createArray(4, 2, 50 * 256) as number[][][]\n IDCT_Source: number[] = []\n nBlock: number[] = [] // number of blocks in the i-th Comp in a scan\n acTab: number[][] = createArray(10, 1) as number[][] // ac HuffTab for the i-th Comp in a scan\n dcTab: number[][] = createArray(10, 1) as number[][] // dc HuffTab for the i-th Comp in a scan\n qTab: number[][] = createArray(10, 1) as number[][] // quantization table for the i-th Comp in a scan\n marker = 0\n markerIndex = 0\n numComp = 0\n restartInterval = 0\n selection = 0\n xDim = 0\n yDim = 0\n xLoc = 0\n yLoc = 0\n outputData: Uint8Array | Uint16Array | null = null\n restarting = false\n mask = 0\n numBytes = 0\n\n precision: number | undefined = undefined\n components: Array = []\n\n getter: null | ((index: number, compOffset: number) => number) = null\n setter: null | ((index: number, val: number, compOffset?: number) => void) = null\n output: null | ((PRED: number[]) => void) = null\n selector: null | ((compOffset?: number) => number) = null\n\n /**\n * The Decoder constructor.\n * @property {number} numBytes - number of bytes per component\n * @type {Function}\n */\n constructor(buffer?: ArrayBuffer | null, numBytes?: number) {\n this.buffer = buffer ?? null\n this.numBytes = numBytes ?? 0\n }\n\n /**\n * Returns decompressed data.\n */\n decompress(buffer: ArrayBuffer, offset: number, length: number): ArrayBuffer {\n const result = this.decode(buffer, offset, length)\n return result.buffer\n }\n\n decode(buffer?: ArrayBuffer, offset?: number, length?: number, numBytes?: number) {\n let scanNum = 0\n const pred = []\n let i\n let compN\n const temp = []\n const index = []\n let mcuNum\n\n if (buffer) {\n this.buffer = buffer\n }\n\n if (numBytes !== undefined) {\n this.numBytes = numBytes\n }\n\n this.stream = new DataStream(this.buffer as ArrayBuffer, offset, length)\n this.buffer = null\n\n this.xLoc = 0\n this.yLoc = 0\n let current = this.stream.get16()\n\n if (current !== 0xffd8) {\n // SOI\n throw new Error('Not a JPEG file')\n }\n\n current = this.stream.get16()\n\n while (current >> 4 !== 0x0ffc || current === 0xffc4) {\n // SOF 0~15\n switch (current) {\n case 0xffc4: // DHT\n this.huffTable.read(this.stream, this.HuffTab)\n break\n case 0xffcc: // DAC\n throw new Error(\"Program doesn't support arithmetic coding. (format throw new IOException)\")\n case 0xffdb:\n this.quantTable.read(this.stream, Decoder.TABLE)\n break\n case 0xffdd:\n this.restartInterval = this.readNumber() ?? 0\n break\n case 0xffe0:\n case 0xffe1:\n case 0xffe2:\n case 0xffe3:\n case 0xffe4:\n case 0xffe5:\n case 0xffe6:\n case 0xffe7:\n case 0xffe8:\n case 0xffe9:\n case 0xffea:\n case 0xffeb:\n case 0xffec:\n case 0xffed:\n case 0xffee:\n case 0xffef:\n this.readApp()\n break\n case 0xfffe:\n this.readComment()\n break\n default:\n if (current >> 8 !== 0xff) {\n throw new Error('ERROR: format throw new IOException! (decode)')\n }\n }\n\n current = this.stream.get16()\n }\n\n if (current < 0xffc0 || current > 0xffc7) {\n throw new Error('ERROR: could not handle arithmetic code!')\n }\n\n this.frame.read(this.stream)\n current = this.stream.get16()\n\n do {\n while (current !== 0x0ffda) {\n // SOS\n switch (current) {\n case 0xffc4: // DHT\n this.huffTable.read(this.stream, this.HuffTab)\n break\n case 0xffcc: // DAC\n throw new Error(\"Program doesn't support arithmetic coding. (format throw new IOException)\")\n case 0xffdb:\n this.quantTable.read(this.stream, Decoder.TABLE)\n break\n case 0xffdd:\n this.restartInterval = this.readNumber() ?? 0\n break\n case 0xffe0:\n case 0xffe1:\n case 0xffe2:\n case 0xffe3:\n case 0xffe4:\n case 0xffe5:\n case 0xffe6:\n case 0xffe7:\n case 0xffe8:\n case 0xffe9:\n case 0xffea:\n case 0xffeb:\n case 0xffec:\n case 0xffed:\n case 0xffee:\n case 0xffef:\n this.readApp()\n break\n case 0xfffe:\n this.readComment()\n break\n default:\n if (current >> 8 !== 0xff) {\n throw new Error('ERROR: format throw new IOException! (Parser.decode)')\n }\n }\n\n current = this.stream.get16()\n }\n\n this.precision = this.frame.precision\n this.components = this.frame.components\n\n if (!this.numBytes) {\n this.numBytes = Math.round(Math.ceil(this.precision / 8))\n }\n\n if (this.numBytes === 1) {\n this.mask = 0xff\n } else {\n this.mask = 0xffff\n }\n\n this.scan.read(this.stream)\n this.numComp = this.scan.numComp\n this.selection = this.scan.selection\n\n if (this.numBytes === 1) {\n if (this.numComp === 3) {\n this.getter = this.getValueRGB\n this.setter = this.setValueRGB\n this.output = this.outputRGB\n } else {\n this.getter = this.getValue8\n this.setter = this.setValue8\n this.output = this.outputSingle\n }\n } else {\n this.getter = this.getValue8\n this.setter = this.setValue8\n this.output = this.outputSingle\n }\n\n switch (this.selection) {\n case 2:\n this.selector = this.select2\n break\n case 3:\n this.selector = this.select3\n break\n case 4:\n this.selector = this.select4\n break\n case 5:\n this.selector = this.select5\n break\n case 6:\n this.selector = this.select6\n break\n case 7:\n this.selector = this.select7\n break\n default:\n this.selector = this.select1\n break\n }\n\n // this.scanComps = this.scan.components\n // this.quantTables = this.quantTable.quantTables\n\n for (i = 0; i < this.numComp; i += 1) {\n compN = this.scan.components[i].scanCompSel\n this.qTab[i] = this.quantTable.quantTables[this.components[compN].quantTableSel]\n this.nBlock[i] = this.components[compN].vSamp * this.components[compN].hSamp\n this.dcTab[i] = this.HuffTab[this.scan.components[i].dcTabSel][0]\n this.acTab[i] = this.HuffTab[this.scan.components[i].acTabSel][1]\n }\n\n this.xDim = this.frame.dimX\n this.yDim = this.frame.dimY\n if (this.numBytes === 1) {\n this.outputData = new Uint8Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp))\n } else {\n this.outputData = new Uint16Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp))\n }\n\n scanNum += 1\n\n while (true) {\n // Decode one scan\n temp[0] = 0\n index[0] = 0\n\n for (i = 0; i < 10; i += 1) {\n pred[i] = 1 << (this.precision - 1)\n }\n\n if (this.restartInterval === 0) {\n current = this.decodeUnit(pred, temp, index)\n\n while (current === 0 && this.xLoc < this.xDim && this.yLoc < this.yDim) {\n this.output(pred)\n current = this.decodeUnit(pred, temp, index)\n }\n\n break // current=MARKER\n }\n\n for (mcuNum = 0; mcuNum < this.restartInterval; mcuNum += 1) {\n this.restarting = mcuNum === 0\n current = this.decodeUnit(pred, temp, index)\n this.output(pred)\n\n if (current !== 0) {\n break\n }\n }\n\n if (current === 0) {\n if (this.markerIndex !== 0) {\n current = 0xff00 | this.marker\n this.markerIndex = 0\n } else {\n current = this.stream.get16()\n }\n }\n\n if (!(current >= Decoder.RESTART_MARKER_BEGIN && current <= Decoder.RESTART_MARKER_END)) {\n break // current=MARKER\n }\n }\n\n if (current === 0xffdc && scanNum === 1) {\n // DNL\n this.readNumber()\n current = this.stream.get16()\n }\n } while (current !== 0xffd9 && this.xLoc < this.xDim && this.yLoc < this.yDim && scanNum === 0)\n\n return this.outputData\n }\n\n decodeUnit(prev: number[], temp: number[], index: number[]): number {\n if (this.numComp === 1) {\n return this.decodeSingle(prev, temp, index)\n } else if (this.numComp === 3) {\n return this.decodeRGB(prev, temp, index)\n } else {\n return -1\n }\n }\n\n select1(compOffset?: number) {\n return this.getPreviousX(compOffset)\n }\n\n select2(compOffset?: number) {\n return this.getPreviousY(compOffset)\n }\n\n select3(compOffset?: number) {\n return this.getPreviousXY(compOffset)\n }\n\n select4(compOffset?: number) {\n return this.getPreviousX(compOffset) + this.getPreviousY(compOffset) - this.getPreviousXY(compOffset)\n }\n\n select5(compOffset?: number) {\n return this.getPreviousX(compOffset) + ((this.getPreviousY(compOffset) - this.getPreviousXY(compOffset)) >> 1)\n }\n\n select6(compOffset?: number) {\n return this.getPreviousY(compOffset) + ((this.getPreviousX(compOffset) - this.getPreviousXY(compOffset)) >> 1)\n }\n\n select7(compOffset?: number) {\n return (this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) / 2\n }\n\n decodeRGB(prev: number[], temp: number[], index: number[]) {\n if (this.selector === null) throw new Error(\"decode hasn't run yet\")\n\n let actab, dctab, qtab, ctrC, i, k, j\n\n prev[0] = this.selector(0)\n prev[1] = this.selector(1)\n prev[2] = this.selector(2)\n\n for (ctrC = 0; ctrC < this.numComp; ctrC += 1) {\n qtab = this.qTab[ctrC]\n actab = this.acTab[ctrC]\n dctab = this.dcTab[ctrC]\n for (i = 0; i < this.nBlock[ctrC]; i += 1) {\n for (k = 0; k < this.IDCT_Source.length; k += 1) {\n this.IDCT_Source[k] = 0\n }\n\n let value = this.getHuffmanValue(dctab, temp, index)\n\n if (value >= 0xff00) {\n return value\n }\n\n prev[ctrC] = this.IDCT_Source[0] = prev[ctrC] + this.getn(index, value, temp, index)\n this.IDCT_Source[0] *= qtab[0]\n\n for (j = 1; j < 64; j += 1) {\n value = this.getHuffmanValue(actab, temp, index)\n\n if (value >= 0xff00) {\n return value\n }\n\n j += value >> 4\n\n if ((value & 0x0f) === 0) {\n if (value >> 4 === 0) {\n break\n }\n } else {\n this.IDCT_Source[Decoder.IDCT_P[j]] = this.getn(index, value & 0x0f, temp, index) * qtab[j]\n }\n }\n }\n }\n\n return 0\n }\n\n decodeSingle(prev: number[], temp: number[], index: number[]) {\n if (this.selector === null) throw new Error(\"decode hasn't run yet\")\n\n let value, i, n, nRestart\n\n if (this.restarting) {\n this.restarting = false\n prev[0] = 1 << (this.frame.precision - 1)\n } else {\n prev[0] = this.selector()\n }\n\n for (i = 0; i < this.nBlock[0]; i += 1) {\n value = this.getHuffmanValue(this.dcTab[0], temp, index)\n if (value >= 0xff00) {\n return value\n }\n\n n = this.getn(prev, value, temp, index)\n nRestart = n >> 8\n\n if (nRestart >= Decoder.RESTART_MARKER_BEGIN && nRestart <= Decoder.RESTART_MARKER_END) {\n return nRestart\n }\n\n prev[0] += n\n }\n\n return 0\n }\n\n //\tHuffman table for fast search: (HuffTab) 8-bit Look up table 2-layer search architecture, 1st-layer represent 256 node (8 bits) if codeword-length > 8\n //\tbits, then the entry of 1st-layer = (# of 2nd-layer table) | MSB and it is stored in the 2nd-layer Size of tables in each layer are 256.\n //\tHuffTab[*][*][0-256] is always the only 1st-layer table.\n //\n //\tAn entry can be: (1) (# of 2nd-layer table) | MSB , for code length > 8 in 1st-layer (2) (Code length) << 8 | HuffVal\n //\n //\tHuffmanValue(table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)\n //\t ):\n //\t return: Huffman Value of table\n //\t 0xFF?? if it receives a MARKER\n //\t Parameter: table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)\n //\t temp temp storage for remainded bits\n //\t index index to bit of temp\n //\t in FILE pointer\n //\t Effect:\n //\t temp store new remainded bits\n //\t index change to new index\n //\t in change to new position\n //\t NOTE:\n //\t Initial by temp=0; index=0;\n //\t NOTE: (explain temp and index)\n //\t temp: is always in the form at calling time or returning time\n //\t | byte 4 | byte 3 | byte 2 | byte 1 |\n //\t | 0 | 0 | 00000000 | 00000??? | if not a MARKER\n //\t ^index=3 (from 0 to 15)\n //\t 321\n //\t NOTE (marker and marker_index):\n //\t If get a MARKER from 'in', marker=the low-byte of the MARKER\n //\t and marker_index=9\n //\t If marker_index=9 then index is always > 8, or HuffmanValue()\n //\t will not be called\n getHuffmanValue(table: number[], temp: number[], index: number[]): number {\n let code, input\n const mask = 0xffff\n\n if (!this.stream) throw new Error('stream not initialized')\n\n if (index[0] < 8) {\n temp[0] <<= 8\n input = this.stream.get8()\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n temp[0] |= input\n } else {\n index[0] -= 8\n }\n\n code = table[temp[0] >> index[0]]\n\n if ((code & Decoder.MSB) !== 0) {\n if (this.markerIndex !== 0) {\n this.markerIndex = 0\n return 0xff00 | this.marker\n }\n\n temp[0] &= mask >> (16 - index[0])\n temp[0] <<= 8\n input = this.stream.get8()\n\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n\n temp[0] |= input\n code = table[(code & 0xff) * 256 + (temp[0] >> index[0])]\n index[0] += 8\n }\n\n index[0] += 8 - (code >> 8)\n\n if (index[0] < 0) {\n throw new Error('index=' + index[0] + ' temp=' + temp[0] + ' code=' + code + ' in HuffmanValue()')\n }\n\n if (index[0] < this.markerIndex) {\n this.markerIndex = 0\n return 0xff00 | this.marker\n }\n\n temp[0] &= mask >> (16 - index[0])\n return code & 0xff\n }\n\n getn(PRED: number[], n: number, temp: number[], index: number[]) {\n let result, input\n const one = 1\n const n_one = -1\n const mask = 0xffff\n\n if (this.stream === null) throw new Error('stream not initialized')\n\n if (n === 0) {\n return 0\n }\n\n if (n === 16) {\n if (PRED[0] >= 0) {\n return -32768\n } else {\n return 32768\n }\n }\n\n index[0] -= n\n\n if (index[0] >= 0) {\n if (index[0] < this.markerIndex && !this.isLastPixel()) {\n // this was corrupting the last pixel in some cases\n this.markerIndex = 0\n return (0xff00 | this.marker) << 8\n }\n\n result = temp[0] >> index[0]\n temp[0] &= mask >> (16 - index[0])\n } else {\n temp[0] <<= 8\n input = this.stream.get8()\n\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n\n temp[0] |= input\n index[0] += 8\n\n if (index[0] < 0) {\n if (this.markerIndex !== 0) {\n this.markerIndex = 0\n return (0xff00 | this.marker) << 8\n }\n\n temp[0] <<= 8\n input = this.stream.get8()\n\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n\n temp[0] |= input\n index[0] += 8\n }\n\n if (index[0] < 0) {\n throw new Error('index=' + index[0] + ' in getn()')\n }\n\n if (index[0] < this.markerIndex) {\n this.markerIndex = 0\n return (0xff00 | this.marker) << 8\n }\n\n result = temp[0] >> index[0]\n temp[0] &= mask >> (16 - index[0])\n }\n\n if (result < one << (n - 1)) {\n result += (n_one << n) + 1\n }\n\n return result\n }\n\n getPreviousX(compOffset = 0): number {\n if (this.getter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.xLoc > 0) {\n return this.getter(this.yLoc * this.xDim + this.xLoc - 1, compOffset)\n } else if (this.yLoc > 0) {\n return this.getPreviousY(compOffset)\n } else {\n return 1 << (this.frame.precision - 1)\n }\n }\n\n getPreviousXY(compOffset = 0) {\n if (this.getter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.xLoc > 0 && this.yLoc > 0) {\n return this.getter((this.yLoc - 1) * this.xDim + this.xLoc - 1, compOffset)\n } else {\n return this.getPreviousY(compOffset)\n }\n }\n\n getPreviousY(compOffset = 0) {\n if (this.getter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.yLoc > 0) {\n return this.getter((this.yLoc - 1) * this.xDim + this.xLoc, compOffset)\n } else {\n return this.getPreviousX(compOffset)\n }\n }\n\n isLastPixel() {\n return this.xLoc === this.xDim - 1 && this.yLoc === this.yDim - 1\n }\n\n outputSingle(PRED: number[]) {\n if (this.setter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.xLoc < this.xDim && this.yLoc < this.yDim) {\n this.setter(this.yLoc * this.xDim + this.xLoc, this.mask & PRED[0])\n\n this.xLoc += 1\n\n if (this.xLoc >= this.xDim) {\n this.yLoc += 1\n this.xLoc = 0\n }\n }\n }\n\n outputRGB(PRED: number[]) {\n if (this.setter === null) throw new Error(\"decode hasn't run yet\")\n\n const offset = this.yLoc * this.xDim + this.xLoc\n\n if (this.xLoc < this.xDim && this.yLoc < this.yDim) {\n this.setter(offset, PRED[0], 0)\n this.setter(offset, PRED[1], 1)\n this.setter(offset, PRED[2], 2)\n\n this.xLoc += 1\n\n if (this.xLoc >= this.xDim) {\n this.yLoc += 1\n this.xLoc = 0\n }\n }\n }\n\n setValue8(index: number, val: number) {\n if (!this.outputData) throw new Error('output data not ready')\n\n if (littleEndian) {\n this.outputData[index] = val\n } else {\n this.outputData[index] = ((val & 0xff) << 8) | ((val >> 8) & 0xff)\n }\n }\n\n getValue8(index: number) {\n if (this.outputData === null) throw new Error('output data not ready')\n if (littleEndian) {\n return this.outputData[index] // mask should not be necessary because outputData is either Int8Array or Int16Array\n } else {\n const val = this.outputData[index]\n return ((val & 0xff) << 8) | ((val >> 8) & 0xff)\n }\n }\n\n setValueRGB(index: number, val: number, compOffset = 0) {\n if (this.outputData === null) return\n this.outputData[index * 3 + compOffset] = val\n }\n\n getValueRGB(index: number, compOffset: number) {\n if (this.outputData === null) throw new Error('output data not ready')\n return this.outputData[index * 3 + compOffset]\n }\n\n readApp() {\n if (this.stream === null) return null\n\n let count = 0\n const length = this.stream.get16()\n count += 2\n\n while (count < length) {\n this.stream.get8()\n count += 1\n }\n\n return length\n }\n\n readComment() {\n if (this.stream === null) return null\n\n let sb = ''\n let count = 0\n\n const length = this.stream.get16()\n count += 2\n\n while (count < length) {\n sb += this.stream.get8()\n count += 1\n }\n\n return sb\n }\n\n readNumber() {\n if (this.stream === null) return null\n\n const Ld = this.stream.get16()\n\n if (Ld !== 4) {\n throw new Error('ERROR: Define number format throw new IOException [Ld!=4]')\n }\n\n return this.stream.get16()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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EA,cAAc;AACZ,QAAI,KAAK,WAAW;AAAM,aAAO;AAEjC,QAAI,KAAK;AACT,QAAI,QAAQ;AAEZ,UAAM,SAAS,KAAK,OAAO,MAAM;AACjC,aAAS;AAET,WAAO,QAAQ,QAAQ;AACrB,YAAM,KAAK,OAAO,KAAK;AACvB,eAAS;AAAA,IACX;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,aAAa;AACX,QAAI,KAAK,WAAW;AAAM,aAAO;AAEjC,UAAM,KAAK,KAAK,OAAO,MAAM;AAE7B,QAAI,OAAO,GAAG;AACZ,YAAM,IAAI,MAAM,2DAA2D;AAAA,IAC7E;AAEA,WAAO,KAAK,OAAO,MAAM;AAAA,EAC3B;AACF;","names":["crcTable"]} \ No newline at end of file diff --git a/tests/bundle.test.ts b/tests/bundle.test.ts new file mode 100644 index 0000000..666eec7 --- /dev/null +++ b/tests/bundle.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from 'vitest' + +// @ts-expect-error -- types will not be found this way, which is fine for this test +import esmLibrary from '..' + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const cjsLibrary = require('..') + +describe('bundling', () => { + it('commonjs export should work', () => { + expect(cjsLibrary.Decoder).toBeDefined() + }) + + it('es module should work', () => { + expect(esmLibrary.Decoder).toBeDefined() + }) +}) diff --git a/tsup.config.ts b/tsup.config.ts index f6da970..54e4f7b 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -31,5 +31,17 @@ export default defineConfig([ clean: false, minify: true, dts: true + }, + { + entry: { + lossless: 'src/main.ts' + }, + target: 'esnext', + format: 'cjs', + outDir: 'release/cjs', + splitting: false, + sourcemap: true, + clean: true, + dts: true } ]) From c5d0e5969e989728ad64e7531c1a7b8b651a75f7 Mon Sep 17 00:00:00 2001 From: Jens Ochsenmeier Date: Thu, 28 Mar 2024 11:00:32 +0100 Subject: [PATCH 3/3] remove map --- .gitignore | 3 ++- release/cjs/lossless.cjs.map | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 release/cjs/lossless.cjs.map diff --git a/.gitignore b/.gitignore index 2afa2cf..3f77dbf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ release.sh .DS_Store *.d.cts *.d.ts -*.js.map \ No newline at end of file +*.js.map +*.cjs.map \ No newline at end of file diff --git a/release/cjs/lossless.cjs.map b/release/cjs/lossless.cjs.map deleted file mode 100644 index 3e27acb..0000000 --- a/release/cjs/lossless.cjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../../src/main.ts","../../src/component-spec.ts","../../src/data-stream.ts","../../src/frame-header.ts","../../src/utils.ts","../../src/huffman-table.ts","../../src/quantization-table.ts","../../src/scan-component.ts","../../src/scan-header.ts","../../src/decoder.ts"],"sourcesContent":["export { ComponentSpec } from './component-spec.js'\nexport { DataStream } from './data-stream.js'\nexport { Decoder } from './decoder.js'\nexport { FrameHeader } from './frame-header.js'\nexport { HuffmanTable } from './huffman-table.js'\nexport { QuantizationTable } from './quantization-table.js'\nexport { ScanComponent } from './scan-component.js'\nexport { ScanHeader } from './scan-header.js'\nexport * as Utils from './utils.js'\n","export const ComponentSpec = {\n hSamp: 0,\n quantTableSel: 0,\n vSamp: 0\n}\n","export class DataStream {\n buffer: Uint8Array\n index: number\n\n constructor(data: ArrayBuffer, offset?: number, length?: number) {\n this.buffer = new Uint8Array(data, offset, length)\n this.index = 0\n }\n\n get16() {\n // var value = this.buffer.getUint16(this.index, false);\n const value = (this.buffer[this.index] << 8) + this.buffer[this.index + 1] // DataView is big-endian by default\n this.index += 2\n return value\n }\n\n get8() {\n // var value = this.buffer.getUint8(this.index);\n const value = this.buffer[this.index]\n this.index += 1\n return value\n }\n}\n","import { ComponentSpec } from './component-spec.js'\nimport { DataStream } from './data-stream.js'\n\nexport class FrameHeader {\n dimX = 0\n dimY = 0\n numComp = 0\n precision = 0\n components: Array = []\n\n read(data: DataStream) {\n let count = 0\n let temp\n\n const length = data.get16()\n count += 2\n\n this.precision = data.get8()\n count += 1\n\n this.dimY = data.get16()\n count += 2\n\n this.dimX = data.get16()\n count += 2\n\n this.numComp = data.get8()\n count += 1\n for (let i = 1; i <= this.numComp; i += 1) {\n if (count > length) {\n throw new Error('ERROR: frame format error')\n }\n\n const c = data.get8()\n count += 1\n\n if (count >= length) {\n throw new Error('ERROR: frame format error [c>=Lf]')\n }\n\n temp = data.get8()\n count += 1\n\n if (!this.components[c]) {\n this.components[c] = { ...ComponentSpec }\n }\n\n this.components[c].hSamp = temp >> 4\n this.components[c].vSamp = temp & 0x0f\n this.components[c].quantTableSel = data.get8()\n count += 1\n }\n\n if (count !== length) {\n throw new Error('ERROR: frame format error [Lf!=count]')\n }\n\n return 1\n }\n}\n","type NestedArray = Array>\n\n// https://stackoverflow.com/a/12588826\nexport const createArray = (...dimensions: number[]): NestedArray => {\n if (dimensions.length > 1) {\n const dim = dimensions[0]\n const rest = dimensions.slice(1)\n const newArray = []\n for (let i = 0; i < dim; i++) {\n newArray[i] = createArray(...rest)\n }\n return newArray\n } else {\n return Array(dimensions[0]).fill(undefined)\n }\n}\n\n// http://stackoverflow.com/questions/18638900/javascript-crc32\nexport const makeCRCTable = function () {\n let c\n const crcTable = []\n for (let n = 0; n < 256; n++) {\n c = n\n for (let k = 0; k < 8; k++) {\n c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1\n }\n crcTable[n] = c\n }\n return crcTable\n}\n\nexport const crcTable = makeCRCTable()\n\nexport const crc32 = function (buffer: ArrayBuffer) {\n const uint8view = new Uint8Array(buffer)\n let crc = 0 ^ -1\n\n for (let i = 0; i < uint8view.length; i++) {\n crc = (crc >>> 8) ^ crcTable[(crc ^ uint8view[i]) & 0xff]\n }\n\n return (crc ^ -1) >>> 0\n}\n","import { DataStream } from './data-stream.js'\nimport { createArray } from './utils.js'\n\nexport class HuffmanTable {\n static MSB = 0x80000000\n\n l: number[][][]\n th: number[]\n v: number[][][][]\n tc: number[][]\n\n constructor() {\n this.l = createArray(4, 2, 16) as number[][][]\n this.th = [0, 0, 0, 0]\n this.v = createArray(4, 2, 16, 200) as number[][][][]\n this.tc = [\n [0, 0],\n [0, 0],\n [0, 0],\n [0, 0]\n ]\n }\n\n read(data: DataStream, HuffTab: number[][][]) {\n let count = 0\n let temp\n let t\n let c\n let i\n let j\n\n const length = data.get16()\n count += 2\n\n while (count < length) {\n temp = data.get8()\n count += 1\n t = temp & 0x0f\n if (t > 3) {\n throw new Error('ERROR: Huffman table ID > 3')\n }\n\n c = temp >> 4\n if (c > 2) {\n throw new Error('ERROR: Huffman table [Table class > 2 ]')\n }\n\n this.th[t] = 1\n this.tc[t][c] = 1\n\n for (i = 0; i < 16; i += 1) {\n this.l[t][c][i] = data.get8()\n count += 1\n }\n\n for (i = 0; i < 16; i += 1) {\n for (j = 0; j < this.l[t][c][i]; j += 1) {\n if (count > length) {\n throw new Error('ERROR: Huffman table format error [count>Lh]')\n }\n\n this.v[t][c][i][j] = data.get8()\n count += 1\n }\n }\n }\n\n if (count !== length) {\n throw new Error('ERROR: Huffman table format error [count!=Lf]')\n }\n\n for (i = 0; i < 4; i += 1) {\n for (j = 0; j < 2; j += 1) {\n if (this.tc[i][j] !== 0) {\n this.buildHuffTable(HuffTab[i][j], this.l[i][j], this.v[i][j])\n }\n }\n }\n\n return 1\n }\n\n //\tBuild_HuffTab()\n //\tParameter: t table ID\n //\t c table class ( 0 for DC, 1 for AC )\n //\t L[i] # of codewords which length is i\n //\t V[i][j] Huffman Value (length=i)\n //\tEffect:\n //\t build up HuffTab[t][c] using L and V.\n buildHuffTable(tab: number[], L: number[], V: number[][]) {\n let currentTable, k, i, j, n\n const temp = 256\n k = 0\n\n for (i = 0; i < 8; i += 1) {\n // i+1 is Code length\n for (j = 0; j < L[i]; j += 1) {\n for (n = 0; n < temp >> (i + 1); n += 1) {\n tab[k] = V[i][j] | ((i + 1) << 8)\n k += 1\n }\n }\n }\n\n for (i = 1; k < 256; i += 1, k += 1) {\n tab[k] = i | HuffmanTable.MSB\n }\n\n currentTable = 1\n k = 0\n\n for (i = 8; i < 16; i += 1) {\n // i+1 is Code length\n for (j = 0; j < L[i]; j += 1) {\n for (n = 0; n < temp >> (i - 7); n += 1) {\n tab[currentTable * 256 + k] = V[i][j] | ((i + 1) << 8)\n k += 1\n }\n\n if (k >= 256) {\n if (k > 256) {\n throw new Error('ERROR: Huffman table error(1)!')\n }\n\n k = 0\n currentTable += 1\n }\n }\n }\n }\n}\n","import { DataStream } from './data-stream.js'\nimport { createArray } from './utils.js'\n\nexport class QuantizationTable {\n precision: number[] = [] // Quantization precision 8 or 16\n tq = [0, 0, 0, 0] // 1: this table is presented\n quantTables: number[][] = createArray(4, 64) as number[][] // Tables\n\n static enhanceQuantizationTable = function (qtab: number[], table: number[]) {\n for (let i = 0; i < 8; i += 1) {\n qtab[table[0 * 8 + i]] *= 90\n qtab[table[4 * 8 + i]] *= 90\n qtab[table[2 * 8 + i]] *= 118\n qtab[table[6 * 8 + i]] *= 49\n qtab[table[5 * 8 + i]] *= 71\n qtab[table[1 * 8 + i]] *= 126\n qtab[table[7 * 8 + i]] *= 25\n qtab[table[3 * 8 + i]] *= 106\n }\n\n for (let i = 0; i < 8; i += 1) {\n qtab[table[0 + 8 * i]] *= 90\n qtab[table[4 + 8 * i]] *= 90\n qtab[table[2 + 8 * i]] *= 118\n qtab[table[6 + 8 * i]] *= 49\n qtab[table[5 + 8 * i]] *= 71\n qtab[table[1 + 8 * i]] *= 126\n qtab[table[7 + 8 * i]] *= 25\n qtab[table[3 + 8 * i]] *= 106\n }\n\n for (let i = 0; i < 64; i += 1) {\n qtab[i] >>= 6\n }\n }\n\n read(data: DataStream, table: number[]) {\n let count = 0\n let temp\n let t\n let i\n\n const length = data.get16()\n count += 2\n\n while (count < length) {\n temp = data.get8()\n count += 1\n t = temp & 0x0f\n\n if (t > 3) {\n throw new Error('ERROR: Quantization table ID > 3')\n }\n\n this.precision[t] = temp >> 4\n\n if (this.precision[t] === 0) {\n this.precision[t] = 8\n } else if (this.precision[t] === 1) {\n this.precision[t] = 16\n } else {\n throw new Error('ERROR: Quantization table precision error')\n }\n\n this.tq[t] = 1\n\n if (this.precision[t] === 8) {\n for (i = 0; i < 64; i += 1) {\n if (count > length) {\n throw new Error('ERROR: Quantization table format error')\n }\n\n this.quantTables[t][i] = data.get8()\n count += 1\n }\n\n QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table)\n } else {\n for (i = 0; i < 64; i += 1) {\n if (count > length) {\n throw new Error('ERROR: Quantization table format error')\n }\n\n this.quantTables[t][i] = data.get16()\n count += 2\n }\n\n QuantizationTable.enhanceQuantizationTable(this.quantTables[t], table)\n }\n }\n\n if (count !== length) {\n throw new Error('ERROR: Quantization table error [count!=Lq]')\n }\n\n return 1\n }\n}\n","export const ScanComponent = {\n acTabSel: 0, // AC table selector\n dcTabSel: 0, // DC table selector\n scanCompSel: 0 // Scan component selector\n}\n","import { DataStream } from './data-stream.js'\nimport { ScanComponent } from './scan-component.js'\n\nexport class ScanHeader {\n ah = 0\n al = 0\n numComp = 0 // Number of components in the scan\n selection = 0 // Start of spectral or predictor selection\n spectralEnd = 0 // End of spectral selection\n components: Array = []\n\n read(data: DataStream) {\n let count = 0\n let i\n let temp\n\n const length = data.get16()\n count += 2\n\n this.numComp = data.get8()\n count += 1\n\n for (i = 0; i < this.numComp; i += 1) {\n this.components[i] = { ...ScanComponent }\n\n if (count > length) {\n throw new Error('ERROR: scan header format error')\n }\n\n this.components[i].scanCompSel = data.get8()\n count += 1\n\n temp = data.get8()\n count += 1\n\n this.components[i].dcTabSel = temp >> 4\n this.components[i].acTabSel = temp & 0x0f\n }\n\n this.selection = data.get8()\n count += 1\n\n this.spectralEnd = data.get8()\n count += 1\n\n temp = data.get8()\n this.ah = temp >> 4\n this.al = temp & 0x0f\n count += 1\n\n if (count !== length) {\n throw new Error('ERROR: scan header format error [count!=Ns]')\n }\n\n return 1\n }\n}\n","import { ComponentSpec } from './component-spec.js'\nimport { DataStream } from './data-stream.js'\nimport { FrameHeader } from './frame-header.js'\nimport { HuffmanTable } from './huffman-table.js'\nimport { QuantizationTable } from './quantization-table.js'\nimport { ScanHeader } from './scan-header.js'\nimport { createArray } from './utils.js'\n\nconst littleEndian = (function () {\n const buffer = new ArrayBuffer(2)\n new DataView(buffer).setInt16(0, 256, true /* littleEndian */)\n // Int16Array uses the platform's endianness.\n return new Int16Array(buffer)[0] === 256\n})()\n\nexport class Decoder {\n static IDCT_P = [\n 0, 5, 40, 16, 45, 2, 7, 42, 21, 56, 8, 61, 18, 47, 1, 4, 41, 23, 58, 13, 32, 24, 37, 10, 63, 17, 44, 3, 6, 43, 20,\n 57, 15, 34, 29, 48, 53, 26, 39, 9, 60, 19, 46, 22, 59, 12, 33, 31, 50, 55, 25, 36, 11, 62, 14, 35, 28, 49, 52, 27,\n 38, 30, 51, 54\n ]\n\n static TABLE = [\n 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44,\n 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49,\n 57, 58, 62, 63\n ]\n\n static MAX_HUFFMAN_SUBTREE = 50\n static MSB = 0x80000000\n static RESTART_MARKER_BEGIN = 0xffd0\n static RESTART_MARKER_END = 0xffd7\n\n buffer: ArrayBuffer | null = null\n stream: DataStream | null = null\n frame = new FrameHeader()\n huffTable = new HuffmanTable()\n quantTable = new QuantizationTable()\n scan = new ScanHeader()\n DU: number[][][] = createArray(10, 4, 64) as number[][][] // at most 10 data units in a MCU, at most 4 data units in one component\n HuffTab: number[][][] = createArray(4, 2, 50 * 256) as number[][][]\n IDCT_Source: number[] = []\n nBlock: number[] = [] // number of blocks in the i-th Comp in a scan\n acTab: number[][] = createArray(10, 1) as number[][] // ac HuffTab for the i-th Comp in a scan\n dcTab: number[][] = createArray(10, 1) as number[][] // dc HuffTab for the i-th Comp in a scan\n qTab: number[][] = createArray(10, 1) as number[][] // quantization table for the i-th Comp in a scan\n marker = 0\n markerIndex = 0\n numComp = 0\n restartInterval = 0\n selection = 0\n xDim = 0\n yDim = 0\n xLoc = 0\n yLoc = 0\n outputData: Uint8Array | Uint16Array | null = null\n restarting = false\n mask = 0\n numBytes = 0\n\n precision: number | undefined = undefined\n components: Array = []\n\n getter: null | ((index: number, compOffset: number) => number) = null\n setter: null | ((index: number, val: number, compOffset?: number) => void) = null\n output: null | ((PRED: number[]) => void) = null\n selector: null | ((compOffset?: number) => number) = null\n\n /**\n * The Decoder constructor.\n * @property {number} numBytes - number of bytes per component\n * @type {Function}\n */\n constructor(buffer?: ArrayBuffer | null, numBytes?: number) {\n this.buffer = buffer ?? null\n this.numBytes = numBytes ?? 0\n }\n\n /**\n * Returns decompressed data.\n */\n decompress(buffer: ArrayBuffer, offset: number, length: number): ArrayBuffer {\n const result = this.decode(buffer, offset, length)\n return result.buffer\n }\n\n decode(buffer?: ArrayBuffer, offset?: number, length?: number, numBytes?: number) {\n let scanNum = 0\n const pred = []\n let i\n let compN\n const temp = []\n const index = []\n let mcuNum\n\n if (buffer) {\n this.buffer = buffer\n }\n\n if (numBytes !== undefined) {\n this.numBytes = numBytes\n }\n\n this.stream = new DataStream(this.buffer as ArrayBuffer, offset, length)\n this.buffer = null\n\n this.xLoc = 0\n this.yLoc = 0\n let current = this.stream.get16()\n\n if (current !== 0xffd8) {\n // SOI\n throw new Error('Not a JPEG file')\n }\n\n current = this.stream.get16()\n\n while (current >> 4 !== 0x0ffc || current === 0xffc4) {\n // SOF 0~15\n switch (current) {\n case 0xffc4: // DHT\n this.huffTable.read(this.stream, this.HuffTab)\n break\n case 0xffcc: // DAC\n throw new Error(\"Program doesn't support arithmetic coding. (format throw new IOException)\")\n case 0xffdb:\n this.quantTable.read(this.stream, Decoder.TABLE)\n break\n case 0xffdd:\n this.restartInterval = this.readNumber() ?? 0\n break\n case 0xffe0:\n case 0xffe1:\n case 0xffe2:\n case 0xffe3:\n case 0xffe4:\n case 0xffe5:\n case 0xffe6:\n case 0xffe7:\n case 0xffe8:\n case 0xffe9:\n case 0xffea:\n case 0xffeb:\n case 0xffec:\n case 0xffed:\n case 0xffee:\n case 0xffef:\n this.readApp()\n break\n case 0xfffe:\n this.readComment()\n break\n default:\n if (current >> 8 !== 0xff) {\n throw new Error('ERROR: format throw new IOException! (decode)')\n }\n }\n\n current = this.stream.get16()\n }\n\n if (current < 0xffc0 || current > 0xffc7) {\n throw new Error('ERROR: could not handle arithmetic code!')\n }\n\n this.frame.read(this.stream)\n current = this.stream.get16()\n\n do {\n while (current !== 0x0ffda) {\n // SOS\n switch (current) {\n case 0xffc4: // DHT\n this.huffTable.read(this.stream, this.HuffTab)\n break\n case 0xffcc: // DAC\n throw new Error(\"Program doesn't support arithmetic coding. (format throw new IOException)\")\n case 0xffdb:\n this.quantTable.read(this.stream, Decoder.TABLE)\n break\n case 0xffdd:\n this.restartInterval = this.readNumber() ?? 0\n break\n case 0xffe0:\n case 0xffe1:\n case 0xffe2:\n case 0xffe3:\n case 0xffe4:\n case 0xffe5:\n case 0xffe6:\n case 0xffe7:\n case 0xffe8:\n case 0xffe9:\n case 0xffea:\n case 0xffeb:\n case 0xffec:\n case 0xffed:\n case 0xffee:\n case 0xffef:\n this.readApp()\n break\n case 0xfffe:\n this.readComment()\n break\n default:\n if (current >> 8 !== 0xff) {\n throw new Error('ERROR: format throw new IOException! (Parser.decode)')\n }\n }\n\n current = this.stream.get16()\n }\n\n this.precision = this.frame.precision\n this.components = this.frame.components\n\n if (!this.numBytes) {\n this.numBytes = Math.round(Math.ceil(this.precision / 8))\n }\n\n if (this.numBytes === 1) {\n this.mask = 0xff\n } else {\n this.mask = 0xffff\n }\n\n this.scan.read(this.stream)\n this.numComp = this.scan.numComp\n this.selection = this.scan.selection\n\n if (this.numBytes === 1) {\n if (this.numComp === 3) {\n this.getter = this.getValueRGB\n this.setter = this.setValueRGB\n this.output = this.outputRGB\n } else {\n this.getter = this.getValue8\n this.setter = this.setValue8\n this.output = this.outputSingle\n }\n } else {\n this.getter = this.getValue8\n this.setter = this.setValue8\n this.output = this.outputSingle\n }\n\n switch (this.selection) {\n case 2:\n this.selector = this.select2\n break\n case 3:\n this.selector = this.select3\n break\n case 4:\n this.selector = this.select4\n break\n case 5:\n this.selector = this.select5\n break\n case 6:\n this.selector = this.select6\n break\n case 7:\n this.selector = this.select7\n break\n default:\n this.selector = this.select1\n break\n }\n\n // this.scanComps = this.scan.components\n // this.quantTables = this.quantTable.quantTables\n\n for (i = 0; i < this.numComp; i += 1) {\n compN = this.scan.components[i].scanCompSel\n this.qTab[i] = this.quantTable.quantTables[this.components[compN].quantTableSel]\n this.nBlock[i] = this.components[compN].vSamp * this.components[compN].hSamp\n this.dcTab[i] = this.HuffTab[this.scan.components[i].dcTabSel][0]\n this.acTab[i] = this.HuffTab[this.scan.components[i].acTabSel][1]\n }\n\n this.xDim = this.frame.dimX\n this.yDim = this.frame.dimY\n if (this.numBytes === 1) {\n this.outputData = new Uint8Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp))\n } else {\n this.outputData = new Uint16Array(new ArrayBuffer(this.xDim * this.yDim * this.numBytes * this.numComp))\n }\n\n scanNum += 1\n\n while (true) {\n // Decode one scan\n temp[0] = 0\n index[0] = 0\n\n for (i = 0; i < 10; i += 1) {\n pred[i] = 1 << (this.precision - 1)\n }\n\n if (this.restartInterval === 0) {\n current = this.decodeUnit(pred, temp, index)\n\n while (current === 0 && this.xLoc < this.xDim && this.yLoc < this.yDim) {\n this.output(pred)\n current = this.decodeUnit(pred, temp, index)\n }\n\n break // current=MARKER\n }\n\n for (mcuNum = 0; mcuNum < this.restartInterval; mcuNum += 1) {\n this.restarting = mcuNum === 0\n current = this.decodeUnit(pred, temp, index)\n this.output(pred)\n\n if (current !== 0) {\n break\n }\n }\n\n if (current === 0) {\n if (this.markerIndex !== 0) {\n current = 0xff00 | this.marker\n this.markerIndex = 0\n } else {\n current = this.stream.get16()\n }\n }\n\n if (!(current >= Decoder.RESTART_MARKER_BEGIN && current <= Decoder.RESTART_MARKER_END)) {\n break // current=MARKER\n }\n }\n\n if (current === 0xffdc && scanNum === 1) {\n // DNL\n this.readNumber()\n current = this.stream.get16()\n }\n } while (current !== 0xffd9 && this.xLoc < this.xDim && this.yLoc < this.yDim && scanNum === 0)\n\n return this.outputData\n }\n\n decodeUnit(prev: number[], temp: number[], index: number[]): number {\n if (this.numComp === 1) {\n return this.decodeSingle(prev, temp, index)\n } else if (this.numComp === 3) {\n return this.decodeRGB(prev, temp, index)\n } else {\n return -1\n }\n }\n\n select1(compOffset?: number) {\n return this.getPreviousX(compOffset)\n }\n\n select2(compOffset?: number) {\n return this.getPreviousY(compOffset)\n }\n\n select3(compOffset?: number) {\n return this.getPreviousXY(compOffset)\n }\n\n select4(compOffset?: number) {\n return this.getPreviousX(compOffset) + this.getPreviousY(compOffset) - this.getPreviousXY(compOffset)\n }\n\n select5(compOffset?: number) {\n return this.getPreviousX(compOffset) + ((this.getPreviousY(compOffset) - this.getPreviousXY(compOffset)) >> 1)\n }\n\n select6(compOffset?: number) {\n return this.getPreviousY(compOffset) + ((this.getPreviousX(compOffset) - this.getPreviousXY(compOffset)) >> 1)\n }\n\n select7(compOffset?: number) {\n return (this.getPreviousX(compOffset) + this.getPreviousY(compOffset)) / 2\n }\n\n decodeRGB(prev: number[], temp: number[], index: number[]) {\n if (this.selector === null) throw new Error(\"decode hasn't run yet\")\n\n let actab, dctab, qtab, ctrC, i, k, j\n\n prev[0] = this.selector(0)\n prev[1] = this.selector(1)\n prev[2] = this.selector(2)\n\n for (ctrC = 0; ctrC < this.numComp; ctrC += 1) {\n qtab = this.qTab[ctrC]\n actab = this.acTab[ctrC]\n dctab = this.dcTab[ctrC]\n for (i = 0; i < this.nBlock[ctrC]; i += 1) {\n for (k = 0; k < this.IDCT_Source.length; k += 1) {\n this.IDCT_Source[k] = 0\n }\n\n let value = this.getHuffmanValue(dctab, temp, index)\n\n if (value >= 0xff00) {\n return value\n }\n\n prev[ctrC] = this.IDCT_Source[0] = prev[ctrC] + this.getn(index, value, temp, index)\n this.IDCT_Source[0] *= qtab[0]\n\n for (j = 1; j < 64; j += 1) {\n value = this.getHuffmanValue(actab, temp, index)\n\n if (value >= 0xff00) {\n return value\n }\n\n j += value >> 4\n\n if ((value & 0x0f) === 0) {\n if (value >> 4 === 0) {\n break\n }\n } else {\n this.IDCT_Source[Decoder.IDCT_P[j]] = this.getn(index, value & 0x0f, temp, index) * qtab[j]\n }\n }\n }\n }\n\n return 0\n }\n\n decodeSingle(prev: number[], temp: number[], index: number[]) {\n if (this.selector === null) throw new Error(\"decode hasn't run yet\")\n\n let value, i, n, nRestart\n\n if (this.restarting) {\n this.restarting = false\n prev[0] = 1 << (this.frame.precision - 1)\n } else {\n prev[0] = this.selector()\n }\n\n for (i = 0; i < this.nBlock[0]; i += 1) {\n value = this.getHuffmanValue(this.dcTab[0], temp, index)\n if (value >= 0xff00) {\n return value\n }\n\n n = this.getn(prev, value, temp, index)\n nRestart = n >> 8\n\n if (nRestart >= Decoder.RESTART_MARKER_BEGIN && nRestart <= Decoder.RESTART_MARKER_END) {\n return nRestart\n }\n\n prev[0] += n\n }\n\n return 0\n }\n\n //\tHuffman table for fast search: (HuffTab) 8-bit Look up table 2-layer search architecture, 1st-layer represent 256 node (8 bits) if codeword-length > 8\n //\tbits, then the entry of 1st-layer = (# of 2nd-layer table) | MSB and it is stored in the 2nd-layer Size of tables in each layer are 256.\n //\tHuffTab[*][*][0-256] is always the only 1st-layer table.\n //\n //\tAn entry can be: (1) (# of 2nd-layer table) | MSB , for code length > 8 in 1st-layer (2) (Code length) << 8 | HuffVal\n //\n //\tHuffmanValue(table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)\n //\t ):\n //\t return: Huffman Value of table\n //\t 0xFF?? if it receives a MARKER\n //\t Parameter: table HuffTab[x][y] (ex) HuffmanValue(HuffTab[1][0],...)\n //\t temp temp storage for remainded bits\n //\t index index to bit of temp\n //\t in FILE pointer\n //\t Effect:\n //\t temp store new remainded bits\n //\t index change to new index\n //\t in change to new position\n //\t NOTE:\n //\t Initial by temp=0; index=0;\n //\t NOTE: (explain temp and index)\n //\t temp: is always in the form at calling time or returning time\n //\t | byte 4 | byte 3 | byte 2 | byte 1 |\n //\t | 0 | 0 | 00000000 | 00000??? | if not a MARKER\n //\t ^index=3 (from 0 to 15)\n //\t 321\n //\t NOTE (marker and marker_index):\n //\t If get a MARKER from 'in', marker=the low-byte of the MARKER\n //\t and marker_index=9\n //\t If marker_index=9 then index is always > 8, or HuffmanValue()\n //\t will not be called\n getHuffmanValue(table: number[], temp: number[], index: number[]): number {\n let code, input\n const mask = 0xffff\n\n if (!this.stream) throw new Error('stream not initialized')\n\n if (index[0] < 8) {\n temp[0] <<= 8\n input = this.stream.get8()\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n temp[0] |= input\n } else {\n index[0] -= 8\n }\n\n code = table[temp[0] >> index[0]]\n\n if ((code & Decoder.MSB) !== 0) {\n if (this.markerIndex !== 0) {\n this.markerIndex = 0\n return 0xff00 | this.marker\n }\n\n temp[0] &= mask >> (16 - index[0])\n temp[0] <<= 8\n input = this.stream.get8()\n\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n\n temp[0] |= input\n code = table[(code & 0xff) * 256 + (temp[0] >> index[0])]\n index[0] += 8\n }\n\n index[0] += 8 - (code >> 8)\n\n if (index[0] < 0) {\n throw new Error('index=' + index[0] + ' temp=' + temp[0] + ' code=' + code + ' in HuffmanValue()')\n }\n\n if (index[0] < this.markerIndex) {\n this.markerIndex = 0\n return 0xff00 | this.marker\n }\n\n temp[0] &= mask >> (16 - index[0])\n return code & 0xff\n }\n\n getn(PRED: number[], n: number, temp: number[], index: number[]) {\n let result, input\n const one = 1\n const n_one = -1\n const mask = 0xffff\n\n if (this.stream === null) throw new Error('stream not initialized')\n\n if (n === 0) {\n return 0\n }\n\n if (n === 16) {\n if (PRED[0] >= 0) {\n return -32768\n } else {\n return 32768\n }\n }\n\n index[0] -= n\n\n if (index[0] >= 0) {\n if (index[0] < this.markerIndex && !this.isLastPixel()) {\n // this was corrupting the last pixel in some cases\n this.markerIndex = 0\n return (0xff00 | this.marker) << 8\n }\n\n result = temp[0] >> index[0]\n temp[0] &= mask >> (16 - index[0])\n } else {\n temp[0] <<= 8\n input = this.stream.get8()\n\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n\n temp[0] |= input\n index[0] += 8\n\n if (index[0] < 0) {\n if (this.markerIndex !== 0) {\n this.markerIndex = 0\n return (0xff00 | this.marker) << 8\n }\n\n temp[0] <<= 8\n input = this.stream.get8()\n\n if (input === 0xff) {\n this.marker = this.stream.get8()\n if (this.marker !== 0) {\n this.markerIndex = 9\n }\n }\n\n temp[0] |= input\n index[0] += 8\n }\n\n if (index[0] < 0) {\n throw new Error('index=' + index[0] + ' in getn()')\n }\n\n if (index[0] < this.markerIndex) {\n this.markerIndex = 0\n return (0xff00 | this.marker) << 8\n }\n\n result = temp[0] >> index[0]\n temp[0] &= mask >> (16 - index[0])\n }\n\n if (result < one << (n - 1)) {\n result += (n_one << n) + 1\n }\n\n return result\n }\n\n getPreviousX(compOffset = 0): number {\n if (this.getter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.xLoc > 0) {\n return this.getter(this.yLoc * this.xDim + this.xLoc - 1, compOffset)\n } else if (this.yLoc > 0) {\n return this.getPreviousY(compOffset)\n } else {\n return 1 << (this.frame.precision - 1)\n }\n }\n\n getPreviousXY(compOffset = 0) {\n if (this.getter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.xLoc > 0 && this.yLoc > 0) {\n return this.getter((this.yLoc - 1) * this.xDim + this.xLoc - 1, compOffset)\n } else {\n return this.getPreviousY(compOffset)\n }\n }\n\n getPreviousY(compOffset = 0) {\n if (this.getter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.yLoc > 0) {\n return this.getter((this.yLoc - 1) * this.xDim + this.xLoc, compOffset)\n } else {\n return this.getPreviousX(compOffset)\n }\n }\n\n isLastPixel() {\n return this.xLoc === this.xDim - 1 && this.yLoc === this.yDim - 1\n }\n\n outputSingle(PRED: number[]) {\n if (this.setter === null) throw new Error(\"decode hasn't run yet\")\n\n if (this.xLoc < this.xDim && this.yLoc < this.yDim) {\n this.setter(this.yLoc * this.xDim + this.xLoc, this.mask & PRED[0])\n\n this.xLoc += 1\n\n if (this.xLoc >= this.xDim) {\n this.yLoc += 1\n this.xLoc = 0\n }\n }\n }\n\n outputRGB(PRED: number[]) {\n if (this.setter === null) throw new Error(\"decode hasn't run yet\")\n\n const offset = this.yLoc * this.xDim + this.xLoc\n\n if (this.xLoc < this.xDim && this.yLoc < this.yDim) {\n this.setter(offset, PRED[0], 0)\n this.setter(offset, PRED[1], 1)\n this.setter(offset, PRED[2], 2)\n\n this.xLoc += 1\n\n if (this.xLoc >= this.xDim) {\n this.yLoc += 1\n this.xLoc = 0\n }\n }\n }\n\n setValue8(index: number, val: number) {\n if (!this.outputData) throw new Error('output data not ready')\n\n if (littleEndian) {\n this.outputData[index] = val\n } else {\n this.outputData[index] = ((val & 0xff) << 8) | ((val >> 8) & 0xff)\n }\n }\n\n getValue8(index: number) {\n if (this.outputData === null) throw new Error('output data not ready')\n if (littleEndian) {\n return this.outputData[index] // mask should not be necessary because outputData is either Int8Array or Int16Array\n } else {\n const val = this.outputData[index]\n return ((val & 0xff) << 8) | ((val >> 8) & 0xff)\n }\n }\n\n setValueRGB(index: number, val: number, compOffset = 0) {\n if (this.outputData === null) return\n this.outputData[index * 3 + compOffset] = val\n }\n\n getValueRGB(index: number, compOffset: number) {\n if (this.outputData === null) throw new Error('output data not ready')\n return this.outputData[index * 3 + compOffset]\n }\n\n readApp() {\n if (this.stream === null) return null\n\n let count = 0\n const length = this.stream.get16()\n count += 2\n\n while (count < length) {\n this.stream.get8()\n count += 1\n }\n\n return length\n }\n\n readComment() {\n if (this.stream === null) return null\n\n let sb = ''\n let count = 0\n\n const length = this.stream.get16()\n count += 2\n\n while (count < length) {\n sb += this.stream.get8()\n count += 1\n }\n\n return sb\n }\n\n readNumber() {\n if (this.stream === null) return null\n\n const Ld = this.stream.get16()\n\n if (Ld !== 4) {\n throw new Error('ERROR: Define number format throw new IOException [Ld!=4]')\n }\n\n return this.stream.get16()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,eAAe;AAAA,EACf,OAAO;AACT;;;ACJO,IAAM,aAAN,MAAiB;AAAA,EACtB;AAAA,EACA;AAAA,EAEA,YAAY,MAAmB,QAAiB,QAAiB;AAC/D,SAAK,SAAS,IAAI,WAAW,MAAM,QAAQ,MAAM;AACjD,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,QAAQ;AAEN,UAAM,SAAS,KAAK,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,OAAO,KAAK,QAAQ,CAAC;AACzE,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEA,OAAO;AAEL,UAAM,QAAQ,KAAK,OAAO,KAAK,KAAK;AACpC,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AACF;;;ACnBO,IAAM,cAAN,MAAkB;AAAA,EACvB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,aAA0C,CAAC;AAAA,EAE3C,KAAK,MAAkB;AACrB,QAAI,QAAQ;AACZ,QAAI;AAEJ,UAAM,SAAS,KAAK,MAAM;AAC1B,aAAS;AAET,SAAK,YAAY,KAAK,KAAK;AAC3B,aAAS;AAET,SAAK,OAAO,KAAK,M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