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

📄 vlc.cc

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CC
📖 第 1 页 / 共 3 页
字号:
/********************************************************************************    Copyright (C) 1999  Dirk Farin    This program is distributed under GNU Public License (GPL) as    outlined in the COPYING file that comes with the source distribution.    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA ********************************************************************************//* NOTE: do not compile this file. It is included inline into vdecoder.cc. */#include "libvideogfx/utility/bitstream/fastbitbuf.hh"#include "video12/vlc.hh"#include "types.hh"#include "error.hh"#define maybeinline inlinestruct DirectVLCTableEntry{  short bits; int nBits;};struct DirectVLC{  int    value;  uint16 bits;};/************************************* MB-INCR ********************************/static DirectVLCTableEntry vlc_mbaddrinc_tab[] ={  {0x08,11}, // ESCAPE-CODE  /* table taken from MSSG-encoder */  {0x01,1},  {0x03,3},  {0x02,3},  {0x03,4},  {0x02,4},  {0x03,5},  {0x02,5},  {0x07,7},  {0x06,7},  {0x0b,8},  {0x0a,8},  {0x09,8},  {0x08,8},  {0x07,8},  {0x06,8},  {0x17,10},  {0x16,10}, {0x15,10}, {0x14,10}, {0x13,10},   {0x12,10}, {0x23,11}, {0x22,11}, {0x21,11},  {0x20,11}, {0x1f,11}, {0x1e,11}, {0x1d,11},  {0x1c,11}, {0x1b,11}, {0x1a,11}, {0x19,11},  {0x18,11}, {0,-1}};#include <iostream.h>#include <iomanip.h>static DirectVLC vlc_mbaddr[2048 /*2^11*/];struct MBAtab{  uint8 mba,len;};static MBAtab MBA_5 [] = {                    {7, 5}, {6, 5}, {5, 4}, {5, 4}, {4, 4}, {4, 4},    {3, 3}, {3, 3}, {3, 3}, {3, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},    {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1},    {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}};static MBAtab MBA_11 [] = {    {33, 11}, {32, 11}, {31, 11}, {30, 11},    {29, 11}, {28, 11}, {27, 11}, {26, 11},    {25, 11}, {24, 11}, {23, 11}, {22, 11},    {21, 10}, {21, 10}, {20, 10}, {20, 10},    {19, 10}, {19, 10}, {18, 10}, {18, 10},    {17, 10}, {17, 10}, {16, 10}, {16, 10},    {15,  8}, {15,  8}, {15,  8}, {15,  8},    {15,  8}, {15,  8}, {15,  8}, {15,  8},    {14,  8}, {14,  8}, {14,  8}, {14,  8},    {14,  8}, {14,  8}, {14,  8}, {14,  8},    {13,  8}, {13,  8}, {13,  8}, {13,  8},    {13,  8}, {13,  8}, {13,  8}, {13,  8},    {12,  8}, {12,  8}, {12,  8}, {12,  8},    {12,  8}, {12,  8}, {12,  8}, {12,  8},    {11,  8}, {11,  8}, {11,  8}, {11,  8},    {11,  8}, {11,  8}, {11,  8}, {11,  8},    {10,  8}, {10,  8}, {10,  8}, {10,  8},    {10,  8}, {10,  8}, {10,  8}, {10,  8},    { 9,  7}, { 9,  7}, { 9,  7}, { 9,  7},    { 9,  7}, { 9,  7}, { 9,  7}, { 9,  7},    { 9,  7}, { 9,  7}, { 9,  7}, { 9,  7},    { 9,  7}, { 9,  7}, { 9,  7}, { 9,  7},    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7}};maybeinline int GetMBAddrIncr(class FastBitBuf& bs){#if 1  MBAtab * tab;  int mba;  mba = 0;  bs.Fill16Bits();  while (1) {    if (bs.Peek16BitsMSB() >= 0x10000000) {      tab = MBA_5 - 2 + bs.PeekBitsFast(5);      bs.SkipBitsFast(tab->len);      return mba + tab->mba;    } else if (bs.Peek16BitsMSB() >= 0x03000000) {      tab = MBA_11 - 24 + bs.PeekBitsFast(11);      bs.SkipBitsFast(tab->len);      return mba + tab->mba;    } else      {	switch (bs.PeekBits(11)) {	case 8:         // macroblock_escape	  mba += 33;	  // no break here on purpose	case 15:        // macroblock_stuffing (MPEG1 only)	  bs.SkipBitsFast(11);	  bs.Fill16Bits();	  break;	default:        // end of slice, or error	  cout << "GetMBAddrIncr-ERROR\n";	  throw Excpt_Huffman(ErrSev_Warning,"Invalid MPEG stream, not existing MB-addr-incr. read. (1)");	  return 0;	}      }  }#else  uint16 code = bs.PeekBits(11);  int val = vlc_mbaddr[code].value;  bs.SkipBits(vlc_mbaddr[code].bits);  if (val<0)    throw Excpt_Huffman(ErrSev_Warning,"Invalid MPEG stream, not existing MB-addr-incr. read. (1)");  if (val!=0) return val;  int val1=33; loop:  code = bs.PeekBits(11);  val = vlc_mbaddr[code].value;  bs.SkipBits(vlc_mbaddr[code].bits);  if (val<0)    throw Excpt_Huffman(ErrSev_Warning,"Invalid MPEG stream, not existing MB-addr-incr. read. (2)");  if (val!=0) return val+val1;  else        { val1 += 33; goto loop; }#endif}/************************************* MB-MODE ********************************/static DirectVLCTableEntry vlc_mbmode_P_tab[] ={  {0,0}, {3,5}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},  {1,3}, {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},  {0,0}, {1,6}, {1,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},  {0,0}, {0,0}, {2,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,-1}};static DirectVLCTableEntry vlc_mbmode_B_tab[] ={  {0,0}, {3,5}, {0,0}, {0,0}, {2,3}, {0,0}, {3,3}, {0,0},  {2,4}, {0,0}, {3,4}, {0,0}, {2,2}, {0,0}, {3,2}, {0,0},  {0,0}, {1,6}, {0,0}, {0,0}, {0,0}, {0,0}, {2,6}, {0,0},  {0,0}, {0,0}, {3,6}, {0,0}, {0,0}, {0,0}, {2,5}, {0,0}, {0,-1}};static DirectVLC vlc_mbmode_P[64 /*2^6*/];static DirectVLC vlc_mbmode_B[64 /*2^6*/];static int GetMBMode_I(class FastBitBuf& bs){  int code = bs.PeekBits(2);  if (code & 2)    {      bs.SkipBitsFast(1);      return 1;    }  else    {      if (code!=1)        throw Excpt_Huffman(ErrSev_Warning,"Invalid MPEG stream, not existing MB-class (I-picture) read.");      bs.SkipBitsFast(2);      return 17;    }}static int GetMBMode_P(class FastBitBuf& bs){  uint16 code = bs.PeekBits(6);  bs.SkipBits(vlc_mbmode_P[code].bits);  if (vlc_mbmode_P[code].value==0)    throw Excpt_Huffman(ErrSev_Warning,"Invalid MPEG stream, not existing MB-class (P-picture) read.");  return vlc_mbmode_P[code].value;}static int GetMBMode_B(class FastBitBuf& bs){  uint16 code = bs.PeekBits(6);  bs.SkipBitsFast(vlc_mbmode_B[code].bits);  if (vlc_mbmode_B[code].value==0)    {      //cerr << "CODEVAL: $" << hex << code << " 6 bits " << endl;      throw Excpt_Huffman(ErrSev_Warning,"Invalid MPEG stream, not existing MB-class (B-picture) read.");    }  return vlc_mbmode_B[code].value;}static int GetMBMode_D(class FastBitBuf& bs){  int c = bs.GetBits(1);  if (c != 1)    {      throw Excpt_Huffman(ErrSev_Error,"Invalid MPEG stream, invalid MB-mode in D-picture read.");    }  return MBMODE_INTRA;}static int (* GetMBMode[5])(class FastBitBuf&) ={  NULL,  GetMBMode_I,  GetMBMode_P,  GetMBMode_B,  GetMBMode_D};/************************************* MotionCode ********************************/static DirectVLCTableEntry vlc_mcode_tab[]={  /* table taken from MSSG-encoder */  {0x01,1},  {0x01,2},  {0x01,3},  {0x01,4},  {0x03,6},  {0x05,7},  {0x04,7},  {0x03,7},  {0x0b,9},  {0x0a,9},  {0x09,9},  {0x11,10},  {0x10,10}, {0x0f,10}, {0x0e,10}, {0x0d,10},  {0x0c,10}, {0,-1}};static DirectVLC vlc_mc[1024 /*2^10*/];maybeinline int GetMotionCode(class FastBitBuf& bs){  uint16 code = bs.PeekBits(10);  bs.SkipBitsFast(vlc_mc[code].bits);  if (vlc_mc[code].value==0)    return 0;  if (bs.GetBits(1)==0)    return  vlc_mc[code].value;  else    return -vlc_mc[code].value;}/************************************* CBP ********************************/static DirectVLCTableEntry vlc_cbp_tab[]={  /* table taken from MSSG-encoder */  {0x01,9}, {0x0b,5}, {0x09,5}, {0x0d,6},   {0x0d,4}, {0x17,7}, {0x13,7}, {0x1f,8},   {0x0c,4}, {0x16,7}, {0x12,7}, {0x1e,8},   {0x13,5}, {0x1b,8}, {0x17,8}, {0x13,8},   {0x0b,4}, {0x15,7}, {0x11,7}, {0x1d,8},   {0x11,5}, {0x19,8}, {0x15,8}, {0x11,8},   {0x0f,6}, {0x0f,8}, {0x0d,8}, {0x03,9},   {0x0f,5}, {0x0b,8}, {0x07,8}, {0x07,9},   {0x0a,4}, {0x14,7}, {0x10,7}, {0x1c,8},   {0x0e,6}, {0x0e,8}, {0x0c,8}, {0x02,9},   {0x10,5}, {0x18,8}, {0x14,8}, {0x10,8},   {0x0e,5}, {0x0a,8}, {0x06,8}, {0x06,9},   {0x12,5}, {0x1a,8}, {0x16,8}, {0x12,8},   {0x0d,5}, {0x09,8}, {0x05,8}, {0x05,9},   {0x0c,5}, {0x08,8}, {0x04,8}, {0x04,9},  {0x07,3}, {0x0a,5}, {0x08,5}, {0x0c,6}, {0,-1}};static DirectVLC vlc_cbp[512 /*2^9*/];maybeinline int GetCBP(class FastBitBuf& bs){  uint16 code = bs.PeekBits(9);  bs.SkipBitsFast(vlc_cbp[code].bits);  return vlc_cbp[code].value;}/************************************* Initialization ********************************/static DirectVLCTableEntry vlc_DClum_tab[]={  /* table taken from MSSG-encoder */  {0x0004,3}, {0x0000,2}, {0x0001,2}, {0x0005,3}, {0x0006,3}, {0x000e,4},  {0x001e,5}, {0x003e,6}, {0x007e,7}, {0x00fe,8}, {0x01fe,9}, {0x01ff,9}, {0,-1}};static DirectVLCTableEntry vlc_DCchrom_tab[]={  /* table taken from MSSG-encoder */  {0x0000,2}, {0x0001,2}, {0x0002,2}, {0x0006,3}, {0x000e,4}, {0x001e,5},  {0x003e,6}, {0x007e,7}, {0x00fe,8}, {0x01fe,9}, {0x03fe,10},{0x03ff,10}, {0,-1}};static DirectVLC vlc_DClum  [1<< 9];static DirectVLC vlc_DCchrom[1<<10];maybeinline int GetDClumSize(class FastBitBuf& bs){  uint16 code = bs.PeekBits(9);  bs.SkipBitsFast(vlc_DClum[code].bits);  return vlc_DClum[code].value;}maybeinline int GetDCchromSize(class FastBitBuf& bs){  uint16 code = bs.PeekBits(10);  bs.SkipBitsFast(vlc_DCchrom[code].bits);  return vlc_DCchrom[code].value;}typedef struct {    uint8 size;    uint8 len;} DCtab;static DCtab DC_lum_5 [] = {    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},    {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},    {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}};static DCtab DC_long [] = {    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},    {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, { 7, 6}, { 7, 6},    {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9}};static DCtab DC_lum_7 [] = {    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},    {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3},    {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3},    {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},    {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},    {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3},    {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3},    {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4},    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {7, 6}, {7, 6}, {8, 7}};#if 0static inline int get_luma_dc_dct_diff (FastBitBuf& bs){  bs.Fill16Bits();#define bit_buf bs.d_buffer#define bits bs.d_freebits  DCtab * tab;  int size;  int dc_diff;  if (bit_buf < 0xf8000000) {    /* Max. codelength = 5 + max. size = 6  <= 16 , no refill needed. */    tab = DC_lum_5 + UBITS (bit_buf, 5);    size = tab->size;    if (size) {      bits += tab->len + size;      bit_buf <<= tab->len;      dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);      bit_buf <<= size;      return dc_diff;    } else {      DUMPBITS (bit_buf, bits, 3);      return 0;    }  } else {    tab = DC_long - 0x1e0 + UBITS (bit_buf, 9);    size = tab->size;    if (size>=9)      {	DUMPBITS(bit_buf,bits,tab->len);	bs.Fill16Bits();	dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);	DUMPBITS(bit_buf,bits,size);      }    else      {	bits += tab->len+size;	bit_buf <<= tab->len;	dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);	bit_buf <<= size;      }    return dc_diff;  }#undef bit_buf#undef bits}#endif#if 1static inline int get_luma_dc_dct_diff (FastBitBuf& bs){  bs.Fill16Bits();#define bit_buf bs.d_buffer#define bits bs.d_freebits  DCtab * tab;  int size;  int dc_diff;  if (bit_buf < 0xfe000000) {    /* Max. codelength = 7 + max. size = 8  <= 15 , no refill needed. */    tab = DC_lum_7 + UBITS (bit_buf, 7);    size = tab->size;    if (size) {      bits += tab->len + size;      bit_buf <<= tab->len;      dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);      bit_buf <<= size;      return dc_diff;    } else {      DUMPBITS (bit_buf, bits, 3);      return 0;    }  } else {    tab = DC_long - 0x1e0 + UBITS (bit_buf, 9);    size = tab->size;    DUMPBITS(bit_buf,bits,tab->len);    bs.Fill16Bits();    dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);

⌨️ 快捷键说明

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