www.pudn.com > avs-m3.rar > vlc.c


 
/* 
************************************************************************************* 
* File name: vlc.c 
* Function: VLC support functions 
* 
************************************************************************************* 
*/ 
 
#include  
#include  
//#include  
#include  
#include  
 
#include "global.h" 
#include "vlc.h" 
#include "header.h" 
#include "global.h" 
//#include "output.h" 
 
// A little trick to avoid those horrible #if TRACE all over the source code 
#if TRACE 
#define SYMTRACESTRING(s) strncpy(sym->tracestring,s,TRACESTRING_SIZE) 
#else 
#define SYMTRACESTRING(s) // do nothing 
#endif 
 
const int SCAN[16][2] = // [scan_pos][x/y] ATTENTION: the ScanPositions are (pix,lin)!    //qwang 2004-3-9 
{ 
	{0,0},{1,0},{0,1},{0,2}, 
	{1,1},{2,0},{3,0},{2,1}, 
	{1,2},{0,3},{1,3},{2,2}, 
	{3,1},{3,2},{2,3},{3,3} 
}; 
 
 
char AVS_2DVLC_INTER_dec[7][64][2]={{{-1,-1}}}; 
const char AVS_2DVLC_INTER[7][26][27] =  
{ 
	{ 
		{ 0, 26, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{ 2, 46, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{ 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{ 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{ 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{18, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{20, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{22, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{28, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{30, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{34, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{36, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{38, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{42, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{44, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{52, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{56, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	}, 
	{ 
		{ 2,  0, 13, 29, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  3, 23, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  5, 35, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  7, 39, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  9, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 11, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 15, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 27, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 37, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 41, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	}, 
	{ 
		{ 2,  0,  5, 11, 23, 35, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  3, 13, 27, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  7, 21, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1,  9, 29, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 15, 37, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 17, 41, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 19, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 39, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	}, 
	{ 
		{ 2,  0,  3,  7, 13, 17, 27, 35, 43, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  5, 11, 21, 33, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  9, 23, 37, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 15, 29, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 19, 41, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 25, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 39, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	}, 
	{ 
		{ 2,  0,  3,  5,  9, 11, 17, 21, 25, 33, 41, 45, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1,  7, 13, 19, 29, 35, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 15, 27, 43, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 23, 37, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 31, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 39, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	}, 
	{ 
		{ 0,  1,  3,  5,  7,  9, 13, 15, 17, 21, 25, 29, 33, 39, 43, 49, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 11, 19, 27, 31, 41, 45, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 23, 37, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 35, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	}, 
	{ 
		{ 0,  1,  3,  5,  7,  9, 11, 13, 17, 19, 21, 23, 25, 29, 33, 35, 39, 41, 43, 47, 49, 57, -1, -1, -1, -1, -1}, 
		{-1, 15, 27, 37, 45, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 31, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
	} 
}; 
const char VLC_Golomb_Order[2][3][7][2] =       //[interlace/frame][intra/inter/chroma][tablenum][grad/maxlevel] 
{ 
	{  //interlace coding 
		{ 
			{2,9}, {2,9}, {1,9}, {2,9}, {2,9}, {3,9}, {-1,-1}, 
		}, 
		{ 
			{3,9}, {2,9}, {1,9}, {2,9}, {2,9}, {2,9}, {3,9}, 
		}, 
		{ 
				{2,9}, {2,9}, {1,9}, {1,9}, {2,9}, {-1,-1}, {-1,-1}, 
		}, 
	},  
	{  //frame coding 
		{ 
			{2,9}, {2,9}, {2,9}, {2,9}, {2,9}, {2,9}, {2,9}, 
		}, 
		{ 
			{3,9}, {2,9}, {2,9}, {2,9}, {2,9}, {2,9}, {2,9}, 
		}, 
		{ 
			{2,9}, {0,9}, {1,9}, {1,9}, {0,9}, {-1,-1}, {-1,-1}, 
		}, 
	} 
}; 
 
const char MaxRun[3][7] =  
{ 
	{22,14,9,6,4,2,1}, 
	{25,18,13,9,6,4,3}, 
	{24,19,10,7,4,-1,-1} 
}; 
 
const char RefAbsLevel[19][26] =  
{ 
	{ 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,-1,-1,-1}, 
	{ 7, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{10, 6, 4, 4, 3, 3, 3, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{13, 7, 5, 4, 3, 2, 2,-1,-1,-1 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{18, 8, 4, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{22, 7, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{27, 4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{ 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 
	{ 5, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1}, 
	{ 7, 5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{10, 6, 5, 4, 3, 3, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{13, 7, 5, 4, 3, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{17, 8, 4, 3, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{22, 6, 3, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{ 5, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,-1}, 
	{ 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1}, 
	{10, 6, 4, 4, 3, 3, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{14, 7, 4, 3, 3, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, 
	{20, 7, 3, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1} 
}; 
 
const int B8SCAN[2][64][2] = // [scan_pos][x/y] ATTENTION: the ScanPositions are (pix,lin)! 
{ 
	{ 
    { 0, 0}, { 0, 1}, { 0, 2}, { 1, 0}, { 0, 3}, { 0, 4}, { 1, 1}, { 1, 2}, 
		{0,5},{0,6},{1,3},{2,0},{2,1},{0,7},{1,4},{2,2}, 
		{3,0},{1,5},{1,6},{2,3},{3,1},{3,2},{4,0},{1,7}, 
		{2,4},{4,1},{2,5},{3,3},{4,2},{2,6},{3,4},{4,3}, 
		{5,0},{5,1},{2,7},{3,5},{4,4},{5,2},{6,0},{5,3}, 
		{3,6},{4,5},{6,1},{6,2},{5,4},{3,7},{4,6},{6,3}, 
		{5,5},{4,7},{6,4},{5,6},{6,5},{5,7},{6,6},{7,0}, 
		{6,7},{7,1},{7,2},{7,3},{7,4},{7,5},{7,6},{7,7} 
	}, 
	{ 
		{ 0, 0}, { 1, 0}, { 0, 1}, { 0, 2}, { 1, 1}, { 2, 0}, { 3, 0}, { 2, 1}, 
		{ 1, 2}, { 0, 3}, { 0, 4}, { 1, 3}, { 2, 2}, { 3, 1}, { 4, 0}, { 5, 0}, 
		{ 4, 1}, { 3, 2}, { 2, 3}, { 1, 4}, { 0, 5}, { 0, 6}, { 1, 5}, { 2, 4}, 
		{ 3, 3}, { 4, 2}, { 5, 1}, { 6, 0}, { 7, 0}, { 6, 1}, { 5, 2}, { 4, 3}, 
		{ 3, 4}, { 2, 5}, { 1, 6}, { 0, 7}, { 1, 7}, { 2, 6}, { 3, 5}, { 4, 4}, 
		{ 5, 3}, { 6, 2}, { 7, 1}, { 7, 2}, { 6, 3}, { 5, 4}, { 4, 5}, { 3, 6}, 
		{ 2, 7}, { 3, 7}, { 4, 6}, { 5, 5}, { 6, 4}, { 7, 3}, { 7, 4}, { 6, 5}, 
		{ 5, 6}, { 4, 7}, { 5, 7}, { 6, 6}, { 7, 5}, { 7, 6}, { 6, 7}, { 7, 7} 
	} 
}; 
//extern int  readSyntaxElement_HybridGOLOMB(SyntaxElement *se); 
 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   ue_v, reads an ue(v) syntax element, the length in bits is stored in  
 *   the global UsedBits variable 
 *  \param  
 *    tracestring:  the string for the trace file 
 *    Return: the value of the coded syntax element 
 *     
 ************************************************************************ 
 */ 
int ue_v (char *tracestring) 
{ 
  SyntaxElement symbol, *sym=&symbol; 
 
  assert (currStream->streamBuffer != NULL); 
  sym->type = SE_HEADER; 
  sym->mapping = mapping_ue;   // Mapping rule 
  SYMTRACESTRING(tracestring); 
  read_VLC (sym); 
 
  return sym->value1; 
} 
 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   ue_v, reads an se(v) syntax element, the length in bits is stored in  
 *   the global UsedBits variable 
 *  \param  
 *    tracestring:  the string for the trace file 
 *    Return: the value of the coded syntax element 
 *     
 ************************************************************************ 
 */ 
int se_v (char *tracestring) 
{ 
  SyntaxElement symbol, *sym=&symbol; 
 
  assert (currStream->streamBuffer != NULL); 
  sym->type = SE_HEADER; 
  sym->mapping = mapping_se;   // Mapping rule: signed integer 
  SYMTRACESTRING(tracestring); 
  read_VLC (sym); 
 
  return sym->value1; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   :ue_v, reads an u(v) syntax element, the length in bits is stored in  
 *    the global UsedBits variable 
 *  \param  
 *    tracestring:  the string for the trace file 
 *    Return: the value of the coded syntax element 
 *     
 ************************************************************************ 
 */ 
int u_v (int LenInBits, char*tracestring) 
{ 
  SyntaxElement symbol, *sym=&symbol; 
 
  assert (currStream->streamBuffer != NULL); 
  sym->type = SE_HEADER; 
  sym->mapping = mapping_ue;   // Mapping rule 
  sym->len = LenInBits; 
  SYMTRACESTRING(tracestring); 
  read_FLC (sym); 
 
  return sym->inf; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *     mapping rule for ue(v) syntax elements 
 *  \param  
 *    lenght and info 
 *  \Return: number in the code table     
 ************************************************************************ 
 */ 
void mapping_ue(int len, int info, int *value1) 
{ 
  *value1 = (int)pow(2,(len/2))+info-1; // *value1 = (int)(2<<(len>>1))+info-1; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *     mapping rule for se(v) syntax elements 
 *  \param  
 *     lenght and info 
 *  \Return: signed mvd    
 ************************************************************************ 
 */ 
void mapping_se(int len,  int info, int *value1) 
{ 
  int n; 
  n = (int)pow(2,(len/2))+info-1; 
  *value1 = (n+1)/2; 
  if((n & 0x01)==0)                           // lsb is signed bit 
    *value1 = -*value1; 
 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   read_cbp_intra 
 ************************************************************************ 
 */ 
void read_cbp_intra(int len,int info,int *cbp) 
{ 
  extern const byte NCBP[48][2]; 
    int cbp_idx; 
  mapping_ue(len,info,&cbp_idx); 
    *cbp=NCBP[cbp_idx][0]; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   read_cbp_inter 
 ************************************************************************ 
 */ 
void read_cbp_inter(int len,int info,int *cbp) 
{ 
  extern const byte NCBP[48][2]; 
  int cbp_idx; 
  mapping_ue(len,info,&cbp_idx); 
    *cbp=NCBP[cbp_idx][1]; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   find_level 
 ************************************************************************ 
 */ 
void find_level(int sign, int *level, int run, int intra, int tableindex, int abs_level_diff) 
{ 
	const byte LEVRUN_INTRA[7][16]= // dongjie 
	{ 
		{ 4, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}, 
		{ 6, 4, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{ 6, 4, 4, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{ 8, 5, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{10, 5, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{12, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{15, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 
	}; 
	 
	const byte LEVRUN_INTER[7][16]= // dongjie 
	{ 
		{ 4, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, 
		{ 5, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}, 
		{ 5, 3, 3, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{ 6, 4, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{ 7, 4, 3, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{ 9, 5, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
		{13, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 
	}; 
	 
	if(intra) 
		*level = (abs_level_diff+LEVRUN_INTRA[tableindex][run]); 
	else 
		*level = (abs_level_diff+LEVRUN_INTER[tableindex][run]); 
	 
	if(sign == 1) 
		*level = -(*level); 
	 
} 
/*! 
 ************************************************************************ 
 *  \brief 
 *   find_level_chroma 
 ************************************************************************ 
 */ 
void find_level_chroma(int sign, int *level, int run, int tableindex, int abs_level_diff) 
{ 
 const byte LEVRUN_CHROMA[4][16]= // dongjie 
  { 
    { 6, 2, 2, 2, 1, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}, 
    { 7, 3, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}, 
    { 9, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
    {12, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 
  }; 
   
  *level = abs_level_diff +  LEVRUN_CHROMA[tableindex/*dongjie*/][run]; 
  if(sign == 1) 
    *level = -(*level); 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *    read next UVLC codeword from UVLC-partition and 
 *    map it to the corresponding syntax element 
 ************************************************************************ 
 */ 
int read_VLC(SyntaxElement *sym) 
{ 
  int frame_bitoffset = currStream->frame_bitoffset; 
  byte *buf = currStream->streamBuffer; 
  int BitstreamLengthInBytes = currStream->bitstream_length; 
 
  sym->len =  GetVLCSymbol (&(sym->inf)); 
 
  if (sym->len == -1) 
    return -1; 
 
  sym->mapping(sym->len,sym->inf,&(sym->value1)); 
 
#if TRACE 
  tracebits(sym->tracestring, sym->len, sym->inf, sym->value1); 
#endif 
 
  return 1; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *    read next UVLC codeword from UVLC-partition and 
 *    map it to the corresponding syntax element 
 ************************************************************************ 
 */ 
int read_UVLC(SyntaxElement *sym) 
{ 
  int frame_bitoffset = currStream->frame_bitoffset; 
  byte *buf = currStream->streamBuffer; 
  int BitstreamLengthInBytes = currStream->bitstream_length; 
 
  if(sym->type == SE_REFFRAME) 
  { 
    sym->len = 1; 
     
    if ((GetVLCSymbol_refidx(&(sym->inf))) < 0) 
      return -1; 
     
    sym->value1 = sym->inf; 
    currStream->frame_bitoffset += sym->len; 
  
	 
#if TRACE 
    tracebits3(sym->tracestring, sym->len, sym->inf, sym->value1);//sym->inf, sym->value1); 
#endif 
    
  } 
  else 
  { 
    sym->len =  GetVLCSymbol (&(sym->inf)); 
    if (sym->len == -1) 
      return -1; 
 
    sym->mapping(sym->len,sym->inf,&(sym->value1)); 
    
#if TRACE 
    tracebits(sym->tracestring, sym->len, sym->inf, sym->value1); 
#endif 
    
  } 
   
  return 1; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *   read next VLC codeword for 4x4 Intra Prediction Mode and 
 *   map it to the corresponding Intra Prediction Direction 
 ************************************************************************ 
 */ 
int read_Intra4x4PredictionMode(SyntaxElement *sym)   //qwang 2004-3-9 
{ 
  int         frame_bitoffset        = currStream->frame_bitoffset; 
  byte        *buf                   = currStream->streamBuffer; 
  int         BitstreamLengthInBytes = currStream->bitstream_length; 
  int		  value1;  //temporal varibale 
 
  sym->len = GetIntraMode (buf, frame_bitoffset, &(sym->inf), BitstreamLengthInBytes); 
 
  if (sym->len == -1) 
    return -1; 
 
  currStream->frame_bitoffset += sym->len; 
  sym->value1                  = sym->len == 1 ? -1 : sym->inf; 
 
    //add ctrl bits 
	if(sym->len == 1) 
		value1 = 0; 
	else 
	    value1 = sym->value1 + 8;   // add 
#if TRACE 
	//tracebits2(sym->tracestring, sym->len, sym->value1); 
    tracebits3(sym->tracestring, sym->len, value1,sym->value1); 
#endif 
 
 
  return 1; 
} 
 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *    
 ************************************************************************ 
 */ 
int GetIntraMode (byte buffer[],int totbitoffset,int *info, int bytecount) 
{ 
 
  register int inf; 
  long byteoffset;      // byte from start of buffer 
  int bitoffset;      // bit from start of byte 
  int ctr_bit=0;      // control bit for current bit posision 
  int bitcounter=1; 
  int len; 
  int info_bit; 
 
  byteoffset = totbitoffset/8; 
  bitoffset  = 7-(totbitoffset%8); 
  ctr_bit    = (buffer[byteoffset] & (0x01< bytecount) 
    { 
      return -1; 
    } 
    inf=(inf<<1); 
    if(buffer[byteoffset] & (0x01<<(bitoffset))) 
      inf |=1; 
  } 
 
  *info = inf; 
  return bitcounter;           // return absolute offset in bit from start of frame 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *      Moves the read pointer of the partition forward by one symbol 
 ************************************************************************ 
 */ 
int GetVLCSymbol (int *info) 
{ 
 
	register int inf; 
	long byteoffset;      // byte from start of buffer 
	int bitoffset;      // bit from start of byte 
	int ctr_bit=0;      // control bit for current bit posision 
	int bitcounter=1; 
	int len; 
	int info_bit; 
	byte *buffer = currStream->streamBuffer; 
	int bytecount = currStream->bitstream_length; 
	int totbitoffset = currStream->frame_bitoffset; 
 
	byteoffset= totbitoffset/8; 
	bitoffset= 7-(totbitoffset%8); 
	ctr_bit = (buffer[byteoffset] & (0x01< bytecount) 
		{ 
			error("parse error", -1); 
			return -1; 
		} 
		inf=(inf<<1); 
		if(buffer[byteoffset] & (0x01<<(bitoffset))) 
			inf |=1; 
	} 
 
	*info = inf; 
 
	currStream->frame_bitoffset += bitcounter; 
	return bitcounter;           // return absolute offset in bit from start of frame 
} 
/*! 
 ************************************************************************ 
 *  \brief 
 *     get one symbol but not moves the read pointer of the partition forward by one symbol 
 ************************************************************************ 
 */ 
int search_ue_code (int totbitoffset) 
{ 
	 
	register int inf; 
	long byteoffset;      // byte from start of buffer 
	int bitoffset;      // bit from start of byte 
	int ctr_bit=0;      // control bit for current bit posision 
	int bitcounter=1; 
	int len; 
	int info_bit; 
	byte *buffer = currStream->streamBuffer; 
	int bytecount = currStream->bitstream_length; 
	int symbal; 
	 
	byteoffset= totbitoffset/8; 
	bitoffset= 7-(totbitoffset%8); 
	ctr_bit = (buffer[byteoffset] & (0x01< bytecount) 
		{ 
			error("parse error", -1); 
			return -1; 
		} 
		inf=(inf<<1); 
		if(buffer[byteoffset] & (0x01<<(bitoffset))) 
			inf |=1; 
	} 
	 
	mapping_ue(bitcounter,inf,&symbal); 
	return symbal; 
} 
/*! 
 ************************************************************************ 
 *  \brief 
 *      
 ************************************************************************ 
 */ 
int GetVLCSymbol_refidx (int *info) 
{ 
   
  register int inf; 
  long byteoffset;      // byte from start of buffer 
  int bitoffset;      // bit from start of byte 
  int bitcounter=1; 
  int len; 
  int info_bit; 
  byte *buffer=currStream->streamBuffer; 
  int bytecount = currStream->bitstream_length; 
  int totbitoffset = currStream->frame_bitoffset; 
   
	byteoffset= totbitoffset/8; 
  bitoffset= 7-(totbitoffset%8); 
   
  len=1; 
  inf=0; 
   
  for(info_bit=0;(info_bit bytecount) 
    { 
      return -1; 
    } 
     
    if(buffer[byteoffset] & (0x01<<(bitoffset))) 
      inf = 1; 
     
    bitcounter++; 
    bitoffset-=1; 
  } 
   
  *info = inf; 
 
  return bitcounter;           // return absolute offset in bit from start of frame 
} 
 
extern void tracebits2(const char *trace_str,  int len,  int info) ; 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *      
 ************************************************************************ 
 */ 
int read_FLC(SyntaxElement *sym) 
{ 
  int frame_bitoffset = currStream->frame_bitoffset; 
  byte *buf = currStream->streamBuffer; 
  int BitstreamLengthInBytes = currStream->bitstream_length; 
 
  if ((GetBits(buf, frame_bitoffset, &(sym->inf), BitstreamLengthInBytes, sym->len)) < 0) 
    return -1; 
 
  currStream->frame_bitoffset += sym->len; // move bitstream pointer 
  sym->value1 = sym->inf; 
 
#if TRACE 
  tracebits2(sym->tracestring, sym->len, sym->inf); 
#endif 
 
  return 1; 
} 
 
/*! 
 ************************************************************************ 
 *  \brief 
 *     Reads bits from the bitstream buffer 
 ************************************************************************ 
 */ 
int GetBits (byte buffer[],int totbitoffset,int *info, int bytecount,  
             int numbits) 
{ 
  register int inf; 
  long byteoffset;      // byte from start of buffer 
  int bitoffset;      // bit from start of byte 
 
  int bitcounter=numbits; 
 
  byteoffset= totbitoffset/8; 
  bitoffset= 7-(totbitoffset%8); 
 
  inf=0; 
  while (numbits) 
  { 
    inf <<=1; 
    inf |= (buffer[byteoffset] & (0x01<>bitoffset; 
    numbits--; 
    bitoffset--; 
    if (bitoffset < 0) 
    { 
      byteoffset++; 
      bitoffset += 8; 
      if (byteoffset > bytecount) 
      { 
        return -1; 
      } 
    } 
  } 
 
  *info = inf; 
 
  return bitcounter;           // return absolute offset in bit from start of frame 
}       
 
/*! 
 ************************************************************************ 
 *  \brief 
 *     Read coefficients of one 4x4 block 
 ************************************************************************ 
 */ 
void readLumaCoeff_4x4_UVLC(int b8, int b4)  
{ 
  int mb_nr          = pgImage->current_mb_nr; 
  SyntaxElement currSE; 
  int ipos; 
  int run, level; 
  int ii,jj,k,i; 
  int boff_x, boff_y; 
  int symbol2D,Golomb_se_type; 
  int intra,vlc_numcoef,buffer_level[17],buffer_run[17],abslevel; 
  int tableindex; 
	// dongjie 
  const char (*table2D)[16],(*table2D_inter)[14]; 
  const char eob_intra[7]={-1,0,0,0,0,0,0};   //MA.Zhan	 
   
  //const char eob_intra[7]={-1,0,2,0,0,0,0}; 
	int incLevel_intra[7]={0,1,2,3,4,6,3000},incRun_intra[7]={-1,3,17,17,17,17,17}; 
	int incLevel_inter[7]={0,1,1,2,3,5,3000},incRun_inter[7]={-1,3,6,17,17,17,17}; 
	 
  //!< used for table switch 
  int level1_inter[16]={1,1,1,1,2,2,2,3,3,3,3,3,3,3,3,3}; 
	int level1_intra[16]={1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2}; 
	// end 
 
  intra          = IS_INTRA(pgcurrMB); 
  Golomb_se_type = SE_LUM_AC_INTER; 
 
  boff_x = (((b8 &1)<<3) + ((b4 &1)<<2)); 
  boff_y = (((b8>>1)<<3) + ((b4>>1)<<2)); 
 
	tableindex = 0;   // table index initialization 
 
  //!=0) 
          { 
						if(i==0) 
						{ 
							VLC_INTRA_dec[i][ipos][0]=level+1; 
							VLC_INTRA_dec[i][ipos][1]=run; 
							 
							VLC_INTRA_dec[i][ipos+1][0]=-(level+1); 
							VLC_INTRA_dec[i][ipos+1][1]=run; 
						} 
						else 
						{ 
							VLC_INTRA_dec[i][ipos][0]=level; 
							VLC_INTRA_dec[i][ipos][1]=run;               
							if(level) 
							{ 
								VLC_INTRA_dec[i][ipos+1][0]=-(level); 
								VLC_INTRA_dec[i][ipos+1][1]=run; 
							} 
						} 
          } 
        } 
    } 
    assert(VLC_INTRA_dec[0][0][1]>=0);        //otherwise, tables are bad. 
  } 
 
  //make decoder table for VLC_INTER code 
	if(VLC_INTER_dec[0][0][1]<0)                                                          // Don't need to set this every time. rewrite later. 
	{ 
		memset(VLC_INTER_dec,-1,sizeof(VLC_INTER_dec)); 
		for(i=0;i<7;i++) 
		{ 
			table2D_inter=VLC_INTER[i]; 
			for(run=0;run<16;run++) 
				for(level=0;level<14;level++) 
				{ 
					ipos=table2D_inter[run][level]; 
					assert(ipos<40); 
					if(ipos>=0) 
					{ 
						if(i==0) 
						{ 
							VLC_INTER_dec[i][ipos][0]=level+1; 
							VLC_INTER_dec[i][ipos][1]=run; 
							 
							VLC_INTER_dec[i][ipos+1][0]=-(level+1); 
							VLC_INTER_dec[i][ipos+1][1]=run; 
						} 
						else 
						{ 
							VLC_INTER_dec[i][ipos][0]=level; 
							VLC_INTER_dec[i][ipos][1]=run;               
							if(level) 
							{ 
								VLC_INTER_dec[i][ipos+1][0]=-(level); 
								VLC_INTER_dec[i][ipos+1][1]=run; 
							} 
						} 
					} 
				} 
		} 
		assert(VLC_INTER_dec[0][0][1]>=0);        //otherwise, tables are bad. 
	} 
 
  ipos  = -1; 
  level = 1;  // get inside loop 
 
	if(intra) 
	{ 
		int previousRunCnt = 0; // added by PSL 20041228 
 
		for(k=0; k<17; k++) 
		{ 
			currSE.type = Golomb_se_type; 
			currSE.golomb_grad = VLC_GC_Order_INTRA[tableindex][0];          
  		currSE.golomb_maxlevels = VLC_GC_Order_INTRA[tableindex][1]; 
       
			read_GOLOMB(&currSE); 
			symbol2D = currSE.value1; // 
			 
			if(symbol2D==eob_intra[tableindex])       
			{ 
				vlc_numcoef = k; 
				break; 
			} 
			 
			if(symbol2D < CODE2D_ESCAPE_SYMBOL) 
			{ 
				level = VLC_INTRA_dec[tableindex][symbol2D][0];    
				run   = VLC_INTRA_dec[tableindex][symbol2D][1];    
			} 
			else 
			{ 
 
				// commented by PSL 20041228 
				//symbol2D_levrun(&level, &run, intra, tableindex, symbol2D); 
				// added by PSL 20041228 
				int abs_lev_diff; 
				int sign; 
				 
				if(symbol2D<71) 
				{					 
					sign = symbol2D&0x1;//MAZHAN for "sign" 
					run = ((symbol2D-39)%32)/2;					 
					abs_lev_diff = 1; 
				} 
				else 
				{ 
					abs_lev_diff = (symbol2D -71)/2+2; 
					sign = symbol2D&0x1;//MAZHAN for "sign" 
					currSE.type = Golomb_se_type; 
					currSE.golomb_grad = 0;          
					currSE.golomb_maxlevels = VLC_GC_Order_INTRA[tableindex][1];     
					read_GOLOMB(&currSE); 
					symbol2D = currSE.value1; 
					run = symbol2D; 
				} 
				find_level(sign, &level, run, intra, tableindex, abs_lev_diff); 
 
			} 
 
#if TRACE  //transferred before table switch 
     snprintf(currSE.tracestring, TRACESTRING_SIZE, "%s (run, level) (%d,%3d) k=%d vlc=%d ", 
             "LUMA4x4_INTRA" ,run, level, VLC_GC_Order_INTRA[tableindex][0], tableindex); 
		 tracebits(currSE.tracestring,currSE.len,currSE.inf,currSE.value1); 
		  
		 fflush(p_trace); 
 
#endif 
       
      // added by PSL 20041228 
			previousRunCnt += run+1; 
			buffer_level[k] = level; 
			buffer_run[k]   = run; 
			abslevel = abs(level); 
 
       
      if(abslevel>=incLevel_intra[tableindex]) 
			{ 
				if(abslevel == 1) 
          tableindex = (run>incRun_intra[tableindex])?level1_intra[run]:tableindex; //Zhan MA 070705 
				else if(abslevel < 4) 
					tableindex = (abslevel+1); 
				else if(abslevel < 6) 
					tableindex = 5; 
				else 
					tableindex = 6; 
     	} 
 
  
      // added by PSL 20041228 
			if (previousRunCnt==16) 
			{ 
				vlc_numcoef = k+1; 
				break; 
			} 
 
 
 
		}//loop for k 
 
		ipos  = -1; 
		for(i=(vlc_numcoef-1); i>=0; i--) 
		{ 
			ipos += (buffer_run[i]+1);           
			ii = SCAN[ipos][0]; 
			jj = SCAN[ipos][1]; 
			pgImage->m7[boff_x + ii][boff_y + jj] = buffer_level[i]; 
		} 
	} 
	else 
	{ 
		int previousRunCnt = 0; // added by PSL 20041228 
		for(k=0; k<17; k++) 
		{ 
			currSE.type = Golomb_se_type; 
			currSE.golomb_grad = VLC_GC_Order_INTER[tableindex][0];          
			currSE.golomb_maxlevels = VLC_GC_Order_INTER[tableindex][1];     
			read_GOLOMB(&currSE); 
			symbol2D = currSE.value1;  
			 
			if((symbol2D==0)&&(tableindex!=0))       
			{ 
				vlc_numcoef = k; 
				break; 
			} 
			 
			if(symbol2D < CODE2D_ESCAPE_SYMBOL) 
			{ 
				level = VLC_INTER_dec[tableindex][symbol2D][0];    
				run   = VLC_INTER_dec[tableindex][symbol2D][1];    
			} 
			else 
			{ 
 
				// commented by PSL 20041228 
				//symbol2D_levrun(&level, &run, intra, tableindex, symbol2D); 
				// added by PSL 20041228 
				int abs_lev_diff; 
				int sign; 
				 
				if(symbol2D<71) 
				{					 
					sign = symbol2D&0x1;//MAZHAN for "sign" 
					run = ((symbol2D-39)%32)/2;					 
					abs_lev_diff = 1; 
				} 
				else 
				{ 
					abs_lev_diff = (symbol2D -71)/2+2; 
					sign = symbol2D&0x1;//MAZHAN for "sign" 
					currSE.type = Golomb_se_type; 
					currSE.golomb_grad = 0;          
					currSE.golomb_maxlevels = VLC_GC_Order_INTER[tableindex][1];     
					read_GOLOMB(&currSE);   
					symbol2D = currSE.value1; 
					run = symbol2D; 
				} 
 
				find_level(sign, &level, run, intra, tableindex, abs_lev_diff); 
			} 
 
#if TRACE  //transferred before table switch 
		 snprintf(currSE.tracestring,TRACESTRING_SIZE, "%s (run, level) (%d,%3d) k=%d vlc=%d ", 
            "LUMA4x4_INTER", run, level, VLC_GC_Order_INTER[tableindex][0], tableindex); 
		  
     tracebits(currSE.tracestring,currSE.len,currSE.inf,currSE.value1); 
		 fflush(p_trace); 
#endif 
			 // added by PSL 20041228 
			previousRunCnt += run+1; 
			buffer_level[k] = level; 
			buffer_run[k]   = run; 
 
			abslevel = abs(level);  //!< checked by Zhan Ma 
 
			if(abslevel>=incLevel_inter[tableindex]) 
			{ 
				if(abslevel == 1) 
        	tableindex = (run>incRun_inter[tableindex])?level1_inter[run]:tableindex; 
        else if(abslevel == 2) 
					tableindex = 4; 
				else if(abslevel <= 4) 
					tableindex = 5; 
				else 
					tableindex = 6; 
			} 
 
			// added by PSL 20041228 
			if (previousRunCnt==16) 
			{ 
				vlc_numcoef = k+1; 
				break; 
			} 
 
		}//loop for k 
		ipos  = -1; 
		for(i=(vlc_numcoef-1); i>=0; i--) 
		{ 
			ipos += (buffer_run[i]+1);           
			ii = SCAN[ipos][0]; 
			jj = SCAN[ipos][1]; 
			pgImage->m7[boff_x + ii][boff_y + jj] = buffer_level[i]; 
		} 
	} 
} 
/*! 
 ************************************************************************ 
 *  \brief 
 *     read chroma coefficents 
 ************************************************************************ 
 */ 
void readChromaCoeff_4x4_UVLC(int b8, int b4)    //qwang 2004-4-27 
{ 
  int mb_nr          = pgImage->current_mb_nr; 
  SyntaxElement currSE; 
  int ipos; 
  int run, level; 
  int ii,jj,k,tableindex,i,vlc_numcoef; 
  int boff_x, boff_y; 
  int symbol2D,Golomb_se_type; 
  int buffer_level[16], buffer_run[16],abslevel; 
  const char (*table2D)[13]; 
   
  int previousRunCnt = 0; // added by PSL 20041228	 
	int incLevel_chroma[4]={0,1,2,3000}; // dongjie 
 
  boff_x = ((b4 &1)<<2); 
  boff_y = ((b4>>1)<<2); 
 
  Golomb_se_type=SE_LUM_AC_INTER; 
  //make decoder table for VLC_CHROMA code 
  if(VLC_CHROMA_dec[0][0][1]<0)                                                          // Don't need to set this every time. rewrite later. 
  { 
    memset(VLC_CHROMA_dec,-1,sizeof(VLC_CHROMA_dec)); 
		for(i=0;i<4;i++) 
		{ 
      table2D=VLC_CHROMA[i]; 
      for(run=0;run<16;run++) 
        for(level=0;level<13;level++) 
        { 
          ipos=table2D[run][level]; 
          assert(ipos<40); 
          if(ipos>=0) 
          {						 
						if(i==0) 
						{ 
							VLC_CHROMA_dec[i][ipos][0]=level+1; 
							VLC_CHROMA_dec[i][ipos][1]=run; 
							 
							VLC_CHROMA_dec[i][ipos+1][0]=-(level+1); 
							VLC_CHROMA_dec[i][ipos+1][1]=run; 
						} 
						else 
						{ 
							VLC_CHROMA_dec[i][ipos][0]=level; 
							VLC_CHROMA_dec[i][ipos][1]=run;               
							if(level) 
							{ 
								VLC_CHROMA_dec[i][ipos+1][0]=-(level); 
								VLC_CHROMA_dec[i][ipos+1][1]=run; 
							} 
						} 
 
          } 
        } 
		} 
    assert(VLC_CHROMA_dec[0][1]>=0);        //otherwise, tables are bad. 
  } 
 
  ipos  = -1; 
  level=1;                        // get inside loop 
	tableindex = 0; 
	for(k=0; k<17; k++) 
	{ 
		currSE.type = Golomb_se_type; 
		currSE.golomb_grad = VLC_GC_Order_CHROMA[tableindex][0];          
		currSE.golomb_maxlevels = VLC_GC_Order_CHROMA[tableindex][1];     
		read_GOLOMB(&currSE); 
		symbol2D = currSE.value1;  
		 
		if((symbol2D==0)&&(tableindex!=0))       
		{ 
			vlc_numcoef = k; 
			break; 
		} 
		 
		if(symbol2D < CODE2D_ESCAPE_SYMBOL) 
		{ 
			level = VLC_CHROMA_dec[tableindex][symbol2D][0];    
			run   = VLC_CHROMA_dec[tableindex][symbol2D][1];    
		} 
		else 
		{ 
			// commented by PSL 20041228 
			//symbol2D_levrun_chroma(&level, &run, symbol2D, tableindex); 
			// added by PSL 20041228 
			int abs_lev_diff; 
			int sign; 
			 
			if(symbol2D<32+39) 
			{				 
				sign = symbol2D&0x1; //MAZHAN for "sign" 
				run = ((symbol2D-39)%32)/2;				 
				abs_lev_diff = 1; 
			} 
			else 
			{ 
				abs_lev_diff = (symbol2D -39-32)/2+2; 
				sign = symbol2D&0x1;//MAZHAN for "sign" 
				 currSE.type = Golomb_se_type; 
				currSE.golomb_grad = 0;          
				currSE.golomb_maxlevels = VLC_GC_Order_CHROMA[tableindex][1];     
				read_GOLOMB(&currSE); 
				symbol2D = currSE.value1; 
				run = symbol2D; 
			} 
			find_level_chroma(sign, &level, run, tableindex, abs_lev_diff); 
		} 
 
#if TRACE  //transferred before table swich 
		 snprintf(currSE.tracestring, TRACESTRING_SIZE, "%s (run, level) (%d,%3d) k=%d vlc=%d ", 
             "CHR4x4",run, level, VLC_GC_Order_CHROMA[tableindex][0], tableindex); 
		 tracebits(currSE.tracestring,currSE.len,currSE.inf,currSE.value1); 
		 fflush(p_trace); 
 
#endif 
 
		// added by PSL 20041228 
		previousRunCnt += run+1; 
		buffer_level[k] = level; 
		buffer_run[k]   = run; 
		abslevel = abs(level); 
 
		if(abslevel>incLevel_chroma[tableindex]) 
		{ 
			if(abslevel<3) 
				tableindex = abslevel; 
			else 
				tableindex = 3; 
		} 
		// added by PSL 20041228 
		if (previousRunCnt==16) 
		{ 
			vlc_numcoef = k+1; 
			break; 
		} 
 
	}//loop for k 
	 
		ipos  = -1; 
		for(i=(vlc_numcoef-1); i>=0; i--) 
		{ 
			ipos += (buffer_run[i]+1);           
			ii = SCAN[ipos][0]; 
			jj = SCAN[ipos][1]; 
			pgImage->m8[b8-4][boff_x + ii][boff_y + jj] = buffer_level[i]; 
		} 
} 
// end 
 
 
#if TRACE 
/*! 
 ************************************************************************ 
 *  \brief 
 *      
 ************************************************************************ 
 */ 
void encode_golomb_word(unsigned int symbol,unsigned int grad0,unsigned int max_levels,unsigned int *res_bits,unsigned int *res_len) 
{ 
  unsigned int level,res,numbits; 
  res=1UL<=res && level=max_levels) 
  { 
    if(symbol>=res) 
      symbol=res-1UL;  //crop if too large. 
  } 
  //set data bits 
  *res_bits=res|symbol; 
  *res_len=numbits; 
} 
/*! 
 ************************************************************************ 
 *  \brief 
 *      
 ************************************************************************ 
 */ 
void encode_multilayer_golomb_word(unsigned int symbol,const unsigned int *grad,const unsigned int *max_levels,unsigned int *res_bits,unsigned int *res_len) 
{ 
  unsigned accbits,acclen,bits,len,tmp; 
  accbits=acclen=0UL; 
  while(1) 
  { 
    encode_golomb_word(symbol,*grad,*max_levels,&bits,&len); 
    accbits=(accbits<>bit)&1UL) ; 
    bit = (bit-1UL) & 7UL ; 
    if(bit==7UL)byte=*(++rd); 
  } 
  *buffer=rd; 
  *bitoff=bit; 
 
  return (((1UL<frame_bitoffset; 
  buf = (unsigned char*)currStream->streamBuffer; 
  BitstreamLengthInBytes = currStream->bitstream_length; 
   
  bit=7UL-(frame_bitoffset&7); 
  read=buf+(frame_bitoffset>>3); 
   
  if(!( se->golomb_maxlevels&~0xFF )) 
  { 
    se->value1=decode_golomb_word(&read,&bit,se->golomb_grad,se->golomb_maxlevels); 
  } 
  else 
  { 
    for(i=0UL;i<4UL;i++) 
    { 
      grad[i]=(se->golomb_grad>>(i<<3))&0xFFUL; 
      max_lev[i]=(se->golomb_maxlevels>>(i<<3))&0xFFUL; 
    } 
    se->value1=decode_multilayer_golomb_word(&read,&bit,grad,max_lev); 
  } 
   
  se->len=(((read-buf)<<3)+(7-bit))-frame_bitoffset; 
   
#if TRACE 
  if(!( se->golomb_maxlevels&~0xFF ))    //only bits 0-7 used? This means normal Golomb word. 
    encode_golomb_word(se->value1,se->golomb_grad,se->golomb_maxlevels,&(se->value2),&len); 
  else 
  { 
    for(i=0UL;i<4UL;i++) 
    { 
      grad[i]=(se->golomb_grad>>(i<<3))&0xFFUL; 
      max_lev[i]=(se->golomb_maxlevels>>(i<<3))&0xFFUL; 
    } 
    encode_multilayer_golomb_word(se->value1,grad,max_lev,&(se->value2),&len); 
  } 
 
#endif 
 
  se->value2=0; 
  currStream->frame_bitoffset += se->len; 
   
  return 1; 
}