huffarray.js
/**
     * Read the next huffman code from the data source and return the
     * value represented by the code.
     * 
     * F.2.2.3
     * 
     * @param {DataViewReader} reader Data source
     * @param {*} img Struct containing information about the image
     */
Read the next huffman code from the data source and return the
value represented by the code.



@param {DataViewReader} reader Data source
@param {*} img Struct containing information about the image
Read the next huffman code from the data source and return the value represented by the code . @param { DataViewReader } reader Data source @param { * } img Struct containing information about the image
decodeHuffman(reader, img) {
        let mincode = [];
        let maxcode = [];
        let valptr = [];
        let i = 0;
        let j = 0;
        while (true) {
            i++;
            if (i > NUM_HUFFMAN_LENGTHS) {
                break;
            }
            if (this.bits[i] === 0) {
                maxcode[i] = -1;
            } else {
                valptr[i] = j;
                mincode[i] = this.huffcode[j];
                j += this.bits[i] - 1;
                maxcode[i] = this.huffcode[j];
                j++;
            }
        }
        i = 1;
        let code = reader.nextBit(img);
        while (code > maxcode[i]) {
            i++;
            let tmp = reader.nextBit(img);
            code = (code << 1) + tmp;
        }
        j = valptr[i];
        j += code - mincode[i];
        let value = this.huffval[j];
        return value;
    }
decodeHuffman ( reader , img ) { let mincode = [ ] ; let maxcode = [ ] ; let valptr = [ ] ; let i = 0 ; let j = 0 ; while ( true ) { i ++ ; if ( i > NUM_HUFFMAN_LENGTHS ) { break ; } if ( this . bits [ i ] === 0 ) { maxcode [ i ] = - 1 ; } else { valptr [ i ] = j ; mincode [ i ] = this . huffcode [ j ] ; j += this . bits [ i ] - 1 ; maxcode [ i ] = this . huffcode [ j ] ; j ++ ; } } i = 1 ; let code = reader . nextBit ( img ) ; while ( code > maxcode [ i ] ) { i ++ ; let tmp = reader . nextBit ( img ) ; code = ( code << 1 ) + tmp ; } j = valptr [ i ] ; j += code - mincode [ i ] ; let value = this . huffval [ j ] ; return value ; }
Read the next huffman code from the data source and return the
 value represented by the code.
Read the next huffman code from the data source and return the value represented by the code .
// let bitString = ""; // bitString += code; // bitString += tmp; // console.log("Found value " + value + " for code " + code + " bitString: " + bitString);