[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.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                          *
# 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 1218  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.3  
changed lines
  Added in v.1.5

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