]> git.sesse.net Git - x264/blobdiff - common/mvpred.c
Add support for the new (4:4:4) colorspaces to x264_picture_alloc
[x264] / common / mvpred.c
index f8ec0c7b95b0871e47334a3f4fa9bc0d48b0dd0f..782445aa135035c92c1fd3a9f35c3c5b936f8135 100644 (file)
@@ -44,9 +44,9 @@ void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int16_t mv
         i_refc = h->mb.cache.ref[i_list][i8 - 8 - 1];
         mv_c   = h->mb.cache.mv[i_list][i8 - 8 - 1];
 
-        if( h->sh.b_mbaff
+        if( SLICE_MBAFF
             && h->mb.cache.ref[i_list][x264_scan8[0]-1] != -2
-            && h->mb.b_interlaced != h->mb.field[h->mb.i_mb_left_xy[0]] )
+            && MB_INTERLACED != h->mb.field[h->mb.i_mb_left_xy[0]] )
         {
             if( idx == 2 )
             {
@@ -187,14 +187,14 @@ static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
     int mb_xy = h->mb.i_mb_xy;
     int type_col[2] = { h->fref[1][0]->mb_type[mb_xy], h->fref[1][0]->mb_type[mb_xy] };
     int partition_col[2] = { h->fref[1][0]->mb_partition[mb_xy], h->fref[1][0]->mb_partition[mb_xy] };
-    int preshift = h->mb.b_interlaced;
-    int postshift = h->mb.b_interlaced;
+    int preshift = MB_INTERLACED;
+    int postshift = MB_INTERLACED;
     int offset = 1;
     int yshift = 1;
     h->mb.i_partition = partition_col[0];
-    if( h->param.b_interlaced && h->fref[1][0]->field[mb_xy] != h->mb.b_interlaced )
+    if( PARAM_INTERLACED && h->fref[1][0]->field[mb_xy] != MB_INTERLACED )
     {
-        if( h->mb.b_interlaced )
+        if( MB_INTERLACED )
         {
             mb_y = h->mb.i_mb_y&~1;
             mb_xy = mb_x + h->mb.i_mb_stride * mb_y;
@@ -214,7 +214,7 @@ static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
         }
         else
         {
-            int cur_poc = h->fdec->i_poc + h->fdec->i_delta_poc[h->mb.b_interlaced&h->mb.i_mb_y&1];
+            int cur_poc = h->fdec->i_poc + h->fdec->i_delta_poc[MB_INTERLACED&h->mb.i_mb_y&1];
             int col_parity = abs(h->fref[1][0]->i_poc + h->fref[1][0]->i_delta_poc[0] - cur_poc)
                           >= abs(h->fref[1][0]->i_poc + h->fref[1][0]->i_delta_poc[1] - cur_poc);
             mb_y = (h->mb.i_mb_y&~1) + col_parity;
@@ -243,8 +243,8 @@ static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
     {
         int x8 = i8&1;
         int y8 = i8>>1;
-        int ypart = (h->sh.b_mbaff && h->fref[1][0]->field[mb_xy] != h->mb.b_interlaced) ?
-                    h->mb.b_interlaced ? y8*6 : 2*(h->mb.i_mb_y&1) + y8 :
+        int ypart = (SLICE_MBAFF && h->fref[1][0]->field[mb_xy] != MB_INTERLACED) ?
+                    MB_INTERLACED ? y8*6 : 2*(h->mb.i_mb_y&1) + y8 :
                     3*y8;
 
         if( IS_INTRA( type_col[y8] ) )
@@ -257,7 +257,7 @@ static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
 
         int i_part_8x8 = i_mb_8x8 + x8 + (ypart>>1) * h->mb.i_b8_stride;
         int i_ref1_ref = h->fref[1][0]->ref[0][i_part_8x8];
-        int i_ref = (map_col_to_list0(i_ref1_ref>>preshift) << postshift) + (offset&i_ref1_ref&h->mb.b_interlaced);
+        int i_ref = (map_col_to_list0(i_ref1_ref>>preshift) << postshift) + (offset&i_ref1_ref&MB_INTERLACED);
 
         if( i_ref >= 0 )
         {
@@ -286,7 +286,7 @@ static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
     return 1;
 }
 
-static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
+static ALWAYS_INLINE int x264_mb_predict_mv_direct16x16_spatial( x264_t *h, int b_interlaced )
 {
     int8_t ref[2];
     ALIGNED_ARRAY_8( int16_t, mv,[2],[2] );
@@ -340,9 +340,9 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
     int type_col[2] = { h->fref[1][0]->mb_type[mb_xy], h->fref[1][0]->mb_type[mb_xy] };
     int partition_col[2] = { h->fref[1][0]->mb_partition[mb_xy], h->fref[1][0]->mb_partition[mb_xy] };
     h->mb.i_partition = partition_col[0];
-    if( h->sh.b_mbaff && h->fref[1][0]->field[mb_xy] != h->mb.b_interlaced )
+    if( b_interlaced && h->fref[1][0]->field[mb_xy] != MB_INTERLACED )
     {
-        if( h->mb.b_interlaced )
+        if( MB_INTERLACED )
         {
             mb_y = h->mb.i_mb_y&~1;
             mb_xy = mb_x + h->mb.i_mb_stride * mb_y;
@@ -360,7 +360,7 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
         }
         else
         {
-            int cur_poc = h->fdec->i_poc + h->fdec->i_delta_poc[h->mb.b_interlaced&h->mb.i_mb_y&1];
+            int cur_poc = h->fdec->i_poc + h->fdec->i_delta_poc[MB_INTERLACED&h->mb.i_mb_y&1];
             int col_parity = abs(h->fref[1][0]->i_poc + h->fref[1][0]->i_delta_poc[0] - cur_poc)
                           >= abs(h->fref[1][0]->i_poc + h->fref[1][0]->i_delta_poc[1] - cur_poc);
             mb_y = (h->mb.i_mb_y&~1) + col_parity;
@@ -370,8 +370,8 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
             h->mb.i_partition = partition_col[0];
         }
     }
-    int i_mb_4x4 = 4 * (h->mb.i_b4_stride*mb_y + mb_x);
-    int i_mb_8x8 = 2 * (h->mb.i_b8_stride*mb_y + mb_x);
+    int i_mb_4x4 = b_interlaced ? 4 * (h->mb.i_b4_stride*mb_y + mb_x) : h->mb.i_b4_xy ;
+    int i_mb_8x8 = b_interlaced ? 2 * (h->mb.i_b8_stride*mb_y + mb_x) : h->mb.i_b8_xy ;
 
     int8_t *l1ref0 = &h->fref[1][0]->ref[0][i_mb_8x8];
     int8_t *l1ref1 = &h->fref[1][0]->ref[1][i_mb_8x8];
@@ -397,7 +397,7 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
         return 0;
     }
 
-    if( !M64( mv ) || (ref[0]&&ref[1]) )
+    if( !M64( mv ) || (!b_interlaced && IS_INTRA( type_col[0] )) || (ref[0]&&ref[1]) )
         return 1;
 
     /* Don't do any checks other than the ones we have to, based
@@ -413,13 +413,13 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
     {
         const int x8 = i8&1;
         const int y8 = i8>>1;
-        int ypart = (h->sh.b_mbaff && h->fref[1][0]->field[mb_xy] != h->mb.b_interlaced) ?
-                    h->mb.b_interlaced ? y8*6 : 2*(h->mb.i_mb_y&1) + y8 :
+        int ypart = (b_interlaced && h->fref[1][0]->field[mb_xy] != MB_INTERLACED) ?
+                    MB_INTERLACED ? y8*6 : 2*(h->mb.i_mb_y&1) + y8 :
                     3*y8;
         int o8 = x8 + (ypart>>1) * h->mb.i_b8_stride;
         int o4 = 3*x8 + ypart * h->mb.i_b4_stride;
 
-        if( IS_INTRA( type_col[y8] ) )
+        if( b_interlaced && IS_INTRA( type_col[y8] ) )
             continue;
 
         int idx;
@@ -440,13 +440,29 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
     return 1;
 }
 
+
+static int x264_mb_predict_mv_direct16x16_spatial_interlaced( x264_t *h )
+{
+    return x264_mb_predict_mv_direct16x16_spatial( h, 1 );
+}
+
+static int x264_mb_predict_mv_direct16x16_spatial_progressive( x264_t *h )
+{
+    return x264_mb_predict_mv_direct16x16_spatial( h, 0 );
+}
+
 int x264_mb_predict_mv_direct16x16( x264_t *h, int *b_changed )
 {
     int b_available;
     if( h->param.analyse.i_direct_mv_pred == X264_DIRECT_PRED_NONE )
         return 0;
     else if( h->sh.b_direct_spatial_mv_pred )
-        b_available = x264_mb_predict_mv_direct16x16_spatial( h );
+    {
+        if( SLICE_MBAFF )
+            b_available = x264_mb_predict_mv_direct16x16_spatial_interlaced( h );
+        else
+            b_available = x264_mb_predict_mv_direct16x16_spatial_progressive( h );
+    }
     else
         b_available = x264_mb_predict_mv_direct16x16_temporal( h );
 
@@ -546,13 +562,13 @@ void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t mvc[
         x264_frame_t *l0 = h->fref[0][0];
         int field = h->mb.i_mb_y&1;
         int curpoc = h->fdec->i_poc + h->fdec->i_delta_poc[field];
-        int refpoc = h->fref[i_list][i_ref>>h->sh.b_mbaff]->i_poc;
+        int refpoc = h->fref[i_list][i_ref>>SLICE_MBAFF]->i_poc;
         refpoc += l0->i_delta_poc[field^(i_ref&1)];
 
 #define SET_TMVP( dx, dy ) \
         { \
             int mb_index = h->mb.i_mb_xy + dx + dy*h->mb.i_mb_stride; \
-            int scale = (curpoc - refpoc) * l0->inv_ref_poc[h->mb.b_interlaced&field]; \
+            int scale = (curpoc - refpoc) * l0->inv_ref_poc[MB_INTERLACED&field]; \
             mvc[i][0] = (l0->mv16x16[mb_index][0]*scale + 128) >> 8; \
             mvc[i][1] = (l0->mv16x16[mb_index][1]*scale + 128) >> 8; \
             i++; \