Revision 3c2ddb59 libavcodec/vc1.c

View differences:

libavcodec/vc1.c
42 42
static const uint16_t table_mb_intra[64][2];
43 43

  
44 44

  
45
/**
46
 * Get unary code of limited length
47
 * @todo FIXME Slow and ugly
48
 * @param gb GetBitContext
49
 * @param[in] stop The bitstop value (unary code of 1's or 0's)
50
 * @param[in] len Maximum length
51
 * @return Unary length/index
52
 */
53
static int get_prefix(GetBitContext *gb, int stop, int len)
54
{
55
#if 1
56
    int i;
57

  
58
    for(i = 0; i < len && get_bits1(gb) != stop; i++);
59
    return i;
60
/*  int i = 0, tmp = !stop;
61

  
62
  while (i != len && tmp != stop)
63
  {
64
    tmp = get_bits(gb, 1);
65
    i++;
66
  }
67
  if (i == len && tmp != stop) return len+1;
68
  return i;*/
69
#else
70
  unsigned int buf;
71
  int log;
72

  
73
  OPEN_READER(re, gb);
74
  UPDATE_CACHE(re, gb);
75
  buf=GET_CACHE(re, gb); //Still not sure
76
  if (stop) buf = ~buf;
77

  
78
  log= av_log2(-buf); //FIXME: -?
79
  if (log < limit){
80
    LAST_SKIP_BITS(re, gb, log+1);
81
    CLOSE_READER(re, gb);
82
    return log;
83
  }
84

  
85
  LAST_SKIP_BITS(re, gb, limit);
86
  CLOSE_READER(re, gb);
87
  return limit;
88
#endif
89
}
90

  
91 45
static inline int decode210(GetBitContext *gb){
92 46
    if (get_bits1(gb))
93 47
        return 0;
......
1131 1085
    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
1132 1086
        v->pquantizer = get_bits(gb, 1);
1133 1087
    v->dquantfrm = 0;
1134
    if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3);
1088
    if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3);
1135 1089
    v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1136 1090
    v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1137 1091
    v->range_x = 1 << (v->k_x - 1);
......
1158 1112
        else v->tt_index = 2;
1159 1113

  
1160 1114
        lowquant = (v->pq > 12) ? 0 : 1;
1161
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
1115
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
1162 1116
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
1163 1117
        {
1164 1118
            int scale, shift, i;
1165
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
1119
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
1166 1120
            v->lumscale = get_bits(gb, 6);
1167 1121
            v->lumshift = get_bits(gb, 6);
1168 1122
            v->use_ic = 1;
......
1305 1259
        v->fcm = decode012(gb);
1306 1260
        if(v->fcm) return -1; // interlaced frames/fields are not implemented
1307 1261
    }
1308
    switch(get_prefix(gb, 0, 4)) {
1262
    switch(get_unary(gb, 0, 4)) {
1309 1263
    case 0:
1310 1264
        v->s.pict_type = P_TYPE;
1311 1265
        break;
......
1388 1342
    case P_TYPE:
1389 1343
        if(v->postprocflag)
1390 1344
            v->postproc = get_bits1(gb);
1391
        if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
1345
        if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
1392 1346
        else v->mvrange = 0;
1393 1347
        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1394 1348
        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
......
1400 1354
        else v->tt_index = 2;
1401 1355

  
1402 1356
        lowquant = (v->pq > 12) ? 0 : 1;
1403
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
1357
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
1404 1358
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
1405 1359
        {
1406 1360
            int scale, shift, i;
1407
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
1361
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
1408 1362
            v->lumscale = get_bits(gb, 6);
1409 1363
            v->lumshift = get_bits(gb, 6);
1410 1364
            /* fill lookup tables for intensity compensation */
......
1479 1433
    case B_TYPE:
1480 1434
        if(v->postprocflag)
1481 1435
            v->postproc = get_bits1(gb);
1482
        if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
1436
        if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
1483 1437
        else v->mvrange = 0;
1484 1438
        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1485 1439
        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
......
2350 2304
                    if(!v->s.esc3_level_length)
2351 2305
                        v->s.esc3_level_length = get_bits(gb, 2) + 8;
2352 2306
                } else { //table 60
2353
                    v->s.esc3_level_length = get_prefix(gb, 1, 6) + 2;
2307
                    v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
2354 2308
                }
2355 2309
                v->s.esc3_run_length = 3 + get_bits(gb, 2);
2356 2310
            }

Also available in: Unified diff