Revision 1052b76f

View differences:

libavcodec/h264.c
488 488
                    x_offset, y_offset, qpix_put, chroma_put);
489 489

  
490 490
        if(h->use_weight == 2){
491
            int weight0 = h->implicit_weight[refn0][refn1];
491
            int weight0 = h->implicit_weight[refn0][refn1][s->mb_y&1];
492 492
            int weight1 = 64 - weight0;
493 493
            luma_weight_avg(  dest_y,  tmp_y,  h->  mb_linesize, 5, weight0, weight1, 0);
494 494
            chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, weight1, 0);
......
531 531
                           h264_weight_func *weight_op, h264_biweight_func *weight_avg,
532 532
                           int list0, int list1){
533 533
    if((h->use_weight==2 && list0 && list1
534
        && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 32))
534
        && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ][h->s.mb_y&1] != 32))
535 535
       || h->use_weight==1)
536 536
        mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr,
537 537
                         x_offset, y_offset, qpix_put, chroma_put,
......
1408 1408
    return 0;
1409 1409
}
1410 1410

  
1411
static void implicit_weight_table(H264Context *h){
1411
/**
1412
 * Initialize implicit_weight table.
1413
 * @param field, 0/1 initialize the weight for interlaced MBAFF
1414
 *                -1 initializes the rest
1415
 */
1416
static void implicit_weight_table(H264Context *h, int field){
1412 1417
    MpegEncContext * const s = &h->s;
1413
    int ref0, ref1, i;
1414
    int cur_poc = s->current_picture_ptr->poc;
1418
    int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
1415 1419

  
1416 1420
    for (i = 0; i < 2; i++) {
1417 1421
        h->luma_weight_flag[i]   = 0;
1418 1422
        h->chroma_weight_flag[i] = 0;
1419 1423
    }
1420 1424

  
1421
    if(   h->ref_count[0] == 1 && h->ref_count[1] == 1
1425
    if(field < 0){
1426
        cur_poc = s->current_picture_ptr->poc;
1427
    if(   h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF
1422 1428
       && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){
1423 1429
        h->use_weight= 0;
1424 1430
        h->use_weight_chroma= 0;
1425 1431
        return;
1426 1432
    }
1433
        ref_start= 0;
1434
        ref_count0= h->ref_count[0];
1435
        ref_count1= h->ref_count[1];
1436
    }else{
1437
        cur_poc = s->current_picture_ptr->field_poc[field];
1438
        ref_start= 16;
1439
        ref_count0= 16+2*h->ref_count[0];
1440
        ref_count1= 16+2*h->ref_count[1];
1441
    }
1427 1442

  
1428 1443
    h->use_weight= 2;
1429 1444
    h->use_weight_chroma= 2;
1430 1445
    h->luma_log2_weight_denom= 5;
1431 1446
    h->chroma_log2_weight_denom= 5;
1432 1447

  
1433
    for(ref0=0; ref0 < h->ref_count[0]; ref0++){
1448
    for(ref0=ref_start; ref0 < ref_count0; ref0++){
1434 1449
        int poc0 = h->ref_list[0][ref0].poc;
1435
        for(ref1=0; ref1 < h->ref_count[1]; ref1++){
1450
        for(ref1=ref_start; ref1 < ref_count1; ref1++){
1436 1451
            int poc1 = h->ref_list[1][ref1].poc;
1437 1452
            int td = av_clip(poc1 - poc0, -128, 127);
1438
            h->implicit_weight[ref0][ref1] = 32;
1453
            int w= 32;
1439 1454
            if(td){
1440 1455
                int tb = av_clip(cur_poc - poc0, -128, 127);
1441 1456
                int tx = (16384 + (FFABS(td) >> 1)) / td;
1442 1457
                int dist_scale_factor = (tb*tx + 32) >> 8;
1443 1458
                if(dist_scale_factor >= -64 && dist_scale_factor <= 128)
1444
                    h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor;
1459
                    w = 64 - dist_scale_factor;
1460
            }
1461
            if(field<0){
1462
                h->implicit_weight[ref0][ref1][0]=
1463
                h->implicit_weight[ref0][ref1][1]= w;
1464
            }else{
1465
                h->implicit_weight[ref0][ref1][field]=w;
1445 1466
            }
1446 1467
        }
1447 1468
    }
......
2005 2026
       ||  (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) )
2006 2027
        pred_weight_table(h);
2007 2028
    else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){
2008
        implicit_weight_table(h);
2029
        implicit_weight_table(h, -1);
2009 2030
    }else {
2010 2031
        h->use_weight = 0;
2011 2032
        for (i = 0; i < 2; i++) {
......
2017 2038
    if(h->nal_ref_idc)
2018 2039
        ff_h264_decode_ref_pic_marking(h0, &s->gb);
2019 2040

  
2020
    if(FRAME_MBAFF)
2041
    if(FRAME_MBAFF){
2021 2042
        ff_h264_fill_mbaff_ref_list(h);
2022 2043

  
2044
        if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){
2045
            implicit_weight_table(h, 0);
2046
            implicit_weight_table(h, 1);
2047
        }
2048
    }
2049

  
2023 2050
    if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred)
2024 2051
        ff_h264_direct_dist_scale_factor(h);
2025 2052
    ff_h264_direct_ref_list_init(h);
libavcodec/h264.h
378 378
    //The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
379 379
    int luma_weight[48][2][2];
380 380
    int chroma_weight[48][2][2][2];
381
    int implicit_weight[48][48];
381
    int implicit_weight[48][48][2];
382 382

  
383 383
    int direct_spatial_mv_pred;
384 384
    int col_parity;
libavcodec/h264_refs.c
323 323
            }
324 324
        }
325 325
    }
326
    for(j=0; j<h->ref_count[1]; j++){
327
        for(i=0; i<h->ref_count[0]; i++)
328
            h->implicit_weight[j][16+2*i] = h->implicit_weight[j][16+2*i+1] = h->implicit_weight[j][i];
329
        memcpy(h->implicit_weight[16+2*j],   h->implicit_weight[j], sizeof(*h->implicit_weight));
330
        memcpy(h->implicit_weight[16+2*j+1], h->implicit_weight[j], sizeof(*h->implicit_weight));
331
    }
332 326
}
333 327

  
334 328
/**

Also available in: Unified diff