From 0d194ee51ed477f843900e657a7edbcbecdffa42 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 1 Feb 2013 19:58:26 +0100 Subject: [PATCH] vc1dec: Fix destination pointers in context for fields This replaces a large number of checks for the second field by fixing the pointers when they are setup This should also fix I/BI field pictures Changes checksums for vc1_sa10143, the file becomes slightly closer to what the reference decoder outputs Based on "vc1dec: the second field is written wrong to the picture" by Sebastian Sandberg Signed-off-by: Michael Niedermayer --- libavcodec/vc1dec.c | 48 +++++++++++++++++--------------------- tests/ref/fate/vc1_sa10143 | 28 +++++++++++----------- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 013e96b107..b4e89c6663 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -74,6 +74,17 @@ enum Imode { }; /** @} */ //imode defines +static void init_block_index(VC1Context *v) +{ + MpegEncContext *s = &v->s; + ff_init_block_index(s); + if (v->field_mode && v->second_field) { + s->dest[0] += s->current_picture_ptr->f.linesize[0]; + s->dest[1] += s->current_picture_ptr->f.linesize[1]; + s->dest[2] += s->current_picture_ptr->f.linesize[2]; + } +} + /** @} */ //Bitplane group @@ -500,13 +511,8 @@ static void vc1_mc_1mv(VC1Context *v, int dir) srcY += s->mspel * (1 + s->linesize); } - if (v->field_mode && v->second_field) { - off = s->current_picture_ptr->f.linesize[0]; - off_uv = s->current_picture_ptr->f.linesize[1]; - } else { off = 0; off_uv = 0; - } if (s->mspel) { dxy = ((my & 3) << 2) | (mx & 3); v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd); @@ -642,8 +648,6 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir) off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8; else off = s->linesize * 4 * (n & 2) + (n & 1) * 8; - if (v->field_mode && v->second_field) - off += s->current_picture_ptr->f.linesize[0]; src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2); if (!fieldmv) @@ -880,7 +884,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) srcU += s->current_picture_ptr->f.linesize[1]; srcV += s->current_picture_ptr->f.linesize[2]; } - off = v->second_field ? s->current_picture_ptr->f.linesize[1] : 0; + off = 0; } if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) @@ -1951,13 +1955,8 @@ static void vc1_interp_mc(VC1Context *v) srcY += s->mspel * (1 + s->linesize); } - if (v->field_mode && v->second_field) { - off = s->current_picture_ptr->f.linesize[0]; - off_uv = s->current_picture_ptr->f.linesize[1]; - } else { off = 0; off_uv = 0; - } if (s->mspel) { dxy = ((my & 3) << 2) | (mx & 3); @@ -3961,7 +3960,6 @@ static int vc1_decode_p_mb_intfi(VC1Context *v) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); - off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0; s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize); // TODO: loop filter } @@ -4008,8 +4006,6 @@ static int vc1_decode_p_mb_intfi(VC1Context *v) dst_idx += i >> 2; val = ((cbp >> (5 - i)) & 1); off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize; - if (v->second_field) - off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]; if (val) { pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, @@ -4238,7 +4234,6 @@ static void vc1_decode_b_mb_intfi(VC1Context *v) for (j = 0; j < 64; j++) s->block[i][j] <<= 1; off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); - off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0; s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize); // TODO: yet to perform loop filter } @@ -4320,8 +4315,6 @@ static void vc1_decode_b_mb_intfi(VC1Context *v) dst_idx += i >> 2; val = ((cbp >> (5 - i)) & 1); off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize; - if (v->second_field) - off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]; if (val) { vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, @@ -4380,7 +4373,7 @@ static void vc1_decode_i_blocks(VC1Context *v) s->first_slice_line = 1; for (s->mb_y = 0; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); for (; s->mb_x < v->end_mb_x; s->mb_x++) { uint8_t *dst[6]; ff_update_block_index(s); @@ -4520,13 +4513,13 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) s->mb_y = s->start_mb_y; if (s->start_mb_y) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0, (1 + s->b8_stride) * sizeof(*s->coded_block)); } for (; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); for (;s->mb_x < s->mb_width; s->mb_x++) { int16_t (*block)[64] = v->block[v->cur_blk_idx]; ff_update_block_index(s); @@ -4597,7 +4590,8 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) /* raw bottom MB row */ s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); + for (;s->mb_x < s->mb_width; s->mb_x++) { ff_update_block_index(s); vc1_put_signed_blocks_clamped(v); @@ -4645,7 +4639,7 @@ static void vc1_decode_p_blocks(VC1Context *v) memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride); for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); for (; s->mb_x < s->mb_width; s->mb_x++) { ff_update_block_index(s); @@ -4673,7 +4667,7 @@ static void vc1_decode_p_blocks(VC1Context *v) } if (apply_loop_filter && v->fcm == PROGRESSIVE) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); for (; s->mb_x < s->mb_width; s->mb_x++) { ff_update_block_index(s); vc1_apply_p_loop_filter(v); @@ -4717,7 +4711,7 @@ static void vc1_decode_b_blocks(VC1Context *v) s->first_slice_line = 1; for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); for (; s->mb_x < s->mb_width; s->mb_x++) { ff_update_block_index(s); @@ -4754,7 +4748,7 @@ static void vc1_decode_skip_blocks(VC1Context *v) s->first_slice_line = 1; for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; - ff_init_block_index(s); + init_block_index(v); ff_update_block_index(s); if (s->last_picture.f.data[0]) { memcpy(s->dest[0], s->last_picture.f.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16); diff --git a/tests/ref/fate/vc1_sa10143 b/tests/ref/fate/vc1_sa10143 index 0d2e697989..6a5137f712 100644 --- a/tests/ref/fate/vc1_sa10143 +++ b/tests/ref/fate/vc1_sa10143 @@ -1,31 +1,31 @@ #tb 0: 1/25 0, 0, 0, 1, 518400, 0x89407f55 -0, 2, 2, 1, 518400, 0x1480849d +0, 2, 2, 1, 518400, 0x8611849c 0, 3, 3, 1, 518400, 0x0e69ff59 -0, 4, 4, 1, 518400, 0x00d6db06 +0, 4, 4, 1, 518400, 0xf31adb03 0, 5, 5, 1, 518400, 0x1a5b6a69 -0, 6, 6, 1, 518400, 0xc1a1232e +0, 6, 6, 1, 518400, 0x6ae6232e 0, 7, 7, 1, 518400, 0x9a4e3c54 -0, 8, 8, 1, 518400, 0x04122b44 +0, 8, 8, 1, 518400, 0xe5852b45 0, 9, 9, 1, 518400, 0x0fcfeebc -0, 10, 10, 1, 518400, 0xc7882dc1 +0, 10, 10, 1, 518400, 0x06e22dc3 0, 11, 11, 1, 518400, 0x9d79df09 -0, 12, 12, 1, 518400, 0xff6b716f +0, 12, 12, 1, 518400, 0xcb2c716f 0, 13, 13, 1, 518400, 0x638a8746 -0, 14, 14, 1, 518400, 0x07572efb +0, 14, 14, 1, 518400, 0xf7032efd 0, 15, 15, 1, 518400, 0x306f6cef -0, 16, 16, 1, 518400, 0xd7602518 +0, 16, 16, 1, 518400, 0xe83d2518 0, 17, 17, 1, 518400, 0x49ab5bf5 -0, 18, 18, 1, 518400, 0x3c736b6c +0, 18, 18, 1, 518400, 0x6b336b6f 0, 19, 19, 1, 518400, 0x95ae00c9 -0, 20, 20, 1, 518400, 0x7b9ab64e +0, 20, 20, 1, 518400, 0x68ddb64f 0, 21, 21, 1, 518400, 0x5205ea68 -0, 22, 22, 1, 518400, 0xb486e618 +0, 22, 22, 1, 518400, 0xb088e617 0, 23, 23, 1, 518400, 0xa3217616 -0, 24, 24, 1, 518400, 0xc66bbc56 +0, 24, 24, 1, 518400, 0x1723bc53 0, 25, 25, 1, 518400, 0xf024872a -0, 26, 26, 1, 518400, 0x97d2a8ba +0, 26, 26, 1, 518400, 0x2e81a8bb 0, 27, 27, 1, 518400, 0xa3a2418e -0, 28, 28, 1, 518400, 0x08460005 +0, 28, 28, 1, 518400, 0xb7beffed 0, 29, 29, 1, 518400, 0x50fb6c94 0, 30, 30, 1, 518400, 0x5584bb40