[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.4, Fri Mar 15 09:19:57 2002 UTC revision 1.6, Wed Jun 12 20:38:40 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 965  Line 970 
970    
971  static const VLC mcbpc_inter_table[257] = {  static const VLC mcbpc_inter_table[257] = {
972          {VLC_ERROR,0},          {VLC_ERROR,0},
973          {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},
974          {50,8}, {50,8}, {51,7}, {51,7}, {51,7}, {51,7}, {34,7}, {34,7}, {34,7},                  {19, 8},
975          {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},
976                    {34, 7},
977            {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7}, {33, 7}, {33, 7}, {33, 7},
978                    {33, 7},
979          {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},
980          {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,
981                                                                                                                                                      6},
982          {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},
983          {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},
984          {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},
985          {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {32,4},                  {32, 4},
986          {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},
987          {32,4}, {32,4}, {32,4}, {32,4}, {32,4}, {16,4}, {16,4}, {16,4}, {16,4},                  {32, 4},
988          {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},
989          {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4}, {16,4},                  {32, 4},
990          {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},
991                    {16, 4},
992            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
993                    {16, 4},
994            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
995                    {16, 4},
996            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
997                    {16, 4},
998          {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},
999          {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},
1000          {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 996  Line 1012 
1012          {1,3}, {1,3}, {1,3}, {0,1}          {1,3}, {1,3}, {1,3}, {0,1}
1013  };  };
1014    
1015  static const VLC cbpy_table[64] =  static const VLC cbpy_table[64] = {
 {  
1016          {-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},
1017          {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},
1018          {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 1011  Line 1026 
1026    
1027    
1028  VLC TMNMVtab0[] = {  VLC TMNMVtab0[] = {
1029          {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},
1030                    {1, 2},
1031          {-1,2}, {-1,2}, {-1,2}, {-1,2}          {-1,2}, {-1,2}, {-1,2}, {-1,2}
1032  };  };
1033    
1034  VLC TMNMVtab1[] = {  VLC TMNMVtab1[] = {
1035          {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,
1036          {9,9}, {9,9}, {-9,9}, {-9,9}, {8,9}, {8,9}, {-8,9}, {-8,9}, {7,7}, {7,7},                                                                                                                                                     9},
1037          {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},
1038          {-7,7}, {-7,7}, {-7,7}, {-7,7}, {6,7}, {6,7}, {6,7}, {6,7}, {6,7}, {6,7},                  {7, 7},
1039          {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},
1040          {-6,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {5,7}, {-5,7},                  {-7, 7},
1041          {-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},
1042          {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6}, {4,6},                  {6, 7},
1043          {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,
1044          {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}, {-4,6}                                                                                                                                                     7},
1045            {-6, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7},
1046                    {-5, 7},
1047            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {4, 6}, {4,
1048                                                                                                                                                            6},
1049                    {4, 6},
1050            {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4,
1051                                                                                                                                                             6},
1052                    {4, 6},
1053            {4, 6}, {4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4,
1054                                                                                                                                                       6},
1055            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
1056                    {-4, 6}
1057  };  };
1058    
1059  VLC TMNMVtab2[] = {  VLC TMNMVtab2[] = {
1060          {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},
1061          {29,11}, {29,11}, {-29,11}, {-29,11}, {28,11}, {28,11}, {-28,11}, {-28,11},                  {-30, 11},
1062          {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},
1063          {25,11}, {25,11}, {-25,11}, {-25,11}, {24,10}, {24,10}, {24,10}, {24,10},                  {-28, 11},
1064          {-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},
1065          {-23,10}, {-23,10}, {-23,10}, {-23,10}, {22,10}, {22,10}, {22,10}, {22,10},                  {-26, 11},
1066          {-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},
1067          {-21,10}, {-21,10}, {-21,10}, {-21,10}, {20,10}, {20,10}, {20,10}, {20,10},                  {24, 10},
1068          {-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},
1069          {-19,10}, {-19,10}, {-19,10}, {-19,10}, {18,10}, {18,10}, {18,10}, {18,10},                  {23, 10},
1070          {-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},
1071          {-17,10}, {-17,10}, {-17,10}, {-17,10}, {16,10}, {16,10}, {16,10}, {16,10},                  {22, 10},
1072          {-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},
1073          {-15,10}, {-15,10}, {-15,10}, {-15,10}, {14,10}, {14,10}, {14,10}, {14,10},                  {21, 10},
1074          {-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},
1075                    {20, 10},
1076            {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10}, {19, 10}, {19, 10}, {19, 10},
1077                    {19, 10},
1078            {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10}, {18, 10}, {18, 10}, {18, 10},
1079                    {18, 10},
1080            {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10}, {17, 10}, {17, 10}, {17, 10},
1081                    {17, 10},
1082            {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10}, {16, 10}, {16, 10}, {16, 10},
1083                    {16, 10},
1084            {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10}, {15, 10}, {15, 10}, {15, 10},
1085                    {15, 10},
1086            {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10}, {14, 10}, {14, 10}, {14, 10},
1087                    {14, 10},
1088            {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10}, {13, 10}, {13, 10}, {13, 10},
1089                    {13, 10},
1090          {-13,10}, {-13,10}, {-13,10}, {-13,10}          {-13,10}, {-13,10}, {-13,10}, {-13,10}
1091  };  };
1092    
# Line 1223  Line 1266 
1266          {2, 2}, {2, 2}, {1, 2}, {1, 2},          {2, 2}, {2, 2}, {1, 2}, {1, 2},
1267  };  };
1268    
1269    static __inline int
1270    get_coeff(Bitstream * bs,
1271                      int *run,
1272                      int *last,
1273                      int intra,
1274                      int short_video_header)
1275    {
1276    
1277            uint32_t mode;
1278            const VLC *tab;
1279            int32_t level;
1280    
1281            if (short_video_header)         // inter-VLCs will be used for both intra and inter blocks
1282                    intra = 0;
1283    
1284            tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1285    
1286            if (tab->code == -1)
1287                    goto error;
1288    
1289            BitstreamSkip(bs, tab->len);
1290    
1291            if (tab->code != ESCAPE) {
1292                    if (!intra) {
1293                            *run = (tab->code >> 4) & 255;
1294                            level = tab->code & 15;
1295                            *last = (tab->code >> 12) & 1;
1296                    } else {
1297                            *run = (tab->code >> 8) & 255;
1298                            level = tab->code & 255;
1299                            *last = (tab->code >> 16) & 1;
1300                    }
1301                    return BitstreamGetBit(bs) ? -level : level;
1302            }
1303    
1304            if (short_video_header) {
1305                    // escape mode 4 - H.263 type, only used if short_video_header = 1
1306                    *last = BitstreamGetBit(bs);
1307                    *run = BitstreamGetBits(bs, 6);
1308                    level = BitstreamGetBits(bs, 8);
1309    
1310                    if (level == 0 || level == 128)
1311                            DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level);
1312    
1313                    return (level >= 128 ? -(256 - level) : level);
1314            }
1315    
1316            mode = BitstreamShowBits(bs, 2);
1317    
1318            if (mode < 3) {
1319                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1320    
1321                    tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1322                    if (tab->code == -1)
1323                            goto error;
1324    
1325                    BitstreamSkip(bs, tab->len);
1326    
1327                    if (!intra) {
1328                            *run = (tab->code >> 4) & 255;
1329                            level = tab->code & 15;
1330                            *last = (tab->code >> 12) & 1;
1331                    } else {
1332                            *run = (tab->code >> 8) & 255;
1333                            level = tab->code & 255;
1334                            *last = (tab->code >> 16) & 1;
1335                    }
1336    
1337                    if (mode < 2)                   // first escape mode, level is offset
1338                            level += max_level[*last + (!intra << 1)][*run];        // need to add back the max level
1339                    else if (mode == 2)             // second escape mode, run is offset
1340                            *run += max_run[*last + (!intra << 1)][level] + 1;
1341    
1342                    return BitstreamGetBit(bs) ? -level : level;
1343            }
1344            // third escape mode - fixed length codes
1345            BitstreamSkip(bs, 2);
1346            *last = BitstreamGetBits(bs, 1);
1347            *run = BitstreamGetBits(bs, 6);
1348            BitstreamSkip(bs, 1);           // marker
1349            level = BitstreamGetBits(bs, 12);
1350            BitstreamSkip(bs, 1);           // marker
1351    
1352            return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
1353    
1354      error:
1355            *run = VLC_ERROR;
1356            return 0;
1357    
1358    }
1359    
1360  #endif /* _VLC_CODES_H */  #endif /* _VLC_CODES_H */

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.6

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