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

Function processDU

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

Source from the content-addressed store, hash-verified

6057 }
6058
6059 function processDU(CDU, fdtbl, DC, HTDC, HTAC){
6060 var EOB = HTAC[0x00];
6061 var M16zeroes = HTAC[0xF0];
6062 var pos;
6063 var I16 = 16;
6064 var I63 = 63;
6065 var I64 = 64;
6066 var DU_DCT = fDCTQuant(CDU, fdtbl);
6067 //ZigZag reorder
6068 for (var j=0;j<I64;++j) {
6069 DU[ZigZag[j]]=DU_DCT[j];
6070 }
6071 var Diff = DU[0] - DC; DC = DU[0];
6072 //Encode DC
6073 if (Diff==0) {
6074 writeBits(HTDC[0]); // Diff might be 0
6075 } else {
6076 pos = 32767+Diff;
6077 writeBits(HTDC[category[pos]]);
6078 writeBits(bitcode[pos]);
6079 }
6080 //Encode ACs
6081 var end0pos = 63; // was const... which is crazy
6082 for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {};
6083 //end0pos = first element in reverse order !=0
6084 if ( end0pos == 0) {
6085 writeBits(EOB);
6086 return DC;
6087 }
6088 var i = 1;
6089 var lng;
6090 while ( i <= end0pos ) {
6091 var startpos = i;
6092 for (; (DU[i]==0) && (i<=end0pos); ++i) {}
6093 var nrzeroes = i-startpos;
6094 if ( nrzeroes >= I16 ) {
6095 lng = nrzeroes>>4;
6096 for (var nrmarker=1; nrmarker <= lng; ++nrmarker)
6097 writeBits(M16zeroes);
6098 nrzeroes = nrzeroes&0xF;
6099 }
6100 pos = 32767+DU[i];
6101 writeBits(HTAC[(nrzeroes<<4)+category[pos]]);
6102 writeBits(bitcode[pos]);
6103 i++;
6104 }
6105 if ( end0pos != I63 ) {
6106 writeBits(EOB);
6107 }
6108 return DC;
6109 }
6110
6111 function initCharLookupTable(){
6112 var sfcc = String.fromCharCode;

Callers 1

JPEGEncoderFunction · 0.70

Calls 2

fDCTQuantFunction · 0.70
writeBitsFunction · 0.70

Tested by

no test coverage detected