MCPcopy Create free account
hub / github.com/TruthHun/BookStack / processDU

Function processDU

static/webuploader/webuploader.fis.js:6034–6084  ·  view source on GitHub ↗
(CDU, fdtbl, DC, HTDC, HTAC)

Source from the content-addressed store, hash-verified

6032 }
6033
6034 function processDU(CDU, fdtbl, DC, HTDC, HTAC){
6035 var EOB = HTAC[0x00];
6036 var M16zeroes = HTAC[0xF0];
6037 var pos;
6038 var I16 = 16;
6039 var I63 = 63;
6040 var I64 = 64;
6041 var DU_DCT = fDCTQuant(CDU, fdtbl);
6042 //ZigZag reorder
6043 for (var j=0;j<I64;++j) {
6044 DU[ZigZag[j]]=DU_DCT[j];
6045 }
6046 var Diff = DU[0] - DC; DC = DU[0];
6047 //Encode DC
6048 if (Diff==0) {
6049 writeBits(HTDC[0]); // Diff might be 0
6050 } else {
6051 pos = 32767+Diff;
6052 writeBits(HTDC[category[pos]]);
6053 writeBits(bitcode[pos]);
6054 }
6055 //Encode ACs
6056 var end0pos = 63; // was const... which is crazy
6057 for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {};
6058 //end0pos = first element in reverse order !=0
6059 if ( end0pos == 0) {
6060 writeBits(EOB);
6061 return DC;
6062 }
6063 var i = 1;
6064 var lng;
6065 while ( i <= end0pos ) {
6066 var startpos = i;
6067 for (; (DU[i]==0) && (i<=end0pos); ++i) {}
6068 var nrzeroes = i-startpos;
6069 if ( nrzeroes >= I16 ) {
6070 lng = nrzeroes>>4;
6071 for (var nrmarker=1; nrmarker <= lng; ++nrmarker)
6072 writeBits(M16zeroes);
6073 nrzeroes = nrzeroes&0xF;
6074 }
6075 pos = 32767+DU[i];
6076 writeBits(HTAC[(nrzeroes<<4)+category[pos]]);
6077 writeBits(bitcode[pos]);
6078 i++;
6079 }
6080 if ( end0pos != I63 ) {
6081 writeBits(EOB);
6082 }
6083 return DC;
6084 }
6085
6086 function initCharLookupTable(){
6087 var sfcc = String.fromCharCode;

Callers 1

JPEGEncoderFunction · 0.70

Calls 2

fDCTQuantFunction · 0.70
writeBitsFunction · 0.70

Tested by

no test coverage detected