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

📄 bitstream.cpp

📁 H.263的编码程序,加了CPU指令优化,VC版.
💻 CPP
字号:
/*!
********************************************************
*\file
*    bitstream.cpp
*\brief
*    for the functions which deal with bitstream operation.
*\date
*    12/6/2002
*\last modified by JiaJie 2003/3/25
*
********************************************************/
#include "bitstream.h"


static unsigned int mskr[33] =
{
  0x00000000, 0x00000001, 0x00000003, 0x00000007,
  0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
  0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
  0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
  0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
  0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
  0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
  0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
  0xffffffff
};
static unsigned int mskl[33] =
{
	0x00000000,
	0x80000000, 0xc0000000, 0xe0000000, 0xf0000000,
	0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
	0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
	0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000,
	0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000,
	0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00,
	0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0,
	0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff
	
};
static unsigned int msk[4] =
{
	0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
};

void putbits(putstrm *putstrmctrl, int val, int n)
{
	  int i,j;
	  unsigned int b;
	  if((putstrmctrl->ptrint == ((putstrmctrl->buff_size >> 2) - 1)) && ((j = putstrmctrl->pcntint) <= n))
	  {
		  //read j bits into pout[] first
		  b = (val >> (n - j)) & mskr[j];
		  putstrmctrl->bitoutint |= b;
		  i = putstrmctrl->bitoutint;
		  i = ((i & msk[0])>>24) | ((i & msk[1])>>8) | ((i & msk[2])<< 8) | ((i & msk[3])<<24);
		  putstrmctrl->poutint[putstrmctrl->ptrint] = i;
		  putstrmctrl->bitoutint = 0;
		  (putstrmctrl->WriteData)((unsigned char *)putstrmctrl->poutint, ((putstrmctrl->ptrint+1)<<2), putstrmctrl->timestamp,
			                    putstrmctrl->pic_type, putstrmctrl->context);
		  putstrmctrl->ptrint = 0;
		  putstrmctrl->pcntint = 32;
		  n -= j;
	  }
	  if (putstrmctrl->pcntint > n)
	  {
		  b = (val << (putstrmctrl->pcntint - n)) & mskr[putstrmctrl->pcntint] & mskl[32 - putstrmctrl->pcntint + n];
		  putstrmctrl->bitoutint |= b;
		  putstrmctrl->pcntint -= n;
	  }
	  else
	  {
		  j = n - putstrmctrl->pcntint;
		  b = (val >> j) & mskr[putstrmctrl->pcntint];
		  putstrmctrl->bitoutint |= b;
		  i = putstrmctrl->bitoutint;
		  i = ((i & msk[0])>>24) | ((i & msk[1])>>8) | ((i & msk[2])<< 8) | ((i & msk[3])<<24);
		  putstrmctrl->poutint[putstrmctrl->ptrint] = i ;
		  putstrmctrl->bitoutint = 0;
		  putstrmctrl->ptrint++;
		  b = (val << (32 - j)) & mskl[j];
		  putstrmctrl->bitoutint |= b;
		  putstrmctrl->pcntint =  32 - j;
	  }
	 if(putstrmctrl->pcntint == 0)
	 {
			 putstrmctrl->pcntint = 32;
	 }

} 

/*
*  alignbits: called when one frame is completely encoded, to make the last bit of the 
*            stream the last bit of a byte
*/
int alignbits (putstrm *putstrmctrl)
{
  int ret_value;
  
  if (putstrmctrl->pcntint!=32)
  {
    ret_value = putstrmctrl->pcntint;	
    putbits (putstrmctrl, 0, ret_value);
    return ret_value;
  }
  else
    return 0;
}

/*
*  clear_buff: called when one frame is completely encoded, to process the data in the stream
*              buffer through a callback function, no matter the buffer is full or not. 
*/
void clear_buff(putstrm *putstrmctrl)
{
  (putstrmctrl->WriteData)((unsigned char *)putstrmctrl->poutint, (putstrmctrl->ptrint*4), putstrmctrl->timestamp,
			              putstrmctrl->pic_type, putstrmctrl->context);
}

⌨️ 快捷键说明

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