]> git.videolan.org Git - x264.git/commitdiff
MBAFF: Calculate bipred POCs
authorSimon Horlick <simonhorlick@gmail.com>
Tue, 15 Mar 2011 01:15:06 +0000 (01:15 +0000)
committerJason Garrett-Glaser <jason@x264.com>
Thu, 12 May 2011 06:06:42 +0000 (23:06 -0700)
Need to calculate two tables for the cases where the current macroblock is
progressive or interlaced as refs are calculated differently for each.

common/common.h
common/macroblock.c

index 64947ed1dc4cdb03061e5ae3f313faea0c1d38e3..d24a155cd0141cba15541690dec78405a4a43665 100644 (file)
@@ -777,9 +777,9 @@ struct x264_t
         int     i_chroma_lambda2_offset;
 
         /* B_direct and weighted prediction */
-        int16_t dist_scale_factor_buf[2][X264_REF_MAX*2][4];
+        int16_t dist_scale_factor_buf[2][2][X264_REF_MAX*2][4];
         int16_t (*dist_scale_factor)[4];
-        int8_t bipred_weight_buf[2][X264_REF_MAX*2][4];
+        int8_t bipred_weight_buf[2][2][X264_REF_MAX*2][4];
         int8_t (*bipred_weight)[4];
         /* maps fref1[0]'s ref indices into the current list0 */
 #define map_col_to_list0(col) h->mb.map_col_to_list0[(col)+2]
index 5230190a98f424ece3f92d3166333ae8a3d08c44..083de0d376e25a60d6182601a5c730b9ad19fb94 100644 (file)
@@ -1170,8 +1170,8 @@ void x264_macroblock_cache_load( x264_t *h, int mb_x, int mb_y )
     /* load skip */
     if( h->sh.i_type == SLICE_TYPE_B )
     {
-        h->mb.bipred_weight = h->mb.bipred_weight_buf[h->mb.b_interlaced&(mb_y&1)];
-        h->mb.dist_scale_factor = h->mb.dist_scale_factor_buf[h->mb.b_interlaced&(mb_y&1)];
+        h->mb.bipred_weight = h->mb.bipred_weight_buf[h->mb.b_interlaced][h->mb.b_interlaced&(mb_y&1)];
+        h->mb.dist_scale_factor = h->mb.dist_scale_factor_buf[h->mb.b_interlaced][h->mb.b_interlaced&(mb_y&1)];
         if( h->param.b_cabac )
         {
             uint8_t skipbp;
@@ -1626,42 +1626,43 @@ void x264_macroblock_cache_save( x264_t *h )
 
 void x264_macroblock_bipred_init( x264_t *h )
 {
-    for( int field = 0; field <= h->sh.b_mbaff; field++ )
-        for( int i_ref0 = 0; i_ref0 < (h->i_ref[0]<<h->sh.b_mbaff); i_ref0++ )
-        {
-            x264_frame_t *l0 = h->fref[0][i_ref0>>h->sh.b_mbaff];
-            int poc0 = l0->i_poc + l0->i_delta_poc[field^(i_ref0&1)];
-            for( int i_ref1 = 0; i_ref1 < (h->i_ref[1]<<h->sh.b_mbaff); i_ref1++ )
+    for( int mbfield = 0; mbfield <= h->sh.b_mbaff; mbfield++ )
+        for( int field = 0; field <= h->sh.b_mbaff; field++ )
+            for( int i_ref0 = 0; i_ref0 < (h->i_ref[0]<<mbfield); i_ref0++ )
             {
-                int dist_scale_factor;
-                x264_frame_t *l1 = h->fref[1][i_ref1>>h->sh.b_mbaff];
-                int poc1 = l1->i_poc + l1->i_delta_poc[field^(i_ref1&1)];
-                int cur_poc = h->fdec->i_poc + h->fdec->i_delta_poc[field];
-                int td = x264_clip3( poc1 - poc0, -128, 127 );
-                if( td == 0 /* || pic0 is a long-term ref */ )
-                    dist_scale_factor = 256;
-                else
+                x264_frame_t *l0 = h->fref[0][i_ref0>>mbfield];
+                int poc0 = l0->i_poc + mbfield*l0->i_delta_poc[field^(i_ref0&1)];
+                for( int i_ref1 = 0; i_ref1 < (h->i_ref[1]<<mbfield); i_ref1++ )
                 {
-                    int tb = x264_clip3( cur_poc - poc0, -128, 127 );
-                    int tx = (16384 + (abs(td) >> 1)) / td;
-                    dist_scale_factor = x264_clip3( (tb * tx + 32) >> 6, -1024, 1023 );
+                    int dist_scale_factor;
+                    x264_frame_t *l1 = h->fref[1][i_ref1>>mbfield];
+                    int cur_poc = h->fdec->i_poc + mbfield*h->fdec->i_delta_poc[field];
+                    int poc1 = l1->i_poc + mbfield*l1->i_delta_poc[field^(i_ref1&1)];
+                    int td = x264_clip3( poc1 - poc0, -128, 127 );
+                    if( td == 0 /* || pic0 is a long-term ref */ )
+                        dist_scale_factor = 256;
+                    else
+                    {
+                        int tb = x264_clip3( cur_poc - poc0, -128, 127 );
+                        int tx = (16384 + (abs(td) >> 1)) / td;
+                        dist_scale_factor = x264_clip3( (tb * tx + 32) >> 6, -1024, 1023 );
+                    }
+
+                    h->mb.dist_scale_factor_buf[mbfield][field][i_ref0][i_ref1] = dist_scale_factor;
+
+                    dist_scale_factor >>= 2;
+                    if( h->param.analyse.b_weighted_bipred
+                          && dist_scale_factor >= -64
+                          && dist_scale_factor <= 128 )
+                    {
+                        h->mb.bipred_weight_buf[mbfield][field][i_ref0][i_ref1] = 64 - dist_scale_factor;
+                        // ssse3 implementation of biweight doesn't support the extrema.
+                        // if we ever generate them, we'll have to drop that optimization.
+                        assert( dist_scale_factor >= -63 && dist_scale_factor <= 127 );
+                    }
+                    else
+                        h->mb.bipred_weight_buf[mbfield][field][i_ref0][i_ref1] = 32;
                 }
-
-                h->mb.dist_scale_factor_buf[field][i_ref0][i_ref1] = dist_scale_factor;
-
-                dist_scale_factor >>= 2;
-                if( h->param.analyse.b_weighted_bipred
-                      && dist_scale_factor >= -64
-                      && dist_scale_factor <= 128 )
-                {
-                    h->mb.bipred_weight_buf[field][i_ref0][i_ref1] = 64 - dist_scale_factor;
-                    // ssse3 implementation of biweight doesn't support the extrema.
-                    // if we ever generate them, we'll have to drop that optimization.
-                    assert( dist_scale_factor >= -63 && dist_scale_factor <= 127 );
-                }
-                else
-                    h->mb.bipred_weight_buf[field][i_ref0][i_ref1] = 32;
             }
-        }
 }