Merge commit 'a84616b736fca5ebd6b87489dd41bc06ccdf7860'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 16 Oct 2013 11:54:41 +0000 (13:54 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 16 Oct 2013 11:54:41 +0000 (13:54 +0200)
* commit 'a84616b736fca5ebd6b87489dd41bc06ccdf7860':
  mpegvideo: K&R formatting cosmetics

Conflicts:
libavcodec/mpegvideo_motion.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/mpegvideo_motion.c

@@@ -40,85 -39,98 +40,94 @@@ static void gmc1_motion(MpegEncContext 
      uint8_t *ptr;
      int src_x, src_y, motion_x, motion_y;
      ptrdiff_t offset, linesize, uvlinesize;
-     int emu=0;
-     motion_x= s->sprite_offset[0][0];
-     motion_y= s->sprite_offset[0][1];
-     src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));
-     src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));
-     motion_x<<=(3-s->sprite_warping_accuracy);
-     motion_y<<=(3-s->sprite_warping_accuracy);
-     src_x = av_clip(src_x, -16, s->width);
+     int emu = 0;
+     motion_x   = s->sprite_offset[0][0];
+     motion_y   = s->sprite_offset[0][1];
+     src_x      = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
+     src_y      = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
+     motion_x <<= (3 - s->sprite_warping_accuracy);
+     motion_y <<= (3 - s->sprite_warping_accuracy);
+     src_x      = av_clip(src_x, -16, s->width);
      if (src_x == s->width)
-         motion_x =0;
+         motion_x = 0;
      src_y = av_clip(src_y, -16, s->height);
      if (src_y == s->height)
-         motion_y =0;
+         motion_y = 0;
  
-     linesize = s->linesize;
+     linesize   = s->linesize;
      uvlinesize = s->uvlinesize;
  
-     ptr = ref_picture[0] + (src_y * linesize) + src_x;
+     ptr = ref_picture[0] + src_y * linesize + src_x;
  
-         if(   (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0)
-            || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){
-             s->vdsp.emulated_edge_mc(s->edge_emu_buffer, linesize,
-                                      ptr, linesize, 17, 17, src_x, src_y,
 -    if (s->flags & CODEC_FLAG_EMU_EDGE) {
+         if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
+             (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
 -            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
++            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, linesize, ptr,
+                                      linesize,
+                                      17, 17,
+                                      src_x, src_y,
                                       s->h_edge_pos, s->v_edge_pos);
-             ptr= s->edge_emu_buffer;
+             ptr = s->edge_emu_buffer;
          }
 -    }
  
-     if((motion_x|motion_y)&7){
-         s->dsp.gmc1(dest_y  , ptr  , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
-         s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
-     }else{
+     if ((motion_x | motion_y) & 7) {
+         s->dsp.gmc1(dest_y, ptr, linesize, 16,
+                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+         s->dsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
+                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+     } else {
          int dxy;
  
-         dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
-         if (s->no_rounding){
+         dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
+         if (s->no_rounding) {
              s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
-         }else{
-             s->hdsp.put_pixels_tab       [0][dxy](dest_y, ptr, linesize, 16);
+         } else {
+             s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
          }
      }
  
-     if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
-     motion_x= s->sprite_offset[1][0];
-     motion_y= s->sprite_offset[1][1];
-     src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));
-     src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));
-     motion_x<<=(3-s->sprite_warping_accuracy);
-     motion_y<<=(3-s->sprite_warping_accuracy);
-     src_x = av_clip(src_x, -8, s->width>>1);
-     if (src_x == s->width>>1)
-         motion_x =0;
-     src_y = av_clip(src_y, -8, s->height>>1);
-     if (src_y == s->height>>1)
-         motion_y =0;
+     if (CONFIG_GRAY && s->flags & CODEC_FLAG_GRAY)
+         return;
+     motion_x   = s->sprite_offset[1][0];
+     motion_y   = s->sprite_offset[1][1];
+     src_x      = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
+     src_y      = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
+     motion_x <<= (3 - s->sprite_warping_accuracy);
+     motion_y <<= (3 - s->sprite_warping_accuracy);
+     src_x      = av_clip(src_x, -8, s->width >> 1);
+     if (src_x == s->width >> 1)
+         motion_x = 0;
+     src_y = av_clip(src_y, -8, s->height >> 1);
+     if (src_y == s->height >> 1)
+         motion_y = 0;
  
      offset = (src_y * uvlinesize) + src_x;
-     ptr = ref_picture[1] + offset;
-         if(   (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0)
-            || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){
+     ptr    = ref_picture[1] + offset;
 -    if (s->flags & CODEC_FLAG_EMU_EDGE) {
+         if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
+             (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
 -            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
 -                                     uvlinesize,
 +            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, uvlinesize,
-                                      ptr, uvlinesize, 9, 9, src_x, src_y,
-                                      s->h_edge_pos>>1, s->v_edge_pos>>1);
-             ptr= s->edge_emu_buffer;
-             emu=1;
++                                     ptr, uvlinesize,
+                                      9, 9,
+                                      src_x, src_y,
+                                      s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+             ptr = s->edge_emu_buffer;
+             emu = 1;
          }
-     s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
 -    }
+     s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8,
+                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
  
      ptr = ref_picture[2] + offset;
-     if(emu){
+     if (emu) {
 -        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
 -                                 uvlinesize,
 +        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, uvlinesize,
-                                  ptr, uvlinesize, 9, 9, src_x, src_y,
-                                  s->h_edge_pos>>1, s->v_edge_pos>>1);
-         ptr= s->edge_emu_buffer;
++                                 ptr, uvlinesize,
+                                  9, 9,
+                                  src_x, src_y,
+                                  s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+         ptr = s->edge_emu_buffer;
      }
-     s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
-     return;
+     s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8,
+                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
  }
  
  static void gmc_motion(MpegEncContext *s,
@@@ -198,14 -212,16 +209,16 @@@ static inline int hpel_motion(MpegEncCo
          dxy |= (motion_y & 1) << 1;
      src += src_y * s->linesize + src_x;
  
-     if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){
-         if(   (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 8, 0)
-            || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&1) - 8, 0)){
-             s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
-                                      src, s->linesize, 9, 9,
-                                      src_x, src_y, s->h_edge_pos, s->v_edge_pos);
-             src= s->edge_emu_buffer;
-             emu=1;
+     if (s->unrestricted_mv && (s->flags & CODEC_FLAG_EMU_EDGE)) {
+         if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 8, 0) ||
+             (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 1) - 8, 0)) {
 -            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
++            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, src,
+                                      s->linesize,
+                                      9, 9,
 -                                     src_x, src_y, s->h_edge_pos,
 -                                     s->v_edge_pos);
++                                     src_x, src_y,
++                                     s->h_edge_pos, s->v_edge_pos);
+             src = s->edge_emu_buffer;
+             emu = 1;
          }
      }
      pix_op[dxy](dest, src, s->linesize, 8);
@@@ -285,46 -310,51 +307,51 @@@ void mpeg_motion_internal(MpegEncContex
      ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
      ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
  
-     if(   (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 16, 0)
-        || (unsigned)src_y > FFMAX(   v_edge_pos - (motion_y&1) - h , 0)){
-             if(is_mpeg12 || s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
-                s->codec_id == AV_CODEC_ID_MPEG1VIDEO){
-                 av_log(s->avctx,AV_LOG_DEBUG,
-                         "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y);
-                 return;
-             }
-             s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
-                                      ptr_y, s->linesize, 17, 17+field_based,
-                                      src_x, src_y<<field_based,
-                                      s->h_edge_pos, s->v_edge_pos);
-             ptr_y = s->edge_emu_buffer;
-             if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
-                 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
-                 s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize,
-                                     ptr_cb, s->uvlinesize,
-                                     9, 9+field_based,
-                                     uvsrc_x, uvsrc_y<<field_based,
-                                     s->h_edge_pos>>1, s->v_edge_pos>>1);
-                 s->vdsp.emulated_edge_mc(uvbuf+16, s->uvlinesize,
-                                     ptr_cr, s->uvlinesize,
-                                     9, 9+field_based,
-                                     uvsrc_x, uvsrc_y<<field_based,
-                                     s->h_edge_pos>>1, s->v_edge_pos>>1);
-                 ptr_cb= uvbuf;
-                 ptr_cr= uvbuf+16;
-             }
+     if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 16, 0) ||
 -        (unsigned)src_y > FFMAX(v_edge_pos - (motion_y & 1) - h, 0)) {
++        (unsigned)src_y > FFMAX(   v_edge_pos - (motion_y & 1) - h , 0)) {
+         if (is_mpeg12 ||
+             s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+             s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
+             av_log(s->avctx, AV_LOG_DEBUG,
+                    "MPEG motion vector out of boundary (%d %d)\n", src_x,
+                    src_y);
+             return;
+         }
 -        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,
++        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, ptr_y,
+                                  s->linesize,
+                                  17, 17 + field_based,
+                                  src_x, src_y << field_based,
+                                  s->h_edge_pos, s->v_edge_pos);
+         ptr_y = s->edge_emu_buffer;
+         if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
+             uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize;
 -            s->vdsp.emulated_edge_mc(uvbuf, ptr_cb,
++            s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize, ptr_cb,
+                                      s->uvlinesize,
+                                      9, 9 + field_based,
+                                      uvsrc_x, uvsrc_y << field_based,
+                                      s->h_edge_pos >> 1, s->v_edge_pos >> 1);
 -            s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr,
++            s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize, ptr_cr,
+                                      s->uvlinesize,
+                                      9, 9 + field_based,
+                                      uvsrc_x, uvsrc_y << field_based,
+                                      s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+             ptr_cb = uvbuf;
+             ptr_cr = uvbuf + 16;
+         }
      }
  
-     if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
-         dest_y += s->linesize;
-         dest_cb+= s->uvlinesize;
-         dest_cr+= s->uvlinesize;
+     /* FIXME use this for field pix too instead of the obnoxious hack which
+      * changes picture.data */
+     if (bottom_field) {
+         dest_y  += s->linesize;
+         dest_cb += s->uvlinesize;
+         dest_cr += s->uvlinesize;
      }
  
-     if(field_select){
-         ptr_y += s->linesize;
-         ptr_cb+= s->uvlinesize;
-         ptr_cr+= s->uvlinesize;
+     if (field_select) {
+         ptr_y  += s->linesize;
+         ptr_cb += s->uvlinesize;
+         ptr_cr += s->uvlinesize;
      }
  
      pix_op[0][dxy](dest_y, ptr_y, linesize, h);
@@@ -367,10 -397,10 +394,10 @@@ static void mpeg_motion_field(MpegEncCo
                                int motion_x, int motion_y, int h, int mb_y)
  {
  #if !CONFIG_SMALL
--    if(s->out_format == FMT_MPEG1)
++    if (s->out_format == FMT_MPEG1)
          mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1,
-                     bottom_field, field_select, ref_picture, pix_op,
-                     motion_x, motion_y, h, 1, mb_y);
+                              bottom_field, field_select, ref_picture, pix_op,
+                              motion_x, motion_y, h, 1, mb_y);
      else
  #endif
          mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1,
@@@ -441,16 -472,15 +469,15 @@@ static inline void obmc_motion(MpegEncC
      int i;
      uint8_t *ptr[5];
  
-     av_assert2(s->quarter_sample==0);
 -    assert(s->quarter_sample == 0);
++    av_assert2(s->quarter_sample == 0);
  
-     for(i=0; i<5; i++){
-         if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){
-             ptr[i]= ptr[MID];
-         }else{
-             ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1);
-             hpel_motion(s, ptr[i], src,
-                         src_x, src_y,
-                         pix_op,
+     for (i = 0; i < 5; i++) {
+         if (i && mv[i][0] == mv[MID][0] && mv[i][1] == mv[MID][1]) {
+             ptr[i] = ptr[MID];
+         } else {
+             ptr[i] = s->obmc_scratchpad + 8 * (i & 1) +
+                      s->linesize * 8 * (i >> 1);
+             hpel_motion(s, ptr[i], src, src_x, src_y, pix_op,
                          mv[i][0], mv[i][1]);
          }
      }
@@@ -505,27 -539,28 +536,31 @@@ static inline void qpel_motion(MpegEncC
      ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
      ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
  
-     if(   (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0)
-        || (unsigned)src_y > FFMAX(   v_edge_pos - (motion_y&3) - h , 0)){
-         s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
+     if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 3) - 16, 0) ||
 -        (unsigned)src_y > FFMAX(v_edge_pos - (motion_y & 3) - h, 0)) {
 -        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,
++        (unsigned)src_y > FFMAX(   v_edge_pos - (motion_y & 3) - h, 0)) {
++        s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
+                                  s->linesize,
 +                                 ptr_y, s->linesize,
-                                  17, 17+field_based, src_x, src_y<<field_based,
+                                  17, 17 + field_based,
+                                  src_x, src_y << field_based,
                                   s->h_edge_pos, s->v_edge_pos);
-         ptr_y= s->edge_emu_buffer;
-         if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
-             uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
+         ptr_y = s->edge_emu_buffer;
+         if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
+             uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize;
 -            s->vdsp.emulated_edge_mc(uvbuf, ptr_cb,
 +            s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize,
-                                      ptr_cb, s->uvlinesize,
++                                     ptr_cb,
+                                      s->uvlinesize,
                                       9, 9 + field_based,
-                                      uvsrc_x, uvsrc_y<<field_based,
-                                      s->h_edge_pos>>1, s->v_edge_pos>>1);
+                                      uvsrc_x, uvsrc_y << field_based,
+                                      s->h_edge_pos >> 1, s->v_edge_pos >> 1);
 -            s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr,
 +            s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize,
-                                      ptr_cr, s->uvlinesize,
++                                     ptr_cr,
+                                      s->uvlinesize,
                                       9, 9 + field_based,
-                                      uvsrc_x, uvsrc_y<<field_based,
-                                      s->h_edge_pos>>1, s->v_edge_pos>>1);
-             ptr_cb= uvbuf;
-             ptr_cr= uvbuf + 16;
+                                      uvsrc_x, uvsrc_y << field_based,
+                                      s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+             ptr_cb = uvbuf;
+             ptr_cr = uvbuf + 16;
          }
      }
  
@@@ -586,25 -621,27 +621,27 @@@ static void chroma_4mv_motion(MpegEncCo
          dxy &= ~2;
  
      offset = src_y * s->uvlinesize + src_x;
-     ptr = ref_picture[1] + offset;
-     if(s->flags&CODEC_FLAG_EMU_EDGE){
-         if(   (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0)
-            || (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){
+     ptr    = ref_picture[1] + offset;
+     if (s->flags & CODEC_FLAG_EMU_EDGE) {
+         if ((unsigned)src_x > FFMAX((s->h_edge_pos >> 1) - (dxy & 1) - 8, 0) ||
+             (unsigned)src_y > FFMAX((s->v_edge_pos >> 1) - (dxy >> 1) - 8, 0)) {
 -            s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
 +            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
-                                      ptr, s->uvlinesize, 9, 9, src_x, src_y,
-                                      s->h_edge_pos>>1, s->v_edge_pos>>1);
-             ptr= s->edge_emu_buffer;
-             emu=1;
+                                      ptr, s->uvlinesize,
+                                      9, 9, src_x, src_y,
+                                      s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+             ptr = s->edge_emu_buffer;
+             emu = 1;
          }
      }
      pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8);
  
      ptr = ref_picture[2] + offset;
-     if(emu){
+     if (emu) {
 -        s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
 +        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
-                                  ptr, s->uvlinesize, 9, 9, src_x, src_y,
-                                  s->h_edge_pos>>1, s->v_edge_pos>>1);
-         ptr= s->edge_emu_buffer;
+                                  ptr, s->uvlinesize,
+                                  9, 9, src_x, src_y,
+                                  s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+         ptr = s->edge_emu_buffer;
      }
      pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
  }
@@@ -649,23 -691,27 +691,27 @@@ static av_always_inline void MPV_motion
  
      prefetch_motion(s, ref_picture, dir);
  
-     if(!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B){
+     if (!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B) {
          LOCAL_ALIGNED_8(int16_t, mv_cache, [4], [4][2]);
-         Picture *cur_frame = &s->current_picture;
-         const int xy= s->mb_x + s->mb_y*s->mb_stride;
-         const int mot_stride= s->b8_stride;
-         const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
+         Picture *cur_frame   = &s->current_picture;
+         const int xy         = s->mb_x + s->mb_y * s->mb_stride;
+         const int mot_stride = s->b8_stride;
+         const int mot_xy     = mb_x * 2 + mb_y * 2 * mot_stride;
  
 -        assert(!s->mb_skipped);
 +        av_assert2(!s->mb_skipped);
  
-         AV_COPY32(mv_cache[1][1], cur_frame->motion_val[0][mot_xy    ]);
+         AV_COPY32(mv_cache[1][1], cur_frame->motion_val[0][mot_xy]);
          AV_COPY32(mv_cache[1][2], cur_frame->motion_val[0][mot_xy + 1]);
  
-         AV_COPY32(mv_cache[2][1], cur_frame->motion_val[0][mot_xy + mot_stride    ]);
-         AV_COPY32(mv_cache[2][2], cur_frame->motion_val[0][mot_xy + mot_stride + 1]);
+         AV_COPY32(mv_cache[2][1],
+                   cur_frame->motion_val[0][mot_xy + mot_stride]);
+         AV_COPY32(mv_cache[2][2],
+                   cur_frame->motion_val[0][mot_xy + mot_stride + 1]);
  
-         AV_COPY32(mv_cache[3][1], cur_frame->motion_val[0][mot_xy + mot_stride    ]);
-         AV_COPY32(mv_cache[3][2], cur_frame->motion_val[0][mot_xy + mot_stride + 1]);
+         AV_COPY32(mv_cache[3][1],
+                   cur_frame->motion_val[0][mot_xy + mot_stride]);
+         AV_COPY32(mv_cache[3][2],
+                   cur_frame->motion_val[0][mot_xy + mot_stride + 1]);
  
          if (mb_y == 0 || IS_INTRA(cur_frame->mb_type[xy - s->mb_stride])) {
              AV_COPY32(mv_cache[0][1], mv_cache[1][1]);
          }
          break;
      case MV_TYPE_8X8:
-     if (!is_mpeg12) {
-         mx = 0;
-         my = 0;
-         if(s->quarter_sample){
-             for(i=0;i<4;i++) {
-                 motion_x = s->mv[dir][i][0];
-                 motion_y = s->mv[dir][i][1];
-                 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
-                 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
-                 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
-                 /* WARNING: do no forget half pels */
-                 src_x = av_clip(src_x, -16, s->width);
-                 if (src_x == s->width)
-                     dxy &= ~3;
-                 src_y = av_clip(src_y, -16, s->height);
-                 if (src_y == s->height)
-                     dxy &= ~12;
-                 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
-                 if(s->flags&CODEC_FLAG_EMU_EDGE){
-                     if(   (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0)
-                        || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){
-                         s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
-                                                  ptr, s->linesize, 9, 9,
-                                                  src_x, src_y,
-                                                  s->h_edge_pos, s->v_edge_pos);
-                         ptr= s->edge_emu_buffer;
+         if (!is_mpeg12) {
+             mx = 0;
+             my = 0;
+             if (s->quarter_sample) {
+                 for (i = 0; i < 4; i++) {
+                     motion_x = s->mv[dir][i][0];
+                     motion_y = s->mv[dir][i][1];
+                     dxy   = ((motion_y & 3) << 2) | (motion_x & 3);
+                     src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
+                     src_y = mb_y * 16 + (motion_y >> 2) + (i >> 1) * 8;
+                     /* WARNING: do no forget half pels */
+                     src_x = av_clip(src_x, -16, s->width);
+                     if (src_x == s->width)
+                         dxy &= ~3;
+                     src_y = av_clip(src_y, -16, s->height);
+                     if (src_y == s->height)
 -                        dxy &= ~12;
++                            dxy &= ~12;
+                     ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
+                     if (s->flags & CODEC_FLAG_EMU_EDGE) {
+                         if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 3) - 8, 0) ||
+                             (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 3) - 8, 0)) {
 -                            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
++                            s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
++                                                     s->linesize, ptr,
+                                                      s->linesize,
+                                                      9, 9,
+                                                      src_x, src_y,
+                                                      s->h_edge_pos,
+                                                      s->v_edge_pos);
+                             ptr = s->edge_emu_buffer;
+                         }
                      }
-                 }
-                 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
-                 qpix_op[1][dxy](dest, ptr, s->linesize);
+                     dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
+                     qpix_op[1][dxy](dest, ptr, s->linesize);
  
-                 mx += s->mv[dir][i][0]/2;
-                 my += s->mv[dir][i][1]/2;
-             }
-         }else{
-             for(i=0;i<4;i++) {
-                 hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
-                             ref_picture[0],
-                             mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
-                             pix_op[1],
-                             s->mv[dir][i][0], s->mv[dir][i][1]);
-                 mx += s->mv[dir][i][0];
-                 my += s->mv[dir][i][1];
+                     mx += s->mv[dir][i][0] / 2;
+                     my += s->mv[dir][i][1] / 2;
+                 }
+             } else {
+                 for (i = 0; i < 4; i++) {
+                     hpel_motion(s,
+                                 dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
+                                 ref_picture[0],
+                                 mb_x * 16 + (i & 1) * 8,
+                                 mb_y * 16 + (i >> 1) * 8,
+                                 pix_op[1],
+                                 s->mv[dir][i][0],
+                                 s->mv[dir][i][1]);
+                     mx += s->mv[dir][i][0];
+                     my += s->mv[dir][i][1];
+                 }
              }
-         }
  
-         if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY))
-             chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
-     }
+             if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY))
+                 chroma_4mv_motion(s, dest_cb, dest_cr,
+                                   ref_picture, pix_op[1], mx, my);
+         }
          break;
      case MV_TYPE_FIELD:
          if (s->picture_structure == PICT_FRAME) {
                                    s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y);
              }
          } else {
-             if(   s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field
-                || !ref_picture[0]){
 -            if (s->picture_structure != s->field_select[dir][0] + 1 &&
 -                s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
++            if (   s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field
++                || !ref_picture[0]) {
                  ref_picture = s->current_picture_ptr->f.data;
              }
  
          }
          break;
      case MV_TYPE_16X8:
-         for(i=0; i<2; i++){
-             uint8_t ** ref2picture;
+         for (i = 0; i < 2; i++) {
+             uint8_t **ref2picture;
  
-             if((s->picture_structure == s->field_select[dir][i] + 1
-                || s->pict_type == AV_PICTURE_TYPE_B || s->first_field) && ref_picture[0]){
-                 ref2picture= ref_picture;
-             }else{
 -            if (s->picture_structure == s->field_select[dir][i] + 1
 -                || s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
++            if ((s->picture_structure == s->field_select[dir][i] + 1
++                || s->pict_type == AV_PICTURE_TYPE_B || s->first_field) && ref_picture[0]) {
+                 ref2picture = ref_picture;
+             } else {
                  ref2picture = s->current_picture_ptr->f.data;
              }
  
          }
          break;
      case MV_TYPE_DMV:
-         if(s->picture_structure == PICT_FRAME){
-             for(i=0; i<2; i++){
+         if (s->picture_structure == PICT_FRAME) {
+             for (i = 0; i < 2; i++) {
                  int j;
-                 for(j=0; j<2; j++){
+                 for (j = 0; j < 2; j++)
                      mpeg_motion_field(s, dest_y, dest_cb, dest_cr,
-                                       j, j^i, ref_picture, pix_op,
-                                       s->mv[dir][2*i + j][0],
-                                       s->mv[dir][2*i + j][1], 8, mb_y);
-                 }
+                                       j, j ^ i, ref_picture, pix_op,
+                                       s->mv[dir][2 * i + j][0],
+                                       s->mv[dir][2 * i + j][1], 8, mb_y);
                  pix_op = s->hdsp.avg_pixels_tab;
              }
-         }else{
+         } else {
 +            if (!ref_picture[0]) {
 +                ref_picture = s->current_picture_ptr->f.data;
 +            }
-             for(i=0; i<2; i++){
+             for (i = 0; i < 2; i++) {
                  mpeg_motion(s, dest_y, dest_cb, dest_cr,
-                             s->picture_structure != i+1,
+                             s->picture_structure != i + 1,
                              ref_picture, pix_op,
-                             s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1);
+                             s->mv[dir][2 * i][0], s->mv[dir][2 * i][1],
+                             16, mb_y >> 1);
  
                  // after put we make avg of the same block
-                 pix_op=s->hdsp.avg_pixels_tab;
+                 pix_op = s->hdsp.avg_pixels_tab;
  
-                 //opposite parity is always in the same frame if this is second field
-                 if(!s->first_field){
+                 /* opposite parity is always in the same frame if this is
+                  * second field */
+                 if (!s->first_field) {
                      ref_picture = s->current_picture_ptr->f.data;
                  }
              }
          }
-     break;
+         break;
 -    default: assert(0);
 +    default: av_assert2(0);
      }
  }