Example #1
0
        private void genDecodeTable(WSQHelper.HuffCode[] huffcodeTable, int[] maxcode, int[] mincode, int[] valptr, int[] huffbits)
        {
            for (int i = 0; i <= MAX_HUFFBITS; i++) {
                maxcode[i] = 0;
                mincode[i] = 0;
                valptr[i] = 0;
            }

            int i2 = 0;
            for (int i = 1; i <= MAX_HUFFBITS; i++) {
                if (huffbits[i - 1] == 0) {
                    maxcode[i] = -1;
                    continue;
                }
                valptr[i] = i2;
                mincode[i] = huffcodeTable[i2].code;
                i2 = i2 + huffbits[i - 1] - 1;
                maxcode[i] = huffcodeTable[i2].code;
                i2++;
            }
        }
Example #2
0
        private void buildHuffcodes(WSQHelper.HuffCode[] huffcodeTable)
        {
            short tempCode = 0;  /*used to construct code word*/
            int pointer = 0;     /*pointer to code word information*/

            int tempSize = huffcodeTable[0].size;
            if (huffcodeTable[pointer].size == 0) {
                return;
            }

            do {
                do {
                    huffcodeTable[pointer].code = tempCode;
                    tempCode++;
                    pointer++;
                } while (huffcodeTable[pointer].size == tempSize);

                if (huffcodeTable[pointer].size == 0)
                    return;

                do {
                    tempCode <<= 1;
                    tempSize++;
                } while (huffcodeTable[pointer].size != tempSize);
            } while (huffcodeTable[pointer].size == tempSize);
        }