]> granicus.if.org Git - libx264/commitdiff
Fix two bugs in QPRD
authorFiona Glaser <fiona@x264.com>
Sun, 16 Aug 2009 10:29:49 +0000 (03:29 -0700)
committerFiona Glaser <fiona@x264.com>
Mon, 17 Aug 2009 17:27:29 +0000 (10:27 -0700)
QPRD could in some cases force blocks to skip when they shouldn't be ~(+0.01db)
Force QPRD to abide by qpmin/qpmax restrictions.

encoder/analyse.c
encoder/rdo.c

index 95569d1344f0c589d2f422d9e953cb5a915105c8..931369cd12a0d8e07b06c3c84083c6f1d5313165 100644 (file)
@@ -2211,9 +2211,9 @@ static inline void x264_mb_analyse_qp_rd( x264_t *h, x264_mb_analysis_t *a )
         h->mb.i_qp = orig_qp;
         failures = 0;
         prevcost = origcost;
-        while( h->mb.i_qp > 0 && h->mb.i_qp < 51 )
+        h->mb.i_qp += direction;
+        while( h->mb.i_qp >= h->param.rc.i_qp_min && h->mb.i_qp <= h->param.rc.i_qp_max )
         {
-            h->mb.i_qp += direction;
             h->mb.i_chroma_qp = h->chroma_qp_table[h->mb.i_qp];
             cost = x264_rd_cost_mb( h, a->i_lambda2 );
             COPY2_IF_LT( bcost, cost, bqp, h->mb.i_qp );
@@ -2236,6 +2236,7 @@ static inline void x264_mb_analyse_qp_rd( x264_t *h, x264_mb_analysis_t *a )
                 break;
             if( direction == 1 && !h->mb.cbp[h->mb.i_mb_xy] )
                 break;
+            h->mb.i_qp += direction;
         }
     }
 
@@ -2243,8 +2244,8 @@ static inline void x264_mb_analyse_qp_rd( x264_t *h, x264_mb_analysis_t *a )
     h->mb.i_chroma_qp = h->chroma_qp_table[h->mb.i_qp];
 
     /* Check transform again; decision from before may no longer be optimal. */
-    if( h->mb.i_qp != orig_qp && x264_mb_transform_8x8_allowed( h ) &&
-        h->param.analyse.b_transform_8x8 )
+    if( h->mb.i_qp != orig_qp && h->param.analyse.b_transform_8x8 &&
+        x264_mb_transform_8x8_allowed( h ) )
     {
         h->mb.b_transform_8x8 ^= 1;
         cost = x264_rd_cost_mb( h, a->i_lambda2 );
index 7a381c5498c64d3dfd402b260e1de9c4acb36dac..dd5d5fe2dfab2ecda9eb5cb8f62d18143a1a5c1a 100644 (file)
@@ -140,6 +140,7 @@ static int x264_rd_cost_mb( x264_t *h, int i_lambda2 )
     int b_transform_bak = h->mb.b_transform_8x8;
     int i_ssd;
     int i_bits;
+    int type_bak = h->mb.i_type;
 
     x264_macroblock_encode( h );
 
@@ -165,6 +166,7 @@ static int x264_rd_cost_mb( x264_t *h, int i_lambda2 )
     }
 
     h->mb.b_transform_8x8 = b_transform_bak;
+    h->mb.i_type = type_bak;
 
     return i_ssd + i_bits;
 }
@@ -206,9 +208,7 @@ uint64_t x264_rd_cost_part( x264_t *h, int i_lambda2, int i4, int i_pixel )
 
     if( i_pixel == PIXEL_16x16 )
     {
-        int type_bak = h->mb.i_type;
         int i_cost = x264_rd_cost_mb( h, i_lambda2 );
-        h->mb.i_type = type_bak;
         return i_cost;
     }