From cc3036c02828d9c071fa8ab7a287872eecc512bb Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 28 Dec 2020 17:12:36 +0000 Subject: [PATCH] add libjpeg --- libjpeg/README.md | 4 + libjpeg/build/debug/README.md | 4 + libjpeg/build/debug/main.js | 18 + libjpeg/build/debug/package.json | 16 + libjpeg/build/release/libjpeg.zip | Bin 0 -> 54606 bytes libjpeg/jpg.js | 4280 +++++++++++++++++++++++++++++ libjpeg/package.json | 16 + libjpeg/project.json | 7 + packages.json | 10 + 9 files changed, 4355 insertions(+) create mode 100644 libjpeg/README.md create mode 100644 libjpeg/build/debug/README.md create mode 100644 libjpeg/build/debug/main.js create mode 100644 libjpeg/build/debug/package.json create mode 100644 libjpeg/build/release/libjpeg.zip create mode 100644 libjpeg/jpg.js create mode 100644 libjpeg/package.json create mode 100644 libjpeg/project.json diff --git a/libjpeg/README.md b/libjpeg/README.md new file mode 100644 index 0000000..0d94227 --- /dev/null +++ b/libjpeg/README.md @@ -0,0 +1,4 @@ +# libjpeg +Simple JPEG/DCT data decoder in JavaScript. Also this project includes JPEG 2000 and JBIG2 decoders. + +Github page: [https://github.com/notmasteryet/jpgjs](https://github.com/notmasteryet/jpgjs) \ No newline at end of file diff --git a/libjpeg/build/debug/README.md b/libjpeg/build/debug/README.md new file mode 100644 index 0000000..0d94227 --- /dev/null +++ b/libjpeg/build/debug/README.md @@ -0,0 +1,4 @@ +# libjpeg +Simple JPEG/DCT data decoder in JavaScript. Also this project includes JPEG 2000 and JBIG2 decoders. + +Github page: [https://github.com/notmasteryet/jpgjs](https://github.com/notmasteryet/jpgjs) \ No newline at end of file diff --git a/libjpeg/build/debug/main.js b/libjpeg/build/debug/main.js new file mode 100644 index 0000000..65ab065 --- /dev/null +++ b/libjpeg/build/debug/main.js @@ -0,0 +1,18 @@ +(function(){}).call(this);var e,t=function(){function t(){this._src=null,this._parser=new e.JpegImage,this.onload=null}return t.prototype={get src(){return this._src},set src(e){this.load(e)},get width(){return this._parser.width},get height(){return this._parser.height},load:function(e){this._src=e, +/** + * @license + * Copyright 2015 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function(e,t){if(0!==e.indexOf("data:")){var r=new XMLHttpRequest;r.open("GET",e,!0),r.responseType="arraybuffer",r.onload=function(){t(r.response)},r.send(null)}else{for(var n=e.indexOf("base64,")+7,i=atob(e.substring(n)),a=new Uint8Array(i.length),s=i.length-1;s>=0;s--)a[s]=i.charCodeAt(s);t(a.buffer)}}(e,function(e){this.parse(new Uint8Array(e)),this.onload&&this.onload()}.bind(this))},parse:function(e){this._parser.parse(e)},getData:function(e,t){return this._parser.getData(e,t,!1)},copyToImageData:function(e){if(2===this._parser.numComponents||this._parser.numComponents>4)throw new Error("Unsupported amount of components");var t,r,n=e.width,i=e.height,a=n*i*4,s=e.data;if(1!==this._parser.numComponents){var o=this._parser.getData(n,i,!0);for(t=0,r=0;t0&&!e[s-1];)s--;a.push({children:[],index:0});var o,c=a[0];for(r=0;r0;)c=a.pop();for(c.index++,a.push(c);a.length<=r;)a.push(o={children:[],index:0}),c.children[c.index]=o.children,c=o;i++}r+10)return d--,m>>d&1;if(255===(m=t[r++])){var e=t[r++];if(e)throw"unexpected marker: "+(m<<8|e).toString(16)}return d=7,m>>>7}function g(e){for(var t=e;;){if("number"==typeof(t=t[v()]))return t;if("object"!=typeof t)throw"invalid huffman sequence"}}function b(e){for(var t=0;e>0;)t=t<<1|v(),e--;return t}function y(e){if(1===e)return 1===v()?1:-1;var t=b(e);return t>=1<0)w--;else for(var n=o,i=c;n<=i;){var a=g(t.huffmanTableAC),s=15&a,l=a>>4;if(0!==s){var f=e[n+=l];t.blockData[r+f]=y(s)*(1<>4,0==(n=15&i))l<15?(w=b(l)+(1<>4;if(0!==o){var l=e[a+=c];t.blockData[r+l]=y(o),a++}else{if(c<15)break;a+=16}}};var z,O,F,B,q=0;for(O=1===L?a[0].blocksPerLine*a[0].blocksPerColumn:f*i.mcusPerColumn,s||(s=O);q=65488&&z<=65495))break;r+=2}return r-p}function a(e,t,r){for(var n,i,a,s,o,c,l,h,f,u,p,m,d,v,g,b,y,x=e.quantizationTable,w=e.blockData,C=0;C<64;C+=8)f=w[t+C],u=w[t+C+1],p=w[t+C+2],m=w[t+C+3],d=w[t+C+4],v=w[t+C+5],g=w[t+C+6],b=w[t+C+7],f*=x[C],0!=(u|p|m|d|v|g|b)?(u*=x[C+1],p*=x[C+2],m*=x[C+3],d*=x[C+4],v*=x[C+5],i=(n=(n=5793*f+128>>8)+(i=5793*d+128>>8)+1>>1)-i,y=3784*(a=p)+1567*(s=g*=x[C+6])+128>>8,a=1567*a-3784*s+128>>8,l=(o=(o=2896*(u-(b*=x[C+7]))+128>>8)+(l=v<<4)+1>>1)-l,c=(h=(h=2896*(u+b)+128>>8)+(c=m<<4)+1>>1)-c,s=(n=n+(s=y)+1>>1)-s,a=(i=i+a+1>>1)-a,y=2276*o+3406*h+2048>>12,o=3406*o-2276*h+2048>>12,h=y,y=799*c+4017*l+2048>>12,c=4017*c-799*l+2048>>12,l=y,r[C]=n+h,r[C+7]=n-h,r[C+1]=i+l,r[C+6]=i-l,r[C+2]=a+c,r[C+5]=a-c,r[C+3]=s+o,r[C+4]=s-o):(y=5793*f+512>>10,r[C]=y,r[C+1]=y,r[C+2]=y,r[C+3]=y,r[C+4]=y,r[C+5]=y,r[C+6]=y,r[C+7]=y);for(var P=0;P<8;++P)f=r[P],0!=((u=r[P+8])|(p=r[P+16])|(m=r[P+24])|(d=r[P+32])|(v=r[P+40])|(g=r[P+48])|(b=r[P+56]))?(i=(n=4112+((n=5793*f+2048>>12)+(i=5793*d+2048>>12)+1>>1))-i,y=3784*(a=p)+1567*(s=g)+2048>>12,a=1567*a-3784*s+2048>>12,s=y,l=(o=(o=2896*(u-b)+2048>>12)+(l=v)+1>>1)-l,c=(h=(h=2896*(u+b)+2048>>12)+(c=m)+1>>1)-c,y=2276*o+3406*h+2048>>12,o=3406*o-2276*h+2048>>12,h=y,y=799*c+4017*l+2048>>12,c=4017*c-799*l+2048>>12,f=(f=(n=n+s+1>>1)+h)<16?0:f>=4080?255:f>>4,u=(u=(i=i+a+1>>1)+(l=y))<16?0:u>=4080?255:u>>4,p=(p=(a=i-a)+c)<16?0:p>=4080?255:p>>4,m=(m=(s=n-s)+o)<16?0:m>=4080?255:m>>4,d=(d=s-o)<16?0:d>=4080?255:d>>4,v=(v=a-c)<16?0:v>=4080?255:v>>4,g=(g=i-l)<16?0:g>=4080?255:g>>4,b=(b=n-h)<16?0:b>=4080?255:b>>4,w[t+P]=f,w[t+P+8]=u,w[t+P+16]=p,w[t+P+24]=m,w[t+P+32]=d,w[t+P+40]=v,w[t+P+48]=g,w[t+P+56]=b):(y=(y=5793*f+8192>>14)<-2040?0:y>=2024?255:y+2056>>4,w[t+P]=y,w[t+P+8]=y,w[t+P+16]=y,w[t+P+24]=y,w[t+P+32]=y,w[t+P+40]=y,w[t+P+48]=y,w[t+P+56]=y)}function s(e,t){for(var r=t.blocksPerLine,i=t.blocksPerColumn,s=new Int16Array(64),o=0;o=255?255:e}return t.prototype={parse:function(t){function n(){var e=t[f]<<8|t[f+1];return f+=2,e}function a(e){for(var t=Math.ceil(e.samplesPerLine/8/e.maxH),r=Math.ceil(e.scanLines/8/e.maxV),n=0;n>4==0)for(y=0;y<64;y++)k[e[y]]=t[f++];else{if(P>>4!=1)throw"DQT: invalid table spec";for(y=0;y<64;y++)k[e[y]]=n()}m[15&P]=k}break;case 65472:case 65473:case 65474:if(o)throw"Only single frame JPEGs supported";n(),(o={}).extended=65473===g,o.progressive=65474===g,o.precision=t[f++],o.scanLines=n(),o.samplesPerLine=n(),o.components=[],o.componentIds={};var I,M=t[f++],S=0,T=0;for(b=0;b>4,D=15&t[f+1];S>4==0?v:d)[15&O]=r(F,q)}break;case 65501:n(),c=n();break;case 65498:n();var E,R=t[f++],U=[];for(b=0;b>4],E.huffmanTableAC=d[15&_],U.push(E)}var J=t[f++],H=t[f++],Y=t[f++],G=i(t,f,o,U,c,J,H,Y>>4,15&Y);f+=G;break;case 65535:255!==t[f]&&f--;break;default:if(255===t[f-3]&&t[f-2]>=192&&t[f-2]<=254){f-=3;break}throw"unknown JPEG marker "+g.toString(16)}g=n()}for(this.width=o.samplesPerLine,this.height=o.scanLines,this.jfif=u,this.adobe=p,this.components=[],b=0;b>8)+x[h+1];return b},_isColorConversionNeeded:function(){return!(!this.adobe||!this.adobe.transformCode)||3===this.numComponents},_convertYccToRgb:function(e){for(var t,r,n,i=0,a=e.length;i=0?255:l<=s?0:255+l*(1/255/255)|0,e[a++]=h>=0?255:h<=s?0:255+h*(1/255/255)|0,e[a++]=f>=0?255:f<=s?0:255+f*(1/255/255)|0}return e},getData:function(e,t,r){if(this.numComponents>4)throw"Unsupported color mode";var n=this._getLinearizedBlockData(e,t);if(3===this.numComponents)return this._convertYccToRgb(n);if(4===this.numComponents){if(this._isColorConversionNeeded())return r?this._convertYcckToRgb(n):this._convertYcckToCmyk(n);if(r)return this._convertCmykToRgb(n)}return n}},t}(),r=function(){var e=[{qe:22017,nmps:1,nlps:1,switchFlag:1},{qe:13313,nmps:2,nlps:6,switchFlag:0},{qe:6145,nmps:3,nlps:9,switchFlag:0},{qe:2753,nmps:4,nlps:12,switchFlag:0},{qe:1313,nmps:5,nlps:29,switchFlag:0},{qe:545,nmps:38,nlps:33,switchFlag:0},{qe:22017,nmps:7,nlps:6,switchFlag:1},{qe:21505,nmps:8,nlps:14,switchFlag:0},{qe:18433,nmps:9,nlps:14,switchFlag:0},{qe:14337,nmps:10,nlps:14,switchFlag:0},{qe:12289,nmps:11,nlps:17,switchFlag:0},{qe:9217,nmps:12,nlps:18,switchFlag:0},{qe:7169,nmps:13,nlps:20,switchFlag:0},{qe:5633,nmps:29,nlps:21,switchFlag:0},{qe:22017,nmps:15,nlps:14,switchFlag:1},{qe:21505,nmps:16,nlps:14,switchFlag:0},{qe:20737,nmps:17,nlps:15,switchFlag:0},{qe:18433,nmps:18,nlps:16,switchFlag:0},{qe:14337,nmps:19,nlps:17,switchFlag:0},{qe:13313,nmps:20,nlps:18,switchFlag:0},{qe:12289,nmps:21,nlps:19,switchFlag:0},{qe:10241,nmps:22,nlps:19,switchFlag:0},{qe:9217,nmps:23,nlps:20,switchFlag:0},{qe:8705,nmps:24,nlps:21,switchFlag:0},{qe:7169,nmps:25,nlps:22,switchFlag:0},{qe:6145,nmps:26,nlps:23,switchFlag:0},{qe:5633,nmps:27,nlps:24,switchFlag:0},{qe:5121,nmps:28,nlps:25,switchFlag:0},{qe:4609,nmps:29,nlps:26,switchFlag:0},{qe:4353,nmps:30,nlps:27,switchFlag:0},{qe:2753,nmps:31,nlps:28,switchFlag:0},{qe:2497,nmps:32,nlps:29,switchFlag:0},{qe:2209,nmps:33,nlps:30,switchFlag:0},{qe:1313,nmps:34,nlps:31,switchFlag:0},{qe:1089,nmps:35,nlps:32,switchFlag:0},{qe:673,nmps:36,nlps:33,switchFlag:0},{qe:545,nmps:37,nlps:34,switchFlag:0},{qe:321,nmps:38,nlps:35,switchFlag:0},{qe:273,nmps:39,nlps:36,switchFlag:0},{qe:133,nmps:40,nlps:37,switchFlag:0},{qe:73,nmps:41,nlps:38,switchFlag:0},{qe:37,nmps:42,nlps:39,switchFlag:0},{qe:21,nmps:43,nlps:40,switchFlag:0},{qe:9,nmps:44,nlps:41,switchFlag:0},{qe:5,nmps:45,nlps:42,switchFlag:0},{qe:1,nmps:45,nlps:43,switchFlag:0},{qe:22017,nmps:46,nlps:46,switchFlag:0}];function t(e,t,r){this.data=e,this.bp=t,this.dataEnd=r,this.chigh=e[t],this.clow=0,this.byteIn(),this.chigh=this.chigh<<7&65535|this.clow>>9&127,this.clow=this.clow<<7&65535,this.ct-=7,this.a=32768}return t.prototype={byteIn:function(){var e=this.data,t=this.bp;255===e[t]?e[t+1]>143?(this.clow+=65280,this.ct=8):(t++,this.clow+=e[t]<<9,this.ct=7,this.bp=t):(t++,this.clow+=t65535&&(this.chigh+=this.clow>>16,this.clow&=65535)},readBit:function(t,r){var n,i=t[r]>>1,a=1&t[r],s=e[i],o=s.qe,c=this.a-o;if(this.chigh>15&1,this.clow=this.clow<<1&65535,this.ct--}while(0==(32768&c));return this.a=c,t[r]=i<<1|a,n}},t}(),n=function(){var e={LL:0,LH:1,HL:1,HH:2};function t(){this.failOnCorruptedImage=!1}function n(e,t){e.x0=Math.ceil(t.XOsiz/e.XRsiz),e.x1=Math.ceil(t.Xsiz/e.XRsiz),e.y0=Math.ceil(t.YOsiz/e.YRsiz),e.y1=Math.ceil(t.Ysiz/e.YRsiz),e.width=e.x1-e.x0,e.height=e.y1-e.y0}function i(e,t){for(var r,n=e.SIZ,i=[],a=Math.ceil((n.Xsiz-n.XTOsiz)/n.XTsiz),s=Math.ceil((n.Ysiz-n.YTOsiz)/n.YTsiz),o=0;o0?Math.min(n.xcb,i.PPx-1):Math.min(n.xcb,i.PPx),i.ycb_=r>0?Math.min(n.ycb,i.PPy-1):Math.min(n.ycb,i.PPy),i}function l(e,t,r){var n=1<t.trx0?Math.ceil(t.trx1/n)-Math.floor(t.trx0/n):0,l=t.try1>t.try0?Math.ceil(t.try1/i)-Math.floor(t.try0/i):0,h=c*l;t.precinctParameters={precinctWidth:n,precinctHeight:i,numprecinctswide:c,numprecinctshigh:l,numprecincts:h,precinctWidthInSubband:s,precinctHeightInSubband:o}}function h(e,t,r){var n,i,a,s,o=r.xcb_,c=r.ycb_,l=1<>o,u=t.tby0>>c,p=t.tbx1+l-1>>o,m=t.tby1+h-1>>c,d=t.resolution.precinctParameters,v=[],g=[];for(i=u;ib.cbxMax&&(b.cbxMax=n),ib.cbyMax&&(b.cbyMax=i)):g[s]=b={cbxMin:n,cbyMin:i,cbxMax:n,cbyMax:i},a.precinct=b}t.codeblockParameters={codeblockWidth:o,codeblockHeight:c,numcodeblockwide:p-f+1,numcodeblockhigh:m-u+1},t.codeblocks=v,t.precincts=g}function p(e,t,r){for(var n=[],i=e.subbands,a=0,s=i.length;ae.codingStyleParameters.decompositionLevelsCount)){for(var t=e.resolutions[l],r=t.precinctParameters.numprecincts;fe.codingStyleParameters.decompositionLevelsCount)){for(var t=e.resolutions[c],r=t.precinctParameters.numprecincts;fe.codingStyleParameters.decompositionLevelsCount)){var a=e.resolutions[r],s=a.precinctParameters.numprecincts;if(!(i>=s)){for(;t=0;--v){var g=c.resolutions[v],b=d*g.precinctParameters.precinctWidth,y=d*g.precinctParameters.precinctHeight;f=Math.min(f,b),u=Math.min(u,y),p=Math.max(p,g.precinctParameters.numprecinctswide),m=Math.max(m,g.precinctParameters.numprecinctshigh),h[v]={width:b,height:y},d<<=1}r=Math.min(r,f),n=Math.min(n,u),i=Math.max(i,p),a=Math.max(a,m),s[o]={resolutions:h,minWidth:f,minHeight:u,maxNumWide:p,maxNumHigh:m}}return{components:s,minWidth:r,minHeight:n,maxNumWide:i,maxNumHigh:a}}function w(e){for(var t=e.SIZ,r=e.currentTile.index,n=e.tiles[r],i=t.Csiz,a=0;a>>(o-=e)&(1<0;){var U=C.shift();void 0===(x=U.codeblock).data&&(x.data=[]),x.data.push({data:t,start:r+s,end:r+s+U.dataLength,codingpasses:U.codingpasses}),s+=U.dataLength}}}return s}function P(e,t,n,i,a,s,o,c){for(var l=i.tbx0,h=i.tby0,f=i.tbx1-i.tbx0,u=i.codeblocks,p="H"===i.type.charAt(0)?1:0,m="H"===i.type.charAt(1)?t:0,d=0,v=u.length;d=s?F:F*(1<0?1-g:0));var S=b.subbands[C],T=e[S.type];P(w,y,0,S,p?1:Math.pow(2,u+T-M)*(1+I/2048),h+M-1,p,f)}d.push({width:y,height:x,items:w})}var A=m.calculate(d,i.tcx0,i.tcy0);return{left:i.tcx0,top:i.tcy0,width:A.width,height:A.height,items:A.items}}function I(e,t){for(var r=e.SIZ.Csiz,n=e.tiles[t],i=0;i>24&255,a>>16&255,a>>8&255,255&a);f("Unsupported header type "+a+" ("+m+")")}l&&(t+=s)}else this.parseCodestream(e,0,e.length)},parseImageProperties:function(e){for(var t=e.getByte();t>=0;)if(65361==(t<<8|(t=e.getByte()))){e.skip(4);var r=e.getInt32()>>>0,n=e.getInt32()>>>0,i=e.getInt32()>>>0,a=e.getInt32()>>>0;e.skip(16);var s=e.getUint16();return this.width=r-i,this.height=n-a,this.componentsCount=s,void(this.bitsPerComponent=8)}throw new Error("JPX Error: No size marker found in JPX stream")},parseCodestream:function(e,t,r){var a={};try{for(var s=!1,l=t;l+1>5,m=[];u>3,A.mu=0):(A.epsilon=e[u]>>3,A.mu=(7&e[u])<<8|e[u+1],u+=2),m.push(A)}T.SPqcds=m,a.mainHeader?a.QCD=T:(a.currentTile.QCD=T,a.currentTile.QCC=[]);break;case 65373:b=o(e,l);var D,L={};switch(u=l+2,a.SIZ.Csiz<257?D=e[u++]:(D=o(e,u),u+=2),31&(p=e[u++])){case 0:d=8,v=!0;break;case 1:d=16,v=!1;break;case 2:d=16,v=!0;break;default:throw new Error("JPX Error: Invalid SQcd value "+p)}for(L.noQuantization=8===d,L.scalarExpounded=v,L.guardBits=p>>5,m=[];u>3,A.mu=0):(A.epsilon=e[u]>>3,A.mu=(7&e[u])<<8|e[u+1],u+=2),m.push(A);L.SPqcds=m,a.mainHeader?a.QCC[D]=L:a.currentTile.QCC[D]=L;break;case 65362:b=o(e,l);var z={};u=l+2;var O=e[u++];z.entropyCoderWithCustomPrecincts=!!(1&O),z.sopMarkerUsed=!!(2&O),z.ephMarkerUsed=!!(4&O),z.progressionOrder=e[u++],z.layersCount=o(e,u),u+=2,z.multipleComponentTransform=e[u++],z.decompositionLevelsCount=e[u++],z.xcb=2+(15&e[u++]),z.ycb=2+(15&e[u++]);var F=e[u++];if(z.selectiveArithmeticCodingBypass=!!(1&F),z.resetContextProbabilities=!!(2&F),z.terminationOnEachCodingPass=!!(4&F),z.verticalyStripe=!!(8&F),z.predictableTermination=!!(16&F),z.segmentationSymbolUsed=!!(32&F),z.reversibleTransformation=e[u++],z.entropyCoderWithCustomPrecincts){for(var B=[];u>4})}z.precinctsSizes=B}var E=[];if(z.selectiveArithmeticCodingBypass&&E.push("selectiveArithmeticCodingBypass"),z.resetContextProbabilities&&E.push("resetContextProbabilities"),z.terminationOnEachCodingPass&&E.push("terminationOnEachCodingPass"),z.verticalyStripe&&E.push("verticalyStripe"),z.predictableTermination&&E.push("predictableTermination"),E.length>0)throw s=!0,new Error("JPX Error: Unsupported COD options ("+E.join(", ")+")");a.mainHeader?a.COD=z:(a.currentTile.COD=z,a.currentTile.COC=[]);break;case 65424:b=o(e,l),(g={}).index=o(e,l+2),g.length=c(e,l+4),g.dataEnd=g.length+l-2,g.partIndex=e[l+8],g.partsCount=e[l+9],a.mainHeader=!1,0===g.partIndex&&(g.COD=a.COD,g.COC=a.COC.slice(0),g.QCD=a.QCD,g.QCC=a.QCC.slice(0)),a.currentTile=g;break;case 65427:0===(g=a.currentTile).partIndex&&(I(a,g.index),w(a)),C(a,e,l,b=g.dataEnd-l);break;case 65365:case 65367:case 65368:case 65380:b=o(e,l);break;case 65363:throw new Error("JPX Error: Codestream code 0xFF53 (COC) is not implemented");default:throw new Error("JPX Error: Unknown codestream code: "+h.toString(16))}l+=b}}catch(e){if(s||this.failOnCorruptedImage)throw e;f("Trying to recover from "+e.message)}this.tiles=function(e){for(var t=e.SIZ,r=e.components,n=t.Csiz,i=[],a=0,s=e.tiles.length;a>2))+y,C=w+b,S[A++]=x<=0?0:x>=u?255:x>>h,S[A++]=w<=0?0:w>=u?255:w>>h,S[A++]=C<=0?0:C>=u?255:C>>h;else for(d=0;d=u?255:x>>h,S[A++]=w<=0?0:w>=u?255:w>>h,S[A++]=C<=0?0:C>=u?255:C>>h;if(D)for(d=0,A=3;d=m?255:P+f>>h}else for(o=0;o=u?255:I+f>>h,A+=n}i.push(T)}return i}(a),this.width=a.SIZ.Xsiz-a.SIZ.XOsiz,this.height=a.SIZ.Ysiz-a.SIZ.YOsiz,this.componentsCount=a.SIZ.Csiz}};var M=function(){function e(e,t){var r=a(Math.max(e,t))+1;this.levels=[];for(var n=0;n>=1,t>>=1,n++}n--,(r=this.levels[n]).items[r.index]=i,this.currentLevel=n,delete this.value},incrementValue:function(){var e=this.levels[this.currentLevel];e.items[e.index]++},nextLevel:function(){var e=this.currentLevel,t=this.levels[e],r=t.items[t.index];return--e<0?(this.value=r,!1):(this.currentLevel=e,(t=this.levels[e]).items[t.index]=r,!0)}},e}(),S=function(){function e(e,t,r){var n=a(Math.max(e,t))+1;this.levels=[];for(var i=0;ir)return this.currentLevel=n,this.propagateValues(),!1;e>>=1,t>>=1,n++}return this.currentLevel=n-1,!0},incrementValue:function(e){var t=this.levels[this.currentLevel];t.items[t.index]=e+1,this.propagateValues()},propagateValues:function(){for(var e=this.currentLevel,t=this.levels[e],r=t.items[t.index];--e>=0;)(t=this.levels[e]).items[t.index]=r},nextLevel:function(){var e=this.currentLevel,t=this.levels[e],r=t.items[t.index];return t.items[t.index]=255,!(--e<0||(this.currentLevel=e,(t=this.levels[e]).items[t.index]=r,0))}},e}(),T=function(){var e=new Uint8Array([0,5,8,0,3,7,8,0,4,7,8,0,0,0,0,0,1,6,8,0,3,7,8,0,4,7,8,0,0,0,0,0,2,6,8,0,3,7,8,0,4,7,8,0,0,0,0,0,2,6,8,0,3,7,8,0,4,7,8,0,0,0,0,0,2,6,8,0,3,7,8,0,4,7,8]),t=new Uint8Array([0,3,4,0,5,7,7,0,8,8,8,0,0,0,0,0,1,3,4,0,6,7,7,0,8,8,8,0,0,0,0,0,2,3,4,0,6,7,7,0,8,8,8,0,0,0,0,0,2,3,4,0,6,7,7,0,8,8,8,0,0,0,0,0,2,3,4,0,6,7,7,0,8,8,8]),r=new Uint8Array([0,1,2,0,1,2,2,0,2,2,2,0,0,0,0,0,3,4,5,0,4,5,5,0,5,5,5,0,0,0,0,0,6,7,7,0,7,7,7,0,7,7,7,0,0,0,0,0,8,8,8,0,8,8,8,0,8,8,8,0,0,0,0,0,8,8,8,0,8,8,8,0,8,8,8]);function n(n,i,a,s,o){this.width=n,this.height=i,this.contextLabelTable="HH"===a?r:"HL"===a?t:e;var c=n*i;this.neighborsSignificance=new Uint8Array(c),this.coefficentsSign=new Uint8Array(c),this.coefficentsMagnitude=o>14?new Uint32Array(c):o>6?new Uint16Array(c):new Uint8Array(c),this.processingFlags=new Uint8Array(c);var l=new Uint8Array(c);if(0!==s)for(var h=0;h0,c=t+10&&(n=r-a,o&&(i[n-1]+=16),c&&(i[n+1]+=16),i[n]+=4),e+1=r)break;if(s[u]&=-2,!n[u]&&a[u]){var d=c[a[u]];if(e.readBit(o,d)){var v=this.decodeSignBit(m,f,u);i[u]=v,n[u]=1,this.setNeighborsSignificance(m,f,u),s[u]|=2}l[u]++,s[u]|=1}}},decodeSignBit:function(e,t,r){var n,i,a,s,o,c,l=this.width,h=this.height,f=this.coefficentsMagnitude,u=this.coefficentsSign;s=t>0&&0!==f[r-1],t+10&&0!==f[r-l],e+1=0?(o=9+n,c=this.decoder.readBit(this.contexts,o)):(o=9-n,c=1^this.decoder.readBit(this.contexts,o)),c},runMagnitudeRefinementPass:function(){for(var e,t=this.decoder,r=this.width,n=this.height,i=this.coefficentsMagnitude,a=this.neighborsSignificance,s=this.contexts,o=this.bitsDecoded,c=this.processingFlags,l=r*n,h=4*r,f=0;f>1,c=-1.586134342059924,l=-.052980118572961,h=.882911075530934,f=.443506852043971,u=1.230174104914001;for(n=(t|=0)-3,i=o+4;i--;n+=2)e[n]*=.8128930661159609;for(a=f*e[(n=t-2)-1],i=o+3;i--&&(s=f*e[n+1],e[n]=u*e[n]-a-s,i--);n+=2)a=f*e[(n+=2)+1],e[n]=u*e[n]-a-s;for(a=h*e[(n=t-1)-1],i=o+2;i--&&(s=h*e[n+1],e[n]-=a+s,i--);n+=2)a=h*e[(n+=2)+1],e[n]-=a+s;for(a=l*e[(n=t)-1],i=o+1;i--&&(s=l*e[n+1],e[n]-=a+s,i--);n+=2)a=l*e[(n+=2)+1],e[n]-=a+s;if(0!==o)for(a=c*e[(n=t+1)-1],i=o;i--&&(s=c*e[n+1],e[n]-=a+s,i--);n+=2)a=c*e[(n+=2)+1],e[n]-=a+s},e}(),L=function(){function e(){A.call(this)}return e.prototype=Object.create(A.prototype),e.prototype.filter=function(e,t,r){var n,i,a=r>>1;for(n=t|=0,i=a+1;i--;n+=2)e[n]-=e[n-1]+e[n+1]+2>>2;for(n=t+1,i=a;i--;n+=2)e[n]+=e[n-1]+e[n+1]>>1},e}();return t}(),i=function(){function e(){}function t(e,t,r){this.data=e,this.start=t,this.end=r}function n(e,t,r){var n=e.getContexts(t),i=1;function a(e){for(var t=0,a=0;a>>0}var s=a(1),o=a(1)?a(1)?a(1)?a(1)?a(1)?a(32)+4436:a(12)+340:a(8)+84:a(6)+20:a(4)+4:a(2);return 0===s?o:o>0?-o:null}function i(e,t,r){for(var n=e.getContexts("IAID"),i=1,a=0;a=z&&S=O)for(_=_<<1&y,p=0;p=0&&A=0&&(D=E[T][A])&&(_|=D<=e?O<<=1:O=O<<1|k[L][z];for(f=0;f=C||z<0||z>=w?O<<=1:O=O<<1|n[L][z];var F=I.readBit(M,O);A[D]=F}}return k}function b(e,t,r,a,s,o,c,l,f,u,p,m,d,v,b,y,x){e&&h("JBIG2 error: huffman is not supported");var w,C,P=[];for(w=0;w>1)+n(M,"IARDX",I),(E>>1)+n(M,"IARDY",I),!1,y,x)}var R,U,X,_=D-(1&m?0:B),J=A-(2&m?F:0);if(u){for(R=0;R>5&7,u=[31&s],p=t+6;if(7===s){l=536870911&c(e,p-1),p+=3;var m=l+7>>3;for(u[0]=e[p++];--m>0;)u.push(e[p++])}else 5!==s&&6!==s||h("JBIG2 error: invalid referred-to flags");r.retainBits=u;var d,v,g=r.number<=256?1:r.number<=65536?2:4,b=[];for(d=0;d>>24&255,k[3]=x.height>>16&255,k[4]=x.height>>8&255,k[5]=255&x.height,d=p,v=e.length;d>2&3,m.huffmanDWSelector=d>>4&3,m.bitmapSizeSelector=d>>6&1,m.aggregationInstancesSelector=d>>7&1,m.bitmapCodingContextUsed=!!(256&d),m.bitmapCodingContextRetained=!!(512&d),m.template=d>>10&3,m.refinementTemplate=d>>12&1,u+=2,!m.huffman){for(a=0===m.template?4:1,n=[],i=0;i>2&3),v.referenceCorner=g>>4&3,v.transposed=!!(64&g),v.combinationOperator=g>>7&3,v.defaultPixelValue=g>>9&1,v.dsOffset=g<<17>>27,v.refinementTemplate=g>>15&1,v.huffman){var b=o(f,u);u+=2,v.huffmanFS=3&b,v.huffmanDS=b>>2&3,v.huffmanDT=b>>4&3,v.huffmanRefinementDW=b>>6&3,v.huffmanRefinementDH=b>>8&3,v.huffmanRefinementDX=b>>10&3,v.huffmanRefinementDY=b>>12&3,v.huffmanRefinementSizeSelector=!!(14&b)}if(v.refinement&&!v.refinementTemplate){for(n=[],i=0;i<2;i++)n.push({x:s(f,u),y:s(f,u+1)}),u+=2;v.refinementAt=n}v.numberOfSymbolInstances=c(f,u),u+=4,v.huffman&&h("JBIG2 error: huffman is not supported"),r=[v,l.referredTo,f,u,p];break;case 38:case 39:var y={};y.info=w(f,u),u+=C;var x=f[u++];if(y.mmr=!!(1&x),y.template=x>>1&3,y.prediction=!!(8&x),!y.mmr){for(a=0===y.template?4:1,n=[],i=0;i>2&1,P.combinationOperator=k>>3&3,P.requiresBuffer=!!(32&k),P.combinationOperatorOverride=!!(64&k),r=[P];break;case 49:case 50:case 51:case 62:break;default:h("JBIG2 error: segment type "+l.typeName+"("+l.type+") is not implemented")}var I="on"+l.typeName;I in t&&t[I].apply(t,r)}function k(e,t){for(var r=0,n=e.length;r>3,r=new Uint8Array(t*e.height);if(e.defaultPixelValue)for(var n=0,i=r.length;n>3,f=s.combinationOperatorOverride?e.combinationOperator:s.combinationOperator,u=this.buffer,p=128>>(7&e.x),m=e.y*l+(e.x>>3);switch(f){case 0:for(r=0;r>=1)||(i=128,a++);m+=l}break;case 2:for(r=0;r>=1)||(i=128,a++);m+=l}break;default:h("JBIG2 error: operator "+f+" is not supported")}},onImmediateGenericRegion:function(e,r,n,i){var a=e.info,s=new t(r,n,i),o=v(e.mmr,a.width,a.height,e.template,e.prediction,null,e.at,s);this.drawBitmap(a,o)},onImmediateLosslessGenericRegion:function(){this.onImmediateGenericRegion.apply(this,arguments)},onSymbolDictionary:function(e,r,s,o,c,l){e.huffman&&h("JBIG2 error: huffman is not supported");var f=this.symbols;f||(this.symbols=f={});for(var u=[],p=0,m=s.length;p1)k=b(e,t,P,y,0,M,1,r.concat(d),x,0,0,1,0,0,u,p,m);else{var S=i(C,w,x),T=n(C,"IARDX",w),A=n(C,"IARDY",w);k=g(P,y,u,St;)t<<=1,r++;return r}function s(e,t){return e[t]<<24>>24}function o(e,t){return e[t]<<8|e[t+1]}function c(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!1}),r}var h=function(){throw console.error.apply(console,arguments),new Error("PDFJS error: "+arguments[0])},f=function(){console.warn.apply(console,arguments)},u=function(){console.info.apply(console,arguments)};i.prototype.parse=function(e){var t=0,r=e.length;151===e[t]&&74===e[t+1]&&66===e[t+2]&&50===e[t+3]&&13===e[t+4]&&10===e[t+5]&&26===e[t+6]&&10===e[t+7]||h("JBIG2 error: invalid header");var n={};t+=8;var i=e[t++];n.randomAccess=!(1&i),2&i||(n.numberOfPages=c(e,t),t+=4);for(var a=this.parseChunks([{data:e,start:t,end:r}]),s=a.currentPageInfo.width,o=a.currentPageInfo.height,l=a.buffer,f=(e=new Uint8Array(s*o),0),u=0,p=0;p>=1;this.width=s,this.height=o,this.data=e},e.JpegImage=t,e.JpxImage=n,e.Jbig2Image=i}(e||(e={}));var r=e.JpegImage,n=e.JpxImage,i=e.Jbig2Image; \ No newline at end of file diff --git a/libjpeg/build/debug/package.json b/libjpeg/build/debug/package.json new file mode 100644 index 0000000..953fec2 --- /dev/null +++ b/libjpeg/build/debug/package.json @@ -0,0 +1,16 @@ +{ + "pkgname": "libjpeg", + "app":"libjpeg", + "name":"libjpeg", + "description":"libjpeg", + "info":{ + "author": "", + "email": "" + }, + "version":"0.1.0-a", + "category":"Library", + "iconclass":"fa fa-cog", + "mimes":["none"], + "dependencies":[], + "locale": {} +} \ No newline at end of file diff --git a/libjpeg/build/release/libjpeg.zip b/libjpeg/build/release/libjpeg.zip new file mode 100644 index 0000000000000000000000000000000000000000..1a21944ed51f3dcb4987a2c93b6fa3e0a2f28017 GIT binary patch literal 54606 zcmd_TS#u*vvZyy#=Psr(J?aObC_6NONT86|2_RWwk*q29VKq5L)=al(oH7thkQibs zEF@7Z{($?c=ld+X|3zoOn_i@PoJ41nW+~dGcr~W4-XID;^bfc>EHkU zck<8ffBr9jy!)@iZ0f)L?sxM4e8Qf!PMsCTK|2&;^g5kX1_sr|KJ(-4+U>M$~!u${8@cMAjzNQw*I~w*! z?JLdwGzn+($uKp`k0+zqXto%K!Q*u}OHmzFyRWW=CvR%Mg|=O(DII2>JSlYFyPDms z7BfA`>o=3_ChT3`NY9t5xB1M+Cr>JFxN*`#Vwj=#``24rzfWzY{^x$L6Aq`LJnxOh zi-}a6Di-`o>ci-3uitN{-i_wNtF{1^Op@=&6uC-~9!^rTn=rLIZg=>xU%b?x!pW2Z zsbap6ViLmChW)gWX-XA~(L6P1FH*zNEH$5o)X|%!y1jmw3LiS*c$Vr7Q=QRZ-0!uA zoe;3hZnPa+OJ3^u+14?-oPhwTHU-9u)To=xm}<{#r&IiMGnO~Nnp-Xy$AT`p4XF`eqPFX?K(eV-alQtj(W z$hX-@I(^7byZ`{U24e>wbd z-%Eu+jJXLP#uFI<-Ruc8!z%^dX(%9%<}20ZySz`wVW-#abr{<4dJej$u19y_WXOn8 z<8U(QO=VW6bnr^L)b9;?GsTSQ^KnT-uYVuopEt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!x!s* zg3)wffYWznghsqvriq-_MaGbbom136*7-(^?PXtGxvRrhd9cjP=4MR{;mj1Gh!JtS zycGFT5lNlAlz8#Q4o+Um^5VW!cqzIv)#R7jcXU}s0E-}9x;7MX){Kij^iA-8CTIEK zlB_$B13g?|akB?|GmI#@oCiekCTJ;FhTv1}XsdNyPOQ`P`J)QcLwoTWlwGb}dqPiw zqkxP1<&GGREUx(y9XHx}dm!lI+_|cQpKc*|FNk$s0dib`%Ni+{p z{9G|MV#&kfqf0Z9=W$%*!uN|{uz7__S+q5XUh$_;>Zg1#mn-Ot=@c;l4PiuUAOTRq z{14;sT5qGkdqdtH%nLr4`5!KO*G2Q%gOboXq3fI}oZKuCmF0{Qmqk*WEZaQ!mw)>A zzyF>5v-_X_%OC%*>i_-tzw<2r|M&d=@nCoV!$E#<^*^Qhz01GSo8O=6iJBW64*u|Z zfA1_Mv*LUT^lFFpUHi0yL~@o-?e?c5bykpjPQ*!!40_4qRLiHhK%|gDE0Qv{pw^6G zn*aUp|3FOa`DJPhiZoK^H?!Gz+Iao?T2p1~c};lOL3@gc{vw>c{_FVquhWb4ugaE* zNBou%5C7wT*!BP2?|vu${|}5<$jbwxPj)@0%5~5Uyv1S zG*%N$-qlpX(JD|lJUuTWBx0jsn$srR^V!X4A}!jcG&Lkva$gg*`6t^8ge_{1-qoA-8Z@>GU{QsW- z?(#np`58E`7Fxx@xX=OBL>QSYwr(QhVzvKcd0J2Y= 0; i--) { + arr[i] = data.charCodeAt(i); + } + callback(arr.buffer); + return; + } + var xhr = new XMLHttpRequest(); + xhr.open("GET", path, true); + xhr.responseType = "arraybuffer"; + xhr.onload = function() { + callback(xhr.response); + }; + xhr.send(null); +} + +var JpegImage = function jpegImage() { + function JpegImage() { + this._src = null; + this._parser = new PDFJS.JpegImage(); + this.onload = null; + } + JpegImage.prototype = { + get src() { + return this._src; + }, + set src(value) { + this.load(value); + }, + get width() { + return this._parser.width; + }, + get height() { + return this._parser.height; + }, + load: function load(path) { + this._src = path; + loadURLasArrayBuffer(path, function(buffer) { + this.parse(new Uint8Array(buffer)); + if (this.onload) { + this.onload(); + } + }.bind(this)); + }, + parse: function(data) { + this._parser.parse(data); + }, + getData: function(width, height) { + return this._parser.getData(width, height, false); + }, + copyToImageData: function copyToImageData(imageData) { + if (this._parser.numComponents === 2 || this._parser.numComponents > 4) { + throw new Error("Unsupported amount of components"); + } + var width = imageData.width, height = imageData.height; + var imageDataBytes = width * height * 4; + var imageDataArray = imageData.data; + var i, j; + if (this._parser.numComponents === 1) { + var values = this._parser.getData(width, height, false); + for (i = 0, j = 0; i < imageDataBytes; ) { + var value = values[j++]; + imageDataArray[i++] = value; + imageDataArray[i++] = value; + imageDataArray[i++] = value; + imageDataArray[i++] = 255; + } + return; + } + var rgb = this._parser.getData(width, height, true); + for (i = 0, j = 0; i < imageDataBytes; ) { + imageDataArray[i++] = rgb[j++]; + imageDataArray[i++] = rgb[j++]; + imageDataArray[i++] = rgb[j++]; + imageDataArray[i++] = 255; + } + } + }; + return JpegImage; +}(); + +if (typeof exports === "function") { + module.exports = { + JpegImage: JpegImage, + JpegDecoder: JpegDecoder, + JpxDecoder: JpxDecoder, + Jbig2Decoder: Jbig2Decoder + }; +} + +var PDFJS; + +(function(PDFJS) { + "use strict"; + var JpegImage = function jpegImage() { + var dctZigZag = new Uint8Array([ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 ]); + var dctCos1 = 4017; + var dctSin1 = 799; + var dctCos3 = 3406; + var dctSin3 = 2276; + var dctCos6 = 1567; + var dctSin6 = 3784; + var dctSqrt2 = 5793; + var dctSqrt1d2 = 2896; + function constructor() {} + function buildHuffmanTable(codeLengths, values) { + var k = 0, code = [], i, j, length = 16; + while (length > 0 && !codeLengths[length - 1]) { + length--; + } + code.push({ + children: [], + index: 0 + }); + var p = code[0], q; + for (i = 0; i < length; i++) { + for (j = 0; j < codeLengths[i]; j++) { + p = code.pop(); + p.children[p.index] = values[k]; + while (p.index > 0) { + p = code.pop(); + } + p.index++; + code.push(p); + while (code.length <= i) { + code.push(q = { + children: [], + index: 0 + }); + p.children[p.index] = q.children; + p = q; + } + k++; + } + if (i + 1 < length) { + code.push(q = { + children: [], + index: 0 + }); + p.children[p.index] = q.children; + p = q; + } + } + return code[0].children; + } + function getBlockBufferOffset(component, row, col) { + return 64 * ((component.blocksPerLine + 1) * row + col); + } + function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) { + var precision = frame.precision; + var samplesPerLine = frame.samplesPerLine; + var scanLines = frame.scanLines; + var mcusPerLine = frame.mcusPerLine; + var progressive = frame.progressive; + var maxH = frame.maxH, maxV = frame.maxV; + var startOffset = offset, bitsData = 0, bitsCount = 0; + function readBit() { + if (bitsCount > 0) { + bitsCount--; + return bitsData >> bitsCount & 1; + } + bitsData = data[offset++]; + if (bitsData === 255) { + var nextByte = data[offset++]; + if (nextByte) { + throw "unexpected marker: " + (bitsData << 8 | nextByte).toString(16); + } + } + bitsCount = 7; + return bitsData >>> 7; + } + function decodeHuffman(tree) { + var node = tree; + while (true) { + node = node[readBit()]; + if (typeof node === "number") { + return node; + } + if (typeof node !== "object") { + throw "invalid huffman sequence"; + } + } + } + function receive(length) { + var n = 0; + while (length > 0) { + n = n << 1 | readBit(); + length--; + } + return n; + } + function receiveAndExtend(length) { + if (length === 1) { + return readBit() === 1 ? 1 : -1; + } + var n = receive(length); + if (n >= 1 << length - 1) { + return n; + } + return n + (-1 << length) + 1; + } + function decodeBaseline(component, offset) { + var t = decodeHuffman(component.huffmanTableDC); + var diff = t === 0 ? 0 : receiveAndExtend(t); + component.blockData[offset] = component.pred += diff; + var k = 1; + while (k < 64) { + var rs = decodeHuffman(component.huffmanTableAC); + var s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + break; + } + k += 16; + continue; + } + k += r; + var z = dctZigZag[k]; + component.blockData[offset + z] = receiveAndExtend(s); + k++; + } + } + function decodeDCFirst(component, offset) { + var t = decodeHuffman(component.huffmanTableDC); + var diff = t === 0 ? 0 : receiveAndExtend(t) << successive; + component.blockData[offset] = component.pred += diff; + } + function decodeDCSuccessive(component, offset) { + component.blockData[offset] |= readBit() << successive; + } + var eobrun = 0; + function decodeACFirst(component, offset) { + if (eobrun > 0) { + eobrun--; + return; + } + var k = spectralStart, e = spectralEnd; + while (k <= e) { + var rs = decodeHuffman(component.huffmanTableAC); + var s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r) - 1; + break; + } + k += 16; + continue; + } + k += r; + var z = dctZigZag[k]; + component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive); + k++; + } + } + var successiveACState = 0, successiveACNextValue; + function decodeACSuccessive(component, offset) { + var k = spectralStart; + var e = spectralEnd; + var r = 0; + var s; + var rs; + while (k <= e) { + var z = dctZigZag[k]; + switch (successiveACState) { + case 0: + rs = decodeHuffman(component.huffmanTableAC); + s = rs & 15; + r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r); + successiveACState = 4; + } else { + r = 16; + successiveACState = 1; + } + } else { + if (s !== 1) { + throw "invalid ACn encoding"; + } + successiveACNextValue = receiveAndExtend(s); + successiveACState = r ? 2 : 3; + } + continue; + + case 1: + case 2: + if (component.blockData[offset + z]) { + component.blockData[offset + z] += readBit() << successive; + } else { + r--; + if (r === 0) { + successiveACState = successiveACState === 2 ? 3 : 0; + } + } + break; + + case 3: + if (component.blockData[offset + z]) { + component.blockData[offset + z] += readBit() << successive; + } else { + component.blockData[offset + z] = successiveACNextValue << successive; + successiveACState = 0; + } + break; + + case 4: + if (component.blockData[offset + z]) { + component.blockData[offset + z] += readBit() << successive; + } + break; + } + k++; + } + if (successiveACState === 4) { + eobrun--; + if (eobrun === 0) { + successiveACState = 0; + } + } + } + function decodeMcu(component, decode, mcu, row, col) { + var mcuRow = mcu / mcusPerLine | 0; + var mcuCol = mcu % mcusPerLine; + var blockRow = mcuRow * component.v + row; + var blockCol = mcuCol * component.h + col; + var offset = getBlockBufferOffset(component, blockRow, blockCol); + decode(component, offset); + } + function decodeBlock(component, decode, mcu) { + var blockRow = mcu / component.blocksPerLine | 0; + var blockCol = mcu % component.blocksPerLine; + var offset = getBlockBufferOffset(component, blockRow, blockCol); + decode(component, offset); + } + var componentsLength = components.length; + var component, i, j, k, n; + var decodeFn; + if (progressive) { + if (spectralStart === 0) { + decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; + } else { + decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; + } + } else { + decodeFn = decodeBaseline; + } + var mcu = 0, marker; + var mcuExpected; + if (componentsLength === 1) { + mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; + } else { + mcuExpected = mcusPerLine * frame.mcusPerColumn; + } + if (!resetInterval) { + resetInterval = mcuExpected; + } + var h, v; + while (mcu < mcuExpected) { + for (i = 0; i < componentsLength; i++) { + components[i].pred = 0; + } + eobrun = 0; + if (componentsLength === 1) { + component = components[0]; + for (n = 0; n < resetInterval; n++) { + decodeBlock(component, decodeFn, mcu); + mcu++; + } + } else { + for (n = 0; n < resetInterval; n++) { + for (i = 0; i < componentsLength; i++) { + component = components[i]; + h = component.h; + v = component.v; + for (j = 0; j < v; j++) { + for (k = 0; k < h; k++) { + decodeMcu(component, decodeFn, mcu, j, k); + } + } + } + mcu++; + } + } + bitsCount = 0; + marker = data[offset] << 8 | data[offset + 1]; + if (marker <= 65280) { + throw "marker was not found"; + } + if (marker >= 65488 && marker <= 65495) { + offset += 2; + } else { + break; + } + } + return offset - startOffset; + } + function quantizeAndInverse(component, blockBufferOffset, p) { + var qt = component.quantizationTable, blockData = component.blockData; + var v0, v1, v2, v3, v4, v5, v6, v7; + var p0, p1, p2, p3, p4, p5, p6, p7; + var t; + for (var row = 0; row < 64; row += 8) { + p0 = blockData[blockBufferOffset + row]; + p1 = blockData[blockBufferOffset + row + 1]; + p2 = blockData[blockBufferOffset + row + 2]; + p3 = blockData[blockBufferOffset + row + 3]; + p4 = blockData[blockBufferOffset + row + 4]; + p5 = blockData[blockBufferOffset + row + 5]; + p6 = blockData[blockBufferOffset + row + 6]; + p7 = blockData[blockBufferOffset + row + 7]; + p0 *= qt[row]; + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { + t = dctSqrt2 * p0 + 512 >> 10; + p[row] = t; + p[row + 1] = t; + p[row + 2] = t; + p[row + 3] = t; + p[row + 4] = t; + p[row + 5] = t; + p[row + 6] = t; + p[row + 7] = t; + continue; + } + p1 *= qt[row + 1]; + p2 *= qt[row + 2]; + p3 *= qt[row + 3]; + p4 *= qt[row + 4]; + p5 *= qt[row + 5]; + p6 *= qt[row + 6]; + p7 *= qt[row + 7]; + v0 = dctSqrt2 * p0 + 128 >> 8; + v1 = dctSqrt2 * p4 + 128 >> 8; + v2 = p2; + v3 = p6; + v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8; + v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8; + v5 = p3 << 4; + v6 = p5 << 4; + v0 = v0 + v1 + 1 >> 1; + v1 = v0 - v1; + t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8; + v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8; + v3 = t; + v4 = v4 + v6 + 1 >> 1; + v6 = v4 - v6; + v7 = v7 + v5 + 1 >> 1; + v5 = v7 - v5; + v0 = v0 + v3 + 1 >> 1; + v3 = v0 - v3; + v1 = v1 + v2 + 1 >> 1; + v2 = v1 - v2; + t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; + v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; + v7 = t; + t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; + v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; + v6 = t; + p[row] = v0 + v7; + p[row + 7] = v0 - v7; + p[row + 1] = v1 + v6; + p[row + 6] = v1 - v6; + p[row + 2] = v2 + v5; + p[row + 5] = v2 - v5; + p[row + 3] = v3 + v4; + p[row + 4] = v3 - v4; + } + for (var col = 0; col < 8; ++col) { + p0 = p[col]; + p1 = p[col + 8]; + p2 = p[col + 16]; + p3 = p[col + 24]; + p4 = p[col + 32]; + p5 = p[col + 40]; + p6 = p[col + 48]; + p7 = p[col + 56]; + if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { + t = dctSqrt2 * p0 + 8192 >> 14; + t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4; + blockData[blockBufferOffset + col] = t; + blockData[blockBufferOffset + col + 8] = t; + blockData[blockBufferOffset + col + 16] = t; + blockData[blockBufferOffset + col + 24] = t; + blockData[blockBufferOffset + col + 32] = t; + blockData[blockBufferOffset + col + 40] = t; + blockData[blockBufferOffset + col + 48] = t; + blockData[blockBufferOffset + col + 56] = t; + continue; + } + v0 = dctSqrt2 * p0 + 2048 >> 12; + v1 = dctSqrt2 * p4 + 2048 >> 12; + v2 = p2; + v3 = p6; + v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12; + v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12; + v5 = p3; + v6 = p5; + v0 = (v0 + v1 + 1 >> 1) + 4112; + v1 = v0 - v1; + t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12; + v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12; + v3 = t; + v4 = v4 + v6 + 1 >> 1; + v6 = v4 - v6; + v7 = v7 + v5 + 1 >> 1; + v5 = v7 - v5; + v0 = v0 + v3 + 1 >> 1; + v3 = v0 - v3; + v1 = v1 + v2 + 1 >> 1; + v2 = v1 - v2; + t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; + v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; + v7 = t; + t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; + v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; + v6 = t; + p0 = v0 + v7; + p7 = v0 - v7; + p1 = v1 + v6; + p6 = v1 - v6; + p2 = v2 + v5; + p5 = v2 - v5; + p3 = v3 + v4; + p4 = v3 - v4; + p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4; + p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4; + p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4; + p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4; + p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4; + p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4; + p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4; + p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4; + blockData[blockBufferOffset + col] = p0; + blockData[blockBufferOffset + col + 8] = p1; + blockData[blockBufferOffset + col + 16] = p2; + blockData[blockBufferOffset + col + 24] = p3; + blockData[blockBufferOffset + col + 32] = p4; + blockData[blockBufferOffset + col + 40] = p5; + blockData[blockBufferOffset + col + 48] = p6; + blockData[blockBufferOffset + col + 56] = p7; + } + } + function buildComponentData(frame, component) { + var blocksPerLine = component.blocksPerLine; + var blocksPerColumn = component.blocksPerColumn; + var computationBuffer = new Int16Array(64); + for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) { + for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) { + var offset = getBlockBufferOffset(component, blockRow, blockCol); + quantizeAndInverse(component, offset, computationBuffer); + } + } + return component.blockData; + } + function clamp0to255(a) { + return a <= 0 ? 0 : a >= 255 ? 255 : a; + } + constructor.prototype = { + parse: function parse(data) { + function readUint16() { + var value = data[offset] << 8 | data[offset + 1]; + offset += 2; + return value; + } + function readDataBlock() { + var length = readUint16(); + var array = data.subarray(offset, offset + length - 2); + offset += array.length; + return array; + } + function prepareComponents(frame) { + var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH); + var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV); + for (var i = 0; i < frame.components.length; i++) { + component = frame.components[i]; + var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH); + var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV); + var blocksPerLineForMcu = mcusPerLine * component.h; + var blocksPerColumnForMcu = mcusPerColumn * component.v; + var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1); + component.blockData = new Int16Array(blocksBufferSize); + component.blocksPerLine = blocksPerLine; + component.blocksPerColumn = blocksPerColumn; + } + frame.mcusPerLine = mcusPerLine; + frame.mcusPerColumn = mcusPerColumn; + } + var offset = 0, length = data.length; + var jfif = null; + var adobe = null; + var pixels = null; + var frame, resetInterval; + var quantizationTables = []; + var huffmanTablesAC = [], huffmanTablesDC = []; + var fileMarker = readUint16(); + if (fileMarker !== 65496) { + throw "SOI not found"; + } + fileMarker = readUint16(); + while (fileMarker !== 65497) { + var i, j, l; + switch (fileMarker) { + 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: + case 65534: + var appData = readDataBlock(); + if (fileMarker === 65504) { + if (appData[0] === 74 && appData[1] === 70 && appData[2] === 73 && appData[3] === 70 && appData[4] === 0) { + jfif = { + version: { + major: appData[5], + minor: appData[6] + }, + densityUnits: appData[7], + xDensity: appData[8] << 8 | appData[9], + yDensity: appData[10] << 8 | appData[11], + thumbWidth: appData[12], + thumbHeight: appData[13], + thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13]) + }; + } + } + if (fileMarker === 65518) { + if (appData[0] === 65 && appData[1] === 100 && appData[2] === 111 && appData[3] === 98 && appData[4] === 101 && appData[5] === 0) { + adobe = { + version: appData[6], + flags0: appData[7] << 8 | appData[8], + flags1: appData[9] << 8 | appData[10], + transformCode: appData[11] + }; + } + } + break; + + case 65499: + var quantizationTablesLength = readUint16(); + var quantizationTablesEnd = quantizationTablesLength + offset - 2; + var z; + while (offset < quantizationTablesEnd) { + var quantizationTableSpec = data[offset++]; + var tableData = new Uint16Array(64); + if (quantizationTableSpec >> 4 === 0) { + for (j = 0; j < 64; j++) { + z = dctZigZag[j]; + tableData[z] = data[offset++]; + } + } else if (quantizationTableSpec >> 4 === 1) { + for (j = 0; j < 64; j++) { + z = dctZigZag[j]; + tableData[z] = readUint16(); + } + } else { + throw "DQT: invalid table spec"; + } + quantizationTables[quantizationTableSpec & 15] = tableData; + } + break; + + case 65472: + case 65473: + case 65474: + if (frame) { + throw "Only single frame JPEGs supported"; + } + readUint16(); + frame = {}; + frame.extended = fileMarker === 65473; + frame.progressive = fileMarker === 65474; + frame.precision = data[offset++]; + frame.scanLines = readUint16(); + frame.samplesPerLine = readUint16(); + frame.components = []; + frame.componentIds = {}; + var componentsCount = data[offset++], componentId; + var maxH = 0, maxV = 0; + for (i = 0; i < componentsCount; i++) { + componentId = data[offset]; + var h = data[offset + 1] >> 4; + var v = data[offset + 1] & 15; + if (maxH < h) { + maxH = h; + } + if (maxV < v) { + maxV = v; + } + var qId = data[offset + 2]; + l = frame.components.push({ + h: h, + v: v, + quantizationTable: quantizationTables[qId] + }); + frame.componentIds[componentId] = l - 1; + offset += 3; + } + frame.maxH = maxH; + frame.maxV = maxV; + prepareComponents(frame); + break; + + case 65476: + var huffmanLength = readUint16(); + for (i = 2; i < huffmanLength; ) { + var huffmanTableSpec = data[offset++]; + var codeLengths = new Uint8Array(16); + var codeLengthSum = 0; + for (j = 0; j < 16; j++, offset++) { + codeLengthSum += codeLengths[j] = data[offset]; + } + var huffmanValues = new Uint8Array(codeLengthSum); + for (j = 0; j < codeLengthSum; j++, offset++) { + huffmanValues[j] = data[offset]; + } + i += 17 + codeLengthSum; + (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues); + } + break; + + case 65501: + readUint16(); + resetInterval = readUint16(); + break; + + case 65498: + var scanLength = readUint16(); + var selectorsCount = data[offset++]; + var components = [], component; + for (i = 0; i < selectorsCount; i++) { + var componentIndex = frame.componentIds[data[offset++]]; + component = frame.components[componentIndex]; + var tableSpec = data[offset++]; + component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; + component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; + components.push(component); + } + var spectralStart = data[offset++]; + var spectralEnd = data[offset++]; + var successiveApproximation = data[offset++]; + var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15); + offset += processed; + break; + + case 65535: + if (data[offset] !== 255) { + offset--; + } + break; + + default: + if (data[offset - 3] === 255 && data[offset - 2] >= 192 && data[offset - 2] <= 254) { + offset -= 3; + break; + } + throw "unknown JPEG marker " + fileMarker.toString(16); + } + fileMarker = readUint16(); + } + this.width = frame.samplesPerLine; + this.height = frame.scanLines; + this.jfif = jfif; + this.adobe = adobe; + this.components = []; + for (i = 0; i < frame.components.length; i++) { + component = frame.components[i]; + this.components.push({ + output: buildComponentData(frame, component), + scaleX: component.h / frame.maxH, + scaleY: component.v / frame.maxV, + blocksPerLine: component.blocksPerLine, + blocksPerColumn: component.blocksPerColumn + }); + } + this.numComponents = this.components.length; + }, + _getLinearizedBlockData: function getLinearizedBlockData(width, height) { + var scaleX = this.width / width, scaleY = this.height / height; + var component, componentScaleX, componentScaleY, blocksPerScanline; + var x, y, i, j, k; + var index; + var offset = 0; + var output; + var numComponents = this.components.length; + var dataLength = width * height * numComponents; + var data = new Uint8Array(dataLength); + var xScaleBlockOffset = new Uint32Array(width); + var mask3LSB = 4294967288; + for (i = 0; i < numComponents; i++) { + component = this.components[i]; + componentScaleX = component.scaleX * scaleX; + componentScaleY = component.scaleY * scaleY; + offset = i; + output = component.output; + blocksPerScanline = component.blocksPerLine + 1 << 3; + for (x = 0; x < width; x++) { + j = 0 | x * componentScaleX; + xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7; + } + for (y = 0; y < height; y++) { + j = 0 | y * componentScaleY; + index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3; + for (x = 0; x < width; x++) { + data[offset] = output[index + xScaleBlockOffset[x]]; + offset += numComponents; + } + } + } + var transform = this.decodeTransform; + if (transform) { + for (i = 0; i < dataLength; ) { + for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) { + data[i] = (data[i] * transform[k] >> 8) + transform[k + 1]; + } + } + } + return data; + }, + _isColorConversionNeeded: function isColorConversionNeeded() { + if (this.adobe && this.adobe.transformCode) { + return true; + } else if (this.numComponents === 3) { + return true; + } else { + return false; + } + }, + _convertYccToRgb: function convertYccToRgb(data) { + var Y, Cb, Cr; + for (var i = 0, length = data.length; i < length; i += 3) { + Y = data[i]; + Cb = data[i + 1]; + Cr = data[i + 2]; + data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr); + data[i + 1] = clamp0to255(Y + 135.459 - .344 * Cb - .714 * Cr); + data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb); + } + return data; + }, + _convertYcckToRgb: function convertYcckToRgb(data) { + var Y, Cb, Cr, k; + var offset = 0; + for (var i = 0, length = data.length; i < length; i += 4) { + Y = data[i]; + Cb = data[i + 1]; + Cr = data[i + 2]; + k = data[i + 3]; + var r = -122.67195406894 + Cb * (-660635669420364e-19 * Cb + .000437130475926232 * Cr - 54080610064599e-18 * Y + .00048449797120281 * k - .154362151871126) + Cr * (-.000957964378445773 * Cr + .000817076911346625 * Y - .00477271405408747 * k + 1.53380253221734) + Y * (.000961250184130688 * Y - .00266257332283933 * k + .48357088451265) + k * (-.000336197177618394 * k + .484791561490776); + var g = 107.268039397724 + Cb * (219927104525741e-19 * Cb - .000640992018297945 * Cr + .000659397001245577 * Y + .000426105652938837 * k - .176491792462875) + Cr * (-.000778269941513683 * Cr + .00130872261408275 * Y + .000770482631801132 * k - .151051492775562) + Y * (.00126935368114843 * Y - .00265090189010898 * k + .25802910206845) + k * (-.000318913117588328 * k - .213742400323665); + var b = -20.810012546947 + Cb * (-.000570115196973677 * Cb - 263409051004589e-19 * Cr + .0020741088115012 * Y - .00288260236853442 * k + .814272968359295) + Cr * (-153496057440975e-19 * Cr - .000132689043961446 * Y + .000560833691242812 * k - .195152027534049) + Y * (.00174418132927582 * Y - .00255243321439347 * k + .116935020465145) + k * (-.000343531996510555 * k + .24165260232407); + data[offset++] = clamp0to255(r); + data[offset++] = clamp0to255(g); + data[offset++] = clamp0to255(b); + } + return data; + }, + _convertYcckToCmyk: function convertYcckToCmyk(data) { + var Y, Cb, Cr; + for (var i = 0, length = data.length; i < length; i += 4) { + Y = data[i]; + Cb = data[i + 1]; + Cr = data[i + 2]; + data[i] = clamp0to255(434.456 - Y - 1.402 * Cr); + data[i + 1] = clamp0to255(119.541 - Y + .344 * Cb + .714 * Cr); + data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb); + } + return data; + }, + _convertCmykToRgb: function convertCmykToRgb(data) { + var c, m, y, k; + var offset = 0; + var min = -255 * 255 * 255; + var scale = 1 / 255 / 255; + for (var i = 0, length = data.length; i < length; i += 4) { + c = data[i]; + m = data[i + 1]; + y = data[i + 2]; + k = data[i + 3]; + var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k - 72734.4411664936) + m * (1.7149763477362134 * m - 5.6096736904047315 * y - 17.873870861415444 * k - 1401.7366389350734) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 4465.541406466231) - k * (21.86122147463605 * k + 48317.86113160301); + var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 20220.756542821975) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 48691.05921601825) + y * (4.444339102852739 * y + 9.8632861493405 * k - 6341.191035517494) - k * (20.737325471181034 * k + 47890.15695978492); + var b = c * (.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - .23883238689178934 * k - 3616.812083916688) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 28620.90484698408) + y * (.03296041114873217 * y + 115.60384449646641 * k - 49363.43385999684) - k * (22.33816807309886 * k + 45932.16563550634); + data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0; + data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0; + data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0; + } + return data; + }, + getData: function getData(width, height, forceRGBoutput) { + if (this.numComponents > 4) { + throw "Unsupported color mode"; + } + var data = this._getLinearizedBlockData(width, height); + if (this.numComponents === 3) { + return this._convertYccToRgb(data); + } else if (this.numComponents === 4) { + if (this._isColorConversionNeeded()) { + if (forceRGBoutput) { + return this._convertYcckToRgb(data); + } else { + return this._convertYcckToCmyk(data); + } + } else if (forceRGBoutput) { + return this._convertCmykToRgb(data); + } + } + return data; + } + }; + return constructor; + }(); + "use strict"; + var ArithmeticDecoder = function ArithmeticDecoderClosure() { + var QeTable = [ { + qe: 22017, + nmps: 1, + nlps: 1, + switchFlag: 1 + }, { + qe: 13313, + nmps: 2, + nlps: 6, + switchFlag: 0 + }, { + qe: 6145, + nmps: 3, + nlps: 9, + switchFlag: 0 + }, { + qe: 2753, + nmps: 4, + nlps: 12, + switchFlag: 0 + }, { + qe: 1313, + nmps: 5, + nlps: 29, + switchFlag: 0 + }, { + qe: 545, + nmps: 38, + nlps: 33, + switchFlag: 0 + }, { + qe: 22017, + nmps: 7, + nlps: 6, + switchFlag: 1 + }, { + qe: 21505, + nmps: 8, + nlps: 14, + switchFlag: 0 + }, { + qe: 18433, + nmps: 9, + nlps: 14, + switchFlag: 0 + }, { + qe: 14337, + nmps: 10, + nlps: 14, + switchFlag: 0 + }, { + qe: 12289, + nmps: 11, + nlps: 17, + switchFlag: 0 + }, { + qe: 9217, + nmps: 12, + nlps: 18, + switchFlag: 0 + }, { + qe: 7169, + nmps: 13, + nlps: 20, + switchFlag: 0 + }, { + qe: 5633, + nmps: 29, + nlps: 21, + switchFlag: 0 + }, { + qe: 22017, + nmps: 15, + nlps: 14, + switchFlag: 1 + }, { + qe: 21505, + nmps: 16, + nlps: 14, + switchFlag: 0 + }, { + qe: 20737, + nmps: 17, + nlps: 15, + switchFlag: 0 + }, { + qe: 18433, + nmps: 18, + nlps: 16, + switchFlag: 0 + }, { + qe: 14337, + nmps: 19, + nlps: 17, + switchFlag: 0 + }, { + qe: 13313, + nmps: 20, + nlps: 18, + switchFlag: 0 + }, { + qe: 12289, + nmps: 21, + nlps: 19, + switchFlag: 0 + }, { + qe: 10241, + nmps: 22, + nlps: 19, + switchFlag: 0 + }, { + qe: 9217, + nmps: 23, + nlps: 20, + switchFlag: 0 + }, { + qe: 8705, + nmps: 24, + nlps: 21, + switchFlag: 0 + }, { + qe: 7169, + nmps: 25, + nlps: 22, + switchFlag: 0 + }, { + qe: 6145, + nmps: 26, + nlps: 23, + switchFlag: 0 + }, { + qe: 5633, + nmps: 27, + nlps: 24, + switchFlag: 0 + }, { + qe: 5121, + nmps: 28, + nlps: 25, + switchFlag: 0 + }, { + qe: 4609, + nmps: 29, + nlps: 26, + switchFlag: 0 + }, { + qe: 4353, + nmps: 30, + nlps: 27, + switchFlag: 0 + }, { + qe: 2753, + nmps: 31, + nlps: 28, + switchFlag: 0 + }, { + qe: 2497, + nmps: 32, + nlps: 29, + switchFlag: 0 + }, { + qe: 2209, + nmps: 33, + nlps: 30, + switchFlag: 0 + }, { + qe: 1313, + nmps: 34, + nlps: 31, + switchFlag: 0 + }, { + qe: 1089, + nmps: 35, + nlps: 32, + switchFlag: 0 + }, { + qe: 673, + nmps: 36, + nlps: 33, + switchFlag: 0 + }, { + qe: 545, + nmps: 37, + nlps: 34, + switchFlag: 0 + }, { + qe: 321, + nmps: 38, + nlps: 35, + switchFlag: 0 + }, { + qe: 273, + nmps: 39, + nlps: 36, + switchFlag: 0 + }, { + qe: 133, + nmps: 40, + nlps: 37, + switchFlag: 0 + }, { + qe: 73, + nmps: 41, + nlps: 38, + switchFlag: 0 + }, { + qe: 37, + nmps: 42, + nlps: 39, + switchFlag: 0 + }, { + qe: 21, + nmps: 43, + nlps: 40, + switchFlag: 0 + }, { + qe: 9, + nmps: 44, + nlps: 41, + switchFlag: 0 + }, { + qe: 5, + nmps: 45, + nlps: 42, + switchFlag: 0 + }, { + qe: 1, + nmps: 45, + nlps: 43, + switchFlag: 0 + }, { + qe: 22017, + nmps: 46, + nlps: 46, + switchFlag: 0 + } ]; + function ArithmeticDecoder(data, start, end) { + this.data = data; + this.bp = start; + this.dataEnd = end; + this.chigh = data[start]; + this.clow = 0; + this.byteIn(); + this.chigh = this.chigh << 7 & 65535 | this.clow >> 9 & 127; + this.clow = this.clow << 7 & 65535; + this.ct -= 7; + this.a = 32768; + } + ArithmeticDecoder.prototype = { + byteIn: function ArithmeticDecoder_byteIn() { + var data = this.data; + var bp = this.bp; + if (data[bp] === 255) { + var b1 = data[bp + 1]; + if (b1 > 143) { + this.clow += 65280; + this.ct = 8; + } else { + bp++; + this.clow += data[bp] << 9; + this.ct = 7; + this.bp = bp; + } + } else { + bp++; + this.clow += bp < this.dataEnd ? data[bp] << 8 : 65280; + this.ct = 8; + this.bp = bp; + } + if (this.clow > 65535) { + this.chigh += this.clow >> 16; + this.clow &= 65535; + } + }, + readBit: function ArithmeticDecoder_readBit(contexts, pos) { + var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1; + var qeTableIcx = QeTable[cx_index]; + var qeIcx = qeTableIcx.qe; + var d; + var a = this.a - qeIcx; + if (this.chigh < qeIcx) { + if (a < qeIcx) { + a = qeIcx; + d = cx_mps; + cx_index = qeTableIcx.nmps; + } else { + a = qeIcx; + d = 1 ^ cx_mps; + if (qeTableIcx.switchFlag === 1) { + cx_mps = d; + } + cx_index = qeTableIcx.nlps; + } + } else { + this.chigh -= qeIcx; + if ((a & 32768) !== 0) { + this.a = a; + return cx_mps; + } + if (a < qeIcx) { + d = 1 ^ cx_mps; + if (qeTableIcx.switchFlag === 1) { + cx_mps = d; + } + cx_index = qeTableIcx.nlps; + } else { + d = cx_mps; + cx_index = qeTableIcx.nmps; + } + } + do { + if (this.ct === 0) { + this.byteIn(); + } + a <<= 1; + this.chigh = this.chigh << 1 & 65535 | this.clow >> 15 & 1; + this.clow = this.clow << 1 & 65535; + this.ct--; + } while ((a & 32768) === 0); + this.a = a; + contexts[pos] = cx_index << 1 | cx_mps; + return d; + } + }; + return ArithmeticDecoder; + }(); + "use strict"; + var JpxImage = function JpxImageClosure() { + var SubbandsGainLog2 = { + LL: 0, + LH: 1, + HL: 1, + HH: 2 + }; + function JpxImage() { + this.failOnCorruptedImage = false; + } + JpxImage.prototype = { + parse: function JpxImage_parse(data) { + var head = readUint16(data, 0); + if (head === 65359) { + this.parseCodestream(data, 0, data.length); + return; + } + var position = 0, length = data.length; + while (position < length) { + var headerSize = 8; + var lbox = readUint32(data, position); + var tbox = readUint32(data, position + 4); + position += headerSize; + if (lbox === 1) { + lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4); + position += 8; + headerSize += 8; + } + if (lbox === 0) { + lbox = length - position + headerSize; + } + if (lbox < headerSize) { + throw new Error("JPX Error: Invalid box field size"); + } + var dataLength = lbox - headerSize; + var jumpDataLength = true; + switch (tbox) { + case 1785737832: + jumpDataLength = false; + break; + + case 1668246642: + var method = data[position]; + var precedence = data[position + 1]; + var approximation = data[position + 2]; + if (method === 1) { + var colorspace = readUint32(data, position + 3); + switch (colorspace) { + case 16: + case 17: + case 18: + break; + + default: + warn("Unknown colorspace " + colorspace); + break; + } + } else if (method === 2) { + info("ICC profile not supported"); + } + break; + + case 1785737827: + this.parseCodestream(data, position, position + dataLength); + break; + + case 1783636e3: + if (218793738 !== readUint32(data, position)) { + warn("Invalid JP2 signature"); + } + break; + + case 1783634458: + case 1718909296: + case 1920099697: + case 1919251232: + case 1768449138: + break; + + default: + var headerType = String.fromCharCode(tbox >> 24 & 255, tbox >> 16 & 255, tbox >> 8 & 255, tbox & 255); + warn("Unsupported header type " + tbox + " (" + headerType + ")"); + break; + } + if (jumpDataLength) { + position += dataLength; + } + } + }, + parseImageProperties: function JpxImage_parseImageProperties(stream) { + var newByte = stream.getByte(); + while (newByte >= 0) { + var oldByte = newByte; + newByte = stream.getByte(); + var code = oldByte << 8 | newByte; + if (code === 65361) { + stream.skip(4); + var Xsiz = stream.getInt32() >>> 0; + var Ysiz = stream.getInt32() >>> 0; + var XOsiz = stream.getInt32() >>> 0; + var YOsiz = stream.getInt32() >>> 0; + stream.skip(16); + var Csiz = stream.getUint16(); + this.width = Xsiz - XOsiz; + this.height = Ysiz - YOsiz; + this.componentsCount = Csiz; + this.bitsPerComponent = 8; + return; + } + } + throw new Error("JPX Error: No size marker found in JPX stream"); + }, + parseCodestream: function JpxImage_parseCodestream(data, start, end) { + var context = {}; + try { + var doNotRecover = false; + var position = start; + while (position + 1 < end) { + var code = readUint16(data, position); + position += 2; + var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile; + switch (code) { + case 65359: + context.mainHeader = true; + break; + + case 65497: + break; + + case 65361: + length = readUint16(data, position); + var siz = {}; + siz.Xsiz = readUint32(data, position + 4); + siz.Ysiz = readUint32(data, position + 8); + siz.XOsiz = readUint32(data, position + 12); + siz.YOsiz = readUint32(data, position + 16); + siz.XTsiz = readUint32(data, position + 20); + siz.YTsiz = readUint32(data, position + 24); + siz.XTOsiz = readUint32(data, position + 28); + siz.YTOsiz = readUint32(data, position + 32); + var componentsCount = readUint16(data, position + 36); + siz.Csiz = componentsCount; + var components = []; + j = position + 38; + for (var i = 0; i < componentsCount; i++) { + var component = { + precision: (data[j] & 127) + 1, + isSigned: !!(data[j] & 128), + XRsiz: data[j + 1], + YRsiz: data[j + 1] + }; + calculateComponentDimensions(component, siz); + components.push(component); + } + context.SIZ = siz; + context.components = components; + calculateTileGrids(context, components); + context.QCC = []; + context.COC = []; + break; + + case 65372: + length = readUint16(data, position); + var qcd = {}; + j = position + 2; + sqcd = data[j++]; + switch (sqcd & 31) { + case 0: + spqcdSize = 8; + scalarExpounded = true; + break; + + case 1: + spqcdSize = 16; + scalarExpounded = false; + break; + + case 2: + spqcdSize = 16; + scalarExpounded = true; + break; + + default: + throw new Error("JPX Error: Invalid SQcd value " + sqcd); + } + qcd.noQuantization = spqcdSize === 8; + qcd.scalarExpounded = scalarExpounded; + qcd.guardBits = sqcd >> 5; + spqcds = []; + while (j < length + position) { + var spqcd = {}; + if (spqcdSize === 8) { + spqcd.epsilon = data[j++] >> 3; + spqcd.mu = 0; + } else { + spqcd.epsilon = data[j] >> 3; + spqcd.mu = (data[j] & 7) << 8 | data[j + 1]; + j += 2; + } + spqcds.push(spqcd); + } + qcd.SPqcds = spqcds; + if (context.mainHeader) { + context.QCD = qcd; + } else { + context.currentTile.QCD = qcd; + context.currentTile.QCC = []; + } + break; + + case 65373: + length = readUint16(data, position); + var qcc = {}; + j = position + 2; + var cqcc; + if (context.SIZ.Csiz < 257) { + cqcc = data[j++]; + } else { + cqcc = readUint16(data, j); + j += 2; + } + sqcd = data[j++]; + switch (sqcd & 31) { + case 0: + spqcdSize = 8; + scalarExpounded = true; + break; + + case 1: + spqcdSize = 16; + scalarExpounded = false; + break; + + case 2: + spqcdSize = 16; + scalarExpounded = true; + break; + + default: + throw new Error("JPX Error: Invalid SQcd value " + sqcd); + } + qcc.noQuantization = spqcdSize === 8; + qcc.scalarExpounded = scalarExpounded; + qcc.guardBits = sqcd >> 5; + spqcds = []; + while (j < length + position) { + spqcd = {}; + if (spqcdSize === 8) { + spqcd.epsilon = data[j++] >> 3; + spqcd.mu = 0; + } else { + spqcd.epsilon = data[j] >> 3; + spqcd.mu = (data[j] & 7) << 8 | data[j + 1]; + j += 2; + } + spqcds.push(spqcd); + } + qcc.SPqcds = spqcds; + if (context.mainHeader) { + context.QCC[cqcc] = qcc; + } else { + context.currentTile.QCC[cqcc] = qcc; + } + break; + + case 65362: + length = readUint16(data, position); + var cod = {}; + j = position + 2; + var scod = data[j++]; + cod.entropyCoderWithCustomPrecincts = !!(scod & 1); + cod.sopMarkerUsed = !!(scod & 2); + cod.ephMarkerUsed = !!(scod & 4); + cod.progressionOrder = data[j++]; + cod.layersCount = readUint16(data, j); + j += 2; + cod.multipleComponentTransform = data[j++]; + cod.decompositionLevelsCount = data[j++]; + cod.xcb = (data[j++] & 15) + 2; + cod.ycb = (data[j++] & 15) + 2; + var blockStyle = data[j++]; + cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1); + cod.resetContextProbabilities = !!(blockStyle & 2); + cod.terminationOnEachCodingPass = !!(blockStyle & 4); + cod.verticalyStripe = !!(blockStyle & 8); + cod.predictableTermination = !!(blockStyle & 16); + cod.segmentationSymbolUsed = !!(blockStyle & 32); + cod.reversibleTransformation = data[j++]; + if (cod.entropyCoderWithCustomPrecincts) { + var precinctsSizes = []; + while (j < length + position) { + var precinctsSize = data[j++]; + precinctsSizes.push({ + PPx: precinctsSize & 15, + PPy: precinctsSize >> 4 + }); + } + cod.precinctsSizes = precinctsSizes; + } + var unsupported = []; + if (cod.selectiveArithmeticCodingBypass) { + unsupported.push("selectiveArithmeticCodingBypass"); + } + if (cod.resetContextProbabilities) { + unsupported.push("resetContextProbabilities"); + } + if (cod.terminationOnEachCodingPass) { + unsupported.push("terminationOnEachCodingPass"); + } + if (cod.verticalyStripe) { + unsupported.push("verticalyStripe"); + } + if (cod.predictableTermination) { + unsupported.push("predictableTermination"); + } + if (unsupported.length > 0) { + doNotRecover = true; + throw new Error("JPX Error: Unsupported COD options (" + unsupported.join(", ") + ")"); + } + if (context.mainHeader) { + context.COD = cod; + } else { + context.currentTile.COD = cod; + context.currentTile.COC = []; + } + break; + + case 65424: + length = readUint16(data, position); + tile = {}; + tile.index = readUint16(data, position + 2); + tile.length = readUint32(data, position + 4); + tile.dataEnd = tile.length + position - 2; + tile.partIndex = data[position + 8]; + tile.partsCount = data[position + 9]; + context.mainHeader = false; + if (tile.partIndex === 0) { + tile.COD = context.COD; + tile.COC = context.COC.slice(0); + tile.QCD = context.QCD; + tile.QCC = context.QCC.slice(0); + } + context.currentTile = tile; + break; + + case 65427: + tile = context.currentTile; + if (tile.partIndex === 0) { + initializeTile(context, tile.index); + buildPackets(context); + } + length = tile.dataEnd - position; + parseTilePackets(context, data, position, length); + break; + + case 65365: + case 65367: + case 65368: + case 65380: + length = readUint16(data, position); + break; + + case 65363: + throw new Error("JPX Error: Codestream code 0xFF53 (COC) is " + "not implemented"); + + default: + throw new Error("JPX Error: Unknown codestream code: " + code.toString(16)); + } + position += length; + } + } catch (e) { + if (doNotRecover || this.failOnCorruptedImage) { + throw e; + } else { + warn("Trying to recover from " + e.message); + } + } + this.tiles = transformComponents(context); + this.width = context.SIZ.Xsiz - context.SIZ.XOsiz; + this.height = context.SIZ.Ysiz - context.SIZ.YOsiz; + this.componentsCount = context.SIZ.Csiz; + } + }; + function calculateComponentDimensions(component, siz) { + component.x0 = Math.ceil(siz.XOsiz / component.XRsiz); + component.x1 = Math.ceil(siz.Xsiz / component.XRsiz); + component.y0 = Math.ceil(siz.YOsiz / component.YRsiz); + component.y1 = Math.ceil(siz.Ysiz / component.YRsiz); + component.width = component.x1 - component.x0; + component.height = component.y1 - component.y0; + } + function calculateTileGrids(context, components) { + var siz = context.SIZ; + var tile, tiles = []; + var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz); + var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); + for (var q = 0; q < numYtiles; q++) { + for (var p = 0; p < numXtiles; p++) { + tile = {}; + tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz); + tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz); + tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz); + tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz); + tile.width = tile.tx1 - tile.tx0; + tile.height = tile.ty1 - tile.ty0; + tile.components = []; + tiles.push(tile); + } + } + context.tiles = tiles; + var componentsCount = siz.Csiz; + for (var i = 0, ii = componentsCount; i < ii; i++) { + var component = components[i]; + for (var j = 0, jj = tiles.length; j < jj; j++) { + var tileComponent = {}; + tile = tiles[j]; + tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz); + tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz); + tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz); + tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz); + tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0; + tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0; + tile.components[i] = tileComponent; + } + } + } + function getBlocksDimensions(context, component, r) { + var codOrCoc = component.codingStyleParameters; + var result = {}; + if (!codOrCoc.entropyCoderWithCustomPrecincts) { + result.PPx = 15; + result.PPy = 15; + } else { + result.PPx = codOrCoc.precinctsSizes[r].PPx; + result.PPy = codOrCoc.precinctsSizes[r].PPy; + } + result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx); + result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy); + return result; + } + function buildPrecincts(context, resolution, dimensions) { + var precinctWidth = 1 << dimensions.PPx; + var precinctHeight = 1 << dimensions.PPy; + var isZeroRes = resolution.resLevel === 0; + var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1); + var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1); + var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0; + var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0; + var numprecincts = numprecinctswide * numprecinctshigh; + resolution.precinctParameters = { + precinctWidth: precinctWidth, + precinctHeight: precinctHeight, + numprecinctswide: numprecinctswide, + numprecinctshigh: numprecinctshigh, + numprecincts: numprecincts, + precinctWidthInSubband: precinctWidthInSubband, + precinctHeightInSubband: precinctHeightInSubband + }; + } + function buildCodeblocks(context, subband, dimensions) { + var xcb_ = dimensions.xcb_; + var ycb_ = dimensions.ycb_; + var codeblockWidth = 1 << xcb_; + var codeblockHeight = 1 << ycb_; + var cbx0 = subband.tbx0 >> xcb_; + var cby0 = subband.tby0 >> ycb_; + var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_; + var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_; + var precinctParameters = subband.resolution.precinctParameters; + var codeblocks = []; + var precincts = []; + var i, j, codeblock, precinctNumber; + for (j = cby0; j < cby1; j++) { + for (i = cbx0; i < cbx1; i++) { + codeblock = { + cbx: i, + cby: j, + tbx0: codeblockWidth * i, + tby0: codeblockHeight * j, + tbx1: codeblockWidth * (i + 1), + tby1: codeblockHeight * (j + 1) + }; + codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0); + codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0); + codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1); + codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1); + var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband); + var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband); + precinctNumber = pi + pj * precinctParameters.numprecinctswide; + codeblock.precinctNumber = precinctNumber; + codeblock.subbandType = subband.type; + codeblock.Lblock = 3; + if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) { + continue; + } + codeblocks.push(codeblock); + var precinct = precincts[precinctNumber]; + if (precinct !== undefined) { + if (i < precinct.cbxMin) { + precinct.cbxMin = i; + } else if (i > precinct.cbxMax) { + precinct.cbxMax = i; + } + if (j < precinct.cbyMin) { + precinct.cbxMin = j; + } else if (j > precinct.cbyMax) { + precinct.cbyMax = j; + } + } else { + precincts[precinctNumber] = precinct = { + cbxMin: i, + cbyMin: j, + cbxMax: i, + cbyMax: j + }; + } + codeblock.precinct = precinct; + } + } + subband.codeblockParameters = { + codeblockWidth: xcb_, + codeblockHeight: ycb_, + numcodeblockwide: cbx1 - cbx0 + 1, + numcodeblockhigh: cby1 - cby0 + 1 + }; + subband.codeblocks = codeblocks; + subband.precincts = precincts; + } + function createPacket(resolution, precinctNumber, layerNumber) { + var precinctCodeblocks = []; + var subbands = resolution.subbands; + for (var i = 0, ii = subbands.length; i < ii; i++) { + var subband = subbands[i]; + var codeblocks = subband.codeblocks; + for (var j = 0, jj = codeblocks.length; j < jj; j++) { + var codeblock = codeblocks[j]; + if (codeblock.precinctNumber !== precinctNumber) { + continue; + } + precinctCodeblocks.push(codeblock); + } + } + return { + layerNumber: layerNumber, + codeblocks: precinctCodeblocks + }; + } + function LayerResolutionComponentPositionIterator(context) { + var siz = context.SIZ; + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var layersCount = tile.codingStyleDefaultParameters.layersCount; + var componentsCount = siz.Csiz; + var maxDecompositionLevelsCount = 0; + for (var q = 0; q < componentsCount; q++) { + maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount); + } + var l = 0, r = 0, i = 0, k = 0; + this.nextPacket = function JpxImage_nextPacket() { + for (;l < layersCount; l++) { + for (;r <= maxDecompositionLevelsCount; r++) { + for (;i < componentsCount; i++) { + var component = tile.components[i]; + if (r > component.codingStyleParameters.decompositionLevelsCount) { + continue; + } + var resolution = component.resolutions[r]; + var numprecincts = resolution.precinctParameters.numprecincts; + for (;k < numprecincts; ) { + var packet = createPacket(resolution, k, l); + k++; + return packet; + } + k = 0; + } + i = 0; + } + r = 0; + } + throw new Error("JPX Error: Out of packets"); + }; + } + function ResolutionLayerComponentPositionIterator(context) { + var siz = context.SIZ; + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var layersCount = tile.codingStyleDefaultParameters.layersCount; + var componentsCount = siz.Csiz; + var maxDecompositionLevelsCount = 0; + for (var q = 0; q < componentsCount; q++) { + maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount); + } + var r = 0, l = 0, i = 0, k = 0; + this.nextPacket = function JpxImage_nextPacket() { + for (;r <= maxDecompositionLevelsCount; r++) { + for (;l < layersCount; l++) { + for (;i < componentsCount; i++) { + var component = tile.components[i]; + if (r > component.codingStyleParameters.decompositionLevelsCount) { + continue; + } + var resolution = component.resolutions[r]; + var numprecincts = resolution.precinctParameters.numprecincts; + for (;k < numprecincts; ) { + var packet = createPacket(resolution, k, l); + k++; + return packet; + } + k = 0; + } + i = 0; + } + l = 0; + } + throw new Error("JPX Error: Out of packets"); + }; + } + function ResolutionPositionComponentLayerIterator(context) { + var siz = context.SIZ; + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var layersCount = tile.codingStyleDefaultParameters.layersCount; + var componentsCount = siz.Csiz; + var l, r, c, p; + var maxDecompositionLevelsCount = 0; + for (c = 0; c < componentsCount; c++) { + var component = tile.components[c]; + maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount); + } + var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1); + for (r = 0; r <= maxDecompositionLevelsCount; ++r) { + var maxNumPrecincts = 0; + for (c = 0; c < componentsCount; ++c) { + var resolutions = tile.components[c].resolutions; + if (r < resolutions.length) { + maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts); + } + } + maxNumPrecinctsInLevel[r] = maxNumPrecincts; + } + l = 0; + r = 0; + c = 0; + p = 0; + this.nextPacket = function JpxImage_nextPacket() { + for (;r <= maxDecompositionLevelsCount; r++) { + for (;p < maxNumPrecinctsInLevel[r]; p++) { + for (;c < componentsCount; c++) { + var component = tile.components[c]; + if (r > component.codingStyleParameters.decompositionLevelsCount) { + continue; + } + var resolution = component.resolutions[r]; + var numprecincts = resolution.precinctParameters.numprecincts; + if (p >= numprecincts) { + continue; + } + for (;l < layersCount; ) { + var packet = createPacket(resolution, p, l); + l++; + return packet; + } + l = 0; + } + c = 0; + } + p = 0; + } + throw new Error("JPX Error: Out of packets"); + }; + } + function PositionComponentResolutionLayerIterator(context) { + var siz = context.SIZ; + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var layersCount = tile.codingStyleDefaultParameters.layersCount; + var componentsCount = siz.Csiz; + var precinctsSizes = getPrecinctSizesInImageScale(tile); + var precinctsIterationSizes = precinctsSizes; + var l = 0, r = 0, c = 0, px = 0, py = 0; + this.nextPacket = function JpxImage_nextPacket() { + for (;py < precinctsIterationSizes.maxNumHigh; py++) { + for (;px < precinctsIterationSizes.maxNumWide; px++) { + for (;c < componentsCount; c++) { + var component = tile.components[c]; + var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; + for (;r <= decompositionLevelsCount; r++) { + var resolution = component.resolutions[r]; + var sizeInImageScale = precinctsSizes.components[c].resolutions[r]; + var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution); + if (k === null) { + continue; + } + for (;l < layersCount; ) { + var packet = createPacket(resolution, k, l); + l++; + return packet; + } + l = 0; + } + r = 0; + } + c = 0; + } + px = 0; + } + throw new Error("JPX Error: Out of packets"); + }; + } + function ComponentPositionResolutionLayerIterator(context) { + var siz = context.SIZ; + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var layersCount = tile.codingStyleDefaultParameters.layersCount; + var componentsCount = siz.Csiz; + var precinctsSizes = getPrecinctSizesInImageScale(tile); + var l = 0, r = 0, c = 0, px = 0, py = 0; + this.nextPacket = function JpxImage_nextPacket() { + for (;c < componentsCount; ++c) { + var component = tile.components[c]; + var precinctsIterationSizes = precinctsSizes.components[c]; + var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; + for (;py < precinctsIterationSizes.maxNumHigh; py++) { + for (;px < precinctsIterationSizes.maxNumWide; px++) { + for (;r <= decompositionLevelsCount; r++) { + var resolution = component.resolutions[r]; + var sizeInImageScale = precinctsIterationSizes.resolutions[r]; + var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution); + if (k === null) { + continue; + } + for (;l < layersCount; ) { + var packet = createPacket(resolution, k, l); + l++; + return packet; + } + l = 0; + } + r = 0; + } + px = 0; + } + py = 0; + } + throw new Error("JPX Error: Out of packets"); + }; + } + function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) { + var posX = pxIndex * precinctIterationSizes.minWidth; + var posY = pyIndex * precinctIterationSizes.minHeight; + if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) { + return null; + } + var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide; + return posX / sizeInImageScale.height + startPrecinctRowIndex; + } + function getPrecinctSizesInImageScale(tile) { + var componentsCount = tile.components.length; + var minWidth = Number.MAX_VALUE; + var minHeight = Number.MAX_VALUE; + var maxNumWide = 0; + var maxNumHigh = 0; + var sizePerComponent = new Array(componentsCount); + for (var c = 0; c < componentsCount; c++) { + var component = tile.components[c]; + var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; + var sizePerResolution = new Array(decompositionLevelsCount + 1); + var minWidthCurrentComponent = Number.MAX_VALUE; + var minHeightCurrentComponent = Number.MAX_VALUE; + var maxNumWideCurrentComponent = 0; + var maxNumHighCurrentComponent = 0; + var scale = 1; + for (var r = decompositionLevelsCount; r >= 0; --r) { + var resolution = component.resolutions[r]; + var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth; + var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight; + minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution); + minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution); + maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide); + maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh); + sizePerResolution[r] = { + width: widthCurrentResolution, + height: heightCurrentResolution + }; + scale <<= 1; + } + minWidth = Math.min(minWidth, minWidthCurrentComponent); + minHeight = Math.min(minHeight, minHeightCurrentComponent); + maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent); + maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent); + sizePerComponent[c] = { + resolutions: sizePerResolution, + minWidth: minWidthCurrentComponent, + minHeight: minHeightCurrentComponent, + maxNumWide: maxNumWideCurrentComponent, + maxNumHigh: maxNumHighCurrentComponent + }; + } + return { + components: sizePerComponent, + minWidth: minWidth, + minHeight: minHeight, + maxNumWide: maxNumWide, + maxNumHigh: maxNumHigh + }; + } + function buildPackets(context) { + var siz = context.SIZ; + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var componentsCount = siz.Csiz; + for (var c = 0; c < componentsCount; c++) { + var component = tile.components[c]; + var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; + var resolutions = []; + var subbands = []; + for (var r = 0; r <= decompositionLevelsCount; r++) { + var blocksDimensions = getBlocksDimensions(context, component, r); + var resolution = {}; + var scale = 1 << decompositionLevelsCount - r; + resolution.trx0 = Math.ceil(component.tcx0 / scale); + resolution.try0 = Math.ceil(component.tcy0 / scale); + resolution.trx1 = Math.ceil(component.tcx1 / scale); + resolution.try1 = Math.ceil(component.tcy1 / scale); + resolution.resLevel = r; + buildPrecincts(context, resolution, blocksDimensions); + resolutions.push(resolution); + var subband; + if (r === 0) { + subband = {}; + subband.type = "LL"; + subband.tbx0 = Math.ceil(component.tcx0 / scale); + subband.tby0 = Math.ceil(component.tcy0 / scale); + subband.tbx1 = Math.ceil(component.tcx1 / scale); + subband.tby1 = Math.ceil(component.tcy1 / scale); + subband.resolution = resolution; + buildCodeblocks(context, subband, blocksDimensions); + subbands.push(subband); + resolution.subbands = [ subband ]; + } else { + var bscale = 1 << decompositionLevelsCount - r + 1; + var resolutionSubbands = []; + subband = {}; + subband.type = "HL"; + subband.tbx0 = Math.ceil(component.tcx0 / bscale - .5); + subband.tby0 = Math.ceil(component.tcy0 / bscale); + subband.tbx1 = Math.ceil(component.tcx1 / bscale - .5); + subband.tby1 = Math.ceil(component.tcy1 / bscale); + subband.resolution = resolution; + buildCodeblocks(context, subband, blocksDimensions); + subbands.push(subband); + resolutionSubbands.push(subband); + subband = {}; + subband.type = "LH"; + subband.tbx0 = Math.ceil(component.tcx0 / bscale); + subband.tby0 = Math.ceil(component.tcy0 / bscale - .5); + subband.tbx1 = Math.ceil(component.tcx1 / bscale); + subband.tby1 = Math.ceil(component.tcy1 / bscale - .5); + subband.resolution = resolution; + buildCodeblocks(context, subband, blocksDimensions); + subbands.push(subband); + resolutionSubbands.push(subband); + subband = {}; + subband.type = "HH"; + subband.tbx0 = Math.ceil(component.tcx0 / bscale - .5); + subband.tby0 = Math.ceil(component.tcy0 / bscale - .5); + subband.tbx1 = Math.ceil(component.tcx1 / bscale - .5); + subband.tby1 = Math.ceil(component.tcy1 / bscale - .5); + subband.resolution = resolution; + buildCodeblocks(context, subband, blocksDimensions); + subbands.push(subband); + resolutionSubbands.push(subband); + resolution.subbands = resolutionSubbands; + } + } + component.resolutions = resolutions; + component.subbands = subbands; + } + var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder; + switch (progressionOrder) { + case 0: + tile.packetsIterator = new LayerResolutionComponentPositionIterator(context); + break; + + case 1: + tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context); + break; + + case 2: + tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context); + break; + + case 3: + tile.packetsIterator = new PositionComponentResolutionLayerIterator(context); + break; + + case 4: + tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context); + break; + + default: + throw new Error("JPX Error: Unsupported progression order " + progressionOrder); + } + } + function parseTilePackets(context, data, offset, dataLength) { + var position = 0; + var buffer, bufferSize = 0, skipNextBit = false; + function readBits(count) { + while (bufferSize < count) { + var b = data[offset + position]; + position++; + if (skipNextBit) { + buffer = buffer << 7 | b; + bufferSize += 7; + skipNextBit = false; + } else { + buffer = buffer << 8 | b; + bufferSize += 8; + } + if (b === 255) { + skipNextBit = true; + } + } + bufferSize -= count; + return buffer >>> bufferSize & (1 << count) - 1; + } + function skipMarkerIfEqual(value) { + if (data[offset + position - 1] === 255 && data[offset + position] === value) { + skipBytes(1); + return true; + } else if (data[offset + position] === 255 && data[offset + position + 1] === value) { + skipBytes(2); + return true; + } + return false; + } + function skipBytes(count) { + position += count; + } + function alignToByte() { + bufferSize = 0; + if (skipNextBit) { + position++; + skipNextBit = false; + } + } + function readCodingpasses() { + if (readBits(1) === 0) { + return 1; + } + if (readBits(1) === 0) { + return 2; + } + var value = readBits(2); + if (value < 3) { + return value + 3; + } + value = readBits(5); + if (value < 31) { + return value + 6; + } + value = readBits(7); + return value + 37; + } + var tileIndex = context.currentTile.index; + var tile = context.tiles[tileIndex]; + var sopMarkerUsed = context.COD.sopMarkerUsed; + var ephMarkerUsed = context.COD.ephMarkerUsed; + var packetsIterator = tile.packetsIterator; + while (position < dataLength) { + alignToByte(); + if (sopMarkerUsed && skipMarkerIfEqual(145)) { + skipBytes(4); + } + var packet = packetsIterator.nextPacket(); + if (!readBits(1)) { + continue; + } + var layerNumber = packet.layerNumber; + var queue = [], codeblock; + for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) { + codeblock = packet.codeblocks[i]; + var precinct = codeblock.precinct; + var codeblockColumn = codeblock.cbx - precinct.cbxMin; + var codeblockRow = codeblock.cby - precinct.cbyMin; + var codeblockIncluded = false; + var firstTimeInclusion = false; + var valueReady; + if (codeblock["included"] !== undefined) { + codeblockIncluded = !!readBits(1); + } else { + precinct = codeblock.precinct; + var inclusionTree, zeroBitPlanesTree; + if (precinct["inclusionTree"] !== undefined) { + inclusionTree = precinct.inclusionTree; + } else { + var width = precinct.cbxMax - precinct.cbxMin + 1; + var height = precinct.cbyMax - precinct.cbyMin + 1; + inclusionTree = new InclusionTree(width, height, layerNumber); + zeroBitPlanesTree = new TagTree(width, height); + precinct.inclusionTree = inclusionTree; + precinct.zeroBitPlanesTree = zeroBitPlanesTree; + } + if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) { + while (true) { + if (readBits(1)) { + valueReady = !inclusionTree.nextLevel(); + if (valueReady) { + codeblock.included = true; + codeblockIncluded = firstTimeInclusion = true; + break; + } + } else { + inclusionTree.incrementValue(layerNumber); + break; + } + } + } + } + if (!codeblockIncluded) { + continue; + } + if (firstTimeInclusion) { + zeroBitPlanesTree = precinct.zeroBitPlanesTree; + zeroBitPlanesTree.reset(codeblockColumn, codeblockRow); + while (true) { + if (readBits(1)) { + valueReady = !zeroBitPlanesTree.nextLevel(); + if (valueReady) { + break; + } + } else { + zeroBitPlanesTree.incrementValue(); + } + } + codeblock.zeroBitPlanes = zeroBitPlanesTree.value; + } + var codingpasses = readCodingpasses(); + while (readBits(1)) { + codeblock.Lblock++; + } + var codingpassesLog2 = log2(codingpasses); + var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock; + var codedDataLength = readBits(bits); + queue.push({ + codeblock: codeblock, + codingpasses: codingpasses, + dataLength: codedDataLength + }); + } + alignToByte(); + if (ephMarkerUsed) { + skipMarkerIfEqual(146); + } + while (queue.length > 0) { + var packetItem = queue.shift(); + codeblock = packetItem.codeblock; + if (codeblock["data"] === undefined) { + codeblock.data = []; + } + codeblock.data.push({ + data: data, + start: offset + position, + end: offset + position + packetItem.dataLength, + codingpasses: packetItem.codingpasses + }); + position += packetItem.dataLength; + } + } + return position; + } + function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) { + var x0 = subband.tbx0; + var y0 = subband.tby0; + var width = subband.tbx1 - subband.tbx0; + var codeblocks = subband.codeblocks; + var right = subband.type.charAt(0) === "H" ? 1 : 0; + var bottom = subband.type.charAt(1) === "H" ? levelWidth : 0; + for (var i = 0, ii = codeblocks.length; i < ii; ++i) { + var codeblock = codeblocks[i]; + var blockWidth = codeblock.tbx1_ - codeblock.tbx0_; + var blockHeight = codeblock.tby1_ - codeblock.tby0_; + if (blockWidth === 0 || blockHeight === 0) { + continue; + } + if (codeblock["data"] === undefined) { + continue; + } + var bitModel, currentCodingpassType; + bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb); + currentCodingpassType = 2; + var data = codeblock.data, totalLength = 0, codingpasses = 0; + var j, jj, dataItem; + for (j = 0, jj = data.length; j < jj; j++) { + dataItem = data[j]; + totalLength += dataItem.end - dataItem.start; + codingpasses += dataItem.codingpasses; + } + var encodedData = new Uint8Array(totalLength); + var position = 0; + for (j = 0, jj = data.length; j < jj; j++) { + dataItem = data[j]; + var chunk = dataItem.data.subarray(dataItem.start, dataItem.end); + encodedData.set(chunk, position); + position += chunk.length; + } + var decoder = new ArithmeticDecoder(encodedData, 0, totalLength); + bitModel.setDecoder(decoder); + for (j = 0; j < codingpasses; j++) { + switch (currentCodingpassType) { + case 0: + bitModel.runSignificancePropogationPass(); + break; + + case 1: + bitModel.runMagnitudeRefinementPass(); + break; + + case 2: + bitModel.runCleanupPass(); + if (segmentationSymbolUsed) { + bitModel.checkSegmentationSymbol(); + } + break; + } + currentCodingpassType = (currentCodingpassType + 1) % 3; + } + var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width; + var sign = bitModel.coefficentsSign; + var magnitude = bitModel.coefficentsMagnitude; + var bitsDecoded = bitModel.bitsDecoded; + var magnitudeCorrection = reversible ? 0 : .5; + var k, n, nb; + position = 0; + var interleave = subband.type !== "LL"; + for (j = 0; j < blockHeight; j++) { + var row = offset / width | 0; + var levelOffset = 2 * row * (levelWidth - width) + right + bottom; + for (k = 0; k < blockWidth; k++) { + n = magnitude[position]; + if (n !== 0) { + n = (n + magnitudeCorrection) * delta; + if (sign[position] !== 0) { + n = -n; + } + nb = bitsDecoded[position]; + var pos = interleave ? levelOffset + (offset << 1) : offset; + if (reversible && nb >= mb) { + coefficients[pos] = n; + } else { + coefficients[pos] = n * (1 << mb - nb); + } + } + offset++; + position++; + } + offset += width - blockWidth; + } + } + } + function transformTile(context, tile, c) { + var component = tile.components[c]; + var codingStyleParameters = component.codingStyleParameters; + var quantizationParameters = component.quantizationParameters; + var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount; + var spqcds = quantizationParameters.SPqcds; + var scalarExpounded = quantizationParameters.scalarExpounded; + var guardBits = quantizationParameters.guardBits; + var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed; + var precision = context.components[c].precision; + var reversible = codingStyleParameters.reversibleTransformation; + var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform(); + var subbandCoefficients = []; + var b = 0; + for (var i = 0; i <= decompositionLevelsCount; i++) { + var resolution = component.resolutions[i]; + var width = resolution.trx1 - resolution.trx0; + var height = resolution.try1 - resolution.try0; + var coefficients = new Float32Array(width * height); + for (var j = 0, jj = resolution.subbands.length; j < jj; j++) { + var mu, epsilon; + if (!scalarExpounded) { + mu = spqcds[0].mu; + epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0); + } else { + mu = spqcds[b].mu; + epsilon = spqcds[b].epsilon; + b++; + } + var subband = resolution.subbands[j]; + var gainLog2 = SubbandsGainLog2[subband.type]; + var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048); + var mb = guardBits + epsilon - 1; + copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed); + } + subbandCoefficients.push({ + width: width, + height: height, + items: coefficients + }); + } + var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0); + return { + left: component.tcx0, + top: component.tcy0, + width: result.width, + height: result.height, + items: result.items + }; + } + function transformComponents(context) { + var siz = context.SIZ; + var components = context.components; + var componentsCount = siz.Csiz; + var resultImages = []; + for (var i = 0, ii = context.tiles.length; i < ii; i++) { + var tile = context.tiles[i]; + var transformedTiles = []; + var c; + for (c = 0; c < componentsCount; c++) { + transformedTiles[c] = transformTile(context, tile, c); + } + var tile0 = transformedTiles[0]; + var out = new Uint8Array(tile0.items.length * componentsCount); + var result = { + left: tile0.left, + top: tile0.top, + width: tile0.width, + height: tile0.height, + items: out + }; + var shift, offset, max, min, maxK; + var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val; + if (tile.codingStyleDefaultParameters.multipleComponentTransform) { + var fourComponents = componentsCount === 4; + var y0items = transformedTiles[0].items; + var y1items = transformedTiles[1].items; + var y2items = transformedTiles[2].items; + var y3items = fourComponents ? transformedTiles[3].items : null; + shift = components[0].precision - 8; + offset = (128 << shift) + .5; + max = 255 * (1 << shift); + maxK = max * .5; + min = -maxK; + var component0 = tile.components[0]; + var alpha01 = componentsCount - 3; + jj = y0items.length; + if (!component0.codingStyleParameters.reversibleTransformation) { + for (j = 0; j < jj; j++, pos += alpha01) { + y0 = y0items[j] + offset; + y1 = y1items[j]; + y2 = y2items[j]; + r = y0 + 1.402 * y2; + g = y0 - .34413 * y1 - .71414 * y2; + b = y0 + 1.772 * y1; + out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift; + out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift; + out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift; + } + } else { + for (j = 0; j < jj; j++, pos += alpha01) { + y0 = y0items[j] + offset; + y1 = y1items[j]; + y2 = y2items[j]; + g = y0 - (y2 + y1 >> 2); + r = g + y2; + b = g + y1; + out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift; + out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift; + out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift; + } + } + if (fourComponents) { + for (j = 0, pos = 3; j < jj; j++, pos += 4) { + k = y3items[j]; + out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift; + } + } + } else { + for (c = 0; c < componentsCount; c++) { + var items = transformedTiles[c].items; + shift = components[c].precision - 8; + offset = (128 << shift) + .5; + max = 127.5 * (1 << shift); + min = -max; + for (pos = c, j = 0, jj = items.length; j < jj; j++) { + val = items[j]; + out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift; + pos += componentsCount; + } + } + } + resultImages.push(result); + } + return resultImages; + } + function initializeTile(context, tileIndex) { + var siz = context.SIZ; + var componentsCount = siz.Csiz; + var tile = context.tiles[tileIndex]; + for (var c = 0; c < componentsCount; c++) { + var component = tile.components[c]; + var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD; + component.quantizationParameters = qcdOrQcc; + var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD; + component.codingStyleParameters = codOrCoc; + } + tile.codingStyleDefaultParameters = context.currentTile.COD; + } + var TagTree = function TagTreeClosure() { + function TagTree(width, height) { + var levelsLength = log2(Math.max(width, height)) + 1; + this.levels = []; + for (var i = 0; i < levelsLength; i++) { + var level = { + width: width, + height: height, + items: [] + }; + this.levels.push(level); + width = Math.ceil(width / 2); + height = Math.ceil(height / 2); + } + } + TagTree.prototype = { + reset: function TagTree_reset(i, j) { + var currentLevel = 0, value = 0, level; + while (currentLevel < this.levels.length) { + level = this.levels[currentLevel]; + var index = i + j * level.width; + if (level.items[index] !== undefined) { + value = level.items[index]; + break; + } + level.index = index; + i >>= 1; + j >>= 1; + currentLevel++; + } + currentLevel--; + level = this.levels[currentLevel]; + level.items[level.index] = value; + this.currentLevel = currentLevel; + delete this.value; + }, + incrementValue: function TagTree_incrementValue() { + var level = this.levels[this.currentLevel]; + level.items[level.index]++; + }, + nextLevel: function TagTree_nextLevel() { + var currentLevel = this.currentLevel; + var level = this.levels[currentLevel]; + var value = level.items[level.index]; + currentLevel--; + if (currentLevel < 0) { + this.value = value; + return false; + } + this.currentLevel = currentLevel; + level = this.levels[currentLevel]; + level.items[level.index] = value; + return true; + } + }; + return TagTree; + }(); + var InclusionTree = function InclusionTreeClosure() { + function InclusionTree(width, height, defaultValue) { + var levelsLength = log2(Math.max(width, height)) + 1; + this.levels = []; + for (var i = 0; i < levelsLength; i++) { + var items = new Uint8Array(width * height); + for (var j = 0, jj = items.length; j < jj; j++) { + items[j] = defaultValue; + } + var level = { + width: width, + height: height, + items: items + }; + this.levels.push(level); + width = Math.ceil(width / 2); + height = Math.ceil(height / 2); + } + } + InclusionTree.prototype = { + reset: function InclusionTree_reset(i, j, stopValue) { + var currentLevel = 0; + while (currentLevel < this.levels.length) { + var level = this.levels[currentLevel]; + var index = i + j * level.width; + level.index = index; + var value = level.items[index]; + if (value === 255) { + break; + } + if (value > stopValue) { + this.currentLevel = currentLevel; + this.propagateValues(); + return false; + } + i >>= 1; + j >>= 1; + currentLevel++; + } + this.currentLevel = currentLevel - 1; + return true; + }, + incrementValue: function InclusionTree_incrementValue(stopValue) { + var level = this.levels[this.currentLevel]; + level.items[level.index] = stopValue + 1; + this.propagateValues(); + }, + propagateValues: function InclusionTree_propagateValues() { + var levelIndex = this.currentLevel; + var level = this.levels[levelIndex]; + var currentValue = level.items[level.index]; + while (--levelIndex >= 0) { + level = this.levels[levelIndex]; + level.items[level.index] = currentValue; + } + }, + nextLevel: function InclusionTree_nextLevel() { + var currentLevel = this.currentLevel; + var level = this.levels[currentLevel]; + var value = level.items[level.index]; + level.items[level.index] = 255; + currentLevel--; + if (currentLevel < 0) { + return false; + } + this.currentLevel = currentLevel; + level = this.levels[currentLevel]; + level.items[level.index] = value; + return true; + } + }; + return InclusionTree; + }(); + var BitModel = function BitModelClosure() { + var UNIFORM_CONTEXT = 17; + var RUNLENGTH_CONTEXT = 18; + var LLAndLHContextsLabel = new Uint8Array([ 0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8 ]); + var HLContextLabel = new Uint8Array([ 0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8 ]); + var HHContextLabel = new Uint8Array([ 0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8 ]); + function BitModel(width, height, subband, zeroBitPlanes, mb) { + this.width = width; + this.height = height; + this.contextLabelTable = subband === "HH" ? HHContextLabel : subband === "HL" ? HLContextLabel : LLAndLHContextsLabel; + var coefficientCount = width * height; + this.neighborsSignificance = new Uint8Array(coefficientCount); + this.coefficentsSign = new Uint8Array(coefficientCount); + this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount); + this.processingFlags = new Uint8Array(coefficientCount); + var bitsDecoded = new Uint8Array(coefficientCount); + if (zeroBitPlanes !== 0) { + for (var i = 0; i < coefficientCount; i++) { + bitsDecoded[i] = zeroBitPlanes; + } + } + this.bitsDecoded = bitsDecoded; + this.reset(); + } + BitModel.prototype = { + setDecoder: function BitModel_setDecoder(decoder) { + this.decoder = decoder; + }, + reset: function BitModel_reset() { + this.contexts = new Int8Array(19); + this.contexts[0] = 4 << 1 | 0; + this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0; + this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0; + }, + setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) { + var neighborsSignificance = this.neighborsSignificance; + var width = this.width, height = this.height; + var left = column > 0; + var right = column + 1 < width; + var i; + if (row > 0) { + i = index - width; + if (left) { + neighborsSignificance[i - 1] += 16; + } + if (right) { + neighborsSignificance[i + 1] += 16; + } + neighborsSignificance[i] += 4; + } + if (row + 1 < height) { + i = index + width; + if (left) { + neighborsSignificance[i - 1] += 16; + } + if (right) { + neighborsSignificance[i + 1] += 16; + } + neighborsSignificance[i] += 4; + } + if (left) { + neighborsSignificance[index - 1] += 1; + } + if (right) { + neighborsSignificance[index + 1] += 1; + } + neighborsSignificance[index] |= 128; + }, + runSignificancePropogationPass: function BitModel_runSignificancePropogationPass() { + var decoder = this.decoder; + var width = this.width, height = this.height; + var coefficentsMagnitude = this.coefficentsMagnitude; + var coefficentsSign = this.coefficentsSign; + var neighborsSignificance = this.neighborsSignificance; + var processingFlags = this.processingFlags; + var contexts = this.contexts; + var labels = this.contextLabelTable; + var bitsDecoded = this.bitsDecoded; + var processedInverseMask = ~1; + var processedMask = 1; + var firstMagnitudeBitMask = 2; + for (var i0 = 0; i0 < height; i0 += 4) { + for (var j = 0; j < width; j++) { + var index = i0 * width + j; + for (var i1 = 0; i1 < 4; i1++, index += width) { + var i = i0 + i1; + if (i >= height) { + break; + } + processingFlags[index] &= processedInverseMask; + if (coefficentsMagnitude[index] || !neighborsSignificance[index]) { + continue; + } + var contextLabel = labels[neighborsSignificance[index]]; + var decision = decoder.readBit(contexts, contextLabel); + if (decision) { + var sign = this.decodeSignBit(i, j, index); + coefficentsSign[index] = sign; + coefficentsMagnitude[index] = 1; + this.setNeighborsSignificance(i, j, index); + processingFlags[index] |= firstMagnitudeBitMask; + } + bitsDecoded[index]++; + processingFlags[index] |= processedMask; + } + } + } + }, + decodeSignBit: function BitModel_decodeSignBit(row, column, index) { + var width = this.width, height = this.height; + var coefficentsMagnitude = this.coefficentsMagnitude; + var coefficentsSign = this.coefficentsSign; + var contribution, sign0, sign1, significance1; + var contextLabel, decoded; + significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0; + if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) { + sign1 = coefficentsSign[index + 1]; + if (significance1) { + sign0 = coefficentsSign[index - 1]; + contribution = 1 - sign1 - sign0; + } else { + contribution = 1 - sign1 - sign1; + } + } else if (significance1) { + sign0 = coefficentsSign[index - 1]; + contribution = 1 - sign0 - sign0; + } else { + contribution = 0; + } + var horizontalContribution = 3 * contribution; + significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0; + if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) { + sign1 = coefficentsSign[index + width]; + if (significance1) { + sign0 = coefficentsSign[index - width]; + contribution = 1 - sign1 - sign0 + horizontalContribution; + } else { + contribution = 1 - sign1 - sign1 + horizontalContribution; + } + } else if (significance1) { + sign0 = coefficentsSign[index - width]; + contribution = 1 - sign0 - sign0 + horizontalContribution; + } else { + contribution = horizontalContribution; + } + if (contribution >= 0) { + contextLabel = 9 + contribution; + decoded = this.decoder.readBit(this.contexts, contextLabel); + } else { + contextLabel = 9 - contribution; + decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1; + } + return decoded; + }, + runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() { + var decoder = this.decoder; + var width = this.width, height = this.height; + var coefficentsMagnitude = this.coefficentsMagnitude; + var neighborsSignificance = this.neighborsSignificance; + var contexts = this.contexts; + var bitsDecoded = this.bitsDecoded; + var processingFlags = this.processingFlags; + var processedMask = 1; + var firstMagnitudeBitMask = 2; + var length = width * height; + var width4 = width * 4; + for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) { + indexNext = Math.min(length, index0 + width4); + for (var j = 0; j < width; j++) { + for (var index = index0 + j; index < indexNext; index += width) { + if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) { + continue; + } + var contextLabel = 16; + if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) { + processingFlags[index] ^= firstMagnitudeBitMask; + var significance = neighborsSignificance[index] & 127; + contextLabel = significance === 0 ? 15 : 14; + } + var bit = decoder.readBit(contexts, contextLabel); + coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit; + bitsDecoded[index]++; + processingFlags[index] |= processedMask; + } + } + } + }, + runCleanupPass: function BitModel_runCleanupPass() { + var decoder = this.decoder; + var width = this.width, height = this.height; + var neighborsSignificance = this.neighborsSignificance; + var coefficentsMagnitude = this.coefficentsMagnitude; + var coefficentsSign = this.coefficentsSign; + var contexts = this.contexts; + var labels = this.contextLabelTable; + var bitsDecoded = this.bitsDecoded; + var processingFlags = this.processingFlags; + var processedMask = 1; + var firstMagnitudeBitMask = 2; + var oneRowDown = width; + var twoRowsDown = width * 2; + var threeRowsDown = width * 3; + var iNext; + for (var i0 = 0; i0 < height; i0 = iNext) { + iNext = Math.min(i0 + 4, height); + var indexBase = i0 * width; + var checkAllEmpty = i0 + 3 < height; + for (var j = 0; j < width; j++) { + var index0 = indexBase + j; + var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0; + var i1 = 0, index = index0; + var i = i0, sign; + if (allEmpty) { + var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT); + if (!hasSignificantCoefficent) { + bitsDecoded[index0]++; + bitsDecoded[index0 + oneRowDown]++; + bitsDecoded[index0 + twoRowsDown]++; + bitsDecoded[index0 + threeRowsDown]++; + continue; + } + i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT); + if (i1 !== 0) { + i = i0 + i1; + index += i1 * width; + } + sign = this.decodeSignBit(i, j, index); + coefficentsSign[index] = sign; + coefficentsMagnitude[index] = 1; + this.setNeighborsSignificance(i, j, index); + processingFlags[index] |= firstMagnitudeBitMask; + index = index0; + for (var i2 = i0; i2 <= i; i2++, index += width) { + bitsDecoded[index]++; + } + i1++; + } + for (i = i0 + i1; i < iNext; i++, index += width) { + if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) { + continue; + } + var contextLabel = labels[neighborsSignificance[index]]; + var decision = decoder.readBit(contexts, contextLabel); + if (decision === 1) { + sign = this.decodeSignBit(i, j, index); + coefficentsSign[index] = sign; + coefficentsMagnitude[index] = 1; + this.setNeighborsSignificance(i, j, index); + processingFlags[index] |= firstMagnitudeBitMask; + } + bitsDecoded[index]++; + } + } + } + }, + checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() { + var decoder = this.decoder; + var contexts = this.contexts; + var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT); + if (symbol !== 10) { + throw new Error("JPX Error: Invalid segmentation symbol"); + } + } + }; + return BitModel; + }(); + var Transform = function TransformClosure() { + function Transform() {} + Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) { + var ll = subbands[0]; + for (var i = 1, ii = subbands.length; i < ii; i++) { + ll = this.iterate(ll, subbands[i], u0, v0); + } + return ll; + }; + Transform.prototype.extend = function extend(buffer, offset, size) { + var i1 = offset - 1, j1 = offset + 1; + var i2 = offset + size - 2, j2 = offset + size; + buffer[i1--] = buffer[j1++]; + buffer[j2++] = buffer[i2--]; + buffer[i1--] = buffer[j1++]; + buffer[j2++] = buffer[i2--]; + buffer[i1--] = buffer[j1++]; + buffer[j2++] = buffer[i2--]; + buffer[i1] = buffer[j1]; + buffer[j2] = buffer[i2]; + }; + Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) { + var llWidth = ll.width, llHeight = ll.height, llItems = ll.items; + var width = hl_lh_hh.width; + var height = hl_lh_hh.height; + var items = hl_lh_hh.items; + var i, j, k, l, u, v; + for (k = 0, i = 0; i < llHeight; i++) { + l = i * 2 * width; + for (j = 0; j < llWidth; j++, k++, l += 2) { + items[l] = llItems[k]; + } + } + llItems = ll.items = null; + var bufferPadding = 4; + var rowBuffer = new Float32Array(width + 2 * bufferPadding); + if (width === 1) { + if ((u0 & 1) !== 0) { + for (v = 0, k = 0; v < height; v++, k += width) { + items[k] *= .5; + } + } + } else { + for (v = 0, k = 0; v < height; v++, k += width) { + rowBuffer.set(items.subarray(k, k + width), bufferPadding); + this.extend(rowBuffer, bufferPadding, width); + this.filter(rowBuffer, bufferPadding, width); + items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k); + } + } + var numBuffers = 16; + var colBuffers = []; + for (i = 0; i < numBuffers; i++) { + colBuffers.push(new Float32Array(height + 2 * bufferPadding)); + } + var b, currentBuffer = 0; + ll = bufferPadding + height; + if (height === 1) { + if ((v0 & 1) !== 0) { + for (u = 0; u < width; u++) { + items[u] *= .5; + } + } + } else { + for (u = 0; u < width; u++) { + if (currentBuffer === 0) { + numBuffers = Math.min(width - u, numBuffers); + for (k = u, l = bufferPadding; l < ll; k += width, l++) { + for (b = 0; b < numBuffers; b++) { + colBuffers[b][l] = items[k + b]; + } + } + currentBuffer = numBuffers; + } + currentBuffer--; + var buffer = colBuffers[currentBuffer]; + this.extend(buffer, bufferPadding, height); + this.filter(buffer, bufferPadding, height); + if (currentBuffer === 0) { + k = u - numBuffers + 1; + for (l = bufferPadding; l < ll; k += width, l++) { + for (b = 0; b < numBuffers; b++) { + items[k + b] = colBuffers[b][l]; + } + } + } + } + } + return { + width: width, + height: height, + items: items + }; + }; + return Transform; + }(); + var IrreversibleTransform = function IrreversibleTransformClosure() { + function IrreversibleTransform() { + Transform.call(this); + } + IrreversibleTransform.prototype = Object.create(Transform.prototype); + IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) { + var len = length >> 1; + offset = offset | 0; + var j, n, current, next; + var alpha = -1.586134342059924; + var beta = -.052980118572961; + var gamma = .882911075530934; + var delta = .443506852043971; + var K = 1.230174104914001; + var K_ = 1 / K; + j = offset - 3; + for (n = len + 4; n--; j += 2) { + x[j] *= K_; + } + j = offset - 2; + current = delta * x[j - 1]; + for (n = len + 3; n--; j += 2) { + next = delta * x[j + 1]; + x[j] = K * x[j] - current - next; + if (n--) { + j += 2; + current = delta * x[j + 1]; + x[j] = K * x[j] - current - next; + } else { + break; + } + } + j = offset - 1; + current = gamma * x[j - 1]; + for (n = len + 2; n--; j += 2) { + next = gamma * x[j + 1]; + x[j] -= current + next; + if (n--) { + j += 2; + current = gamma * x[j + 1]; + x[j] -= current + next; + } else { + break; + } + } + j = offset; + current = beta * x[j - 1]; + for (n = len + 1; n--; j += 2) { + next = beta * x[j + 1]; + x[j] -= current + next; + if (n--) { + j += 2; + current = beta * x[j + 1]; + x[j] -= current + next; + } else { + break; + } + } + if (len !== 0) { + j = offset + 1; + current = alpha * x[j - 1]; + for (n = len; n--; j += 2) { + next = alpha * x[j + 1]; + x[j] -= current + next; + if (n--) { + j += 2; + current = alpha * x[j + 1]; + x[j] -= current + next; + } else { + break; + } + } + } + }; + return IrreversibleTransform; + }(); + var ReversibleTransform = function ReversibleTransformClosure() { + function ReversibleTransform() { + Transform.call(this); + } + ReversibleTransform.prototype = Object.create(Transform.prototype); + ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) { + var len = length >> 1; + offset = offset | 0; + var j, n; + for (j = offset, n = len + 1; n--; j += 2) { + x[j] -= x[j - 1] + x[j + 1] + 2 >> 2; + } + for (j = offset + 1, n = len; n--; j += 2) { + x[j] += x[j - 1] + x[j + 1] >> 1; + } + }; + return ReversibleTransform; + }(); + return JpxImage; + }(); + "use strict"; + var Jbig2Image = function Jbig2ImageClosure() { + function ContextCache() {} + ContextCache.prototype = { + getContexts: function(id) { + if (id in this) { + return this[id]; + } + return this[id] = new Int8Array(1 << 16); + } + }; + function DecodingContext(data, start, end) { + this.data = data; + this.start = start; + this.end = end; + } + DecodingContext.prototype = { + get decoder() { + var decoder = new ArithmeticDecoder(this.data, this.start, this.end); + return shadow(this, "decoder", decoder); + }, + get contextCache() { + var cache = new ContextCache(); + return shadow(this, "contextCache", cache); + } + }; + function decodeInteger(contextCache, procedure, decoder) { + var contexts = contextCache.getContexts(procedure); + var prev = 1; + function readBits(length) { + var v = 0; + for (var i = 0; i < length; i++) { + var bit = decoder.readBit(contexts, prev); + prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256; + v = v << 1 | bit; + } + return v >>> 0; + } + var sign = readBits(1); + var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2); + return sign === 0 ? value : value > 0 ? -value : null; + } + function decodeIAID(contextCache, decoder, codeLength) { + var contexts = contextCache.getContexts("IAID"); + var prev = 1; + for (var i = 0; i < codeLength; i++) { + var bit = decoder.readBit(contexts, prev); + prev = prev << 1 | bit; + } + if (codeLength < 31) { + return prev & (1 << codeLength) - 1; + } + return prev & 2147483647; + } + var SegmentTypes = [ "SymbolDictionary", null, null, null, "IntermediateTextRegion", null, "ImmediateTextRegion", "ImmediateLosslessTextRegion", null, null, null, null, null, null, null, null, "patternDictionary", null, null, null, "IntermediateHalftoneRegion", null, "ImmediateHalftoneRegion", "ImmediateLosslessHalftoneRegion", null, null, null, null, null, null, null, null, null, null, null, null, "IntermediateGenericRegion", null, "ImmediateGenericRegion", "ImmediateLosslessGenericRegion", "IntermediateGenericRefinementRegion", null, "ImmediateGenericRefinementRegion", "ImmediateLosslessGenericRefinementRegion", null, null, null, null, "PageInformation", "EndOfPage", "EndOfStripe", "EndOfFile", "Profiles", "Tables", null, null, null, null, null, null, null, null, "Extension" ]; + var CodingTemplates = [ [ { + x: -1, + y: -2 + }, { + x: 0, + y: -2 + }, { + x: 1, + y: -2 + }, { + x: -2, + y: -1 + }, { + x: -1, + y: -1 + }, { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: 2, + y: -1 + }, { + x: -4, + y: 0 + }, { + x: -3, + y: 0 + }, { + x: -2, + y: 0 + }, { + x: -1, + y: 0 + } ], [ { + x: -1, + y: -2 + }, { + x: 0, + y: -2 + }, { + x: 1, + y: -2 + }, { + x: 2, + y: -2 + }, { + x: -2, + y: -1 + }, { + x: -1, + y: -1 + }, { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: 2, + y: -1 + }, { + x: -3, + y: 0 + }, { + x: -2, + y: 0 + }, { + x: -1, + y: 0 + } ], [ { + x: -1, + y: -2 + }, { + x: 0, + y: -2 + }, { + x: 1, + y: -2 + }, { + x: -2, + y: -1 + }, { + x: -1, + y: -1 + }, { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: -2, + y: 0 + }, { + x: -1, + y: 0 + } ], [ { + x: -3, + y: -1 + }, { + x: -2, + y: -1 + }, { + x: -1, + y: -1 + }, { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: -4, + y: 0 + }, { + x: -3, + y: 0 + }, { + x: -2, + y: 0 + }, { + x: -1, + y: 0 + } ] ]; + var RefinementTemplates = [ { + coding: [ { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: -1, + y: 0 + } ], + reference: [ { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: -1, + y: 0 + }, { + x: 0, + y: 0 + }, { + x: 1, + y: 0 + }, { + x: -1, + y: 1 + }, { + x: 0, + y: 1 + }, { + x: 1, + y: 1 + } ] + }, { + coding: [ { + x: -1, + y: -1 + }, { + x: 0, + y: -1 + }, { + x: 1, + y: -1 + }, { + x: -1, + y: 0 + } ], + reference: [ { + x: 0, + y: -1 + }, { + x: -1, + y: 0 + }, { + x: 0, + y: 0 + }, { + x: 1, + y: 0 + }, { + x: 0, + y: 1 + }, { + x: 1, + y: 1 + } ] + } ]; + var ReusedContexts = [ 39717, 1941, 229, 405 ]; + var RefinementReusedContexts = [ 32, 8 ]; + function decodeBitmapTemplate0(width, height, decodingContext) { + var decoder = decodingContext.decoder; + var contexts = decodingContext.contextCache.getContexts("GB"); + var contextLabel, i, j, pixel, row, row1, row2, bitmap = []; + var OLD_PIXEL_MASK = 31735; + for (i = 0; i < height; i++) { + row = bitmap[i] = new Uint8Array(width); + row1 = i < 1 ? row : bitmap[i - 1]; + row2 = i < 2 ? row : bitmap[i - 2]; + contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4; + for (j = 0; j < width; j++) { + row[j] = pixel = decoder.readBit(contexts, contextLabel); + contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel; + } + } + return bitmap; + } + function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) { + if (mmr) { + error("JBIG2 error: MMR encoding is not supported"); + } + if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) { + return decodeBitmapTemplate0(width, height, decodingContext); + } + var useskip = !!skip; + var template = CodingTemplates[templateIndex].concat(at); + template.sort(function(a, b) { + return a.y - b.y || a.x - b.x; + }); + var templateLength = template.length; + var templateX = new Int8Array(templateLength); + var templateY = new Int8Array(templateLength); + var changingTemplateEntries = []; + var reuseMask = 0, minX = 0, maxX = 0, minY = 0; + var c, k; + for (k = 0; k < templateLength; k++) { + templateX[k] = template[k].x; + templateY[k] = template[k].y; + minX = Math.min(minX, template[k].x); + maxX = Math.max(maxX, template[k].x); + minY = Math.min(minY, template[k].y); + if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) { + reuseMask |= 1 << templateLength - 1 - k; + } else { + changingTemplateEntries.push(k); + } + } + var changingEntriesLength = changingTemplateEntries.length; + var changingTemplateX = new Int8Array(changingEntriesLength); + var changingTemplateY = new Int8Array(changingEntriesLength); + var changingTemplateBit = new Uint16Array(changingEntriesLength); + for (c = 0; c < changingEntriesLength; c++) { + k = changingTemplateEntries[c]; + changingTemplateX[c] = template[k].x; + changingTemplateY[c] = template[k].y; + changingTemplateBit[c] = 1 << templateLength - 1 - k; + } + var sbb_left = -minX; + var sbb_top = -minY; + var sbb_right = width - maxX; + var pseudoPixelContext = ReusedContexts[templateIndex]; + var row = new Uint8Array(width); + var bitmap = []; + var decoder = decodingContext.decoder; + var contexts = decodingContext.contextCache.getContexts("GB"); + var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift; + for (var i = 0; i < height; i++) { + if (prediction) { + var sltp = decoder.readBit(contexts, pseudoPixelContext); + ltp ^= sltp; + if (ltp) { + bitmap.push(row); + continue; + } + } + row = new Uint8Array(row); + bitmap.push(row); + for (j = 0; j < width; j++) { + if (useskip && skip[i][j]) { + row[j] = 0; + continue; + } + if (j >= sbb_left && j < sbb_right && i >= sbb_top) { + contextLabel = contextLabel << 1 & reuseMask; + for (k = 0; k < changingEntriesLength; k++) { + i0 = i + changingTemplateY[k]; + j0 = j + changingTemplateX[k]; + bit = bitmap[i0][j0]; + if (bit) { + bit = changingTemplateBit[k]; + contextLabel |= bit; + } + } + } else { + contextLabel = 0; + shift = templateLength - 1; + for (k = 0; k < templateLength; k++, shift--) { + j0 = j + templateX[k]; + if (j0 >= 0 && j0 < width) { + i0 = i + templateY[k]; + if (i0 >= 0) { + bit = bitmap[i0][j0]; + if (bit) { + contextLabel |= bit << shift; + } + } + } + } + } + var pixel = decoder.readBit(contexts, contextLabel); + row[j] = pixel; + } + } + return bitmap; + } + function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) { + var codingTemplate = RefinementTemplates[templateIndex].coding; + if (templateIndex === 0) { + codingTemplate = codingTemplate.concat([ at[0] ]); + } + var codingTemplateLength = codingTemplate.length; + var codingTemplateX = new Int32Array(codingTemplateLength); + var codingTemplateY = new Int32Array(codingTemplateLength); + var k; + for (k = 0; k < codingTemplateLength; k++) { + codingTemplateX[k] = codingTemplate[k].x; + codingTemplateY[k] = codingTemplate[k].y; + } + var referenceTemplate = RefinementTemplates[templateIndex].reference; + if (templateIndex === 0) { + referenceTemplate = referenceTemplate.concat([ at[1] ]); + } + var referenceTemplateLength = referenceTemplate.length; + var referenceTemplateX = new Int32Array(referenceTemplateLength); + var referenceTemplateY = new Int32Array(referenceTemplateLength); + for (k = 0; k < referenceTemplateLength; k++) { + referenceTemplateX[k] = referenceTemplate[k].x; + referenceTemplateY[k] = referenceTemplate[k].y; + } + var referenceWidth = referenceBitmap[0].length; + var referenceHeight = referenceBitmap.length; + var pseudoPixelContext = RefinementReusedContexts[templateIndex]; + var bitmap = []; + var decoder = decodingContext.decoder; + var contexts = decodingContext.contextCache.getContexts("GR"); + var ltp = 0; + for (var i = 0; i < height; i++) { + if (prediction) { + var sltp = decoder.readBit(contexts, pseudoPixelContext); + ltp ^= sltp; + if (ltp) { + error("JBIG2 error: prediction is not supported"); + } + } + var row = new Uint8Array(width); + bitmap.push(row); + for (var j = 0; j < width; j++) { + var i0, j0; + var contextLabel = 0; + for (k = 0; k < codingTemplateLength; k++) { + i0 = i + codingTemplateY[k]; + j0 = j + codingTemplateX[k]; + if (i0 < 0 || j0 < 0 || j0 >= width) { + contextLabel <<= 1; + } else { + contextLabel = contextLabel << 1 | bitmap[i0][j0]; + } + } + for (k = 0; k < referenceTemplateLength; k++) { + i0 = i + referenceTemplateY[k] + offsetY; + j0 = j + referenceTemplateX[k] + offsetX; + if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) { + contextLabel <<= 1; + } else { + contextLabel = contextLabel << 1 | referenceBitmap[i0][j0]; + } + } + var pixel = decoder.readBit(contexts, contextLabel); + row[j] = pixel; + } + } + return bitmap; + } + function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) { + if (huffman) { + error("JBIG2 error: huffman is not supported"); + } + var newSymbols = []; + var currentHeight = 0; + var symbolCodeLength = log2(symbols.length + numberOfNewSymbols); + var decoder = decodingContext.decoder; + var contextCache = decodingContext.contextCache; + while (newSymbols.length < numberOfNewSymbols) { + var deltaHeight = decodeInteger(contextCache, "IADH", decoder); + currentHeight += deltaHeight; + var currentWidth = 0; + var totalWidth = 0; + while (true) { + var deltaWidth = decodeInteger(contextCache, "IADW", decoder); + if (deltaWidth === null) { + break; + } + currentWidth += deltaWidth; + totalWidth += currentWidth; + var bitmap; + if (refinement) { + var numberOfInstances = decodeInteger(contextCache, "IAAI", decoder); + if (numberOfInstances > 1) { + bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext); + } else { + var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); + var rdx = decodeInteger(contextCache, "IARDX", decoder); + var rdy = decodeInteger(contextCache, "IARDY", decoder); + var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length]; + bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext); + } + } else { + bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext); + } + newSymbols.push(bitmap); + } + } + var exportedSymbols = []; + var flags = [], currentFlag = false; + var totalSymbolsLength = symbols.length + numberOfNewSymbols; + while (flags.length < totalSymbolsLength) { + var runLength = decodeInteger(contextCache, "IAEX", decoder); + while (runLength--) { + flags.push(currentFlag); + } + currentFlag = !currentFlag; + } + for (var i = 0, ii = symbols.length; i < ii; i++) { + if (flags[i]) { + exportedSymbols.push(symbols[i]); + } + } + for (var j = 0; j < numberOfNewSymbols; i++, j++) { + if (flags[i]) { + exportedSymbols.push(newSymbols[j]); + } + } + return exportedSymbols; + } + function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) { + if (huffman) { + error("JBIG2 error: huffman is not supported"); + } + var bitmap = []; + var i, row; + for (i = 0; i < height; i++) { + row = new Uint8Array(width); + if (defaultPixelValue) { + for (var j = 0; j < width; j++) { + row[j] = defaultPixelValue; + } + } + bitmap.push(row); + } + var decoder = decodingContext.decoder; + var contextCache = decodingContext.contextCache; + var stripT = -decodeInteger(contextCache, "IADT", decoder); + var firstS = 0; + i = 0; + while (i < numberOfSymbolInstances) { + var deltaT = decodeInteger(contextCache, "IADT", decoder); + stripT += deltaT; + var deltaFirstS = decodeInteger(contextCache, "IAFS", decoder); + firstS += deltaFirstS; + var currentS = firstS; + do { + var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, "IAIT", decoder); + var t = stripSize * stripT + currentT; + var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); + var applyRefinement = refinement && decodeInteger(contextCache, "IARI", decoder); + var symbolBitmap = inputSymbols[symbolId]; + var symbolWidth = symbolBitmap[0].length; + var symbolHeight = symbolBitmap.length; + if (applyRefinement) { + var rdw = decodeInteger(contextCache, "IARDW", decoder); + var rdh = decodeInteger(contextCache, "IARDH", decoder); + var rdx = decodeInteger(contextCache, "IARDX", decoder); + var rdy = decodeInteger(contextCache, "IARDY", decoder); + symbolWidth += rdw; + symbolHeight += rdh; + symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext); + } + var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight); + var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0); + var s2, t2, symbolRow; + if (transposed) { + for (s2 = 0; s2 < symbolHeight; s2++) { + row = bitmap[offsetS + s2]; + if (!row) { + continue; + } + symbolRow = symbolBitmap[s2]; + var maxWidth = Math.min(width - offsetT, symbolWidth); + switch (combinationOperator) { + case 0: + for (t2 = 0; t2 < maxWidth; t2++) { + row[offsetT + t2] |= symbolRow[t2]; + } + break; + + case 2: + for (t2 = 0; t2 < maxWidth; t2++) { + row[offsetT + t2] ^= symbolRow[t2]; + } + break; + + default: + error("JBIG2 error: operator " + combinationOperator + " is not supported"); + } + } + currentS += symbolHeight - 1; + } else { + for (t2 = 0; t2 < symbolHeight; t2++) { + row = bitmap[offsetT + t2]; + if (!row) { + continue; + } + symbolRow = symbolBitmap[t2]; + switch (combinationOperator) { + case 0: + for (s2 = 0; s2 < symbolWidth; s2++) { + row[offsetS + s2] |= symbolRow[s2]; + } + break; + + case 2: + for (s2 = 0; s2 < symbolWidth; s2++) { + row[offsetS + s2] ^= symbolRow[s2]; + } + break; + + default: + error("JBIG2 error: operator " + combinationOperator + " is not supported"); + } + } + currentS += symbolWidth - 1; + } + i++; + var deltaS = decodeInteger(contextCache, "IADS", decoder); + if (deltaS === null) { + break; + } + currentS += deltaS + dsOffset; + } while (true); + } + return bitmap; + } + function readSegmentHeader(data, start) { + var segmentHeader = {}; + segmentHeader.number = readUint32(data, start); + var flags = data[start + 4]; + var segmentType = flags & 63; + if (!SegmentTypes[segmentType]) { + error("JBIG2 error: invalid segment type: " + segmentType); + } + segmentHeader.type = segmentType; + segmentHeader.typeName = SegmentTypes[segmentType]; + segmentHeader.deferredNonRetain = !!(flags & 128); + var pageAssociationFieldSize = !!(flags & 64); + var referredFlags = data[start + 5]; + var referredToCount = referredFlags >> 5 & 7; + var retainBits = [ referredFlags & 31 ]; + var position = start + 6; + if (referredFlags === 7) { + referredToCount = readUint32(data, position - 1) & 536870911; + position += 3; + var bytes = referredToCount + 7 >> 3; + retainBits[0] = data[position++]; + while (--bytes > 0) { + retainBits.push(data[position++]); + } + } else if (referredFlags === 5 || referredFlags === 6) { + error("JBIG2 error: invalid referred-to flags"); + } + segmentHeader.retainBits = retainBits; + var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4; + var referredTo = []; + var i, ii; + for (i = 0; i < referredToCount; i++) { + var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position); + referredTo.push(number); + position += referredToSegmentNumberSize; + } + segmentHeader.referredTo = referredTo; + if (!pageAssociationFieldSize) { + segmentHeader.pageAssociation = data[position++]; + } else { + segmentHeader.pageAssociation = readUint32(data, position); + position += 4; + } + segmentHeader.length = readUint32(data, position); + position += 4; + if (segmentHeader.length === 4294967295) { + if (segmentType === 38) { + var genericRegionInfo = readRegionSegmentInformation(data, position); + var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength]; + var genericRegionMmr = !!(genericRegionSegmentFlags & 1); + var searchPatternLength = 6; + var searchPattern = new Uint8Array(searchPatternLength); + if (!genericRegionMmr) { + searchPattern[0] = 255; + searchPattern[1] = 172; + } + searchPattern[2] = genericRegionInfo.height >>> 24 & 255; + searchPattern[3] = genericRegionInfo.height >> 16 & 255; + searchPattern[4] = genericRegionInfo.height >> 8 & 255; + searchPattern[5] = genericRegionInfo.height & 255; + for (i = position, ii = data.length; i < ii; i++) { + var j = 0; + while (j < searchPatternLength && searchPattern[j] === data[i + j]) { + j++; + } + if (j === searchPatternLength) { + segmentHeader.length = i + searchPatternLength; + break; + } + } + if (segmentHeader.length === 4294967295) { + error("JBIG2 error: segment end was not found"); + } + } else { + error("JBIG2 error: invalid unknown segment length"); + } + } + segmentHeader.headerEnd = position; + return segmentHeader; + } + function readSegments(header, data, start, end) { + var segments = []; + var position = start; + while (position < end) { + var segmentHeader = readSegmentHeader(data, position); + position = segmentHeader.headerEnd; + var segment = { + header: segmentHeader, + data: data + }; + if (!header.randomAccess) { + segment.start = position; + position += segmentHeader.length; + segment.end = position; + } + segments.push(segment); + if (segmentHeader.type === 51) { + break; + } + } + if (header.randomAccess) { + for (var i = 0, ii = segments.length; i < ii; i++) { + segments[i].start = position; + position += segments[i].header.length; + segments[i].end = position; + } + } + return segments; + } + function readRegionSegmentInformation(data, start) { + return { + width: readUint32(data, start), + height: readUint32(data, start + 4), + x: readUint32(data, start + 8), + y: readUint32(data, start + 12), + combinationOperator: data[start + 16] & 7 + }; + } + var RegionSegmentInformationFieldLength = 17; + function processSegment(segment, visitor) { + var header = segment.header; + var data = segment.data, position = segment.start, end = segment.end; + var args, at, i, atLength; + switch (header.type) { + case 0: + var dictionary = {}; + var dictionaryFlags = readUint16(data, position); + dictionary.huffman = !!(dictionaryFlags & 1); + dictionary.refinement = !!(dictionaryFlags & 2); + dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3; + dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3; + dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1; + dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1; + dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256); + dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512); + dictionary.template = dictionaryFlags >> 10 & 3; + dictionary.refinementTemplate = dictionaryFlags >> 12 & 1; + position += 2; + if (!dictionary.huffman) { + atLength = dictionary.template === 0 ? 4 : 1; + at = []; + for (i = 0; i < atLength; i++) { + at.push({ + x: readInt8(data, position), + y: readInt8(data, position + 1) + }); + position += 2; + } + dictionary.at = at; + } + if (dictionary.refinement && !dictionary.refinementTemplate) { + at = []; + for (i = 0; i < 2; i++) { + at.push({ + x: readInt8(data, position), + y: readInt8(data, position + 1) + }); + position += 2; + } + dictionary.refinementAt = at; + } + dictionary.numberOfExportedSymbols = readUint32(data, position); + position += 4; + dictionary.numberOfNewSymbols = readUint32(data, position); + position += 4; + args = [ dictionary, header.number, header.referredTo, data, position, end ]; + break; + + case 6: + case 7: + var textRegion = {}; + textRegion.info = readRegionSegmentInformation(data, position); + position += RegionSegmentInformationFieldLength; + var textRegionSegmentFlags = readUint16(data, position); + position += 2; + textRegion.huffman = !!(textRegionSegmentFlags & 1); + textRegion.refinement = !!(textRegionSegmentFlags & 2); + textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3); + textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3; + textRegion.transposed = !!(textRegionSegmentFlags & 64); + textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3; + textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1; + textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27; + textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1; + if (textRegion.huffman) { + var textRegionHuffmanFlags = readUint16(data, position); + position += 2; + textRegion.huffmanFS = textRegionHuffmanFlags & 3; + textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3; + textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3; + textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3; + textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3; + textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3; + textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3; + textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14); + } + if (textRegion.refinement && !textRegion.refinementTemplate) { + at = []; + for (i = 0; i < 2; i++) { + at.push({ + x: readInt8(data, position), + y: readInt8(data, position + 1) + }); + position += 2; + } + textRegion.refinementAt = at; + } + textRegion.numberOfSymbolInstances = readUint32(data, position); + position += 4; + if (textRegion.huffman) { + error("JBIG2 error: huffman is not supported"); + } + args = [ textRegion, header.referredTo, data, position, end ]; + break; + + case 38: + case 39: + var genericRegion = {}; + genericRegion.info = readRegionSegmentInformation(data, position); + position += RegionSegmentInformationFieldLength; + var genericRegionSegmentFlags = data[position++]; + genericRegion.mmr = !!(genericRegionSegmentFlags & 1); + genericRegion.template = genericRegionSegmentFlags >> 1 & 3; + genericRegion.prediction = !!(genericRegionSegmentFlags & 8); + if (!genericRegion.mmr) { + atLength = genericRegion.template === 0 ? 4 : 1; + at = []; + for (i = 0; i < atLength; i++) { + at.push({ + x: readInt8(data, position), + y: readInt8(data, position + 1) + }); + position += 2; + } + genericRegion.at = at; + } + args = [ genericRegion, data, position, end ]; + break; + + case 48: + var pageInfo = { + width: readUint32(data, position), + height: readUint32(data, position + 4), + resolutionX: readUint32(data, position + 8), + resolutionY: readUint32(data, position + 12) + }; + if (pageInfo.height === 4294967295) { + delete pageInfo.height; + } + var pageSegmentFlags = data[position + 16]; + var pageStripingInformatiom = readUint16(data, position + 17); + pageInfo.lossless = !!(pageSegmentFlags & 1); + pageInfo.refinement = !!(pageSegmentFlags & 2); + pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1; + pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3; + pageInfo.requiresBuffer = !!(pageSegmentFlags & 32); + pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64); + args = [ pageInfo ]; + break; + + case 49: + break; + + case 50: + break; + + case 51: + break; + + case 62: + break; + + default: + error("JBIG2 error: segment type " + header.typeName + "(" + header.type + ") is not implemented"); + } + var callbackName = "on" + header.typeName; + if (callbackName in visitor) { + visitor[callbackName].apply(visitor, args); + } + } + function processSegments(segments, visitor) { + for (var i = 0, ii = segments.length; i < ii; i++) { + processSegment(segments[i], visitor); + } + } + function parseJbig2(data, start, end) { + var position = start; + if (data[position] !== 151 || data[position + 1] !== 74 || data[position + 2] !== 66 || data[position + 3] !== 50 || data[position + 4] !== 13 || data[position + 5] !== 10 || data[position + 6] !== 26 || data[position + 7] !== 10) { + error("JBIG2 error: invalid header"); + } + var header = {}; + position += 8; + var flags = data[position++]; + header.randomAccess = !(flags & 1); + if (!(flags & 2)) { + header.numberOfPages = readUint32(data, position); + position += 4; + } + var segments = readSegments(header, data, position, end); + error("Not implemented"); + } + function parseJbig2Chunks(chunks) { + var visitor = new SimpleSegmentVisitor(); + for (var i = 0, ii = chunks.length; i < ii; i++) { + var chunk = chunks[i]; + var segments = readSegments({}, chunk.data, chunk.start, chunk.end); + processSegments(segments, visitor); + } + return visitor; + } + function SimpleSegmentVisitor() {} + SimpleSegmentVisitor.prototype = { + onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) { + this.currentPageInfo = info; + var rowSize = info.width + 7 >> 3; + var buffer = new Uint8Array(rowSize * info.height); + if (info.defaultPixelValue) { + for (var i = 0, ii = buffer.length; i < ii; i++) { + buffer[i] = 255; + } + } + this.buffer = buffer; + }, + drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) { + var pageInfo = this.currentPageInfo; + var width = regionInfo.width, height = regionInfo.height; + var rowSize = pageInfo.width + 7 >> 3; + var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator; + var buffer = this.buffer; + var mask0 = 128 >> (regionInfo.x & 7); + var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3); + var i, j, mask, offset; + switch (combinationOperator) { + case 0: + for (i = 0; i < height; i++) { + mask = mask0; + offset = offset0; + for (j = 0; j < width; j++) { + if (bitmap[i][j]) { + buffer[offset] |= mask; + } + mask >>= 1; + if (!mask) { + mask = 128; + offset++; + } + } + offset0 += rowSize; + } + break; + + case 2: + for (i = 0; i < height; i++) { + mask = mask0; + offset = offset0; + for (j = 0; j < width; j++) { + if (bitmap[i][j]) { + buffer[offset] ^= mask; + } + mask >>= 1; + if (!mask) { + mask = 128; + offset++; + } + } + offset0 += rowSize; + } + break; + + default: + error("JBIG2 error: operator " + combinationOperator + " is not supported"); + } + }, + onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) { + var regionInfo = region.info; + var decodingContext = new DecodingContext(data, start, end); + var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext); + this.drawBitmap(regionInfo, bitmap); + }, + onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() { + this.onImmediateGenericRegion.apply(this, arguments); + }, + onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) { + var huffmanTables; + if (dictionary.huffman) { + error("JBIG2 error: huffman is not supported"); + } + var symbols = this.symbols; + if (!symbols) { + this.symbols = symbols = {}; + } + var inputSymbols = []; + for (var i = 0, ii = referredSegments.length; i < ii; i++) { + inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]); + } + var decodingContext = new DecodingContext(data, start, end); + symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext); + }, + onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) { + var regionInfo = region.info; + var huffmanTables; + var symbols = this.symbols; + var inputSymbols = []; + for (var i = 0, ii = referredSegments.length; i < ii; i++) { + inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]); + } + var symbolCodeLength = log2(inputSymbols.length); + var decodingContext = new DecodingContext(data, start, end); + var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext); + this.drawBitmap(regionInfo, bitmap); + }, + onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() { + this.onImmediateTextRegion.apply(this, arguments); + } + }; + function Jbig2Image() {} + Jbig2Image.prototype = { + parseChunks: function Jbig2Image_parseChunks(chunks) { + return parseJbig2Chunks(chunks); + } + }; + return Jbig2Image; + }(); + function log2(x) { + var n = 1, i = 0; + while (x > n) { + n <<= 1; + i++; + } + return i; + } + function readInt8(data, start) { + return data[start] << 24 >> 24; + } + function readUint16(data, offset) { + return data[offset] << 8 | data[offset + 1]; + } + function readUint32(data, offset) { + return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0; + } + function shadow(obj, prop, value) { + Object.defineProperty(obj, prop, { + value: value, + enumerable: true, + configurable: true, + writable: false + }); + return value; + } + var error = function() { + console.error.apply(console, arguments); + throw new Error("PDFJS error: " + arguments[0]); + }; + var warn = function() { + console.warn.apply(console, arguments); + }; + var info = function() { + console.info.apply(console, arguments); + }; + Jbig2Image.prototype.parse = function parseJbig2(data) { + var position = 0, end = data.length; + if (data[position] !== 151 || data[position + 1] !== 74 || data[position + 2] !== 66 || data[position + 3] !== 50 || data[position + 4] !== 13 || data[position + 5] !== 10 || data[position + 6] !== 26 || data[position + 7] !== 10) { + error("JBIG2 error: invalid header"); + } + var header = {}; + position += 8; + var flags = data[position++]; + header.randomAccess = !(flags & 1); + if (!(flags & 2)) { + header.numberOfPages = readUint32(data, position); + position += 4; + } + var visitor = this.parseChunks([ { + data: data, + start: position, + end: end + } ]); + var width = visitor.currentPageInfo.width; + var height = visitor.currentPageInfo.height; + var bitPacked = visitor.buffer; + var data = new Uint8Array(width * height); + var q = 0, k = 0; + for (var i = 0; i < height; i++) { + var mask = 0, buffer; + for (var j = 0; j < width; j++) { + if (!mask) { + mask = 128; + buffer = bitPacked[k++]; + } + data[q++] = buffer & mask ? 0 : 255; + mask >>= 1; + } + } + this.width = width; + this.height = height; + this.data = data; + }; + PDFJS.JpegImage = JpegImage; + PDFJS.JpxImage = JpxImage; + PDFJS.Jbig2Image = Jbig2Image; +})(PDFJS || (PDFJS = {})); + +var JpegDecoder = PDFJS.JpegImage; + +var JpxDecoder = PDFJS.JpxImage; + +var Jbig2Decoder = PDFJS.Jbig2Image; \ No newline at end of file diff --git a/libjpeg/package.json b/libjpeg/package.json new file mode 100644 index 0000000..953fec2 --- /dev/null +++ b/libjpeg/package.json @@ -0,0 +1,16 @@ +{ + "pkgname": "libjpeg", + "app":"libjpeg", + "name":"libjpeg", + "description":"libjpeg", + "info":{ + "author": "", + "email": "" + }, + "version":"0.1.0-a", + "category":"Library", + "iconclass":"fa fa-cog", + "mimes":["none"], + "dependencies":[], + "locale": {} +} \ No newline at end of file diff --git a/libjpeg/project.json b/libjpeg/project.json new file mode 100644 index 0000000..23e27f7 --- /dev/null +++ b/libjpeg/project.json @@ -0,0 +1,7 @@ +{ + "name": "libjpeg", + "css": [], + "javascripts": ["jpg.js"], + "coffees": [], + "copies": ["package.json", "README.md"] +} \ No newline at end of file diff --git a/packages.json b/packages.json index 4e485cc..4ec0499 100644 --- a/packages.json +++ b/packages.json @@ -139,6 +139,16 @@ "dependencies": [], "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Katex/build/release/Katex.zip" }, + { + "pkgname": "libjpeg", + "name": "libjpeg", + "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libjpeg/README.md", + "category": "Library", + "author": "", + "version": "0.1.0-a", + "dependencies": [], + "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libjpeg/build/release/libjpeg.zip" + }, { "pkgname": "LuaPlayground", "name": "LuaPlayground",