⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mvbitstream.h

📁 优化过的xvid1.1.2源代码
💻 H
字号:
#ifndef _MVBITSTREAM_H_
#define _MVBITSTREAM_H_

#include "MVGlobal.h"

/* this bitstream functions is extracted from the Bitstream.h
*  their work is read bitstream , now I delete some functions
*  which work in encoder and not called in decoder, 
*  such as BitstreamPutBit,BitstreamPutBits
*  BitstreamPad,BitstreamPadAlways,BitstreamForward,BitstreamReset,
*  BitstreamLength
*  wuhaibin 2007-01-22
*/

void __inline BitstreamInit(Bitstream * const bs,
			  void *const bitstream,
			  uint32_t length)
{
	uint32_t tmp;
	size_t bitpos;
	ptr_t adjbitstream = (ptr_t)bitstream;

	/*
	 * Start the stream on a uint32_t boundary, by rounding down to the
	 * previous uint32_t and skipping the intervening bytes.
	 */
	bitpos = ((sizeof(uint32_t)-1) & (size_t)bitstream);
	adjbitstream = adjbitstream - bitpos;
	bs->start = bs->tail = (uint32_t *) adjbitstream;

	tmp = *bs->start;

#ifndef ARCH_IS_BIG_ENDIAN
		BSWAP(tmp);
#endif
	bs->bufa = tmp;

	tmp = *(bs->start + 1);

#ifndef ARCH_IS_BIG_ENDIAN
		BSWAP(tmp);
#endif

	bs->bufb = tmp;

	bs->pos = bs->initpos = bitpos*8;
	/* preserve the intervening bytes */
	if (bs->initpos > 0)
		bs->buf = bs->bufa & (0xffffffff << (32 - bs->initpos));
	else
		bs->buf = 0;
	bs->length = length;
}

uint32_t __inline BitstreamShowBits(Bitstream * const bs,
				                    const uint32_t bits)
{
	int nbit = (bits + bs->pos) - 32;

	if (nbit > 0) {
		return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) | (bs->
																 bufb >> (32 -
																		  nbit));
	} else {
		return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);
	}
}


/* skip n bits forward in bitstream */

void __inline BitstreamSkip(Bitstream * const bs,
			                const uint32_t bits)
{
	bs->pos += bits;

	if (bs->pos >= 32) 
	{
		uint32_t tmp;

		bs->bufa = bs->bufb;
		if (bs->tail<(bs->start+((bs->length+3)>>2)))
		{
			tmp = *((uint32_t *) bs->tail + 2);
#ifndef ARCH_IS_BIG_ENDIAN
		BSWAP(tmp);
#endif
			bs->bufb = tmp;
			bs->tail++;
		}
		else
		{
			bs->bufb = 0;
		}
		bs->pos -= 32;
	}
}

uint32_t __inline BitstreamGetBits(Bitstream * const bs,
									const uint32_t n)
{
	uint32_t ret = BitstreamShowBits(bs, n);

	BitstreamSkip(bs, n);

	return ret;
}


/* read single bit from bitstream */

__inline uint32_t  BitstreamGetBit(Bitstream * const bs)
{
	return BitstreamGetBits(bs, 1);
}


/* number of bits to next byte alignment */
__inline uint32_t BitstreamNumBitsToByteAlign(Bitstream *bs)
{
	uint32_t n = (32 - bs->pos) % 8;
	return n == 0 ? 8 : n;
}


/* show nbits from next byte alignment */
__inline uint32_t BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
{
	int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
	int nbit = (bits + bspos) - 32;

	if (bspos >= 32)
	{
		return bs->bufb >> (32 - nbit);
	} 
	else
	  if (nbit > 0) 
	  {
		return ((bs->bufa & (0xffffffff >> bspos)) << nbit) |
			    (bs->bufb >> (32 - nbit));
	  } 
	  else 
	  {
		return (bs->bufa & (0xffffffff >> bspos)) >> (32 - bspos - bits);
	  }

}

/* move forward to the next byte boundary */

__inline void BitstreamByteAlign(Bitstream * const bs)
{
	uint32_t remainder = bs->pos % 8;

	if (remainder)
	{
		BitstreamSkip(bs, 8 - remainder);
	}
}


/* bitstream length (unit bits) */

uint32_t __inline BitstreamPos(const Bitstream * const bs)
{
	return((uint32_t)(8*((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos - bs->initpos));
}

/* extracted form bitstream.c,wuhaibin 2007-01-22*/ 
void bs_get_matrix(Bitstream * bs, uint8_t * matrix);

/*extracted form decoder.c ,wuhaibin 2007-01-22*/
int32_t get_dbquant(Bitstream * bs);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -