private int HuffmanValue(int table[], int temp[], int index[],
                             InputStream in) throws Exception {
        int code, input, mask = 0xFFFF;
        if (index[0] < 8) {
            temp[0] <<= 8;
            input = get8(in);
            if (input == 0xFF) {
                marker = get8(in);
                if (marker != 0) {
                    marker_index = 9;
                }
            }
            temp[0] |= input;
        } else {
            index[0] -= 8;
        }
        code = table[temp[0] >> index[0]];
        if ((code & MSB) != 0) {
            if (marker_index != 0) {
                marker_index = 0;
                return 0xFF00 | marker;
            }
            temp[0] &= (mask >> (16 - index[0]));
            temp[0] <<= 8;
            input = get8(in);
            if (input == 0xFF) {
                marker = get8(in);
                if (marker != 0) {
                    marker_index = 9;
                }
            }
            temp[0] |= input;
            code = table[(code & 0xFF) * 256 + (temp[0] >> index[0])];
            index[0] += 8;
        }
        index[0] += 8 - (code >> 8);
        if (index[0] < 0) {
            error("index=" + index[0] + " temp=" + temp[0] + " code=" + code +
                    " in HuffmanValue()");
        }
        if (index[0] < marker_index) {
            marker_index = 0;
            return 0xFF00 | marker;
        }
        temp[0] &= (mask >> (16 - index[0]));
        return code & 0xFF;
    }