[cvs] / xvidcore / src / bitstream / vlc_codes.h Repository:
ViewVC logotype

Diff of /xvidcore/src/bitstream/vlc_codes.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Fri Mar 8 02:44:38 2002 UTC revision 1.5, Wed Apr 10 07:43:20 2002 UTC
# Line 2  Line 2 
2  #define _VLC_CODES_H_  #define _VLC_CODES_H_
3    
4  #include "../portab.h"  #include "../portab.h"
5    #include "mbcoding.h"
6    
7  #define VLC_ERROR       (-1)  #define VLC_ERROR       (-1)
8    #define ESCAPE 7167
9    
10  typedef struct  typedef struct
11  {  {
# Line 11  Line 13 
13          int8_t len;          int8_t len;
14  } VLC;  } VLC;
15    
16    static VLC *DCT3D[2];
17    
18    
19  /******************************************************************  /******************************************************************
20  /* common tables between encoder/decoder                          *   * common tables between encoder/decoder                          *
21  /******************************************************************/   ******************************************************************/
22    
23  /* constants taken from momusys/vm_common/inlcude/max_level.h */  /* constants taken from momusys/vm_common/inlcude/max_level.h */
24  static char max_level[4][64] = {  static char max_level[4][64] = {
# Line 207  Line 211 
211    
212    
213  /******************************************************************  /******************************************************************
214  /* encoder tables                                                 *   * encoder tables                                                 *
215  /******************************************************************/   ******************************************************************/
216    
217  /* DCT coefficients. Four tables, two for last = 0, two for last = 1.  /* DCT coefficients. Four tables, two for last = 0, two for last = 1.
218     the sign bit must be added afterwards. */     the sign bit must be added afterwards. */
# Line 343  Line 347 
347  /* rest of coeffs for last = 1. indexing by [run-2] */  /* rest of coeffs for last = 1. indexing by [run-2] */
348    
349  static VLC coeff_tab3[40][1] = {  static VLC coeff_tab3[40][1] = {
350      {0x0e, 6}, {0x0d, 6}, {0x0c, 6},          {{0x0e, 6}},  {{0x0d, 6}},  {{0x0c, 6}},
351      {0x13, 7}, {0x12, 7}, {0x11, 7}, {0x10, 7},          {{0x13, 7}},  {{0x12, 7}},  {{0x11, 7}},  {{0x10, 7}},
352      {0x1a, 8}, {0x19, 8}, {0x18, 8}, {0x17, 8},          {{0x1a, 8}},  {{0x19, 8}},  {{0x18, 8}},  {{0x17, 8}},
353      {0x16, 8}, {0x15, 8}, {0x14, 8}, {0x13, 8},          {{0x16, 8}},  {{0x15, 8}},  {{0x14, 8}},  {{0x13, 8}},
354      {0x18, 9}, {0x17, 9}, {0x16, 9}, {0x15, 9},          {{0x18, 9}},  {{0x17, 9}},  {{0x16, 9}},  {{0x15, 9}},
355      {0x14, 9}, {0x13, 9}, {0x12, 9}, {0x11, 9},          {{0x14, 9}},  {{0x13, 9}},  {{0x12, 9}},  {{0x11, 9}},
356      {0x07, 10}, {0x06, 10}, {0x05, 10}, {0x04, 10},          {{0x07, 10}}, {{0x06, 10}}, {{0x05, 10}}, {{0x04, 10}},
357      {0x24, 11}, {0x25, 11}, {0x26, 11}, {0x27, 11},          {{0x24, 11}}, {{0x25, 11}}, {{0x26, 11}}, {{0x27, 11}},
358      {0x58, 12}, {0x59, 12}, {0x5a, 12}, {0x5b, 12},          {{0x58, 12}}, {{0x59, 12}}, {{0x5a, 12}}, {{0x5b, 12}},
359      {0x5c, 12}, {0x5d, 12}, {0x5e, 12}, {0x5f, 12},          {{0x5c, 12}}, {{0x5d, 12}}, {{0x5e, 12}}, {{0x5f, 12}},
360      {0x00, 0}          {{0x00, 0}}
361  };  };
362    
363  /* New tables for Intra luminance coefficients. Same codewords,  /* New tables for Intra luminance coefficients. Same codewords,
# Line 446  Line 450 
450  /* Coeffs for last = 0, run = 10 -> 14. Indexed by [run-10] */  /* Coeffs for last = 0, run = 10 -> 14. Indexed by [run-10] */
451    
452  static VLC coeff_tab7[5][1] = {  static VLC coeff_tab7[5][1] = {
453      {0x17, 8}, {0x19, 9}, {0x18, 9}, {0x07, 10},          {{0x17, 8}}, {{0x19, 9}}, {{0x18, 9}}, {{0x07, 10}},
454      {0x58, 12}          {{0x58, 12}}
455  };  };
456    
457  /* Coeffs for last = 1, run = 0. Indexed by [level-1] */  /* Coeffs for last = 1, run = 0. Indexed by [level-1] */
# Line 501  Line 505 
505  /* Coeffs for last = 1, run = 7 -> 20. Indexed by [run-7] */  /* Coeffs for last = 1, run = 7 -> 20. Indexed by [run-7] */
506    
507  static VLC coeff_tab10[14][1] = {  static VLC coeff_tab10[14][1] = {
508      {0x14, 8}, {0x13, 8}, {0x1a, 8}, {0x15, 9},          {{0x14, 8}},  {{0x13, 8}}, {{0x1a, 8}}, {{0x15, 9}},
509      {0x14, 9}, {0x13, 9}, {0x12, 9}, {0x11, 9},          {{0x14, 9}},  {{0x13, 9}}, {{0x12, 9}}, {{0x11, 9}},
510      {0x26, 11}, {0x27, 11}, {0x5c, 12}, {0x5d, 12},          {{0x26, 11}}, {{0x27, 11}}, {{0x5c, 12}}, {{0x5d, 12}},
511      {0x5e, 12}, {0x5f, 12}          {{0x5e, 12}}, {{0x5f, 12}}
512  };  };
513    
514    
# Line 632  Line 636 
636          coeff_inter_last1,          coeff_inter_last1,
637  };  };
638    
639  static const VLC mcbpc_I[4] = {  /* MCBPC Indexing by cbpc in first two bits, mode in last two.
640          {1, 1}, {1, 3}, {2, 3}, {3, 3}   CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
641  };   Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */
642    
643  static const VLC mcbpc_P_intra[4] = {  static VLC mcbpc_intra_tab[15] = {
644          {3, 5}, {4, 8}, {3, 8}, {3, 7}      {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
645  };      {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0},
646        {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0},
647  static const VLC mcbpc_P_inter[4] = {      {0x00, 0}, {0x03, 3}, {0x03, 6}
648          {1, 1}, {3, 4}, {2, 4}, {5, 6}  };
649  };  
650    /* MCBPC inter.
651  static const VLC mcbpc_P_inter4v[4] = {     Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */
652          {2, 3}, {5, 7}, {4, 7}, {5, 8}  
653    static VLC mcbpc_inter_tab[29] = {
654        {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0},
655        {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0},
656        {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0},
657        {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
658  };  };
659    
660  static const VLC cbpy_tab[16] = {  static const VLC cbpy_tab[16] = {
# Line 933  Line 942 
942  {0x10, 11}, {0x0e, 11}, {0x0c, 11}, {0x0a, 11},  {0x10, 11}, {0x0e, 11}, {0x0c, 11}, {0x0a, 11},
943  {0x08, 11}, {0x0e, 12}, {0x0c, 12}, {0x0a, 12},  {0x08, 11}, {0x0e, 12}, {0x0c, 12}, {0x0a, 12},
944  {0x08, 12}, {0x06, 12}, {0x04, 12}, {0x06, 13},  {0x08, 12}, {0x06, 12}, {0x04, 12}, {0x06, 13},
945  {0x04, 13},          {0x04, 13}
946  };  };
947    
948    
949  /******************************************************************  /******************************************************************
950  /* decoder tables                                                                             *   * decoder tables                                                 *
951  /******************************************************************/   ******************************************************************/
952    
953  static const VLC mcbpc_intra_table[64] = {  static const VLC mcbpc_intra_table[64] = {
954          {-1,0},          {-1,0},
# Line 954  Line 963 
963          {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},          {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},
964          {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},          {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},
965          {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},          {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},
966          {3, 1},          {3, 1}
967  };  };
968    
969    
# Line 988  Line 997 
997          {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3},          {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3},
998          {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3},          {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3},
999          {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3},          {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3}, {1,3},
1000          {1,3}, {1,3}, {1,3}, {0,1},          {1,3}, {1,3}, {1,3}, {0,1}
1001  };  };
1002    
1003  static const VLC cbpy_table[64] =  static const VLC cbpy_table[64] =
# Line 1001  Line 1010 
1010    {11,4}, {11,4}, {11,4}, {11,4}, {7,4},  {7,4},  {7,4},  {7,4},    {11,4}, {11,4}, {11,4}, {11,4}, {7,4},  {7,4},  {7,4},  {7,4},
1011          {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},          {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},
1012          {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},          {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},
1013          {15, 2}, {15, 2},          {15, 2}, {15, 2}
1014  };  };
1015    
1016    
# Line 1062  Line 1071 
1071  {17,3}, {17,3}, {17,3}, {17,3}, {17,3}, {17,3},  {17,3}, {17,3}, {17,3}, {17,3}, {17,3}, {17,3},
1072  {33,4}, {33,4}, {33,4}, {33,4}, {33,4}, {33,4},  {33,4}, {33,4}, {33,4}, {33,4}, {33,4}, {33,4},
1073  {33,4}, {33,4}, {2,4}, {2,4},{2,4},{2,4},  {33,4}, {33,4}, {2,4}, {2,4},{2,4},{2,4},
1074  {2,4}, {2,4},{2,4},{2,4},          {2,4}, {2,4},{2,4},{2,4}
1075  };  };
1076    
1077    
# Line 1082  Line 1091 
1091  {4241,8}, {4241,8}, {4241,8}, {4241,8}, {225,8}, {225,8},  {4241,8}, {4241,8}, {4241,8}, {4241,8}, {225,8}, {225,8},
1092  {225,8}, {225,8}, {209,8}, {209,8}, {209,8}, {209,8},  {225,8}, {225,8}, {209,8}, {209,8}, {209,8}, {209,8},
1093  {34,8}, {34,8}, {34,8}, {34,8}, {19,8}, {19,8},  {34,8}, {34,8}, {34,8}, {34,8}, {19,8}, {19,8},
1094  {19,8}, {19,8}, {5,8}, {5,8}, {5,8}, {5,8},          {19,8}, {19,8}, {5,8}, {5,8}, {5,8}, {5,8}
1095  };  };
1096    
1097  VLC DCT3Dtab2[] = {  VLC DCT3Dtab2[] = {
# Line 1106  Line 1115 
1115  {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7},  {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7},
1116  {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7},  {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7},
1117  {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7},  {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7}, {7167,7},
1118  {7167,7}, };          {7167,7}
1119    };
1120    
1121    
1122  /* New tables for Intra luminance blocks */  /* New tables for Intra luminance blocks */
# Line 1139  Line 1149 
1149      {0x00101, 4}, {0x00101, 4}, {0x00101, 4}, {0x00101, 4},      {0x00101, 4}, {0x00101, 4}, {0x00101, 4}, {0x00101, 4},
1150      {0x00101, 4}, {0x00101, 4}, {0x00101, 4}, {0x00101, 4},      {0x00101, 4}, {0x00101, 4}, {0x00101, 4}, {0x00101, 4},
1151      {0x00003, 4}, {0x00003, 4}, {0x00003, 4}, {0x00003, 4},      {0x00003, 4}, {0x00003, 4}, {0x00003, 4}, {0x00003, 4},
1152      {0x00003, 4}, {0x00003, 4}, {0x00003, 4}, {0x00003, 4},          {0x00003, 4}, {0x00003, 4}, {0x00003, 4}, {0x00003, 4}
1153  };  };
1154    
1155    
# Line 1167  Line 1177 
1177      {0x00104, 8}, {0x00104, 8}, {0x00104, 8}, {0x00104, 8},      {0x00104, 8}, {0x00104, 8}, {0x00104, 8}, {0x00104, 8},
1178      {0x0000c, 8}, {0x0000c, 8}, {0x0000c, 8}, {0x0000c, 8},      {0x0000c, 8}, {0x0000c, 8}, {0x0000c, 8}, {0x0000c, 8},
1179      {0x0000b, 8}, {0x0000b, 8}, {0x0000b, 8}, {0x0000b, 8},      {0x0000b, 8}, {0x0000b, 8}, {0x0000b, 8}, {0x0000b, 8},
1180      {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8},          {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8}
1181  };  };
1182    
1183  VLC DCT3Dtab5[] = {  VLC DCT3Dtab5[] = {
# Line 1200  Line 1210 
1210      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1211      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1212      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1213      {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},          {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}
1214  };  };
1215    
1216  VLC ERRtab[] = {  VLC ERRtab[] = {
# Line 1208  Line 1218 
1218          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1219          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1220          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1221          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},          {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}
1222  };  };
1223    
1224  static const VLC dc_lum_tab[] = {  static const VLC dc_lum_tab[] = {
# Line 1217  Line 1227 
1227          {2, 2}, {2, 2}, {1, 2}, {1, 2},          {2, 2}, {2, 2}, {1, 2}, {1, 2},
1228  };  };
1229    
1230    static __inline int get_coeff(Bitstream * bs, int *run, int *last,
1231                                                              int intra, int short_video_header)
1232    {
1233    
1234            uint32_t mode;
1235            const VLC *tab;
1236            int32_t level;
1237    
1238            if(short_video_header) // inter-VLCs will be used for both intra and inter blocks
1239                    intra = 0;
1240    
1241            tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1242    
1243            if(tab->code == -1)
1244                    goto error;
1245    
1246            BitstreamSkip(bs, tab->len);
1247    
1248            if(tab->code != ESCAPE) {
1249                    if(!intra)
1250                    {
1251                            *run = (tab->code >> 4) & 255;
1252                            level = tab->code & 15;
1253                            *last = (tab->code >> 12) & 1;
1254                    }
1255                    else
1256                    {
1257                            *run = (tab->code >> 8) & 255;
1258                            level = tab->code & 255;
1259                            *last = (tab->code >> 16) & 1;
1260                    }
1261                    return BitstreamGetBit(bs) ? -level : level;
1262            }
1263    
1264            if(short_video_header)
1265            {
1266                    // escape mode 4 - H.263 type, only used if short_video_header = 1
1267                    *last = BitstreamGetBit(bs);
1268                    *run = BitstreamGetBits(bs, 6);
1269                    level = BitstreamGetBits(bs, 8);
1270    
1271                    if (level == 0 || level == 128)
1272                            DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level);
1273    
1274                    return (level >= 128 ? -(256 - level) : level);
1275            }
1276    
1277            mode = BitstreamShowBits(bs, 2);
1278    
1279            if(mode < 3) {
1280                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1281    
1282                    tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1283                    if (tab->code == -1)
1284                            goto error;
1285    
1286                    BitstreamSkip(bs, tab->len);
1287    
1288                    if (!intra) {
1289                            *run = (tab->code >> 4) & 255;
1290                            level = tab->code & 15;
1291                            *last = (tab->code >> 12) & 1;
1292                    }
1293                    else
1294                    {
1295                            *run = (tab->code >> 8) & 255;
1296                            level = tab->code & 255;
1297                            *last = (tab->code >> 16) & 1;
1298                    }
1299    
1300                    if(mode < 2) // first escape mode, level is offset
1301                            level += max_level[*last + (!intra<<1)][*run]; // need to add back the max level
1302                    else if(mode == 2)  // second escape mode, run is offset
1303                            *run += max_run[*last + (!intra<<1)][level] + 1;
1304    
1305                    return BitstreamGetBit(bs) ? -level : level;
1306            }
1307    
1308            // third escape mode - fixed length codes
1309            BitstreamSkip(bs, 2);
1310            *last = BitstreamGetBits(bs, 1);
1311            *run = BitstreamGetBits(bs, 6);
1312            BitstreamSkip(bs, 1);                           // marker
1313            level = BitstreamGetBits(bs, 12);
1314            BitstreamSkip(bs, 1);                           // marker
1315    
1316            return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
1317    
1318     error:
1319            *run = VLC_ERROR;
1320            return 0;
1321    
1322    }
1323    
1324  #endif /* _VLC_CODES_H */  #endif /* _VLC_CODES_H */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4