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

Function processDU

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

Source from the content-addressed store, hash-verified

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

Callers 1

JPEGEncoderFunction · 0.70

Calls 2

fDCTQuantFunction · 0.70
writeBitsFunction · 0.70

Tested by

no test coverage detected