Ejemplo n.º 1
0
static int read_offset(LHALH1Decoder *decoder, unsigned int *result)
{
    unsigned int offset;
    int future, offset2;

    // The offset can be up to 8 bits long, but is likely not
    // that long. Use the lookup table to find the offset
    // and its length.

    future = peek_bits(&decoder->bit_stream_reader, 8);

    if (future < 0) {
        return 0;
    }

    offset = decoder->offset_lookup[future];

    // Skip past the offset bits and also read the following
    // lower-order bits.

    read_bits(&decoder->bit_stream_reader,
              decoder->offset_lengths[offset]);

    offset2 = read_bits(&decoder->bit_stream_reader, 6);

    if (offset2 < 0) {
        return 0;
    }

    *result = (offset << 6) | (unsigned int) offset2;

    return 1;
}
Ejemplo n.º 2
0
static inline int get_run(stream_CFD_state *ss, stream_cursor_read *pr, const cfd_node decode[],
           int initial_bits, int min_bits, int *runlen, const char *str)
{
    cfd_declare_state;
    const cfd_node *np;
    int clen;
    cfd_load_state();

    HCD_ENSURE_BITS_ELSE(initial_bits) {
        /* We might still have enough bits for the specific code. */
        if (bits_left < min_bits)
            goto outl;
        np = &decode[hcd_peek_bits_left() << (initial_bits - bits_left)];
        if ((clen = np->code_length) > bits_left)
            goto outl;
        goto locl;
    }
    np = &decode[peek_bits(initial_bits)];
    if ((clen = np->code_length) > initial_bits) {
            IF_DEBUG(uint init_bits = peek_bits(initial_bits));
            if (!avail_bits(clen)) goto outl;
            clen -= initial_bits;
            skip_bits(initial_bits);
            ensure_bits(clen, outl);                /* can't goto outl */
            np = &decode[np->run_length + peek_var_bits(clen)];
            if_debug4('W', "%s xcode=0x%x,%d rlen=%d\n", str,
                      (init_bits << np->code_length) +
                        peek_var_bits(np->code_length),
                      initial_bits + np->code_length,
                      np->run_length);
            skip_bits(np->code_length);
    } else {
locl:
       if_debug4('W', "%s code=0x%x,%d rlen=%d\n", str,
                      peek_var_bits(clen), clen, np->run_length);
       skip_bits(clen);
    }
    *runlen = np->run_length;

    cfd_store_state();
    return(0);
outl:
    cfd_store_state();
    return(-1);
}
Ejemplo n.º 3
0
static int read_bits(BitStreamReader *reader,
                     unsigned int n)
{
	int result;

	result = peek_bits(reader, n);

	if (result >= 0) {
		reader->bit_buffer <<= n;
		reader->bits -= n;
	}

	return result;
}