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

📄 vlc.c

📁 AVS视频编解码器 能实现视频图像的高效率压缩 能在VC上高速运行
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2003, Advanced Audio Video Coding Standard, Part II
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the users without any
* license fee or royalty on an "as is" basis. The AVS disclaims
* any and all warranties, whether express, implied, or statutory,
* including any implied warranties of merchantability or of fitness
* for a particular purpose. In no event shall the contributors or 
* the AVS be liable for any incidental, punitive, or consequential
* damages of any kind whatsoever arising from the use of this program.
*
* This disclaimer of warranty extends to the user of this program
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The AVS does not represent or warrant that the program furnished
* hereunder are free of infringement of any third-party patents.
* Commercial implementations of AVS, including shareware, may be
* subject to royalty fees to patent holders. Information regarding
* the AVS patent policy is available from the AVS Web site at
* http://www.avs.org.cn
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
************************************************************************
*/

/*
*************************************************************************************
* File name: 
* Function: 
*
*************************************************************************************
*/

#include "contributors.h"

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "golomb.h"
#include "vlc.h"

/*const int NCBP[64][2]=
{
  { 4, 0},{37, 1},{38, 2},{21, 8},{39, 3},{22, 9},{41,20},{ 5,16},
  {40, 4},{42,21},{23,10},{ 6,17}, {24,11},{ 7,18},{ 8,19},{ 3,12},
  {44, 5},{47,34},{50,37},{26,22},{53,40},{29,25},{59,58},{10,46},
  {56,43},{62,61},{32,28},{13,49},{35,31},{16,52},{19,55},{ 1,13},
  {45, 6},{48,35},{51,38},{27,23}, {54,41},{30,26},{60,59},{11,47},
  {57,44},{63,62},{33,29},{14,50},{36,32},{17,53},{20,56},{ 2,14},
  {43, 7},{46,36},{49,39},{25,24},{52,42},{28,27},{58,60},{ 9,48},
  {55,45},{61,63},{31,30},{12,51}, {34,33},{15,54},{18,57},{ 0,15}
};*/

const int NCBP[64][2]=                                     // jlzheng 7.20
{
  { 4, 0},{16, 19},{17, 16},{19, 15},{14, 18},{9, 11},{22,31},{ 8,13},
  {11, 17},{21,30},{10,12},{ 7,9}, {12,10},{ 6,7},{ 5,8},{ 1,1},
  {35, 4},{47,42},{48,38},{38,27},{46,39},{36,33},{50,59},{26,26},
  {45,40},{52,58},{41,35},{28,25},{37,29},{23,24},{31,28},{ 2,3},
  {43, 5},{51,51},{56,52},{39,37}, {55,50},{33,43},{62,63},{27,44},
  {54,53},{60,62},{40,48},{32,47},{42,34},{24,45},{29,49},{ 3,6},
  {49, 14},{53,55},{57,56},{25,36},{58,54},{30,41},{59,60},{ 15,21},
  {61,57},{63,61},{44,46},{18,22}, {34,32},{13,20},{20,23},{ 0,2}
};

/*
*************************************************************************
* Function:ue_v, writes an ue(v) syntax element, returns the length in bits
* Input:
		tracestring
      the string for the trace file
        value
      the value to be coded
        bitstream
      the Bitstream the value should be coded into
* Output:
* Return:  Number of bits used by the coded syntax element
* Attention: This function writes always the bit buffer for the progressive scan flag, and
      should not be used (or should be modified appropriately) for the interlace crap
      When used in the context of the Parameter Sets, this is obviously not a
      problem.
*************************************************************************
*/

int ue_v (char *tracestring, int value, Bitstream *bitstream)
{
  SyntaxElement symbol, *sym=&symbol;
  sym->type = SE_HEADER;
  sym->mapping = ue_linfo;               // Mapping rule: unsigned integer
  sym->value1 = value;

#if TRACE
  strncpy(sym->tracestring,tracestring,TRACESTRING_SIZE);
#endif

  return writeSyntaxElement_UVLC (sym, bitstream);
}

/*
*************************************************************************
* Function:ue_v, writes an ue(v) syntax element, returns the length in bits
* Input:
		 tracestring
      the string for the trace file
         value
      the value to be coded
         bitstream
      the Bitstream the value should be coded into
* Output:
* Return: Number of bits used by the coded syntax element
* Attention:
		This function writes always the bit buffer for the progressive scan flag, and
      should not be used (or should be modified appropriately) for the interlace crap
      When used in the context of the Parameter Sets, this is obviously not a
      problem.
*************************************************************************
*/

int se_v (char *tracestring, int value, Bitstream *bitstream)
{
  SyntaxElement symbol, *sym=&symbol;
  sym->type = SE_HEADER;
  sym->mapping = se_linfo;               // Mapping rule: signed integer
  sym->value1 = value;
  
#if TRACE
  strncpy(sym->tracestring,tracestring,TRACESTRING_SIZE);
#endif

  return writeSyntaxElement_UVLC (sym, bitstream);
}

/*
*************************************************************************
* Function: u_1, writes a flag (u(1) syntax element, returns the length in bits, 
           always 1
* Input:
	     tracestring
      the string for the trace file
		 value
      the value to be coded
         bitstream
      the Bitstream the value should be coded into
* Output:
* Return: Number of bits used by the coded syntax element (always 1)
* Attention:This function writes always the bit buffer for the progressive scan flag, and
      should not be used (or should be modified appropriately) for the interlace crap
      When used in the context of the Parameter Sets, this is obviously not a
      problem.
*************************************************************************
*/

int u_1 (char *tracestring, int value, Bitstream *bitstream)
{
  SyntaxElement symbol, *sym=&symbol;

  sym->bitpattern = value;
  sym->len = 1;
  sym->type = SE_HEADER;
  sym->value1 = value;

#if TRACE
  strncpy(sym->tracestring,tracestring,TRACESTRING_SIZE);
#endif

  return writeSyntaxElement_fixed(sym, bitstream);
}

/*
*************************************************************************
* Function:u_v, writes a a n bit fixed length syntax element, returns the length in bits, 
* Input:
		tracestring
      the string for the trace file
         value
      the value to be coded
        bitstream
      the Bitstream the value should be coded into
* Output:
* Return: Number of bits used by the coded syntax element 
* Attention:This function writes always the bit buffer for the progressive scan flag, and
      should not be used (or should be modified appropriately) for the interlace crap
      When used in the context of the Parameter Sets, this is obviously not a
     problem.
*************************************************************************
*/
int u_v (int n, char *tracestring, int value, Bitstream *bitstream)
{
  SyntaxElement symbol, *sym=&symbol;

  sym->bitpattern = value;
  sym->len = n;
  sym->type = SE_HEADER;
  sym->value1 = value;

#if TRACE
  strncpy(sym->tracestring,tracestring,TRACESTRING_SIZE);
#endif

  return writeSyntaxElement_fixed(sym, bitstream);
}


/*
*************************************************************************
* Function:mapping for ue(v) syntax elements
* Input:
		ue
      value to be mapped
       info
      returns mapped value
       len
      returns mapped value length
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void ue_linfo(int ue, int dummy, int *len,int *info)
{
  int i,nn;

  nn=(ue+1)/2;

  for (i=0; i < 16 && nn != 0; i++)
  {
    nn /= 2;
  }

  *len= 2*i + 1;
  *info=ue+1-(int)pow(2,i);
  
}

/*
*************************************************************************
* Function:mapping for ue(v) syntax elements
* Input:
		ue
      value to be mapped
       info
      returns mapped value
       len
      returns mapped value length
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void se_linfo(int se, int dummy, int *len,int *info)
{

  int i,n,sign,nn;

  sign=0;

  if (se <= 0)
  {
    sign=1;
  }
  n=abs(se) << 1;

  //n+1 is the number in the code table.  Based on this we find length and info

  nn=n/2;
  for (i=0; i < 16 && nn != 0; i++)
  {
    nn /= 2;
  }
  *len=i*2 + 1;
  *info=n - (int)pow(2,i) + sign;

}

/*
*************************************************************************
* Function:
* Input:Number in the code table
* Output:lenght and info
* Return: 
* Attention:
*************************************************************************
*/

void cbp_linfo_intra(int cbp, int dummy, int *len,int *info)
{
  //extern const int NCBP[48][2];
	extern const int NCBP[64][2];
  ue_linfo(NCBP[cbp][0], dummy, len, info);
}


/*
*************************************************************************
* Function:
* Input:Number in the code table
* Output:lenght and info
* Return: 
* Attention:
*************************************************************************
*/

void cbp_linfo_inter(int cbp, int dummy, int *len,int *info)
{
	extern const int NCBP[64][2];
  ue_linfo(NCBP[cbp][1], dummy, len, info);
}

/*
*************************************************************************
* Function:Makes code word and passes it back
      A code word has the following format: 0 0 0 ... 1 Xn ...X2 X1 X0.

⌨️ 快捷键说明

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