[08/15] vc1dec: Add avg & variable direction support to vc1_mc_4mv_chroma4()

Message ID 1369729571-75967-8-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö May 28, 2013, 8:26 a.m.
From: Michael Niedermayer <michaelni@gmx.at>

---
 libavcodec/vc1dec.c |   51 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 16 deletions(-)

Comments

Kostya Shishkov May 28, 2013, 9:37 a.m. | #1
On Tue, May 28, 2013 at 11:26:04AM +0300, Martin Storsjö wrote:
> From: Michael Niedermayer <michaelni@gmx.at>
 
I'd say that commit message can be improved and the motion compensation part
needs to be reindented, otherwise looks OK.
Martin Storsjö May 28, 2013, 9:50 a.m. | #2
On Tue, 28 May 2013, Kostya Shishkov wrote:

> On Tue, May 28, 2013 at 11:26:04AM +0300, Martin Storsjö wrote:
>> From: Michael Niedermayer <michaelni@gmx.at>
>
> I'd say that commit message can be improved and the motion compensation part
> needs to be reindented, otherwise looks OK.

Reindented the block that was left unindented, what would be a better 
commit message here?

"Add support for averaging and for specifying the direction to 
vc1_mc_4mv_chroma4()"?

// Martin
Kostya Shishkov May 28, 2013, 10:09 a.m. | #3
On Tue, May 28, 2013 at 12:50:03PM +0300, Martin Storsjö wrote:
> On Tue, 28 May 2013, Kostya Shishkov wrote:
> 
> >On Tue, May 28, 2013 at 11:26:04AM +0300, Martin Storsjö wrote:
> >>From: Michael Niedermayer <michaelni@gmx.at>
> >
> >I'd say that commit message can be improved and the motion compensation part
> >needs to be reindented, otherwise looks OK.
> 
> Reindented the block that was left unindented, what would be a
> better commit message here?
> 
> "Add support for averaging and for specifying the direction to
> vc1_mc_4mv_chroma4()"?

Handle top and bottom blocks in vc1_mc_4mv_chroma4() differently if needed.

And in expanded log message it would be good to mention what was changed
exactly, e.g.:

Now it can use different references for those blocks and even use averaging.

(I'm not good at composing commit messages myself).

Patch

diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 4f4ce5b..d956f7f 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,20 +1019,29 @@  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]];
+                const uint8_t *lutuv1 = lutuv[v->ref_field_type[i<2 ? dir : dir2]];
 
                 src  = srcU;
                 src2 = srcV;
                 for (j = 0; j < 5; j++) {
                     for (i = 0; i < 5; i++) {
-                        src[i]  = lutuv[src[i]];
-                        src2[i] = lutuv[src2[i]];
+                        src[i]  = lutuv1[src[i]];
+                        src2[i] = lutuv1[src2[i]];
                     }
                     src  += s->uvlinesize << 1;
                     src2 += s->uvlinesize << 1;
                 }
             }
         }
+        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 {
         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]);
@@ -1031,6 +1049,7 @@  static void vc1_mc_4mv_chroma4(VC1Context *v)
             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,7 @@  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);
                 } else {
                     vc1_mc_1mv(v, 0);
                     vc1_interp_mc(v);
@@ -4531,7 +4550,7 @@  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);
             } else if (bmvtype == BMV_TYPE_INTERPOLATED) {
                 mvbp = v->twomvbp;
                 dmv_x = dmv_y = 0;
@@ -4579,7 +4598,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, 0, 0, 0);
             } else {
                 dir = bmvtype == BMV_TYPE_BACKWARD;