Revision 642d7e84 libavcodec/vp3.c

View differences:

libavcodec/vp3.c
139 139
    int last_coeff;
140 140
    int motion_x;
141 141
    int motion_y;
142
    /* this indicates which ffmpeg put_pixels() function to use:
143
     * 00b = no halfpel, 01b = x halfpel, 10b = y halfpel, 11b = both halfpel */
144
    int motion_halfpel_index;
145 142
    /* address of first pixel taking into account which plane the fragment
146 143
     * lives on as well as the plane stride */
147 144
    int first_pixel;
......
816 813
        memset(s->all_fragments[i].coeffs, 0, 64 * sizeof(DCTELEM));
817 814
        s->all_fragments[i].coeff_count = 0;
818 815
        s->all_fragments[i].last_coeff = 0;
816
s->all_fragments[i].motion_x = 0xbeef;
817
s->all_fragments[i].motion_y = 0xbeef;
819 818
    }
820 819
}
821 820

  
......
1161 1160

  
1162 1161
                /* if any of the superblocks are not partially coded, flag
1163 1162
                 * a boolean to decode the list of fully-coded superblocks */
1164
                if (bit == 0)
1163
                if (bit == 0) {
1165 1164
                    decode_fully_flags = 1;
1166
            } else {
1167

  
1168
                /* make a note of the fact that there are partially coded
1169
                 * superblocks */
1170
                decode_partial_blocks = 1;
1165
                } else {
1171 1166

  
1167
                    /* make a note of the fact that there are partially coded
1168
                     * superblocks */
1169
                    decode_partial_blocks = 1;
1170
                }
1172 1171
            }
1173 1172
            s->superblock_coding[current_superblock++] = 
1174 1173
                (bit) ? SB_PARTIALLY_CODED : SB_NOT_CODED;
......
1309 1308
        /* only Y fragments coded in this frame */
1310 1309
        s->last_coded_y_fragment = s->coded_fragment_list_index - 1;
1311 1310
    else 
1312
        /* end the list of coded fragments */
1311
        /* end the list of coded C fragments */
1313 1312
        s->last_coded_c_fragment = s->coded_fragment_list_index - 1;
1314 1313

  
1315 1314
    debug_block_coding("    %d total coded fragments, y: %d -> %d, c: %d -> %d\n",
......
1407 1406
}
1408 1407

  
1409 1408
/*
1410
 * This function adjusts the components of a motion vector for the halfpel
1411
 * motion grid. c_plane indicates whether the vector applies to the U or V
1412
 * plane. The function returns the halfpel function index to be used in
1413
 * ffmpeg's put_pixels[]() array of functions.
1414
 */
1415
static inline int adjust_vector(int *x, int *y, int c_plane)
1416
{
1417
    int motion_halfpel_index = 0;
1418
    int x_halfpel;
1419
    int y_halfpel;
1420

  
1421
    if (!c_plane) {
1422

  
1423
        x_halfpel = *x & 1;
1424
        motion_halfpel_index |= x_halfpel;
1425
        if (*x >= 0)
1426
            *x >>= 1;
1427
        else
1428
            *x = -( (-(*x) >> 1) + x_halfpel);
1429

  
1430
        y_halfpel = *y & 1;
1431
        motion_halfpel_index |= (y_halfpel << 1);
1432
        if (*y >= 0)
1433
            *y >>= 1;
1434
        else
1435
            *y = -( (-(*y) >> 1) + y_halfpel);
1436

  
1437
    } else {
1438

  
1439
        x_halfpel = ((*x & 0x03) != 0);
1440
        motion_halfpel_index |= x_halfpel;
1441
        if (*x >= 0)
1442
            *x >>= 2;
1443
        else
1444
            *x = -( (-(*x) >> 2) + x_halfpel);
1445

  
1446
        y_halfpel = ((*y & 0x03) != 0);
1447
        motion_halfpel_index |= (y_halfpel << 1);
1448
        if (*y >= 0)
1449
            *y >>= 2;
1450
        else
1451
            *y = -( (-(*y) >> 2) + y_halfpel);
1452

  
1453
    }
1454

  
1455
    return motion_halfpel_index;
1456
}
1457

  
1458
/*
1459 1409
 * This function unpacks all the motion vectors for the individual
1460 1410
 * macroblocks from the bitstream.
1461 1411
 */
......
1527 1477
                    }
1528 1478

  
1529 1479
                    /* vector maintenance, only on MODE_INTER_PLUS_MV */
1530
                    if (s->all_fragments[current_fragment].coding_method ==
1480
                    if (s->macroblock_coding[current_macroblock] ==
1531 1481
                        MODE_INTER_PLUS_MV) {
1532 1482
                        prior_last_motion_x = last_motion_x;
1533 1483
                        prior_last_motion_y = last_motion_y;
......
1614 1564
                /* assign the motion vectors to the correct fragments */
1615 1565
                debug_vectors("    vectors for macroblock starting @ fragment %d (coding method %d):\n",
1616 1566
                    current_fragment,
1617
                    s->all_fragments[current_fragment].coding_method);
1567
                    s->macroblock_coding[current_macroblock]);
1618 1568
                for (k = 0; k < 6; k++) {
1619 1569
                    current_fragment = 
1620 1570
                        s->macroblock_fragments[current_macroblock * 6 + k];
......
1625 1575
                            current_fragment, s->fragment_count);
1626 1576
                        return 1;
1627 1577
                    }
1628
                    s->all_fragments[current_fragment].motion_halfpel_index =
1629
                        adjust_vector(&motion_x[k], &motion_y[k],
1630
                        ((k == 4) || (k == 5)));
1631 1578
                    s->all_fragments[current_fragment].motion_x = motion_x[k];
1632 1579
                    s->all_fragments[current_fragment].motion_y = motion_y[k];
1633
                    debug_vectors("    vector %d: fragment %d = (%d, %d), index %d\n",
1634
                        k, current_fragment, motion_x[k], motion_y[k],
1635
                        s->all_fragments[current_fragment].motion_halfpel_index);
1580
                    debug_vectors("    vector %d: fragment %d = (%d, %d)\n",
1581
                        k, current_fragment, motion_x[k], motion_y[k]);
1636 1582
                }
1637 1583
            }
1638 1584
        }
......
2141 2087
            /* transform if this block was coded */
2142 2088
            if (s->all_fragments[i].coding_method != MODE_COPY) {
2143 2089

  
2144
                /* sort out the motion vector */
2145
                motion_x = s->all_fragments[i].motion_x;
2146
                motion_y = s->all_fragments[i].motion_y;
2147
                motion_halfpel_index = s->all_fragments[i].motion_halfpel_index;
2148

  
2149 2090
                motion_source = s->all_fragments[i].first_pixel;
2150
                motion_source += motion_x;
2151
                motion_source += (motion_y * stride);
2152

  
2153
                /* if the are any problems with a motion vector, refuse
2154
                 * to render the block */
2155
                if ((motion_source < upper_motion_limit) ||
2156
                    (motion_source > lower_motion_limit)) {
2157
//                    printf ("  vp3: help! motion source (%d) out of range (%d..%d)\n",
2158
//                        motion_source, upper_motion_limit, lower_motion_limit);
2159
                    continue;
2091
                motion_halfpel_index = 0;
2092

  
2093
                /* sort out the motion vector if this fragment is coded
2094
                 * using a motion vector method */
2095
                if ((s->all_fragments[i].coding_method > MODE_INTRA) &&
2096
                    (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) {
2097
                    motion_x = s->all_fragments[i].motion_x;
2098
                    motion_y = s->all_fragments[i].motion_y;
2099
if ((motion_x == 0xbeef) || (motion_y == 0xbeef))
2100
printf (" help! got beefy vector! (%X, %X)\n", motion_x, motion_y);
2101

  
2102
                    if (motion_x >= 0) {
2103
                        motion_halfpel_index = motion_x & 0x01;
2104
                        motion_source += (motion_x >> 1);
2105
                    } else  {
2106
                        motion_x = -motion_x;
2107
                        motion_halfpel_index = motion_x & 0x01;
2108
                        motion_source -= ((motion_x + 1) >> 1);
2109
                    }
2110

  
2111
//                    motion_y = -motion_y;
2112
                    if (motion_y >= 0) {
2113
                        motion_halfpel_index |= (motion_y & 0x01) << 1;
2114
                        motion_source += ((motion_y >> 1) * stride);
2115
                    } else  {
2116
                        motion_y = -motion_y;
2117
                        motion_halfpel_index |= (motion_y & 0x01) << 1;
2118
                        motion_source -= (((motion_y + 1) >> 1) * stride);
2119
                    }
2120

  
2121
                    /* if the are any problems with a motion vector, refuse
2122
                     * to render the block */
2123
                    if ((motion_source < upper_motion_limit) ||
2124
                        (motion_source > lower_motion_limit)) {
2125
//                        printf ("  vp3: help! motion source (%d) out of range (%d..%d)\n",
2126
//                            motion_source, upper_motion_limit, lower_motion_limit);
2127
                        continue;
2128
                    }
2160 2129
                }
2161 2130

  
2162 2131
                /* first, take care of copying a block from either the
......
2304 2273
    int c_superblock_count;
2305 2274

  
2306 2275
    s->avctx = avctx;
2276
#if 0
2307 2277
    s->width = avctx->width;
2308 2278
    s->height = avctx->height;
2279
#else
2280
    s->width = (avctx->width + 15) & 0xFFFFFFF0;
2281
    s->height = (avctx->height + 15) & 0xFFFFFFF0;
2282
#endif
2309 2283
    avctx->pix_fmt = PIX_FMT_YUV420P;
2310 2284
    avctx->has_b_frames = 0;
2311 2285
    dsputil_init(&s->dsp, avctx);
......
2432 2406
    skip_bits(&gb, 1);
2433 2407
    s->last_quality_index = s->quality_index;
2434 2408
    s->quality_index = get_bits(&gb, 6);
2435
    if (s->quality_index != s->last_quality_index)
2436
        init_dequantizer(s);
2437 2409

  
2438 2410
    debug_vp3(" VP3 frame #%d: Q index = %d", counter, s->quality_index);
2439 2411
    counter++;
2440 2412

  
2413
    if (s->quality_index != s->last_quality_index)
2414
        init_dequantizer(s);
2415

  
2441 2416
    if (s->keyframe) {
2442 2417

  
2443 2418
        debug_vp3(", keyframe\n");
......
2510 2485
        s->fragment_width / 2, s->fragment_height / 2);
2511 2486

  
2512 2487
    render_fragments(s, 0, s->width, s->height, 0);
2488
#if 1
2513 2489
    render_fragments(s, s->u_fragment_start, s->width / 2, s->height / 2, 1);
2514 2490
    render_fragments(s, s->v_fragment_start, s->width / 2, s->height / 2, 2);
2491
#else
2492
memset(s->current_frame.data[1], 0x80, s->width * s->height / 4);
2493
memset(s->current_frame.data[2], 0x80, s->width * s->height / 4);
2494
#endif
2515 2495

  
2516 2496
#if KEYFRAMES_ONLY
2517 2497
}

Also available in: Unified diff