]> granicus.if.org Git - libx264/commitdiff
cosmetics: move some stuff from macroblock_encode to cache_save
authorLoren Merritt <pengvado@videolan.org>
Sat, 8 Oct 2005 21:17:44 +0000 (21:17 +0000)
committerLoren Merritt <pengvado@videolan.org>
Sat, 8 Oct 2005 21:17:44 +0000 (21:17 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@319 df754926-b1dd-0310-bc7b-ec298dee348c

common/common.h
common/macroblock.c
encoder/analyse.c
encoder/cabac.c
encoder/cavlc.c
encoder/encoder.c
encoder/macroblock.c

index b11ef9ea30edec95312850f9ef8c3a895dc6f384..403fb367aa65d51a97a456c52b57424cce5b3f40 100644 (file)
@@ -55,7 +55,9 @@
 #define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) )
 #define X264_ABS(a)   ( (a)< 0 ? -(a) : (a) )
 #define X264_MIN3(a,b,c) X264_MIN((a),X264_MIN((b),(c)))
+#define X264_MAX3(a,b,c) X264_MAX((a),X264_MAX((b),(c)))
 #define X264_MIN4(a,b,c,d) X264_MIN((a),X264_MIN3((b),(c),(d)))
+#define X264_MAX4(a,b,c,d) X264_MAX((a),X264_MAX3((b),(c),(d)))
 
 /****************************************************************************
  * Generals functions
@@ -157,6 +159,7 @@ typedef struct
 
     int i_cabac_init_idc;
 
+    int i_qp;
     int i_qp_delta;
     int b_sp_for_swidth;
     int i_qs_delta;
index f03aa5d5154d29c00949d07dcb83e18d6406f3e3..11e17545767df70d97890dc07055759cf630e01b 100644 (file)
@@ -1430,11 +1430,12 @@ void x264_macroblock_cache_save( x264_t *h )
 
     h->mb.type[i_mb_xy] = i_mb_type;
 
-    if( IS_SKIP( h->mb.i_type ) )
-        h->mb.qp[i_mb_xy] = h->mb.i_last_qp;
+    if( h->mb.i_type != I_16x16 && h->mb.i_cbp_luma == 0 && h->mb.i_cbp_chroma == 0 )
+        h->mb.i_qp = h->mb.i_last_qp;
+    h->mb.qp[i_mb_xy] = h->mb.i_qp;
 
-    h->mb.i_last_dqp = h->mb.qp[i_mb_xy] - h->mb.i_last_qp;
-    h->mb.i_last_qp = h->mb.qp[i_mb_xy];
+    h->mb.i_last_dqp = h->mb.i_qp - h->mb.i_last_qp;
+    h->mb.i_last_qp = h->mb.i_qp;
 
     /* save intra4x4 */
     if( i_mb_type == I_4x4 )
@@ -1475,6 +1476,8 @@ void x264_macroblock_cache_save( x264_t *h )
         }
     }
 
+    if( h->mb.i_cbp_luma == 0 && h->mb.i_type != I_8x8 )
+        h->mb.b_transform_8x8 = 0;
     h->mb.mb_transform_size[i_mb_xy] = h->mb.b_transform_8x8;
 
     if( !IS_INTRA( i_mb_type ) )
index 30fec4f326611832f46e8795c4a85c0cbd4d7069..b70f767de58184889579f58219578ebff339c3ac 100644 (file)
@@ -193,7 +193,7 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
     memset( a, 0, sizeof( x264_mb_analysis_t ) );
 
     /* conduct the analysis using this lamda and QP */
-    a->i_qp = i_qp;
+    a->i_qp = h->mb.i_qp = i_qp;
     a->i_lambda = i_qp0_cost_table[i_qp];
     a->i_lambda2 = i_qp0_cost2_table[i_qp];
     a->b_mbrd = h->param.analyse.i_subpel_refine >= 6 && h->sh.i_type != SLICE_TYPE_B;
@@ -1643,18 +1643,15 @@ static inline void x264_mb_analyse_transform_rd( x264_t *h, x264_mb_analysis_t *
 void x264_macroblock_analyse( x264_t *h )
 {
     x264_mb_analysis_t analysis;
+    int i_cost = COST_MAX;
     int i;
 
-    h->mb.i_qp =
-    h->mb.qp[h->mb.i_mb_xy] = x264_ratecontrol_qp( h );
-
     /* init analysis */
-    x264_mb_analyse_init( h, &analysis, h->mb.qp[h->mb.i_mb_xy] );
+    x264_mb_analyse_init( h, &analysis, x264_ratecontrol_qp( h ) );
 
     /*--------------------------- Do the analysis ---------------------------*/
     if( h->sh.i_type == SLICE_TYPE_I )
     {
-        int i_cost;
         x264_mb_analyse_intra( h, &analysis, COST_MAX );
 
         i_cost = analysis.i_sad_i16x16;
@@ -1670,7 +1667,6 @@ void x264_macroblock_analyse( x264_t *h )
     else if( h->sh.i_type == SLICE_TYPE_P )
     {
         int b_skip = 0;
-        int i_cost;
         int i_intra_cost, i_intra_type;
 
         /* Fast P_SKIP detection */
@@ -1917,7 +1913,6 @@ void x264_macroblock_analyse( x264_t *h )
         {
             const unsigned int flags = h->param.analyse.inter;
             int i_partition;
-            int i_cost;
 
             x264_mb_analyse_load_costs( h, &analysis );
 
index 7cb9656bd59bea77762f3a915fcd67774cea274c..9cdb6360f2d04bc56e682cec6a2a2e995cfe0a4e 100644 (file)
@@ -71,6 +71,8 @@ static inline void x264_cabac_mb_type_intra( x264_t *h, x264_cabac_t *cb, int i_
     }
     else
     {
+        int i_pred = x264_mb_pred_mode16x16_fix[h->mb.i_intra16x16_pred_mode];
+
         x264_cabac_encode_decision( cb, ctx0, 1 );
         x264_cabac_encode_terminal( cb,       0 );
 
@@ -84,8 +86,8 @@ static inline void x264_cabac_mb_type_intra( x264_t *h, x264_cabac_t *cb, int i_
             x264_cabac_encode_decision( cb, ctx2, 1 );
             x264_cabac_encode_decision( cb, ctx3, ( h->mb.i_cbp_chroma == 1 ? 0 : 1 ) );
         }
-        x264_cabac_encode_decision( cb, ctx4, ( (h->mb.i_intra16x16_pred_mode / 2) ? 1 : 0 ));
-        x264_cabac_encode_decision( cb, ctx5, ( (h->mb.i_intra16x16_pred_mode % 2) ? 1 : 0 ));
+        x264_cabac_encode_decision( cb, ctx4, ( (i_pred / 2) ? 1 : 0 ));
+        x264_cabac_encode_decision( cb, ctx5, ( (i_pred % 2) ? 1 : 0 ));
     }
 }
 
@@ -397,7 +399,7 @@ static void x264_cabac_mb_cbp_chroma( x264_t *h, x264_cabac_t *cb )
 static void x264_cabac_mb_qp_delta( x264_t *h, x264_cabac_t *cb )
 {
     int i_mbn_xy = h->mb.i_mb_xy - 1;
-    int i_dqp = h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp;
+    int i_dqp = h->mb.i_qp - h->mb.i_last_qp;
     int val = i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp - 1);
     int ctx;
 
@@ -917,7 +919,7 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
             for( i = 0; i < 16; i += di )
             {
                 const int i_pred = x264_mb_predict_intra4x4_mode( h, i );
-                const int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
+                const int i_mode = x264_mb_pred_mode4x4_fix( h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] );
                 x264_cabac_mb_intra4x4_pred_mode( cb, i_pred, i_mode );
             }
         }
index dc442f094eec1a9f8d68664feaacbc91270bd9d2..74489ff4c79206eeb4153ca6e26c6ea50d1282e9 100644 (file)
@@ -431,7 +431,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
         for( i = 0; i < 16; i += di )
         {
             int i_pred = x264_mb_predict_intra4x4_mode( h, i );
-            int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
+            int i_mode = x264_mb_pred_mode4x4_fix( h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] );
 
             if( i_pred == i_mode)
             {
@@ -454,7 +454,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
     }
     else if( i_mb_type == I_16x16 )
     {
-        bs_write_ue( s, i_mb_i_offset + 1 + h->mb.i_intra16x16_pred_mode +
+        bs_write_ue( s, i_mb_i_offset + 1 + x264_mb_pred_mode16x16_fix[h->mb.i_intra16x16_pred_mode] +
                         h->mb.i_cbp_chroma * 4 + ( h->mb.i_cbp_luma == 0 ? 0 : 12 ) );
         bs_write_ue( s, x264_mb_pred_mode8x8c_fix[ h->mb.i_chroma_pred_mode ] );
     }
@@ -684,7 +684,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
     /* write residual */
     if( i_mb_type == I_16x16 )
     {
-        bs_write_se( s, h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp );
+        bs_write_se( s, h->mb.i_qp - h->mb.i_last_qp );
 
         /* DC Luma */
         block_residual_write_cavlc( h, s, BLOCK_INDEX_LUMA_DC , h->dct.luma16x16_dc, 16 );
@@ -696,7 +696,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
     }
     else if( h->mb.i_cbp_luma != 0 || h->mb.i_cbp_chroma != 0 )
     {
-        bs_write_se( s, h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp );
+        bs_write_se( s, h->mb.i_qp - h->mb.i_last_qp );
         x264_macroblock_luma_write_cavlc( h, s );
     }
     if( h->mb.i_cbp_chroma != 0 )
index 4a4f9b8ec154bac15f30d7f0e106ddf2d43142b3..3ca83ea7ef21085ba0d5102702916ce12ec48606 100644 (file)
@@ -198,6 +198,7 @@ static void x264_slice_header_init( x264_t *h, x264_slice_header_t *sh,
 
     sh->i_cabac_init_idc = param->i_cabac_init_idc;
 
+    sh->i_qp = i_qp;
     sh->i_qp_delta = i_qp - pps->i_pic_init_qp;
     sh->b_sp_for_swidth = 0;
     sh->i_qs_delta = 0;
@@ -939,10 +940,10 @@ static int x264_slice_write( x264_t *h )
         bs_align_1( &h->out.bs );
 
         /* init cabac */
-        x264_cabac_context_init( &h->cabac, h->sh.i_type, h->sh.pps->i_pic_init_qp + h->sh.i_qp_delta, h->sh.i_cabac_init_idc );
+        x264_cabac_context_init( &h->cabac, h->sh.i_type, h->sh.i_qp, h->sh.i_cabac_init_idc );
         x264_cabac_encode_init ( &h->cabac, &h->out.bs );
     }
-    h->mb.i_last_qp = h->pps->i_pic_init_qp + h->sh.i_qp_delta;
+    h->mb.i_last_qp = h->sh.i_qp;
     h->mb.i_last_dqp = 0;
 
     for( mb_xy = h->sh.i_first_mb, i_skip = 0; mb_xy < h->sh.i_last_mb; mb_xy++ )
@@ -1497,7 +1498,7 @@ do_encode:
     /* update cabac */
     if( h->param.b_cabac && h->param.i_cabac_init_idc == -1 )
     {
-        x264_cabac_model_update( &h->cabac, i_slice_type, h->sh.pps->i_pic_init_qp + h->sh.i_qp_delta );
+        x264_cabac_model_update( &h->cabac, i_slice_type, h->sh.i_qp );
     }
 
     /* handle references */
index 0b767038bdd511aec1e38c1b1b4505a7cc8cc30c..3b0e34050248154721b3d84ecb695b86af7462c1 100644 (file)
@@ -566,9 +566,6 @@ void x264_macroblock_encode( x264_t *h )
 
         /* encode the 16x16 macroblock */
         x264_mb_encode_i16x16( h, i_qp );
-
-        /* fix the pred mode value */
-        h->mb.i_intra16x16_pred_mode = x264_mb_pred_mode16x16_fix[i_mode];
     }
     else if( h->mb.i_type == I_8x8 )
     {
@@ -581,7 +578,6 @@ void x264_macroblock_encode( x264_t *h )
 
             h->predict_8x8[i_mode]( p_dst, i_dst, h->mb.i_neighbour8[i] );
             x264_mb_encode_i8x8( h, i, i_qp );
-            h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]] = x264_mb_pred_mode4x4_fix(i_mode);
         }
     }
     else if( h->mb.i_type == I_4x4 )
@@ -599,7 +595,6 @@ void x264_macroblock_encode( x264_t *h )
 
             h->predict_4x4[i_mode]( p_dst, i_dst );
             x264_mb_encode_i4x4( h, i, i_qp );
-            h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] = x264_mb_pred_mode4x4_fix(i_mode);
         }
     }
     else    /* Inter MB */
@@ -779,14 +774,6 @@ void x264_macroblock_encode( x264_t *h )
     /* store cbp */
     h->mb.cbp[h->mb.i_mb_xy] = (i_cbp_dc << 8) | (h->mb.i_cbp_chroma << 4) | h->mb.i_cbp_luma;
 
-    if( h->mb.i_type != I_16x16 && h->mb.i_cbp_luma == 0 && h->mb.i_cbp_chroma == 0 )
-    {
-        /* It won'y change anything at the decoder side but it is needed else the
-         * decoder will fail to read the next QP */
-        h->mb.qp[h->mb.i_mb_xy] = h->mb.i_last_qp;
-    }
-
-
     /* Check for P_SKIP
      * XXX: in the me perhaps we should take x264_mb_predict_mv_pskip into account
      *      (if multiple mv give same result)*/
@@ -801,8 +788,6 @@ void x264_macroblock_encode( x264_t *h )
             h->mb.cache.mv[0][x264_scan8[0]][1] == mvp[1] )
         {
             h->mb.i_type = P_SKIP;
-            h->mb.qp[h->mb.i_mb_xy] = h->mb.i_last_qp;  /* Needed */
-            /* XXX qp reset may have issues when used in RD instead of the real encode */
         }
     }
 
@@ -811,11 +796,7 @@ void x264_macroblock_encode( x264_t *h )
         h->mb.i_cbp_luma == 0x00 && h->mb.i_cbp_chroma== 0x00 )
     {
         h->mb.i_type = B_SKIP;
-        h->mb.qp[h->mb.i_mb_xy] = h->mb.i_last_qp;  /* Needed */
     }
-
-    if( h->mb.i_cbp_luma == 0 && h->mb.i_type != I_8x8 )
-        h->mb.b_transform_8x8 = 0;
 }
 
 /*****************************************************************************