[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.3, Sat Mar 9 15:53:05 2002 UTC revision 1.6.2.1, Sat Nov 2 15:52:31 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  {  {
12          uint32_t code;          uint32_t code;
13          int8_t len;          int8_t len;
14  } VLC;  }
15    VLC;
16    
17    static VLC *DCT3D[2];
18    
19    
20  /******************************************************************  /******************************************************************
# Line 210  Line 215 
215   * encoder tables                                                 *   * encoder tables                                                 *
216   ******************************************************************/   ******************************************************************/
217    
218    static VLC sprite_trajectory_code[32768];
219    
220    static VLC sprite_trajectory_len[15] = {
221            { 0x00 , 2},
222            { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},
223            { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8},
224            { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };
225    
226    
227  /* DCT coefficients. Four tables, two for last = 0, two for last = 1.  /* DCT coefficients. Four tables, two for last = 0, two for last = 1.
228     the sign bit must be added afterwards. */     the sign bit must be added afterwards. */
229    
# Line 632  Line 646 
646          coeff_inter_last1,          coeff_inter_last1,
647  };  };
648    
649  static const VLC mcbpc_I[4] = {  /* MCBPC Indexing by cbpc in first two bits, mode in last two.
650          {1, 1}, {1, 3}, {2, 3}, {3, 3}   CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
651  };   Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */
652    
653  static const VLC mcbpc_P_intra[4] = {  static VLC mcbpc_intra_tab[15] = {
654          {3, 5}, {4, 8}, {3, 8}, {3, 7}          {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
655  };          {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0},
656            {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0},
657  static const VLC mcbpc_P_inter[4] = {          {0x00, 0}, {0x03, 3}, {0x03, 6}
658          {1, 1}, {3, 4}, {2, 4}, {5, 6}  };
659  };  
660    /* MCBPC inter.
661  static const VLC mcbpc_P_inter4v[4] = {     Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */
662          {2, 3}, {5, 7}, {4, 7}, {5, 8}  
663    static VLC mcbpc_inter_tab[29] = {
664            {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0},
665            {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0},
666            {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0},
667            {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
668  };  };
669    
670  static const VLC cbpy_tab[16] = {  static const VLC cbpy_tab[16] = {
# Line 960  Line 979 
979    
980  static const VLC mcbpc_inter_table[257] = {  static const VLC mcbpc_inter_table[257] = {
981          {VLC_ERROR,0},          {VLC_ERROR,0},
982          {255,9}, {52,9}, {36,9}, {20,9}, {49,9}, {35,8}, {35,8}, {19,8}, {19,8},          {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8}, {19, 8},
983          {50,8}, {50,8}, {51,7}, {51,7}, {51,7}, {51,7}, {34,7}, {34,7}, {34,7},                  {19, 8},
984          {34,7}, {18,7}, {18,7}, {18,7}, {18,7}, {33,7}, {33,7}, {33,7}, {33,7},          {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7}, {34, 7}, {34, 7},
985                    {34, 7},
986            {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7}, {33, 7}, {33, 7}, {33, 7},
987                    {33, 7},
988          {17,7}, {17,7}, {17,7}, {17,7}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6},          {17,7}, {17,7}, {17,7}, {17,7}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6},
989          {4,6}, {4,6}, {4,6}, {48,6}, {48,6}, {48,6}, {48,6}, {48,6}, {48,6},          {4, 6}, {4, 6}, {4, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48,
990                                                                                                                                                      6},
991          {48,6}, {48,6}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5},          {48,6}, {48,6}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5},
992          {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5},          {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5}, {3,5},
993          {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4},          {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
994          {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4},                  {32, 4},
995          {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4},          {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
996          {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {16,4}, {16,4}, {16,4}, {16,4},                  {32, 4},
997          {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4},          {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
998          {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4},                  {32, 4},
999          {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4},          {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {16, 4}, {16, 4}, {16, 4},
1000                    {16, 4},
1001            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1002                    {16, 4},
1003            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1004                    {16, 4},
1005            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1006                    {16, 4},
1007          {16,4}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3},          {16,4}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3},
1008          {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3},          {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3},
1009          {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3},          {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3}, {2,3},
# Line 991  Line 1021 
1021          {1,3}, {1,3}, {1,3}, {0,1}          {1,3}, {1,3}, {1,3}, {0,1}
1022  };  };
1023    
1024  static const VLC cbpy_table[64] =  static const VLC cbpy_table[64] = {
 {  
1025          {-1,0}, {-1,0}, {6,6},  {9,6},  {8,5},  {8,5},  {4,5},  {4,5},          {-1,0}, {-1,0}, {6,6},  {9,6},  {8,5},  {8,5},  {4,5},  {4,5},
1026          {2,5},  {2,5},  {1,5},  {1,5},  {0,4},  {0,4},  {0,4},  {0,4},          {2,5},  {2,5},  {1,5},  {1,5},  {0,4},  {0,4},  {0,4},  {0,4},
1027          {12,4}, {12,4}, {12,4}, {12,4}, {10,4}, {10,4}, {10,4}, {10,4},          {12,4}, {12,4}, {12,4}, {12,4}, {10,4}, {10,4}, {10,4}, {10,4},
# Line 1006  Line 1035 
1035    
1036    
1037  VLC TMNMVtab0[] = {  VLC TMNMVtab0[] = {
1038          {3,4}, {-3,4}, {2,3}, {2,3}, {-2,3}, {-2,3}, {1,2}, {1,2}, {1,2}, {1,2},          {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2}, {1, 2}, {1, 2},
1039                    {1, 2},
1040          {-1,2}, {-1,2}, {-1,2}, {-1,2}          {-1,2}, {-1,2}, {-1,2}, {-1,2}
1041  };  };
1042    
1043  VLC TMNMVtab1[] = {  VLC TMNMVtab1[] = {
1044          {12,10}, {-12,10}, {11,10}, {-11,10}, {10,9}, {10,9}, {-10,9}, {-10,9},          {12, 10}, {-12, 10}, {11, 10}, {-11, 10}, {10, 9}, {10, 9}, {-10, 9}, {-10,
1045          {9,9}, {9,9}, {-9,9}, {-9,9}, {8,9}, {8,9}, {-8,9}, {-8,9}, {7,7}, {7,7},                                                                                                                                                     9},
1046          {7,7}, {7,7}, {7,7}, {7,7}, {7,7}, {7,7}, {-7,7}, {-7,7}, {-7,7}, {-7,7},          {9, 9}, {9, 9}, {-9, 9}, {-9, 9}, {8, 9}, {8, 9}, {-8, 9}, {-8, 9}, {7, 7},
1047          {-7,7}, {-7,7}, {-7,7}, {-7,7}, {6,7}, {6,7}, {6,7}, {6,7}, {6,7}, {6,7},                  {7, 7},
1048          {6,7}, {6,7}, {-6,7}, {-6,7}, {-6,7}, {-6,7}, {-6,7}, {-6,7}, {-6,7},          {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1049          {-6,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {-5,7},                  {-7, 7},
1050          {-5,7}, {-5,7}, {-5,7}, {-5,7}, {-5,7}, {-5,7}, {-5,7}, {4,6}, {4,6}, {4,6},          {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7},
1051          {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6},                  {6, 7},
1052          {4,6}, {4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6},          {6, 7}, {6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6,
1053          {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}                                                                                                                                                     7},
1054            {-6, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7},
1055                    {-5, 7},
1056            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {4, 6}, {4,
1057                                                                                                                                                            6},
1058                    {4, 6},
1059            {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4,
1060                                                                                                                                                             6},
1061                    {4, 6},
1062            {4, 6}, {4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4,
1063                                                                                                                                                       6},
1064            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
1065                    {-4, 6}
1066  };  };
1067    
1068  VLC TMNMVtab2[] = {  VLC TMNMVtab2[] = {
1069          {32,12}, {-32,12}, {31,12}, {-31,12}, {30,11}, {30,11}, {-30,11}, {-30,11},          {32, 12}, {-32, 12}, {31, 12}, {-31, 12}, {30, 11}, {30, 11}, {-30, 11},
1070          {29,11}, {29,11}, {-29,11}, {-29,11}, {28,11}, {28,11}, {-28,11}, {-28,11},                  {-30, 11},
1071          {27,11}, {27,11}, {-27,11}, {-27,11}, {26,11}, {26,11}, {-26,11}, {-26,11},          {29, 11}, {29, 11}, {-29, 11}, {-29, 11}, {28, 11}, {28, 11}, {-28, 11},
1072          {25,11}, {25,11}, {-25,11}, {-25,11}, {24,10}, {24,10}, {24,10}, {24,10},                  {-28, 11},
1073          {-24,10}, {-24,10}, {-24,10}, {-24,10}, {23,10}, {23,10}, {23,10}, {23,10},          {27, 11}, {27, 11}, {-27, 11}, {-27, 11}, {26, 11}, {26, 11}, {-26, 11},
1074          {-23,10}, {-23,10}, {-23,10}, {-23,10}, {22,10}, {22,10}, {22,10}, {22,10},                  {-26, 11},
1075          {-22,10}, {-22,10}, {-22,10}, {-22,10}, {21,10}, {21,10}, {21,10}, {21,10},          {25, 11}, {25, 11}, {-25, 11}, {-25, 11}, {24, 10}, {24, 10}, {24, 10},
1076          {-21,10}, {-21,10}, {-21,10}, {-21,10}, {20,10}, {20,10}, {20,10}, {20,10},                  {24, 10},
1077          {-20,10}, {-20,10}, {-20,10}, {-20,10}, {19,10}, {19,10}, {19,10}, {19,10},          {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10}, {23, 10}, {23, 10}, {23, 10},
1078          {-19,10}, {-19,10}, {-19,10}, {-19,10}, {18,10}, {18,10}, {18,10}, {18,10},                  {23, 10},
1079          {-18,10}, {-18,10}, {-18,10}, {-18,10}, {17,10}, {17,10}, {17,10}, {17,10},          {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10}, {22, 10}, {22, 10}, {22, 10},
1080          {-17,10}, {-17,10}, {-17,10}, {-17,10}, {16,10}, {16,10}, {16,10}, {16,10},                  {22, 10},
1081          {-16,10}, {-16,10}, {-16,10}, {-16,10}, {15,10}, {15,10}, {15,10}, {15,10},          {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10}, {21, 10}, {21, 10}, {21, 10},
1082          {-15,10}, {-15,10}, {-15,10}, {-15,10}, {14,10}, {14,10}, {14,10}, {14,10},                  {21, 10},
1083          {-14,10}, {-14,10}, {-14,10}, {-14,10}, {13,10}, {13,10}, {13,10}, {13,10},          {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10}, {20, 10}, {20, 10}, {20, 10},
1084                    {20, 10},
1085            {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10}, {19, 10}, {19, 10}, {19, 10},
1086                    {19, 10},
1087            {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10}, {18, 10}, {18, 10}, {18, 10},
1088                    {18, 10},
1089            {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10}, {17, 10}, {17, 10}, {17, 10},
1090                    {17, 10},
1091            {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10}, {16, 10}, {16, 10}, {16, 10},
1092                    {16, 10},
1093            {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10}, {15, 10}, {15, 10}, {15, 10},
1094                    {15, 10},
1095            {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10}, {14, 10}, {14, 10}, {14, 10},
1096                    {14, 10},
1097            {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10}, {13, 10}, {13, 10}, {13, 10},
1098                    {13, 10},
1099          {-13,10}, {-13,10}, {-13,10}, {-13,10}          {-13,10}, {-13,10}, {-13,10}, {-13,10}
1100  };  };
1101    
# Line 1218  Line 1275 
1275          {2, 2}, {2, 2}, {1, 2}, {1, 2},          {2, 2}, {2, 2}, {1, 2}, {1, 2},
1276  };  };
1277    
1278    static __inline int
1279    get_coeff(Bitstream * bs,
1280                      int *run,
1281                      int *last,
1282                      int intra,
1283                      int short_video_header)
1284    {
1285    
1286            uint32_t mode;
1287            const VLC *tab;
1288            int32_t level;
1289    
1290            if (short_video_header)         // inter-VLCs will be used for both intra and inter blocks
1291                    intra = 0;
1292    
1293            tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1294    
1295            if (tab->code == -1)
1296                    goto error;
1297    
1298            BitstreamSkip(bs, tab->len);
1299    
1300            if (tab->code != ESCAPE) {
1301                    if (!intra) {
1302                            *run = (tab->code >> 4) & 255;
1303                            level = tab->code & 15;
1304                            *last = (tab->code >> 12) & 1;
1305                    } else {
1306                            *run = (tab->code >> 8) & 255;
1307                            level = tab->code & 255;
1308                            *last = (tab->code >> 16) & 1;
1309                    }
1310                    return BitstreamGetBit(bs) ? -level : level;
1311            }
1312    
1313            if (short_video_header) {
1314                    // escape mode 4 - H.263 type, only used if short_video_header = 1
1315                    *last = BitstreamGetBit(bs);
1316                    *run = BitstreamGetBits(bs, 6);
1317                    level = BitstreamGetBits(bs, 8);
1318    
1319                    if (level == 0 || level == 128)
1320                            DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level);
1321    
1322                    return (level >= 128 ? -(256 - level) : level);
1323            }
1324    
1325            mode = BitstreamShowBits(bs, 2);
1326    
1327            if (mode < 3) {
1328                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1329    
1330                    tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1331                    if (tab->code == -1)
1332                            goto error;
1333    
1334                    BitstreamSkip(bs, tab->len);
1335    
1336                    if (!intra) {
1337                            *run = (tab->code >> 4) & 255;
1338                            level = tab->code & 15;
1339                            *last = (tab->code >> 12) & 1;
1340                    } else {
1341                            *run = (tab->code >> 8) & 255;
1342                            level = tab->code & 255;
1343                            *last = (tab->code >> 16) & 1;
1344                    }
1345    
1346                    if (mode < 2)                   // first escape mode, level is offset
1347                            level += max_level[*last + (!intra << 1)][*run];        // need to add back the max level
1348                    else if (mode == 2)             // second escape mode, run is offset
1349                            *run += max_run[*last + (!intra << 1)][level] + 1;
1350    
1351                    return BitstreamGetBit(bs) ? -level : level;
1352            }
1353            // third escape mode - fixed length codes
1354            BitstreamSkip(bs, 2);
1355            *last = BitstreamGetBits(bs, 1);
1356            *run = BitstreamGetBits(bs, 6);
1357            BitstreamSkip(bs, 1);           // marker
1358            level = BitstreamGetBits(bs, 12);
1359            BitstreamSkip(bs, 1);           // marker
1360    
1361            return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
1362    
1363      error:
1364            *run = VLC_ERROR;
1365            return 0;
1366    
1367    }
1368    
1369  #endif /* _VLC_CODES_H */  #endif /* _VLC_CODES_H */

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.6.2.1

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