From 7e30bfcb9176880f06714e8ef83303d56b1eafea Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 3 May 2013 17:44:30 +0200 Subject: [PATCH] vc1dec: Fix mixed field/frame intensity compensation Fixes Ticket2523 Signed-off-by: Michael Niedermayer --- libavcodec/vc1dec.c | 58 +++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index c92364a38f..8edf731773 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -351,7 +351,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) int off, off_uv; int v_edge_pos = s->v_edge_pos >> v->field_mode; int i; - const uint8_t *luty, *lutuv; + uint8_t (*luty)[256], (*lutuv)[256]; int use_ic; if ((!v->field_mode || @@ -391,23 +391,23 @@ static void vc1_mc_1mv(VC1Context *v, int dir) srcY = s->current_picture.f.data[0]; srcU = s->current_picture.f.data[1]; srcV = s->current_picture.f.data[2]; - luty = v->curr_luty [v->ref_field_type[dir]]; - lutuv= v->curr_lutuv[v->ref_field_type[dir]]; + luty = v->curr_luty; + lutuv= v->curr_lutuv; use_ic=v->curr_use_ic; } else { srcY = s->last_picture.f.data[0]; srcU = s->last_picture.f.data[1]; srcV = s->last_picture.f.data[2]; - luty = v->last_luty [v->ref_field_type[dir]]; - lutuv= v->last_lutuv[v->ref_field_type[dir]]; + luty = v->last_luty ; + lutuv= v->last_lutuv; use_ic=v->last_use_ic; } } else { srcY = s->next_picture.f.data[0]; srcU = s->next_picture.f.data[1]; srcV = s->next_picture.f.data[2]; - luty = v->next_luty [v->ref_field_type[dir]]; - lutuv= v->next_lutuv[v->ref_field_type[dir]]; + luty = v->next_luty ; + lutuv= v->next_lutuv; use_ic=v->next_use_ic; } @@ -494,16 +494,18 @@ static void vc1_mc_1mv(VC1Context *v, int dir) src = srcY; for (j = 0; j < 17 + s->mspel * 2; j++) { + int f = v->field_mode ? v->ref_field_type[dir] : ((j + src_y - s->mspel)&1) ; for (i = 0; i < 17 + s->mspel * 2; i++) - src[i] = luty[src[i]]; + src[i] = luty[f][src[i]]; src += s->linesize; } src = srcU; src2 = srcV; for (j = 0; j < 9; j++) { + int f = v->field_mode ? v->ref_field_type[dir] : ((j + uvsrc_y)&1); for (i = 0; i < 9; i++) { - src[i] = lutuv[src[i]]; - src2[i] = lutuv[src2[i]]; + src[i] = lutuv[f][src[i]]; + src2[i] = lutuv[f][src2[i]]; } src += s->uvlinesize; src2 += s->uvlinesize; @@ -563,7 +565,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) int off; int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0; int v_edge_pos = s->v_edge_pos >> v->field_mode; - const uint8_t *luty; + uint8_t (*luty)[256]; int use_ic; if ((!v->field_mode || @@ -577,16 +579,16 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) if (!dir) { if (v->field_mode && (v->cur_field_type != v->ref_field_type[dir]) && v->second_field) { srcY = s->current_picture.f.data[0]; - luty = v->curr_luty[v->ref_field_type[dir]]; + luty = v->curr_luty; use_ic=v->curr_use_ic; } else { srcY = s->last_picture.f.data[0]; - luty = v->last_luty[v->ref_field_type[dir]]; + luty = v->last_luty; use_ic=v->last_use_ic; } } else { srcY = s->next_picture.f.data[0]; - luty = v->next_luty[v->ref_field_type[dir]]; + luty = v->next_luty; use_ic=v->next_use_ic; } @@ -719,8 +721,9 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) src = srcY; for (j = 0; j < 9 + s->mspel * 2; j++) { + int f = v->field_mode ? v->ref_field_type[dir] : (((j<mspel << fieldmv))&1); for (i = 0; i < 9 + s->mspel * 2; i++) - src[i] = luty[src[i]]; + src[i] = luty[f][src[i]]; src += s->linesize << fieldmv; } } @@ -808,7 +811,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) int valid_count; int chroma_ref_type = v->cur_field_type, off = 0; int v_edge_pos = s->v_edge_pos >> v->field_mode; - const uint8_t *lutuv; + uint8_t (*lutuv)[256]; int use_ic; if (!v->field_mode && !v->s.last_picture.f.data[0]) @@ -875,18 +878,18 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) if (v->field_mode && (v->cur_field_type != chroma_ref_type) && v->second_field) { srcU = s->current_picture.f.data[1]; srcV = s->current_picture.f.data[2]; - lutuv= v->curr_lutuv[chroma_ref_type]; + lutuv= v->curr_lutuv; use_ic=v->curr_use_ic; } else { srcU = s->last_picture.f.data[1]; srcV = s->last_picture.f.data[2]; - lutuv= v->last_lutuv[chroma_ref_type]; + lutuv= v->last_lutuv; use_ic=v->last_use_ic; } } else { srcU = s->next_picture.f.data[1]; srcV = s->next_picture.f.data[2]; - lutuv= v->next_lutuv[chroma_ref_type]; + lutuv= v->next_lutuv; use_ic=v->next_use_ic; } @@ -941,9 +944,10 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) src = srcU; src2 = srcV; for (j = 0; j < 9; j++) { + int f = v->field_mode ? chroma_ref_type : ((j + uvsrc_y)&1); for (i = 0; i < 9; i++) { - src[i] = lutuv[src[i]]; - src2[i] = lutuv[src2[i]]; + src[i] = lutuv[f][src[i]]; + src2[i] = lutuv[f][src2[i]]; } src += s->uvlinesize; src2 += s->uvlinesize; @@ -1992,23 +1996,25 @@ static void vc1_interp_mc(VC1Context *v) } if (use_ic) { - const uint8_t *luty = v->next_luty [v->ref_field_type[1]]; - const uint8_t *lutuv= v->next_lutuv[v->ref_field_type[1]]; + uint8_t (*luty )[256] = v->next_luty; + uint8_t (*lutuv)[256] = v->next_lutuv; int i, j; uint8_t *src, *src2; src = srcY; for (j = 0; j < 17 + s->mspel * 2; j++) { + int f = v->field_mode ? v->ref_field_type[1] : ((j+src_y - s->mspel)&1); for (i = 0; i < 17 + s->mspel * 2; i++) - src[i] = luty[src[i]]; + src[i] = luty[f][src[i]]; src += s->linesize; } src = srcU; src2 = srcV; for (j = 0; j < 9; j++) { + int f = v->field_mode ? v->ref_field_type[1] : ((j+uvsrc_y)&1); for (i = 0; i < 9; i++) { - src[i] = lutuv[src[i]]; - src2[i] = lutuv[src2[i]]; + src[i] = lutuv[f][src[i]]; + src2[i] = lutuv[f][src2[i]]; } src += s->uvlinesize; src2 += s->uvlinesize;