From 3ced06f2838838574b4169969a816a7bad861915 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 24 Apr 2013 20:41:31 +0200 Subject: [PATCH 1/8] vc1dec: Implement intensity compensation for vc1_interp_mc() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index c47e3b043b..e43a3d209a 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -1899,6 +1899,7 @@ static void vc1_interp_mc(VC1Context *v) } if (v->rangeredfrm || s->h_edge_pos < 22 || v_edge_pos < 22 + || v->mv_mode == MV_PMODE_INTENSITY_COMP || (unsigned)(src_x - 1) > s->h_edge_pos - (mx & 3) - 16 - 3 || (unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) { uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; @@ -1937,6 +1938,30 @@ static void vc1_interp_mc(VC1Context *v) src2 += s->uvlinesize; } } + + if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + const uint8_t *luty = v->next_luty [v->ref_field_type[1]]; + const uint8_t *lutuv= v->next_lutuv[v->ref_field_type[1]]; + int i, j; + uint8_t *src, *src2; + + src = srcY; + for (j = 0; j < 17 + s->mspel * 2; j++) { + for (i = 0; i < 17 + s->mspel * 2; i++) + src[i] = luty[src[i]]; + src += s->linesize; + } + src = srcU; + src2 = srcV; + for (j = 0; j < 9; j++) { + for (i = 0; i < 9; i++) { + src[i] = lutuv[src[i]]; + src2[i] = lutuv[src2[i]]; + } + src += s->uvlinesize; + src2 += s->uvlinesize; + } + } srcY += s->mspel * (1 + s->linesize); } From 5053a9a1ffd907ae1d189c03c7e86bb375a44ded Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 24 Apr 2013 20:27:34 +0200 Subject: [PATCH 2/8] vc1: Use shuffled use_ic instead of equally shuffled mv_mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index e43a3d209a..01c3f5fa6c 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -349,6 +349,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) int v_edge_pos = s->v_edge_pos >> v->field_mode; int i; const uint8_t *luty, *lutuv; + int use_ic; if ((!v->field_mode || (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) && @@ -389,12 +390,14 @@ static void vc1_mc_1mv(VC1Context *v, int dir) 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]]; + 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]]; + use_ic = v->last_use_ic; } } else { srcY = s->next_picture.f.data[0]; @@ -402,6 +405,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) 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]]; + use_ic = v->next_use_ic; } src_x = s->mb_x * 16 + (mx >> 2); @@ -437,7 +441,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) srcV = s->edge_emu_buffer + 18 * s->linesize; } - if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) + if (v->rangeredfrm || use_ic || s->h_edge_pos < 22 || v_edge_pos < 22 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel * 3 || (unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) { @@ -478,7 +482,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) } } /* if we deal with intensity compensation we need to scale source blocks */ - if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + if (use_ic) { int i, j; uint8_t *src, *src2; @@ -552,6 +556,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) 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; + int use_ic; if ((!v->field_mode || (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) && @@ -565,13 +570,16 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) 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]]; + use_ic = v->curr_use_ic; } else { srcY = s->last_picture.f.data[0]; luty = v->last_luty[v->ref_field_type[dir]]; + use_ic = v->last_use_ic; } } else { srcY = s->next_picture.f.data[0]; luty = v->next_luty[v->ref_field_type[dir]]; + use_ic = v->next_use_ic; } if (v->field_mode) { @@ -668,7 +676,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) v_edge_pos--; if (fieldmv && (src_y & 1) && src_y < 4) src_y--; - if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) + if (v->rangeredfrm || use_ic || s->h_edge_pos < 13 || v_edge_pos < 23 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2 || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) { @@ -692,7 +700,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) } } /* if we deal with intensity compensation we need to scale source blocks */ - if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + if (use_ic) { int i, j; uint8_t *src; @@ -788,6 +796,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) int chroma_ref_type = v->cur_field_type; int v_edge_pos = s->v_edge_pos >> v->field_mode; const uint8_t *lutuv; + int use_ic; if (!v->field_mode && !v->s.last_picture.f.data[0]) return; @@ -854,15 +863,18 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) srcU = s->current_picture.f.data[1]; srcV = s->current_picture.f.data[2]; lutuv = v->curr_lutuv[chroma_ref_type]; + 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]; + 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]; + use_ic = v->next_use_ic; } srcU += uvsrc_y * s->uvlinesize + uvsrc_x; @@ -875,7 +887,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) } } - if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) + if (v->rangeredfrm || use_ic || s->h_edge_pos < 18 || v_edge_pos < 18 || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9 || (unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) { @@ -905,7 +917,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) } } /* if we deal with intensity compensation we need to scale source blocks */ - if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + if (use_ic) { int i, j; uint8_t *src, *src2; @@ -948,6 +960,7 @@ static void vc1_mc_4mv_chroma4(VC1Context *v) static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 }; int v_dist = fieldmv ? 1 : 4; // vertical offset for lower sub-blocks int v_edge_pos = s->v_edge_pos >> 1; + int use_ic = v->last_use_ic; if (!v->s.last_picture.f.data[0]) return; @@ -980,7 +993,7 @@ static void vc1_mc_4mv_chroma4(VC1Context *v) v_edge_pos--; if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2) uvsrc_y--; - if ((v->mv_mode == MV_PMODE_INTENSITY_COMP) + if (use_ic || s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv) || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5 || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) { @@ -994,7 +1007,7 @@ static void vc1_mc_4mv_chroma4(VC1Context *v) srcV = s->edge_emu_buffer + 16; /* if we deal with intensity compensation we need to scale source blocks */ - if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + if (use_ic) { int i, j; uint8_t *src, *src2; const uint8_t *lutuv = v->last_lutuv[v->ref_field_type[0]]; @@ -1844,6 +1857,7 @@ static void vc1_interp_mc(VC1Context *v) int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; int off, off_uv; int v_edge_pos = s->v_edge_pos >> v->field_mode; + int use_ic = v->next_use_ic; if (!v->field_mode && !v->s.next_picture.f.data[0]) return; @@ -1898,8 +1912,7 @@ static void vc1_interp_mc(VC1Context *v) srcV = s->edge_emu_buffer + 18 * s->linesize; } - if (v->rangeredfrm || s->h_edge_pos < 22 || v_edge_pos < 22 - || v->mv_mode == MV_PMODE_INTENSITY_COMP + if (v->rangeredfrm || s->h_edge_pos < 22 || v_edge_pos < 22 || use_ic || (unsigned)(src_x - 1) > s->h_edge_pos - (mx & 3) - 16 - 3 || (unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) { uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; @@ -1939,7 +1952,7 @@ static void vc1_interp_mc(VC1Context *v) } } - if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + 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]]; int i, j; From b412f705b58ececaeef4ca904b89f00612ac129e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 24 Apr 2013 21:56:34 +0200 Subject: [PATCH 3/8] vc1dec: Drop old use_ic code from vc1_b_mc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 01c3f5fa6c..fb0c5c288b 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -2034,31 +2034,18 @@ static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs) static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode) { - int use_ic = v->next_use_ic || v->curr_use_ic || v->last_use_ic; - if (use_ic) { - v->mv_mode2 = v->mv_mode; - v->mv_mode = MV_PMODE_INTENSITY_COMP; - } if (direct) { vc1_mc_1mv(v, 0); vc1_interp_mc(v); - if (use_ic) - v->mv_mode = v->mv_mode2; return; } if (mode == BMV_TYPE_INTERPOLATED) { vc1_mc_1mv(v, 0); vc1_interp_mc(v); - if (use_ic) - v->mv_mode = v->mv_mode2; return; } - if (use_ic && (mode == BMV_TYPE_BACKWARD)) - v->mv_mode = v->mv_mode2; vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD)); - if (use_ic) - v->mv_mode = v->mv_mode2; } static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], From c69765a2ccc66bd41f03470ba34899a16de9e2cb Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 25 Apr 2013 20:35:35 +0200 Subject: [PATCH 4/8] vc1dec: Fix doxy for vc1_mc_4mv_chroma4() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index fb0c5c288b..4f4ce5bbbd 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -946,7 +946,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) } } -/** Do motion compensation for 4-MV field chroma macroblock (both U and V) +/** Do motion compensation for 4-MV interlaced frame chroma macroblock (both U and V) */ static void vc1_mc_4mv_chroma4(VC1Context *v) { From 1be175f929b9a7429b2226ebb07a9a3a5b50256c Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 25 Apr 2013 21:30:41 +0200 Subject: [PATCH 5/8] vc1dec: Handle top and bottom blocks in vc1_mc_4mv_chroma4() differently if needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now it can use different references for those blocks and even use averaging. This fixes several chroma artifacts in several videos. Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 63 ++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 4f4ce5bbbd..c648929e1f 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -948,7 +948,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) /** Do motion compensation for 4-MV interlaced frame chroma macroblock (both U and V) */ -static void vc1_mc_4mv_chroma4(VC1Context *v) +static void vc1_mc_4mv_chroma4(VC1Context *v, int dir, int dir2, int avg) { MpegEncContext *s = &v->s; H264ChromaContext *h264chroma = &v->h264chroma; @@ -960,17 +960,17 @@ static void vc1_mc_4mv_chroma4(VC1Context *v) static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 }; int v_dist = fieldmv ? 1 : 4; // vertical offset for lower sub-blocks int v_edge_pos = s->v_edge_pos >> 1; - int use_ic = v->last_use_ic; + int use_ic; + uint8_t (*lutuv)[256]; - if (!v->s.last_picture.f.data[0]) - return; if (s->flags & CODEC_FLAG_GRAY) return; for (i = 0; i < 4; i++) { - tx = s->mv[0][i][0]; + int d = i < 2 ? dir: dir2; + tx = s->mv[d][i][0]; uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1; - ty = s->mv[0][i][1]; + ty = s->mv[d][i][1]; if (fieldmv) uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF]; else @@ -984,8 +984,17 @@ static void vc1_mc_4mv_chroma4(VC1Context *v) // FIXME: implement proper pull-back (see vc1cropmv.c, vc1CROPMV_ChromaPullBack()) uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); - srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; - srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; + if (i < 2 ? dir : dir2) { + srcU = s->next_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; + srcV = s->next_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; + lutuv = v->next_lutuv; + use_ic = v->next_use_ic; + } else { + srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; + srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; + lutuv = v->last_lutuv; + use_ic = v->last_use_ic; + } uvmx_field[i] = (uvmx_field[i] & 3) << 1; uvmy_field[i] = (uvmy_field[i] & 3) << 1; @@ -1010,26 +1019,36 @@ static void vc1_mc_4mv_chroma4(VC1Context *v) if (use_ic) { int i, j; uint8_t *src, *src2; - const uint8_t *lutuv = v->last_lutuv[v->ref_field_type[0]]; src = srcU; src2 = srcV; for (j = 0; j < 5; j++) { + int f = (uvsrc_y + (j << fieldmv)) & 1; for (i = 0; i < 5; 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 << 1; src2 += s->uvlinesize << 1; } } } - if (!v->rnd) { - h264chroma->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); - h264chroma->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + if (avg) { + if (!v->rnd) { + h264chroma->avg_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + h264chroma->avg_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + } else { + v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + } } else { - v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); - v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + if (!v->rnd) { + h264chroma->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + h264chroma->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + } else { + v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); + } } } } @@ -3845,7 +3864,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0); vc1_mc_4mv_luma(v, i, 0, 0); } else if (i == 4) { - vc1_mc_4mv_chroma4(v); + vc1_mc_4mv_chroma4(v, 0, 0, 0); } } } else if (twomv) { @@ -3864,7 +3883,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], 0); vc1_mc_4mv_luma(v, 2, 0, 0); vc1_mc_4mv_luma(v, 3, 0, 0); - vc1_mc_4mv_chroma4(v); + vc1_mc_4mv_chroma4(v, 0, 0, 0); } else { mvbp = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][2]; dmv_x = dmv_y = 0; @@ -4512,7 +4531,8 @@ static int vc1_decode_b_mb_intfr(VC1Context *v) vc1_mc_4mv_luma(v, i, 0, 0); vc1_mc_4mv_luma(v, i, 1, 1); } - vc1_mc_4mv_chroma4(v); + vc1_mc_4mv_chroma4(v, 0, 0, 0); + vc1_mc_4mv_chroma4(v, 1, 1, 1); } else { vc1_mc_1mv(v, 0); vc1_interp_mc(v); @@ -4531,7 +4551,8 @@ static int vc1_decode_b_mb_intfr(VC1Context *v) vc1_mc_4mv_luma(v, j+1, dir, dir); } - vc1_mc_4mv_chroma4(v); + vc1_mc_4mv_chroma4(v, 0, 0, 0); + vc1_mc_4mv_chroma4(v, 1, 1, 1); } else if (bmvtype == BMV_TYPE_INTERPOLATED) { mvbp = v->twomvbp; dmv_x = dmv_y = 0; @@ -4579,7 +4600,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v) vc1_mc_4mv_luma(v, 1, dir, 0); vc1_mc_4mv_luma(v, 2, dir2, 0); vc1_mc_4mv_luma(v, 3, dir2, 0); - vc1_mc_4mv_chroma4(v); + vc1_mc_4mv_chroma4(v, dir, dir2, 0); } else { dir = bmvtype == BMV_TYPE_BACKWARD; From 17410faa22a91cea82087395790faad745789fc8 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 24 Apr 2013 20:42:07 +0200 Subject: [PATCH 6/8] vc1dec: Match addressing between compensation and MC in vc1_mc_4mv_chroma4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index c648929e1f..2b3edc6725 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -1028,8 +1028,8 @@ static void vc1_mc_4mv_chroma4(VC1Context *v, int dir, int dir2, int avg) src[i] = lutuv[f][src[i]]; src2[i] = lutuv[f][src2[i]]; } - src += s->uvlinesize << 1; - src2 += s->uvlinesize << 1; + src += s->uvlinesize << fieldmv; + src2 += s->uvlinesize << fieldmv; } } } From d8b9dbe7768c958dc40d65450f6cc5740f1b46a7 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 3 May 2013 17:44:30 +0200 Subject: [PATCH 7/8] vc1dec: Fix mixed field/frame intensity compensation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/vc1dec.c | 58 +++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 2b3edc6725..42dc83f120 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -348,7 +348,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; 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 || @@ -388,23 +388,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; } @@ -488,16 +488,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; @@ -555,7 +557,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 || @@ -569,16 +571,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; } @@ -706,8 +708,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; } } @@ -795,7 +798,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) int valid_count; int chroma_ref_type = v->cur_field_type; 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]) @@ -862,18 +865,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; } @@ -924,9 +927,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; @@ -1972,23 +1976,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; From 728214992e3698305550c1762f973d2ac567f016 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 26 Apr 2013 03:44:05 +0200 Subject: [PATCH 8/8] vc1dec: Remove interlaced warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add a note about the feature in the changelog. Signed-off-by: Martin Storsjö --- Changelog | 1 + libavcodec/vc1.c | 3 --- libavcodec/vc1.h | 2 -- libavcodec/version.h | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index b8fbca2c4a..a20d62f864 100644 --- a/Changelog +++ b/Changelog @@ -21,6 +21,7 @@ version 10: - Apple Intermediate Codec decoder - Escape 130 video decoder - support for slice multithreading in libavfilter +- VC-1 interlaced B-frame support version 9: diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c index 7d09234f9b..d6586bfaeb 100644 --- a/libavcodec/vc1.c +++ b/libavcodec/vc1.c @@ -854,9 +854,6 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) if (fcm) { if (fcm == ILACE_FIELD) field_mode = 1; - if (!v->warn_interlaced++) - av_log(v->s.avctx, AV_LOG_ERROR, - "Interlaced frames/fields support is incomplete\n"); } } else { fcm = PROGRESSIVE; diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h index 8439203f88..0ece45a290 100644 --- a/libavcodec/vc1.h +++ b/libavcodec/vc1.h @@ -401,8 +401,6 @@ typedef struct VC1Context{ int end_mb_x; ///< Horizontal macroblock limit (used only by mss2) int parse_only; ///< Context is used within parser - - int warn_interlaced; } VC1Context; /** Find VC-1 marker in buffer diff --git a/libavcodec/version.h b/libavcodec/version.h index 5fd9bd2ff9..f3a2668e12 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #define LIBAVCODEC_VERSION_MAJOR 55 #define LIBAVCODEC_VERSION_MINOR 7 -#define LIBAVCODEC_VERSION_MICRO 0 +#define LIBAVCODEC_VERSION_MICRO 1 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \