| @@ -488,7 +488,7 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom · 487 unmodified lines |
| 488 | x_offset, y_offset, qpix_put, chroma_put); | 488 | x_offset, y_offset, qpix_put, chroma_put); |
| 489 | | 489 | |
| 490 | if(h->use_weight == 2){ | 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 | int weight1 = 64 - weight0; | 492 | int weight1 = 64 - weight0; |
| 493 | luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, weight1, 0); | 493 | luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, weight1, 0); |
| 494 | chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, weight1, 0); | 494 | chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, weight1, 0); |
| @@ -531,7 +531,7 @@ static inline void mc_part(H264Context *h, int n, int square, int chroma_height, · 36 unmodified lines |
| 531 | h264_weight_func *weight_op, h264_biweight_func *weight_avg, | 531 | h264_weight_func *weight_op, h264_biweight_func *weight_avg, |
| 532 | int list0, int list1){ | 532 | int list0, int list1){ |
| 533 | if((h->use_weight==2 && list0 && list1 | 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 | || h->use_weight==1) | 535 | || h->use_weight==1) |
| 536 | mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, | 536 | mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, |
| 537 | x_offset, y_offset, qpix_put, chroma_put, | 537 | x_offset, y_offset, qpix_put, chroma_put, |
| @@ -1408,40 +1408,61 @@ static int pred_weight_table(H264Context *h){ · 870 unmodified lines |
| 1408 | return 0; | 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 | MpegEncContext * const s = &h->s; | 1417 | MpegEncContext * const s = &h->s; |
| 1413 | int ref0, ref1, i; | 1418 | int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1; |
| 1414 | int cur_poc = s->current_picture_ptr->poc; | | |
| 1415 | | 1419 | |
| 1416 | for (i = 0; i < 2; i++) { | 1420 | for (i = 0; i < 2; i++) { |
| 1417 | h->luma_weight_flag[i] = 0; | 1421 | h->luma_weight_flag[i] = 0; |
| 1418 | h->chroma_weight_flag[i] = 0; | 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 | && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){ | 1428 | && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){ |
| 1423 | h->use_weight= 0; | 1429 | h->use_weight= 0; |
| 1424 | h->use_weight_chroma= 0; | 1430 | h->use_weight_chroma= 0; |
| 1425 | return; | 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 | h->use_weight= 2; | 1443 | h->use_weight= 2; |
| 1429 | h->use_weight_chroma= 2; | 1444 | h->use_weight_chroma= 2; |
| 1430 | h->luma_log2_weight_denom= 5; | 1445 | h->luma_log2_weight_denom= 5; |
| 1431 | h->chroma_log2_weight_denom= 5; | 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 | int poc0 = h->ref_list[0][ref0].poc; | 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 | int poc1 = h->ref_list[1][ref1].poc; | 1451 | int poc1 = h->ref_list[1][ref1].poc; |
| 1437 | int td = av_clip(poc1 - poc0, -128, 127); | 1452 | int td = av_clip(poc1 - poc0, -128, 127); |
| 1438 | h->implicit_weight[ref0][ref1] = 32; | 1453 | int w= 32; |
| 1439 | if(td){ | 1454 | if(td){ |
| 1440 | int tb = av_clip(cur_poc - poc0, -128, 127); | 1455 | int tb = av_clip(cur_poc - poc0, -128, 127); |
| 1441 | int tx = (16384 + (FFABS(td) >> 1)) / td; | 1456 | int tx = (16384 + (FFABS(td) >> 1)) / td; |
| 1442 | int dist_scale_factor = (tb*tx + 32) >> 8; | 1457 | int dist_scale_factor = (tb*tx + 32) >> 8; |
| 1443 | if(dist_scale_factor >= -64 && dist_scale_factor <= 128) | 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,7 +2026,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ · 557 unmodified lines |
| 2005 | || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) ) | 2026 | || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) ) |
| 2006 | pred_weight_table(h); | 2027 | pred_weight_table(h); |
| 2007 | else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){ | 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 | }else { | 2030 | }else { |
| 2010 | h->use_weight = 0; | 2031 | h->use_weight = 0; |
| 2011 | for (i = 0; i < 2; i++) { | 2032 | for (i = 0; i < 2; i++) { |
| @@ -2017,9 +2038,15 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ · 5 unmodified lines |
| 2017 | if(h->nal_ref_idc) | 2038 | if(h->nal_ref_idc) |
| 2018 | ff_h264_decode_ref_pic_marking(h0, &s->gb); | 2039 | ff_h264_decode_ref_pic_marking(h0, &s->gb); |
| 2019 | | 2040 | |
| 2020 | if(FRAME_MBAFF) | 2041 | if(FRAME_MBAFF){ |
| 2021 | ff_h264_fill_mbaff_ref_list(h); | 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 | if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred) | 2050 | if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred) |
| 2024 | ff_h264_direct_dist_scale_factor(h); | 2051 | ff_h264_direct_dist_scale_factor(h); |
| 2025 | ff_h264_direct_ref_list_init(h); | 2052 | ff_h264_direct_ref_list_init(h); |