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

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

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

revision 113, Wed Apr 10 07:40:51 2002 UTC revision 114, Wed Apr 10 07:43:25 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 1223  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.113  
changed lines
  Added in v.114

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