]> git.sesse.net Git - x264/commitdiff
Massive cosmetic and syntax cleanup
authorFiona Glaser <fiona@x264.com>
Wed, 31 Mar 2010 08:44:07 +0000 (01:44 -0700)
committerFiona Glaser <fiona@x264.com>
Mon, 5 Apr 2010 20:52:48 +0000 (13:52 -0700)
Convert all applicable loops to use C99 loop index syntax.
Clean up most inconsistent syntax in ratecontrol.c, visualize, ppc, etc.
Replace log(x)/log(2) constructs with log2, and similar with log10.
Fix all -Wshadow violations.
Fix visualize support.

43 files changed:
common/cabac.c
common/common.c
common/common.h
common/cpu.c
common/dct.c
common/display-x11.c
common/frame.c
common/macroblock.c
common/macroblock.h
common/mc.c
common/osdep.h
common/pixel.c
common/ppc/dct.c
common/ppc/dct.h
common/ppc/deblock.c
common/ppc/mc.c
common/ppc/pixel.c
common/ppc/predict.c
common/ppc/quant.c
common/predict.c
common/quant.c
common/set.c
common/visualize.c
common/vlc.c
encoder/analyse.c
encoder/cabac.c
encoder/cavlc.c
encoder/encoder.c
encoder/lookahead.c
encoder/macroblock.c
encoder/me.c
encoder/ratecontrol.c
encoder/rdo.c
encoder/set.c
encoder/slicetype.c
input/avs.c
input/timecode.c
input/y4m.c
input/yuv.c
output/matroska_ebml.c
output/mp4.c
tools/checkasm.c
x264.c

index ad05203c5885e64191a29419d78b317e7597c93c..f50aef6f5510e661bc499835bef5662ae3f6833c 100644 (file)
@@ -787,21 +787,14 @@ const uint16_t x264_cabac_entropy[128][2] =
 void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model )
 {
     const int8_t (*cabac_context_init)[460][2];
-    int i;
 
     if( i_slice_type == SLICE_TYPE_I )
-    {
         cabac_context_init = &x264_cabac_context_init_I;
-    }
     else
-    {
         cabac_context_init = &x264_cabac_context_init_PB[i_model];
-    }
 
-    for( i = 0; i < 460; i++ )
-    {
+    for( int i = 0; i < 460; i++ )
         cb->state[i] = x264_clip3( (((*cabac_context_init)[i][0] * i_qp) >> 4) + (*cabac_context_init)[i][1], 1, 126 );
-    }
 }
 
 void x264_cabac_encode_init( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end )
@@ -824,9 +817,7 @@ static inline void x264_cabac_putbyte( x264_cabac_t *cb )
         cb->i_queue -= 8;
 
         if( (out & 0xff) == 0xff )
-        {
             cb->i_bytes_outstanding++;
-        }
         else
         {
             int carry = out >> 8;
@@ -886,10 +877,9 @@ void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
 void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val )
 {
     int k, i;
-    uint32_t x;
     for( k = exp_bits; val >= (1<<k); k++ )
         val -= 1<<k;
-    x = (((1<<(k-exp_bits))-1)<<(k+1))+val;
+    uint32_t x = (((1<<(k-exp_bits))-1)<<(k+1))+val;
     k = 2*k+1-exp_bits;
     i = ((k-1)&7)+1;
     do {
index e4c4084fc889ca0c7427d10ed6d922ed8d815bda..6038c511f8d29c89a61da5f6e8e57c0eec4d32dc 100644 (file)
@@ -451,8 +451,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
 
 static int parse_enum( const char *arg, const char * const *names, int *dst )
 {
-    int i;
-    for( i = 0; names[i]; i++ )
+    for( int i = 0; names[i]; i++ )
         if( !strcmp( arg, names[i] ) )
         {
             *dst = i;
@@ -527,10 +526,10 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
 
     if( strchr( name, '_' ) ) // s/_/-/g
     {
-        char *p;
+        char *c;
         name_buf = strdup(name);
-        while( (p = strchr( name_buf, '_' )) )
-            *p = '-';
+        while( (c = strchr( name_buf, '_' )) )
+            *c = '-';
         name = name_buf;
     }
 
@@ -892,9 +891,9 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->rc.f_aq_strength = atof(value);
     OPT("pass")
     {
-        int i = x264_clip3( atoi(value), 0, 3 );
-        p->rc.b_stat_write = i & 1;
-        p->rc.b_stat_read = i & 2;
+        int pass = x264_clip3( atoi(value), 0, 3 );
+        p->rc.b_stat_write = pass & 1;
+        p->rc.b_stat_read = pass & 2;
     }
     OPT("stats")
     {
index c77dfa6d44f11bf151fb17179a4d028031f5559e..8d202dccc0c495e0b7db0a956e43993506e90dc0 100644 (file)
@@ -165,8 +165,8 @@ static ALWAYS_INLINE void x264_median_mv( int16_t *dst, int16_t *a, int16_t *b,
 
 static ALWAYS_INLINE int x264_predictor_difference( int16_t (*mvc)[2], intptr_t i_mvc )
 {
-    int sum = 0, i;
-    for( i = 0; i < i_mvc-1; i++ )
+    int sum = 0;
+    for( int i = 0; i < i_mvc-1; i++ )
     {
         sum += abs( mvc[i][0] - mvc[i+1][0] )
              + abs( mvc[i][1] - mvc[i+1][1] );
index 2dd55d19e38ede808fee69664e041c1b485f94b3..db2d4578d66e96217ddcae0e9eca5d2b6e1773a3 100644 (file)
@@ -167,7 +167,7 @@ uint32_t x264_cpu_detect( void )
         /* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and 6/14 (core1 "yonah")
          * theoretically support sse2, but it's significantly slower than mmx for
          * almost all of x264's functions, so let's just pretend they don't. */
-        if( family==6 && (model==9 || model==13 || model==14) )
+        if( family == 6 && (model == 9 || model == 13 || model == 14) )
         {
             cpu &= ~(X264_CPU_SSE2|X264_CPU_SSE3);
             assert(!(cpu&(X264_CPU_SSSE3|X264_CPU_SSE4)));
@@ -188,14 +188,15 @@ uint32_t x264_cpu_detect( void )
         {
             // Cache and TLB Information
             static const char cache32_ids[] = { 0x0a, 0x0c, 0x41, 0x42, 0x43, 0x44, 0x45, 0x82, 0x83, 0x84, 0x85, 0 };
-            static const char cache64_ids[] = { 0x22, 0x23, 0x25, 0x29, 0x2c, 0x46, 0x47, 0x49, 0x60, 0x66, 0x67, 0x68, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7c, 0x7f, 0x86, 0x87, 0 };
+            static const char cache64_ids[] = { 0x22, 0x23, 0x25, 0x29, 0x2c, 0x46, 0x47, 0x49, 0x60, 0x66, 0x67,
+                                                0x68, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7c, 0x7f, 0x86, 0x87, 0 };
             uint32_t buf[4];
-            int max, i=0, j;
+            int max, i = 0;
             do {
                 x264_cpu_cpuid( 2, buf+0, buf+1, buf+2, buf+3 );
                 max = buf[0]&0xff;
                 buf[0] &= ~0xff;
-                for(j=0; j<4; j++)
+                for( int j = 0; j < 4; j++ )
                     if( !(buf[j]>>31) )
                         while( buf[j] )
                         {
@@ -241,9 +242,7 @@ uint32_t x264_cpu_detect( void )
     int      error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );
 
     if( error == 0 && has_altivec != 0 )
-    {
         cpu |= X264_CPU_ALTIVEC;
-    }
 
     return cpu;
 }
@@ -252,7 +251,7 @@ uint32_t x264_cpu_detect( void )
 
 uint32_t x264_cpu_detect( void )
 {
-    static void (* oldsig)( int );
+    static void (*oldsig)( int );
 
     oldsig = signal( SIGILL, sigill_handler );
     if( sigsetjmp( jmpbuf, 1 ) )
index 07af94f809a853f5c61976a22dbf2bbe3243171d..3917510c9b3fbbcf43db6f67304e71a6763dc7bb 100644 (file)
@@ -38,16 +38,13 @@ int x264_dct8_weight2_zigzag[2][64];
 static void dct4x4dc( int16_t d[16] )
 {
     int16_t tmp[16];
-    int s01, s23;
-    int d01, d23;
-    int i;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        s01 = d[i*4+0] + d[i*4+1];
-        d01 = d[i*4+0] - d[i*4+1];
-        s23 = d[i*4+2] + d[i*4+3];
-        d23 = d[i*4+2] - d[i*4+3];
+        int s01 = d[i*4+0] + d[i*4+1];
+        int d01 = d[i*4+0] - d[i*4+1];
+        int s23 = d[i*4+2] + d[i*4+3];
+        int d23 = d[i*4+2] - d[i*4+3];
 
         tmp[0*4+i] = s01 + s23;
         tmp[1*4+i] = s01 - s23;
@@ -55,12 +52,12 @@ static void dct4x4dc( int16_t d[16] )
         tmp[3*4+i] = d01 + d23;
     }
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        s01 = tmp[i*4+0] + tmp[i*4+1];
-        d01 = tmp[i*4+0] - tmp[i*4+1];
-        s23 = tmp[i*4+2] + tmp[i*4+3];
-        d23 = tmp[i*4+2] - tmp[i*4+3];
+        int s01 = tmp[i*4+0] + tmp[i*4+1];
+        int d01 = tmp[i*4+0] - tmp[i*4+1];
+        int s23 = tmp[i*4+2] + tmp[i*4+3];
+        int d23 = tmp[i*4+2] - tmp[i*4+3];
 
         d[i*4+0] = ( s01 + s23 + 1 ) >> 1;
         d[i*4+1] = ( s01 - s23 + 1 ) >> 1;
@@ -72,16 +69,13 @@ static void dct4x4dc( int16_t d[16] )
 static void idct4x4dc( int16_t d[16] )
 {
     int16_t tmp[16];
-    int s01, s23;
-    int d01, d23;
-    int i;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        s01 = d[i*4+0] + d[i*4+1];
-        d01 = d[i*4+0] - d[i*4+1];
-        s23 = d[i*4+2] + d[i*4+3];
-        d23 = d[i*4+2] - d[i*4+3];
+        int s01 = d[i*4+0] + d[i*4+1];
+        int d01 = d[i*4+0] - d[i*4+1];
+        int s23 = d[i*4+2] + d[i*4+3];
+        int d23 = d[i*4+2] - d[i*4+3];
 
         tmp[0*4+i] = s01 + s23;
         tmp[1*4+i] = s01 - s23;
@@ -89,12 +83,12 @@ static void idct4x4dc( int16_t d[16] )
         tmp[3*4+i] = d01 + d23;
     }
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        s01 = tmp[i*4+0] + tmp[i*4+1];
-        d01 = tmp[i*4+0] - tmp[i*4+1];
-        s23 = tmp[i*4+2] + tmp[i*4+3];
-        d23 = tmp[i*4+2] - tmp[i*4+3];
+        int s01 = tmp[i*4+0] + tmp[i*4+1];
+        int d01 = tmp[i*4+0] - tmp[i*4+1];
+        int s23 = tmp[i*4+2] + tmp[i*4+3];
+        int d23 = tmp[i*4+2] - tmp[i*4+3];
 
         d[i*4+0] = s01 + s23;
         d[i*4+1] = s01 - s23;
@@ -106,13 +100,10 @@ static void idct4x4dc( int16_t d[16] )
 static inline void pixel_sub_wxh( int16_t *diff, int i_size,
                                   uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
 {
-    int y, x;
-    for( y = 0; y < i_size; y++ )
+    for( int y = 0; y < i_size; y++ )
     {
-        for( x = 0; x < i_size; x++ )
-        {
+        for( int x = 0; x < i_size; x++ )
             diff[x + y*i_size] = pix1[x] - pix2[x];
-        }
         pix1 += i_pix1;
         pix2 += i_pix2;
     }
@@ -122,16 +113,15 @@ static void sub4x4_dct( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 )
 {
     int16_t d[16];
     int16_t tmp[16];
-    int i;
 
     pixel_sub_wxh( d, 4, pix1, FENC_STRIDE, pix2, FDEC_STRIDE );
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        const int s03 = d[i*4+0] + d[i*4+3];
-        const int s12 = d[i*4+1] + d[i*4+2];
-        const int d03 = d[i*4+0] - d[i*4+3];
-        const int d12 = d[i*4+1] - d[i*4+2];
+        int s03 = d[i*4+0] + d[i*4+3];
+        int s12 = d[i*4+1] + d[i*4+2];
+        int d03 = d[i*4+0] - d[i*4+3];
+        int d12 = d[i*4+1] - d[i*4+2];
 
         tmp[0*4+i] =   s03 +   s12;
         tmp[1*4+i] = 2*d03 +   d12;
@@ -139,12 +129,12 @@ static void sub4x4_dct( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 )
         tmp[3*4+i] =   d03 - 2*d12;
     }
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        const int s03 = tmp[i*4+0] + tmp[i*4+3];
-        const int s12 = tmp[i*4+1] + tmp[i*4+2];
-        const int d03 = tmp[i*4+0] - tmp[i*4+3];
-        const int d12 = tmp[i*4+1] - tmp[i*4+2];
+        int s03 = tmp[i*4+0] + tmp[i*4+3];
+        int s12 = tmp[i*4+1] + tmp[i*4+2];
+        int d03 = tmp[i*4+0] - tmp[i*4+3];
+        int d12 = tmp[i*4+1] - tmp[i*4+2];
 
         dct[i*4+0] =   s03 +   s12;
         dct[i*4+1] = 2*d03 +   d12;
@@ -184,17 +174,16 @@ static int sub4x4_dct_dc( uint8_t *pix1, uint8_t *pix2 )
 
 static void sub8x8_dct_dc( int16_t dct[4], uint8_t *pix1, uint8_t *pix2 )
 {
-    int d0, d1, d2, d3;
     dct[0] = sub4x4_dct_dc( &pix1[0], &pix2[0] );
     dct[1] = sub4x4_dct_dc( &pix1[4], &pix2[4] );
     dct[2] = sub4x4_dct_dc( &pix1[4*FENC_STRIDE+0], &pix2[4*FDEC_STRIDE+0] );
     dct[3] = sub4x4_dct_dc( &pix1[4*FENC_STRIDE+4], &pix2[4*FDEC_STRIDE+4] );
 
     /* 2x2 DC transform */
-    d0 = dct[0] + dct[1];
-    d1 = dct[2] + dct[3];
-    d2 = dct[0] - dct[1];
-    d3 = dct[2] - dct[3];
+    int d0 = dct[0] + dct[1];
+    int d1 = dct[2] + dct[3];
+    int d2 = dct[0] - dct[1];
+    int d3 = dct[2] - dct[3];
     dct[0] = d0 + d1;
     dct[2] = d2 + d3;
     dct[1] = d0 - d1;
@@ -205,15 +194,13 @@ static void add4x4_idct( uint8_t *p_dst, int16_t dct[16] )
 {
     int16_t d[16];
     int16_t tmp[16];
-    int x, y;
-    int i;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        const int s02 =  dct[0*4+i]     +  dct[2*4+i];
-        const int d02 =  dct[0*4+i]     -  dct[2*4+i];
-        const int s13 =  dct[1*4+i]     + (dct[3*4+i]>>1);
-        const int d13 = (dct[1*4+i]>>1) -  dct[3*4+i];
+        int s02 =  dct[0*4+i]     +  dct[2*4+i];
+        int d02 =  dct[0*4+i]     -  dct[2*4+i];
+        int s13 =  dct[1*4+i]     + (dct[3*4+i]>>1);
+        int d13 = (dct[1*4+i]>>1) -  dct[3*4+i];
 
         tmp[i*4+0] = s02 + s13;
         tmp[i*4+1] = d02 + d13;
@@ -221,12 +208,12 @@ static void add4x4_idct( uint8_t *p_dst, int16_t dct[16] )
         tmp[i*4+3] = s02 - s13;
     }
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        const int s02 =  tmp[0*4+i]     +  tmp[2*4+i];
-        const int d02 =  tmp[0*4+i]     -  tmp[2*4+i];
-        const int s13 =  tmp[1*4+i]     + (tmp[3*4+i]>>1);
-        const int d13 = (tmp[1*4+i]>>1) -  tmp[3*4+i];
+        int s02 =  tmp[0*4+i]     +  tmp[2*4+i];
+        int d02 =  tmp[0*4+i]     -  tmp[2*4+i];
+        int s13 =  tmp[1*4+i]     + (tmp[3*4+i]>>1);
+        int d13 = (tmp[1*4+i]>>1) -  tmp[3*4+i];
 
         d[0*4+i] = ( s02 + s13 + 32 ) >> 6;
         d[1*4+i] = ( d02 + d13 + 32 ) >> 6;
@@ -235,9 +222,9 @@ static void add4x4_idct( uint8_t *p_dst, int16_t dct[16] )
     }
 
 
-    for( y = 0; y < 4; y++ )
+    for( int y = 0; y < 4; y++ )
     {
-        for( x = 0; x < 4; x++ )
+        for( int x = 0; x < 4; x++ )
             p_dst[x] = x264_clip_uint8( p_dst[x] + d[y*4+x] );
         p_dst += FDEC_STRIDE;
     }
@@ -264,22 +251,22 @@ static void add16x16_idct( uint8_t *p_dst, int16_t dct[16][16] )
  ****************************************************************************/
 
 #define DCT8_1D {\
-    const int s07 = SRC(0) + SRC(7);\
-    const int s16 = SRC(1) + SRC(6);\
-    const int s25 = SRC(2) + SRC(5);\
-    const int s34 = SRC(3) + SRC(4);\
-    const int a0 = s07 + s34;\
-    const int a1 = s16 + s25;\
-    const int a2 = s07 - s34;\
-    const int a3 = s16 - s25;\
-    const int d07 = SRC(0) - SRC(7);\
-    const int d16 = SRC(1) - SRC(6);\
-    const int d25 = SRC(2) - SRC(5);\
-    const int d34 = SRC(3) - SRC(4);\
-    const int a4 = d16 + d25 + (d07 + (d07>>1));\
-    const int a5 = d07 - d34 - (d25 + (d25>>1));\
-    const int a6 = d07 + d34 - (d16 + (d16>>1));\
-    const int a7 = d16 - d25 + (d34 + (d34>>1));\
+    int s07 = SRC(0) + SRC(7);\
+    int s16 = SRC(1) + SRC(6);\
+    int s25 = SRC(2) + SRC(5);\
+    int s34 = SRC(3) + SRC(4);\
+    int a0 = s07 + s34;\
+    int a1 = s16 + s25;\
+    int a2 = s07 - s34;\
+    int a3 = s16 - s25;\
+    int d07 = SRC(0) - SRC(7);\
+    int d16 = SRC(1) - SRC(6);\
+    int d25 = SRC(2) - SRC(5);\
+    int d34 = SRC(3) - SRC(4);\
+    int a4 = d16 + d25 + (d07 + (d07>>1));\
+    int a5 = d07 - d34 - (d25 + (d25>>1));\
+    int a6 = d07 + d34 - (d16 + (d16>>1));\
+    int a7 = d16 - d25 + (d34 + (d34>>1));\
     DST(0) =  a0 + a1     ;\
     DST(1) =  a4 + (a7>>2);\
     DST(2) =  a2 + (a3>>1);\
@@ -292,21 +279,20 @@ static void add16x16_idct( uint8_t *p_dst, int16_t dct[16][16] )
 
 static void sub8x8_dct8( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 )
 {
-    int i;
     int16_t tmp[64];
 
     pixel_sub_wxh( tmp, 8, pix1, FENC_STRIDE, pix2, FDEC_STRIDE );
 
 #define SRC(x) tmp[x*8+i]
 #define DST(x) tmp[x*8+i]
-    for( i = 0; i < 8; i++ )
+    for( int i = 0; i < 8; i++ )
         DCT8_1D
 #undef SRC
 #undef DST
 
 #define SRC(x) tmp[i*8+x]
 #define DST(x) dct[x*8+i]
-    for( i = 0; i < 8; i++ )
+    for( int i = 0; i < 8; i++ )
         DCT8_1D
 #undef SRC
 #undef DST
@@ -321,22 +307,22 @@ static void sub16x16_dct8( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 )
 }
 
 #define IDCT8_1D {\
-    const int a0 =  SRC(0) + SRC(4);\
-    const int a2 =  SRC(0) - SRC(4);\
-    const int a4 = (SRC(2)>>1) - SRC(6);\
-    const int a6 = (SRC(6)>>1) + SRC(2);\
-    const int b0 = a0 + a6;\
-    const int b2 = a2 + a4;\
-    const int b4 = a2 - a4;\
-    const int b6 = a0 - a6;\
-    const int a1 = -SRC(3) + SRC(5) - SRC(7) - (SRC(7)>>1);\
-    const int a3 =  SRC(1) + SRC(7) - SRC(3) - (SRC(3)>>1);\
-    const int a5 = -SRC(1) + SRC(7) + SRC(5) + (SRC(5)>>1);\
-    const int a7 =  SRC(3) + SRC(5) + SRC(1) + (SRC(1)>>1);\
-    const int b1 = (a7>>2) + a1;\
-    const int b3 =  a3 + (a5>>2);\
-    const int b5 = (a3>>2) - a5;\
-    const int b7 =  a7 - (a1>>2);\
+    int a0 =  SRC(0) + SRC(4);\
+    int a2 =  SRC(0) - SRC(4);\
+    int a4 = (SRC(2)>>1) - SRC(6);\
+    int a6 = (SRC(6)>>1) + SRC(2);\
+    int b0 = a0 + a6;\
+    int b2 = a2 + a4;\
+    int b4 = a2 - a4;\
+    int b6 = a0 - a6;\
+    int a1 = -SRC(3) + SRC(5) - SRC(7) - (SRC(7)>>1);\
+    int a3 =  SRC(1) + SRC(7) - SRC(3) - (SRC(3)>>1);\
+    int a5 = -SRC(1) + SRC(7) + SRC(5) + (SRC(5)>>1);\
+    int a7 =  SRC(3) + SRC(5) + SRC(1) + (SRC(1)>>1);\
+    int b1 = (a7>>2) + a1;\
+    int b3 =  a3 + (a5>>2);\
+    int b5 = (a3>>2) - a5;\
+    int b7 =  a7 - (a1>>2);\
     DST(0, b0 + b7);\
     DST(1, b2 + b5);\
     DST(2, b4 + b3);\
@@ -349,20 +335,18 @@ static void sub16x16_dct8( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 )
 
 static void add8x8_idct8( uint8_t *dst, int16_t dct[64] )
 {
-    int i;
-
     dct[0] += 32; // rounding for the >>6 at the end
 
 #define SRC(x)     dct[x*8+i]
 #define DST(x,rhs) dct[x*8+i] = (rhs)
-    for( i = 0; i < 8; i++ )
+    for( int i = 0; i < 8; i++ )
         IDCT8_1D
 #undef SRC
 #undef DST
 
 #define SRC(x)     dct[i*8+x]
 #define DST(x,rhs) dst[i + x*FDEC_STRIDE] = x264_clip_uint8( dst[i + x*FDEC_STRIDE] + ((rhs) >> 6) );
-    for( i = 0; i < 8; i++ )
+    for( int i = 0; i < 8; i++ )
         IDCT8_1D
 #undef SRC
 #undef DST
@@ -378,9 +362,8 @@ static void add16x16_idct8( uint8_t *dst, int16_t dct[4][64] )
 
 static void inline add4x4_idct_dc( uint8_t *p_dst, int16_t dc )
 {
-    int i;
     dc = (dc + 32) >> 6;
-    for( i = 0; i < 4; i++, p_dst += FDEC_STRIDE )
+    for( int i = 0; i < 4; i++, p_dst += FDEC_STRIDE )
     {
         p_dst[0] = x264_clip_uint8( p_dst[0] + dc );
         p_dst[1] = x264_clip_uint8( p_dst[1] + dc );
@@ -399,8 +382,7 @@ static void add8x8_idct_dc( uint8_t *p_dst, int16_t dct[4] )
 
 static void add16x16_idct_dc( uint8_t *p_dst, int16_t dct[16] )
 {
-    int i;
-    for( i = 0; i < 4; i++, dct += 4, p_dst += 4*FDEC_STRIDE )
+    for( int i = 0; i < 4; i++, dct += 4, p_dst += 4*FDEC_STRIDE )
     {
         add4x4_idct_dc( &p_dst[ 0], dct[0] );
         add4x4_idct_dc( &p_dst[ 4], dct[1] );
@@ -537,12 +519,11 @@ void x264_dct_init( int cpu, x264_dct_function_t *dctf )
 
 void x264_dct_init_weights( void )
 {
-    int i, j;
-    for( j=0; j<2; j++ )
+    for( int j = 0; j < 2; j++ )
     {
-        for( i=0; i<16; i++ )
+        for( int i = 0; i < 16; i++ )
             x264_dct4_weight2_zigzag[j][i] = x264_dct4_weight2_tab[ x264_zigzag_scan4[j][i] ];
-        for( i=0; i<64; i++ )
+        for( int i = 0; i < 64; i++ )
             x264_dct8_weight2_zigzag[j][i] = x264_dct8_weight2_tab[ x264_zigzag_scan8[j][i] ];
     }
 }
@@ -707,11 +688,10 @@ static int zigzag_sub_8x8_field( int16_t level[64], const uint8_t *p_src, uint8_
 
 static void zigzag_interleave_8x8_cavlc( int16_t *dst, int16_t *src, uint8_t *nnz )
 {
-    int i,j;
-    for( i=0; i<4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         int nz = 0;
-        for( j=0; j<16; j++ )
+        for( int j = 0; j < 16; j++ )
         {
             nz |= src[i+j*4];
             dst[i*16+j] = src[i+j*4];
index 0245f85c3eecce0c9f257b08fc19443a3694c03a..dcbbf8ec552ba8f678ea85ef8b69bd0921b623ec 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * x264: h264 encoder
+ * x264: x11 interface for visualization module
  *****************************************************************************
  * Copyright (C) 2005 Tuukka Toivonen <tuukkat@ee.oulu.fi>
  *
 static long event_mask = ConfigureNotify|ExposureMask|KeyPressMask|ButtonPressMask|StructureNotifyMask|ResizeRedirectMask;
 
 static Display *disp_display = NULL;
-static struct disp_window {
-       int init;
-       Window window;
+static struct disp_window
+{
+    int init;
+    Window window;
 } disp_window[10];
 
-static inline void disp_chkerror(int cond, char *e) {
-       if (!cond) return;
-       fprintf(stderr, "error: %s\n", e ? e : "?");
-       abort();
+static inline void disp_chkerror( int cond, char *e )
+{
+    if( !cond )
+        return;
+    fprintf( stderr, "error: %s\n", e ? e : "?" );
+    abort();
 }
 
-static void disp_init_display(void) {
-       Visual *visual;
-       int dpy_class;
-       int screen;
-       int dpy_depth;
-
-       if (disp_display != NULL) return;
-       memset(&disp_window, 0, sizeof(disp_window));
-       disp_display = XOpenDisplay("");
-       disp_chkerror(!disp_display, "no display");
-       screen = DefaultScreen(disp_display);
-       visual = DefaultVisual(disp_display, screen);
-       dpy_class = visual->class;
-       dpy_depth = DefaultDepth(disp_display, screen);
-       disp_chkerror(!((dpy_class == TrueColor && dpy_depth == 32)
-               || (dpy_class == TrueColor && dpy_depth == 24)
-               || (dpy_class == TrueColor && dpy_depth == 16)
-               || (dpy_class == PseudoColor && dpy_depth == 8)),
-               "requires 8 bit PseudoColor or 16/24/32 bit TrueColor display");
+static void disp_init_display()
+{
+    Visual *visual;
+    int dpy_class;
+    int screen;
+    int dpy_depth;
+
+    if( disp_display )
+        return;
+    memset( &disp_window, 0, sizeof(disp_window) );
+    disp_display = XOpenDisplay( "" );
+    disp_chkerror( !disp_display, "no display" );
+    screen = DefaultScreen( disp_display );
+    visual = DefaultVisual( disp_display, screen );
+    dpy_class = visual->class;
+    dpy_depth = DefaultDepth( disp_display, screen );
+    disp_chkerror( !((dpy_class == TrueColor && dpy_depth == 32)
+        || (dpy_class == TrueColor && dpy_depth == 24)
+        || (dpy_class == TrueColor && dpy_depth == 16)
+        || (dpy_class == PseudoColor && dpy_depth == 8)),
+        "requires 8 bit PseudoColor or 16/24/32 bit TrueColor display" );
 }
 
-static void disp_init_window(int num, int width, int height, const unsigned char *tit) {
-       XSizeHints *shint;
-       XSetWindowAttributes xswa;
-       XEvent xev;
-       int screen = DefaultScreen(disp_display);
-       Visual *visual = DefaultVisual (disp_display, screen);
-       unsigned int fg, bg;
-       unsigned int mask;
-       char title[200];
-       Window window;
-       int dpy_depth;
-
-       if (tit) {
-               snprintf(title, 200, "%s: %i/disp", tit, num);
-       } else {
-               snprintf(title, 200, "%i/disp", num);
-       }
-       shint = XAllocSizeHints();
-       disp_chkerror(!shint, "memerror");
-       shint->min_width = shint->max_width = shint->width = width;
-       shint->min_height = shint->max_height = shint->height = height;
-       shint->flags = PSize | PMinSize | PMaxSize;
-       disp_chkerror(num<0 || num>=10, "bad win num");
-       if (!disp_window[num].init) {
-               disp_window[num].init = 1;
-               bg = WhitePixel(disp_display, screen);
-               fg = BlackPixel(disp_display, screen);
-               dpy_depth = DefaultDepth(disp_display, screen);
-               if (dpy_depth==32 || dpy_depth==24 || dpy_depth==16) {
-                       mask |= CWColormap;
-                       xswa.colormap = XCreateColormap(disp_display, DefaultRootWindow(disp_display), visual, AllocNone);
-               }
-               xswa.background_pixel = bg;
-               xswa.border_pixel = fg;
-               xswa.backing_store = Always;
-               xswa.backing_planes = -1;
-               xswa.bit_gravity = NorthWestGravity;
-               mask = CWBackPixel | CWBorderPixel | CWBackingStore | CWBackingPlanes | CWBitGravity;
-               window = XCreateWindow(disp_display, DefaultRootWindow(disp_display),
-                               shint->x, shint->y, shint->width, shint->height,
-                               1, dpy_depth, InputOutput, visual, mask, &xswa);
-               disp_window[num].window = window;
-
-               XSelectInput(disp_display, window, event_mask);
-               XSetStandardProperties(disp_display, window, title, title, None, NULL, 0, shint);       /* Tell other applications about this window */
-               XMapWindow(disp_display, window);                                                       /* Map window. */
-               do {                                                                                    /* Wait for map. */
-                       XNextEvent(disp_display, &xev);
-               } while (xev.type!=MapNotify || xev.xmap.event!=window);
-               //XSelectInput(disp_display, window, KeyPressMask);                                     /*  XSelectInput(display, window, NoEventMask);*/
-       }
-       window = disp_window[num].window;
-       XSetStandardProperties(disp_display, window, title, title, None, NULL, 0, shint);               /* Tell other applications about this window */
-       XResizeWindow(disp_display, window, width, height);
-       XSync(disp_display, 1);
-       XFree(shint);
+static void disp_init_window( int num, int width, int height, const unsigned char *title )
+{
+    XSetWindowAttributes xswa;
+    XEvent xev;
+    int screen = DefaultScreen(disp_display);
+    Visual *visual = DefaultVisual (disp_display, screen);
+    char buf[200];
+    Window window;
+
+    if( title )
+        snprintf( buf, 200, "%s: %i/disp", title, num );
+    else
+        snprintf( buf, 200, "%i/disp", num );
+
+    XSizeHints *shint = XAllocSizeHints();
+    disp_chkerror( !shint, "memerror" );
+    shint->min_width = shint->max_width = shint->width = width;
+    shint->min_height = shint->max_height = shint->height = height;
+    shint->flags = PSize | PMinSize | PMaxSize;
+    disp_chkerror( num < 0 || num >= 10, "bad win num" );
+    if( !disp_window[num].init )
+    {
+        unsigned int mask = 0;
+        disp_window[num].init = 1;
+        unsigned int bg = WhitePixel( disp_display, screen );
+        unsigned int fg = BlackPixel( disp_display, screen );
+        int dpy_depth = DefaultDepth( disp_display, screen );
+        if( dpy_depth==32 || dpy_depth==24 || dpy_depth==16 )
+        {
+            mask |= CWColormap;
+            xswa.colormap = XCreateColormap( disp_display, DefaultRootWindow( disp_display ), visual, AllocNone );
+        }
+        xswa.background_pixel = bg;
+        xswa.border_pixel = fg;
+        xswa.backing_store = Always;
+        xswa.backing_planes = -1;
+        xswa.bit_gravity = NorthWestGravity;
+        mask = CWBackPixel | CWBorderPixel | CWBackingStore | CWBackingPlanes | CWBitGravity;
+        window = XCreateWindow( disp_display, DefaultRootWindow( disp_display ),
+                                shint->x, shint->y, shint->width, shint->height,
+                                1, dpy_depth, InputOutput, visual, mask, &xswa );
+        disp_window[num].window = window;
+
+        XSelectInput( disp_display, window, event_mask );
+        XSetStandardProperties( disp_display, window, buf, buf, None, NULL, 0, shint );
+        XMapWindow( disp_display, window );
+
+        do {
+            XNextEvent( disp_display, &xev );
+        } while( xev.type != MapNotify || xev.xmap.event != window );
+    }
+    window = disp_window[num].window;
+    XSetStandardProperties( disp_display, window, buf, buf, None, NULL, 0, shint );
+    XResizeWindow( disp_display, window, width, height );
+    XSync( disp_display, 1 );
+    XFree( shint );
 }
 
-void disp_sync(void) {
-       XSync(disp_display, 1);
+void disp_sync()
+{
+    XSync( disp_display, 1 );
 }
 
-void disp_setcolor(unsigned char *name) {
-       int screen;
-       GC gc;
-       XColor c_exact, c_nearest;
-       Colormap cm;
-       Status st;
-
-       screen = DefaultScreen(disp_display);
-       gc = DefaultGC(disp_display, screen);           /* allocate colors */
-       cm = DefaultColormap(disp_display, screen);
-       st = XAllocNamedColor(disp_display, cm, name, &c_nearest, &c_exact);
-       disp_chkerror(st!=1, "XAllocNamedColor error");
-       XSetForeground(disp_display, gc, c_nearest.pixel);
+void disp_setcolor( unsigned char *name )
+{
+    XColor c_exact, c_nearest;
+
+    int screen = DefaultScreen( disp_display );
+    GC gc = DefaultGC( disp_display, screen );
+    Colormap cm = DefaultColormap( disp_display, screen );
+    Status st = XAllocNamedColor( disp_display, cm, name, &c_nearest, &c_exact );
+    disp_chkerror( st != 1, "XAllocNamedColor error" );
+    XSetForeground( disp_display, gc, c_nearest.pixel );
 }
 
-void disp_gray(int num, char *data, int width, int height, int stride, const unsigned char *tit) {
-       Visual *visual;
-       XImage *ximage;
-       unsigned char *image;
-       int y,x,pixelsize;
-       char dummy;
-       int t = 1;
-       int dpy_depth;
-       int screen;
-       GC gc;
-       //XEvent xev;
-
-       disp_init_display();
-       disp_init_window(num, width, height, tit);
-       screen = DefaultScreen(disp_display);
-       visual = DefaultVisual(disp_display, screen);
-       dpy_depth = DefaultDepth(disp_display, screen);
-       ximage = XCreateImage(disp_display, visual, dpy_depth, ZPixmap, 0, &dummy, width, height, 8, 0);
-       disp_chkerror(!ximage, "no ximage");
-       if (*(char *)&t == 1) {
-               ximage->byte_order = LSBFirst;
-               ximage->bitmap_bit_order = LSBFirst;
-       } else {
-               ximage->byte_order = MSBFirst;
-               ximage->bitmap_bit_order = MSBFirst;
-       }
-       pixelsize = dpy_depth>8 ? sizeof(int) : sizeof(unsigned char);
-       image = malloc(width * height * pixelsize);
-       disp_chkerror(!image, "malloc failed");
-       for (y=0; y<height; y++) for (x=0; x<width; x++) {
-               memset(&image[(width*y + x)*pixelsize], data[y*stride+x], pixelsize);
-       }
-       ximage->data = image;
-       gc = DefaultGC(disp_display, screen);   /* allocate colors */
-
-//     XUnmapWindow(disp_display, disp_window[num].window);                                                    /* Map window. */
-//     XMapWindow(disp_display, disp_window[num].window);                                                      /* Map window. */
-       XPutImage(disp_display, disp_window[num].window, gc, ximage, 0, 0, 0, 0, width, height);
-//             do {                                                                                    /* Wait for map. */
-//                     XNextEvent(disp_display, &xev);
-//             } while (xev.type!=MapNotify || xev.xmap.event!=disp_window[num].window);
-       XPutImage(disp_display, disp_window[num].window, gc, ximage, 0, 0, 0, 0, width, height);
-
-       XDestroyImage(ximage);
-       XSync(disp_display, 1);
+void disp_gray( int num, char *data, int width, int height, int stride, const unsigned char *title )
+{
+    char dummy;
+
+    disp_init_display();
+    disp_init_window( num, width, height, title );
+    int screen = DefaultScreen( disp_display );
+    Visual *visual = DefaultVisual( disp_display, screen );
+    int dpy_depth = DefaultDepth( disp_display, screen );
+    XImage *ximage = XCreateImage( disp_display, visual, dpy_depth, ZPixmap, 0, &dummy, width, height, 8, 0 );
+    disp_chkerror( !ximage, "no ximage" );
+#ifdef WORDS_BIGENDIAN
+    ximage->byte_order = MSBFirst;
+    ximage->bitmap_bit_order = MSBFirst;
+#else
+    ximage->byte_order = LSBFirst;
+    ximage->bitmap_bit_order = LSBFirst;
+#endif
+
+    int pixelsize = dpy_depth>8 ? sizeof(int) : sizeof(unsigned char);
+    uint8_t *image = malloc( width * height * pixelsize );
+    disp_chkerror( !image, "malloc failed" );
+    for( int y = 0; y < height; y++ )
+        for( int x = 0; x < width; x++ )
+            memset( &image[(width*y + x)*pixelsize], data[y*stride+x], pixelsize );
+    ximage->data = image;
+    GC gc = DefaultGC( disp_display, screen );
+
+    XPutImage( disp_display, disp_window[num].window, gc, ximage, 0, 0, 0, 0, width, height );
+    XPutImage( disp_display, disp_window[num].window, gc, ximage, 0, 0, 0, 0, width, height );
+
+    XDestroyImage( ximage );
+    XSync( disp_display, 1 );
 
 }
 
-void disp_gray_zoom(int num, char *data, int width, int height, int stride, const unsigned char *tit, int zoom) {
-       unsigned char *dataz;
-       int y,x,y0,x0;
-       dataz = malloc(width*zoom * height*zoom);
-       disp_chkerror(!dataz, "malloc");
-       for (y=0; y<height; y++) for (x=0; x<width; x++) {
-               for (y0=0; y0<zoom; y0++) for (x0=0; x0<zoom; x0++) {
-                       dataz[(y*zoom + y0)*width*zoom + x*zoom + x0] = data[y*stride+x];
-               }
-       }
-       disp_gray(num, dataz, width*zoom, height*zoom, width*zoom, tit);
-       free(dataz);
+void disp_gray_zoom(int num, char *data, int width, int height, int stride, const unsigned char *title, int zoom)
+{
+    unsigned char *dataz = malloc( width*zoom * height*zoom );
+    disp_chkerror( !dataz, "malloc" );
+    for( int y = 0; y < height; y++ )
+        for( int x = 0; x < width; x++ )
+            for( int y0 = 0; y0 < zoom; y0++ )
+                for( int x0 = 0; x0 < zoom; x0++ )
+                    dataz[(y*zoom + y0)*width*zoom + x*zoom + x0] = data[y*stride+x];
+    disp_gray( num, dataz, width*zoom, height*zoom, width*zoom, title );
+    free( dataz );
 }
 
-void disp_point(int num, int x1, int y1) {
-       int screen;
-       GC gc;
-       screen = DefaultScreen(disp_display);
-       gc = DefaultGC(disp_display, screen);           /* allocate colors */
-       XDrawPoint(disp_display, disp_window[num].window, gc, x1, y1);
-//     XSync(disp_display, 1);
+void disp_point( int num, int x1, int y1 )
+{
+    int screen = DefaultScreen( disp_display );
+    GC gc = DefaultGC( disp_display, screen );
+    XDrawPoint( disp_display, disp_window[num].window, gc, x1, y1 );
 }
 
-void disp_line(int num, int x1, int y1, int x2, int y2) {
-       int screen;
-       GC gc;
-       screen = DefaultScreen(disp_display);
-       gc = DefaultGC(disp_display, screen);           /* allocate colors */
-       XDrawLine(disp_display, disp_window[num].window, gc, x1, y1, x2, y2);
-//     XSync(disp_display, 1);
+void disp_line( int num, int x1, int y1, int x2, int y2 )
+{
+    int screen = DefaultScreen( disp_display );
+    GC gc = DefaultGC( disp_display, screen );
+    XDrawLine( disp_display, disp_window[num].window, gc, x1, y1, x2, y2 );
 }
 
-void disp_rect(int num, int x1, int y1, int x2, int y2) {
-       int screen;
-       GC gc;
-       screen = DefaultScreen(disp_display);
-
-       gc = DefaultGC(disp_display, screen);           /* allocate colors */
-       XDrawRectangle(disp_display, disp_window[num].window, gc, x1, y1, x2-x1, y2-y1);
-//     XSync(disp_display, 1);
+void disp_rect( int num, int x1, int y1, int x2, int y2 )
+{
+    int screen = DefaultScreen( disp_display );
+    GC gc = DefaultGC( disp_display, screen );
+    XDrawRectangle( disp_display, disp_window[num].window, gc, x1, y1, x2-x1, y2-y1 );
 }
index 8bf253d3b1c66ae5dcc6e6bdc0c4af25bca851a7..fc67fbb5a64cb985a43412f23f0cd057a5d402a9 100644 (file)
@@ -29,7 +29,6 @@
 x264_frame_t *x264_frame_new( x264_t *h, int b_fdec )
 {
     x264_frame_t *frame;
-    int i, j;
 
     int i_mb_count = h->mb.i_mb_count;
     int i_stride, i_width, i_lines;
@@ -46,7 +45,7 @@ x264_frame_t *x264_frame_new( x264_t *h, int b_fdec )
     i_lines  = ALIGN( h->param.i_height, 16<<h->param.b_interlaced );
 
     frame->i_plane = 3;
-    for( i = 0; i < 3; i++ )
+    for( int i = 0; i < 3; i++ )
     {
         frame->i_stride[i] = ALIGN( i_stride >> !!i, align );
         frame->i_width[i] = i_width >> !!i;
@@ -55,14 +54,14 @@ x264_frame_t *x264_frame_new( x264_t *h, int b_fdec )
 
     luma_plane_size = (frame->i_stride[0] * (frame->i_lines[0] + 2*i_padv));
     chroma_plane_size = (frame->i_stride[1] * (frame->i_lines[1] + 2*i_padv));
-    for( i = 1; i < 3; i++ )
+    for( int i = 1; i < 3; i++ )
     {
         CHECKED_MALLOC( frame->buffer[i], chroma_plane_size );
         frame->plane[i] = frame->buffer[i] + (frame->i_stride[i] * i_padv + PADH)/2;
     }
 
-    for( i = 0; i < h->param.i_bframe + 2; i++ )
-        for( j = 0; j < h->param.i_bframe + 2; j++ )
+    for( int i = 0; i < h->param.i_bframe + 2; i++ )
+        for( int j = 0; j < h->param.i_bframe + 2; j++ )
             CHECKED_MALLOC( frame->i_row_satds[i][j], i_lines/16 * sizeof(int) );
 
     frame->i_poc = -1;
@@ -89,7 +88,7 @@ x264_frame_t *x264_frame_new( x264_t *h, int b_fdec )
     if( h->param.analyse.i_subpel_refine && b_fdec )
     {
         CHECKED_MALLOC( frame->buffer[0], 4*luma_plane_size );
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             frame->filtered[i] = frame->buffer[0] + i*luma_plane_size + frame->i_stride[0] * i_padv + PADH;
         frame->plane[0] = frame->filtered[0];
     }
@@ -137,18 +136,18 @@ x264_frame_t *x264_frame_new( x264_t *h, int b_fdec )
             luma_plane_size = frame->i_stride_lowres * (frame->i_lines[0]/2 + 2*PADV);
 
             CHECKED_MALLOC( frame->buffer_lowres[0], 4 * luma_plane_size );
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 frame->lowres[i] = frame->buffer_lowres[0] + (frame->i_stride_lowres * PADV + PADH) + i * luma_plane_size;
 
-            for( j = 0; j <= !!h->param.i_bframe; j++ )
-                for( i = 0; i <= h->param.i_bframe; i++ )
+            for( int j = 0; j <= !!h->param.i_bframe; j++ )
+                for( int i = 0; i <= h->param.i_bframe; i++ )
                 {
                     CHECKED_MALLOCZERO( frame->lowres_mvs[j][i], 2*h->mb.i_mb_count*sizeof(int16_t) );
                     CHECKED_MALLOC( frame->lowres_mv_costs[j][i], h->mb.i_mb_count*sizeof(int) );
                 }
             CHECKED_MALLOC( frame->i_propagate_cost, (i_mb_count+3) * sizeof(uint16_t) );
-            for( j = 0; j <= h->param.i_bframe+1; j++ )
-                for( i = 0; i <= h->param.i_bframe+1; i++ )
+            for( int j = 0; j <= h->param.i_bframe+1; j++ )
+                for( int i = 0; i <= h->param.i_bframe+1; i++ )
                 {
                     CHECKED_MALLOC( frame->lowres_costs[j][i], (i_mb_count+3) * sizeof(uint16_t) );
                     CHECKED_MALLOC( frame->lowres_inter_types[j][i], (i_mb_count+3)/4 * sizeof(uint8_t) );
@@ -180,27 +179,26 @@ fail:
 
 void x264_frame_delete( x264_frame_t *frame )
 {
-    int i, j;
     /* Duplicate frames are blank copies of real frames (including pointers),
      * so freeing those pointers would cause a double free later. */
     if( !frame->b_duplicate )
     {
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             x264_free( frame->buffer[i] );
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             x264_free( frame->buffer_lowres[i] );
-        for( i = 0; i < X264_BFRAME_MAX+2; i++ )
-            for( j = 0; j < X264_BFRAME_MAX+2; j++ )
+        for( int i = 0; i < X264_BFRAME_MAX+2; i++ )
+            for( int j = 0; j < X264_BFRAME_MAX+2; j++ )
                 x264_free( frame->i_row_satds[i][j] );
-        for( j = 0; j < 2; j++ )
-            for( i = 0; i <= X264_BFRAME_MAX; i++ )
+        for( int j = 0; j < 2; j++ )
+            for( int i = 0; i <= X264_BFRAME_MAX; i++ )
             {
                 x264_free( frame->lowres_mvs[j][i] );
                 x264_free( frame->lowres_mv_costs[j][i] );
             }
         x264_free( frame->i_propagate_cost );
-        for( j = 0; j <= X264_BFRAME_MAX+1; j++ )
-            for( i = 0; i <= X264_BFRAME_MAX+1; i++ )
+        for( int j = 0; j <= X264_BFRAME_MAX+1; j++ )
+            for( int i = 0; i <= X264_BFRAME_MAX+1; i++ )
             {
                 x264_free( frame->lowres_costs[j][i] );
                 x264_free( frame->lowres_inter_types[j][i] );
@@ -225,7 +223,6 @@ void x264_frame_delete( x264_frame_t *frame )
 int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
 {
     int i_csp = src->img.i_csp & X264_CSP_MASK;
-    int i;
     if( i_csp != X264_CSP_I420 && i_csp != X264_CSP_YV12 )
     {
         x264_log( h, X264_LOG_ERROR, "Arg invalid CSP\n" );
@@ -238,7 +235,7 @@ int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
     dst->param      = src->param;
     dst->i_pic_struct = src->i_pic_struct;
 
-    for( i=0; i<3; i++ )
+    for( int i = 0; i < 3; i++ )
     {
         int s = (i_csp == X264_CSP_YV12 && i) ? i^3 : i;
         uint8_t *plane = src->img.plane[s];
@@ -260,8 +257,7 @@ int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
 static void plane_expand_border( uint8_t *pix, int i_stride, int i_width, int i_height, int i_padh, int i_padv, int b_pad_top, int b_pad_bottom )
 {
 #define PPIXEL(x, y) ( pix + (x) + (y)*i_stride )
-    int y;
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
         /* left band */
         memset( PPIXEL(-i_padh, y), PPIXEL(0, y)[0], i_padh );
@@ -270,22 +266,21 @@ static void plane_expand_border( uint8_t *pix, int i_stride, int i_width, int i_
     }
     /* upper band */
     if( b_pad_top )
-    for( y = 0; y < i_padv; y++ )
-        memcpy( PPIXEL(-i_padh, -y-1), PPIXEL(-i_padh, 0), i_width+2*i_padh );
+        for( int y = 0; y < i_padv; y++ )
+            memcpy( PPIXEL(-i_padh, -y-1), PPIXEL(-i_padh, 0), i_width+2*i_padh );
     /* lower band */
     if( b_pad_bottom )
-    for( y = 0; y < i_padv; y++ )
-        memcpy( PPIXEL(-i_padh, i_height+y), PPIXEL(-i_padh, i_height-1), i_width+2*i_padh );
+        for( int y = 0; y < i_padv; y++ )
+            memcpy( PPIXEL(-i_padh, i_height+y), PPIXEL(-i_padh, i_height-1), i_width+2*i_padh );
 #undef PPIXEL
 }
 
 void x264_frame_expand_border( x264_t *h, x264_frame_t *frame, int mb_y, int b_end )
 {
-    int i;
     int b_start = !mb_y;
     if( mb_y & h->sh.b_mbaff )
         return;
-    for( i = 0; i < frame->i_plane; i++ )
+    for( int i = 0; i < frame->i_plane; i++ )
     {
         int stride = frame->i_stride[i];
         int width = 16*h->sps->i_mb_width >> !!i;
@@ -319,8 +314,7 @@ void x264_frame_expand_border_filtered( x264_t *h, x264_frame_t *frame, int mb_y
     int height = b_end ? (16*(h->sps->i_mb_height - mb_y) >> h->sh.b_mbaff) + 16 : 16;
     int padh = PADH - 4;
     int padv = PADV - 8;
-    int i;
-    for( i = 1; i < 4; i++ )
+    for( int i = 1; i < 4; i++ )
     {
         // buffer: 8 luma, to match the hpel filter
         uint8_t *pix = frame->filtered[i] + (16*mb_y - (8 << h->sh.b_mbaff)) * stride - 4;
@@ -330,23 +324,19 @@ void x264_frame_expand_border_filtered( x264_t *h, x264_frame_t *frame, int mb_y
             plane_expand_border( pix+stride, stride*2, width, height, padh, padv, b_start, b_end );
         }
         else
-        {
             plane_expand_border( pix, stride, width, height, padh, padv, b_start, b_end );
-        }
     }
 }
 
 void x264_frame_expand_border_lowres( x264_frame_t *frame )
 {
-    int i;
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
         plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_width_lowres, frame->i_lines_lowres, PADH, PADV, 1, 1 );
 }
 
 void x264_frame_expand_border_mod16( x264_t *h, x264_frame_t *frame )
 {
-    int i, y;
-    for( i = 0; i < frame->i_plane; i++ )
+    for( int i = 0; i < frame->i_plane; i++ )
     {
         int i_subsample = i ? 1 : 0;
         int i_width = h->param.i_width >> i_subsample;
@@ -356,14 +346,14 @@ void x264_frame_expand_border_mod16( x264_t *h, x264_frame_t *frame )
 
         if( i_padx )
         {
-            for( y = 0; y < i_height; y++ )
+            for( int y = 0; y < i_height; y++ )
                 memset( &frame->plane[i][y*frame->i_stride[i] + i_width],
                          frame->plane[i][y*frame->i_stride[i] + i_width - 1],
                          i_padx );
         }
         if( i_pady )
         {
-            for( y = i_height; y < i_height + i_pady; y++ )
+            for( int y = i_height; y < i_height + i_pady; y++ )
                 memcpy( &frame->plane[i][y*frame->i_stride[i]],
                         &frame->plane[i][(i_height-(~y&h->param.b_interlaced)-1)*frame->i_stride[i]],
                         i_width + i_padx );
@@ -378,13 +368,12 @@ static void munge_cavlc_nnz_row( x264_t *h, int mb_y, uint8_t (*buf)[16] )
 {
     uint32_t (*src)[6] = (uint32_t(*)[6])h->mb.non_zero_count + mb_y * h->sps->i_mb_width;
     int8_t *transform = h->mb.mb_transform_size + mb_y * h->sps->i_mb_width;
-    int x, nnz;
-    for( x=0; x<h->sps->i_mb_width; x++ )
+    for( int x = 0; x<h->sps->i_mb_width; x++ )
     {
         memcpy( buf+x, src+x, 16 );
         if( transform[x] )
         {
-            nnz = src[x][0] | src[x][1];
+            int nnz = src[x][0] | src[x][1];
             src[x][0] = src[x][1] = ((uint16_t)nnz ? 0x0101 : 0) + (nnz>>16 ? 0x01010000 : 0);
             nnz = src[x][2] | src[x][3];
             src[x][2] = src[x][3] = ((uint16_t)nnz ? 0x0101 : 0) + (nnz>>16 ? 0x01010000 : 0);
@@ -395,8 +384,7 @@ static void munge_cavlc_nnz_row( x264_t *h, int mb_y, uint8_t (*buf)[16] )
 static void restore_cavlc_nnz_row( x264_t *h, int mb_y, uint8_t (*buf)[16] )
 {
     uint8_t (*dst)[24] = h->mb.non_zero_count + mb_y * h->sps->i_mb_width;
-    int x;
-    for( x=0; x<h->sps->i_mb_width; x++ )
+    for( int x = 0; x < h->sps->i_mb_width; x++ )
         memcpy( dst+x, buf+x, 16 );
 }
 
@@ -460,22 +448,21 @@ static const int8_t i_tc0_table[52+12*2][4] =
 /* From ffmpeg */
 static inline void deblock_luma_c( uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0 )
 {
-    int i, d;
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         if( tc0[i] < 0 )
         {
             pix += 4*ystride;
             continue;
         }
-        for( d = 0; d < 4; d++ )
+        for( int d = 0; d < 4; d++ )
         {
-            const int p2 = pix[-3*xstride];
-            const int p1 = pix[-2*xstride];
-            const int p0 = pix[-1*xstride];
-            const int q0 = pix[ 0*xstride];
-            const int q1 = pix[ 1*xstride];
-            const int q2 = pix[ 2*xstride];
+            int p2 = pix[-3*xstride];
+            int p1 = pix[-2*xstride];
+            int p0 = pix[-1*xstride];
+            int q0 = pix[ 0*xstride];
+            int q1 = pix[ 1*xstride];
+            int q2 = pix[ 2*xstride];
 
             if( abs( p0 - q0 ) < alpha && abs( p1 - p0 ) < beta && abs( q1 - q0 ) < beta )
             {
@@ -513,21 +500,20 @@ static void deblock_h_luma_c( uint8_t *pix, int stride, int alpha, int beta, int
 
 static inline void deblock_chroma_c( uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0 )
 {
-    int i, d;
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        const int tc = tc0[i];
+        int tc = tc0[i];
         if( tc <= 0 )
         {
             pix += 2*ystride;
             continue;
         }
-        for( d = 0; d < 2; d++ )
+        for( int d = 0; d < 2; d++ )
         {
-            const int p1 = pix[-2*xstride];
-            const int p0 = pix[-1*xstride];
-            const int q0 = pix[ 0*xstride];
-            const int q1 = pix[ 1*xstride];
+            int p1 = pix[-2*xstride];
+            int p0 = pix[-1*xstride];
+            int q0 = pix[ 0*xstride];
+            int q1 = pix[ 1*xstride];
 
             if( abs( p0 - q0 ) < alpha && abs( p1 - p0 ) < beta && abs( q1 - q0 ) < beta )
             {
@@ -550,15 +536,14 @@ static void deblock_h_chroma_c( uint8_t *pix, int stride, int alpha, int beta, i
 
 static inline void deblock_luma_intra_c( uint8_t *pix, int xstride, int ystride, int alpha, int beta )
 {
-    int d;
-    for( d = 0; d < 16; d++ )
+    for( int d = 0; d < 16; d++ )
     {
-        const int p2 = pix[-3*xstride];
-        const int p1 = pix[-2*xstride];
-        const int p0 = pix[-1*xstride];
-        const int q0 = pix[ 0*xstride];
-        const int q1 = pix[ 1*xstride];
-        const int q2 = pix[ 2*xstride];
+        int p2 = pix[-3*xstride];
+        int p1 = pix[-2*xstride];
+        int p0 = pix[-1*xstride];
+        int q0 = pix[ 0*xstride];
+        int q1 = pix[ 1*xstride];
+        int q2 = pix[ 2*xstride];
 
         if( abs( p0 - q0 ) < alpha && abs( p1 - p0 ) < beta && abs( q1 - q0 ) < beta )
         {
@@ -603,13 +588,12 @@ static void deblock_h_luma_intra_c( uint8_t *pix, int stride, int alpha, int bet
 
 static inline void deblock_chroma_intra_c( uint8_t *pix, int xstride, int ystride, int alpha, int beta )
 {
-    int d;
-    for( d = 0; d < 8; d++ )
+    for( int d = 0; d < 8; d++ )
     {
-        const int p1 = pix[-2*xstride];
-        const int p0 = pix[-1*xstride];
-        const int q0 = pix[ 0*xstride];
-        const int q1 = pix[ 1*xstride];
+        int p1 = pix[-2*xstride];
+        int p0 = pix[-1*xstride];
+        int q0 = pix[ 0*xstride];
+        int q1 = pix[ 1*xstride];
 
         if( abs( p0 - q0 ) < alpha && abs( p1 - p0 ) < beta && abs( q1 - q0 ) < beta )
         {
@@ -630,9 +614,9 @@ static void deblock_h_chroma_intra_c( uint8_t *pix, int stride, int alpha, int b
 
 static inline void deblock_edge( x264_t *h, uint8_t *pix1, uint8_t *pix2, int i_stride, uint8_t bS[4], int i_qp, int b_chroma, x264_deblock_inter_t pf_inter )
 {
-    const int index_a = i_qp + h->sh.i_alpha_c0_offset;
-    const int alpha = alpha_table(index_a);
-    const int beta  = beta_table(i_qp + h->sh.i_beta_offset);
+    int index_a = i_qp + h->sh.i_alpha_c0_offset;
+    int alpha = alpha_table(index_a);
+    int beta  = beta_table(i_qp + h->sh.i_beta_offset);
     int8_t tc[4];
 
     if( !alpha || !beta )
@@ -650,8 +634,8 @@ static inline void deblock_edge( x264_t *h, uint8_t *pix1, uint8_t *pix2, int i_
 
 static inline void deblock_edge_intra( x264_t *h, uint8_t *pix1, uint8_t *pix2, int i_stride, uint8_t bS[4], int i_qp, int b_chroma, x264_deblock_intra_t pf_intra )
 {
-    const int alpha = alpha_table(i_qp + h->sh.i_alpha_c0_offset);
-    const int beta  = beta_table(i_qp + h->sh.i_beta_offset);
+    int alpha = alpha_table(i_qp + h->sh.i_alpha_c0_offset);
+    int beta  = beta_table(i_qp + h->sh.i_beta_offset);
 
     if( !alpha || !beta )
         return;
@@ -663,12 +647,12 @@ static inline void deblock_edge_intra( x264_t *h, uint8_t *pix1, uint8_t *pix2,
 
 void x264_frame_deblock_row( x264_t *h, int mb_y )
 {
-    const int s8x8 = 2 * h->mb.i_mb_stride;
-    const int s4x4 = 4 * h->mb.i_mb_stride;
-    const int b_interlaced = h->sh.b_mbaff;
-    const int mvy_limit = 4 >> b_interlaced;
-    const int qp_thresh = 15 - X264_MIN(h->sh.i_alpha_c0_offset, h->sh.i_beta_offset) - X264_MAX(0, h->param.analyse.i_chroma_qp_offset);
-    const int no_sub8x8 = !(h->param.analyse.inter & X264_ANALYSE_PSUB8x8);
+    int s8x8 = 2 * h->mb.i_mb_stride;
+    int s4x4 = 4 * h->mb.i_mb_stride;
+    int b_interlaced = h->sh.b_mbaff;
+    int mvy_limit = 4 >> b_interlaced;
+    int qp_thresh = 15 - X264_MIN(h->sh.i_alpha_c0_offset, h->sh.i_beta_offset) - X264_MAX(0, h->param.analyse.i_chroma_qp_offset);
+    int no_sub8x8 = !(h->param.analyse.inter & X264_ANALYSE_PSUB8x8);
     int mb_x;
     int stridey   = h->fdec->i_stride[0];
     int stride2y  = stridey << b_interlaced;
@@ -681,11 +665,11 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
 
     for( mb_x = 0; mb_x < h->sps->i_mb_width; mb_x += (~b_interlaced | mb_y)&1, mb_y ^= b_interlaced )
     {
-        const int mb_xy  = mb_y * h->mb.i_mb_stride + mb_x;
-        const int mb_8x8 = 2 * s8x8 * mb_y + 2 * mb_x;
-        const int mb_4x4 = 4 * s4x4 * mb_y + 4 * mb_x;
-        const int b_8x8_transform = h->mb.mb_transform_size[mb_xy];
-        const int i_qp = h->mb.qp[mb_xy];
+        int mb_xy  = mb_y * h->mb.i_mb_stride + mb_x;
+        int mb_8x8 = 2 * s8x8 * mb_y + 2 * mb_x;
+        int mb_4x4 = 4 * s4x4 * mb_y + 4 * mb_x;
+        int b_8x8_transform = h->mb.mb_transform_size[mb_xy];
+        int i_qp = h->mb.qp[mb_xy];
         int i_edge_end = (h->mb.type[mb_xy] == P_SKIP) ? 1 : 4;
         uint8_t *pixy = h->fdec->plane[0] + 16*mb_y*stridey  + 16*mb_x;
         uint8_t *pixu = h->fdec->plane[1] +  8*mb_y*strideuv +  8*mb_x;
@@ -746,7 +730,7 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
             else\
             {\
                 M32( bS ) = 0x00000000;\
-                for( i = 0; i < 4; i++ )\
+                for( int i = 0; i < 4; i++ )\
                 {\
                     int x  = i_dir == 0 ? i_edge : i;\
                     int y  = i_dir == 0 ? i      : i_edge;\
@@ -795,7 +779,7 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
         #define DEBLOCK_DIR(i_dir)\
         {\
             int i_edge = (i_dir ? (mb_y <= b_interlaced) : (mb_x == 0));\
-            int i_qpn, i, mbn_xy, mbn_8x8, mbn_4x4;\
+            int i_qpn, mbn_xy, mbn_8x8, mbn_4x4;\
             ALIGNED_4( uint8_t bS[4] );  /* filtering strength */\
             if( i_edge )\
                 i_edge+= b_8x8_transform;\
@@ -842,8 +826,7 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
 
 void x264_frame_deblock( x264_t *h )
 {
-    int mb_y;
-    for( mb_y = 0; mb_y < h->sps->i_mb_height; mb_y += 1 + h->sh.b_mbaff )
+    for( int mb_y = 0; mb_y < h->sps->i_mb_height; mb_y += 1 + h->sh.b_mbaff )
         x264_frame_deblock_row( h, mb_y );
 }
 
@@ -1051,10 +1034,10 @@ x264_frame_t *x264_frame_pop_blank_unused( x264_t *h )
 
 void x264_frame_sort( x264_frame_t **list, int b_dts )
 {
-    int i, b_ok;
+    int b_ok;
     do {
         b_ok = 1;
-        for( i = 0; list[i+1]; i++ )
+        for( int i = 0; list[i+1]; i++ )
         {
             int dtype = list[i]->i_type - list[i+1]->i_type;
             int dtime = list[i]->i_frame - list[i+1]->i_frame;
@@ -1072,12 +1055,11 @@ void x264_frame_sort( x264_frame_t **list, int b_dts )
 void x264_weight_scale_plane( x264_t *h, uint8_t *dst, int i_dst_stride, uint8_t *src, int i_src_stride,
                          int i_width, int i_height, x264_weight_t *w )
 {
-    int x;
     /* Weight horizontal strips of height 16. This was found to be the optimal height
      * in terms of the cache loads. */
     while( i_height > 0 )
     {
-        for( x = 0; x < i_width; x += 16 )
+        for( int x = 0; x < i_width; x += 16 )
             w->weightfn[16>>2]( dst+x, i_dst_stride, src+x, i_src_stride, w, X264_MIN( i_height, 16 ) );
         i_height -= 16;
         dst += 16 * i_dst_stride;
index 089779da1f52c1cd12053064203c8508ed96608e..671d252923a0e9dcfff25c3fe256df12c381aad2 100644 (file)
@@ -154,16 +154,13 @@ void x264_mb_predict_mv_pskip( x264_t *h, int16_t mv[2] )
         M32( mv ) = 0;
     }
     else
-    {
         x264_mb_predict_mv_16x16( h, 0, 0, mv );
-    }
 }
 
 static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
 {
     int i_mb_4x4 = 16 * h->mb.i_mb_stride * h->mb.i_mb_y + 4 * h->mb.i_mb_x;
     int i_mb_8x8 =  4 * h->mb.i_mb_stride * h->mb.i_mb_y + 2 * h->mb.i_mb_x;
-    int i8;
     const int type_col = h->fref1[0]->mb_type[h->mb.i_mb_xy];
     const int partition_col = h->fref1[0]->mb_partition[h->mb.i_mb_xy];
 
@@ -187,20 +184,20 @@ static int x264_mb_predict_mv_direct16x16_temporal( x264_t *h )
     int width = 4 >> ((D_16x16 - partition_col)&1);
     int height = 4 >> ((D_16x16 - partition_col)>>1);
 
-    for( i8 = 0; i8 < max_i8; i8 += step )
+    for( int i8 = 0; i8 < max_i8; i8 += step )
     {
-        const int x8 = i8%2;
-        const int y8 = i8/2;
-        const int i_part_8x8 = i_mb_8x8 + x8 + y8 * h->mb.i_b8_stride;
-        const int i_ref1_ref = h->fref1[0]->ref[0][i_part_8x8];
-        const int i_ref = (map_col_to_list0(i_ref1_ref>>h->sh.b_mbaff) << h->sh.b_mbaff) + (i_ref1_ref&h->sh.b_mbaff);
+        int x8 = i8&1;
+        int y8 = i8>>1;
+        int i_part_8x8 = i_mb_8x8 + x8 + y8 * h->mb.i_b8_stride;
+        int i_ref1_ref = h->fref1[0]->ref[0][i_part_8x8];
+        int i_ref = (map_col_to_list0(i_ref1_ref>>h->sh.b_mbaff) << h->sh.b_mbaff) + (i_ref1_ref&h->sh.b_mbaff);
 
         if( i_ref >= 0 )
         {
-            const int dist_scale_factor = h->mb.dist_scale_factor[i_ref][0];
-            const int16_t *mv_col = h->fref1[0]->mv[0][i_mb_4x4 + 3*x8 + 3*y8 * h->mb.i_b4_stride];
-            const int l0x = ( dist_scale_factor * mv_col[0] + 128 ) >> 8;
-            const int l0y = ( dist_scale_factor * mv_col[1] + 128 ) >> 8;
+            int dist_scale_factor = h->mb.dist_scale_factor[i_ref][0];
+            int16_t *mv_col = h->fref1[0]->mv[0][i_mb_4x4 + 3*x8 + 3*y8 * h->mb.i_b4_stride];
+            int l0x = ( dist_scale_factor * mv_col[0] + 128 ) >> 8;
+            int l0y = ( dist_scale_factor * mv_col[1] + 128 ) >> 8;
             if( h->param.i_threads > 1 && (l0y > h->mb.mv_max_spel[1] || l0y-mv_col[1] > h->mb.mv_max_spel[1]) )
                 return 0;
             x264_macroblock_cache_ref( h, 2*x8, 2*y8, width, height, 0, i_ref );
@@ -225,7 +222,6 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
 {
     int8_t ref[2];
     ALIGNED_ARRAY_8( int16_t, mv,[2],[2] );
-    int i_list, i8, i_ref;
     const int8_t *l1ref0 = &h->fref1[0]->ref[0][h->mb.i_b8_xy];
     const int8_t *l1ref1 = &h->fref1[0]->ref[1][h->mb.i_b8_xy];
     const int16_t (*l1mv[2])[2] = { (const int16_t (*)[2]) &h->fref1[0]->mv[0][h->mb.i_b4_xy],
@@ -235,7 +231,7 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
 
     h->mb.i_partition = partition_col;
 
-    for( i_list = 0; i_list < 2; i_list++ )
+    for( int i_list = 0; i_list < 2; i_list++ )
     {
         int     i_refa = h->mb.cache.ref[i_list][X264_SCAN8_0 - 1];
         int16_t *mv_a  = h->mb.cache.mv[i_list][X264_SCAN8_0 - 1];
@@ -249,7 +245,7 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
             mv_c   = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 - 1];
         }
 
-        i_ref = X264_MIN3( (unsigned)i_refa, (unsigned)i_refb, (unsigned)i_refc );
+        int i_ref = X264_MIN3( (unsigned)i_refa, (unsigned)i_refb, (unsigned)i_refc );
         if( i_ref < 0 )
         {
             i_ref = -1;
@@ -310,7 +306,7 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h )
     int height = 4 >> ((D_16x16 - partition_col)>>1);
 
     /* col_zero_flag */
-    for( i8 = 0; i8 < max_i8; i8 += step )
+    for( int i8 = 0; i8 < max_i8; i8 += step )
     {
         const int x8 = i8&1;
         const int y8 = i8>>1;
@@ -377,9 +373,7 @@ int x264_mb_predict_mv_direct16x16( x264_t *h, int *b_changed )
 
     /* cache ref & mv */
     if( b_available )
-    {
-        int l;
-        for( l = 0; l < 2; l++ )
+        for( int l = 0; l < 2; l++ )
         {
             CP32( h->mb.cache.direct_mv[l][0], h->mb.cache.mv[l][x264_scan8[ 0]] );
             CP32( h->mb.cache.direct_mv[l][1], h->mb.cache.mv[l][x264_scan8[ 4]] );
@@ -391,7 +385,6 @@ int x264_mb_predict_mv_direct16x16( x264_t *h, int *b_changed )
             h->mb.cache.direct_ref[l][3] = h->mb.cache.ref[l][x264_scan8[12]];
             h->mb.cache.direct_partition = h->mb.i_partition;
         }
-    }
 
     return b_available;
 }
@@ -482,11 +475,10 @@ void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t mvc[
 /* Set up a lookup table for delta pocs to reduce an IDIV to an IMUL */
 static void setup_inverse_delta_pocs( x264_t *h )
 {
-    int i, field;
-    for( field = 0; field <= h->sh.b_mbaff; field++ )
+    for( int field = 0; field <= h->sh.b_mbaff; field++ )
     {
         int curpoc = h->fdec->i_poc + field*h->sh.i_delta_poc_bottom;
-        for( i = 0; i < (h->i_ref0<<h->sh.b_mbaff); i++ )
+        for( int i = 0; i < (h->i_ref0<<h->sh.b_mbaff); i++ )
         {
             int refpoc = h->fref0[i>>h->sh.b_mbaff]->i_poc;
             if( h->sh.b_mbaff && field^(i&1) )
@@ -500,10 +492,10 @@ static void setup_inverse_delta_pocs( x264_t *h )
 
 static NOINLINE void x264_mb_mc_0xywh( x264_t *h, int x, int y, int width, int height )
 {
-    const int i8 = x264_scan8[0]+x+8*y;
-    const int i_ref = h->mb.cache.ref[0][i8];
-    const int mvx   = x264_clip3( h->mb.cache.mv[0][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
-    int       mvy   = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
+    int i8    = x264_scan8[0]+x+8*y;
+    int i_ref = h->mb.cache.ref[0][i8];
+    int mvx   = x264_clip3( h->mb.cache.mv[0][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
+    int mvy   = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
 
     h->mc.mc_luma( &h->mb.pic.p_fdec[0][4*y*FDEC_STRIDE+4*x], FDEC_STRIDE,
                    h->mb.pic.p_fref[0][i_ref], h->mb.pic.i_stride[0],
@@ -534,10 +526,10 @@ static NOINLINE void x264_mb_mc_0xywh( x264_t *h, int x, int y, int width, int h
 }
 static NOINLINE void x264_mb_mc_1xywh( x264_t *h, int x, int y, int width, int height )
 {
-    const int i8 = x264_scan8[0]+x+8*y;
-    const int i_ref = h->mb.cache.ref[1][i8];
-    const int mvx   = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
-    int       mvy   = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
+    int i8    = x264_scan8[0]+x+8*y;
+    int i_ref = h->mb.cache.ref[1][i8];
+    int mvx   = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
+    int mvy   = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
 
     h->mc.mc_luma( &h->mb.pic.p_fdec[0][4*y*FDEC_STRIDE+4*x], FDEC_STRIDE,
                    h->mb.pic.p_fref[1][i_ref], h->mb.pic.i_stride[0],
@@ -557,16 +549,16 @@ static NOINLINE void x264_mb_mc_1xywh( x264_t *h, int x, int y, int width, int h
 
 static NOINLINE void x264_mb_mc_01xywh( x264_t *h, int x, int y, int width, int height )
 {
-    const int i8 = x264_scan8[0]+x+8*y;
-    const int i_ref0 = h->mb.cache.ref[0][i8];
-    const int i_ref1 = h->mb.cache.ref[1][i8];
-    const int weight = h->mb.bipred_weight[i_ref0][i_ref1];
-    const int mvx0   = x264_clip3( h->mb.cache.mv[0][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
-    const int mvx1   = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
-    int       mvy0   = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
-    int       mvy1   = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
-    int       i_mode = x264_size2pixel[height][width];
-    int       i_stride0 = 16, i_stride1 = 16;
+    int i8 = x264_scan8[0]+x+8*y;
+    int i_ref0 = h->mb.cache.ref[0][i8];
+    int i_ref1 = h->mb.cache.ref[1][i8];
+    int weight = h->mb.bipred_weight[i_ref0][i_ref1];
+    int mvx0   = x264_clip3( h->mb.cache.mv[0][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
+    int mvx1   = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
+    int mvy0   = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
+    int mvy1   = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
+    int i_mode = x264_size2pixel[height][width];
+    int i_stride0 = 16, i_stride1 = 16;
     ALIGNED_ARRAY_16( uint8_t, tmp0,[16*16] );
     ALIGNED_ARRAY_16( uint8_t, tmp1,[16*16] );
     uint8_t *src0, *src1;
@@ -597,8 +589,8 @@ static NOINLINE void x264_mb_mc_01xywh( x264_t *h, int x, int y, int width, int
 
 void x264_mb_mc_8x8( x264_t *h, int i8 )
 {
-    const int x = 2*(i8&1);
-    const int y = 2*(i8>>1);
+    int x = 2*(i8&1);
+    int y = 2*(i8>>1);
 
     if( h->sh.i_type == SLICE_TYPE_P )
     {
@@ -625,10 +617,10 @@ void x264_mb_mc_8x8( x264_t *h, int i8 )
     }
     else
     {
-        const int i8 = x264_scan8[0] + x + 8*y;
+        int scan8 = x264_scan8[0] + x + 8*y;
 
-        if( h->mb.cache.ref[0][i8] >= 0 )
-            if( h->mb.cache.ref[1][i8] >= 0 )
+        if( h->mb.cache.ref[0][scan8] >= 0 )
+            if( h->mb.cache.ref[1][scan8] >= 0 )
                 x264_mb_mc_01xywh( h, x, y, 2, 2 );
             else
                 x264_mb_mc_0xywh( h, x, y, 2, 2 );
@@ -641,16 +633,15 @@ void x264_mb_mc( x264_t *h )
 {
     if( h->mb.i_partition == D_8x8 )
     {
-        int i;
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             x264_mb_mc_8x8( h, i );
     }
     else
     {
-        const int ref0a = h->mb.cache.ref[0][x264_scan8[ 0]];
-        const int ref0b = h->mb.cache.ref[0][x264_scan8[12]];
-        const int ref1a = h->mb.cache.ref[1][x264_scan8[ 0]];
-        const int ref1b = h->mb.cache.ref[1][x264_scan8[12]];
+        int ref0a = h->mb.cache.ref[0][x264_scan8[ 0]];
+        int ref0b = h->mb.cache.ref[0][x264_scan8[12]];
+        int ref1a = h->mb.cache.ref[1][x264_scan8[ 0]];
+        int ref1b = h->mb.cache.ref[1][x264_scan8[12]];
 
         if( h->mb.i_partition == D_16x16 )
         {
@@ -688,7 +679,6 @@ void x264_mb_mc( x264_t *h )
 
 int x264_macroblock_cache_init( x264_t *h )
 {
-    int i, j;
     int i_mb_count = h->mb.i_mb_count;
 
     h->mb.i_mb_stride = h->sps->i_mb_width;
@@ -715,7 +705,7 @@ int x264_macroblock_cache_init( x264_t *h )
         CHECKED_MALLOC( h->mb.mvd[1], i_mb_count * sizeof( **h->mb.mvd ) );
     }
 
-    for( i=0; i<2; i++ )
+    for( int i = 0; i < 2; i++ )
     {
         int i_refs = X264_MIN(16, (i ? 1 + !!h->param.i_bframe_pyramid : h->param.i_frame_reference) ) << h->param.b_interlaced;
         if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART )
@@ -723,7 +713,7 @@ int x264_macroblock_cache_init( x264_t *h )
         else if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_BLIND )
             i_refs = X264_MIN(16, i_refs + 1); //blind weights add one duplicate frame
 
-        for( j=0; j < i_refs; j++ )
+        for( int j = 0; j < i_refs; j++ )
             CHECKED_MALLOC( h->mb.mvr[i][j], 2 * i_mb_count * sizeof(int16_t) );
     }
 
@@ -732,7 +722,7 @@ int x264_macroblock_cache_init( x264_t *h )
         int i_padv = PADV << h->param.b_interlaced;
 #define ALIGN(x,a) (((x)+((a)-1))&~((a)-1))
         int align = h->param.cpu&X264_CPU_CACHELINE_64 ? 64 : h->param.cpu&X264_CPU_CACHELINE_32 ? 32 : 16;
-        int i_stride, luma_plane_size;
+        int i_stride, luma_plane_size = 0;
         int numweightbuf;
 
         if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_FAKE )
@@ -762,13 +752,13 @@ int x264_macroblock_cache_init( x264_t *h )
                 numweightbuf = 1;
         }
 
-        for( i = 0; i < numweightbuf; i++ )
+        for( int i = 0; i < numweightbuf; i++ )
             CHECKED_MALLOC( h->mb.p_weight_buf[i], luma_plane_size );
 #undef ALIGN
     }
 
-    for( i=0; i<=h->param.b_interlaced; i++ )
-        for( j=0; j<3; j++ )
+    for( int i = 0; i <= h->param.b_interlaced; i++ )
+        for( int j = 0; j < 3; j++ )
         {
             /* shouldn't really be initialized, just silences a valgrind false-positive in predict_8x8_filter_mmx */
             CHECKED_MALLOCZERO( h->mb.intra_border_backup[i][j], (h->sps->i_mb_width*16+32)>>!!j );
@@ -780,14 +770,13 @@ fail: return -1;
 }
 void x264_macroblock_cache_end( x264_t *h )
 {
-    int i, j;
-    for( i=0; i<=h->param.b_interlaced; i++ )
-        for( j=0; j<3; j++ )
+    for( int i = 0; i <= h->param.b_interlaced; i++ )
+        for( int j = 0; j < 3; j++ )
             x264_free( h->mb.intra_border_backup[i][j] - 8 );
-    for( i=0; i<2; i++ )
-        for( j=0; j<32; j++ )
+    for( int i = 0; i < 2; i++ )
+        for( int j = 0; j < 32; j++ )
             x264_free( h->mb.mvr[i][j] );
-    for( i=0; i<16; i++ )
+    for( int i = 0; i < 16; i++ )
         x264_free( h->mb.p_weight_buf[i] );
 
     if( h->param.b_cabac )
@@ -805,8 +794,6 @@ void x264_macroblock_cache_end( x264_t *h )
 }
 void x264_macroblock_slice_init( x264_t *h )
 {
-    int i, j;
-
     h->mb.mv[0] = h->fdec->mv[0];
     h->mb.mv[1] = h->fdec->mv[1];
     h->mb.ref[0] = h->fdec->ref[0];
@@ -816,20 +803,20 @@ void x264_macroblock_slice_init( x264_t *h )
 
     h->fdec->i_ref[0] = h->i_ref0;
     h->fdec->i_ref[1] = h->i_ref1;
-    for( i = 0; i < h->i_ref0; i++ )
+    for( int i = 0; i < h->i_ref0; i++ )
         h->fdec->ref_poc[0][i] = h->fref0[i]->i_poc;
     if( h->sh.i_type == SLICE_TYPE_B )
     {
-        for( i = 0; i < h->i_ref1; i++ )
+        for( int i = 0; i < h->i_ref1; i++ )
             h->fdec->ref_poc[1][i] = h->fref1[i]->i_poc;
 
         map_col_to_list0(-1) = -1;
         map_col_to_list0(-2) = -2;
-        for( i = 0; i < h->fref1[0]->i_ref[0]; i++ )
+        for( int i = 0; i < h->fref1[0]->i_ref[0]; i++ )
         {
             int poc = h->fref1[0]->ref_poc[0][i];
             map_col_to_list0(i) = -2;
-            for( j = 0; j < h->i_ref0; j++ )
+            for( int j = 0; j < h->i_ref0; j++ )
                 if( h->fref0[j]->i_poc == poc )
                 {
                     map_col_to_list0(i) = j;
@@ -900,8 +887,7 @@ void x264_prefetch_fenc( x264_t *h, x264_frame_t *fenc, int i_mb_x, int i_mb_y )
 static NOINLINE void copy_column8( uint8_t *dst, uint8_t *src )
 {
     // input pointers are offset by 4 rows because that's faster (smaller instruction size on x86)
-    int i;
-    for( i = -4; i < 4; i++ )
+    for( int i = -4; i < 4; i++ )
         dst[i*FDEC_STRIDE] = src[i*FDEC_STRIDE];
 }
 
@@ -918,7 +904,6 @@ static void ALWAYS_INLINE x264_macroblock_load_pic_pointers( x264_t *h, int i_mb
                                 &h->mb.intra_border_backup[i_mb_y & h->sh.b_mbaff][i][i_mb_x*16>>!!i];
     int ref_pix_offset[2] = { i_pix_offset, i_pix_offset };
     x264_frame_t **fref[2] = { h->fref0, h->fref1 };
-    int j, k;
     if( h->mb.b_interlaced )
         ref_pix_offset[1] += (1-2*(i_mb_y&1)) * i_stride;
     h->mb.pic.i_stride[i] = i_stride2;
@@ -930,14 +915,14 @@ static void ALWAYS_INLINE x264_macroblock_load_pic_pointers( x264_t *h, int i_mb
     else
         memset( &h->mb.pic.p_fdec[i][-1-FDEC_STRIDE], 0, w*3/2+1 );
     if( h->mb.b_interlaced || h->mb.b_reencode_mb )
-        for( j = 0; j < w; j++ )
+        for( int j = 0; j < w; j++ )
             h->mb.pic.p_fdec[i][-1+j*FDEC_STRIDE] = plane_fdec[-1+j*i_stride2];
-    for( j = 0; j < h->mb.pic.i_fref[0]; j++ )
+    for( int j = 0; j < h->mb.pic.i_fref[0]; j++ )
     {
         h->mb.pic.p_fref[0][j][i==0 ? 0:i+3] = &fref[0][j >> h->mb.b_interlaced]->plane[i][ref_pix_offset[j&1]];
         if( i == 0 )
         {
-            for( k = 1; k < 4; k++ )
+            for( int k = 1; k < 4; k++ )
                 h->mb.pic.p_fref[0][j][k] = &fref[0][j >> h->mb.b_interlaced]->filtered[k][ref_pix_offset[j&1]];
             if( h->sh.weight[j][0].weightfn )
                 h->mb.pic.p_fref_w[j] = &h->fenc->weighted[j >> h->mb.b_interlaced][ref_pix_offset[j&1]];
@@ -946,11 +931,11 @@ static void ALWAYS_INLINE x264_macroblock_load_pic_pointers( x264_t *h, int i_mb
         }
     }
     if( h->sh.i_type == SLICE_TYPE_B )
-        for( j = 0; j < h->mb.pic.i_fref[1]; j++ )
+        for( int j = 0; j < h->mb.pic.i_fref[1]; j++ )
         {
             h->mb.pic.p_fref[1][j][i==0 ? 0:i+3] = &fref[1][j >> h->mb.b_interlaced]->plane[i][ref_pix_offset[j&1]];
             if( i == 0 )
-                for( k = 1; k < 4; k++ )
+                for( int k = 1; k < 4; k++ )
                     h->mb.pic.p_fref[1][j][k] = &fref[1][j >> h->mb.b_interlaced]->filtered[k][ref_pix_offset[j&1]];
         }
 }
@@ -968,8 +953,6 @@ void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
     int i_top_type = -1;    /* gcc warn */
     int i_left_type= -1;
 
-    int i;
-
     /* init index */
     h->mb.i_mb_x = i_mb_x;
     h->mb.i_mb_y = i_mb_y;
@@ -1117,9 +1100,9 @@ void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
     if( h->fdec->integral )
     {
         assert( !h->mb.b_interlaced );
-        for( i = 0; i < h->mb.pic.i_fref[0]; i++ )
+        for( int i = 0; i < h->mb.pic.i_fref[0]; i++ )
             h->mb.pic.p_integral[0][i] = &h->fref0[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
-        for( i = 0; i < h->mb.pic.i_fref[1]; i++ )
+        for( int i = 0; i < h->mb.pic.i_fref[1]; i++ )
             h->mb.pic.p_integral[1][i] = &h->fref1[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
     }
 
@@ -1131,9 +1114,7 @@ void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
         const int s8x8 = h->mb.i_b8_stride;
         const int s4x4 = h->mb.i_b4_stride;
 
-        int i_list;
-
-        for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2  : 1 ); i_list++ )
+        for( int i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2  : 1 ); i_list++ )
         {
             /*
             h->mb.cache.ref[i_list][x264_scan8[5 ]+1] =
@@ -1208,7 +1189,7 @@ void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
             else
             {
                 const int i8 = x264_scan8[0] - 1;
-                for( i = 0; i < 4; i++ )
+                for( int i = 0; i < 4; i++ )
                 {
                     h->mb.cache.ref[i_list][i8+i*8] = -2;
                     M32( h->mb.cache.mv[i_list][i8+i*8] ) = 0;
@@ -1230,7 +1211,7 @@ void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
                     CP16( h->mb.cache.mvd[i_list][x264_scan8[10] - 1], h->mb.mvd[i_list][i_left_xy][3] );
                 }
                 else
-                    for( i = 0; i < 4; i++ )
+                    for( int i = 0; i < 4; i++ )
                         M16( h->mb.cache.mvd[i_list][x264_scan8[0]-1+i*8] ) = 0;
             }
         }
@@ -1279,9 +1260,8 @@ static void ALWAYS_INLINE x264_macroblock_store_pic( x264_t *h, int i )
     int i_pix_offset = h->mb.b_interlaced
                      ? w * (h->mb.i_mb_x + (h->mb.i_mb_y&~1) * i_stride) + (h->mb.i_mb_y&1) * i_stride
                      : w * (h->mb.i_mb_x + h->mb.i_mb_y * i_stride);
-    h->mc.copy[i?PIXEL_8x8:PIXEL_16x16](
-        &h->fdec->plane[i][i_pix_offset], i_stride2,
-        h->mb.pic.p_fdec[i], FDEC_STRIDE, w );
+    h->mc.copy[i?PIXEL_8x8:PIXEL_16x16]( &h->fdec->plane[i][i_pix_offset], i_stride2,
+                                         h->mb.pic.p_fdec[i], FDEC_STRIDE, w );
 }
 
 void x264_macroblock_cache_save( x264_t *h )
@@ -1298,8 +1278,6 @@ void x264_macroblock_cache_save( x264_t *h )
     int8_t *intra4x4_pred_mode = h->mb.intra4x4_pred_mode[i_mb_xy];
     uint8_t *non_zero_count = h->mb.non_zero_count[i_mb_xy];
 
-    int y;
-
     x264_macroblock_store_pic( h, 0 );
     x264_macroblock_store_pic( h, 1 );
     x264_macroblock_store_pic( h, 2 );
@@ -1365,7 +1343,7 @@ void x264_macroblock_cache_save( x264_t *h )
             h->mb.ref[0][i_mb_8x8+1+0*s8x8] = h->mb.cache.ref[0][x264_scan8[4]];
             h->mb.ref[0][i_mb_8x8+0+1*s8x8] = h->mb.cache.ref[0][x264_scan8[8]];
             h->mb.ref[0][i_mb_8x8+1+1*s8x8] = h->mb.cache.ref[0][x264_scan8[12]];
-            for( y = 0; y < 4; y++ )
+            for( int y = 0; y < 4; y++ )
             {
                 CP64( h->mb.mv[0][i_mb_4x4+y*s4x4+0], h->mb.cache.mv[0][x264_scan8[0]+8*y+0] );
                 CP64( h->mb.mv[0][i_mb_4x4+y*s4x4+2], h->mb.cache.mv[0][x264_scan8[0]+8*y+2] );
@@ -1376,7 +1354,7 @@ void x264_macroblock_cache_save( x264_t *h )
                 h->mb.ref[1][i_mb_8x8+1+0*s8x8] = h->mb.cache.ref[1][x264_scan8[4]];
                 h->mb.ref[1][i_mb_8x8+0+1*s8x8] = h->mb.cache.ref[1][x264_scan8[8]];
                 h->mb.ref[1][i_mb_8x8+1+1*s8x8] = h->mb.cache.ref[1][x264_scan8[12]];
-                for( y = 0; y < 4; y++ )
+                for( int y = 0; y < 4; y++ )
                 {
                     CP64( h->mb.mv[1][i_mb_4x4+y*s4x4+0], h->mb.cache.mv[1][x264_scan8[0]+8*y+0] );
                     CP64( h->mb.mv[1][i_mb_4x4+y*s4x4+2], h->mb.cache.mv[1][x264_scan8[0]+8*y+2] );
@@ -1385,12 +1363,11 @@ void x264_macroblock_cache_save( x264_t *h )
         }
         else
         {
-            int i_list;
-            for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2  : 1 ); i_list++ )
+            for( int i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2  : 1 ); i_list++ )
             {
                 M16( &h->mb.ref[i_list][i_mb_8x8+0*s8x8] ) = (uint8_t)(-1) * 0x0101;
                 M16( &h->mb.ref[i_list][i_mb_8x8+1*s8x8] ) = (uint8_t)(-1) * 0x0101;
-                for( y = 0; y < 4; y++ )
+                for( int y = 0; y < 4; y++ )
                 {
                     M64( h->mb.mv[i_list][i_mb_4x4+y*s4x4+0] ) = 0;
                     M64( h->mb.mv[i_list][i_mb_4x4+y*s4x4+2] ) = 0;
@@ -1452,14 +1429,13 @@ void x264_macroblock_cache_save( x264_t *h )
 
 void x264_macroblock_bipred_init( x264_t *h )
 {
-    int i_ref0, i_ref1, field;
-    for( field = 0; field <= h->sh.b_mbaff; field++ )
-        for( i_ref0 = 0; i_ref0 < (h->i_ref0<<h->sh.b_mbaff); i_ref0++ )
+    for( int field = 0; field <= h->sh.b_mbaff; field++ )
+        for( int i_ref0 = 0; i_ref0 < (h->i_ref0<<h->sh.b_mbaff); i_ref0++ )
         {
             int poc0 = h->fref0[i_ref0>>h->sh.b_mbaff]->i_poc;
             if( h->sh.b_mbaff && field^(i_ref0&1) )
                 poc0 += h->sh.i_delta_poc_bottom;
-            for( i_ref1 = 0; i_ref1 < (h->i_ref1<<h->sh.b_mbaff); i_ref1++ )
+            for( int i_ref1 = 0; i_ref1 < (h->i_ref1<<h->sh.b_mbaff); i_ref1++ )
             {
                 int dist_scale_factor;
                 int poc1 = h->fref1[i_ref1>>h->sh.b_mbaff]->i_poc;
index 3e75c4c83443fb54fe2ee9d78fe4f32cdd5428a3..b1c5b64daf8f01df9f247af055f7606715c6bc6a 100644 (file)
@@ -346,8 +346,7 @@ static ALWAYS_INLINE int array_non_zero_int( int16_t *v, int i_count )
         return !!(M64( &v[0] ) | M64( &v[4] ) | M64( &v[8] ) | M64( &v[12] ));
     else
     {
-        int i;
-        for( i = 0; i < i_count; i+=4 )
+        for( int i = 0; i < i_count; i+=4 )
             if( M64( &v[i] ) ) return 1;
         return 0;
     }
@@ -372,9 +371,7 @@ static ALWAYS_INLINE int x264_mb_predict_non_zero_code( x264_t *h, int idx )
     int i_ret = za + zb;
 
     if( i_ret < 0x80 )
-    {
         i_ret = ( i_ret + 1 ) >> 1;
-    }
     return i_ret & 0x7f;
 }
 /* x264_mb_transform_8x8_allowed:
index ac41e9b313dc2b051df086cc791e390b6a2fe2c0..859e5fc6097ca98002a7e951feb3f071f22e9cd9 100644 (file)
@@ -39,13 +39,10 @@ static inline void pixel_avg( uint8_t *dst,  int i_dst_stride,
                               uint8_t *src2, int i_src2_stride,
                               int i_width, int i_height )
 {
-    int x, y;
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
-        for( x = 0; x < i_width; x++ )
-        {
+        for( int x = 0; x < i_width; x++ )
             dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
-        }
         dst  += i_dst_stride;
         src1 += i_src1_stride;
         src2 += i_src2_stride;
@@ -54,13 +51,10 @@ static inline void pixel_avg( uint8_t *dst,  int i_dst_stride,
 
 static inline void pixel_avg_wxh( uint8_t *dst, int i_dst, uint8_t *src1, int i_src1, uint8_t *src2, int i_src2, int width, int height )
 {
-    int x, y;
-    for( y = 0; y < height; y++ )
+    for( int y = 0; y < height; y++ )
     {
-        for( x = 0; x < width; x++ )
-        {
+        for( int x = 0; x < width; x++ )
             dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
-        }
         src1 += i_src1;
         src2 += i_src2;
         dst += i_dst;
@@ -72,9 +66,8 @@ static inline void pixel_avg_wxh( uint8_t *dst, int i_dst, uint8_t *src1, int i_
 #define op_scale2(x) dst[x] = x264_clip_uint8( (src1[x]*i_weight1 + src2[x]*i_weight2 + (1<<5)) >> 6 )
 static inline void pixel_avg_weight_wxh( uint8_t *dst, int i_dst, uint8_t *src1, int i_src1, uint8_t *src2, int i_src2, int width, int height, int i_weight1 )
 {
-    int y;
     const int i_weight2 = 64 - i_weight1;
-    for( y = 0; y<height; y++, dst += i_dst, src1 += i_src1, src2 += i_src2 )
+    for( int y = 0; y<height; y++, dst += i_dst, src1 += i_src1, src2 += i_src2 )
     {
         op_scale2(0);
         op_scale2(1);
@@ -128,20 +121,16 @@ static void x264_weight_cache( x264_t *h, x264_weight_t *w )
 #define opscale_noden(x) dst[x] = x264_clip_uint8( src[x] * weight->i_scale + weight->i_offset )
 static inline void mc_weight( uint8_t *dst, int i_dst_stride, uint8_t *src, int i_src_stride, const x264_weight_t *weight, int i_width, int i_height )
 {
-
-    int x, y;
     if( weight->i_denom >= 1 )
     {
-        for( y = 0; y < i_height; y++, dst += i_dst_stride, src += i_src_stride )
-        {
-            for( x = 0; x < i_width; x++ )
+        for( int y = 0; y < i_height; y++, dst += i_dst_stride, src += i_src_stride )
+            for( int x = 0; x < i_width; x++ )
                 opscale( x );
-        }
     }
     else
     {
-        for( y = 0; y < i_height; y++, dst += i_dst_stride, src += i_src_stride )
-            for( x = 0; x < i_width; x++ )
+        for( int y = 0; y < i_height; y++, dst += i_dst_stride, src += i_src_stride )
+            for( int x = 0; x < i_width; x++ )
                 opscale_noden( x );
     }
 }
@@ -149,17 +138,16 @@ static inline void mc_weight( uint8_t *dst, int i_dst_stride, uint8_t *src, int
 #define MC_WEIGHT_C( name, lx ) \
     static void name( uint8_t *dst, int i_dst_stride, uint8_t *src, int i_src_stride, const x264_weight_t *weight, int height ) \
 { \
-    int x, y; \
     if( weight->i_denom >= 1 ) \
     { \
-        for( y = 0; y < height; y++, dst += i_dst_stride, src += i_src_stride ) \
-            for( x = 0; x < lx; x++ ) \
+        for( int y = 0; y < height; y++, dst += i_dst_stride, src += i_src_stride ) \
+            for( int x = 0; x < lx; x++ ) \
                 opscale( x ); \
     } \
     else \
     { \
-        for( y = 0; y < height; y++, dst += i_dst_stride, src += i_src_stride ) \
-            for( x = 0; x < lx; x++ ) \
+        for( int y = 0; y < height; y++, dst += i_dst_stride, src += i_src_stride ) \
+            for( int x = 0; x < lx; x++ ) \
                 opscale_noden( x ); \
     } \
 }
@@ -183,9 +171,7 @@ static weight_fn_t x264_mc_weight_wtab[6] =
 const x264_weight_t weight_none[3] = { {{0}} };
 static void mc_copy( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
 {
-    int y;
-
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
         memcpy( dst, src, i_width );
 
@@ -198,19 +184,18 @@ static void mc_copy( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_str
 static void hpel_filter( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
                          int stride, int width, int height, int16_t *buf )
 {
-    int x, y;
-    for( y=0; y<height; y++ )
+    for( int y = 0; y < height; y++ )
     {
-        for( x=-2; x<width+3; x++ )
+        for( int x = -2; x < width+3; x++ )
         {
             int v = TAPFILTER(src,stride);
-            dstv[x] = x264_clip_uint8((v + 16) >> 5);
+            dstv[x] = x264_clip_uint8( (v + 16) >> 5 );
             buf[x+2] = v;
         }
-        for( x=0; x<width; x++ )
-            dstc[x] = x264_clip_uint8((TAPFILTER(buf+2,1) + 512) >> 10);
-        for( x=0; x<width; x++ )
-            dsth[x] = x264_clip_uint8((TAPFILTER(src,1) + 16) >> 5);
+        for( int x = 0; x < width; x++ )
+            dstc[x] = x264_clip_uint8( (TAPFILTER(buf+2,1) + 512) >> 10 );
+        for( int x = 0; x < width; x++ )
+            dsth[x] = x264_clip_uint8( (TAPFILTER(src,1) + 16) >> 5 );
         dsth += stride;
         dstv += stride;
         dstc += stride;
@@ -281,28 +266,22 @@ static void mc_chroma( uint8_t *dst, int i_dst_stride,
                        int i_width, int i_height )
 {
     uint8_t *srcp;
-    int x, y;
-
-    const int d8x = mvx&0x07;
-    const int d8y = mvy&0x07;
 
-    const int cA = (8-d8x)*(8-d8y);
-    const int cB = d8x    *(8-d8y);
-    const int cC = (8-d8x)*d8y;
-    const int cD = d8x    *d8y;
+    int d8x = mvx&0x07;
+    int d8y = mvy&0x07;
+    int cA = (8-d8x)*(8-d8y);
+    int cB = d8x    *(8-d8y);
+    int cC = (8-d8x)*d8y;
+    int cD = d8x    *d8y;
 
-    src  += (mvy >> 3) * i_src_stride + (mvx >> 3);
+    src += (mvy >> 3) * i_src_stride + (mvx >> 3);
     srcp = &src[i_src_stride];
 
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
-        for( x = 0; x < i_width; x++ )
-        {
-            dst[x] = ( cA*src[x]  + cB*src[x+1] +
-                       cC*srcp[x] + cD*srcp[x+1] + 32 ) >> 6;
-        }
+        for( int x = 0; x < i_width; x++ )
+            dst[x] = ( cA*src[x]  + cB*src[x+1] + cC*srcp[x] + cD*srcp[x+1] + 32 ) >> 6;
         dst  += i_dst_stride;
-
         src   = srcp;
         srcp += i_src_stride;
     }
@@ -342,8 +321,8 @@ static void memzero_aligned( void * dst, int n )
 
 static void integral_init4h( uint16_t *sum, uint8_t *pix, int stride )
 {
-    int x, v = pix[0]+pix[1]+pix[2]+pix[3];
-    for( x=0; x<stride-4; x++ )
+    int v = pix[0]+pix[1]+pix[2]+pix[3];
+    for( int x = 0; x < stride-4; x++ )
     {
         sum[x] = v + sum[x-stride];
         v += pix[x+4] - pix[x];
@@ -352,8 +331,8 @@ static void integral_init4h( uint16_t *sum, uint8_t *pix, int stride )
 
 static void integral_init8h( uint16_t *sum, uint8_t *pix, int stride )
 {
-    int x, v = pix[0]+pix[1]+pix[2]+pix[3]+pix[4]+pix[5]+pix[6]+pix[7];
-    for( x=0; x<stride-8; x++ )
+    int v = pix[0]+pix[1]+pix[2]+pix[3]+pix[4]+pix[5]+pix[6]+pix[7];
+    for( int x = 0; x < stride-8; x++ )
     {
         sum[x] = v + sum[x-stride];
         v += pix[x+8] - pix[x];
@@ -362,17 +341,15 @@ static void integral_init8h( uint16_t *sum, uint8_t *pix, int stride )
 
 static void integral_init4v( uint16_t *sum8, uint16_t *sum4, int stride )
 {
-    int x;
-    for( x=0; x<stride-8; x++ )
+    for( int x = 0; x < stride-8; x++ )
         sum4[x] = sum8[x+4*stride] - sum8[x];
-    for( x=0; x<stride-8; x++ )
+    for( int x = 0; x < stride-8; x++ )
         sum8[x] = sum8[x+8*stride] + sum8[x+8*stride+4] - sum8[x] - sum8[x+4];
 }
 
 static void integral_init8v( uint16_t *sum8, int stride )
 {
-    int x;
-    for( x=0; x<stride-8; x++ )
+    for( int x = 0; x < stride-8; x++ )
         sum8[x] = sum8[x+8*stride] - sum8[x];
 }
 
@@ -382,10 +359,9 @@ void x264_frame_init_lowres( x264_t *h, x264_frame_t *frame )
     int i_stride = frame->i_stride[0];
     int i_height = frame->i_lines[0];
     int i_width  = frame->i_width[0];
-    int x, y;
 
     // duplicate last row and column so that their interpolation doesn't have to be special-cased
-    for( y=0; y<i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
         src[i_width+y*i_stride] = src[i_width-1+y*i_stride];
     memcpy( src+i_stride*i_height, src+i_stride*(i_height-1), i_width+1 );
     h->mc.frame_init_lowres_core( src, frame->lowres[0], frame->lowres[1], frame->lowres[2], frame->lowres[3],
@@ -394,24 +370,23 @@ void x264_frame_init_lowres( x264_t *h, x264_frame_t *frame )
 
     memset( frame->i_cost_est, -1, sizeof(frame->i_cost_est) );
 
-    for( x = 0; x < h->param.i_bframe + 2; x++ )
-        for( y = 0; y < h->param.i_bframe + 2; y++ )
+    for( int y = 0; y < h->param.i_bframe + 2; y++ )
+        for( int x = 0; x < h->param.i_bframe + 2; x++ )
             frame->i_row_satds[y][x][0] = -1;
 
-    for( y = 0; y <= !!h->param.i_bframe; y++ )
-        for( x = 0; x <= h->param.i_bframe; x++ )
+    for( int y = 0; y <= !!h->param.i_bframe; y++ )
+        for( int x = 0; x <= h->param.i_bframe; x++ )
             frame->lowres_mvs[y][x][0][0] = 0x7FFF;
 }
 
 static void frame_init_lowres_core( uint8_t *src0, uint8_t *dst0, uint8_t *dsth, uint8_t *dstv, uint8_t *dstc,
                                     int src_stride, int dst_stride, int width, int height )
 {
-    int x,y;
-    for( y=0; y<height; y++ )
+    for( int y = 0; y < height; y++ )
     {
         uint8_t *src1 = src0+src_stride;
         uint8_t *src2 = src1+src_stride;
-        for( x=0; x<width; x++ )
+        for( int x = 0; x<width; x++ )
         {
             // slower than naive bilinear, but matches asm
 #define FILTER(a,b,c,d) ((((a+b+1)>>1)+((c+d+1)>>1)+1)>>1)
@@ -431,7 +406,8 @@ static void frame_init_lowres_core( uint8_t *src0, uint8_t *dst0, uint8_t *dsth,
 
 #if defined(__GNUC__) && (defined(ARCH_X86) || defined(ARCH_X86_64))
 // gcc isn't smart enough to use the "idiv" instruction
-static ALWAYS_INLINE int32_t div_64_32(int64_t x, int32_t y) {
+static ALWAYS_INLINE int32_t div_64_32(int64_t x, int32_t y)
+{
     int32_t quotient, remainder;
     asm("idiv %4"
         :"=a"(quotient), "=d"(remainder)
@@ -448,8 +424,7 @@ static ALWAYS_INLINE int32_t div_64_32(int64_t x, int32_t y) {
 static void mbtree_propagate_cost( int *dst, uint16_t *propagate_in, uint16_t *intra_costs,
                                    uint16_t *inter_costs, uint16_t *inv_qscales, int len )
 {
-    int i;
-    for( i=0; i<len; i++ )
+    for( int i = 0; i < len; i++ )
     {
         int propagate_amount = propagate_in[i] + ((intra_costs[i] * inv_qscales[i] + 128)>>8);
         dst[i] = div_64_32((int64_t)propagate_amount * (intra_costs[i] - inter_costs[i]), intra_costs[i]);
@@ -519,12 +494,11 @@ void x264_frame_filter( x264_t *h, x264_frame_t *frame, int mb_y, int b_end )
     int start = (mb_y*16 >> b_interlaced) - 8; // buffer = 4 for deblock + 3 for 6tap, rounded to 8
     int height = ((b_end ? frame->i_lines[0] : mb_y*16) >> b_interlaced) + 8;
     int offs = start*stride - 8; // buffer = 3 for 6tap, aligned to 8 for simd
-    int y;
 
     if( mb_y & b_interlaced )
         return;
 
-    for( y=0; y<=b_interlaced; y++, offs+=frame->i_stride[0] )
+    for( int y = 0; y <= b_interlaced; y++, offs += frame->i_stride[0] )
     {
         h->mc.hpel_filter(
             frame->filtered[1] + offs,
@@ -549,7 +523,7 @@ void x264_frame_filter( x264_t *h, x264_frame_t *frame, int mb_y, int b_end )
         }
         if( b_end )
             height += PADV-9;
-        for( y = start; y < height; y++ )
+        for( int y = start; y < height; y++ )
         {
             uint8_t  *pix  = frame->plane[0] + y * stride - PADH;
             uint16_t *sum8 = frame->integral + (y+1) * stride - PADH;
index a6a83f6b2cd6e6033627ebc3cbc9c7af10beb5e6..f97547f75f472e1425f25ddc4252efc7e5f1c073 100644 (file)
@@ -38,7 +38,8 @@
 #endif
 
 #ifndef HAVE_LOG2F
-#define log2f(x) (logf((x))/0.693147180559945f)
+#define log2f(x) (logf(x)/0.693147180559945f)
+#define log2(x) (log(x)/0.693147180559945)
 #endif
 
 #ifdef _WIN32
index 02c490fd53819a12a4e171ca86176a1e5e5f4aec..20c5170aebe132ec3aad7f84e736622b03bd9447 100644 (file)
@@ -45,10 +45,9 @@ static int name( uint8_t *pix1, int i_stride_pix1,  \
                  uint8_t *pix2, int i_stride_pix2 ) \
 {                                                   \
     int i_sum = 0;                                  \
-    int x, y;                                       \
-    for( y = 0; y < ly; y++ )                       \
+    for( int y = 0; y < ly; y++ )                   \
     {                                               \
-        for( x = 0; x < lx; x++ )                   \
+        for( int x = 0; x < lx; x++ )               \
         {                                           \
             i_sum += abs( pix1[x] - pix2[x] );      \
         }                                           \
@@ -76,10 +75,9 @@ static int name( uint8_t *pix1, int i_stride_pix1,  \
                  uint8_t *pix2, int i_stride_pix2 ) \
 {                                                   \
     int i_sum = 0;                                  \
-    int x, y;                                       \
-    for( y = 0; y < ly; y++ )                       \
+    for( int y = 0; y < ly; y++ )                   \
     {                                               \
-        for( x = 0; x < lx; x++ )                   \
+        for( int x = 0; x < lx; x++ )               \
         {                                           \
             int d = pix1[x] - pix2[x];              \
             i_sum += d*d;                           \
@@ -101,14 +99,14 @@ PIXEL_SSD_C( x264_pixel_ssd_4x4,    4,  4 )
 int64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2, int i_width, int i_height )
 {
     int64_t i_ssd = 0;
-    int x, y;
+    int y;
     int align = !(((intptr_t)pix1 | (intptr_t)pix2 | i_pix1 | i_pix2) & 15);
 
 #define SSD(size) i_ssd += pf->ssd[size]( pix1 + y*i_pix1 + x, i_pix1, \
                                           pix2 + y*i_pix2 + x, i_pix2 );
     for( y = 0; y < i_height-15; y += 16 )
     {
-        x = 0;
+        int x = 0;
         if( align )
             for( ; x < i_width-15; x += 16 )
                 SSD(PIXEL_16x16);
@@ -116,21 +114,21 @@ int64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, uint8_t *pix1, int i_pix1
             SSD(PIXEL_8x16);
     }
     if( y < i_height-7 )
-        for( x = 0; x < i_width-7; x += 8 )
+        for( int x = 0; x < i_width-7; x += 8 )
             SSD(PIXEL_8x8);
 #undef SSD
 
 #define SSD1 { int d = pix1[y*i_pix1+x] - pix2[y*i_pix2+x]; i_ssd += d*d; }
-    if( i_width % 8 != 0 )
+    if( i_width & 7 )
     {
         for( y = 0; y < (i_height & ~7); y++ )
-            for( x = i_width & ~7; x < i_width; x++ )
+            for( int x = i_width & ~7; x < i_width; x++ )
                 SSD1;
     }
-    if( i_height % 8 != 0 )
+    if( i_height & 7 )
     {
         for( y = i_height & ~7; y < i_height; y++ )
-            for( x = 0; x < i_width; x++ )
+            for( int x = 0; x < i_width; x++ )
                 SSD1;
     }
 #undef SSD1
@@ -146,10 +144,9 @@ int64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, uint8_t *pix1, int i_pix1
 static uint64_t name( uint8_t *pix, int i_stride ) \
 {                                             \
     uint32_t sum = 0, sqr = 0;                \
-    int x, y;                                 \
-    for( y = 0; y < w; y++ )                  \
+    for( int y = 0; y < w; y++ )              \
     {                                         \
-        for( x = 0; x < w; x++ )              \
+        for( int x = 0; x < w; x++ )          \
         {                                     \
             sum += pix[x];                    \
             sqr += pix[x] * pix[x];           \
@@ -168,10 +165,9 @@ PIXEL_VAR_C( x264_pixel_var_8x8,    8 )
 static int pixel_var2_8x8( uint8_t *pix1, int i_stride1, uint8_t *pix2, int i_stride2, int *ssd )
 {
     uint32_t var = 0, sum = 0, sqr = 0;
-    int x, y;
-    for( y = 0; y < 8; y++ )
+    for( int y = 0; y < 8; y++ )
     {
-        for( x = 0; x < 8; x++ )
+        for( int x = 0; x < 8; x++ )
         {
             int diff = pix1[x] - pix2[x];
             sum += diff;
@@ -187,7 +183,7 @@ static int pixel_var2_8x8( uint8_t *pix1, int i_stride1, uint8_t *pix2, int i_st
 }
 
 
-#define HADAMARD4(d0,d1,d2,d3,s0,s1,s2,s3) {\
+#define HADAMARD4(d0, d1, d2, d3, s0, s1, s2, s3) {\
     int t0 = s0 + s1;\
     int t1 = s0 - s1;\
     int t2 = s2 + s3;\
@@ -213,9 +209,9 @@ static ALWAYS_INLINE uint32_t abs2( uint32_t a )
 static NOINLINE int x264_pixel_satd_4x4( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
 {
     uint32_t tmp[4][2];
-    uint32_t a0,a1,a2,a3,b0,b1;
-    int sum=0, i;
-    for( i=0; i<4; i++, pix1+=i_pix1, pix2+=i_pix2 )
+    uint32_t a0, a1, a2, a3, b0, b1;
+    int sum = 0;
+    for( int i = 0; i < 4; i++, pix1 += i_pix1, pix2 += i_pix2 )
     {
         a0 = pix1[0] - pix2[0];
         a1 = pix1[1] - pix2[1];
@@ -226,9 +222,9 @@ static NOINLINE int x264_pixel_satd_4x4( uint8_t *pix1, int i_pix1, uint8_t *pix
         tmp[i][0] = b0 + b1;
         tmp[i][1] = b0 - b1;
     }
-    for( i=0; i<2; i++ )
+    for( int i = 0; i < 2; i++ )
     {
-        HADAMARD4( a0,a1,a2,a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );
+        HADAMARD4( a0, a1, a2, a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );
         a0 = abs2(a0) + abs2(a1) + abs2(a2) + abs2(a3);
         sum += ((uint16_t)a0) + (a0>>16);
     }
@@ -238,9 +234,9 @@ static NOINLINE int x264_pixel_satd_4x4( uint8_t *pix1, int i_pix1, uint8_t *pix
 static NOINLINE int x264_pixel_satd_8x4( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
 {
     uint32_t tmp[4][4];
-    uint32_t a0,a1,a2,a3;
-    int sum=0, i;
-    for( i=0; i<4; i++, pix1+=i_pix1, pix2+=i_pix2 )
+    uint32_t a0, a1, a2, a3;
+    int sum = 0;
+    for( int i = 0; i < 4; i++, pix1 += i_pix1, pix2 += i_pix2 )
     {
         a0 = (pix1[0] - pix2[0]) + ((pix1[4] - pix2[4]) << 16);
         a1 = (pix1[1] - pix2[1]) + ((pix1[5] - pix2[5]) << 16);
@@ -248,9 +244,9 @@ static NOINLINE int x264_pixel_satd_8x4( uint8_t *pix1, int i_pix1, uint8_t *pix
         a3 = (pix1[3] - pix2[3]) + ((pix1[7] - pix2[7]) << 16);
         HADAMARD4( tmp[i][0], tmp[i][1], tmp[i][2], tmp[i][3], a0,a1,a2,a3 );
     }
-    for( i=0; i<4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        HADAMARD4( a0,a1,a2,a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );
+        HADAMARD4( a0, a1, a2, a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );
         sum += abs2(a0) + abs2(a1) + abs2(a2) + abs2(a3);
     }
     return (((uint16_t)sum) + ((uint32_t)sum>>16)) >> 1;
@@ -282,9 +278,9 @@ PIXEL_SATD_C( 4,  8,  x264_pixel_satd_4x4 )
 static NOINLINE int sa8d_8x8( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
 {
     uint32_t tmp[8][4];
-    uint32_t a0,a1,a2,a3,a4,a5,a6,a7,b0,b1,b2,b3;
-    int sum=0, i;
-    for( i=0; i<8; i++, pix1+=i_pix1, pix2+=i_pix2 )
+    uint32_t a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3;
+    int sum = 0;
+    for( int i = 0; i < 8; i++, pix1 += i_pix1, pix2 += i_pix2 )
     {
         a0 = pix1[0] - pix2[0];
         a1 = pix1[1] - pix2[1];
@@ -300,10 +296,10 @@ static NOINLINE int sa8d_8x8( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pi
         b3 = (a6+a7) + ((a6-a7)<<16);
         HADAMARD4( tmp[i][0], tmp[i][1], tmp[i][2], tmp[i][3], b0,b1,b2,b3 );
     }
-    for( i=0; i<4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
-        HADAMARD4( a0,a1,a2,a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );
-        HADAMARD4( a4,a5,a6,a7, tmp[4][i], tmp[5][i], tmp[6][i], tmp[7][i] );
+        HADAMARD4( a0, a1, a2, a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );
+        HADAMARD4( a4, a5, a6, a7, tmp[4][i], tmp[5][i], tmp[6][i], tmp[7][i] );
         b0  = abs2(a0+a4) + abs2(a0-a4);
         b0 += abs2(a1+a5) + abs2(a1-a5);
         b0 += abs2(a2+a6) + abs2(a2-a6);
@@ -332,9 +328,9 @@ static int x264_pixel_sa8d_16x16( uint8_t *pix1, int i_pix1, uint8_t *pix2, int
 static NOINLINE uint64_t pixel_hadamard_ac( uint8_t *pix, int stride )
 {
     uint32_t tmp[32];
-    uint32_t a0,a1,a2,a3,dc;
-    int sum4=0, sum8=0, i;
-    for( i=0; i<8; i++, pix+=stride )
+    uint32_t a0, a1, a2, a3, dc;
+    int sum4 = 0, sum8 = 0;
+    for( int i = 0; i < 8; i++, pix+=stride )
     {
         uint32_t *t = tmp + (i&3) + (i&4)*4;
         a0 = (pix[0]+pix[1]) + ((pix[0]-pix[1])<<16);
@@ -346,16 +342,16 @@ static NOINLINE uint64_t pixel_hadamard_ac( uint8_t *pix, int stride )
         t[8] = a2 + a3;
         t[12] = a2 - a3;
     }
-    for( i=0; i<8; i++ )
+    for( int i = 0; i < 8; i++ )
     {
-        HADAMARD4( a0,a1,a2,a3, tmp[i*4+0], tmp[i*4+1], tmp[i*4+2], tmp[i*4+3] );
+        HADAMARD4( a0, a1, a2, a3, tmp[i*4+0], tmp[i*4+1], tmp[i*4+2], tmp[i*4+3] );
         tmp[i*4+0] = a0;
         tmp[i*4+1] = a1;
         tmp[i*4+2] = a2;
         tmp[i*4+3] = a3;
         sum4 += abs2(a0) + abs2(a1) + abs2(a2) + abs2(a3);
     }
-    for( i=0; i<8; i++ )
+    for( int i = 0; i < 8; i++ )
     {
         HADAMARD4( a0,a1,a2,a3, tmp[i], tmp[8+i], tmp[16+i], tmp[24+i] );
         sum8 += abs2(a0) + abs2(a1) + abs2(a2) + abs2(a3);
@@ -466,12 +462,11 @@ static void ssim_4x4x2_core( const uint8_t *pix1, int stride1,
                              const uint8_t *pix2, int stride2,
                              int sums[2][4])
 {
-    int x, y, z;
-    for(z=0; z<2; z++)
+    for( int z = 0; z < 2; z++ )
     {
-        uint32_t s1=0, s2=0, ss=0, s12=0;
-        for(y=0; y<4; y++)
-            for(x=0; x<4; x++)
+        uint32_t s1 = 0, s2 = 0, ss = 0, s12 = 0;
+        for( int y = 0; y < 4; y++ )
+            for( int x = 0; x < 4; x++ )
             {
                 int a = pix1[x+y*stride1];
                 int b = pix2[x+y*stride2];
@@ -496,15 +491,14 @@ static float ssim_end1( int s1, int s2, int ss, int s12 )
     static const int ssim_c2 = (int)(.03*.03*255*255*64*63 + .5);
     int vars = ss*64 - s1*s1 - s2*s2;
     int covar = s12*64 - s1*s2;
-    return (float)(2*s1*s2 + ssim_c1) * (float)(2*covar + ssim_c2)\
-           / ((float)(s1*s1 + s2*s2 + ssim_c1) * (float)(vars + ssim_c2));
+    return (float)(2*s1*s2 + ssim_c1) * (float)(2*covar + ssim_c2)
+         / ((float)(s1*s1 + s2*s2 + ssim_c1) * (float)(vars + ssim_c2));
 }
 
 static float ssim_end4( int sum0[5][4], int sum1[5][4], int width )
 {
-    int i;
     float ssim = 0.0;
-    for( i = 0; i < width; i++ )
+    for( int i = 0; i < width; i++ )
         ssim += ssim_end1( sum0[i][0] + sum0[i+1][0] + sum1[i][0] + sum1[i+1][0],
                            sum0[i][1] + sum0[i+1][1] + sum1[i][1] + sum1[i+1][1],
                            sum0[i][2] + sum0[i+1][2] + sum1[i][2] + sum1[i+1][2],
@@ -517,22 +511,21 @@ float x264_pixel_ssim_wxh( x264_pixel_function_t *pf,
                            uint8_t *pix2, int stride2,
                            int width, int height, void *buf )
 {
-    int x, y, z;
+    int z = 0;
     float ssim = 0.0;
     int (*sum0)[4] = buf;
     int (*sum1)[4] = sum0 + width/4+3;
     width >>= 2;
     height >>= 2;
-    z = 0;
-    for( y = 1; y < height; y++ )
+    for( int y = 1; y < height; y++ )
     {
         for( ; z <= y; z++ )
         {
             XCHG( void*, sum0, sum1 );
-            for( x = 0; x < width; x+=2 )
+            for( int x = 0; x < width; x+=2 )
                 pf->ssim_4x4x2_core( &pix1[4*(x+z*stride1)], stride1, &pix2[4*(x+z*stride2)], stride2, &sum0[x] );
         }
-        for( x = 0; x < width-1; x += 4 )
+        for( int x = 0; x < width-1; x += 4 )
             ssim += pf->ssim_end4( sum0+x, sum1+x, X264_MIN(4,width-x-1) );
     }
     return ssim;
@@ -545,8 +538,8 @@ float x264_pixel_ssim_wxh( x264_pixel_function_t *pf,
 static int x264_pixel_ads4( int enc_dc[4], uint16_t *sums, int delta,
                             uint16_t *cost_mvx, int16_t *mvs, int width, int thresh )
 {
-    int nmv=0, i;
-    for( i=0; i<width; i++, sums++ )
+    int nmv = 0;
+    for( int i = 0; i < width; i++, sums++ )
     {
         int ads = abs( enc_dc[0] - sums[0] )
                 + abs( enc_dc[1] - sums[8] )
@@ -562,8 +555,8 @@ static int x264_pixel_ads4( int enc_dc[4], uint16_t *sums, int delta,
 static int x264_pixel_ads2( int enc_dc[2], uint16_t *sums, int delta,
                             uint16_t *cost_mvx, int16_t *mvs, int width, int thresh )
 {
-    int nmv=0, i;
-    for( i=0; i<width; i++, sums++ )
+    int nmv = 0;
+    for( int i = 0; i < width; i++, sums++ )
     {
         int ads = abs( enc_dc[0] - sums[0] )
                 + abs( enc_dc[1] - sums[delta] )
@@ -577,8 +570,8 @@ static int x264_pixel_ads2( int enc_dc[2], uint16_t *sums, int delta,
 static int x264_pixel_ads1( int enc_dc[1], uint16_t *sums, int delta,
                             uint16_t *cost_mvx, int16_t *mvs, int width, int thresh )
 {
-    int nmv=0, i;
-    for( i=0; i<width; i++, sums++ )
+    int nmv = 0;
+    for( int i = 0; i<width; i++, sums++ )
     {
         int ads = abs( enc_dc[0] - sums[0] )
                 + cost_mvx[i];
index d79d782efc4324568311d2051b2c988b88d3b8a9..fdadf535ff254c7adf0fa37f9a677b5804dc1110 100644 (file)
@@ -36,8 +36,7 @@
     b3 = vec_sub( a0, a1 );              \
     b3 = vec_sub( b3, a1 )
 
-void x264_sub4x4_dct_altivec( int16_t dct[4][4],
-        uint8_t *pix1, uint8_t *pix2 )
+void x264_sub4x4_dct_altivec( int16_t dct[4][4], uint8_t *pix1, uint8_t *pix2 )
 {
     PREP_DIFF_8BYTEALIGNED;
     vec_s16_t dct0v, dct1v, dct2v, dct3v;
@@ -59,8 +58,7 @@ void x264_sub4x4_dct_altivec( int16_t dct[4][4],
     vec_st(vec_perm(tmp2v, tmp3v, permHighv), 16, (int16_t*)dct);
 }
 
-void x264_sub8x8_dct_altivec( int16_t dct[4][4][4],
-        uint8_t *pix1, uint8_t *pix2 )
+void x264_sub8x8_dct_altivec( int16_t dct[4][4][4], uint8_t *pix1, uint8_t *pix2 )
 {
     PREP_DIFF_8BYTEALIGNED;
     vec_s16_t dct0v, dct1v, dct2v, dct3v, dct4v, dct5v, dct6v, dct7v;
@@ -99,8 +97,7 @@ void x264_sub8x8_dct_altivec( int16_t dct[4][4][4],
     vec_st(vec_perm(tmp6v, tmp7v, permLowv),  112, (int16_t*)dct);
 }
 
-void x264_sub16x16_dct_altivec( int16_t dct[16][4][4],
-        uint8_t *pix1, uint8_t *pix2 ) 
+void x264_sub16x16_dct_altivec( int16_t dct[16][4][4], uint8_t *pix1, uint8_t *pix2 )
 {
     x264_sub8x8_dct_altivec( &dct[ 0], &pix1[0], &pix2[0] );
     x264_sub8x8_dct_altivec( &dct[ 4], &pix1[8], &pix2[8] );
index 6b2664168f8904d7ec452200678feff268b4d4d9..f5466645879dc709badf1bd3b4c9ef8f703c4f4e 100644 (file)
 #ifndef X264_PPC_DCT_H
 #define X264_PPC_DCT_H
 
-void x264_sub4x4_dct_altivec( int16_t dct[4][4],
-        uint8_t *pix1, uint8_t *pix2 );
-void x264_sub8x8_dct_altivec( int16_t dct[4][4][4],
-        uint8_t *pix1, uint8_t *pix2 );
-void x264_sub16x16_dct_altivec( int16_t dct[16][4][4],
-        uint8_t *pix1, uint8_t *pix2 );
+void x264_sub4x4_dct_altivec( int16_t dct[4][4], uint8_t *pix1, uint8_t *pix2 );
+void x264_sub8x8_dct_altivec( int16_t dct[4][4][4], uint8_t *pix1, uint8_t *pix2 );
+void x264_sub16x16_dct_altivec( int16_t dct[16][4][4], uint8_t *pix1, uint8_t *pix2 );
 
 void x264_add4x4_idct_altivec( uint8_t *p_dst, int16_t dct[4][4] );
 void x264_add8x8_idct_altivec( uint8_t *p_dst, int16_t dct[4][4][4] );
 void x264_add16x16_idct_altivec( uint8_t *p_dst, int16_t dct[16][4][4] );
 
-void x264_sub8x8_dct8_altivec( int16_t dct[8][8],
-        uint8_t *pix1, uint8_t *pix2 );
-void x264_sub16x16_dct8_altivec( int16_t dct[4][8][8],
-        uint8_t *pix1, uint8_t *pix2 );
+void x264_sub8x8_dct8_altivec( int16_t dct[8][8], uint8_t *pix1, uint8_t *pix2 );
+void x264_sub16x16_dct8_altivec( int16_t dct[4][8][8], uint8_t *pix1, uint8_t *pix2 );
 
 void x264_add8x8_idct8_altivec( uint8_t *dst, int16_t dct[8][8] );
 void x264_add16x16_idct8_altivec( uint8_t *dst, int16_t dct[4][8][8] );
index 14171e615c15c0db8c8c3be21be7bde5981db76f..0b6c7384d67c33a437b3fd3cb56755bcbb819574 100644 (file)
@@ -21,7 +21,8 @@
 #include "common/common.h"
 #include "ppccommon.h"
 
-#define transpose4x16(r0, r1, r2, r3) {      \
+#define transpose4x16(r0, r1, r2, r3)        \
+{                                            \
     register vec_u8_t r4;                    \
     register vec_u8_t r5;                    \
     register vec_u8_t r6;                    \
     r3 = vec_mergel(r5, r7);  /*all set 3*/  \
 }
 
-static inline void write16x4(uint8_t *dst, int dst_stride,
-                             register vec_u8_t r0, register vec_u8_t r1,
-                             register vec_u8_t r2, register vec_u8_t r3) {
+static inline void write16x4( uint8_t *dst, int dst_stride,
+                              register vec_u8_t r0, register vec_u8_t r1,
+                              register vec_u8_t r2, register vec_u8_t r3 )
+{
     ALIGNED_16(unsigned char result[64]);
     uint32_t *src_int = (uint32_t *)result, *dst_int = (uint32_t *)dst;
     int int_dst_stride = dst_stride/4;
@@ -69,7 +71,8 @@ static inline void write16x4(uint8_t *dst, int dst_stride,
 }
 
 /** \brief performs a 6x16 transpose of data in src, and stores it to dst */
-#define readAndTranspose16x6(src, src_stride, r8, r9, r10, r11, r12, r13) {\
+#define readAndTranspose16x6(src, src_stride, r8, r9, r10, r11, r12, r13)\
+{\
     register vec_u8_t r0, r1, r2, r3, r4, r5, r6, r7, r14, r15;\
     VEC_LOAD(src,                  r0, 16, vec_u8_t, pix );    \
     VEC_LOAD(src +    src_stride,  r1, 16, vec_u8_t, pix );    \
@@ -130,10 +133,8 @@ static inline void write16x4(uint8_t *dst, int dst_stride,
 }
 
 // out: o = |x-y| < a
-static inline vec_u8_t diff_lt_altivec ( register vec_u8_t x,
-                                         register vec_u8_t y,
-                                         register vec_u8_t a) {
-
+static inline vec_u8_t diff_lt_altivec( register vec_u8_t x, register vec_u8_t y, register vec_u8_t a )
+{
     register vec_u8_t diff = vec_subs(x, y);
     register vec_u8_t diffneg = vec_subs(y, x);
     register vec_u8_t o = vec_or(diff, diffneg); /* |x-y| */
@@ -141,13 +142,9 @@ static inline vec_u8_t diff_lt_altivec ( register vec_u8_t x,
     return o;
 }
 
-static inline vec_u8_t h264_deblock_mask ( register vec_u8_t p0,
-                                           register vec_u8_t p1,
-                                           register vec_u8_t q0,
-                                           register vec_u8_t q1,
-                                           register vec_u8_t alpha,
-                                           register vec_u8_t beta) {
-
+static inline vec_u8_t h264_deblock_mask( register vec_u8_t p0, register vec_u8_t p1, register vec_u8_t q0,
+                                          register vec_u8_t q1, register vec_u8_t alpha, register vec_u8_t beta )
+{
     register vec_u8_t mask;
     register vec_u8_t tempmask;
 
@@ -161,11 +158,9 @@ static inline vec_u8_t h264_deblock_mask ( register vec_u8_t p0,
 }
 
 // out: newp1 = clip((p2 + ((p0 + q0 + 1) >> 1)) >> 1, p1-tc0, p1+tc0)
-static inline vec_u8_t h264_deblock_q1(register vec_u8_t p0,
-                                       register vec_u8_t p1,
-                                       register vec_u8_t p2,
-                                       register vec_u8_t q0,
-                                       register vec_u8_t tc0) {
+static inline vec_u8_t h264_deblock_q1( register vec_u8_t p0, register vec_u8_t p1, register vec_u8_t p2,
+                                        register vec_u8_t q0, register vec_u8_t tc0 )
+{
 
     register vec_u8_t average = vec_avg(p0, q0);
     register vec_u8_t temp;
@@ -187,8 +182,8 @@ static inline vec_u8_t h264_deblock_q1(register vec_u8_t p0,
     return newp1;
 }
 
-#define h264_deblock_p0_q0(p0, p1, q0, q1, tc0masked) {                                         \
-                                                                                                \
+#define h264_deblock_p0_q0(p0, p1, q0, q1, tc0masked)                                           \
+{                                                                                               \
     const vec_u8_t A0v = vec_sl(vec_splat_u8(10), vec_splat_u8(4));                             \
                                                                                                 \
     register vec_u8_t pq0bit = vec_xor(p0,q0);                                                  \
@@ -219,8 +214,9 @@ static inline vec_u8_t h264_deblock_q1(register vec_u8_t p0,
     q0 = vec_adds(q0, deltaneg);                                                                \
 }
 
-#define h264_loop_filter_luma_altivec(p2, p1, p0, q0, q1, q2, alpha, beta, tc0) {            \
-    ALIGNED_16(unsigned char temp[16]);                                              \
+#define h264_loop_filter_luma_altivec(p2, p1, p0, q0, q1, q2, alpha, beta, tc0)              \
+{                                                                                            \
+    ALIGNED_16(unsigned char temp[16]);                                                      \
     register vec_u8_t alphavec;                                                              \
     register vec_u8_t betavec;                                                               \
     register vec_u8_t mask;                                                                  \
@@ -239,7 +235,7 @@ static inline vec_u8_t h264_deblock_q1(register vec_u8_t p0,
     alphavec = vec_splat(alphavec, 0x0);                                                     \
     mask = h264_deblock_mask(p0, p1, q0, q1, alphavec, betavec); /*if in block */            \
                                                                                              \
-    *((int *)temp) = *((int *)tc0);                                                          \
+    M32( temp ) = M32( tc0 );                                                                \
     tc0vec = vec_ld(0, (signed char*)temp);                                                  \
     tc0vec = vec_mergeh(tc0vec, tc0vec);                                                     \
     tc0vec = vec_mergeh(tc0vec, tc0vec);                                                     \
@@ -265,9 +261,10 @@ static inline vec_u8_t h264_deblock_q1(register vec_u8_t p0,
     q1 = newq1;                                                                              \
 }
 
-void x264_deblock_v_luma_altivec(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) {
-
-    if((tc0[0] & tc0[1] & tc0[2] & tc0[3]) >= 0) {
+void x264_deblock_v_luma_altivec( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
+{
+    if( (tc0[0] & tc0[1] & tc0[2] & tc0[3]) >= 0 )
+    {
         register vec_u8_t p2 = vec_ld(-3*stride, pix);
         register vec_u8_t p1 = vec_ld(-2*stride, pix);
         register vec_u8_t p0 = vec_ld(-1*stride, pix);
@@ -282,10 +279,11 @@ void x264_deblock_v_luma_altivec(uint8_t *pix, int stride, int alpha, int beta,
     }
 }
 
-void x264_deblock_h_luma_altivec(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) {
+void x264_deblock_h_luma_altivec( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
+{
 
     register vec_u8_t line0, line1, line2, line3, line4, line5;
-    if((tc0[0] & tc0[1] & tc0[2] & tc0[3]) < 0)
+    if( (tc0[0] & tc0[1] & tc0[2] & tc0[3]) < 0 )
         return;
     PREP_LOAD;
     vec_u8_t _pix_ = vec_lvsl(0, pix-3);
index a588d8f2ec63bf505c400ffab42ebfde633683ac..dfe250a7fccb7818ec287dfa5943dd5c8ebf4c3c 100644 (file)
@@ -58,13 +58,10 @@ static inline void x264_pixel_avg2_w4_altivec( uint8_t *dst,  int i_dst,
                                                uint8_t *src1, int i_src1,
                                                uint8_t *src2, int i_height )
 {
-    int x, y;
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
-        for( x = 0; x < 4; x++ )
-        {
+        for( int x = 0; x < 4; x++ )
             dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
-        }
         dst  += i_dst;
         src1 += i_src1;
         src2 += i_src1;
@@ -75,14 +72,13 @@ static inline void x264_pixel_avg2_w8_altivec( uint8_t *dst,  int i_dst,
                                                uint8_t *src1, int i_src1,
                                                uint8_t *src2, int i_height )
 {
-    int y;
     vec_u8_t src1v, src2v;
     PREP_LOAD;
     PREP_STORE8;
     PREP_LOAD_SRC( src1 );
     PREP_LOAD_SRC( src2 );
 
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
         VEC_LOAD( src1, src1v, 8, vec_u8_t, src1 );
         VEC_LOAD( src2, src2v, 8, vec_u8_t, src2 );
@@ -99,13 +95,12 @@ static inline void x264_pixel_avg2_w16_altivec( uint8_t *dst,  int i_dst,
                                                 uint8_t *src1, int i_src1,
                                                 uint8_t *src2, int i_height )
 {
-    int y;
     vec_u8_t src1v, src2v;
     PREP_LOAD;
     PREP_LOAD_SRC( src1 );
     PREP_LOAD_SRC( src2 );
 
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
         VEC_LOAD( src1, src1v, 16, vec_u8_t, src1 );
         VEC_LOAD( src2, src2v, 16, vec_u8_t, src2 );
@@ -146,12 +141,11 @@ MC_COPY( x264_mc_copy_w8_altivec,  8  )
 static void x264_mc_copy_w16_altivec( uint8_t *dst, int i_dst,
                                       uint8_t *src, int i_src, int i_height )
 {
-    int y;
     vec_u8_t cpyV;
     PREP_LOAD;
     PREP_LOAD_SRC( src );
 
-    for( y = 0; y < i_height; y++)
+    for( int y = 0; y < i_height; y++)
     {
         VEC_LOAD( src, cpyV, 16, vec_u8_t, src );
         vec_st(cpyV, 0, dst);
@@ -165,9 +159,7 @@ static void x264_mc_copy_w16_altivec( uint8_t *dst, int i_dst,
 static void x264_mc_copy_w16_aligned_altivec( uint8_t *dst, int i_dst,
                                               uint8_t *src, int i_src, int i_height )
 {
-    int y;
-
-    for( y = 0; y < i_height; ++y)
+    for( int y = 0; y < i_height; ++y)
     {
         vec_u8_t cpyV = vec_ld( 0, src);
         vec_st(cpyV, 0, dst);
@@ -190,16 +182,17 @@ static void mc_luma_altivec( uint8_t *dst,    int i_dst_stride,
     {
         uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
 
-        switch(i_width) {
-        case 4:
-            x264_pixel_avg2_w4_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
-            break;
-        case 8:
-            x264_pixel_avg2_w8_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
-            break;
-        case 16:
-        default:
-            x264_pixel_avg2_w16_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
+        switch( i_width )
+        {
+            case 4:
+                x264_pixel_avg2_w4_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
+                break;
+            case 8:
+                x264_pixel_avg2_w8_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
+                break;
+            case 16:
+            default:
+                x264_pixel_avg2_w16_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
         }
         if( weight->weightfn )
             weight->weightfn[i_width>>2]( dst, i_dst_stride, dst, i_dst_stride, weight, i_height );
@@ -208,16 +201,17 @@ static void mc_luma_altivec( uint8_t *dst,    int i_dst_stride,
         weight->weightfn[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, weight, i_height );
     else
     {
-        switch(i_width) {
-        case 4:
-            x264_mc_copy_w4_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
-            break;
-        case 8:
-            x264_mc_copy_w8_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
-            break;
-        case 16:
-            x264_mc_copy_w16_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
-            break;
+        switch( i_width )
+        {
+            case 4:
+                x264_mc_copy_w4_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
+                break;
+            case 8:
+                x264_mc_copy_w8_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
+                break;
+            case 16:
+                x264_mc_copy_w16_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
+                break;
         }
     }
 }
@@ -235,21 +229,22 @@ static uint8_t *get_ref_altivec( uint8_t *dst,   int *i_dst_stride,
     if( qpel_idx & 5 ) /* qpel interpolation needed */
     {
         uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
-        switch(i_width) {
-        case 4:
-            x264_pixel_avg2_w4_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
-            break;
-        case 8:
-            x264_pixel_avg2_w8_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
-            break;
-        case 12:
-        case 16:
-        default:
-            x264_pixel_avg2_w16_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
-            break;
-        case 20:
-            x264_pixel_avg2_w20_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
-            break;
+        switch( i_width )
+        {
+            case 4:
+                x264_pixel_avg2_w4_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
+                break;
+            case 8:
+                x264_pixel_avg2_w8_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
+                break;
+            case 12:
+            case 16:
+            default:
+                x264_pixel_avg2_w16_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
+                break;
+            case 20:
+                x264_pixel_avg2_w20_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
+                break;
         }
         if( weight->weightfn )
             weight->weightfn[i_width>>2]( dst, *i_dst_stride, dst, *i_dst_stride, weight, i_height );
@@ -273,24 +268,21 @@ static void mc_chroma_2xh( uint8_t *dst, int i_dst_stride,
                            int i_height )
 {
     uint8_t *srcp;
-    int y;
     int d8x = mvx&0x07;
     int d8y = mvy&0x07;
 
-    const int cA = (8-d8x)*(8-d8y);
-    const int cB = d8x    *(8-d8y);
-    const int cC = (8-d8x)*d8y;
-    const int cD = d8x    *d8y;
+    int cA = (8-d8x)*(8-d8y);
+    int cB = d8x    *(8-d8y);
+    int cC = (8-d8x)*d8y;
+    int cD = d8x    *d8y;
 
-    src  += (mvy >> 3) * i_src_stride + (mvx >> 3);
-    srcp  = &src[i_src_stride];
+    src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+    srcp = &src[i_src_stride];
 
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
-        dst[0] = ( cA*src[0] +  cB*src[0+1] +
-                  cC*srcp[0] + cD*srcp[0+1] + 32 ) >> 6;
-        dst[1] = ( cA*src[1] +  cB*src[1+1] +
-                  cC*srcp[1] + cD*srcp[1+1] + 32 ) >> 6;
+        dst[0] = ( cA*src[0] +  cB*src[0+1] + cC*srcp[0] + cD*srcp[0+1] + 32 ) >> 6;
+        dst[1] = ( cA*src[1] +  cB*src[1+1] + cC*srcp[1] + cD*srcp[1+1] + 32 ) >> 6;
 
         src  += i_src_stride;
         srcp += i_src_stride;
@@ -309,7 +301,6 @@ static void mc_chroma_altivec_4xh( uint8_t *dst, int i_dst_stride,
                                    int i_height )
 {
     uint8_t *srcp;
-    int y;
     int d8x = mvx & 0x07;
     int d8y = mvy & 0x07;
 
@@ -319,8 +310,8 @@ static void mc_chroma_altivec_4xh( uint8_t *dst, int i_dst_stride,
     coeff[2] = (8-d8x)*d8y;
     coeff[3] = d8x    *d8y;
 
-    src  += (mvy >> 3) * i_src_stride + (mvx >> 3);
-    srcp  = &src[i_src_stride];
+    src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+    srcp = &src[i_src_stride];
 
     LOAD_ZERO;
     PREP_LOAD;
@@ -344,7 +335,7 @@ static void mc_chroma_altivec_4xh( uint8_t *dst, int i_dst_stride,
     src2v_16B = vec_u8_to_u16( src2v_8B );
     src3v_16B = vec_sld( src2v_16B, src2v_16B, 2 );
 
-    for( y = 0; y < i_height; y+=2 )
+    for( int y = 0; y < i_height; y += 2 )
     {
         src0v_16A = src2v_16B;
         src1v_16A = src3v_16B;
@@ -390,7 +381,6 @@ static void mc_chroma_altivec_8xh( uint8_t *dst, int i_dst_stride,
                                    int i_height )
 {
     uint8_t *srcp;
-    int y;
     int d8x = mvx & 0x07;
     int d8y = mvy & 0x07;
 
@@ -400,8 +390,8 @@ static void mc_chroma_altivec_8xh( uint8_t *dst, int i_dst_stride,
     coeff[2] = (8-d8x)*d8y;
     coeff[3] = d8x    *d8y;
 
-    src  += (mvy >> 3) * i_src_stride + (mvx >> 3);
-    srcp  = &src[i_src_stride];
+    src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+    srcp = &src[i_src_stride];
 
     LOAD_ZERO;
     PREP_LOAD;
@@ -425,7 +415,7 @@ static void mc_chroma_altivec_8xh( uint8_t *dst, int i_dst_stride,
     VEC_LOAD( src, src2v_8B, 9, vec_u8_t, src );
     src3v_8B = vec_sld( src2v_8B, src2v_8B, 1 );
 
-    for( y = 0; y < i_height; y+=2 )
+    for( int y = 0; y < i_height; y+=2 )
     {
         src0v_8A = src2v_8B;
         src1v_8A = src3v_8B;
@@ -462,20 +452,14 @@ static void mc_chroma_altivec( uint8_t *dst, int i_dst_stride,
                                int i_width, int i_height )
 {
     if( i_width == 8 )
-    {
         mc_chroma_altivec_8xh( dst, i_dst_stride, src, i_src_stride,
                                mvx, mvy, i_height );
-    }
     else if( i_width == 4 )
-    {
         mc_chroma_altivec_4xh( dst, i_dst_stride, src, i_src_stride,
                                mvx, mvy, i_height );
-    }
     else
-    {
         mc_chroma_2xh( dst, i_dst_stride, src, i_src_stride,
                        mvx, mvy, i_height );
-    }
 }
 
 #define HPEL_FILTER_1( t1v, t2v, t3v, t4v, t5v, t6v ) \
@@ -624,8 +608,6 @@ static void mc_chroma_altivec( uint8_t *dst, int i_dst_stride,
 void x264_hpel_filter_altivec( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
                                int i_stride, int i_width, int i_height, int16_t *buf )
 {
-    int x, y;
-
     vec_u8_t destv;
     vec_u8_t src1v, src2v, src3v, src4v, src5v, src6v;
     vec_s16_t dest1v, dest2v;
@@ -655,9 +637,9 @@ void x264_hpel_filter_altivec( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint
     temp_u.s[0]=32;
     thirtytwov = (vec_s16_t)vec_splat( temp_u.v, 0 );
 
-    for( y = 0; y < i_height; y++ )
+    for( int y = 0; y < i_height; y++ )
     {
-        x = 0;
+        int x = 0;
 
         /* horizontal_filter */
         HPEL_FILTER_HORIZONTAL();
@@ -705,8 +687,7 @@ void x264_hpel_filter_altivec( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint
         temp5v = vec_u8_to_s16_h( src5v );
         temp6v = vec_u8_to_s16_h( src6v );
 
-        HPEL_FILTER_1( temp1v, temp2v, temp3v,
-                       temp4v, temp5v, temp6v );
+        HPEL_FILTER_1( temp1v, temp2v, temp3v, temp4v, temp5v, temp6v );
 
         /* central_filter */
         tempav = tempcv;
@@ -724,14 +705,14 @@ static void frame_init_lowres_core_altivec( uint8_t *src0, uint8_t *dst0, uint8_
 {
     int w = width/16;
     int end = (width & 15);
-    int x, y;
     vec_u8_t src0v, src1v, src2v;
     vec_u8_t lv, hv, src1p1v;
     vec_u8_t avg0v, avg1v, avghv, avghp1v, avgleftv, avgrightv;
     static const vec_u8_t inverse_bridge_shuffle = CV(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E );
 
-    for( y=0; y<height; y++ )
+    for( int y = 0; y < height; y++ )
     {
+        int x;
         uint8_t *src1 = src0+src_stride;
         uint8_t *src2 = src1+src_stride;
 
@@ -742,7 +723,7 @@ static void frame_init_lowres_core_altivec( uint8_t *src0, uint8_t *dst0, uint8_
         avg0v = vec_avg(src0v, src1v);
         avg1v = vec_avg(src1v, src2v);
 
-        for( x=0; x<w; x++ )
+        for( x = 0; x < w; x++ )
         {
             lv = vec_ld(16*(x*2+1), src0);
             src1v = vec_ld(16*(x*2+1), src1);
@@ -775,7 +756,7 @@ static void frame_init_lowres_core_altivec( uint8_t *src0, uint8_t *dst0, uint8_
             avg1v = avghp1v;
 
         }
-        if (end)
+        if( end )
         {
             lv = vec_ld(16*(x*2+1), src0);
             src1v = vec_ld(16*(x*2+1), src1);
index 64d4c493fd06798f5780d800471775bf548804d8..439e9d2d785021776a4af13ae384b3876e5e7cb1 100644 (file)
 static int name( uint8_t *pix1, int i_pix1,            \
                  uint8_t *pix2, int i_pix2 )           \
 {                                                      \
-    int y;                                             \
-    ALIGNED_16( int sum );                     \
+    ALIGNED_16( int sum );                             \
                                                        \
     LOAD_ZERO;                                         \
     PREP_LOAD;                                         \
     vec_u8_t  pix1v, pix2v;                            \
     vec_s32_t sumv = zero_s32v;                        \
-    for( y = 0; y < ly; y++ )                          \
+    for( int y = 0; y < ly; y++ )                      \
     {                                                  \
         VEC_LOAD_G( pix1, pix1v, lx, vec_u8_t );       \
         VEC_LOAD_G( pix2, pix2v, lx, vec_u8_t );       \
@@ -634,7 +633,6 @@ static void pixel_sad_x4_16x16_altivec( uint8_t *fenc,
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
     ALIGNED_16( int sum3 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -659,7 +657,7 @@ static void pixel_sad_x4_16x16_altivec( uint8_t *fenc,
     perm2vB = vec_lvsl(0, pix2 + i_stride);
     perm3vB = vec_lvsl(0, pix3 + i_stride);
 
-    for (y = 0; y < 8; y++)
+    for( int y = 0; y < 8; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -685,11 +683,8 @@ static void pixel_sad_x4_16x16_altivec( uint8_t *fenc,
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
 
         temp_lv = vec_ld(0, pix0);
@@ -716,14 +711,9 @@ static void pixel_sad_x4_16x16_altivec( uint8_t *fenc,
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
-
-
     }
 
     sum0v = vec_sums( sum0v, zero_s32v );
@@ -754,7 +744,6 @@ static void pixel_sad_x3_16x16_altivec( uint8_t *fenc, uint8_t *pix0,
     ALIGNED_16( int sum0 );
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv; // temporary load vectors
@@ -775,7 +764,7 @@ static void pixel_sad_x3_16x16_altivec( uint8_t *fenc, uint8_t *pix0,
     perm1vB = vec_lvsl(0, pix1 + i_stride);
     perm2vB = vec_lvsl(0, pix2 + i_stride);
 
-    for (y = 0; y < 8; y++)
+    for( int y = 0; y < 8; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -796,9 +785,7 @@ static void pixel_sad_x3_16x16_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
 
         temp_lv = vec_ld(0, pix0);
@@ -821,9 +808,7 @@ static void pixel_sad_x3_16x16_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
     }
 
@@ -850,7 +835,6 @@ static void pixel_sad_x4_16x8_altivec( uint8_t *fenc, uint8_t *pix0, uint8_t *pi
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
     ALIGNED_16( int sum3 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -874,7 +858,7 @@ static void pixel_sad_x4_16x8_altivec( uint8_t *fenc, uint8_t *pix0, uint8_t *pi
     perm2vB = vec_lvsl(0, pix2 + i_stride);
     perm3vB = vec_lvsl(0, pix3 + i_stride);
 
-    for (y = 0; y < 4; y++)
+    for( int y = 0; y < 4; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -900,11 +884,8 @@ static void pixel_sad_x4_16x8_altivec( uint8_t *fenc, uint8_t *pix0, uint8_t *pi
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
 
         temp_lv = vec_ld(0, pix0);
@@ -931,11 +912,8 @@ static void pixel_sad_x4_16x8_altivec( uint8_t *fenc, uint8_t *pix0, uint8_t *pi
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
     }
 
@@ -967,7 +945,6 @@ static void pixel_sad_x3_16x8_altivec( uint8_t *fenc, uint8_t *pix0,
     ALIGNED_16( int sum0 );
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -988,7 +965,7 @@ static void pixel_sad_x3_16x8_altivec( uint8_t *fenc, uint8_t *pix0,
     perm1vB = vec_lvsl(0, pix1 + i_stride);
     perm2vB = vec_lvsl(0, pix2 + i_stride);
 
-    for (y = 0; y < 4; y++)
+    for( int y = 0; y < 4; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -1009,9 +986,7 @@ static void pixel_sad_x3_16x8_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
 
         temp_lv = vec_ld(0, pix0);
@@ -1033,9 +1008,7 @@ static void pixel_sad_x3_16x8_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
     }
 
@@ -1066,7 +1039,6 @@ static void pixel_sad_x4_8x16_altivec( uint8_t *fenc,
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
     ALIGNED_16( int sum3 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -1091,7 +1063,7 @@ static void pixel_sad_x4_8x16_altivec( uint8_t *fenc,
     perm2vB = vec_lvsl(0, pix2 + i_stride);
     perm3vB = vec_lvsl(0, pix3 + i_stride);
 
-    for (y = 0; y < 8; y++)
+    for( int y = 0; y < 8; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -1118,11 +1090,8 @@ static void pixel_sad_x4_8x16_altivec( uint8_t *fenc,
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
 
         temp_lv = vec_ld(0, pix0);
@@ -1150,11 +1119,8 @@ static void pixel_sad_x4_8x16_altivec( uint8_t *fenc,
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
     }
 
@@ -1186,7 +1152,6 @@ static void pixel_sad_x3_8x16_altivec( uint8_t *fenc, uint8_t *pix0,
     ALIGNED_16( int sum0 );
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -1208,7 +1173,7 @@ static void pixel_sad_x3_8x16_altivec( uint8_t *fenc, uint8_t *pix0,
     perm1vB = vec_lvsl(0, pix1 + i_stride);
     perm2vB = vec_lvsl(0, pix2 + i_stride);
 
-    for (y = 0; y < 8; y++)
+    for( int y = 0; y < 8; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -1230,9 +1195,7 @@ static void pixel_sad_x3_8x16_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
 
         temp_lv = vec_ld(0, pix0);
@@ -1255,9 +1218,7 @@ static void pixel_sad_x3_8x16_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
     }
 
@@ -1287,7 +1248,6 @@ static void pixel_sad_x4_8x8_altivec( uint8_t *fenc,
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
     ALIGNED_16( int sum3 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -1312,7 +1272,7 @@ static void pixel_sad_x4_8x8_altivec( uint8_t *fenc,
     perm2vB = vec_lvsl(0, pix2 + i_stride);
     perm3vB = vec_lvsl(0, pix3 + i_stride);
 
-    for (y = 0; y < 4; y++)
+    for( int y = 0; y < 4; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -1339,11 +1299,8 @@ static void pixel_sad_x4_8x8_altivec( uint8_t *fenc,
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
 
         temp_lv = vec_ld(0, pix0);
@@ -1371,11 +1328,8 @@ static void pixel_sad_x4_8x8_altivec( uint8_t *fenc,
         pix3 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
-
         sum3v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix3v ), vec_min( fencv, pix3v ) ), (vec_u32_t) sum3v );
     }
 
@@ -1407,7 +1361,6 @@ static void pixel_sad_x3_8x8_altivec( uint8_t *fenc, uint8_t *pix0,
     ALIGNED_16( int sum0 );
     ALIGNED_16( int sum1 );
     ALIGNED_16( int sum2 );
-    int y;
 
     LOAD_ZERO;
     vec_u8_t temp_lv, temp_hv;
@@ -1429,7 +1382,7 @@ static void pixel_sad_x3_8x8_altivec( uint8_t *fenc, uint8_t *pix0,
     perm1vB = vec_lvsl(0, pix1 + i_stride);
     perm2vB = vec_lvsl(0, pix2 + i_stride);
 
-    for (y = 0; y < 4; y++)
+    for( int y = 0; y < 4; y++ )
     {
         temp_lv = vec_ld(0, pix0);
         temp_hv = vec_ld(16, pix0);
@@ -1451,9 +1404,7 @@ static void pixel_sad_x3_8x8_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
 
         temp_lv = vec_ld(0, pix0);
@@ -1476,9 +1427,7 @@ static void pixel_sad_x3_8x8_altivec( uint8_t *fenc, uint8_t *pix0,
         pix2 += i_stride;
 
         sum0v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix0v ), vec_min( fencv, pix0v ) ), (vec_u32_t) sum0v );
-
         sum1v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix1v ), vec_min( fencv, pix1v ) ), (vec_u32_t) sum1v );
-
         sum2v = (vec_s32_t) vec_sum4s( vec_sub( vec_max( fencv, pix2v ), vec_min( fencv, pix2v ) ), (vec_u32_t) sum2v );
     }
 
@@ -1508,7 +1457,6 @@ static int pixel_ssd_16x16_altivec ( uint8_t *pix1, int i_stride_pix1,
 {
     ALIGNED_16( int sum );
 
-    int y;
     LOAD_ZERO;
     vec_u8_t  pix1vA, pix2vA, pix1vB, pix2vB;
     vec_u32_t sumv;
@@ -1526,7 +1474,7 @@ static int pixel_ssd_16x16_altivec ( uint8_t *pix1, int i_stride_pix1,
     pix2vA = vec_perm(temp_lv, temp_hv, permA);
     pix1vA = vec_ld(0, pix1);
 
-    for (y=0; y < 7; y++)
+    for( int y = 0; y < 7; y++ )
     {
         pix1 += i_stride_pix1;
         pix2 += i_stride_pix2;
@@ -1588,7 +1536,6 @@ static int pixel_ssd_8x8_altivec ( uint8_t *pix1, int i_stride_pix1,
 {
     ALIGNED_16( int sum );
 
-    int y;
     LOAD_ZERO;
     vec_u8_t  pix1v, pix2v;
     vec_u32_t sumv;
@@ -1603,7 +1550,7 @@ static int pixel_ssd_8x8_altivec ( uint8_t *pix1, int i_stride_pix1,
     perm1v = vec_lvsl(0, pix1);
     perm2v = vec_lvsl(0, pix2);
 
-    for (y=0; y < 8; y++)
+    for( int y = 0; y < 8; y++ )
     {
         temp_hv = vec_ld(0, pix1);
         temp_lv = vec_ld(7, pix1);
@@ -1645,8 +1592,7 @@ static uint64_t x264_pixel_var_16x16_altivec( uint8_t *pix, int i_stride )
     vec_u32_t sqr_v = zero_u32v;
     vec_u32_t sum_v = zero_u32v;
 
-    int y;
-    for( y = 0; y < 16; ++y )
+    for( int y = 0; y < 16; y++ )
     {
         vec_u8_t pix0_v = vec_ld(0, pix);
         sum_v = vec_sum4s(pix0_v, sum_v);
@@ -1673,7 +1619,8 @@ static uint64_t x264_pixel_var_8x8_altivec( uint8_t *pix, int i_stride )
     vec_u32_t sqr_v = zero_u32v;
     vec_u32_t sum_v = zero_u32v;
 
-    static const vec_u8_t perm_tab[] = {
+    static const vec_u8_t perm_tab[] =
+    {
         CV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,  /* pix=mod16, i_stride=mod16 */
            0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17),
         CV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,  /* pix=mod8, i_stride=mod16  */
@@ -1681,8 +1628,7 @@ static uint64_t x264_pixel_var_8x8_altivec( uint8_t *pix, int i_stride )
     };
     vec_u8_t perm = perm_tab[ ((uintptr_t)pix & 8) >> 3 ];
 
-    int y;
-    for( y = 0; y < 8; y+=2 )
+    for( int y = 0; y < 4; y++ )
     {
         vec_u8_t pix0_v = vec_ld(0, pix);
         vec_u8_t pix1_v = vec_ld(i_stride, pix);
@@ -1944,7 +1890,8 @@ static uint64_t pixel_hadamard_ac_altivec( uint8_t *pix, int stride, const vec_u
 }
 
 
-static const vec_u8_t hadamard_permtab[] = {
+static const vec_u8_t hadamard_permtab[] =
+{
     CV(0x10,0x00,0x11,0x01, 0x12,0x02,0x13,0x03,     /* pix = mod16 */
        0x14,0x04,0x15,0x05, 0x16,0x06,0x17,0x07 ),
     CV(0x18,0x08,0x19,0x09, 0x1A,0x0A,0x1B,0x0B,     /* pix = mod8 */
@@ -1981,7 +1928,8 @@ static uint64_t x264_pixel_hadamard_ac_8x16_altivec( uint8_t *pix, int stride )
     return ((sum>>34)<<32) + ((uint32_t)sum>>1);
 }
 
-static uint64_t x264_pixel_hadamard_ac_8x8_altivec( uint8_t *pix, int stride ) {
+static uint64_t x264_pixel_hadamard_ac_8x8_altivec( uint8_t *pix, int stride )
+{
     vec_u8_t perm = hadamard_permtab[ (((uintptr_t)pix & 8) >> 3) ];
     uint64_t sum = pixel_hadamard_ac_altivec( pix, stride, perm );
     return ((sum>>34)<<32) + ((uint32_t)sum>>1);
@@ -1997,7 +1945,6 @@ static void ssim_4x4x2_core_altivec( const uint8_t *pix1, int stride1,
 {
     ALIGNED_16( int temp[4] );
 
-    int y;
     vec_u8_t pix1v, pix2v;
     vec_u32_t s1v, s2v, ssv, s12v;
     PREP_LOAD;
@@ -2007,7 +1954,7 @@ static void ssim_4x4x2_core_altivec( const uint8_t *pix1, int stride1,
 
     s1v = s2v = ssv = s12v = zero_u32v;
 
-    for(y=0; y<4; y++)
+    for( int y = 0; y < 4; y++ )
     {
         VEC_LOAD( &pix1[y*stride1], pix1v, 16, vec_u8_t, pix1 );
         VEC_LOAD( &pix2[y*stride2], pix2v, 16, vec_u8_t, pix2 );
index b90cc8a13c7d63f1fa5f42daf9269abf18e74f88..3fb1a2b77bab105ee3c09927d97ff061a0beebf2 100644 (file)
 
 static void predict_8x8c_p_altivec( uint8_t *src )
 {
-    int i;
-    int a, b, c;
-    int H = 0;
-    int V = 0;
-    int i00;
+    int H = 0, V = 0;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         H += ( i + 1 ) * ( src[4+i - FDEC_STRIDE] - src[2 - i -FDEC_STRIDE] );
         V += ( i + 1 ) * ( src[-1 +(i+4)*FDEC_STRIDE] - src[-1+(2-i)*FDEC_STRIDE] );
     }
 
-    a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
-    b = ( 17 * H + 16 ) >> 5;
-    c = ( 17 * V + 16 ) >> 5;
-    i00 = a -3*b -3*c + 16;
+    int a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
+    int b = ( 17 * H + 16 ) >> 5;
+    int c = ( 17 * V + 16 ) >> 5;
+    int i00 = a -3*b -3*c + 16;
 
     vec_s16_u i00_u, b_u, c_u;
     i00_u.s[0] = i00;
@@ -58,7 +54,7 @@ static void predict_8x8c_p_altivec( uint8_t *src )
 
     PREP_STORE8;
 
-    for( i = 0; i < 8; ++i )
+    for( int i = 0; i < 8; ++i )
     {
         vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
         vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_0_v);
@@ -76,21 +72,18 @@ static void predict_8x8c_p_altivec( uint8_t *src )
 
 static void predict_16x16_p_altivec( uint8_t *src )
 {
-    int16_t a, b, c, i;
-    int H = 0;
-    int V = 0;
-    int16_t i00;
+    int H = 0, V = 0;
 
-    for( i = 1; i <= 8; i++ )
+    for( int i = 1; i <= 8; i++ )
     {
         H += i * ( src[7+i - FDEC_STRIDE ]  - src[7-i - FDEC_STRIDE ] );
         V += i * ( src[(7+i)*FDEC_STRIDE -1] - src[(7-i)*FDEC_STRIDE -1] );
     }
 
-    a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );
-    b = ( 5 * H + 32 ) >> 6;
-    c = ( 5 * V + 32 ) >> 6;
-    i00 = a - b * 7 - c * 7 + 16;
+    int a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );
+    int b = ( 5 * H + 32 ) >> 6;
+    int c = ( 5 * V + 32 ) >> 6;
+    int i00 = a - b * 7 - c * 7 + 16;
 
     vec_s16_u i00_u, b_u, c_u;
     i00_u.s[0] = i00;
@@ -107,9 +100,7 @@ static void predict_16x16_p_altivec( uint8_t *src )
     vec_s16_t add_i0_b_0v = vec_mladd(induc_v, b_v, i00_v);
     vec_s16_t add_i0_b_8v = vec_adds(b8_v, add_i0_b_0v);
 
-    int y;
-
-    for( y = 0; y < 16; y++ )
+    for( int y = 0; y < 16; y++ )
     {
         vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
         vec_s16_t shift_8_v = vec_sra(add_i0_b_8v, val5_v);
@@ -122,7 +113,7 @@ static void predict_16x16_p_altivec( uint8_t *src )
 }
 
 #define PREDICT_16x16_DC_ALTIVEC(v) \
-for (i=0; i<16; i+=2)               \
+for( int i = 0; i < 16; i += 2)     \
 {                                   \
     vec_st(v, 0, src);              \
     vec_st(v, FDEC_STRIDE, src);    \
@@ -132,9 +123,8 @@ for (i=0; i<16; i+=2)               \
 static void predict_16x16_dc_altivec( uint8_t *src )
 {
     uint32_t dc = 0;
-    int i;
 
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         dc += src[-1 + i * FDEC_STRIDE];
         dc += src[i - FDEC_STRIDE];
@@ -148,12 +138,9 @@ static void predict_16x16_dc_altivec( uint8_t *src )
 static void predict_16x16_dc_left_altivec( uint8_t *src )
 {
     uint32_t dc = 0;
-    int i;
 
-    for( i = 0; i < 16; i++ )
-    {
+    for( int i = 0; i < 16; i++ )
         dc += src[-1 + i * FDEC_STRIDE];
-    }
     vec_u8_u v ; v.s[0] = (( dc + 8 ) >> 4);
     vec_u8_t bc_v = vec_splat(v.v, 0);
 
@@ -163,12 +150,9 @@ static void predict_16x16_dc_left_altivec( uint8_t *src )
 static void predict_16x16_dc_top_altivec( uint8_t *src )
 {
     uint32_t dc = 0;
-    int i;
 
-    for( i = 0; i < 16; i++ )
-    {
+    for( int i = 0; i < 16; i++ )
         dc += src[i - FDEC_STRIDE];
-    }
     vec_u8_u v ; v.s[0] = (( dc + 8 ) >> 4);
     vec_u8_t bc_v = vec_splat(v.v, 0);
 
@@ -177,7 +161,6 @@ static void predict_16x16_dc_top_altivec( uint8_t *src )
 
 static void predict_16x16_dc_128_altivec( uint8_t *src )
 {
-    int i;
     /* test if generating the constant is faster than loading it.
     vector unsigned int bc_v = (vector unsigned int)CV(0x80808080, 0x80808080, 0x80808080, 0x80808080);
     */
@@ -187,9 +170,7 @@ static void predict_16x16_dc_128_altivec( uint8_t *src )
 
 static void predict_16x16_h_altivec( uint8_t *src )
 {
-    int i;
-
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         vec_u8_t v = vec_ld(-1, src);
         vec_u8_t v_v = vec_splat(v, 15);
@@ -207,9 +188,7 @@ static void predict_16x16_v_altivec( uint8_t *src )
     v.s[2] = *(uint32_t*)&src[ 8-FDEC_STRIDE];
     v.s[3] = *(uint32_t*)&src[12-FDEC_STRIDE];
 
-    int i;
-
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         vec_st(v.v, 0, (uint32_t*)src);
         src += FDEC_STRIDE;
index d1d9d72ab68a4670f69dad86ca7237f2caf51e33..4b2825cfa32c90422ea58072e6236f06d83a1ab6 100644 (file)
 #include "quant.h"            
 
 // quant of a whole 4x4 block, unrolled 2x and "pre-scheduled"
-#define QUANT_16_U( idx0, idx1 )                                             \
-temp1v = vec_ld((idx0), *dct);                                               \
-temp2v = vec_ld((idx1), *dct);                                               \
-mfvA = vec_ld((idx0), mf);                                                   \
-mfvB = vec_ld((idx1), mf);                                                   \
-biasvA = vec_ld((idx0), bias);                                               \
-biasvB = vec_ld((idx1), bias);                                               \
-mskA = vec_cmplt(temp1v, zero_s16v);                                         \
-mskB = vec_cmplt(temp2v, zero_s16v);                                         \
-coefvA = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp1v), temp1v);             \
-coefvB = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp2v), temp2v);             \
-coefvA = vec_adds(coefvA, biasvA);                                           \
-coefvB = vec_adds(coefvB, biasvB);                                           \
-multEvenvA = vec_mule(coefvA, mfvA);                                         \
-multOddvA = vec_mulo(coefvA, mfvA);                                          \
-multEvenvB = vec_mule(coefvB, mfvB);                                         \
-multOddvB = vec_mulo(coefvB, mfvB);                                          \
-multEvenvA = vec_sr(multEvenvA, i_qbitsv);                                   \
-multOddvA = vec_sr(multOddvA, i_qbitsv);                                     \
-multEvenvB = vec_sr(multEvenvB, i_qbitsv);                                   \
-multOddvB = vec_sr(multOddvB, i_qbitsv);                                     \
-temp1v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvA, multOddvA), vec_mergel(multEvenvA, multOddvA)); \
-temp2v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvB, multOddvB), vec_mergel(multEvenvB, multOddvB)); \
-temp1v = vec_xor(temp1v, mskA);                                              \
-temp2v = vec_xor(temp2v, mskB);                                              \
-temp1v = vec_adds(temp1v, vec_and(mskA, one));                               \
-vec_st(temp1v, (idx0), (int16_t*)dct);                                       \
-temp2v = vec_adds(temp2v, vec_and(mskB, one));                               \
-nz = vec_or(nz, vec_or(temp1v, temp2v));                                     \
-vec_st(temp2v, (idx1), (int16_t*)dct);
+#define QUANT_16_U( idx0, idx1 )                                    \
+{                                                                   \
+    temp1v = vec_ld((idx0), *dct);                                  \
+    temp2v = vec_ld((idx1), *dct);                                  \
+    mfvA = vec_ld((idx0), mf);                                      \
+    mfvB = vec_ld((idx1), mf);                                      \
+    biasvA = vec_ld((idx0), bias);                                  \
+    biasvB = vec_ld((idx1), bias);                                  \
+    mskA = vec_cmplt(temp1v, zero_s16v);                            \
+    mskB = vec_cmplt(temp2v, zero_s16v);                            \
+    coefvA = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp1v), temp1v);\
+    coefvB = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp2v), temp2v);\
+    coefvA = vec_adds(coefvA, biasvA);                              \
+    coefvB = vec_adds(coefvB, biasvB);                              \
+    multEvenvA = vec_mule(coefvA, mfvA);                            \
+    multOddvA = vec_mulo(coefvA, mfvA);                             \
+    multEvenvB = vec_mule(coefvB, mfvB);                            \
+    multOddvB = vec_mulo(coefvB, mfvB);                             \
+    multEvenvA = vec_sr(multEvenvA, i_qbitsv);                      \
+    multOddvA = vec_sr(multOddvA, i_qbitsv);                        \
+    multEvenvB = vec_sr(multEvenvB, i_qbitsv);                      \
+    multOddvB = vec_sr(multOddvB, i_qbitsv);                        \
+    temp1v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvA, multOddvA), vec_mergel(multEvenvA, multOddvA)); \
+    temp2v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvB, multOddvB), vec_mergel(multEvenvB, multOddvB)); \
+    temp1v = vec_xor(temp1v, mskA);                                 \
+    temp2v = vec_xor(temp2v, mskB);                                 \
+    temp1v = vec_adds(temp1v, vec_and(mskA, one));                  \
+    vec_st(temp1v, (idx0), (int16_t*)dct);                          \
+    temp2v = vec_adds(temp2v, vec_and(mskB, one));                  \
+    nz = vec_or(nz, vec_or(temp1v, temp2v));                        \
+    vec_st(temp2v, (idx1), (int16_t*)dct);                          \
+}
                 
 int x264_quant_4x4_altivec( int16_t dct[4][4], uint16_t mf[16], uint16_t bias[16] )
 {
@@ -83,32 +85,34 @@ int x264_quant_4x4_altivec( int16_t dct[4][4], uint16_t mf[16], uint16_t bias[16
 }
 
 // DC quant of a whole 4x4 block, unrolled 2x and "pre-scheduled"
-#define QUANT_16_U_DC( idx0, idx1 )                             \
-temp1v = vec_ld((idx0), *dct);                                  \
-temp2v = vec_ld((idx1), *dct);                                  \
-mskA = vec_cmplt(temp1v, zero_s16v);                            \
-mskB = vec_cmplt(temp2v, zero_s16v);                            \
-coefvA = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp1v), temp1v);\
-coefvB = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp2v), temp2v);\
-coefvA = vec_add(coefvA, biasv);                                \
-coefvB = vec_add(coefvB, biasv);                                \
-multEvenvA = vec_mule(coefvA, mfv);                             \
-multOddvA = vec_mulo(coefvA, mfv);                              \
-multEvenvB = vec_mule(coefvB, mfv);                             \
-multOddvB = vec_mulo(coefvB, mfv);                              \
-multEvenvA = vec_sr(multEvenvA, i_qbitsv);                      \
-multOddvA = vec_sr(multOddvA, i_qbitsv);                        \
-multEvenvB = vec_sr(multEvenvB, i_qbitsv);                      \
-multOddvB = vec_sr(multOddvB, i_qbitsv);                        \
-temp1v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvA, multOddvA), vec_mergel(multEvenvA, multOddvA)); \
-temp2v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvB, multOddvB), vec_mergel(multEvenvB, multOddvB)); \
-temp1v = vec_xor(temp1v, mskA);                                 \
-temp2v = vec_xor(temp2v, mskB);                                 \
-temp1v = vec_add(temp1v, vec_and(mskA, one));                   \
-vec_st(temp1v, (idx0), (int16_t*)dct);                          \
-temp2v = vec_add(temp2v, vec_and(mskB, one));                   \
-nz = vec_or(nz, vec_or(temp1v, temp2v));                        \
-vec_st(temp2v, (idx1), (int16_t*)dct);
+#define QUANT_16_U_DC( idx0, idx1 )                                 \
+{                                                                   \
+    temp1v = vec_ld((idx0), *dct);                                  \
+    temp2v = vec_ld((idx1), *dct);                                  \
+    mskA = vec_cmplt(temp1v, zero_s16v);                            \
+    mskB = vec_cmplt(temp2v, zero_s16v);                            \
+    coefvA = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp1v), temp1v);\
+    coefvB = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp2v), temp2v);\
+    coefvA = vec_add(coefvA, biasv);                                \
+    coefvB = vec_add(coefvB, biasv);                                \
+    multEvenvA = vec_mule(coefvA, mfv);                             \
+    multOddvA = vec_mulo(coefvA, mfv);                              \
+    multEvenvB = vec_mule(coefvB, mfv);                             \
+    multOddvB = vec_mulo(coefvB, mfv);                              \
+    multEvenvA = vec_sr(multEvenvA, i_qbitsv);                      \
+    multOddvA = vec_sr(multOddvA, i_qbitsv);                        \
+    multEvenvB = vec_sr(multEvenvB, i_qbitsv);                      \
+    multOddvB = vec_sr(multOddvB, i_qbitsv);                        \
+    temp1v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvA, multOddvA), vec_mergel(multEvenvA, multOddvA)); \
+    temp2v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvB, multOddvB), vec_mergel(multEvenvB, multOddvB)); \
+    temp1v = vec_xor(temp1v, mskA);                                 \
+    temp2v = vec_xor(temp2v, mskB);                                 \
+    temp1v = vec_add(temp1v, vec_and(mskA, one));                   \
+    vec_st(temp1v, (idx0), (int16_t*)dct);                          \
+    temp2v = vec_add(temp2v, vec_and(mskB, one));                   \
+    nz = vec_or(nz, vec_or(temp1v, temp2v));                        \
+    vec_st(temp2v, (idx1), (int16_t*)dct);                          \
+}
 
 int x264_quant_4x4_dc_altivec( int16_t dct[4][4], int mf, int bias )
 {
@@ -146,22 +150,24 @@ int x264_quant_4x4_dc_altivec( int16_t dct[4][4], int mf, int bias )
 }
 
 // DC quant of a whole 2x2 block
-#define QUANT_4_U_DC( idx0 )                                    \
-const vec_u16_t sel = (vec_u16_t) CV(-1,-1,-1,-1,0,0,0,0);      \
-temp1v = vec_ld((idx0), *dct);                                  \
-mskA = vec_cmplt(temp1v, zero_s16v);                            \
-coefvA = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp1v), temp1v);\
-coefvA = vec_add(coefvA, biasv);                                \
-multEvenvA = vec_mule(coefvA, mfv);                             \
-multOddvA = vec_mulo(coefvA, mfv);                              \
-multEvenvA = vec_sr(multEvenvA, i_qbitsv);                      \
-multOddvA = vec_sr(multOddvA, i_qbitsv);                        \
-temp2v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvA, multOddvA), vec_mergel(multEvenvA, multOddvA)); \
-temp2v = vec_xor(temp2v, mskA);                                 \
-temp2v = vec_add(temp2v, vec_and(mskA, one));                   \
-temp1v = vec_sel(temp1v, temp2v, sel);                          \
-nz = vec_or(nz, temp1v);                                        \
-vec_st(temp1v, (idx0), (int16_t*)dct);
+#define QUANT_4_U_DC( idx0 )                                        \
+{                                                                   \
+    const vec_u16_t sel = (vec_u16_t) CV(-1,-1,-1,-1,0,0,0,0);      \
+    temp1v = vec_ld((idx0), *dct);                                  \
+    mskA = vec_cmplt(temp1v, zero_s16v);                            \
+    coefvA = (vec_u16_t)vec_max(vec_sub(zero_s16v, temp1v), temp1v);\
+    coefvA = vec_add(coefvA, biasv);                                \
+    multEvenvA = vec_mule(coefvA, mfv);                             \
+    multOddvA = vec_mulo(coefvA, mfv);                              \
+    multEvenvA = vec_sr(multEvenvA, i_qbitsv);                      \
+    multOddvA = vec_sr(multOddvA, i_qbitsv);                        \
+    temp2v = (vec_s16_t) vec_packs(vec_mergeh(multEvenvA, multOddvA), vec_mergel(multEvenvA, multOddvA)); \
+    temp2v = vec_xor(temp2v, mskA);                                 \
+    temp2v = vec_add(temp2v, vec_and(mskA, one));                   \
+    temp1v = vec_sel(temp1v, temp2v, sel);                          \
+    nz = vec_or(nz, temp1v);                                        \
+    vec_st(temp1v, (idx0), (int16_t*)dct);                          \
+}
 
 int x264_quant_2x2_dc_altivec( int16_t dct[2][2], int mf, int bias )
 {
@@ -218,12 +224,9 @@ int x264_quant_8x8_altivec( int16_t dct[8][8], uint16_t mf[64], uint16_t bias[64
     vec_u32_u qbits_u;
     qbits_u.s[0]=16;
     i_qbitsv = vec_splat(qbits_u.v, 0);
-    
-    int i;
 
-    for ( i=0; i<4; i++ ) {
-      QUANT_16_U( i*2*16, i*2*16+16 );
-    }
+    for( int i = 0; i < 4; i++ )
+        QUANT_16_U( i*2*16, i*2*16+16 );
     return vec_any_ne(nz, zero_s16v);
 }
 
@@ -268,9 +271,8 @@ int x264_quant_8x8_altivec( int16_t dct[8][8], uint16_t mf[64], uint16_t bias[64
 
 void x264_dequant_4x4_altivec( int16_t dct[4][4], int dequant_mf[6][4][4], int i_qp )
 {
-    const int i_mf = i_qp%6;
-    const int i_qbits = i_qp/6 - 4;
-    int y;
+    int i_mf = i_qp%6;
+    int i_qbits = i_qp/6 - 4;
 
     vec_s16_t dctv;
     vec_s16_t dct1v, dct2v;
@@ -286,7 +288,7 @@ void x264_dequant_4x4_altivec( int16_t dct[4][4], int dequant_mf[6][4][4], int i
         qbits_u.s[0]=i_qbits;
         i_qbitsv = vec_splat(qbits_u.v, 0);
 
-        for( y = 0; y < 4; y+=2 )
+        for( int y = 0; y < 4; y+=2 )
             DEQUANT_SHL();
     }
     else
@@ -308,16 +310,15 @@ void x264_dequant_4x4_altivec( int16_t dct[4][4], int dequant_mf[6][4][4], int i
         sixteen_u.s[0]=16;
         sixteenv = vec_splat(sixteen_u.v, 0);
 
-        for( y = 0; y < 4; y+=2 )
+        for( int y = 0; y < 4; y+=2 )
             DEQUANT_SHR();
     }
 }
 
 void x264_dequant_8x8_altivec( int16_t dct[8][8], int dequant_mf[6][8][8], int i_qp )
 {
-    const int i_mf = i_qp%6;
-    const int i_qbits = i_qp/6 - 6;
-    int y;
+    int i_mf = i_qp%6;
+    int i_qbits = i_qp/6 - 6;
 
     vec_s16_t dctv;
     vec_s16_t dct1v, dct2v;
@@ -333,7 +334,7 @@ void x264_dequant_8x8_altivec( int16_t dct[8][8], int dequant_mf[6][8][8], int i
         qbits_u.s[0]=i_qbits;
         i_qbitsv = vec_splat(qbits_u.v, 0);
 
-        for( y = 0; y < 8; y++ )
+        for( int y = 0; y < 8; y++ )
             DEQUANT_SHL();
     }
     else
@@ -355,7 +356,7 @@ void x264_dequant_8x8_altivec( int16_t dct[8][8], int dequant_mf[6][8][8], int i
         sixteen_u.s[0]=16;
         sixteenv = vec_splat(sixteen_u.v, 0);
 
-        for( y = 0; y < 8; y++ )
+        for( int y = 0; y < 8; y++ )
             DEQUANT_SHR();
     }
 }
index 6c3047426d0a6aa8dc8eb80f2a18a68811a054a1..ce6d8fe0c8e1473873ee6e084fdb2c447990c693 100644 (file)
@@ -42,7 +42,7 @@
  ****************************************************************************/
 
 #define PREDICT_16x16_DC(v) \
-    for( i = 0; i < 16; i++ )\
+    for( int i = 0; i < 16; i++ )\
     {\
         M32( src+ 0 ) = v;\
         M32( src+ 4 ) = v;\
@@ -54,9 +54,8 @@
 static void predict_16x16_dc( uint8_t *src )
 {
     uint32_t dc = 0;
-    int i;
 
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         dc += src[-1 + i * FDEC_STRIDE];
         dc += src[i - FDEC_STRIDE];
@@ -68,12 +67,9 @@ static void predict_16x16_dc( uint8_t *src )
 static void predict_16x16_dc_left( uint8_t *src )
 {
     uint32_t dc = 0;
-    int i;
 
-    for( i = 0; i < 16; i++ )
-    {
+    for( int i = 0; i < 16; i++ )
         dc += src[-1 + i * FDEC_STRIDE];
-    }
     dc = (( dc + 8 ) >> 4) * 0x01010101;
 
     PREDICT_16x16_DC(dc);
@@ -81,26 +77,20 @@ static void predict_16x16_dc_left( uint8_t *src )
 static void predict_16x16_dc_top( uint8_t *src )
 {
     uint32_t dc = 0;
-    int i;
 
-    for( i = 0; i < 16; i++ )
-    {
+    for( int i = 0; i < 16; i++ )
         dc += src[i - FDEC_STRIDE];
-    }
     dc = (( dc + 8 ) >> 4) * 0x01010101;
 
     PREDICT_16x16_DC(dc);
 }
 static void predict_16x16_dc_128( uint8_t *src )
 {
-    int i;
     PREDICT_16x16_DC(0x80808080);
 }
 static void predict_16x16_h( uint8_t *src )
 {
-    int i;
-
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         const uint32_t v = 0x01010101 * src[-1];
         M32( src+ 0 ) = v;
@@ -108,7 +98,6 @@ static void predict_16x16_h( uint8_t *src )
         M32( src+ 8 ) = v;
         M32( src+12 ) = v;
         src += FDEC_STRIDE;
-
     }
 }
 static void predict_16x16_v( uint8_t *src )
@@ -117,9 +106,8 @@ static void predict_16x16_v( uint8_t *src )
     uint32_t v1 = M32( &src[ 4-FDEC_STRIDE] );
     uint32_t v2 = M32( &src[ 8-FDEC_STRIDE] );
     uint32_t v3 = M32( &src[12-FDEC_STRIDE] );
-    int i;
 
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         M32( src+ 0 ) = v0;
         M32( src+ 4 ) = v1;
@@ -130,29 +118,25 @@ static void predict_16x16_v( uint8_t *src )
 }
 static void predict_16x16_p( uint8_t *src )
 {
-    int x, y, i;
-    int a, b, c;
-    int H = 0;
-    int V = 0;
-    int i00;
+    int H = 0, V = 0;
 
     /* calculate H and V */
-    for( i = 0; i <= 7; i++ )
+    for( int i = 0; i <= 7; i++ )
     {
         H += ( i + 1 ) * ( src[ 8 + i - FDEC_STRIDE ] - src[6 -i -FDEC_STRIDE] );
         V += ( i + 1 ) * ( src[-1 + (8+i)*FDEC_STRIDE] - src[-1 + (6-i)*FDEC_STRIDE] );
     }
 
-    a = 16 * ( src[-1 + 15*FDEC_STRIDE] + src[15 - FDEC_STRIDE] );
-    b = ( 5 * H + 32 ) >> 6;
-    c = ( 5 * V + 32 ) >> 6;
+    int a = 16 * ( src[-1 + 15*FDEC_STRIDE] + src[15 - FDEC_STRIDE] );
+    int b = ( 5 * H + 32 ) >> 6;
+    int c = ( 5 * V + 32 ) >> 6;
 
-    i00 = a - b * 7 - c * 7 + 16;
+    int i00 = a - b * 7 - c * 7 + 16;
 
-    for( y = 0; y < 16; y++ )
+    for( int y = 0; y < 16; y++ )
     {
         int pix = i00;
-        for( x = 0; x < 16; x++ )
+        for( int x = 0; x < 16; x++ )
         {
             src[x] = x264_clip_uint8( pix>>5 );
             pix += b;
@@ -169,9 +153,7 @@ static void predict_16x16_p( uint8_t *src )
 
 static void predict_8x8c_dc_128( uint8_t *src )
 {
-    int y;
-
-    for( y = 0; y < 8; y++ )
+    for( int y = 0; y < 8; y++ )
     {
         M32( src+0 ) = 0x80808080;
         M32( src+4 ) = 0x80808080;
@@ -180,10 +162,9 @@ static void predict_8x8c_dc_128( uint8_t *src )
 }
 static void predict_8x8c_dc_left( uint8_t *src )
 {
-    int y;
     uint32_t dc0 = 0, dc1 = 0;
 
-    for( y = 0; y < 4; y++ )
+    for( int y = 0; y < 4; y++ )
     {
         dc0 += src[y * FDEC_STRIDE     - 1];
         dc1 += src[(y+4) * FDEC_STRIDE - 1];
@@ -191,13 +172,13 @@ static void predict_8x8c_dc_left( uint8_t *src )
     dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
     dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
 
-    for( y = 0; y < 4; y++ )
+    for( int y = 0; y < 4; y++ )
     {
         M32( src+0 ) = dc0;
         M32( src+4 ) = dc0;
         src += FDEC_STRIDE;
     }
-    for( y = 0; y < 4; y++ )
+    for( int y = 0; y < 4; y++ )
     {
         M32( src+0 ) = dc1;
         M32( src+4 ) = dc1;
@@ -207,10 +188,9 @@ static void predict_8x8c_dc_left( uint8_t *src )
 }
 static void predict_8x8c_dc_top( uint8_t *src )
 {
-    int y, x;
     uint32_t dc0 = 0, dc1 = 0;
 
-    for( x = 0; x < 4; x++ )
+    for( int x = 0; x < 4; x++ )
     {
         dc0 += src[x     - FDEC_STRIDE];
         dc1 += src[x + 4 - FDEC_STRIDE];
@@ -218,7 +198,7 @@ static void predict_8x8c_dc_top( uint8_t *src )
     dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
     dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
 
-    for( y = 0; y < 8; y++ )
+    for( int y = 0; y < 8; y++ )
     {
         M32( src+0 ) = dc0;
         M32( src+4 ) = dc1;
@@ -227,17 +207,14 @@ static void predict_8x8c_dc_top( uint8_t *src )
 }
 static void predict_8x8c_dc( uint8_t *src )
 {
-    int y;
     int s0 = 0, s1 = 0, s2 = 0, s3 = 0;
-    uint32_t dc0, dc1, dc2, dc3;
-    int i;
 
     /*
           s0 s1
        s2
        s3
     */
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         s0 += src[i - FDEC_STRIDE];
         s1 += src[i + 4 - FDEC_STRIDE];
@@ -248,19 +225,19 @@ static void predict_8x8c_dc( uint8_t *src )
        dc0 dc1
        dc2 dc3
      */
-    dc0 = (( s0 + s2 + 4 ) >> 3)*0x01010101;
-    dc1 = (( s1 + 2 ) >> 2)*0x01010101;
-    dc2 = (( s3 + 2 ) >> 2)*0x01010101;
-    dc3 = (( s1 + s3 + 4 ) >> 3)*0x01010101;
+    uint32_t dc0 = (( s0 + s2 + 4 ) >> 3)*0x01010101;
+    uint32_t dc1 = (( s1 + 2 ) >> 2)*0x01010101;
+    uint32_t dc2 = (( s3 + 2 ) >> 2)*0x01010101;
+    uint32_t dc3 = (( s1 + s3 + 4 ) >> 3)*0x01010101;
 
-    for( y = 0; y < 4; y++ )
+    for( int y = 0; y < 4; y++ )
     {
         M32( src+0 ) = dc0;
         M32( src+4 ) = dc1;
         src += FDEC_STRIDE;
     }
 
-    for( y = 0; y < 4; y++ )
+    for( int y = 0; y < 4; y++ )
     {
         M32( src+0 ) = dc2;
         M32( src+4 ) = dc3;
@@ -269,9 +246,7 @@ static void predict_8x8c_dc( uint8_t *src )
 }
 static void predict_8x8c_h( uint8_t *src )
 {
-    int i;
-
-    for( i = 0; i < 8; i++ )
+    for( int i = 0; i < 8; i++ )
     {
         uint32_t v = 0x01010101 * src[-1];
         M32( src+0 ) = v;
@@ -283,9 +258,8 @@ static void predict_8x8c_v( uint8_t *src )
 {
     uint32_t v0 = M32( src+0-FDEC_STRIDE );
     uint32_t v1 = M32( src+4-FDEC_STRIDE );
-    int i;
 
-    for( i = 0; i < 8; i++ )
+    for( int i = 0; i < 8; i++ )
     {
         M32( src+0 ) = v0;
         M32( src+4 ) = v1;
@@ -294,28 +268,23 @@ static void predict_8x8c_v( uint8_t *src )
 }
 static void predict_8x8c_p( uint8_t *src )
 {
-    int i;
-    int x,y;
-    int a, b, c;
-    int H = 0;
-    int V = 0;
-    int i00;
+    int H = 0, V = 0;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         H += ( i + 1 ) * ( src[4+i - FDEC_STRIDE] - src[2 - i -FDEC_STRIDE] );
         V += ( i + 1 ) * ( src[-1 +(i+4)*FDEC_STRIDE] - src[-1+(2-i)*FDEC_STRIDE] );
     }
 
-    a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
-    b = ( 17 * H + 16 ) >> 5;
-    c = ( 17 * V + 16 ) >> 5;
-    i00 = a -3*b -3*c + 16;
+    int a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
+    int b = ( 17 * H + 16 ) >> 5;
+    int c = ( 17 * V + 16 ) >> 5;
+    int i00 = a -3*b -3*c + 16;
 
-    for( y = 0; y < 8; y++ )
+    for( int y = 0; y < 8; y++ )
     {
         int pix = i00;
-        for( x = 0; x < 8; x++ )
+        for( int x = 0; x < 8; x++ )
         {
             src[x] = x264_clip_uint8( pix>>5 );
             pix += b;
@@ -368,22 +337,22 @@ static void predict_4x4_v( uint8_t *src )
 }
 
 #define PREDICT_4x4_LOAD_LEFT\
-    const int l0 = SRC(-1,0);\
-    const int l1 = SRC(-1,1);\
-    const int l2 = SRC(-1,2);\
-    UNUSED const int l3 = SRC(-1,3);
+    int l0 = SRC(-1,0);\
+    int l1 = SRC(-1,1);\
+    int l2 = SRC(-1,2);\
+    UNUSED int l3 = SRC(-1,3);
 
 #define PREDICT_4x4_LOAD_TOP\
-    const int t0 = SRC(0,-1);\
-    const int t1 = SRC(1,-1);\
-    const int t2 = SRC(2,-1);\
-    UNUSED const int t3 = SRC(3,-1);
+    int t0 = SRC(0,-1);\
+    int t1 = SRC(1,-1);\
+    int t2 = SRC(2,-1);\
+    UNUSED int t3 = SRC(3,-1);
 
 #define PREDICT_4x4_LOAD_TOP_RIGHT\
-    const int t4 = SRC(4,-1);\
-    const int t5 = SRC(5,-1);\
-    const int t6 = SRC(6,-1);\
-    UNUSED const int t7 = SRC(7,-1);
+    int t4 = SRC(4,-1);\
+    int t5 = SRC(5,-1);\
+    int t6 = SRC(6,-1);\
+    UNUSED int t7 = SRC(7,-1);
 
 #define F1(a,b)   (((a)+(b)+1)>>1)
 #define F2(a,b,c) (((a)+2*(b)+(c)+2)>>2)
@@ -402,7 +371,7 @@ static void predict_4x4_ddl( uint8_t *src )
 }
 static void predict_4x4_ddr( uint8_t *src )
 {
-    const int lt = SRC(-1,-1);
+    int lt = SRC(-1,-1);
     PREDICT_4x4_LOAD_LEFT
     PREDICT_4x4_LOAD_TOP
     SRC(3,0)= F2(t3,t2,t1);
@@ -416,7 +385,7 @@ static void predict_4x4_ddr( uint8_t *src )
 
 static void predict_4x4_vr( uint8_t *src )
 {
-    const int lt = SRC(-1,-1);
+    int lt = SRC(-1,-1);
     PREDICT_4x4_LOAD_LEFT
     PREDICT_4x4_LOAD_TOP
     SRC(0,3)= F2(l2,l1,l0);
@@ -433,7 +402,7 @@ static void predict_4x4_vr( uint8_t *src )
 
 static void predict_4x4_hd( uint8_t *src )
 {
-    const int lt= SRC(-1,-1);
+    int lt= SRC(-1,-1);
     PREDICT_4x4_LOAD_LEFT
     PREDICT_4x4_LOAD_TOP
     SRC(0,3)= F1(l2,l3);
@@ -498,7 +467,7 @@ static void predict_8x8_filter( uint8_t *src, uint8_t edge[33], int i_neighbor,
     {
         edge[15] = (SRC(0,-1) + 2*SRC(-1,-1) + SRC(-1,0) + 2) >> 2;
         edge[14] = ((have_lt ? SRC(-1,-1) : SRC(-1,0))
-                    + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2;
+                 + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2;
         PL(1) PL(2) PL(3) PL(4) PL(5) PL(6)
         edge[7] = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2;
     }
@@ -507,10 +476,10 @@ static void predict_8x8_filter( uint8_t *src, uint8_t edge[33], int i_neighbor,
     {
         int have_tr = i_neighbor & MB_TOPRIGHT;
         edge[16] = ((have_lt ? SRC(-1,-1) : SRC(0,-1))
-                    + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2;
+                 + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2;
         PT(1) PT(2) PT(3) PT(4) PT(5) PT(6)
         edge[23] = (SRC(6,-1) + 2*SRC(7,-1)
-                    + (have_tr ? SRC(8,-1) : SRC(7,-1)) + 2) >> 2;
+                 + (have_tr ? SRC(8,-1) : SRC(7,-1)) + 2) >> 2;
 
         if( i_filters & MB_TOPRIGHT )
         {
@@ -533,11 +502,11 @@ static void predict_8x8_filter( uint8_t *src, uint8_t edge[33], int i_neighbor,
 #undef PT
 
 #define PL(y) \
-    UNUSED const int l##y = edge[14-y];
+    UNUSED int l##y = edge[14-y];
 #define PT(x) \
-    UNUSED const int t##x = edge[16+x];
+    UNUSED int t##x = edge[16+x];
 #define PREDICT_8x8_LOAD_TOPLEFT \
-    const int lt = edge[15];
+    int lt = edge[15];
 #define PREDICT_8x8_LOAD_LEFT \
     PL(0) PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) PL(7)
 #define PREDICT_8x8_LOAD_TOP \
@@ -546,8 +515,7 @@ static void predict_8x8_filter( uint8_t *src, uint8_t edge[33], int i_neighbor,
     PT(8) PT(9) PT(10) PT(11) PT(12) PT(13) PT(14) PT(15)
 
 #define PREDICT_8x8_DC(v) \
-    int y; \
-    for( y = 0; y < 8; y++ ) { \
+    for( int y = 0; y < 8; y++ ) { \
         M32( src+0 ) = v; \
         M32( src+4 ) = v; \
         src += FDEC_STRIDE; \
@@ -560,21 +528,21 @@ static void predict_8x8_dc_128( uint8_t *src, uint8_t edge[33] )
 static void predict_8x8_dc_left( uint8_t *src, uint8_t edge[33] )
 {
     PREDICT_8x8_LOAD_LEFT
-    const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101;
+    uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101;
     PREDICT_8x8_DC(dc);
 }
 static void predict_8x8_dc_top( uint8_t *src, uint8_t edge[33] )
 {
     PREDICT_8x8_LOAD_TOP
-    const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101;
+    uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101;
     PREDICT_8x8_DC(dc);
 }
 static void predict_8x8_dc( uint8_t *src, uint8_t edge[33] )
 {
     PREDICT_8x8_LOAD_LEFT
     PREDICT_8x8_LOAD_TOP
-    const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7
-                         +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101;
+    uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7
+                   +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101;
     PREDICT_8x8_DC(dc);
 }
 static void predict_8x8_h( uint8_t *src, uint8_t edge[33] )
@@ -587,9 +555,8 @@ static void predict_8x8_h( uint8_t *src, uint8_t edge[33] )
 }
 static void predict_8x8_v( uint8_t *src, uint8_t edge[33] )
 {
-    const uint64_t top = M64( edge+16 );
-    int y;
-    for( y = 0; y < 8; y++ )
+    uint64_t top = M64( edge+16 );
+    for( int y = 0; y < 8; y++ )
         M64( src+y*FDEC_STRIDE ) = top;
 }
 static void predict_8x8_ddl( uint8_t *src, uint8_t edge[33] )
@@ -756,9 +723,7 @@ void x264_predict_16x16_init( int cpu, x264_predict_t pf[7] )
 
 #ifdef HAVE_ALTIVEC
     if( cpu&X264_CPU_ALTIVEC )
-    {
         x264_predict_16x16_init_altivec( pf );
-    }
 #endif
 
 #ifdef HAVE_ARMV6
@@ -782,9 +747,7 @@ void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] )
 
 #ifdef HAVE_ALTIVEC
     if( cpu&X264_CPU_ALTIVEC )
-    {
         x264_predict_8x8c_init_altivec( pf );
-    }
 #endif
 
 #ifdef HAVE_ARMV6
index b0d1afb5d64f11ffa6e21b43d9d17150db1006e6..ce074e267798c434b5d46de90e2753face6aa9fe 100644 (file)
 
 static int quant_8x8( int16_t dct[64], uint16_t mf[64], uint16_t bias[64] )
 {
-    int i, nz = 0;
-    for( i = 0; i < 64; i++ )
+    int nz = 0;
+    for( int i = 0; i < 64; i++ )
         QUANT_ONE( dct[i], mf[i], bias[i] );
     return !!nz;
 }
 
 static int quant_4x4( int16_t dct[16], uint16_t mf[16], uint16_t bias[16] )
 {
-    int i, nz = 0;
-    for( i = 0; i < 16; i++ )
+    int nz = 0;
+    for( int i = 0; i < 16; i++ )
         QUANT_ONE( dct[i], mf[i], bias[i] );
     return !!nz;
 }
 
 static int quant_4x4_dc( int16_t dct[16], int mf, int bias )
 {
-    int i, nz = 0;
-    for( i = 0; i < 16; i++ )
+    int nz = 0;
+    for( int i = 0; i < 16; i++ )
         QUANT_ONE( dct[i], mf, bias );
     return !!nz;
 }
@@ -86,17 +86,16 @@ static void dequant_4x4( int16_t dct[16], int dequant_mf[6][16], int i_qp )
 {
     const int i_mf = i_qp%6;
     const int i_qbits = i_qp/6 - 4;
-    int i;
 
     if( i_qbits >= 0 )
     {
-        for( i = 0; i < 16; i++ )
+        for( int i = 0; i < 16; i++ )
             DEQUANT_SHL( i );
     }
     else
     {
         const int f = 1 << (-i_qbits-1);
-        for( i = 0; i < 16; i++ )
+        for( int i = 0; i < 16; i++ )
             DEQUANT_SHR( i );
     }
 }
@@ -105,17 +104,16 @@ static void dequant_8x8( int16_t dct[64], int dequant_mf[6][64], int i_qp )
 {
     const int i_mf = i_qp%6;
     const int i_qbits = i_qp/6 - 6;
-    int i;
 
     if( i_qbits >= 0 )
     {
-        for( i = 0; i < 64; i++ )
+        for( int i = 0; i < 64; i++ )
             DEQUANT_SHL( i );
     }
     else
     {
         const int f = 1 << (-i_qbits-1);
-        for( i = 0; i < 64; i++ )
+        for( int i = 0; i < 64; i++ )
             DEQUANT_SHR( i );
     }
 }
@@ -123,27 +121,25 @@ static void dequant_8x8( int16_t dct[64], int dequant_mf[6][64], int i_qp )
 static void dequant_4x4_dc( int16_t dct[16], int dequant_mf[6][16], int i_qp )
 {
     const int i_qbits = i_qp/6 - 6;
-    int i;
 
     if( i_qbits >= 0 )
     {
         const int i_dmf = dequant_mf[i_qp%6][0] << i_qbits;
-        for( i = 0; i < 16; i++ )
+        for( int i = 0; i < 16; i++ )
             dct[i] *= i_dmf;
     }
     else
     {
         const int i_dmf = dequant_mf[i_qp%6][0];
         const int f = 1 << (-i_qbits-1);
-        for( i = 0; i < 16; i++ )
+        for( int i = 0; i < 16; i++ )
             dct[i] = ( dct[i] * i_dmf + f ) >> (-i_qbits);
     }
 }
 
 static void x264_denoise_dct( int16_t *dct, uint32_t *sum, uint16_t *offset, int size )
 {
-    int i;
-    for( i=1; i<size; i++ )
+    for( int i = 1; i < size; i++ )
     {
         int level = dct[i];
         int sign = level>>15;
@@ -163,13 +159,17 @@ static void x264_denoise_dct( int16_t *dct, uint32_t *sum, uint16_t *offset, int
  *  chroma: for the complete mb: if score < 7 -> null
  */
 
-const uint8_t x264_decimate_table4[16] = {
-    3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0 };
-const uint8_t x264_decimate_table8[64] = {
+const uint8_t x264_decimate_table4[16] =
+{
+    3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0
+};
+const uint8_t x264_decimate_table8[64] =
+{
     3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
     1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+};
 
 static int ALWAYS_INLINE x264_decimate_score_internal( int16_t *dct, int i_max )
 {
index f9379f08b31f0c25cd80c1407de3943d2138f927..50d42137fa12c46177274a96ae65d9ce0b9f1fdb 100644 (file)
@@ -73,16 +73,16 @@ int x264_cqm_init( x264_t *h )
     int def_dequant8[6][64];
     int quant4_mf[4][6][16];
     int quant8_mf[2][6][64];
-    int q, i, j, i_list;
     int deadzone[4] = { 32 - h->param.analyse.i_luma_deadzone[1],
                         32 - h->param.analyse.i_luma_deadzone[0],
                         32 - 11, 32 - 21 };
     int max_qp_err = -1;
     int max_chroma_qp_err = -1;
 
-    for( i = 0; i < 6; i++ )
+    for( int i = 0; i < 6; i++ )
     {
         int size = i<4 ? 16 : 64;
+        int j;
         for( j = (i<4 ? 0 : 4); j < i; j++ )
             if( !memcmp( h->pps->scaling_list[i], h->pps->scaling_list[j], size*sizeof(uint8_t) ) )
                 break;
@@ -109,15 +109,15 @@ int x264_cqm_init( x264_t *h )
             CHECKED_MALLOC( h->quant4_bias[i], 52*size*sizeof(uint16_t) );
     }
 
-    for( q = 0; q < 6; q++ )
+    for( int q = 0; q < 6; q++ )
     {
-        for( i = 0; i < 16; i++ )
+        for( int i = 0; i < 16; i++ )
         {
             int j = (i&1) + ((i>>2)&1);
             def_dequant4[q][i] = dequant4_scale[q][j];
             def_quant4[q][i]   =   quant4_scale[q][j];
         }
-        for( i = 0; i < 64; i++ )
+        for( int i = 0; i < 64; i++ )
         {
             int j = quant8_scan[((i>>1)&12) | (i&3)];
             def_dequant8[q][i] = dequant8_scale[q][j];
@@ -125,28 +125,29 @@ int x264_cqm_init( x264_t *h )
         }
     }
 
-    for( q = 0; q < 6; q++ )
+    for( int q = 0; q < 6; q++ )
     {
-        for( i_list = 0; i_list < 4; i_list++ )
-            for( i = 0; i < 16; i++ )
+        for( int i_list = 0; i_list < 4; i_list++ )
+            for( int i = 0; i < 16; i++ )
             {
                 h->dequant4_mf[i_list][q][i] = def_dequant4[q][i] * h->pps->scaling_list[i_list][i];
                      quant4_mf[i_list][q][i] = DIV(def_quant4[q][i] * 16, h->pps->scaling_list[i_list][i]);
             }
-        for( i_list = 0; i_list < 2; i_list++ )
-            for( i = 0; i < 64; i++ )
+        for( int i_list = 0; i_list < 2; i_list++ )
+            for( int i = 0; i < 64; i++ )
             {
                 h->dequant8_mf[i_list][q][i] = def_dequant8[q][i] * h->pps->scaling_list[4+i_list][i];
                      quant8_mf[i_list][q][i] = DIV(def_quant8[q][i] * 16, h->pps->scaling_list[4+i_list][i]);
             }
     }
-    for( q = 0; q < 52; q++ )
+    for( int q = 0; q < 52; q++ )
     {
-        for( i_list = 0; i_list < 4; i_list++ )
-            for( i = 0; i < 16; i++ )
+        int j;
+        for( int i_list = 0; i_list < 4; i_list++ )
+            for( int i = 0; i < 16; i++ )
             {
                 h->unquant4_mf[i_list][q][i] = (1ULL << (q/6 + 15 + 8)) / quant4_mf[i_list][q%6][i];
-                h->  quant4_mf[i_list][q][i] = j = SHIFT(quant4_mf[i_list][q%6][i], q/6 - 1);
+                h->quant4_mf[i_list][q][i] = j = SHIFT(quant4_mf[i_list][q%6][i], q/6 - 1);
                 // round to nearest, unless that would cause the deadzone to be negative
                 h->quant4_bias[i_list][q][i] = X264_MIN( DIV(deadzone[i_list]<<10, j), (1<<15)/j );
                 if( j > 0xffff && q > max_qp_err && (i_list == CQM_4IY || i_list == CQM_4PY) )
@@ -155,15 +156,15 @@ int x264_cqm_init( x264_t *h )
                     max_chroma_qp_err = q;
             }
         if( h->param.analyse.b_transform_8x8 )
-        for( i_list = 0; i_list < 2; i_list++ )
-            for( i = 0; i < 64; i++ )
-            {
-                h->unquant8_mf[i_list][q][i] = (1ULL << (q/6 + 16 + 8)) / quant8_mf[i_list][q%6][i];
-                h->  quant8_mf[i_list][q][i] = j = SHIFT(quant8_mf[i_list][q%6][i], q/6);
-                h->quant8_bias[i_list][q][i] = X264_MIN( DIV(deadzone[i_list]<<10, j), (1<<15)/j );
-                if( j > 0xffff && q > max_qp_err )
-                    max_qp_err = q;
-            }
+            for( int i_list = 0; i_list < 2; i_list++ )
+                for( int i = 0; i < 64; i++ )
+                {
+                    h->unquant8_mf[i_list][q][i] = (1ULL << (q/6 + 16 + 8)) / quant8_mf[i_list][q%6][i];
+                    h->quant8_mf[i_list][q][i] = j = SHIFT(quant8_mf[i_list][q%6][i], q/6);
+                    h->quant8_bias[i_list][q][i] = X264_MIN( DIV(deadzone[i_list]<<10, j), (1<<15)/j );
+                    if( j > 0xffff && q > max_qp_err )
+                        max_qp_err = q;
+                }
     }
 
     if( !h->mb.b_lossless && max_qp_err >= h->param.rc.i_qp_min )
@@ -185,8 +186,9 @@ fail:
 }
 
 #define CQM_DELETE( n, max )\
-    for( i = 0; i < max; i++ )\
+    for( int i = 0; i < max; i++ )\
     {\
+        int j;\
         for( j = 0; j < i; j++ )\
             if( h->quant##n##_mf[i] == h->quant##n##_mf[j] )\
                 break;\
@@ -205,7 +207,6 @@ fail:
 
 void x264_cqm_delete( x264_t *h )
 {
-    int i, j;
     CQM_DELETE( 4, 4 );
     CQM_DELETE( 8, 2 );
 }
@@ -213,11 +214,9 @@ void x264_cqm_delete( x264_t *h )
 static int x264_cqm_parse_jmlist( x264_t *h, const char *buf, const char *name,
                            uint8_t *cqm, const uint8_t *jvt, int length )
 {
-    char *p;
-    char *nextvar;
     int i;
 
-    p = strstr( buf, name );
+    char *p = strstr( buf, name );
     if( !p )
     {
         memset( cqm, 16, length );
@@ -228,7 +227,7 @@ static int x264_cqm_parse_jmlist( x264_t *h, const char *buf, const char *name,
     if( *p == 'U' || *p == 'V' )
         p++;
 
-    nextvar = strstr( p, "INT" );
+    char *nextvar = strstr( p, "INT" );
 
     for( i = 0; i < length && (p = strpbrk( p, " \t\n," )) && (p = strpbrk( p, "0123456789" )); i++ )
     {
@@ -258,12 +257,12 @@ static int x264_cqm_parse_jmlist( x264_t *h, const char *buf, const char *name,
 
 int x264_cqm_parse_file( x264_t *h, const char *filename )
 {
-    char *buf, *p;
+    char *p;
     int b_error = 0;
 
     h->param.i_cqm_preset = X264_CQM_CUSTOM;
 
-    buf = x264_slurp_file( filename );
+    char *buf = x264_slurp_file( filename );
     if( !buf )
     {
         x264_log( h, X264_LOG_ERROR, "can't open file '%s'\n", filename );
index 1d3dd84565c6b52e3b59641641721eda68e96cc5..1b598d34485bd14f32b91dc8f36a1c477c5ba51f 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * x264: h264 encoder
+ * x264: visualization module
  *****************************************************************************
  * Copyright (C) 2005 Tuukka Toivonen <tuukkat@ee.oulu.fi>
  *
@@ -41,7 +41,8 @@
 #include "visualize.h"
 #include "display.h"
 
-typedef struct {
+typedef struct
+{
     int     i_type;
     int     i_partition;
     int     i_sub_partition[4];
@@ -51,92 +52,86 @@ typedef struct {
     int16_t mv[2][4][4][2];                /* [list][y][x][mvxy] */
 } visualize_t;
 
-/* {{{ [fold] char *get_string(const stringlist_t *sl, int entries, int code) */
 /* Return string from stringlist corresponding to the given code */
 #define GET_STRING(sl, code) get_string((sl), sizeof(sl)/sizeof(*(sl)), code)
 
-typedef struct {
+typedef struct
+{
     int code;
     char *string;
 } stringlist_t;
 
-static char *get_string(const stringlist_t *sl, int entries, int code)
+static char *get_string( const stringlist_t *sl, int entries, int code )
 {
-    int i;
-
-    for (i=0; i<entries; i++) {
-        if (sl[i].code==code) break;
-    }
-    return (i>=entries) ? "?" : sl[i].string;
+    for( int i = 0; i < entries; i++ )
+        if( sl[i].code == code )
+            return sl[i].string;
+    return "?";
 }
-/* }}} */
-/* {{{ [fold] void mv(int x0, int y0, int16_t dmv[2], int ref, int zoom, char *col) */
+
 /* Plot motion vector */
-static void mv(int x0, int y0, int16_t dmv[2], int ref, int zoom, char *col)
+static void mv( int x0, int y0, int16_t dmv[2], int ref, int zoom, char *col )
 {
     int dx = dmv[0];
     int dy = dmv[1];
-    int i;
 
-    dx = (dx * zoom + 2) >> 2;                     /* Quarter pixel accurate MVs */
+    dx = (dx * zoom + 2) >> 2;
     dy = (dy * zoom + 2) >> 2;
-    disp_line(0, x0, y0, x0+dx, y0+dy);
-    for (i=1; i<ref; i++){
-        disp_line(0, x0, y0-i, x0+i, y0);
-        disp_line(0, x0+i, y0, x0, y0+i);
-        disp_line(0, x0, y0+i, x0-i, y0);
-        disp_line(0, x0-i, y0, x0, y0-i);
+    disp_line( 0, x0, y0, x0+dx, y0+dy );
+    for( int i = 1; i < ref; i++ )
+    {
+        disp_line( 0, x0  , y0-i, x0+i, y0   );
+        disp_line( 0, x0+i, y0  , x0  , y0+i );
+        disp_line( 0, x0  , y0+i, x0-i, y0   );
+        disp_line( 0, x0-i, y0  , x0  , y0-i );
     }
-    disp_setcolor("black");
-    disp_point(0, x0, y0);
-    disp_setcolor(col);
+    disp_setcolor( "black" );
+    disp_point( 0, x0, y0 );
+    disp_setcolor( col );
 }
-/* }}} */
 
-/* {{{ [fold] void x264_visualize_init( x264_t *h ) */
 int x264_visualize_init( x264_t *h )
 {
-    int mb = h->sps->i_mb_width * h->sps->i_mb_height;
-    CHECKED_MALLOC( h->visualize, mb * sizeof(visualize_t) );
+    CHECKED_MALLOC( h->visualize, h->sps->i_mb_width * h->sps->i_mb_height * sizeof(visualize_t) );
     return 0;
 fail:
     return -1;
 }
-/* }}} */
-/* {{{ [fold] void x264_visualize_mb( x264_t *h ) */
+
 void x264_visualize_mb( x264_t *h )
 {
     visualize_t *v = (visualize_t*)h->visualize + h->mb.i_mb_xy;
-    int i, l, x, y;
 
-    /* Save all data for the MB what we need for drawing the visualization */
+    /* Save all data for the MB that we need for drawing the visualization */
     v->i_type = h->mb.i_type;
     v->i_partition = h->mb.i_partition;
-    for (i=0; i<4; i++) v->i_sub_partition[i] = h->mb.i_sub_partition[i];
-    for (y=0; y<4; y++) for (x=0; x<4; x++)
-        v->intra4x4_pred_mode[y][x] = h->mb.cache.intra4x4_pred_mode[X264_SCAN8_0+y*8+x];
-    for (l=0; l<2; l++) for (y=0; y<4; y++) for (x=0; x<4; x++) {
-        for (i=0; i<2; i++) {
-            v->mv[l][y][x][i] = h->mb.cache.mv[l][X264_SCAN8_0+y*8+x][i];
-        }
-        v->ref[l][y][x] = h->mb.cache.ref[l][X264_SCAN8_0+y*8+x];
-    }
+    for( int i = 0; i < 4; i++ )
+        v->i_sub_partition[i] = h->mb.i_sub_partition[i];
+    for( int y = 0; y < 4; y++ )
+        for( int x = 0; x < 4; x++ )
+            v->intra4x4_pred_mode[y][x] = h->mb.cache.intra4x4_pred_mode[X264_SCAN8_0+y*8+x];
+    for( int l = 0; l < 2; l++ )
+        for( int y = 0; y < 4; y++ )
+            for( int x = 0; x < 4; x++ )
+            {
+                for( int i = 0; i < 2; i++ )
+                    v->mv[l][y][x][i] = h->mb.cache.mv[l][X264_SCAN8_0+y*8+x][i];
+                v->ref[l][y][x] = h->mb.cache.ref[l][X264_SCAN8_0+y*8+x];
+            }
     v->i_intra16x16_pred_mode = h->mb.i_intra16x16_pred_mode;
 }
-/* }}} */
-/* {{{ [fold] void x264_visualize_close( x264_t *h ) */
+
 void x264_visualize_close( x264_t *h )
 {
     x264_free(h->visualize);
 }
-/* }}} */
-/* {{{ [fold] void x264_visualize_show( x264_t *h ) */
+
 /* Display visualization (block types, MVs) of the encoded frame */
 /* FIXME: B-type MBs not handled yet properly */
 void x264_visualize_show( x264_t *h )
 {
-    int mb_xy;
-    static const stringlist_t mb_types[] = {
+    static const stringlist_t mb_types[] =
+    {
         /* Block types marked as NULL will not be drawn */
         { I_4x4   , "red" },
         { I_8x8   , "#ff5640" },
@@ -170,154 +165,171 @@ void x264_visualize_show( x264_t *h )
     const int height = h->param.i_height;
     const int stride = h->fdec->i_stride[0];
 
-    if (borders) {
-        disp_gray_zoom(0, frame - pad*stride - pad, width+2*pad, height+2*pad, stride, "fdec", zoom);
-    } else {
-        disp_gray_zoom(0, frame, width, height, stride, "fdec", zoom);
-    }
+    if( borders )
+        disp_gray_zoom( 0, frame - pad*stride - pad, width+2*pad, height+2*pad, stride, "fdec", zoom );
+    else
+        disp_gray_zoom( 0, frame, width, height, stride, "fdec", zoom );
 
-    for( mb_xy = 0; mb_xy < h->sps->i_mb_width * h->sps->i_mb_height; mb_xy++ )
+    for( int mb_xy = 0; mb_xy < h->sps->i_mb_width * h->sps->i_mb_height; mb_xy++ )
     {
         visualize_t *const v = (visualize_t*)h->visualize + mb_xy;
         const int mb_y = mb_xy / h->sps->i_mb_width;
         const int mb_x = mb_xy % h->sps->i_mb_width;
-        char *const col = GET_STRING(mb_types, v->i_type);
+        char *const col = GET_STRING( mb_types, v->i_type );
         int x = mb_x*16*zoom;
         int y = mb_y*16*zoom;
         int l = 0;
-        unsigned int i, j;
 
-        if (col==NULL) continue;
-        if (borders) {
+        if( !col )
+            continue;
+
+        if( borders )
+        {
             x += pad*zoom;
             y += pad*zoom;
         }
-        disp_setcolor(col);
-        if (drawbox) disp_rect(0, x, y, x+16*zoom-1, y+16*zoom-1);
 
-        if (v->i_type==P_L0 || v->i_type==P_8x8 || v->i_type==P_SKIP) {
+        disp_setcolor( col );
+        if( drawbox ) disp_rect( 0, x, y, x+16*zoom-1, y+16*zoom-1 );
 
+        if( v->i_type==P_L0 || v->i_type==P_8x8 || v->i_type==P_SKIP )
+        {
             /* Predicted (inter) mode, with motion vector */
-            if (v->i_partition==D_16x16 || v->i_type==P_SKIP) {
-                mv(x+8*zoom, y+8*zoom, v->mv[l][0][0], v->ref[l][0][0], zoom, col);
+            if( v->i_partition == D_16x16 || v->i_type == P_SKIP )
+                mv( x+8*zoom, y+8*zoom, v->mv[l][0][0], v->ref[l][0][0], zoom, col );
+            else if (v->i_partition == D_16x8)
+            {
+                if( drawbox ) disp_rect( 0, x, y, x+16*zoom, y+8*zoom );
+                mv( x+8*zoom, y+4*zoom, v->mv[l][0][0], v->ref[l][0][0], zoom, col );
+                if( drawbox ) disp_rect( 0, x, y+8*zoom, x+16*zoom, y+16*zoom );
+                mv( x+8*zoom, y+12*zoom, v->mv[l][2][0], v->ref[l][2][0], zoom, col );
             }
-            if (v->i_partition==D_16x8) {
-                if (drawbox) disp_rect(0, x, y, x+16*zoom, y+8*zoom);
-                mv(x+8*zoom, y+4*zoom, v->mv[l][0][0], v->ref[l][0][0], zoom, col);
-                if (drawbox) disp_rect(0, x, y+8*zoom, x+16*zoom, y+16*zoom);
-                mv(x+8*zoom, y+12*zoom, v->mv[l][2][0], v->ref[l][2][0], zoom, col);
+            else if( v->i_partition==D_8x16 )
+            {
+                if( drawbox ) disp_rect( 0, x,          y, x+8*zoom,  y+16*zoom );
+                mv( x+4*zoom, y+8*zoom, v->mv[l][0][0], v->ref[l][0][0], zoom, col );
+                if( drawbox ) disp_rect( 0, x+8*zoom,   y, x+16*zoom, y+16*zoom );
+                mv( x+12*zoom, y+8*zoom, v->mv[l][0][2], v->ref[l][0][2], zoom, col );
             }
-            if (v->i_partition==D_8x16) {
-                if (drawbox) disp_rect(0, x,          y, x+8*zoom,  y+16*zoom);
-                mv(x+4*zoom, y+8*zoom, v->mv[l][0][0], v->ref[l][0][0], zoom, col);
-                if (drawbox) disp_rect(0, x+8*zoom,   y, x+16*zoom, y+16*zoom);
-                mv(x+12*zoom, y+8*zoom, v->mv[l][0][2], v->ref[l][0][2], zoom, col);
-            }
-            if (v->i_partition==D_8x8) {
-                for (i=0; i<2; i++) for (j=0; j<2; j++) {
-                    int sp = v->i_sub_partition[i*2+j];
-                    const int x0 = x + j*8*zoom;
-                    const int y0 = y + i*8*zoom;
-                    l = x264_mb_partition_listX_table[0][sp] ? 0 : 1; /* FIXME: not tested if this works */
-                    if (IS_SUB8x8(sp)) {
-                        if (drawbox) disp_rect(0, x0, y0, x0+8*zoom, y0+8*zoom);
-                        mv(x0+4*zoom, y0+4*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col);
-                    }
-                    if (IS_SUB8x4(sp)) {
-                        if (drawbox) disp_rect(0, x0, y0, x0+8*zoom, y0+4*zoom);
-                        if (drawbox) disp_rect(0, x0, y0+4*zoom, x0+8*zoom, y0+8*zoom);
-                        mv(x0+4*zoom, y0+2*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col);
-                        mv(x0+4*zoom, y0+6*zoom, v->mv[l][2*i+1][2*j], v->ref[l][2*i+1][2*j], zoom, col);
-                    }
-                    if (IS_SUB4x8(sp)) {
-                        if (drawbox) disp_rect(0, x0, y0, x0+4*zoom, y0+8*zoom);
-                        if (drawbox) disp_rect(0, x0+4*zoom, y0, x0+8*zoom, y0+8*zoom);
-                        mv(x0+2*zoom, y0+4*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col);
-                        mv(x0+6*zoom, y0+4*zoom, v->mv[l][2*i][2*j+1], v->ref[l][2*i][2*j+1], zoom, col);
+            else if( v->i_partition==D_8x8 )
+            {
+                for( int i = 0; i < 2; i++ )
+                    for( int j = 0; j < 2; j++ )
+                    {
+                        int sp = v->i_sub_partition[i*2+j];
+                        const int x0 = x + j*8*zoom;
+                        const int y0 = y + i*8*zoom;
+                        l = x264_mb_partition_listX_table[0][sp] ? 0 : 1; /* FIXME: not tested if this works */
+                        if( IS_SUB8x8(sp) )
+                        {
+                            if( drawbox ) disp_rect( 0, x0, y0, x0+8*zoom, y0+8*zoom );
+                            mv( x0+4*zoom, y0+4*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col );
+                        }
+                        else if( IS_SUB8x4(sp) )
+                        {
+                            if( drawbox ) disp_rect( 0, x0, y0, x0+8*zoom, y0+4*zoom );
+                            if( drawbox ) disp_rect( 0, x0, y0+4*zoom, x0+8*zoom, y0+8*zoom );
+                            mv( x0+4*zoom, y0+2*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col );
+                            mv( x0+4*zoom, y0+6*zoom, v->mv[l][2*i+1][2*j], v->ref[l][2*i+1][2*j], zoom, col );
+                        }
+                        else if( IS_SUB4x8(sp) )
+                        {
+                            if( drawbox ) disp_rect( 0, x0, y0, x0+4*zoom, y0+8*zoom );
+                            if( drawbox ) disp_rect( 0, x0+4*zoom, y0, x0+8*zoom, y0+8*zoom );
+                            mv( x0+2*zoom, y0+4*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col );
+                            mv( x0+6*zoom, y0+4*zoom, v->mv[l][2*i][2*j+1], v->ref[l][2*i][2*j+1], zoom, col );
+                        }
+                        else if( IS_SUB4x4(sp) )
+                        {
+                            if( drawbox ) disp_rect( 0, x0, y0, x0+4*zoom, y0+4*zoom );
+                            if( drawbox ) disp_rect( 0, x0+4*zoom, y0, x0+8*zoom, y0+4*zoom );
+                            if( drawbox ) disp_rect( 0, x0, y0+4*zoom, x0+4*zoom, y0+8*zoom );
+                            if( drawbox ) disp_rect( 0, x0+4*zoom, y0+4*zoom, x0+8*zoom, y0+8*zoom );
+                            mv( x0+2*zoom, y0+2*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col );
+                            mv( x0+6*zoom, y0+2*zoom, v->mv[l][2*i][2*j+1], v->ref[l][2*i][2*j+1], zoom, col );
+                            mv( x0+2*zoom, y0+6*zoom, v->mv[l][2*i+1][2*j], v->ref[l][2*i+1][2*j], zoom, col );
+                            mv( x0+6*zoom, y0+6*zoom, v->mv[l][2*i+1][2*j+1], v->ref[l][2*i+1][2*j+1], zoom, col );
+                        }
                     }
-                    if (IS_SUB4x4(sp)) {
-                        if (drawbox) disp_rect(0, x0, y0, x0+4*zoom, y0+4*zoom);
-                        if (drawbox) disp_rect(0, x0+4*zoom, y0, x0+8*zoom, y0+4*zoom);
-                        if (drawbox) disp_rect(0, x0, y0+4*zoom, x0+4*zoom, y0+8*zoom);
-                        if (drawbox) disp_rect(0, x0+4*zoom, y0+4*zoom, x0+8*zoom, y0+8*zoom);
-                        mv(x0+2*zoom, y0+2*zoom, v->mv[l][2*i][2*j], v->ref[l][2*i][2*j], zoom, col);
-                        mv(x0+6*zoom, y0+2*zoom, v->mv[l][2*i][2*j+1], v->ref[l][2*i][2*j+1], zoom, col);
-                        mv(x0+2*zoom, y0+6*zoom, v->mv[l][2*i+1][2*j], v->ref[l][2*i+1][2*j], zoom, col);
-                        mv(x0+6*zoom, y0+6*zoom, v->mv[l][2*i+1][2*j+1], v->ref[l][2*i+1][2*j+1], zoom, col);
-                    }
-                }
             }
         }
 
-        if (IS_INTRA(v->i_type) || v->i_type==I_PCM) {
+        if( IS_INTRA(v->i_type) || v->i_type == I_PCM )
+        {
             /* Intra coded */
-            if (v->i_type==I_16x16) {
+            if( v->i_type == I_16x16 )
+            {
                 switch (v->i_intra16x16_pred_mode) {
                 case I_PRED_16x16_V:
-                    disp_line(0, x+2*zoom, y+2*zoom, x+14*zoom, y+2*zoom);
+                    disp_line( 0, x+2*zoom, y+2*zoom, x+14*zoom, y+2*zoom );
                     break;
                 case I_PRED_16x16_H:
-                    disp_line(0, x+2*zoom, y+2*zoom, x+2*zoom, y+14*zoom);
+                    disp_line( 0, x+2*zoom, y+2*zoom, x+2*zoom, y+14*zoom );
                     break;
                 case I_PRED_16x16_DC:
                 case I_PRED_16x16_DC_LEFT:
                 case I_PRED_16x16_DC_TOP:
                 case I_PRED_16x16_DC_128:
-                    disp_line(0, x+2*zoom, y+2*zoom, x+14*zoom, y+2*zoom);
-                    disp_line(0, x+2*zoom, y+2*zoom, x+2*zoom, y+14*zoom);
+                    disp_line( 0, x+2*zoom, y+2*zoom, x+14*zoom, y+2*zoom );
+                    disp_line( 0, x+2*zoom, y+2*zoom, x+2*zoom, y+14*zoom );
                     break;
                 case I_PRED_16x16_P:
-                    disp_line(0, x+2*zoom, y+2*zoom, x+8*zoom, y+8*zoom);
+                    disp_line( 0, x+2*zoom, y+2*zoom, x+8*zoom, y+8*zoom );
                     break;
                 }
             }
-            if (v->i_type==I_4x4 || v->i_type==I_8x8) {
-                const int di = v->i_type==I_8x8 ? 2 : 1;
+            if( v->i_type==I_4x4 || v->i_type==I_8x8 )
+            {
+                const int di = v->i_type == I_8x8 ? 2 : 1;
                 const int zoom2 = zoom * di;
-                for (i=0; i<4; i+=di) for (j=0; j<4; j+=di) {
-                    const int x0 = x + j*4*zoom;
-                    const int y0 = y + i*4*zoom;
-                    if (drawbox) disp_rect(0, x0, y0, x0+4*zoom2, y0+4*zoom2);
-                    switch (v->intra4x4_pred_mode[i][j]) {
-                    case I_PRED_4x4_V:         /* Vertical */
-                        disp_line(0, x0+0*zoom2, y0+1*zoom2, x0+4*zoom2, y0+1*zoom2);
-                        break;
-                    case I_PRED_4x4_H:         /* Horizontal */
-                        disp_line(0, x0+1*zoom2, y0+0*zoom2, x0+1*zoom2, y0+4*zoom2);
-                        break;
-                    case I_PRED_4x4_DC:                /* DC, average from top and left sides */
-                    case I_PRED_4x4_DC_LEFT:
-                    case I_PRED_4x4_DC_TOP:
-                    case I_PRED_4x4_DC_128:
-                        disp_line(0, x0+1*zoom2, y0+1*zoom2, x0+4*zoom2, y0+1*zoom2);
-                        disp_line(0, x0+1*zoom2, y0+1*zoom2, x0+1*zoom2, y0+4*zoom2);
-                        break;
-                    case I_PRED_4x4_DDL:       /* Topright-bottomleft */
-                        disp_line(0, x0+0*zoom2, y0+0*zoom2, x0+4*zoom2, y0+4*zoom2);
-                        break;
-                    case I_PRED_4x4_DDR:       /* Topleft-bottomright */
-                        disp_line(0, x0+0*zoom2, y0+4*zoom2, x0+4*zoom2, y0+0*zoom2);
-                        break;
-                    case I_PRED_4x4_VR:                /* Mix of topleft-bottomright and vertical */
-                        disp_line(0, x0+0*zoom2, y0+2*zoom2, x0+4*zoom2, y0+1*zoom2);
-                        break;
-                    case I_PRED_4x4_HD:                /* Mix of topleft-bottomright and horizontal */
-                        disp_line(0, x0+2*zoom2, y0+0*zoom2, x0+1*zoom2, y0+4*zoom2);
-                        break;
-                    case I_PRED_4x4_VL:                /* Mix of topright-bottomleft and vertical */
-                        disp_line(0, x0+0*zoom2, y0+1*zoom2, x0+4*zoom2, y0+2*zoom2);
-                        break;
-                    case I_PRED_4x4_HU:                /* Mix of topright-bottomleft and horizontal */
-                        disp_line(0, x0+1*zoom2, y0+0*zoom2, x0+2*zoom2, y0+4*zoom2);
-                        break;
+                for( int i = 0; i < 4; i += di )
+                    for( int j = 0; j < 4; j += di )
+                    {
+                        const int x0 = x + j*4*zoom;
+                        const int y0 = y + i*4*zoom;
+                        if( drawbox ) disp_rect( 0, x0, y0, x0+4*zoom2, y0+4*zoom2 );
+                        switch( v->intra4x4_pred_mode[i][j] )
+                        {
+                            case I_PRED_4x4_V:        /* Vertical */
+                                disp_line( 0, x0+0*zoom2, y0+1*zoom2, x0+4*zoom2, y0+1*zoom2 );
+                                break;
+                            case I_PRED_4x4_H:        /* Horizontal */
+                                disp_line( 0, x0+1*zoom2, y0+0*zoom2, x0+1*zoom2, y0+4*zoom2 );
+                                break;
+                            case I_PRED_4x4_DC:        /* DC, average from top and left sides */
+                            case I_PRED_4x4_DC_LEFT:
+                            case I_PRED_4x4_DC_TOP:
+                            case I_PRED_4x4_DC_128:
+                                disp_line( 0, x0+1*zoom2, y0+1*zoom2, x0+4*zoom2, y0+1*zoom2 );
+                                disp_line( 0, x0+1*zoom2, y0+1*zoom2, x0+1*zoom2, y0+4*zoom2 );
+                                break;
+                            case I_PRED_4x4_DDL:    /* Topright-bottomleft */
+                                disp_line( 0, x0+0*zoom2, y0+0*zoom2, x0+4*zoom2, y0+4*zoom2 );
+                                break;
+                            case I_PRED_4x4_DDR:    /* Topleft-bottomright */
+                                disp_line( 0, x0+0*zoom2, y0+4*zoom2, x0+4*zoom2, y0+0*zoom2 );
+                                break;
+                            case I_PRED_4x4_VR:        /* Mix of topleft-bottomright and vertical */
+                                disp_line( 0, x0+0*zoom2, y0+2*zoom2, x0+4*zoom2, y0+1*zoom2 );
+                                break;
+                            case I_PRED_4x4_HD:        /* Mix of topleft-bottomright and horizontal */
+                                disp_line( 0, x0+2*zoom2, y0+0*zoom2, x0+1*zoom2, y0+4*zoom2 );
+                                break;
+                            case I_PRED_4x4_VL:        /* Mix of topright-bottomleft and vertical */
+                                disp_line( 0, x0+0*zoom2, y0+1*zoom2, x0+4*zoom2, y0+2*zoom2 );
+                                break;
+                            case I_PRED_4x4_HU:        /* Mix of topright-bottomleft and horizontal */
+                                disp_line( 0, x0+1*zoom2, y0+0*zoom2, x0+2*zoom2, y0+4*zoom2 );
+                                break;
+                        }
                     }
-                }
             }
         }
     }
 
     disp_sync();
-    if (waitkey) getchar();
+    if( waitkey )
+        getchar();
 }
 /* }}} */
 
index e575dfb14877333e0568079afd57def299b03422..158b3e2a2aecfbaaea906788ee19d365ab7e6959 100644 (file)
@@ -873,10 +873,8 @@ vlc_large_t x264_level_token[7][LEVEL_TABLE_SIZE];
 
 void x264_init_vlc_tables()
 {
-    int16_t level;
-    int i_suffix;
-    for( i_suffix = 0; i_suffix < 7; i_suffix++ )
-        for( level = -LEVEL_TABLE_SIZE/2; level < LEVEL_TABLE_SIZE/2; level++ )
+    for( int i_suffix = 0; i_suffix < 7; i_suffix++ )
+        for( int16_t level = -LEVEL_TABLE_SIZE/2; level < LEVEL_TABLE_SIZE/2; level++ )
         {
             int mask = level >> 15;
             int abs_level = (level^mask)-mask;
index ce7520af60f233033f523036c81557ba4f0116f4..fecdd3bd0e9ae43e53622c248b25e3330ab39cc7 100644 (file)
@@ -240,30 +240,29 @@ static UNUSED x264_pthread_mutex_t cost_ref_mutex = X264_PTHREAD_MUTEX_INITIALIZ
 
 int x264_analyse_init_costs( x264_t *h, int qp )
 {
-    int i, j;
     int lambda = x264_lambda_tab[qp];
     if( h->cost_mv[lambda] )
         return 0;
     /* factor of 4 from qpel, 2 from sign, and 2 because mv can be opposite from mvp */
     CHECKED_MALLOC( h->cost_mv[lambda], (4*4*2048 + 1) * sizeof(uint16_t) );
     h->cost_mv[lambda] += 2*4*2048;
-    for( i = 0; i <= 2*4*2048; i++ )
+    for( int i = 0; i <= 2*4*2048; i++ )
     {
         h->cost_mv[lambda][-i] =
         h->cost_mv[lambda][i]  = lambda * (log2f(i+1)*2 + 0.718f + !!i) + .5f;
     }
     x264_pthread_mutex_lock( &cost_ref_mutex );
-    for( i = 0; i < 3; i++ )
-        for( j = 0; j < 33; j++ )
+    for( int i = 0; i < 3; i++ )
+        for( int j = 0; j < 33; j++ )
             x264_cost_ref[lambda][i][j] = i ? lambda * bs_size_te( i, j ) : 0;
     x264_pthread_mutex_unlock( &cost_ref_mutex );
     if( h->param.analyse.i_me_method >= X264_ME_ESA && !h->cost_mv_fpel[lambda][0] )
     {
-        for( j=0; j<4; j++ )
+        for( int j = 0; j < 4; j++ )
         {
             CHECKED_MALLOC( h->cost_mv_fpel[lambda][j], (4*2048 + 1) * sizeof(uint16_t) );
             h->cost_mv_fpel[lambda][j] += 2*2048;
-            for( i = -2*2048; i < 2*2048; i++ )
+            for( int i = -2*2048; i < 2*2048; i++ )
                 h->cost_mv_fpel[lambda][j][i] = h->cost_mv[lambda][i*4+j];
         }
     }
@@ -274,21 +273,19 @@ fail:
 
 void x264_analyse_free_costs( x264_t *h )
 {
-    int i, j;
-    for( i = 0; i < 92; i++ )
+    for( int i = 0; i < 92; i++ )
     {
         if( h->cost_mv[i] )
             x264_free( h->cost_mv[i] - 2*4*2048 );
         if( h->cost_mv_fpel[i][0] )
-            for( j = 0; j < 4; j++ )
+            for( int j = 0; j < 4; j++ )
                 x264_free( h->cost_mv_fpel[i][j] - 2*2048 );
     }
 }
 
 void x264_analyse_weight_frame( x264_t *h, int end )
 {
-    int j;
-    for( j=0; j<h->i_ref0; j++ )
+    for( int j = 0; j < h->i_ref0; j++ )
     {
         if( h->sh.weight[j][0].weightfn )
         {
@@ -297,13 +294,11 @@ void x264_analyse_weight_frame( x264_t *h, int end )
             int i_padv = PADV << h->param.b_interlaced;
             int offset, height;
             uint8_t *src = frame->filtered[0] - frame->i_stride[0]*i_padv - PADH;
-            int k;
             height = X264_MIN( 16 + end + i_padv, h->fref0[j]->i_lines[0] + i_padv*2 ) - h->fenc->i_lines_weighted;
             offset = h->fenc->i_lines_weighted*frame->i_stride[0];
             h->fenc->i_lines_weighted += height;
             if( height )
-            {
-                for( k = j; k < h->i_ref0; k++ )
+                for( int k = j; k < h->i_ref0; k++ )
                     if( h->sh.weight[k][0].weightfn )
                     {
                         uint8_t *dst = h->fenc->weighted[k] - h->fenc->i_stride[0]*i_padv - PADH;
@@ -311,7 +306,6 @@ void x264_analyse_weight_frame( x264_t *h, int end )
                                                  src + offset, frame->i_stride[0],
                                                  width, height, &h->sh.weight[k][0] );
                     }
-            }
             break;
         }
     }
@@ -349,12 +343,12 @@ static void x264_mb_analyse_init_qp( x264_t *h, x264_mb_analysis_t *a, int i_qp
 
 static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
 {
-    int i = h->param.analyse.i_subpel_refine - (h->sh.i_type == SLICE_TYPE_B);
+    int subme = h->param.analyse.i_subpel_refine - (h->sh.i_type == SLICE_TYPE_B);
 
     /* mbrd == 1 -> RD mode decision */
     /* mbrd == 2 -> RD refinement */
     /* mbrd == 3 -> QPRD */
-    a->i_mbrd = (i>=6) + (i>=8) + (h->param.analyse.i_subpel_refine>=10);
+    a->i_mbrd = (subme>=6) + (subme>=8) + (h->param.analyse.i_subpel_refine>=10);
 
     x264_mb_analyse_init_qp( h, a, i_qp );
 
@@ -379,7 +373,6 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
     /* II: Inter part P/B frame */
     if( h->sh.i_type != SLICE_TYPE_I )
     {
-        int i, j;
         int i_fmv_range = 4 * h->param.analyse.i_mv_range;
         // limit motion search to a slightly smaller range than the theoretical limit,
         // since the search may go a few iterations past its given range
@@ -411,11 +404,11 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
             {
                 int pix_y = (h->mb.i_mb_y | h->mb.b_interlaced) * 16;
                 int thresh = pix_y + h->param.analyse.i_mv_range_thread;
-                for( i = (h->sh.i_type == SLICE_TYPE_B); i >= 0; i-- )
+                for( int i = (h->sh.i_type == SLICE_TYPE_B); i >= 0; i-- )
                 {
                     x264_frame_t **fref = i ? h->fref1 : h->fref0;
                     int i_ref = i ? h->i_ref1 : h->i_ref0;
-                    for( j=0; j<i_ref; j++ )
+                    for( int j = 0; j < i_ref; j++ )
                     {
                         x264_frame_cond_wait( fref[j]->orig, thresh );
                         thread_mvy_range = X264_MIN( thread_mvy_range, fref[j]->orig->i_lines_completed - pix_y );
@@ -468,7 +461,7 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
             a->i_cost8x16bi    = COST_MAX;
         }
         else if( h->param.analyse.inter & X264_ANALYSE_PSUB8x8 )
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
             {
                 a->l0.i_cost4x4[i] =
                 a->l0.i_cost8x4[i] =
@@ -640,7 +633,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
     uint8_t  *p_src = h->mb.pic.p_fenc[0];
     uint8_t  *p_dst = h->mb.pic.p_fdec[0];
 
-    int i, idx;
+    int idx;
     int b_merged_satd = !!h->pixf.intra_mbcmp_x3_16x16 && !h->mb.b_lossless;
 
     /*---------------- Try all mode and calculate their score ---------------*/
@@ -654,7 +647,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
         h->predict_16x16[I_PRED_16x16_P]( p_dst );
         a->i_satd_i16x16_dir[I_PRED_16x16_P] =
             h->pixf.mbcmp[PIXEL_16x16]( p_dst, FDEC_STRIDE, p_src, FENC_STRIDE );
-        for( i=0; i<4; i++ )
+        for( int i = 0; i < 4; i++ )
         {
             int cost = a->i_satd_i16x16_dir[i] += a->i_lambda * bs_size_ue(i);
             COPY2_IF_LT( a->i_satd_i16x16, cost, a->i_predict16x16, i );
@@ -685,8 +678,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
 
     /* Not heavily tuned */
     const uint8_t i16x16_thresh[11] = { 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4 };
-    int thresh = i16x16_thresh[h->mb.i_subpel_refine];
-    if( a->b_fast_intra && a->i_satd_i16x16 > (thresh*i_satd_inter)>>1 )
+    if( a->b_fast_intra && a->i_satd_i16x16 > (i16x16_thresh[h->mb.i_subpel_refine]*i_satd_inter)>>1 )
         return;
 
     /* 8x8 prediction selection */
@@ -721,7 +713,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
                 int satd[9];
                 h->pixf.intra_mbcmp_x3_8x8( p_src_by, edge, satd );
                 satd[i_pred_mode] -= 3 * a->i_lambda;
-                for( i=2; i>=0; i-- )
+                for( int i = 2; i >= 0; i-- )
                 {
                     int cost = a->i_satd_i8x8_dir[i][idx] = satd[i];
                     COPY2_IF_LT( i_best, cost, a->i_predict8x8[idx], i );
@@ -781,8 +773,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
         }
         /* Not heavily tuned */
         const uint8_t i8x8_thresh[11] = { 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6 };
-        int thresh = i8x8_thresh[h->mb.i_subpel_refine];
-        if( X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*thresh)>>2 )
+        if( X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
             return;
     }
 
@@ -806,7 +797,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
             int i_best = COST_MAX;
             int i_pred_mode = x264_mb_predict_intra4x4_mode( h, idx );
 
-            const int8_t *predict_mode = predict_4x4_mode_available( h->mb.i_neighbour4[idx] );
+            predict_mode = predict_4x4_mode_available( h->mb.i_neighbour4[idx] );
 
             if( (h->mb.i_neighbour4[idx] & (MB_TOPRIGHT|MB_TOP)) == MB_TOP )
                 /* emulate missing topright samples */
@@ -817,7 +808,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
                 int satd[9];
                 h->pixf.intra_mbcmp_x3_4x4( p_src_by, p_dst_by, satd );
                 satd[i_pred_mode] -= 3 * a->i_lambda;
-                for( i=2; i>=0; i-- )
+                for( int i = 2; i >= 0; i-- )
                     COPY2_IF_LT( i_best, satd[i], a->i_predict4x4[idx], i );
                 predict_mode += 3;
             }
@@ -915,8 +906,7 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
 {
     uint8_t  *p_dst = h->mb.pic.p_fdec[0];
 
-    int i, idx, x, y;
-    int i_mode, i_thresh;
+    int x, y;
     uint64_t i_satd, i_best;
     h->mb.i_skip_intra = 0;
 
@@ -924,7 +914,7 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
     {
         int old_pred_mode = a->i_predict16x16;
         const int8_t *predict_mode = predict_16x16_mode_available( h->mb.i_neighbour_intra );
-        i_thresh = a->i_satd_i16x16_dir[old_pred_mode] * 9/8;
+        int i_thresh = a->i_satd_i16x16_dir[old_pred_mode] * 9/8;
         i_best = a->i_satd_i16x16;
         for( ; *predict_mode >= 0; predict_mode++ )
         {
@@ -943,11 +933,11 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
     {
         int8_t predict_mode_sorted[4];
         int i_max;
-        i_thresh = a->i_satd_i8x8chroma * 5/4;
+        int i_thresh = a->i_satd_i8x8chroma * 5/4;
 
         for( i_max = 0; *predict_mode >= 0; predict_mode++ )
         {
-            i_mode = *predict_mode;
+            int i_mode = *predict_mode;
             if( a->i_satd_i8x8chroma_dir[i_mode] < i_thresh && i_mode != a->i_predict8x8chroma )
                 predict_mode_sorted[i_max++] = i_mode;
         }
@@ -960,9 +950,9 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
              * coefs for the current chroma mode are still around, so we only
              * have to recount the bits. */
             i_best = x264_rd_cost_i8x8_chroma( h, i_chroma_lambda, a->i_predict8x8chroma, 0 );
-            for( i = 0; i < i_max; i++ )
+            for( int i = 0; i < i_max; i++ )
             {
-                i_mode = predict_mode_sorted[i];
+                int i_mode = predict_mode_sorted[i];
                 if( h->mb.b_lossless )
                     x264_predict_lossless_8x8_chroma( h, i_mode );
                 else
@@ -985,12 +975,12 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
     {
         uint32_t pels[4] = {0}; // doesn't need initting, just shuts up a gcc warning
         int i_nnz = 0;
-        for( idx = 0; idx < 16; idx++ )
+        for( int idx = 0; idx < 16; idx++ )
         {
             uint8_t *p_dst_by = p_dst + block_idx_xy_fdec[idx];
             i_best = COST_MAX64;
 
-            const int8_t *predict_mode = predict_4x4_mode_available( h->mb.i_neighbour4[idx] );
+            predict_mode = predict_4x4_mode_available( h->mb.i_neighbour4[idx] );
 
             if( (h->mb.i_neighbour4[idx] & (MB_TOPRIGHT|MB_TOP)) == MB_TOP )
                 /* emulate missing topright samples */
@@ -998,7 +988,7 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
 
             for( ; *predict_mode >= 0; predict_mode++ )
             {
-                i_mode = *predict_mode;
+                int i_mode = *predict_mode;
                 if( h->mb.b_lossless )
                     x264_predict_lossless_4x4( h, p_dst_by, idx, i_mode );
                 else
@@ -1029,27 +1019,26 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
     else if( h->mb.i_type == I_8x8 )
     {
         ALIGNED_ARRAY_16( uint8_t, edge,[33] );
-        for( idx = 0; idx < 4; idx++ )
+        for( int idx = 0; idx < 4; idx++ )
         {
             uint64_t pels_h = 0;
             uint8_t pels_v[7];
             uint16_t i_nnz[2] = {0}; //shut up gcc
             uint8_t *p_dst_by;
-            int j;
             int cbp_luma_new = 0;
-            i_thresh = a->i_satd_i8x8_dir[a->i_predict8x8[idx]][idx] * 11/8;
+            int i_thresh = a->i_satd_i8x8_dir[a->i_predict8x8[idx]][idx] * 11/8;
 
             i_best = COST_MAX64;
             x = idx&1;
             y = idx>>1;
 
             p_dst_by = p_dst + 8*x + 8*y*FDEC_STRIDE;
-            const int8_t *predict_mode = predict_4x4_mode_available( h->mb.i_neighbour8[idx] );
+            predict_mode = predict_4x4_mode_available( h->mb.i_neighbour8[idx] );
             h->predict_8x8_filter( p_dst_by, edge, h->mb.i_neighbour8[idx], ALL_NEIGHBORS );
 
             for( ; *predict_mode >= 0; predict_mode++ )
             {
-                i_mode = *predict_mode;
+                int i_mode = *predict_mode;
                 if( a->i_satd_i8x8_dir[i_mode][idx] > i_thresh )
                     continue;
 
@@ -1068,7 +1057,7 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
 
                     pels_h = M64( p_dst_by+7*FDEC_STRIDE );
                     if( !(idx&1) )
-                        for( j=0; j<7; j++ )
+                        for( int j = 0; j < 7; j++ )
                             pels_v[j] = p_dst_by[7+j*FDEC_STRIDE];
                     i_nnz[0] = M16( &h->mb.cache.non_zero_count[x264_scan8[4*idx+0]] );
                     i_nnz[1] = M16( &h->mb.cache.non_zero_count[x264_scan8[4*idx+2]] );
@@ -1077,7 +1066,7 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
             a->i_cbp_i8x8_luma = cbp_luma_new;
             M64( p_dst_by+7*FDEC_STRIDE ) = pels_h;
             if( !(idx&1) )
-                for( j=0; j<7; j++ )
+                for( int j = 0; j < 7; j++ )
                     p_dst_by[7+j*FDEC_STRIDE] = pels_v[j];
             M16( &h->mb.cache.non_zero_count[x264_scan8[4*idx+0]] ) = i_nnz[0];
             M16( &h->mb.cache.non_zero_count[x264_scan8[4*idx+2]] ) = i_nnz[1];
@@ -1116,7 +1105,7 @@ static void x264_intra_rd_refine( x264_t *h, x264_mb_analysis_t *a )
 static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
 {
     x264_me_t m;
-    int i_ref, i_mvc;
+    int i_mvc;
     ALIGNED_4( int16_t mvc[8][2] );
     int i_halfpel_thresh = INT_MAX;
     int *p_halfpel_thresh = h->mb.pic.i_fref[0]>1 ? &i_halfpel_thresh : NULL;
@@ -1126,7 +1115,7 @@ static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
     LOAD_FENC( &m, h->mb.pic.p_fenc, 0, 0 );
 
     a->l0.me16x16.cost = INT_MAX;
-    for( i_ref = 0; i_ref < h->mb.pic.i_fref[0]; i_ref++ )
+    for( int i_ref = 0; i_ref < h->mb.pic.i_fref[0]; i_ref++ )
     {
         m.i_ref_cost = REF_COST( 0, i_ref );
         i_halfpel_thresh -= m.i_ref_cost;
@@ -1195,7 +1184,6 @@ static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
 static void x264_mb_analyse_inter_p8x8_mixed_ref( x264_t *h, x264_mb_analysis_t *a )
 {
     x264_me_t m;
-    int i_ref, i;
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     int i_maxref = h->mb.pic.i_fref[0]-1;
 
@@ -1223,10 +1211,10 @@ static void x264_mb_analyse_inter_p8x8_mixed_ref( x264_t *h, x264_mb_analysis_t
     }
     #undef CHECK_NEIGHBOUR
 
-    for( i_ref = 0; i_ref <= i_maxref; i_ref++ )
+    for( int i_ref = 0; i_ref <= i_maxref; i_ref++ )
         CP32( a->l0.mvc[i_ref][0], h->mb.mvr[0][i_ref][h->mb.i_mb_xy] );
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         x264_me_t *l0m = &a->l0.me8x8[i];
         const int x8 = i%2;
@@ -1236,7 +1224,7 @@ static void x264_mb_analyse_inter_p8x8_mixed_ref( x264_t *h, x264_mb_analysis_t
 
         LOAD_FENC( &m, p_fenc, 8*x8, 8*y8 );
         l0m->cost = INT_MAX;
-        for( i_ref = 0; i_ref <= i_maxref || i_ref == h->mb.ref_blind_dupe; )
+        for( int i_ref = 0; i_ref <= i_maxref || i_ref == h->mb.ref_blind_dupe; )
         {
             m.i_ref_cost = REF_COST( 0, i_ref );
 
@@ -1293,7 +1281,6 @@ static void x264_mb_analyse_inter_p8x8( x264_t *h, x264_mb_analysis_t *a )
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     int i_mvc;
     int16_t (*mvc)[2] = a->l0.mvc[i_ref];
-    int i;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_8x8;
@@ -1301,7 +1288,7 @@ static void x264_mb_analyse_inter_p8x8( x264_t *h, x264_mb_analysis_t *a )
     i_mvc = 1;
     CP32( mvc[0], a->l0.me16x16.mv );
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         x264_me_t *m = &a->l0.me8x8[i];
         const int x8 = i%2;
@@ -1343,12 +1330,11 @@ static void x264_mb_analyse_inter_p16x8( x264_t *h, x264_mb_analysis_t *a )
     x264_me_t m;
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     ALIGNED_4( int16_t mvc[3][2] );
-    int i, j;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_16x8;
 
-    for( i = 0; i < 2; i++ )
+    for( int i = 0; i < 2; i++ )
     {
         x264_me_t *l0m = &a->l0.me16x8[i];
         const int minref = X264_MIN( a->l0.me8x8[2*i].i_ref, a->l0.me8x8[2*i+1].i_ref );
@@ -1360,7 +1346,7 @@ static void x264_mb_analyse_inter_p16x8( x264_t *h, x264_mb_analysis_t *a )
 
         LOAD_FENC( &m, p_fenc, 0, 8*i );
         l0m->cost = INT_MAX;
-        for( j = 0; j < i_ref8s; j++ )
+        for( int j = 0; j < i_ref8s; j++ )
         {
             const int i_ref = ref8[j];
             m.i_ref_cost = REF_COST( 0, i_ref );
@@ -1401,12 +1387,11 @@ static void x264_mb_analyse_inter_p8x16( x264_t *h, x264_mb_analysis_t *a )
     x264_me_t m;
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     ALIGNED_4( int16_t mvc[3][2] );
-    int i, j;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_8x16;
 
-    for( i = 0; i < 2; i++ )
+    for( int i = 0; i < 2; i++ )
     {
         x264_me_t *l0m = &a->l0.me8x16[i];
         const int minref = X264_MIN( a->l0.me8x8[i].i_ref, a->l0.me8x8[i+2].i_ref );
@@ -1418,7 +1403,7 @@ static void x264_mb_analyse_inter_p8x16( x264_t *h, x264_mb_analysis_t *a )
 
         LOAD_FENC( &m, p_fenc, 8*i, 0 );
         l0m->cost = INT_MAX;
-        for( j = 0; j < i_ref8s; j++ )
+        for( int j = 0; j < i_ref8s; j++ )
         {
             const int i_ref = ref8[j];
             m.i_ref_cost = REF_COST( 0, i_ref );
@@ -1503,12 +1488,11 @@ static void x264_mb_analyse_inter_p4x4( x264_t *h, x264_mb_analysis_t *a, int i8
     uint8_t  **p_fref = h->mb.pic.p_fref[0][a->l0.me8x8[i8x8].i_ref];
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     const int i_ref = a->l0.me8x8[i8x8].i_ref;
-    int i4x4;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_8x8;
 
-    for( i4x4 = 0; i4x4 < 4; i4x4++ )
+    for( int i4x4 = 0; i4x4 < 4; i4x4++ )
     {
         const int idx = 4*i8x8 + i4x4;
         const int x4 = block_idx_x[idx];
@@ -1543,12 +1527,11 @@ static void x264_mb_analyse_inter_p8x4( x264_t *h, x264_mb_analysis_t *a, int i8
     uint8_t  **p_fref = h->mb.pic.p_fref[0][a->l0.me8x8[i8x8].i_ref];
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     const int i_ref = a->l0.me8x8[i8x8].i_ref;
-    int i8x4;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_8x8;
 
-    for( i8x4 = 0; i8x4 < 2; i8x4++ )
+    for( int i8x4 = 0; i8x4 < 2; i8x4++ )
     {
         const int idx = 4*i8x8 + 2*i8x4;
         const int x4 = block_idx_x[idx];
@@ -1580,12 +1563,11 @@ static void x264_mb_analyse_inter_p4x8( x264_t *h, x264_mb_analysis_t *a, int i8
     uint8_t  **p_fref = h->mb.pic.p_fref[0][a->l0.me8x8[i8x8].i_ref];
     uint8_t  **p_fenc = h->mb.pic.p_fenc;
     const int i_ref = a->l0.me8x8[i8x8].i_ref;
-    int i4x8;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_8x8;
 
-    for( i4x8 = 0; i4x8 < 2; i4x8++ )
+    for( int i4x8 = 0; i4x8 < 2; i4x8++ )
     {
         const int idx = 4*i8x8 + i4x8;
         const int x4 = block_idx_x[idx];
@@ -1643,7 +1625,7 @@ static void x264_mb_analyse_inter_b16x16( x264_t *h, x264_mb_analysis_t *a )
     ALIGNED_ARRAY_16( uint8_t, pix1,[16*16] );
     uint8_t *src0, *src1;
     int stride0 = 16, stride1 = 16;
-    int i_ref, i_mvc, l;
+    int i_ref, i_mvc;
     ALIGNED_4( int16_t mvc[9][2] );
     int try_skip = a->b_try_skip;
     int list1_skipped = 0;
@@ -1659,7 +1641,7 @@ static void x264_mb_analyse_inter_b16x16( x264_t *h, x264_mb_analysis_t *a )
     /* 16x16 Search on list 0 and list 1 */
     a->l0.me16x16.cost = INT_MAX;
     a->l1.me16x16.cost = INT_MAX;
-    for( l = 1; l >= 0; )
+    for( int l = 1; l >= 0; )
     {
         x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
 
@@ -1866,7 +1848,6 @@ static inline void x264_mb_cache_mv_b8x16( x264_t *h, x264_mb_analysis_t *a, int
 static void x264_mb_analyse_inter_b8x8_mixed_ref( x264_t *h, x264_mb_analysis_t *a )
 {
     ALIGNED_ARRAY_8( uint8_t, pix,[2],[8*8] );
-    int i_ref, i, l;
     int i_maxref[2] = {h->mb.pic.i_fref[0]-1, h->mb.pic.i_fref[1]-1};
 
     /* early termination: if 16x16 chose ref 0, then evalute no refs older
@@ -1878,7 +1859,7 @@ static void x264_mb_analyse_inter_b8x8_mixed_ref( x264_t *h, x264_mb_analysis_t
             i_maxref[l] = ref;\
     }
 
-    for( l = 0; l < 2; l++ )
+    for( int l = 0; l < 2; l++ )
     {
         x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
         if( i_maxref[l] > 0 && lX->me16x16.i_ref == 0 &&
@@ -1899,7 +1880,7 @@ static void x264_mb_analyse_inter_b8x8_mixed_ref( x264_t *h, x264_mb_analysis_t
 
     a->i_cost8x8bi = 0;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         int x8 = i%2;
         int y8 = i/2;
@@ -1911,12 +1892,12 @@ static void x264_mb_analyse_inter_b8x8_mixed_ref( x264_t *h, x264_mb_analysis_t
         m.i_pixel = PIXEL_8x8;
         LOAD_FENC( &m, h->mb.pic.p_fenc, 8*x8, 8*y8 );
 
-        for( l = 0; l < 2; l++ )
+        for( int l = 0; l < 2; l++ )
         {
             x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
 
             lX->me8x8[i].cost = INT_MAX;
-            for( i_ref = 0; i_ref <= i_maxref[l]; i_ref++ )
+            for( int i_ref = 0; i_ref <= i_maxref[l]; i_ref++ )
             {
                 m.i_ref_cost = REF_COST( l, i_ref );;
 
@@ -1971,14 +1952,13 @@ static void x264_mb_analyse_inter_b8x8( x264_t *h, x264_mb_analysis_t *a )
         { h->mb.pic.p_fref[0][a->l0.me16x16.i_ref],
           h->mb.pic.p_fref[1][a->l1.me16x16.i_ref] };
     ALIGNED_ARRAY_8( uint8_t, pix,[2],[8*8] );
-    int i, l;
 
     /* XXX Needed for x264_mb_predict_mv */
     h->mb.i_partition = D_8x8;
 
     a->i_cost8x8bi = 0;
 
-    for( i = 0; i < 4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         const int x8 = i%2;
         const int y8 = i/2;
@@ -1987,7 +1967,7 @@ static void x264_mb_analyse_inter_b8x8( x264_t *h, x264_mb_analysis_t *a )
         int stride[2] = {8,8};
         uint8_t *src[2];
 
-        for( l = 0; l < 2; l++ )
+        for( int l = 0; l < 2; l++ )
         {
             x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
             x264_me_t *m = &lX->me8x8[i];
@@ -2039,12 +2019,11 @@ static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a )
 {
     ALIGNED_ARRAY_16( uint8_t, pix,[2],[16*8] );
     ALIGNED_4( int16_t mvc[3][2] );
-    int i, j, l, i_ref;
 
     h->mb.i_partition = D_16x8;
     a->i_cost16x8bi = 0;
 
-    for( i = 0; i < 2; i++ )
+    for( int i = 0; i < 2; i++ )
     {
         int i_part_cost;
         int i_part_cost_bi = 0;
@@ -2054,15 +2033,15 @@ static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a )
         m.i_pixel = PIXEL_16x8;
         LOAD_FENC( &m, h->mb.pic.p_fenc, 0, 8*i );
 
-        for( l = 0; l < 2; l++ )
+        for( int l = 0; l < 2; l++ )
         {
             x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
             int ref8[2] = { lX->me8x8[2*i].i_ref, lX->me8x8[2*i+1].i_ref };
             int i_ref8s = ( ref8[0] == ref8[1] ) ? 1 : 2;
             lX->me16x8[i].cost = INT_MAX;
-            for( j = 0; j < i_ref8s; j++ )
+            for( int j = 0; j < i_ref8s; j++ )
             {
-                i_ref = ref8[j];
+                int i_ref = ref8[j];
                 m.i_ref_cost = REF_COST( l, i_ref );;
 
                 LOAD_HPELS( &m, h->mb.pic.p_fref[l][i_ref], l, i_ref, 0, 8*i );
@@ -2122,12 +2101,11 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a )
 {
     ALIGNED_ARRAY_8( uint8_t, pix,[2],[8*16] );
     ALIGNED_4( int16_t mvc[3][2] );
-    int i, j, l, i_ref;
 
     h->mb.i_partition = D_8x16;
     a->i_cost8x16bi = 0;
 
-    for( i = 0; i < 2; i++ )
+    for( int i = 0; i < 2; i++ )
     {
         int i_part_cost;
         int i_part_cost_bi = 0;
@@ -2137,15 +2115,15 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a )
         m.i_pixel = PIXEL_8x16;
         LOAD_FENC( &m, h->mb.pic.p_fenc, 8*i, 0 );
 
-        for( l = 0; l < 2; l++ )
+        for( int l = 0; l < 2; l++ )
         {
             x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
             int ref8[2] = { lX->me8x8[i].i_ref, lX->me8x8[i+2].i_ref };
             int i_ref8s = ( ref8[0] == ref8[1] ) ? 1 : 2;
             lX->me8x16[i].cost = INT_MAX;
-            for( j = 0; j < i_ref8s; j++ )
+            for( int j = 0; j < i_ref8s; j++ )
             {
-                i_ref = ref8[j];
+                int i_ref = ref8[j];
                 m.i_ref_cost = REF_COST( l, i_ref );
 
                 LOAD_HPELS( &m, h->mb.pic.p_fref[l][i_ref], l, i_ref, 8*i, 0 );
@@ -2236,23 +2214,22 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
         h->mb.i_partition = D_8x8;
         if( h->param.analyse.inter & X264_ANALYSE_PSUB8x8 )
         {
-            int i;
             x264_macroblock_cache_ref( h, 0, 0, 2, 2, 0, a->l0.me8x8[0].i_ref );
             x264_macroblock_cache_ref( h, 2, 0, 2, 2, 0, a->l0.me8x8[1].i_ref );
             x264_macroblock_cache_ref( h, 0, 2, 2, 2, 0, a->l0.me8x8[2].i_ref );
             x264_macroblock_cache_ref( h, 2, 2, 2, 2, 0, a->l0.me8x8[3].i_ref );
             /* FIXME: In the 8x8 blocks where RDO isn't run, the NNZ values used for context selection
              * for future blocks are those left over from previous RDO calls. */
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
             {
                 int costs[4] = {a->l0.i_cost4x4[i], a->l0.i_cost8x4[i], a->l0.i_cost4x8[i], a->l0.me8x8[i].cost};
-                int thresh = X264_MIN4( costs[0], costs[1], costs[2], costs[3] ) * 5 / 4;
+                int sub8x8_thresh = X264_MIN4( costs[0], costs[1], costs[2], costs[3] ) * 5 / 4;
                 int subtype, btype = D_L0_8x8;
                 uint64_t bcost = COST_MAX64;
                 for( subtype = D_L0_4x4; subtype <= D_L0_8x8; subtype++ )
                 {
                     uint64_t cost;
-                    if( costs[subtype] > thresh || (subtype == D_L0_8x8 && bcost == COST_MAX64) )
+                    if( costs[subtype] > sub8x8_thresh || (subtype == D_L0_8x8 && bcost == COST_MAX64) )
                         continue;
                     h->mb.i_sub_partition[i] = subtype;
                     x264_mb_cache_mv_p8x8( h, a, i );
@@ -2347,7 +2324,6 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
 static void x264_refine_bidir( x264_t *h, x264_mb_analysis_t *a )
 {
     int i_biweight;
-    int i;
 
     if( IS_INTRA(h->mb.i_type) )
         return;
@@ -2362,7 +2338,7 @@ static void x264_refine_bidir( x264_t *h, x264_mb_analysis_t *a )
             }
             break;
         case D_16x8:
-            for( i=0; i<2; i++ )
+            for( int i = 0; i < 2; i++ )
                 if( a->i_mb_partition16x8[i] == D_BI_8x8 )
                 {
                     i_biweight = h->mb.bipred_weight[a->l0.me16x8[i].i_ref][a->l1.me16x8[i].i_ref];
@@ -2370,7 +2346,7 @@ static void x264_refine_bidir( x264_t *h, x264_mb_analysis_t *a )
                 }
             break;
         case D_8x16:
-            for( i=0; i<2; i++ )
+            for( int i = 0; i < 2; i++ )
                 if( a->i_mb_partition8x16[i] == D_BI_8x8 )
                 {
                     i_biweight = h->mb.bipred_weight[a->l0.me8x16[i].i_ref][a->l1.me8x16[i].i_ref];
@@ -2378,7 +2354,7 @@ static void x264_refine_bidir( x264_t *h, x264_mb_analysis_t *a )
                 }
             break;
         case D_8x8:
-            for( i=0; i<4; i++ )
+            for( int i = 0; i < 4; i++ )
                 if( h->mb.i_sub_partition[i] == D_BI_8x8 )
                 {
                     i_biweight = h->mb.bipred_weight[a->l0.me8x8[i].i_ref][a->l1.me8x8[i].i_ref];
@@ -2392,13 +2368,12 @@ static inline void x264_mb_analyse_transform( x264_t *h )
 {
     if( x264_mb_transform_8x8_allowed( h ) && h->param.analyse.b_transform_8x8 && !h->mb.b_lossless )
     {
-        int i_cost4, i_cost8;
         /* Only luma MC is really needed, but the full MC is re-used in macroblock_encode. */
         x264_mb_mc( h );
 
-        i_cost8 = h->pixf.sa8d[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
+        int i_cost8 = h->pixf.sa8d[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
                                              h->mb.pic.p_fdec[0], FDEC_STRIDE );
-        i_cost4 = h->pixf.satd[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
+        int i_cost4 = h->pixf.satd[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
                                              h->mb.pic.p_fdec[0], FDEC_STRIDE );
 
         h->mb.b_transform_8x8 = i_cost8 < i_cost4;
@@ -2410,11 +2385,10 @@ static inline void x264_mb_analyse_transform_rd( x264_t *h, x264_mb_analysis_t *
 {
     if( x264_mb_transform_8x8_allowed( h ) && h->param.analyse.b_transform_8x8 )
     {
-        int i_rd8;
         x264_analyse_update_cache( h, a );
         h->mb.b_transform_8x8 ^= 1;
         /* FIXME only luma is needed, but the score for comparison already includes chroma */
-        i_rd8 = x264_rd_cost_mb( h, a->i_lambda2 );
+        int i_rd8 = x264_rd_cost_mb( h, a->i_lambda2 );
 
         if( *i_rd >= i_rd8 )
         {
@@ -2436,14 +2410,14 @@ static inline void x264_mb_analyse_transform_rd( x264_t *h, x264_mb_analysis_t *
  * trick. */
 static inline void x264_mb_analyse_qp_rd( x264_t *h, x264_mb_analysis_t *a )
 {
-    int bcost, cost, direction, failures, prevcost, origcost;
+    int bcost, cost, failures, prevcost, origcost;
     int orig_qp = h->mb.i_qp, bqp = h->mb.i_qp;
     int last_qp_tried = 0;
     origcost = bcost = x264_rd_cost_mb( h, a->i_lambda2 );
     int origcbp = h->mb.cbp[h->mb.i_mb_xy];
 
     /* If CBP is already zero, don't raise the quantizer any higher. */
-    for( direction = origcbp ? 1 : -1; direction >= -1; direction-=2 )
+    for( int direction = origcbp ? 1 : -1; direction >= -1; direction-=2 )
     {
         /* Without psy-RD, require monotonicity when moving quant away from previous
          * macroblock's quant; allow 1 failure when moving quant towards previous quant.
@@ -2546,7 +2520,6 @@ void x264_macroblock_analyse( x264_t *h )
 {
     x264_mb_analysis_t analysis;
     int i_cost = COST_MAX;
-    int i;
 
     h->mb.i_qp = x264_ratecontrol_qp( h );
     if( h->param.rc.i_aq_mode )
@@ -2622,7 +2595,7 @@ intra_analysis:
             assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
             /* Set up MVs for future predictors */
             if( b_skip )
-                for( i = 0; i < h->mb.pic.i_fref[0]; i++ )
+                for( int i = 0; i < h->mb.pic.i_fref[0]; i++ )
                     M32( h->mb.mvr[0][i][h->mb.i_mb_xy] ) = 0;
         }
         else
@@ -2639,7 +2612,7 @@ intra_analysis:
 
             if( h->mb.i_type == P_SKIP )
             {
-                for( i = 1; i < h->mb.pic.i_fref[0]; i++ )
+                for( int i = 1; i < h->mb.pic.i_fref[0]; i++ )
                     M32( h->mb.mvr[0][i][h->mb.i_mb_xy] ) = 0;
                 return;
             }
@@ -2667,7 +2640,7 @@ intra_analysis:
                 /* Do sub 8x8 */
                 if( flags & X264_ANALYSE_PSUB8x8 )
                 {
-                    for( i = 0; i < 4; i++ )
+                    for( int i = 0; i < 4; i++ )
                     {
                         x264_mb_analyse_inter_p4x4( h, &analysis, i );
                         if( analysis.l0.i_cost4x4[i] < analysis.l0.me8x8[i].cost )
@@ -2730,9 +2703,8 @@ intra_analysis:
             }
             else if( i_partition == D_8x8 )
             {
-                int i8x8;
                 i_cost = 0;
-                for( i8x8 = 0; i8x8 < 4; i8x8++ )
+                for( int i8x8 = 0; i8x8 < 4; i8x8++ )
                 {
                     switch( h->mb.i_sub_partition[i8x8] )
                     {
@@ -2854,9 +2826,8 @@ intra_analysis:
                 }
                 else if( i_partition == D_8x8 )
                 {
-                    int i8x8;
                     x264_analyse_update_cache( h, &analysis );
-                    for( i8x8 = 0; i8x8 < 4; i8x8++ )
+                    for( int i8x8 = 0; i8x8 < 4; i8x8++ )
                     {
                         if( h->mb.i_sub_partition[i8x8] == D_L0_8x8 )
                         {
@@ -2896,7 +2867,7 @@ intra_analysis:
         if( h->mb.b_direct_auto_write )
         {
             /* direct=auto heuristic: prefer whichever mode allows more Skip macroblocks */
-            for( i = 0; i < 2; i++ )
+            for( int i = 0; i < 2; i++ )
             {
                 int b_changed = 1;
                 h->sh.b_direct_spatial_mv_pred ^= 1;
@@ -2939,9 +2910,9 @@ intra_analysis:
             /* Set up MVs for future predictors */
             if( b_skip )
             {
-                for( i = 0; i < h->mb.pic.i_fref[0]; i++ )
+                for( int i = 0; i < h->mb.pic.i_fref[0]; i++ )
                     M32( h->mb.mvr[0][i][h->mb.i_mb_xy] ) = 0;
-                for( i = 0; i < h->mb.pic.i_fref[1]; i++ )
+                for( int i = 0; i < h->mb.pic.i_fref[1]; i++ )
                     M32( h->mb.mvr[1][i][h->mb.i_mb_xy] ) = 0;
             }
         }
@@ -2966,9 +2937,9 @@ intra_analysis:
 
             if( h->mb.i_type == B_SKIP )
             {
-                for( i = 1; i < h->mb.pic.i_fref[0]; i++ )
+                for( int i = 1; i < h->mb.pic.i_fref[0]; i++ )
                     M32( h->mb.mvr[0][i][h->mb.i_mb_xy] ) = 0;
-                for( i = 1; i < h->mb.pic.i_fref[1]; i++ )
+                for( int i = 1; i < h->mb.pic.i_fref[1]; i++ )
                     M32( h->mb.mvr[0][i][h->mb.i_mb_xy] ) = 0;
                 return;
             }
@@ -3055,7 +3026,7 @@ intra_analysis:
             }
             else if( i_partition == D_16x8 )
             {
-                for( i=0; i<2; i++ )
+                for( int i = 0; i < 2; i++ )
                 {
                     if( analysis.i_mb_partition16x8[i] != D_L1_8x8 )
                         x264_me_refine_qpel( h, &analysis.l0.me16x8[i] );
@@ -3065,7 +3036,7 @@ intra_analysis:
             }
             else if( i_partition == D_8x16 )
             {
-                for( i=0; i<2; i++ )
+                for( int i = 0; i < 2; i++ )
                 {
                     if( analysis.i_mb_partition8x16[i] != D_L1_8x8 )
                         x264_me_refine_qpel( h, &analysis.l0.me8x16[i] );
@@ -3075,7 +3046,7 @@ intra_analysis:
             }
             else if( i_partition == D_8x8 )
             {
-                for( i=0; i<4; i++ )
+                for( int i = 0; i < 4; i++ )
                 {
                     x264_me_t *m;
                     int i_part_cost_old;
@@ -3175,7 +3146,7 @@ intra_analysis:
                 }
                 else if( i_partition == D_16x8 )
                 {
-                    for( i = 0; i < 2; i++ )
+                    for( int i = 0; i < 2; i++ )
                     {
                         h->mb.i_sub_partition[i*2] = h->mb.i_sub_partition[i*2+1] = analysis.i_mb_partition16x8[i];
                         if( analysis.i_mb_partition16x8[i] == D_L0_8x8 )
@@ -3191,7 +3162,7 @@ intra_analysis:
                 }
                 else if( i_partition == D_8x16 )
                 {
-                    for( i = 0; i < 2; i++ )
+                    for( int i = 0; i < 2; i++ )
                     {
                         h->mb.i_sub_partition[i] = h->mb.i_sub_partition[i+2] = analysis.i_mb_partition8x16[i];
                         if( analysis.i_mb_partition8x16[i] == D_L0_8x8 )
@@ -3207,7 +3178,7 @@ intra_analysis:
                 }
                 else if( i_partition == D_8x8 )
                 {
-                    for( i = 0; i < 4; i++ )
+                    for( int i = 0; i < 4; i++ )
                     {
                         if( h->mb.i_sub_partition[i] == D_L0_8x8 )
                             x264_me_refine_qpel_rd( h, &analysis.l0.me8x8[i], analysis.i_lambda2, i*4, 0 );
@@ -3256,18 +3227,16 @@ intra_analysis:
 /*-------------------- Update MB from the analysis ----------------------*/
 static void x264_analyse_update_cache( x264_t *h, x264_mb_analysis_t *a  )
 {
-    int i;
-
     switch( h->mb.i_type )
     {
         case I_4x4:
-            for( i = 0; i < 16; i++ )
+            for( int i = 0; i < 16; i++ )
                 h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] = a->i_predict4x4[i];
 
             x264_mb_analyse_intra_chroma( h, a );
             break;
         case I_8x8:
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 x264_macroblock_cache_intra8x8_pred( h, 2*(i&1), 2*(i>>1), a->i_predict8x8[i] );
 
             x264_mb_analyse_intra_chroma( h, a );
@@ -3313,7 +3282,7 @@ static void x264_analyse_update_cache( x264_t *h, x264_mb_analysis_t *a  )
             x264_macroblock_cache_ref( h, 2, 0, 2, 2, 0, a->l0.me8x8[1].i_ref );
             x264_macroblock_cache_ref( h, 0, 2, 2, 2, 0, a->l0.me8x8[2].i_ref );
             x264_macroblock_cache_ref( h, 2, 2, 2, 2, 0, a->l0.me8x8[3].i_ref );
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 x264_mb_cache_mv_p8x8( h, a, i );
             break;
 
@@ -3336,7 +3305,7 @@ static void x264_analyse_update_cache( x264_t *h, x264_mb_analysis_t *a  )
 
         case B_8x8:
             /* optimize: cache might not need to be rewritten */
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 x264_mb_cache_mv_b8x8( h, a, i, 1 );
             break;
 
@@ -3388,8 +3357,7 @@ static void x264_analyse_update_cache( x264_t *h, x264_mb_analysis_t *a  )
 #ifndef NDEBUG
     if( h->i_thread_frames > 1 && !IS_INTRA(h->mb.i_type) )
     {
-        int l;
-        for( l=0; l <= (h->sh.i_type == SLICE_TYPE_B); l++ )
+        for( int l = 0; l <= (h->sh.i_type == SLICE_TYPE_B); l++ )
         {
             int completed;
             int ref = h->mb.cache.ref[l][x264_scan8[0]];
index 27e6868cf506c8ee88a1fb643cb73229bd816022..8c85f7a9d6891115dd8f284682fccd30279d8492 100644 (file)
@@ -332,7 +332,6 @@ static void x264_cabac_mb_ref( x264_t *h, x264_cabac_t *cb, int i_list, int idx
     const int i8 = x264_scan8[idx];
     const int i_refa = h->mb.cache.ref[i_list][i8 - 1];
     const int i_refb = h->mb.cache.ref[i_list][i8 - 8];
-    int i_ref  = h->mb.cache.ref[i_list][i8];
     int ctx  = 0;
 
     if( i_refa > 0 && !h->mb.cache.skip[i8 - 1] )
@@ -340,11 +339,10 @@ static void x264_cabac_mb_ref( x264_t *h, x264_cabac_t *cb, int i_list, int idx
     if( i_refb > 0 && !h->mb.cache.skip[i8 - 8] )
         ctx += 2;
 
-    while( i_ref > 0 )
+    for( int i_ref = h->mb.cache.ref[i_list][i8]; i_ref > 0; i_ref-- )
     {
         x264_cabac_encode_decision( cb, 54 + ctx, 1 );
         ctx = (ctx>>2)+4;
-        i_ref--;
     }
     x264_cabac_encode_decision( cb, 54 + ctx, 0 );
 }
@@ -353,7 +351,6 @@ static ALWAYS_INLINE int x264_cabac_mb_mvd_cpn( x264_t *h, x264_cabac_t *cb, int
 {
     const int i_abs = abs( mvd );
     const int ctxbase = l ? 47 : 40;
-    int i;
 #if RDO_SKIP_BS
     if( i_abs == 0 )
         x264_cabac_encode_decision( cb, ctxbase + ctx, 0 );
@@ -362,7 +359,7 @@ static ALWAYS_INLINE int x264_cabac_mb_mvd_cpn( x264_t *h, x264_cabac_t *cb, int
         x264_cabac_encode_decision( cb, ctxbase + ctx, 1 );
         if( i_abs <= 3 )
         {
-            for( i = 1; i < i_abs; i++ )
+            for( int i = 1; i < i_abs; i++ )
                 x264_cabac_encode_decision( cb, ctxbase + i + 2, 1 );
             x264_cabac_encode_decision( cb, ctxbase + i_abs + 2, 0 );
             x264_cabac_encode_bypass( cb, mvd < 0 );
@@ -395,13 +392,13 @@ static ALWAYS_INLINE int x264_cabac_mb_mvd_cpn( x264_t *h, x264_cabac_t *cb, int
         x264_cabac_encode_decision( cb, ctxbase + ctx, 1 );
         if( i_abs < 9 )
         {
-            for( i = 1; i < i_abs; i++ )
+            for( int i = 1; i < i_abs; i++ )
                 x264_cabac_encode_decision( cb, ctxbase + ctxes[i-1], 1 );
             x264_cabac_encode_decision( cb, ctxbase + ctxes[i_abs-1], 0 );
         }
         else
         {
-            for( i = 1; i < 9; i++ )
+            for( int i = 1; i < 9; i++ )
                 x264_cabac_encode_decision( cb, ctxbase + ctxes[i-1], 1 );
             x264_cabac_encode_ue_bypass( cb, 3, i_abs - 9 );
         }
@@ -559,7 +556,7 @@ static void block_residual_write_cabac( x264_t *h, x264_cabac_t *cb, int i_ctxBl
     const int i_ctx_sig = significant_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
     const int i_ctx_last = last_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
     const int i_ctx_level = coeff_abs_level_m1_offset[i_ctxBlockCat];
-    const uint8_t *significant_coeff_flag_offset = significant_coeff_flag_offset_8x8[h->mb.b_interlaced];
+    const uint8_t *sig_offset = significant_coeff_flag_offset_8x8[h->mb.b_interlaced];
     int i_coeff_abs_m1[64];
     int i_coeff_sign[64];
     int i_coeff = 0;
@@ -577,7 +574,7 @@ static void block_residual_write_cabac( x264_t *h, x264_cabac_t *cb, int i_ctxBl
             i_coeff_abs_m1[i_coeff] = abs(l[i]) - 1;\
             i_coeff_sign[i_coeff] = l[i] < 0;\
             i_coeff++;\
-            x264_cabac_encode_decision( cb, i_ctx_sig + (l8x8 ? significant_coeff_flag_offset[i] : i), 1 );\
+            x264_cabac_encode_decision( cb, i_ctx_sig + (l8x8 ? sig_offset[i] : i), 1 );\
             if( i == i_last )\
             {\
                 x264_cabac_encode_decision( cb, i_ctx_last + (l8x8 ? last_coeff_flag_offset_8x8[i] : i), 1 );\
@@ -587,7 +584,7 @@ static void block_residual_write_cabac( x264_t *h, x264_cabac_t *cb, int i_ctxBl
                 x264_cabac_encode_decision( cb, i_ctx_last + (l8x8 ? last_coeff_flag_offset_8x8[i] : i), 0 );\
         }\
         else\
-            x264_cabac_encode_decision( cb, i_ctx_sig + (l8x8 ? significant_coeff_flag_offset[i] : i), 0 );\
+            x264_cabac_encode_decision( cb, i_ctx_sig + (l8x8 ? sig_offset[i] : i), 0 );\
         i++;\
         if( i == i_count_m1 )\
         {\
@@ -653,8 +650,8 @@ static void ALWAYS_INLINE block_residual_write_cabac_internal( x264_t *h, x264_c
     const int i_ctx_sig = significant_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
     const int i_ctx_last = last_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
     const int i_ctx_level = coeff_abs_level_m1_offset[i_ctxBlockCat];
-    const uint8_t *significant_coeff_flag_offset = significant_coeff_flag_offset_8x8[h->mb.b_interlaced];
-    int i_last, i_coeff_abs, ctx, i, node_ctx;
+    const uint8_t *sig_offset = significant_coeff_flag_offset_8x8[h->mb.b_interlaced];
+    int i_last, i_coeff_abs, ctx, node_ctx;
 
     i_last = h->quantf.coeff_last[i_ctxBlockCat](l);
 
@@ -663,7 +660,7 @@ static void ALWAYS_INLINE block_residual_write_cabac_internal( x264_t *h, x264_c
 
     if( i_last != (b_8x8 ? 63 : count_cat_m1[i_ctxBlockCat]) )
     {
-        x264_cabac_encode_decision( cb, i_ctx_sig + (b_8x8?significant_coeff_flag_offset[i_last]:i_last), 1 );
+        x264_cabac_encode_decision( cb, i_ctx_sig + (b_8x8?sig_offset[i_last]:i_last), 1 );
         x264_cabac_encode_decision( cb, i_ctx_last + (b_8x8?last_coeff_flag_offset_8x8[i_last]:i_last), 1 );
     }
 
@@ -691,12 +688,12 @@ static void ALWAYS_INLINE block_residual_write_cabac_internal( x264_t *h, x264_c
         x264_cabac_encode_bypass( cb, 0 ); // sign
     }
 
-    for( i = i_last-1 ; i >= 0; i-- )
+    for( int i = i_last-1 ; i >= 0; i-- )
     {
         if( l[i] )
         {
             i_coeff_abs = abs(l[i]);
-            x264_cabac_encode_decision( cb, i_ctx_sig + (b_8x8?significant_coeff_flag_offset[i]:i), 1 );
+            x264_cabac_encode_decision( cb, i_ctx_sig + (b_8x8?sig_offset[i]:i), 1 );
             x264_cabac_encode_decision( cb, i_ctx_last + (b_8x8?last_coeff_flag_offset_8x8[i]:i), 0 );
             ctx = coeff_abs_level1_ctx[node_ctx] + i_ctx_level;
 
@@ -725,7 +722,7 @@ static void ALWAYS_INLINE block_residual_write_cabac_internal( x264_t *h, x264_c
             }
         }
         else
-            x264_cabac_encode_decision( cb, i_ctx_sig + (b_8x8?significant_coeff_flag_offset[i]:i), 0 );
+            x264_cabac_encode_decision( cb, i_ctx_sig + (b_8x8?sig_offset[i]:i), 0 );
     }
 }
 
@@ -755,7 +752,6 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
 {
     const int i_mb_type = h->mb.i_type;
     int i_list;
-    int i;
 
 #if !RDO_SKIP_BS
     const int i_mb_pos_start = x264_cabac_pos( cb );
@@ -773,10 +769,10 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
 
         memcpy( cb->p, h->mb.pic.p_fenc[0], 256 );
         cb->p += 256;
-        for( i = 0; i < 8; i++ )
+        for( int i = 0; i < 8; i++ )
             memcpy( cb->p + i*8, h->mb.pic.p_fenc[1] + i*FENC_STRIDE, 8 );
         cb->p += 64;
-        for( i = 0; i < 8; i++ )
+        for( int i = 0; i < 8; i++ )
             memcpy( cb->p + i*8, h->mb.pic.p_fenc[2] + i*FENC_STRIDE, 8 );
         cb->p += 64;
 
@@ -798,7 +794,7 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
         if( i_mb_type != I_16x16 )
         {
             int di = h->mb.b_transform_8x8 ? 4 : 1;
-            for( i = 0; i < 16; i += di )
+            for( int i = 0; i < 16; i += di )
             {
                 const int i_pred = x264_mb_predict_intra4x4_mode( h, i );
                 const int i_mode = x264_mb_pred_mode4x4_fix( h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] );
@@ -842,7 +838,7 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
     else if( i_mb_type == P_8x8 )
     {
         /* sub mb type */
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             x264_cabac_mb_sub_p_partition( cb, h->mb.i_sub_partition[i] );
 
         /* ref 0 */
@@ -854,31 +850,31 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
             x264_cabac_mb_ref( h, cb, 0, 12 );
         }
 
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             x264_cabac_mb8x8_mvd( h, cb, i );
     }
     else if( i_mb_type == B_8x8 )
     {
         /* sub mb type */
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             x264_cabac_mb_sub_b_partition( cb, h->mb.i_sub_partition[i] );
 
         /* ref */
         if( h->mb.pic.i_fref[0] > 1 )
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
                     x264_cabac_mb_ref( h, cb, 0, 4*i );
 
         if( h->mb.pic.i_fref[1] > 1 )
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
                     x264_cabac_mb_ref( h, cb, 1, 4*i );
 
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
                 x264_cabac_mb_mvd( h, cb, 0, 4*i, 2, 2 );
 
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
                 x264_cabac_mb_mvd( h, cb, 1, 4*i, 2, 2 );
     }
@@ -948,18 +944,18 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
 
             /* AC Luma */
             if( h->mb.i_cbp_luma != 0 )
-                for( i = 0; i < 16; i++ )
+                for( int i = 0; i < 16; i++ )
                     block_residual_write_cabac_cbf( h, cb, DCT_LUMA_AC, i, h->dct.luma4x4[i]+1, 1 );
         }
         else if( h->mb.b_transform_8x8 )
         {
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 if( h->mb.i_cbp_luma & ( 1 << i ) )
                     block_residual_write_cabac_8x8( h, cb, h->dct.luma8x8[i] );
         }
         else
         {
-            for( i = 0; i < 16; i++ )
+            for( int i = 0; i < 16; i++ )
                 if( h->mb.i_cbp_luma & ( 1 << ( i / 4 ) ) )
                     block_residual_write_cabac_cbf( h, cb, DCT_LUMA_4x4, i, h->dct.luma4x4[i], b_intra );
         }
@@ -969,7 +965,7 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb )
             block_residual_write_cabac_cbf( h, cb, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0], b_intra );
             block_residual_write_cabac_cbf( h, cb, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1], b_intra );
             if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */
-                for( i = 16; i < 24; i++ )
+                for( int i = 16; i < 24; i++ )
                     block_residual_write_cabac_cbf( h, cb, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1, b_intra );
         }
     }
@@ -991,7 +987,6 @@ static void x264_partition_size_cabac( x264_t *h, x264_cabac_t *cb, int i8, int
 {
     const int i_mb_type = h->mb.i_type;
     int b_8x16 = h->mb.i_partition == D_8x16;
-    int j;
 
     if( i_mb_type == P_8x8 )
     {
@@ -1013,18 +1008,15 @@ static void x264_partition_size_cabac( x264_t *h, x264_cabac_t *cb, int i8, int
             x264_cabac_mb_mvd( h, cb, 1, 4*i8, 2, 2 );
     }
 
-    for( j = (i_pixel < PIXEL_8x8); j >= 0; j-- )
+    for( int j = (i_pixel < PIXEL_8x8); j >= 0; j-- )
     {
         if( h->mb.i_cbp_luma & (1 << i8) )
         {
             if( h->mb.b_transform_8x8 )
                 block_residual_write_cabac_8x8( h, cb, h->dct.luma8x8[i8] );
             else
-            {
-                int i4;
-                for( i4 = 0; i4 < 4; i4++ )
+                for( int i4 = 0; i4 < 4; i4++ )
                     block_residual_write_cabac_cbf( h, cb, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4], 0 );
-            }
         }
 
         block_residual_write_cabac_cbf( h, cb, DCT_CHROMA_AC, 16+i8, h->dct.luma4x4[16+i8]+1, 0 );
@@ -1077,11 +1069,8 @@ static void x264_i8x8_chroma_size_cabac( x264_t *h, x264_cabac_t *cb )
         block_residual_write_cabac_cbf( h, cb, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1], 1 );
 
         if( h->mb.i_cbp_chroma == 2 )
-        {
-            int i;
-            for( i = 16; i < 24; i++ )
+            for( int i = 16; i < 24; i++ )
                 block_residual_write_cabac_cbf( h, cb, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1, 1 );
-        }
     }
 }
 #endif
index 589eae7c052b35e1a855d58edd884d7746ed286f..d5a9dd5d778ba2c008e7b3cb4961a6d91f6ffb2e 100644 (file)
@@ -119,7 +119,7 @@ static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l,
     static const uint8_t ctz_index[8] = {3,0,1,0,2,0,1,0};
     static const int count_cat[5] = {16, 15, 16, 4, 15};
     x264_run_level_t runlevel;
-    int i_trailing, i_total_zero, i_suffix_length, i;
+    int i_trailing, i_total_zero, i_suffix_length;
     int i_total = 0;
     unsigned int i_sign;
 
@@ -159,7 +159,7 @@ static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l,
         }
         else
             i_suffix_length = block_residual_write_cavlc_escape( h, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
-        for( i = i_trailing+1; i < i_total; i++ )
+        for( int i = i_trailing+1; i < i_total; i++ )
         {
             val = runlevel.level[i] + LEVEL_TABLE_SIZE/2;
             if( (unsigned)val < LEVEL_TABLE_SIZE )
@@ -180,7 +180,7 @@ static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l,
             bs_write_vlc( s, x264_total_zeros[i_total-1][i_total_zero] );
     }
 
-    for( i = 0; i < i_total-1 && i_total_zero > 0; i++ )
+    for( int i = 0; i < i_total-1 && i_total_zero > 0; i++ )
     {
         int i_zl = X264_MIN( i_total_zero, 7 );
         bs_write_vlc( s, x264_run_before[i_zl-1][runlevel.run[i]] );
@@ -262,18 +262,17 @@ static inline void cavlc_mb8x8_mvd( x264_t *h, int i )
 
 static inline void x264_macroblock_luma_write_cavlc( x264_t *h, int i8start, int i8end )
 {
-    int i8, i4;
     if( h->mb.b_transform_8x8 )
     {
         /* shuffle 8x8 dct coeffs into 4x4 lists */
-        for( i8 = i8start; i8 <= i8end; i8++ )
+        for( int i8 = i8start; i8 <= i8end; i8++ )
             if( h->mb.i_cbp_luma & (1 << i8) )
                 h->zigzagf.interleave_8x8_cavlc( h->dct.luma4x4[i8*4], h->dct.luma8x8[i8], &h->mb.cache.non_zero_count[x264_scan8[i8*4]] );
     }
 
-    for( i8 = i8start; i8 <= i8end; i8++ )
+    for( int i8 = i8start; i8 <= i8end; i8++ )
         if( h->mb.i_cbp_luma & (1 << i8) )
-            for( i4 = 0; i4 < 4; i4++ )
+            for( int i4 = 0; i4 < 4; i4++ )
                 block_residual_write_cavlc( h, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4] );
 }
 
@@ -286,7 +285,6 @@ void x264_macroblock_write_cavlc( x264_t *h )
     const int i_mb_type = h->mb.i_type;
     static const uint8_t i_offsets[3] = {5,23,0};
     int i_mb_i_offset = i_offsets[h->sh.i_type];
-    int i;
 
 #if RDO_SKIP_BS
     s->i_bits_encoded = 0;
@@ -313,10 +311,10 @@ void x264_macroblock_write_cavlc( x264_t *h )
 
         memcpy( s->p, h->mb.pic.p_fenc[0], 256 );
         s->p += 256;
-        for( i = 0; i < 8; i++ )
+        for( int i = 0; i < 8; i++ )
             memcpy( s->p + i*8, h->mb.pic.p_fenc[1] + i*FENC_STRIDE, 8 );
         s->p += 64;
-        for( i = 0; i < 8; i++ )
+        for( int i = 0; i < 8; i++ )
             memcpy( s->p + i*8, h->mb.pic.p_fenc[2] + i*FENC_STRIDE, 8 );
         s->p += 64;
 
@@ -340,7 +338,7 @@ void x264_macroblock_write_cavlc( x264_t *h )
             bs_write1( s, h->mb.b_transform_8x8 );
 
         /* Prediction: Luma */
-        for( i = 0; i < 16; i += di )
+        for( int i = 0; i < 16; i += di )
         {
             int i_pred = x264_mb_predict_intra4x4_mode( h, i );
             int i_mode = x264_mb_pred_mode4x4_fix( h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] );
@@ -408,7 +406,7 @@ void x264_macroblock_write_cavlc( x264_t *h )
 
         /* sub mb type */
         if( h->param.analyse.inter & X264_ANALYSE_PSUB8x8 )
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 bs_write_ue( s, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i] ] );
         else
             bs_write( s, 4, 0xf );
@@ -422,7 +420,7 @@ void x264_macroblock_write_cavlc( x264_t *h )
             bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[12]] );
         }
 
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             cavlc_mb8x8_mvd( h, i );
     }
     else if( i_mb_type == B_8x8 )
@@ -430,24 +428,24 @@ void x264_macroblock_write_cavlc( x264_t *h )
         bs_write_ue( s, 22 );
 
         /* sub mb type */
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             bs_write_ue( s, sub_mb_type_b_to_golomb[ h->mb.i_sub_partition[i] ] );
 
         /* ref */
         if( h->mb.pic.i_fref[0] > 1 )
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
                     bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[i*4]] );
         if( h->mb.pic.i_fref[1] > 1 )
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
                 if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
                     bs_write_te( s, h->mb.pic.i_fref[1] - 1, h->mb.cache.ref[1][x264_scan8[i*4]] );
 
         /* mvd */
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
                 cavlc_mb_mvd( h, 0, 4*i, 2 );
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
             if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
                 cavlc_mb_mvd( h, 1, 4*i, 2 );
     }
@@ -517,7 +515,7 @@ void x264_macroblock_write_cavlc( x264_t *h )
 
         /* AC Luma */
         if( h->mb.i_cbp_luma )
-            for( i = 0; i < 16; i++ )
+            for( int i = 0; i < 16; i++ )
                 block_residual_write_cavlc( h, DCT_LUMA_AC, i, h->dct.luma4x4[i]+1 );
     }
     else if( h->mb.i_cbp_luma | h->mb.i_cbp_chroma )
@@ -531,7 +529,7 @@ void x264_macroblock_write_cavlc( x264_t *h )
         block_residual_write_cavlc( h, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
         block_residual_write_cavlc( h, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
         if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */
-            for( i = 16; i < 24; i++ )
+            for( int i = 16; i < 24; i++ )
                 block_residual_write_cavlc( h, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
     }
 
@@ -634,8 +632,7 @@ static int x264_i8x8_chroma_size_cavlc( x264_t *h )
 
         if( h->mb.i_cbp_chroma == 2 )
         {
-            int i;
-            for( i = 16; i < 24; i++ )
+            for( int i = 16; i < 24; i++ )
                 block_residual_write_cavlc( h, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
         }
     }
index 2d66283ccc1c051f62f95778744d500abbdeb361..d3028021cfe12f1229435b4358377240e9968d03 100644 (file)
@@ -56,19 +56,18 @@ static float x264_psnr( int64_t i_sqe, int64_t i_size )
     if( f_mse <= 0.0000000001 ) /* Max 100dB */
         return 100;
 
-    return (float)(-10.0 * log( f_mse ) / log( 10.0 ));
+    return -10.0 * log10( f_mse );
 }
 
 static void x264_frame_dump( x264_t *h )
 {
     FILE *f = fopen( h->param.psz_dump_yuv, "r+b" );
-    int i, y;
     if( !f )
         return;
     /* Write the frame in display order */
     fseek( f, (uint64_t)h->fdec->i_frame * h->param.i_height * h->param.i_width * 3/2, SEEK_SET );
-    for( i = 0; i < h->fdec->i_plane; i++ )
-        for( y = 0; y < h->param.i_height >> !!i; y++ )
+    for( int i = 0; i < h->fdec->i_plane; i++ )
+        for( int y = 0; y < h->param.i_height >> !!i; y++ )
             fwrite( &h->fdec->plane[i][y*h->fdec->i_stride[i]], 1, h->param.i_width >> !!i, f );
     fclose( f );
 }
@@ -80,7 +79,6 @@ static void x264_slice_header_init( x264_t *h, x264_slice_header_t *sh,
                                     int i_idr_pic_id, int i_frame, int i_qp )
 {
     x264_param_t *param = &h->param;
-    int i;
 
     /* First we fill all fields */
     sh->sps = sps;
@@ -139,7 +137,7 @@ static void x264_slice_header_init( x264_t *h, x264_slice_header_t *sh,
     if( sh->b_ref_pic_list_reordering_l0 )
     {
         int pred_frame_num = i_frame;
-        for( i = 0; i < h->i_ref0; i++ )
+        for( int i = 0; i < h->i_ref0; i++ )
         {
             int diff = h->fref0[i]->i_frame_num - pred_frame_num;
             if( diff == 0 )
@@ -157,25 +155,18 @@ static void x264_slice_header_init( x264_t *h, x264_slice_header_t *sh,
     sh->b_sp_for_swidth = 0;
     sh->i_qs_delta = 0;
 
+    int deblock_thresh = i_qp + 2 * X264_MIN(param->i_deblocking_filter_alphac0, param->i_deblocking_filter_beta);
     /* If effective qp <= 15, deblocking would have no effect anyway */
-    if( param->b_deblocking_filter
-        && ( h->mb.b_variable_qp
-        || 15 < i_qp + 2 * X264_MIN(param->i_deblocking_filter_alphac0, param->i_deblocking_filter_beta) ) )
-    {
+    if( param->b_deblocking_filter && (h->mb.b_variable_qp || 15 < deblock_thresh ) )
         sh->i_disable_deblocking_filter_idc = 0;
-    }
     else
-    {
         sh->i_disable_deblocking_filter_idc = 1;
-    }
     sh->i_alpha_c0_offset = param->i_deblocking_filter_alphac0 << 1;
     sh->i_beta_offset = param->i_deblocking_filter_beta << 1;
 }
 
 static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal_ref_idc )
 {
-    int i;
-
     if( sh->b_mbaff )
     {
         assert( sh->i_first_mb % (2*sh->sps->i_mb_width) == 0 );
@@ -196,36 +187,27 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
     }
 
     if( sh->i_idr_pic_id >= 0 ) /* NAL IDR */
-    {
         bs_write_ue( s, sh->i_idr_pic_id );
-    }
 
     if( sh->sps->i_poc_type == 0 )
     {
         bs_write( s, sh->sps->i_log2_max_poc_lsb, sh->i_poc & ((1<<sh->sps->i_log2_max_poc_lsb)-1) );
         if( sh->pps->b_pic_order && !sh->b_field_pic )
-        {
             bs_write_se( s, sh->i_delta_poc_bottom );
-        }
     }
     else if( sh->sps->i_poc_type == 1 && !sh->sps->b_delta_pic_order_always_zero )
     {
         bs_write_se( s, sh->i_delta_poc[0] );
         if( sh->pps->b_pic_order && !sh->b_field_pic )
-        {
             bs_write_se( s, sh->i_delta_poc[1] );
-        }
     }
 
     if( sh->pps->b_redundant_pic_cnt )
-    {
         bs_write_ue( s, sh->i_redundant_pic_cnt );
-    }
 
     if( sh->i_type == SLICE_TYPE_B )
-    {
         bs_write1( s, sh->b_direct_spatial_mv_pred );
-    }
+
     if( sh->i_type == SLICE_TYPE_P || sh->i_type == SLICE_TYPE_SP || sh->i_type == SLICE_TYPE_B )
     {
         bs_write1( s, sh->b_num_ref_idx_override );
@@ -233,9 +215,7 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
         {
             bs_write_ue( s, sh->i_num_ref_idx_l0_active - 1 );
             if( sh->i_type == SLICE_TYPE_B )
-            {
                 bs_write_ue( s, sh->i_num_ref_idx_l1_active - 1 );
-            }
         }
     }
 
@@ -245,11 +225,10 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
         bs_write1( s, sh->b_ref_pic_list_reordering_l0 );
         if( sh->b_ref_pic_list_reordering_l0 )
         {
-            for( i = 0; i < sh->i_num_ref_idx_l0_active; i++ )
+            for( int i = 0; i < sh->i_num_ref_idx_l0_active; i++ )
             {
                 bs_write_ue( s, sh->ref_pic_list_order[0][i].idc );
                 bs_write_ue( s, sh->ref_pic_list_order[0][i].arg );
-
             }
             bs_write_ue( s, 3 );
         }
@@ -259,7 +238,7 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
         bs_write1( s, sh->b_ref_pic_list_reordering_l1 );
         if( sh->b_ref_pic_list_reordering_l1 )
         {
-            for( i = 0; i < sh->i_num_ref_idx_l1_active; i++ )
+            for( int i = 0; i < sh->i_num_ref_idx_l1_active; i++ )
             {
                 bs_write_ue( s, sh->ref_pic_list_order[1][i].idc );
                 bs_write_ue( s, sh->ref_pic_list_order[1][i].arg );
@@ -273,7 +252,7 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
         /* pred_weight_table() */
         bs_write_ue( s, sh->weight[0][0].i_denom );
         bs_write_ue( s, sh->weight[0][1].i_denom );
-        for( i = 0; i < sh->i_num_ref_idx_l0_active; i++ )
+        for( int i = 0; i < sh->i_num_ref_idx_l0_active; i++ )
         {
             int luma_weight_l0_flag = !!sh->weight[i][0].weightfn;
             int chroma_weight_l0_flag = !!sh->weight[i][1].weightfn || !!sh->weight[i][2].weightfn;
@@ -286,8 +265,7 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
             bs_write1( s, chroma_weight_l0_flag );
             if( chroma_weight_l0_flag )
             {
-                int j;
-                for( j = 1; j < 3; j++ )
+                for( int j = 1; j < 3; j++ )
                 {
                     bs_write_se( s, sh->weight[i][j].i_scale );
                     bs_write_se( s, sh->weight[i][j].i_offset );
@@ -312,8 +290,7 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
             bs_write1( s, sh->i_mmco_command_count > 0 ); /* adaptive_ref_pic_marking_mode_flag */
             if( sh->i_mmco_command_count > 0 )
             {
-                int i;
-                for( i = 0; i < sh->i_mmco_command_count; i++ )
+                for( int i = 0; i < sh->i_mmco_command_count; i++ )
                 {
                     bs_write_ue( s, 1 ); /* mark short term ref as unused */
                     bs_write_ue( s, sh->mmco[i].i_difference_of_pic_nums - 1 );
@@ -324,9 +301,8 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
     }
 
     if( sh->pps->b_cabac && sh->i_type != SLICE_TYPE_I )
-    {
         bs_write_ue( s, sh->i_cabac_init_idc );
-    }
+
     bs_write_se( s, sh->i_qp_delta );      /* slice qp delta */
 
     if( sh->pps->b_deblocking_filter_control )
@@ -345,16 +321,13 @@ static void x264_slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal
 static int x264_bitstream_check_buffer( x264_t *h )
 {
     uint8_t *bs_bak = h->out.p_bitstream;
-    if( ( h->param.b_cabac && (h->cabac.p_end - h->cabac.p < 2500) )
-     || ( h->out.bs.p_end - h->out.bs.p < 2500 ) )
+    if( (h->param.b_cabac && (h->cabac.p_end - h->cabac.p < 2500)) ||
+        (h->out.bs.p_end - h->out.bs.p < 2500) )
     {
-        intptr_t delta;
-        int i;
-
         h->out.i_bitstream += 100000;
         CHECKED_MALLOC( h->out.p_bitstream, h->out.i_bitstream );
         h->mc.memcpy_aligned( h->out.p_bitstream, bs_bak, (h->out.i_bitstream - 100000) & ~15 );
-        delta = h->out.p_bitstream - bs_bak;
+        intptr_t delta = h->out.p_bitstream - bs_bak;
 
         h->out.bs.p_start += delta;
         h->out.bs.p += delta;
@@ -364,7 +337,7 @@ static int x264_bitstream_check_buffer( x264_t *h )
         h->cabac.p += delta;
         h->cabac.p_end = h->out.p_bitstream + h->out.i_bitstream;
 
-        for( i = 0; i <= h->out.i_nal; i++ )
+        for( int i = 0; i <= h->out.i_nal; i++ )
             h->out.nal[i].p_payload += delta;
         x264_free( bs_bak );
     }
@@ -503,8 +476,8 @@ static int x264_validate_parameters( x264_t *h )
     if( h->param.rc.i_rc_method == X264_RC_CQP )
     {
         float qp_p = h->param.rc.i_qp_constant;
-        float qp_i = qp_p - 6*log(h->param.rc.f_ip_factor)/log(2);
-        float qp_b = qp_p + 6*log(h->param.rc.f_pb_factor)/log(2);
+        float qp_i = qp_p - 6*log2f( h->param.rc.f_ip_factor );
+        float qp_b = qp_p + 6*log2f( h->param.rc.f_pb_factor );
         h->param.rc.i_qp_min = x264_clip3( (int)(X264_MIN3( qp_p, qp_i, qp_b )), 0, 51 );
         h->param.rc.i_qp_max = x264_clip3( (int)(X264_MAX3( qp_p, qp_i, qp_b ) + .999), 0, 51 );
         h->param.rc.i_aq_mode = 0;
@@ -880,7 +853,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
 {
     x264_t *h;
     char buf[1000], *p;
-    int i, qp, i_slicetype_length;
+    int qp, i_slicetype_length;
 
     CHECKED_MALLOCZERO( h, sizeof(x264_t) );
 
@@ -1004,7 +977,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
     mbcmp_init( h );
 
     p = buf + sprintf( buf, "using cpu capabilities:" );
-    for( i=0; x264_cpu_names[i].flags; i++ )
+    for( int i = 0; x264_cpu_names[i].flags; i++ )
     {
         if( !strcmp(x264_cpu_names[i].name, "SSE2")
             && h->param.cpu & (X264_CPU_SSE2_IS_FAST|X264_CPU_SSE2_IS_SLOW) )
@@ -1043,13 +1016,13 @@ x264_t *x264_encoder_open( x264_param_t *param )
     h->nal_buffer_size = h->out.i_bitstream * 3/2 + 4;
 
     h->thread[0] = h;
-    for( i = 1; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
+    for( int i = 1; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
         CHECKED_MALLOC( h->thread[i], sizeof(x264_t) );
 
     if( x264_lookahead_init( h, i_slicetype_length ) )
         goto fail;
 
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
     {
         int init_nal_count = h->param.i_slice_count + 3;
         int allocate_threadlocal_data = !h->param.b_sliced_threads || !i;
@@ -1075,7 +1048,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
     }
 
     /* Allocate scratch buffer */
-    for( i = 0; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
+    for( int i = 0; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
     {
         int buf_hpel = (h->fdec->i_width[0]+48) * sizeof(int16_t);
         int buf_ssim = h->param.analyse.b_ssim * 8 * (h->param.i_width/4+3) * sizeof(int);
@@ -1228,6 +1201,7 @@ static void x264_nal_start( x264_t *h, int i_type, int i_ref_idc )
     nal->i_payload= 0;
     nal->p_payload= &h->out.p_bitstream[bs_pos( &h->out.bs ) / 8];
 }
+
 /* if number of allocated nals is not enough, re-allocate a larger one. */
 static int x264_nal_check_buffer( x264_t *h )
 {
@@ -1243,6 +1217,7 @@ static int x264_nal_check_buffer( x264_t *h )
     }
     return 0;
 }
+
 static int x264_nal_end( x264_t *h )
 {
     x264_nal_t *nal = &h->out.nal[h->out.i_nal];
@@ -1254,12 +1229,12 @@ static int x264_nal_end( x264_t *h )
 
 static int x264_encoder_encapsulate_nals( x264_t *h, int start )
 {
-    int nal_size = 0, previous_nal_size = 0, i;
+    int nal_size = 0, previous_nal_size = 0;
 
-    for( i = 0; i < start; i++ )
+    for( int i = 0; i < start; i++ )
         previous_nal_size += h->out.nal[i].i_payload;
 
-    for( i = start; i < h->out.i_nal; i++ )
+    for( int i = start; i < h->out.i_nal; i++ )
         nal_size += h->out.nal[i].i_payload;
 
     /* Worst-case NAL unit escaping: reallocate the buffer if it's too small. */
@@ -1276,7 +1251,7 @@ static int x264_encoder_encapsulate_nals( x264_t *h, int start )
 
     uint8_t *nal_buffer = h->nal_buffer + previous_nal_size;
 
-    for( i = start; i < h->out.i_nal; i++ )
+    for( int i = start; i < h->out.i_nal; i++ )
     {
         int long_startcode = !i || h->out.nal[i].i_type == NAL_SPS || h->out.nal[i].i_type == NAL_PPS;
         int size = x264_nal_encode( nal_buffer, &h->out.nal[i], h->param.b_annexb, long_startcode );
@@ -1333,8 +1308,7 @@ int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
  * from the standard's default. */
 static inline void x264_reference_check_reorder( x264_t *h )
 {
-    int i;
-    for( i = 0; i < h->i_ref0 - 1; i++ )
+    for( int i = 0; i < h->i_ref0 - 1; i++ )
         /* P and B-frames use different default orders. */
         if( h->sh.i_type == SLICE_TYPE_P ? h->fref0[i]->i_frame_num < h->fref0[i+1]->i_frame_num
                                          : h->fref0[i]->i_poc < h->fref0[i+1]->i_poc )
@@ -1387,19 +1361,16 @@ int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t
 
 static void x264_weighted_pred_init( x264_t *h )
 {
-    int i_ref;
-    int i;
-
     /* for now no analysis and set all weights to nothing */
-    for( i_ref = 0; i_ref < h->i_ref0; i_ref++ )
+    for( int i_ref = 0; i_ref < h->i_ref0; i_ref++ )
         h->fenc->weighted[i_ref] = h->fref0[i_ref]->filtered[0];
 
     // FIXME: This only supports weighting of one reference frame
     // and duplicates of that frame.
     h->fenc->i_lines_weighted = 0;
 
-    for( i_ref = 0; i_ref < (h->i_ref0 << h->sh.b_mbaff); i_ref++ )
-        for( i = 0; i < 3; i++ )
+    for( int i_ref = 0; i_ref < (h->i_ref0 << h->sh.b_mbaff); i_ref++ )
+        for( int i = 0; i < 3; i++ )
             h->sh.weight[i_ref][i].weightfn = NULL;
 
 
@@ -1410,11 +1381,10 @@ static void x264_weighted_pred_init( x264_t *h )
     int denom = -1;
     int weightluma = 0;
     int buffer_next = 0;
-    int j;
     //FIXME: when chroma support is added, move this into loop
     h->sh.weight[0][1].weightfn = h->sh.weight[0][2].weightfn = NULL;
     h->sh.weight[0][1].i_denom = h->sh.weight[0][2].i_denom = 0;
-    for( j = 0; j < h->i_ref0; j++ )
+    for( int j = 0; j < h->i_ref0; j++ )
     {
         if( h->fenc->weight[j][0].weightfn )
         {
@@ -1456,7 +1426,7 @@ static void x264_weighted_pred_init( x264_t *h )
 
 static inline void x264_reference_build_list( x264_t *h, int i_poc )
 {
-    int i, b_ok;
+    int b_ok;
 
     /* build ref list 0/1 */
     h->mb.pic.i_fref[0] = h->i_ref0 = 0;
@@ -1464,23 +1434,19 @@ static inline void x264_reference_build_list( x264_t *h, int i_poc )
     if( h->sh.i_type == SLICE_TYPE_I )
         return;
 
-    for( i = 0; h->frames.reference[i]; i++ )
+    for( int i = 0; h->frames.reference[i]; i++ )
     {
         if( h->frames.reference[i]->i_poc < i_poc )
-        {
             h->fref0[h->i_ref0++] = h->frames.reference[i];
-        }
         else if( h->frames.reference[i]->i_poc > i_poc )
-        {
             h->fref1[h->i_ref1++] = h->frames.reference[i];
-        }
     }
 
     /* Order ref0 from higher to lower poc */
     do
     {
         b_ok = 1;
-        for( i = 0; i < h->i_ref0 - 1; i++ )
+        for( int i = 0; i < h->i_ref0 - 1; i++ )
         {
             if( h->fref0[i]->i_poc < h->fref0[i+1]->i_poc )
             {
@@ -1492,7 +1458,7 @@ static inline void x264_reference_build_list( x264_t *h, int i_poc )
     } while( !b_ok );
 
     if( h->sh.i_mmco_remove_from_end )
-        for( i = h->i_ref0-1; i >= h->i_ref0 - h->sh.i_mmco_remove_from_end; i-- )
+        for( int i = h->i_ref0-1; i >= h->i_ref0 - h->sh.i_mmco_remove_from_end; i-- )
         {
             int diff = h->i_frame_num - h->fref0[i]->i_frame_num;
             h->sh.mmco[h->sh.i_mmco_command_count].i_poc = h->fref0[i]->i_poc;
@@ -1503,7 +1469,7 @@ static inline void x264_reference_build_list( x264_t *h, int i_poc )
     do
     {
         b_ok = 1;
-        for( i = 0; i < h->i_ref1 - 1; i++ )
+        for( int i = 0; i < h->i_ref1 - 1; i++ )
         {
             if( h->fref1[i]->i_poc > h->fref1[i+1]->i_poc )
             {
@@ -1585,23 +1551,17 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y )
         return;
 
     if( !b_end && !h->param.b_sliced_threads )
-    {
-        int i, j;
-        for( j=0; j<=h->sh.b_mbaff; j++ )
-            for( i=0; i<3; i++ )
+        for( int j = 0; j <= h->sh.b_mbaff; j++ )
+            for( int i = 0; i < 3; i++ )
             {
                 memcpy( h->mb.intra_border_backup[j][i],
                         h->fdec->plane[i] + ((mb_y*16 >> !!i) + j - 1 - h->sh.b_mbaff) * h->fdec->i_stride[i],
                         h->sps->i_mb_width*16 >> !!i );
             }
-    }
 
     if( b_deblock )
-    {
-        int y;
-        for( y = min_y; y < max_y; y += (1 << h->sh.b_mbaff) )
+        for( int y = min_y; y < max_y; y += (1 << h->sh.b_mbaff) )
             x264_frame_deblock_row( h, y );
-    }
 
     if( b_hpel )
     {
@@ -1620,15 +1580,12 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y )
     max_y = b_end ? h->param.i_height : mb_y*16-8;
 
     if( h->param.analyse.b_psnr )
-    {
-        int i;
-        for( i=0; i<3; i++ )
+        for( int i = 0; i < 3; i++ )
             h->stat.frame.i_ssd[i] +=
                 x264_pixel_ssd_wxh( &h->pixf,
                     h->fdec->plane[i] + (min_y>>!!i) * h->fdec->i_stride[i], h->fdec->i_stride[i],
                     h->fenc->plane[i] + (min_y>>!!i) * h->fenc->i_stride[i], h->fenc->i_stride[i],
                     h->param.i_width >> !!i, (max_y-min_y) >> !!i );
-    }
 
     if( h->param.analyse.b_ssim )
     {
@@ -1646,7 +1603,6 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y )
 
 static inline int x264_reference_update( x264_t *h )
 {
-    int i, j;
     if( !h->fdec->b_kept_as_ref )
     {
         if( h->i_thread_frames > 1 )
@@ -1660,8 +1616,8 @@ static inline int x264_reference_update( x264_t *h )
     }
 
     /* apply mmco from previous frame. */
-    for( i = 0; i < h->sh.i_mmco_command_count; i++ )
-        for( j = 0; h->frames.reference[j]; j++ )
+    for( int i = 0; i < h->sh.i_mmco_command_count; i++ )
+        for( int j = 0; h->frames.reference[j]; j++ )
             if( h->frames.reference[j]->i_poc == h->sh.mmco[i].i_poc )
                 x264_frame_push_unused( h, x264_frame_shift( &h->frames.reference[j] ) );
 
@@ -1685,13 +1641,13 @@ static inline void x264_reference_reset( x264_t *h )
 
 static inline void x264_reference_hierarchy_reset( x264_t *h )
 {
-    int i, ref;
+    int ref;
     int b_hasdelayframe = 0;
     if( !h->param.i_bframe_pyramid )
         return;
 
     /* look for delay frames -- chain must only contain frames that are disposable */
-    for( i = 0; h->frames.current[i] && IS_DISPOSABLE( h->frames.current[i]->i_type ); i++ )
+    for( int i = 0; h->frames.current[i] && IS_DISPOSABLE( h->frames.current[i]->i_type ); i++ )
         b_hasdelayframe |= h->frames.current[i]->i_coded
                         != h->frames.current[i]->i_frame + h->sps->vui.i_num_reorder_frames;
 
@@ -1771,7 +1727,7 @@ static int x264_slice_write( x264_t *h )
 {
     int i_skip;
     int mb_xy, i_mb_x, i_mb_y;
-    int i, i_list, i_ref, i_skip_bak = 0; /* Shut up GCC. */
+    int i_skip_bak = 0; /* Shut up GCC. */
     bs_t bs_bak;
     x264_cabac_t cabac_bak;
     uint8_t cabac_prevbyte_bak = 0; /* Shut up GCC. */
@@ -1916,13 +1872,13 @@ static int x264_slice_write( x264_t *h )
             if( h->mb.i_partition != D_8x8 )
                     h->stat.frame.i_mb_partition[h->mb.i_partition] += 4;
                 else
-                    for( i = 0; i < 4; i++ )
+                    for( int i = 0; i < 4; i++ )
                         h->stat.frame.i_mb_partition[h->mb.i_sub_partition[i]] ++;
             if( h->param.i_frame_reference > 1 )
-                for( i_list = 0; i_list <= (h->sh.i_type == SLICE_TYPE_B); i_list++ )
-                    for( i = 0; i < 4; i++ )
+                for( int i_list = 0; i_list <= (h->sh.i_type == SLICE_TYPE_B); i_list++ )
+                    for( int i = 0; i < 4; i++ )
                     {
-                        i_ref = h->mb.cache.ref[i_list][ x264_scan8[4*i] ];
+                        int i_ref = h->mb.cache.ref[i_list][ x264_scan8[4*i] ];
                         if( i_ref >= 0 )
                             h->stat.frame.i_mb_count_ref[i_list][i_ref] ++;
                     }
@@ -1949,10 +1905,10 @@ static int x264_slice_write( x264_t *h )
                 if( h->mb.i_type == I_16x16 )
                     h->stat.frame.i_mb_pred_mode[0][h->mb.i_intra16x16_pred_mode]++;
                 else if( h->mb.i_type == I_8x8 )
-                    for( i = 0; i < 16; i += 4 )
+                    for( int i = 0; i < 16; i += 4 )
                         h->stat.frame.i_mb_pred_mode[1][h->mb.cache.intra4x4_pred_mode[x264_scan8[i]]]++;
                 else //if( h->mb.i_type == I_4x4 )
-                    for( i = 0; i < 16; i++ )
+                    for( int i = 0; i < 16; i++ )
                         h->stat.frame.i_mb_pred_mode[2][h->mb.cache.intra4x4_pred_mode[x264_scan8[i]]]++;
             }
         }
@@ -2008,10 +1964,9 @@ static void x264_thread_sync_context( x264_t *dst, x264_t *src )
         return;
 
     // reference counting
-    x264_frame_t **f;
-    for( f = src->frames.reference; *f; f++ )
+    for( x264_frame_t **f = src->frames.reference; *f; f++ )
         (*f)->i_reference_count++;
-    for( f = dst->frames.reference; *f; f++ )
+    for( x264_frame_t **f = dst->frames.reference; *f; f++ )
         x264_frame_push_unused( src, *f );
     src->fdec->i_reference_count++;
     x264_frame_push_unused( src, dst->fdec );
@@ -2082,10 +2037,9 @@ static void *x264_slices_write( x264_t *h )
 
 static int x264_threaded_slices_write( x264_t *h )
 {
-    int i, j;
     void *ret = NULL;
     /* set first/last mb and sync contexts */
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
     {
         x264_t *t = h->thread[i];
         if( i )
@@ -2105,13 +2059,13 @@ static int x264_threaded_slices_write( x264_t *h )
     x264_threads_distribute_ratecontrol( h );
 
     /* dispatch */
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
     {
         if( x264_pthread_create( &h->thread[i]->thread_handle, NULL, (void*)x264_slices_write, (void*)h->thread[i] ) )
             return -1;
         h->thread[i]->b_thread_active = 1;
     }
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
     {
         x264_pthread_join( h->thread[i]->thread_handle, &ret );
         h->thread[i]->b_thread_active = 0;
@@ -2120,15 +2074,15 @@ static int x264_threaded_slices_write( x264_t *h )
     }
 
     /* deblocking and hpel filtering */
-    for( i = 0; i <= h->sps->i_mb_height; i++ )
+    for( int i = 0; i <= h->sps->i_mb_height; i++ )
         x264_stack_align( x264_fdec_filter_row, h, i );
 
     x264_threads_merge_ratecontrol( h );
 
-    for( i = 1; i < h->param.i_threads; i++ )
+    for( int i = 1; i < h->param.i_threads; i++ )
     {
         x264_t *t = h->thread[i];
-        for( j = 0; j < t->out.i_nal; j++ )
+        for( int j = 0; j < t->out.i_nal; j++ )
         {
             h->out.nal[h->out.i_nal] = t->out.nal[j];
             h->out.i_nal++;
@@ -2136,7 +2090,7 @@ static int x264_threaded_slices_write( x264_t *h )
         }
         /* All entries in stat.frame are ints except for ssd/ssim,
          * which are only calculated in the main thread. */
-        for( j = 0; j < (offsetof(x264_t,stat.frame.i_ssd) - offsetof(x264_t,stat.frame.i_mv_bits)) / sizeof(int); j++ )
+        for( int j = 0; j < (offsetof(x264_t,stat.frame.i_ssd) - offsetof(x264_t,stat.frame.i_mv_bits)) / sizeof(int); j++ )
             ((int*)&h->stat.frame)[j] += ((int*)&t->stat.frame)[j];
     }
 
@@ -2162,7 +2116,7 @@ int     x264_encoder_encode( x264_t *h,
                              x264_picture_t *pic_out )
 {
     x264_t *thread_current, *thread_prev, *thread_oldest;
-    int i_nal_type, i_nal_ref_idc, i_global_qp, i;
+    int i_nal_type, i_nal_ref_idc, i_global_qp;
     int overhead = NALU_OVERHEAD;
 
     if( h->i_thread_frames > 1 )
@@ -2174,7 +2128,6 @@ int     x264_encoder_encode( x264_t *h,
         x264_thread_sync_context( thread_current, thread_prev );
         x264_thread_sync_ratecontrol( thread_current, thread_prev, thread_oldest );
         h = thread_current;
-//      fprintf(stderr, "current: %p  prev: %p  oldest: %p \n", thread_current, thread_prev, thread_oldest);
     }
     else
     {
@@ -2352,7 +2305,7 @@ int     x264_encoder_encode( x264_t *h,
     /* Init bitstream context */
     if( h->param.b_sliced_threads )
     {
-        for( i = 0; i < h->param.i_threads; i++ )
+        for( int i = 0; i < h->param.i_threads; i++ )
         {
             bs_init( &h->thread[i]->out.bs, h->thread[i]->out.p_bitstream, h->thread[i]->out.i_bitstream );
             h->thread[i]->out.i_nal = 0;
@@ -2526,7 +2479,6 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
                                    x264_nal_t **pp_nal, int *pi_nal,
                                    x264_picture_t *pic_out )
 {
-    int i, j, i_list, frame_size;
     char psz_message[80];
 
     if( h->b_thread_active )
@@ -2545,7 +2497,7 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
 
     x264_frame_push_unused( thread_current, h->fenc );
 
-    frame_size = x264_encoder_encapsulate_nals( h, 0 );
+    int frame_size = x264_encoder_encapsulate_nals( h, 0 );
 
     /* Set output picture properties */
     if( h->sh.i_type == SLICE_TYPE_I )
@@ -2583,7 +2535,7 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
         x264_log( h, X264_LOG_WARNING, "invalid DTS: PTS is less than DTS\n" );
 
     pic_out->img.i_plane = h->fdec->i_plane;
-    for(i = 0; i < 3; i++)
+    for( int i = 0; i < 3; i++ )
     {
         pic_out->img.i_stride[i] = h->fdec->i_stride[i];
         pic_out->img.plane[i] = h->fdec->plane[i];
@@ -2637,34 +2589,32 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
     h->stat.i_frame_size[h->sh.i_type] += frame_size;
     h->stat.f_frame_qp[h->sh.i_type] += h->fdec->f_qp_avg_aq;
 
-    for( i = 0; i < X264_MBTYPE_MAX; i++ )
+    for( int i = 0; i < X264_MBTYPE_MAX; i++ )
         h->stat.i_mb_count[h->sh.i_type][i] += h->stat.frame.i_mb_count[i];
-    for( i = 0; i < X264_PARTTYPE_MAX; i++ )
+    for( int i = 0; i < X264_PARTTYPE_MAX; i++ )
         h->stat.i_mb_partition[h->sh.i_type][i] += h->stat.frame.i_mb_partition[i];
-    for( i = 0; i < 2; i++ )
+    for( int i = 0; i < 2; i++ )
         h->stat.i_mb_count_8x8dct[i] += h->stat.frame.i_mb_count_8x8dct[i];
-    for( i = 0; i < 6; i++ )
+    for( int i = 0; i < 6; i++ )
         h->stat.i_mb_cbp[i] += h->stat.frame.i_mb_cbp[i];
-    for( i = 0; i < 3; i++ )
-        for( j = 0; j < 13; j++ )
+    for( int i = 0; i < 3; i++ )
+        for( int j = 0; j < 13; j++ )
             h->stat.i_mb_pred_mode[i][j] += h->stat.frame.i_mb_pred_mode[i][j];
     if( h->sh.i_type != SLICE_TYPE_I )
-        for( i_list = 0; i_list < 2; i_list++ )
-            for( i = 0; i < 32; i++ )
+        for( int i_list = 0; i_list < 2; i_list++ )
+            for( int i = 0; i < 32; i++ )
                 h->stat.i_mb_count_ref[h->sh.i_type][i_list][i] += h->stat.frame.i_mb_count_ref[i_list][i];
     if( h->sh.i_type == SLICE_TYPE_P )
     {
         h->stat.i_consecutive_bframes[h->fdec->i_frame - h->fref0[0]->i_frame - 1]++;
         if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART )
-        {
-            for( i = 0; i < 3; i++ )
-                for( j = 0; j < h->i_ref0; j++ )
+            for( int i = 0; i < 3; i++ )
+                for( int j = 0; j < h->i_ref0; j++ )
                     if( h->sh.weight[0][i].i_denom != 0 )
                     {
                         h->stat.i_wpred[i]++;
                         break;
                     }
-        }
     }
     if( h->sh.i_type == SLICE_TYPE_B )
     {
@@ -2673,11 +2623,9 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
         {
             //FIXME somewhat arbitrary time constants
             if( h->stat.i_direct_score[0] + h->stat.i_direct_score[1] > h->mb.i_mb_count )
-            {
-                for( i = 0; i < 2; i++ )
+                for( int i = 0; i < 2; i++ )
                     h->stat.i_direct_score[i] = h->stat.i_direct_score[i] * 9/10;
-            }
-            for( i = 0; i < 2; i++ )
+            for( int i = 0; i < 2; i++ )
                 h->stat.i_direct_score[i] += h->stat.frame.i_direct_score[i];
         }
     }
@@ -2735,8 +2683,7 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
 {
     static const char mb_chars[] = { 'i', 'i', 'I', 'C', 'P', '8', 'S',
         'D', '<', 'X', 'B', 'X', '>', 'B', 'B', 'B', 'B', '8', 'S' };
-    int mb_xy;
-    for( mb_xy = 0; mb_xy < h->sps->i_mb_width * h->sps->i_mb_height; mb_xy++ )
+    for( int mb_xy = 0; mb_xy < h->sps->i_mb_width * h->sps->i_mb_height; mb_xy++ )
     {
         if( h->mb.type[mb_xy] < X264_MBTYPE_MAX && h->mb.type[mb_xy] >= 0 )
             fprintf( stderr, "%c ", mb_chars[ h->mb.type[mb_xy] ] );
@@ -2751,7 +2698,7 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
 
     /* Remove duplicates, must be done near the end as breaks h->fref0 array
      * by freeing some of its pointers. */
-     for( i = 0; i < h->i_ref0; i++ )
+     for( int i = 0; i < h->i_ref0; i++ )
          if( h->fref0[i] && h->fref0[i]->b_duplicate )
          {
              x264_frame_push_blank_unused( h, h->fref0[i] );
@@ -2783,7 +2730,6 @@ void    x264_encoder_close  ( x264_t *h )
     int64_t i_yuv_size = 3 * h->param.i_width * h->param.i_height / 2;
     int64_t i_mb_count_size[2][7] = {{0}};
     char buf[200];
-    int i, j, i_list, i_type;
     int b_print_pcm = h->stat.i_mb_count[SLICE_TYPE_I][I_PCM]
                    || h->stat.i_mb_count[SLICE_TYPE_P][I_PCM]
                    || h->stat.i_mb_count[SLICE_TYPE_B][I_PCM];
@@ -2793,19 +2739,17 @@ void    x264_encoder_close  ( x264_t *h )
     if( h->param.i_threads > 1 )
     {
         // don't strictly have to wait for the other threads, but it's simpler than canceling them
-        for( i = 0; i < h->param.i_threads; i++ )
+        for( int i = 0; i < h->param.i_threads; i++ )
             if( h->thread[i]->b_thread_active )
                 x264_pthread_join( h->thread[i]->thread_handle, NULL );
         if( h->i_thread_frames > 1 )
         {
-            for( i = 0; i < h->i_thread_frames; i++ )
-            {
+            for( int i = 0; i < h->i_thread_frames; i++ )
                 if( h->thread[i]->b_thread_active )
                 {
                     assert( h->thread[i]->fenc->i_reference_count == 1 );
                     x264_frame_delete( h->thread[i]->fenc );
                 }
-            }
 
             x264_t *thread_prev = h->thread[h->i_thread_phase];
             x264_thread_sync_ratecontrol( h, thread_prev, h );
@@ -2816,7 +2760,7 @@ void    x264_encoder_close  ( x264_t *h )
     h->i_frame++;
 
     /* Slices used and PSNR */
-    for( i=0; i<5; i++ )
+    for( int i = 0; i < 5; i++ )
     {
         static const int slice_order[] = { SLICE_TYPE_I, SLICE_TYPE_SI, SLICE_TYPE_P, SLICE_TYPE_SP, SLICE_TYPE_B };
         static const char *slice_name[] = { "P", "B", "I", "SP", "SI" };
@@ -2853,15 +2797,15 @@ void    x264_encoder_close  ( x264_t *h )
         char *p = buf;
         int den = 0;
         // weight by number of frames (including the P-frame) that are in a sequence of N B-frames
-        for( i=0; i<=h->param.i_bframe; i++ )
+        for( int i = 0; i <= h->param.i_bframe; i++ )
             den += (i+1) * h->stat.i_consecutive_bframes[i];
-        for( i=0; i<=h->param.i_bframe; i++ )
+        for( int i = 0; i <= h->param.i_bframe; i++ )
             p += sprintf( p, " %4.1f%%", 100. * (i+1) * h->stat.i_consecutive_bframes[i] / den );
         x264_log( h, X264_LOG_INFO, "consecutive B-frames:%s\n", buf );
     }
 
-    for( i_type = 0; i_type < 2; i_type++ )
-        for( i = 0; i < X264_PARTTYPE_MAX; i++ )
+    for( int i_type = 0; i_type < 2; i_type++ )
+        for( int i = 0; i < X264_PARTTYPE_MAX; i++ )
         {
             if( i == D_DIRECT_8x8 ) continue; /* direct is counted as its own type */
             i_mb_count_size[i_type][x264_mb_partition_pixel_table[i]] += h->stat.i_mb_partition[i_type][i];
@@ -2899,8 +2843,8 @@ void    x264_encoder_close  ( x264_t *h )
         int64_t *i_mb_size = i_mb_count_size[SLICE_TYPE_B];
         int64_t list_count[3] = {0}; /* 0 == L0, 1 == L1, 2 == BI */
         x264_print_intra( i_mb_count, i_count, b_print_pcm, buf );
-        for( i = 0; i < X264_PARTTYPE_MAX; i++ )
-            for( j = 0; j < 2; j++ )
+        for( int i = 0; i < X264_PARTTYPE_MAX; i++ )
+            for( int j = 0; j < 2; j++ )
             {
                 int l0 = x264_mb_type_list_table[i][0][j];
                 int l1 = x264_mb_type_list_table[i][1][j];
@@ -2980,7 +2924,7 @@ void    x264_encoder_close  ( x264_t *h )
 
         int64_t fixed_pred_modes[3][9] = {{0}};
         int64_t sum_pred_modes[3] = {0};
-        for( i = 0; i <= I_PRED_16x16_DC_128; i++ )
+        for( int i = 0; i <= I_PRED_16x16_DC_128; i++ )
         {
             fixed_pred_modes[0][x264_mb_pred_mode16x16_fix[i]] += h->stat.i_mb_pred_mode[0][i];
             sum_pred_modes[0] += h->stat.i_mb_pred_mode[0][i];
@@ -2991,9 +2935,9 @@ void    x264_encoder_close  ( x264_t *h )
                       fixed_pred_modes[0][1] * 100.0 / sum_pred_modes[0],
                       fixed_pred_modes[0][2] * 100.0 / sum_pred_modes[0],
                       fixed_pred_modes[0][3] * 100.0 / sum_pred_modes[0] );
-        for( i = 1; i <= 2; i++ )
+        for( int i = 1; i <= 2; i++ )
         {
-            for( j = 0; j <= I_PRED_8x8_DC_128; j++ )
+            for( int j = 0; j <= I_PRED_8x8_DC_128; j++ )
             {
                 fixed_pred_modes[i][x264_mb_pred_mode4x4_fix(j)] += h->stat.i_mb_pred_mode[i][j];
                 sum_pred_modes[i] += h->stat.i_mb_pred_mode[i][j];
@@ -3015,15 +2959,13 @@ void    x264_encoder_close  ( x264_t *h )
             x264_log( h, X264_LOG_INFO, "Weighted P-Frames: Y:%.1f%%\n",
                       h->stat.i_wpred[0] * 100.0 / h->stat.i_frame_count[SLICE_TYPE_P] );
 
-        for( i_list = 0; i_list < 2; i_list++ )
-        {
-            int i_slice;
-            for( i_slice = 0; i_slice < 2; i_slice++ )
+        for( int i_list = 0; i_list < 2; i_list++ )
+            for( int i_slice = 0; i_slice < 2; i_slice++ )
             {
                 char *p = buf;
                 int64_t i_den = 0;
                 int i_max = 0;
-                for( i = 0; i < 32; i++ )
+                for( int i = 0; i < 32; i++ )
                     if( h->stat.i_mb_count_ref[i_slice][i_list][i] )
                     {
                         i_den += h->stat.i_mb_count_ref[i_slice][i_list][i];
@@ -3031,11 +2973,10 @@ void    x264_encoder_close  ( x264_t *h )
                     }
                 if( i_max == 0 )
                     continue;
-                for( i = 0; i <= i_max; i++ )
+                for( int i = 0; i <= i_max; i++ )
                     p += sprintf( p, " %4.1f%%", 100. * h->stat.i_mb_count_ref[i_slice][i_list][i] / i_den );
                 x264_log( h, X264_LOG_INFO, "ref %c L%d:%s\n", "PB"[i_slice], i_list, buf );
             }
-        }
 
         if( h->param.analyse.b_ssim )
         {
@@ -3082,7 +3023,7 @@ void    x264_encoder_close  ( x264_t *h )
 
     h = h->thread[0];
 
-    for( i = h->param.i_threads - 1; i >= 0; i-- )
+    for( int i = h->param.i_threads - 1; i >= 0; i-- )
     {
         x264_frame_t **frame;
 
@@ -3115,14 +3056,13 @@ void    x264_encoder_close  ( x264_t *h )
 int x264_encoder_delayed_frames( x264_t *h )
 {
     int delayed_frames = 0;
-    int i;
     if( h->i_thread_frames > 1 )
     {
-        for( i=0; i<h->i_thread_frames; i++ )
+        for( int i = 0; i < h->i_thread_frames; i++ )
             delayed_frames += h->thread[i]->b_thread_active;
         h = h->thread[h->i_thread_phase];
     }
-    for( i=0; h->frames.current[i]; i++ )
+    for( int i = 0; h->frames.current[i]; i++ )
         delayed_frames++;
     x264_pthread_mutex_lock( &h->lookahead->ofbuf.mutex );
     x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex );
index b66eedc576f636d101ced75232bccf45f5cac066..7a0c6d3a7ffc51ef3f8dcae86ba72855d523b6bf 100644 (file)
@@ -129,8 +129,7 @@ int x264_lookahead_init( x264_t *h, int i_slicetype_length )
 {
     x264_lookahead_t *look;
     CHECKED_MALLOCZERO( look, sizeof(x264_lookahead_t) );
-    int i;
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
         h->thread[i]->lookahead = look;
 
     look->i_last_keyframe = - h->param.i_keyint_max;
@@ -193,10 +192,9 @@ void x264_lookahead_put_frame( x264_t *h, x264_frame_t *frame )
 
 int x264_lookahead_is_empty( x264_t *h )
 {
-    int b_empty;
     x264_pthread_mutex_lock( &h->lookahead->ofbuf.mutex );
     x264_pthread_mutex_lock( &h->lookahead->next.mutex );
-    b_empty = !h->lookahead->next.i_size && !h->lookahead->ofbuf.i_size;
+    int b_empty = !h->lookahead->next.i_size && !h->lookahead->ofbuf.i_size;
     x264_pthread_mutex_unlock( &h->lookahead->next.mutex );
     x264_pthread_mutex_unlock( &h->lookahead->ofbuf.mutex );
     return b_empty;
index 8f37a0aaf65ff158439285cf084ace33b51994c0..ca62368b31eccfc716935e68ba0a2bc935c36336 100644 (file)
@@ -189,12 +189,12 @@ static void x264_mb_encode_i16x16( x264_t *h, int i_qp )
     ALIGNED_ARRAY_16( int16_t, dct4x4,[16],[16] );
     ALIGNED_ARRAY_16( int16_t, dct_dc4x4,[16] );
 
-    int i, nz;
+    int nz;
     int decimate_score = h->mb.b_dct_decimate ? 0 : 9;
 
     if( h->mb.b_lossless )
     {
-        for( i = 0; i < 16; i++ )
+        for( int i = 0; i < 16; i++ )
         {
             int oe = block_idx_xy_fenc[i];
             int od = block_idx_xy_fdec[i];
@@ -210,7 +210,7 @@ static void x264_mb_encode_i16x16( x264_t *h, int i_qp )
 
     h->dctf.sub16x16_dct( dct4x4, p_src, p_dst );
 
-    for( i = 0; i < 16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         /* copy dc coeff */
         dct_dc4x4[block_idx_xy_1d[i]] = dct4x4[i][0];
@@ -251,7 +251,7 @@ static void x264_mb_encode_i16x16( x264_t *h, int i_qp )
         h->dctf.idct4x4dc( dct_dc4x4 );
         h->quantf.dequant_4x4_dc( dct_dc4x4, h->dequant4_mf[CQM_4IY], i_qp );  /* XXX not inversed */
         if( h->mb.i_cbp_luma )
-            for( i = 0; i < 16; i++ )
+            for( int i = 0; i < 16; i++ )
                 dct4x4[i][0] = dct_dc4x4[block_idx_xy_1d[i]];
     }
 
@@ -319,7 +319,7 @@ static inline int x264_mb_optimize_chroma_dc( x264_t *h, int b_inter, int i_qp,
 
 void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
 {
-    int i, ch, nz, nz_dc;
+    int nz, nz_dc;
     int b_decimate = b_inter && h->mb.b_dct_decimate;
     ALIGNED_ARRAY_16( int16_t, dct2x2,[4] );
     h->mb.i_cbp_chroma = 0;
@@ -345,7 +345,7 @@ void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
             h->mb.cache.non_zero_count[x264_scan8[23]] = 0;
             h->mb.cache.non_zero_count[x264_scan8[25]] = 0;
             h->mb.cache.non_zero_count[x264_scan8[26]] = 0;
-            for( ch = 0; ch < 2; ch++ )
+            for( int ch = 0; ch < 2; ch++ )
             {
                 if( ssd[ch] > thresh )
                 {
@@ -353,8 +353,7 @@ void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
                     if( h->mb.b_trellis )
                         nz_dc = x264_quant_dc_trellis( h, dct2x2, CQM_4IC+b_inter, i_qp, DCT_CHROMA_DC, !b_inter, 1 );
                     else
-                        nz_dc = h->quantf.quant_2x2_dc( dct2x2, h->quant4_mf[CQM_4IC+b_inter][i_qp][0]>>1, h->quant4_bias[CQM_4IC+b_inter][i_qp][0]<<
-    1 );
+                        nz_dc = h->quantf.quant_2x2_dc( dct2x2, h->quant4_mf[CQM_4IC+b_inter][i_qp][0]>>1, h->quant4_bias[CQM_4IC+b_inter][i_qp][0]<<1 );
 
                     if( nz_dc )
                     {
@@ -372,7 +371,7 @@ void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
         }
     }
 
-    for( ch = 0; ch < 2; ch++ )
+    for( int ch = 0; ch < 2; ch++ )
     {
         uint8_t  *p_src = h->mb.pic.p_fenc[1+ch];
         uint8_t  *p_dst = h->mb.pic.p_fdec[1+ch];
@@ -383,7 +382,7 @@ void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
 
         if( h->mb.b_lossless )
         {
-            for( i = 0; i < 4; i++ )
+            for( int i = 0; i < 4; i++ )
             {
                 int oe = block_idx_x[i]*4 + block_idx_y[i]*4*FENC_STRIDE;
                 int od = block_idx_x[i]*4 + block_idx_y[i]*4*FDEC_STRIDE;
@@ -398,7 +397,7 @@ void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qp )
         h->dctf.sub8x8_dct( dct4x4, p_src, p_dst );
         dct2x2dc( dct2x2, dct4x4 );
         /* calculate dct coeffs */
-        for( i = 0; i < 4; i++ )
+        for( int i = 0; i < 4; i++ )
         {
             if( h->mb.b_trellis )
                 nz = x264_quant_4x4_trellis( h, dct4x4[i], CQM_4IC+b_inter, i_qp, DCT_CHROMA_AC, !b_inter, 1, 0 );
@@ -586,7 +585,7 @@ void x264_macroblock_encode( x264_t *h )
     int i_qp = h->mb.i_qp;
     int b_decimate = h->mb.b_dct_decimate;
     int b_force_no_skip = 0;
-    int i,idx,nz;
+    int nz;
     h->mb.i_cbp_luma = 0;
     h->mb.cache.non_zero_count[x264_scan8[24]] = 0;
 
@@ -661,7 +660,7 @@ void x264_macroblock_encode( x264_t *h )
             if( h->mb.i_skip_intra == 2 )
                 h->mc.memcpy_aligned( h->dct.luma8x8, h->mb.pic.i8x8_dct_buf, sizeof(h->mb.pic.i8x8_dct_buf) );
         }
-        for( i = h->mb.i_skip_intra ? 3 : 0 ; i < 4; i++ )
+        for( int i = h->mb.i_skip_intra ? 3 : 0 ; i < 4; i++ )
         {
             uint8_t  *p_dst = &h->mb.pic.p_fdec[0][8 * (i&1) + 8 * (i>>1) * FDEC_STRIDE];
             int      i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]];
@@ -691,7 +690,7 @@ void x264_macroblock_encode( x264_t *h )
             if( h->mb.i_skip_intra == 2 )
                 h->mc.memcpy_aligned( h->dct.luma4x4, h->mb.pic.i4x4_dct_buf, sizeof(h->mb.pic.i4x4_dct_buf) );
         }
-        for( i = h->mb.i_skip_intra ? 15 : 0 ; i < 16; i++ )
+        for( int i = h->mb.i_skip_intra ? 15 : 0 ; i < 16; i++ )
         {
             uint8_t  *p_dst = &h->mb.pic.p_fdec[0][block_idx_xy_fdec[i]];
             int      i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
@@ -709,7 +708,6 @@ void x264_macroblock_encode( x264_t *h )
     }
     else    /* Inter MB */
     {
-        int i8x8, i4x4;
         int i_decimate_mb = 0;
 
         /* Don't repeat motion compensation if it was already done in non-RD transform analysis */
@@ -719,7 +717,7 @@ void x264_macroblock_encode( x264_t *h )
         if( h->mb.b_lossless )
         {
             if( h->mb.b_transform_8x8 )
-                for( i8x8 = 0; i8x8 < 4; i8x8++ )
+                for( int i8x8 = 0; i8x8 < 4; i8x8++ )
                 {
                     int x = 8*(i8x8&1);
                     int y = 8*(i8x8>>1);
@@ -730,7 +728,7 @@ void x264_macroblock_encode( x264_t *h )
                     h->mb.i_cbp_luma |= nz << i8x8;
                 }
             else
-                for( i4x4 = 0; i4x4 < 16; i4x4++ )
+                for( int i4x4 = 0; i4x4 < 16; i4x4++ )
                 {
                     nz = h->zigzagf.sub_4x4( h->dct.luma4x4[i4x4],
                                         h->mb.pic.p_fenc[0]+block_idx_xy_fenc[i4x4],
@@ -746,7 +744,7 @@ void x264_macroblock_encode( x264_t *h )
             h->dctf.sub16x16_dct8( dct8x8, h->mb.pic.p_fenc[0], h->mb.pic.p_fdec[0] );
             h->nr_count[1] += h->mb.b_noise_reduction * 4;
 
-            for( idx = 0; idx < 4; idx++ )
+            for( int idx = 0; idx < 4; idx++ )
             {
                 if( h->mb.b_noise_reduction )
                     h->quantf.denoise_dct( dct8x8[idx], h->nr_residual_sum[1], h->nr_offset[1], 64 );
@@ -774,7 +772,7 @@ void x264_macroblock_encode( x264_t *h )
             }
             else
             {
-                for( idx = 0; idx < 4; idx++ )
+                for( int idx = 0; idx < 4; idx++ )
                 {
                     if( h->mb.i_cbp_luma&(1<<idx) )
                     {
@@ -793,15 +791,15 @@ void x264_macroblock_encode( x264_t *h )
             h->dctf.sub16x16_dct( dct4x4, h->mb.pic.p_fenc[0], h->mb.pic.p_fdec[0] );
             h->nr_count[0] += h->mb.b_noise_reduction * 16;
 
-            for( i8x8 = 0; i8x8 < 4; i8x8++ )
+            for( int i8x8 = 0; i8x8 < 4; i8x8++ )
             {
                 int i_decimate_8x8 = 0;
                 int cbp = 0;
 
                 /* encode one 4x4 block */
-                for( i4x4 = 0; i4x4 < 4; i4x4++ )
+                for( int i4x4 = 0; i4x4 < 4; i4x4++ )
                 {
-                    idx = i8x8 * 4 + i4x4;
+                    int idx = i8x8 * 4 + i4x4;
 
                     if( h->mb.b_noise_reduction )
                         h->quantf.denoise_dct( dct4x4[idx], h->nr_residual_sum[0], h->nr_offset[0], 16 );
@@ -843,7 +841,7 @@ void x264_macroblock_encode( x264_t *h )
                 }
                 else
                 {
-                    for( i8x8 = 0; i8x8 < 4; i8x8++ )
+                    for( int i8x8 = 0; i8x8 < 4; i8x8++ )
                         if( h->mb.i_cbp_luma&(1<<i8x8) )
                             h->dctf.add8x8_idct( &h->mb.pic.p_fdec[0][(i8x8&1)*8 + (i8x8>>1)*8*FDEC_STRIDE], &dct4x4[i8x8*4] );
                 }
@@ -910,10 +908,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
 
     int i_qp = h->mb.i_qp;
     int mvp[2];
-    int ch, thresh, ssd;
-
-    int i8x8, i4x4;
-    int i_decimate_mb;
+    int thresh, ssd;
 
     if( !b_bidir )
     {
@@ -927,7 +922,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
                        mvp[0], mvp[1], 16, 16, &h->sh.weight[0][0] );
     }
 
-    for( i8x8 = 0, i_decimate_mb = 0; i8x8 < 4; i8x8++ )
+    for( int i8x8 = 0, i_decimate_mb = 0; i8x8 < 4; i8x8++ )
     {
         int fenc_offset = (i8x8&1) * 8 + (i8x8>>1) * FENC_STRIDE * 8;
         int fdec_offset = (i8x8&1) * 8 + (i8x8>>1) * FDEC_STRIDE * 8;
@@ -935,7 +930,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
         h->dctf.sub8x8_dct( dct4x4, h->mb.pic.p_fenc[0] + fenc_offset,
                                     h->mb.pic.p_fdec[0] + fdec_offset );
         /* encode one 4x4 block */
-        for( i4x4 = 0; i4x4 < 4; i4x4++ )
+        for( int i4x4 = 0; i4x4 < 4; i4x4++ )
         {
             if( !h->quantf.quant_4x4( dct4x4[i4x4], h->quant4_mf[CQM_4PY][i_qp], h->quant4_bias[CQM_4PY][i_qp] ) )
                 continue;
@@ -950,7 +945,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
     i_qp = h->mb.i_chroma_qp;
     thresh = (x264_lambda2_tab[i_qp] + 32) >> 6;
 
-    for( ch = 0; ch < 2; ch++ )
+    for( int ch = 0; ch < 2; ch++ )
     {
         uint8_t  *p_src = h->mb.pic.p_fenc[1+ch];
         uint8_t  *p_dst = h->mb.pic.p_fdec[1+ch];
@@ -987,7 +982,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
         h->dctf.sub8x8_dct( dct4x4, p_src, p_dst );
 
         /* calculate dct coeffs */
-        for( i4x4 = 0, i_decimate_mb = 0; i4x4 < 4; i4x4++ )
+        for( int i4x4 = 0, i_decimate_mb = 0; i4x4 < 4; i4x4++ )
         {
             /* We don't need to zero the DC coefficient before quantization because we already
              * checked that all the DCs were zero above at twice the precision that quant4x4
@@ -1013,20 +1008,19 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir )
 
 void x264_noise_reduction_update( x264_t *h )
 {
-    int cat, i;
-    for( cat = 0; cat < 2; cat++ )
+    for( int cat = 0; cat < 2; cat++ )
     {
         int size = cat ? 64 : 16;
         const uint16_t *weight = cat ? x264_dct8_weight2_tab : x264_dct4_weight2_tab;
 
         if( h->nr_count[cat] > (cat ? (1<<16) : (1<<18)) )
         {
-            for( i = 0; i < size; i++ )
+            for( int i = 0; i < size; i++ )
                 h->nr_residual_sum[cat][i] >>= 1;
             h->nr_count[cat] >>= 1;
         }
 
-        for( i = 0; i < size; i++ )
+        for( int i = 0; i < size; i++ )
             h->nr_offset[cat][i] =
                 ((uint64_t)h->param.analyse.i_noise_reduction * h->nr_count[cat]
                  + h->nr_residual_sum[cat][i]/2)
@@ -1045,14 +1039,13 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 )
     uint8_t *p_fdec = h->mb.pic.p_fdec[0] + (i8&1)*8 + (i8>>1)*8*FDEC_STRIDE;
     int b_decimate = h->mb.b_dct_decimate;
     int nnz8x8 = 0;
-    int ch, nz;
+    int nz;
 
     if( !h->mb.b_skip_mc )
         x264_mb_mc_8x8( h, i8 );
 
     if( h->mb.b_lossless )
     {
-        int i4;
         if( h->mb.b_transform_8x8 )
         {
             nnz8x8 = h->zigzagf.sub_8x8( h->dct.luma8x8[i8], p_fenc, p_fdec );
@@ -1060,9 +1053,8 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 )
         }
         else
         {
-            for( i4 = i8*4; i4 < i8*4+4; i4++ )
+            for( int i4 = i8*4; i4 < i8*4+4; i4++ )
             {
-                int nz;
                 nz = h->zigzagf.sub_4x4( h->dct.luma4x4[i4],
                                     h->mb.pic.p_fenc[0]+block_idx_xy_fenc[i4],
                                     h->mb.pic.p_fdec[0]+block_idx_xy_fdec[i4] );
@@ -1070,7 +1062,7 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 )
                 nnz8x8 |= nz;
             }
         }
-        for( ch = 0; ch < 2; ch++ )
+        for( int ch = 0; ch < 2; ch++ )
         {
             int16_t dc;
             p_fenc = h->mb.pic.p_fenc[1+ch] + (i8&1)*4 + (i8>>1)*4*FENC_STRIDE;
@@ -1107,11 +1099,10 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 )
         }
         else
         {
-            int i4;
             int i_decimate_8x8 = 0;
             ALIGNED_ARRAY_16( int16_t, dct4x4,[4],[16] );
             h->dctf.sub8x8_dct( dct4x4, p_fenc, p_fdec );
-            for( i4 = 0; i4 < 4; i4++ )
+            for( int i4 = 0; i4 < 4; i4++ )
             {
                 nz = x264_quant_4x4( h, dct4x4[i4], i_qp, DCT_LUMA_4x4, 0, i8*4+i4 );
                 h->mb.cache.non_zero_count[x264_scan8[i8*4+i4]] = nz;
@@ -1136,7 +1127,7 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 )
 
         i_qp = h->mb.i_chroma_qp;
 
-        for( ch = 0; ch < 2; ch++ )
+        for( int ch = 0; ch < 2; ch++ )
         {
             ALIGNED_ARRAY_16( int16_t, dct4x4,[16] );
             p_fenc = h->mb.pic.p_fenc[1+ch] + (i8&1)*4 + (i8>>1)*4*FENC_STRIDE;
index d534fbcfb575ba35d109660346652e7a24b87e59..b0e16a56cd6bd7d6486a9a460a06462cfeba30c6 100644 (file)
@@ -146,7 +146,7 @@ static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_ite
 
 #define CROSS( start, x_max, y_max )\
 {\
-    i = start;\
+    int i = start;\
     if( (x_max) <= X264_MIN(mv_x_max-omx, omx-mv_x_min) )\
         for( ; i < (x_max)-2; i+=4 )\
             COST_MV_X4( i,0, -i,0, i+2,0, -i-2,0 );\
@@ -184,8 +184,6 @@ void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc,
     uint8_t *p_fref_w = m->p_fref_w;
     ALIGNED_ARRAY_16( uint8_t, pix,[16*16] );
 
-    int i, j;
-    int dir;
     int costs[16];
 
     int mv_x_min = h->mb.mv_min_fpel[0];
@@ -218,7 +216,7 @@ void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc,
         uint32_t bmv = pack16to32_mask(bmx,bmy);
         if( i_mvc )
             COST_MV_HPEL( bmx, bmy );
-        for( i = 0; i < i_mvc; i++ )
+        for( int i = 0; i < i_mvc; i++ )
         {
             if( M32( mvc[i] ) && (bmv - M32( mvc[i] )) )
             {
@@ -242,7 +240,7 @@ void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc,
          * sensible to remove the cost of the MV from the rounded MVP to avoid unfairly
          * biasing against use of the predicted motion vector. */
         bcost -= BITS_MVD( pmx, pmy );
-        for( i = 0; i < i_mvc; i++ )
+        for( int i = 0; i < i_mvc; i++ )
         {
             int mx = (mvc[i][0] + 2) >> 2;
             int my = (mvc[i][1] + 2) >> 2;
@@ -258,104 +256,108 @@ void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc,
 
     switch( h->mb.i_me_method )
     {
-    case X264_ME_DIA:
-        /* diamond search, radius 1 */
-        i = 0;
-        bcost <<= 4;
-        do
-        {
-            COST_MV_X4_DIR( 0,-1, 0,1, -1,0, 1,0, costs );
-            COPY1_IF_LT( bcost, (costs[0]<<4)+1 );
-            COPY1_IF_LT( bcost, (costs[1]<<4)+3 );
-            COPY1_IF_LT( bcost, (costs[2]<<4)+4 );
-            COPY1_IF_LT( bcost, (costs[3]<<4)+12 );
-            if( !(bcost&15) )
-                break;
-            bmx -= (bcost<<28)>>30;
-            bmy -= (bcost<<30)>>30;
-            bcost &= ~15;
-            if( !CHECK_MVRANGE(bmx, bmy) )
-                break;
-        } while( ++i < i_me_range );
-        bcost >>= 4;
-        break;
-
-    case X264_ME_HEX:
-me_hex2:
-        /* hexagon search, radius 2 */
-#if 0
-        for( i = 0; i < i_me_range/2; i++ )
+        case X264_ME_DIA:
         {
-            omx = bmx; omy = bmy;
-            COST_MV( omx-2, omy   );
-            COST_MV( omx-1, omy+2 );
-            COST_MV( omx+1, omy+2 );
-            COST_MV( omx+2, omy   );
-            COST_MV( omx+1, omy-2 );
-            COST_MV( omx-1, omy-2 );
-            if( bmx == omx && bmy == omy )
-                break;
-            if( !CHECK_MVRANGE(bmx, bmy) )
-                break;
+            /* diamond search, radius 1 */
+            bcost <<= 4;
+            int i = 0;
+            do
+            {
+                COST_MV_X4_DIR( 0,-1, 0,1, -1,0, 1,0, costs );
+                COPY1_IF_LT( bcost, (costs[0]<<4)+1 );
+                COPY1_IF_LT( bcost, (costs[1]<<4)+3 );
+                COPY1_IF_LT( bcost, (costs[2]<<4)+4 );
+                COPY1_IF_LT( bcost, (costs[3]<<4)+12 );
+                if( !(bcost&15) )
+                    break;
+                bmx -= (bcost<<28)>>30;
+                bmy -= (bcost<<30)>>30;
+                bcost &= ~15;
+                if( !CHECK_MVRANGE(bmx, bmy) )
+                    break;
+            } while( ++i < i_me_range );
+            bcost >>= 4;
+            break;
         }
-#else
-        /* equivalent to the above, but eliminates duplicate candidates */
-
-        /* hexagon */
-        COST_MV_X3_DIR( -2,0, -1, 2,  1, 2, costs   );
-        COST_MV_X3_DIR(  2,0,  1,-2, -1,-2, costs+3 );
-        bcost <<= 3;
-        COPY1_IF_LT( bcost, (costs[0]<<3)+2 );
-        COPY1_IF_LT( bcost, (costs[1]<<3)+3 );
-        COPY1_IF_LT( bcost, (costs[2]<<3)+4 );
-        COPY1_IF_LT( bcost, (costs[3]<<3)+5 );
-        COPY1_IF_LT( bcost, (costs[4]<<3)+6 );
-        COPY1_IF_LT( bcost, (costs[5]<<3)+7 );
-
-        if( bcost&7 )
-        {
-            dir = (bcost&7)-2;
-            bmx += hex2[dir+1][0];
-            bmy += hex2[dir+1][1];
 
-            /* half hexagon, not overlapping the previous iteration */
-            for( i = 1; i < i_me_range>>1 && CHECK_MVRANGE(bmx, bmy); i++ )
+        case X264_ME_HEX:
             {
-                COST_MV_X3_DIR( hex2[dir+0][0], hex2[dir+0][1],
-                                hex2[dir+1][0], hex2[dir+1][1],
-                                hex2[dir+2][0], hex2[dir+2][1],
-                                costs );
-                bcost &= ~7;
-                COPY1_IF_LT( bcost, (costs[0]<<3)+1 );
-                COPY1_IF_LT( bcost, (costs[1]<<3)+2 );
-                COPY1_IF_LT( bcost, (costs[2]<<3)+3 );
-                if( !(bcost&7) )
+    me_hex2:
+            /* hexagon search, radius 2 */
+    #if 0
+            for( int i = 0; i < i_me_range/2; i++ )
+            {
+                omx = bmx; omy = bmy;
+                COST_MV( omx-2, omy   );
+                COST_MV( omx-1, omy+2 );
+                COST_MV( omx+1, omy+2 );
+                COST_MV( omx+2, omy   );
+                COST_MV( omx+1, omy-2 );
+                COST_MV( omx-1, omy-2 );
+                if( bmx == omx && bmy == omy )
+                    break;
+                if( !CHECK_MVRANGE(bmx, bmy) )
                     break;
-                dir += (bcost&7)-2;
-                dir = mod6m1[dir+1];
+            }
+    #else
+            /* equivalent to the above, but eliminates duplicate candidates */
+
+            /* hexagon */
+            COST_MV_X3_DIR( -2,0, -1, 2,  1, 2, costs   );
+            COST_MV_X3_DIR(  2,0,  1,-2, -1,-2, costs+3 );
+            bcost <<= 3;
+            COPY1_IF_LT( bcost, (costs[0]<<3)+2 );
+            COPY1_IF_LT( bcost, (costs[1]<<3)+3 );
+            COPY1_IF_LT( bcost, (costs[2]<<3)+4 );
+            COPY1_IF_LT( bcost, (costs[3]<<3)+5 );
+            COPY1_IF_LT( bcost, (costs[4]<<3)+6 );
+            COPY1_IF_LT( bcost, (costs[5]<<3)+7 );
+
+            if( bcost&7 )
+            {
+                int dir = (bcost&7)-2;
                 bmx += hex2[dir+1][0];
                 bmy += hex2[dir+1][1];
+
+                /* half hexagon, not overlapping the previous iteration */
+                for( int i = 1; i < i_me_range>>1 && CHECK_MVRANGE(bmx, bmy); i++ )
+                {
+                    COST_MV_X3_DIR( hex2[dir+0][0], hex2[dir+0][1],
+                                    hex2[dir+1][0], hex2[dir+1][1],
+                                    hex2[dir+2][0], hex2[dir+2][1],
+                                    costs );
+                    bcost &= ~7;
+                    COPY1_IF_LT( bcost, (costs[0]<<3)+1 );
+                    COPY1_IF_LT( bcost, (costs[1]<<3)+2 );
+                    COPY1_IF_LT( bcost, (costs[2]<<3)+3 );
+                    if( !(bcost&7) )
+                        break;
+                    dir += (bcost&7)-2;
+                    dir = mod6m1[dir+1];
+                    bmx += hex2[dir+1][0];
+                    bmy += hex2[dir+1][1];
+                }
             }
+            bcost >>= 3;
+    #endif
+            /* square refine */
+            int dir = 0;
+            COST_MV_X4_DIR(  0,-1,  0,1, -1,0, 1,0, costs );
+            COPY2_IF_LT( bcost, costs[0], dir, 1 );
+            COPY2_IF_LT( bcost, costs[1], dir, 2 );
+            COPY2_IF_LT( bcost, costs[2], dir, 3 );
+            COPY2_IF_LT( bcost, costs[3], dir, 4 );
+            COST_MV_X4_DIR( -1,-1, -1,1, 1,-1, 1,1, costs );
+            COPY2_IF_LT( bcost, costs[0], dir, 5 );
+            COPY2_IF_LT( bcost, costs[1], dir, 6 );
+            COPY2_IF_LT( bcost, costs[2], dir, 7 );
+            COPY2_IF_LT( bcost, costs[3], dir, 8 );
+            bmx += square1[dir][0];
+            bmy += square1[dir][1];
+            break;
         }
-        bcost >>= 3;
-#endif
-        /* square refine */
-        dir = 0;
-        COST_MV_X4_DIR(  0,-1,  0,1, -1,0, 1,0, costs );
-        COPY2_IF_LT( bcost, costs[0], dir, 1 );
-        COPY2_IF_LT( bcost, costs[1], dir, 2 );
-        COPY2_IF_LT( bcost, costs[2], dir, 3 );
-        COPY2_IF_LT( bcost, costs[3], dir, 4 );
-        COST_MV_X4_DIR( -1,-1, -1,1, 1,-1, 1,1, costs );
-        COPY2_IF_LT( bcost, costs[0], dir, 5 );
-        COPY2_IF_LT( bcost, costs[1], dir, 6 );
-        COPY2_IF_LT( bcost, costs[2], dir, 7 );
-        COPY2_IF_LT( bcost, costs[3], dir, 8 );
-        bmx += square1[dir][0];
-        bmy += square1[dir][1];
-        break;
 
-    case X264_ME_UMH:
+        case X264_ME_UMH:
         {
             /* Uneven-cross Multi-Hexagon-grid Search
              * as in JM, except with different early termination */
@@ -371,7 +373,7 @@ me_hex2:
             if( pmx | pmy )
                 DIA1_ITER( 0, 0 );
 
-            if(i_pixel == PIXEL_4x4)
+            if( i_pixel == PIXEL_4x4 )
                 goto me_hex2;
 
             ucost2 = bcost;
@@ -464,7 +466,7 @@ me_hex2:
             omx = bmx; omy = bmy;
             const uint16_t *p_cost_omvx = p_cost_mvx + omx*4;
             const uint16_t *p_cost_omvy = p_cost_mvy + omy*4;
-            i = 1;
+            int i = 1;
             do
             {
                 static const int hex4[16][2] = {
@@ -477,7 +479,7 @@ me_hex2:
                 if( 4*i > X264_MIN4( mv_x_max-omx, omx-mv_x_min,
                                      mv_y_max-omy, omy-mv_y_min ) )
                 {
-                    for( j = 0; j < 16; j++ )
+                    for( int j = 0; j < 16; j++ )
                     {
                         int mx = omx + hex4[j][0]*i;
                         int my = omy + hex4[j][1]*i;
@@ -551,8 +553,8 @@ me_hex2:
             break;
         }
 
-    case X264_ME_ESA:
-    case X264_ME_TESA:
+        case X264_ME_ESA:
+        case X264_ME_TESA:
         {
             const int min_x = X264_MAX( bmx - i_me_range, mv_x_min );
             const int min_y = X264_MAX( bmy - i_me_range, mv_y_min );
@@ -560,12 +562,10 @@ me_hex2:
             const int max_y = X264_MIN( bmy + i_me_range, mv_y_max );
             /* SEA is fastest in multiples of 4 */
             const int width = (max_x - min_x + 3) & ~3;
-            int my;
 #if 0
             /* plain old exhaustive search */
-            int mx;
-            for( my = min_y; my <= max_y; my++ )
-                for( mx = min_x; mx <= max_x; mx++ )
+            for( int my = min_y; my <= max_y; my++ )
+                for( int mx = min_x; mx <= max_x; mx++ )
                     COST_MV( mx, my );
 #else
             /* successive elimination by comparing DC before a full SAD,
@@ -599,20 +599,21 @@ me_hex2:
                 int sad_thresh = i_me_range <= 16 ? 10 : i_me_range <= 24 ? 11 : 12;
                 int bsad = h->pixf.sad[i_pixel]( p_fenc, FENC_STRIDE, p_fref_w+bmy*stride+bmx, stride )
                          + BITS_MVD( bmx, bmy );
-                for( my = min_y; my <= max_y; my++ )
+                for( int my = min_y; my <= max_y; my++ )
                 {
+                    int i;
                     int ycost = p_cost_mvy[my<<2];
                     if( bsad <= ycost )
                         continue;
                     bsad -= ycost;
                     xn = h->pixf.ads[i_pixel]( enc_dc, sums_base + min_x + my * stride, delta,
                                                cost_fpel_mvx+min_x, xs, width, bsad*17/16 );
-                    for( i=0; i<xn-2; i+=3 )
+                    for( i = 0; i < xn-2; i += 3 )
                     {
                         uint8_t *ref = p_fref_w+min_x+my*stride;
                         int sads[3];
                         h->pixf.sad_x3[i_pixel]( p_fenc, ref+xs[i], ref+xs[i+1], ref+xs[i+2], stride, sads );
-                        for( j=0; j<3; j++ )
+                        for( int j = 0; j < 3; j++ )
                         {
                             int sad = sads[j] + cost_fpel_mvx[xs[i+j]];
                             if( sad < bsad*sad_thresh>>3 )
@@ -625,7 +626,7 @@ me_hex2:
                             }
                         }
                     }
-                    for( ; i<xn; i++ )
+                    for( ; i < xn; i++ )
                     {
                         int mx = min_x+xs[i];
                         int sad = h->pixf.sad[i_pixel]( p_fenc, FENC_STRIDE, p_fref_w+mx+my*stride, stride )
@@ -646,10 +647,11 @@ me_hex2:
                 sad_thresh = bsad*sad_thresh>>3;
                 while( nmvsad > limit*2 && sad_thresh > bsad )
                 {
+                    int i;
                     // halve the range if the domain is too large... eh, close enough
                     sad_thresh = (sad_thresh + bsad) >> 1;
-                    for( i=0; i<nmvsad && mvsads[i].sad <= sad_thresh; i++ );
-                    for( j=i; j<nmvsad; j++ )
+                    for( i = 0; i < nmvsad && mvsads[i].sad <= sad_thresh; i++ );
+                    for( int j = i; j < nmvsad; j++ )
                     {
                         uint32_t sad;
                         if( WORD_SIZE == 8 && sizeof(mvsad_t) == 8 )
@@ -673,7 +675,7 @@ me_hex2:
                 while( nmvsad > limit )
                 {
                     int bi = 0;
-                    for( i=1; i<nmvsad; i++ )
+                    for( int i = 1; i < nmvsad; i++ )
                         if( mvsads[i].sad > mvsads[bi].sad )
                             bi = i;
                     nmvsad--;
@@ -682,24 +684,25 @@ me_hex2:
                     else
                         mvsads[bi] = mvsads[nmvsad];
                 }
-                for( i=0; i<nmvsad; i++ )
+                for( int i = 0; i < nmvsad; i++ )
                     COST_MV( mvsads[i].mv[0], mvsads[i].mv[1] );
             }
             else
             {
                 // just ADS and SAD
-                for( my = min_y; my <= max_y; my++ )
+                for( int my = min_y; my <= max_y; my++ )
                 {
+                    int i;
                     int ycost = p_cost_mvy[my<<2];
                     if( bcost <= ycost )
                         continue;
                     bcost -= ycost;
                     xn = h->pixf.ads[i_pixel]( enc_dc, sums_base + min_x + my * stride, delta,
                                                cost_fpel_mvx+min_x, xs, width, bcost );
-                    for( i=0; i<xn-2; i+=3 )
+                    for( i = 0; i < xn-2; i += 3 )
                         COST_MV_X3_ABS( min_x+xs[i],my, min_x+xs[i+1],my, min_x+xs[i+2],my );
                     bcost += ycost;
-                    for( ; i<xn; i++ )
+                    for( ; i < xn; i++ )
                         COST_MV( min_x+xs[i], my );
                 }
             }
@@ -805,8 +808,6 @@ static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_ite
     const int mvy_offset = h->mb.b_interlaced & m->i_ref ? (h->mb.i_mb_y & 1)*4 - 2 : 0;
 
     ALIGNED_ARRAY_16( uint8_t, pix,[2],[32*18] );   // really 17x17, but round up for alignment
-    int omx, omy;
-    int i;
 
     int bmx = m->mv[0];
     int bmy = m->mv[1];
@@ -823,7 +824,7 @@ static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_ite
     }
 
     /* halfpel diamond search */
-    for( i = hpel_iters; i > 0; i-- )
+    for( int i = hpel_iters; i > 0; i-- )
     {
         int omx = bmx, omy = bmy;
         int costs[4];
@@ -865,13 +866,12 @@ static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_ite
 
     /* quarterpel diamond search */
     bdir = -1;
-    for( i = qpel_iters; i > 0; i-- )
+    for( int i = qpel_iters; i > 0; i-- )
     {
         if( bmy <= h->mb.mv_min_spel[1] || bmy >= h->mb.mv_max_spel[1] || bmx <= h->mb.mv_min_spel[0] || bmx >= h->mb.mv_max_spel[0] )
             break;
         odir = bdir;
-        omx = bmx;
-        omy = bmy;
+        int omx = bmx, omy = bmy;
         COST_MV_SATD( omx, omy - 1, 0 );
         COST_MV_SATD( omx, omy + 1, 1 );
         COST_MV_SATD( omx - 1, omy, 2 );
@@ -931,8 +931,6 @@ static void ALWAYS_INLINE x264_me_refine_bidir( x264_t *h, x264_me_t *m0, x264_m
     int bm1x = m1->mv[0];
     int bm1y = m1->mv[1];
     int bcost = COST_MAX;
-    int pass = 0;
-    int j;
     int mc_list0 = 1, mc_list1 = 1;
     uint64_t bcostrd = COST_MAX64;
     uint16_t amvd;
@@ -971,7 +969,7 @@ static void ALWAYS_INLINE x264_me_refine_bidir( x264_t *h, x264_me_t *m0, x264_m
 
     h->mc.memzero_aligned( visited, sizeof(uint8_t[8][8][8]) );
 
-    for( pass = 0; pass < 8; pass++ )
+    for( int pass = 0; pass < 8; pass++ )
     {
         int bestj = 0;
         /* check all mv pairs that differ in at most 2 components from the current mvs. */
@@ -979,14 +977,14 @@ static void ALWAYS_INLINE x264_me_refine_bidir( x264_t *h, x264_me_t *m0, x264_m
          * from bidir ME are the same with and without chroma ME. */
 
         if( mc_list0 )
-            for( j = x264_iter_kludge; j < 9; j++ )
+            for( int j = x264_iter_kludge; j < 9; j++ )
                 BIME_CACHE( square1[j][0], square1[j][1], 0 );
 
         if( mc_list1 )
-            for( j = x264_iter_kludge; j < 9; j++ )
+            for( int j = x264_iter_kludge; j < 9; j++ )
                 BIME_CACHE( square1[j][0], square1[j][1], 1 );
 
-        for( j = !!pass; j < 33; j++ )
+        for( int j = !!pass; j < 33; j++ )
         {
             int m0x = dia4d[j][0] + bm0x;
             int m0y = dia4d[j][1] + bm0y;
@@ -1103,7 +1101,7 @@ void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int
     uint64_t bcost = COST_MAX64;
     int bmx = m->mv[0];
     int bmy = m->mv[1];
-    int omx, omy, pmx, pmy, i, j;
+    int omx, omy, pmx, pmy;
     unsigned bsatd;
     int satd;
     int dir = -2;
@@ -1155,7 +1153,7 @@ void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int
     dir = -2;
     omx = bmx;
     omy = bmy;
-    for( j=0; j<6; j++ )
+    for( int j = 0; j < 6; j++ )
     {
         COST_MV_SATD( omx + hex2[j+1][0], omy + hex2[j+1][1], satd, 1 );
         COST_MV_RD  ( omx + hex2[j+1][0], omy + hex2[j+1][1], satd, 1, j );
@@ -1164,7 +1162,7 @@ void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int
     if( dir != -2 )
     {
         /* half hexagon, not overlapping the previous iteration */
-        for( i = 1; i < 10; i++ )
+        for( int i = 1; i < 10; i++ )
         {
             const int odir = mod6m1[dir+1];
             if( bmy < h->mb.mv_min_spel[1] + 3 ||
@@ -1173,7 +1171,7 @@ void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int
             dir = -2;
             omx = bmx;
             omy = bmy;
-            for( j=0; j<3; j++ )
+            for( int j = 0; j < 3; j++ )
             {
                 COST_MV_SATD( omx + hex2[odir+j][0], omy + hex2[odir+j][1], satd, 1 );
                 COST_MV_RD  ( omx + hex2[odir+j][0], omy + hex2[odir+j][1], satd, 1, odir-1+j );
@@ -1186,7 +1184,7 @@ void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int
     /* square refine, same pattern as ME HEX. */
     omx = bmx;
     omy = bmy;
-    for( i=0; i<8; i++ )
+    for( int i = 0; i < 8; i++ )
     {
         COST_MV_SATD( omx + square1[i+1][0], omy + square1[i+1][1], satd, 1 );
         COST_MV_RD  ( omx + square1[i+1][0], omy + square1[i+1][1], satd, 0, 0 );
index 1ccceb51fc392ffdc9e8fa702c83c356dc903a1e..5074980f746f90d7e242568651d90f1178cadaf9 100644 (file)
@@ -1,4 +1,4 @@
-/***************************************************-*- coding: iso-8859-1 -*-
+/*****************************************************************************
  * ratecontrol.c: h264 encoder library (Rate Control)
  *****************************************************************************
  * Copyright (C) 2005-2008 x264 project
@@ -182,22 +182,22 @@ static void update_predictor( predictor_t *p, double q, double var, double bits
  * qp = h.264's quantizer
  * qscale = linearized quantizer = Lagrange multiplier
  */
-static inline double qp2qscale(double qp)
+static inline double qp2qscale( double qp )
 {
-    return 0.85 * pow(2.0, ( qp - 12.0 ) / 6.0);
+    return 0.85 * pow( 2.0, ( qp - 12.0 ) / 6.0 );
 }
-static inline double qscale2qp(double qscale)
+static inline double qscale2qp( double qscale )
 {
-    return 12.0 + 6.0 * log(qscale/0.85) / log(2.0);
+    return 12.0 + 6.0 * log2( qscale/0.85 );
 }
 
 /* Texture bitrate is not quite inversely proportional to qscale,
  * probably due the the changing number of SKIP blocks.
  * MV bits level off at about qp<=12, because the lambda used
  * for motion estimation is constant there. */
-static inline double qscale2bits(ratecontrol_entry_t *rce, double qscale)
+static inline double qscale2bits( ratecontrol_entry_t *rce, double qscale )
 {
-    if(qscale<0.1)
+    if( qscale<0.1 )
         qscale = 0.1;
     return (rce->tex_bits + .1) * pow( rce->qscale / qscale, 1.1 )
            + rce->mv_bits * pow( X264_MAX(rce->qscale, 1) / X264_MAX(qscale, 1), 0.5 )
@@ -238,17 +238,15 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame )
 {
     /* constants chosen to result in approximately the same overall bitrate as without AQ.
      * FIXME: while they're written in 5 significant digits, they're only tuned to 2. */
-    int mb_x, mb_y;
     float strength;
     float avg_adj = 0.f;
     /* Need to init it anyways for MB tree. */
     if( h->param.rc.f_aq_strength == 0 )
     {
-        int mb_xy;
         memset( frame->f_qp_offset, 0, h->mb.i_mb_count * sizeof(float) );
         memset( frame->f_qp_offset_aq, 0, h->mb.i_mb_count * sizeof(float) );
         if( h->frames.b_have_lowres )
-            for( mb_xy = 0; mb_xy < h->mb.i_mb_count; mb_xy++ )
+            for( int mb_xy = 0; mb_xy < h->mb.i_mb_count; mb_xy++ )
                 frame->i_inv_qscale_factor[mb_xy] = 256;
         return;
     }
@@ -256,8 +254,8 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame )
     if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE )
     {
         float avg_adj_pow2 = 0.f;
-        for( mb_y = 0; mb_y < h->sps->i_mb_height; mb_y++ )
-            for( mb_x = 0; mb_x < h->sps->i_mb_width; mb_x++ )
+        for( int mb_y = 0; mb_y < h->sps->i_mb_height; mb_y++ )
+            for( int mb_x = 0; mb_x < h->sps->i_mb_width; mb_x++ )
             {
                 uint32_t energy = ac_energy_mb( h, mb_x, mb_y, frame );
                 float qp_adj = powf( energy + 1, 0.125f );
@@ -273,8 +271,8 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame )
     else
         strength = h->param.rc.f_aq_strength * 1.0397f;
 
-    for( mb_y = 0; mb_y < h->sps->i_mb_height; mb_y++ )
-        for( mb_x = 0; mb_x < h->sps->i_mb_width; mb_x++ )
+    for( int mb_y = 0; mb_y < h->sps->i_mb_height; mb_y++ )
+        for( int mb_x = 0; mb_x < h->sps->i_mb_width; mb_x++ )
         {
             float qp_adj;
             if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE )
@@ -314,7 +312,6 @@ int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame )
 {
     x264_ratecontrol_t *rc = h->rc;
     uint8_t i_type_actual = rc->entry[frame->i_frame].pict_type;
-    int i;
 
     if( rc->entry[frame->i_frame].kept_as_ref )
     {
@@ -338,7 +335,7 @@ int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame )
             } while( i_type != i_type_actual );
         }
 
-        for( i = 0; i < h->mb.i_mb_count; i++ )
+        for( int i = 0; i < h->mb.i_mb_count; i++ )
         {
             frame->f_qp_offset[i] = ((float)(int16_t)endian_fix16( rc->qp_buffer[rc->qpbuf_pos][i] )) * (1/256.0);
             if( h->frames.b_have_lowres )
@@ -360,7 +357,6 @@ int x264_reference_build_list_optimal( x264_t *h )
     x264_frame_t *frames[16];
     x264_weight_t weights[16][3];
     int refcount[16];
-    int ref, i;
 
     if( rce->refs != h->i_ref0 )
         return -1;
@@ -372,12 +368,12 @@ int x264_reference_build_list_optimal( x264_t *h )
 
     /* For now don't reorder ref 0; it seems to lower quality
        in most cases due to skips. */
-    for( ref = 1; ref < h->i_ref0; ref++ )
+    for( int ref = 1; ref < h->i_ref0; ref++ )
     {
         int max = -1;
         int bestref = 1;
 
-        for( i = 1; i < h->i_ref0; i++ )
+        for( int i = 1; i < h->i_ref0; i++ )
             if( !frames[i]->b_duplicate || frames[i]->i_frame != h->fref0[ref-1]->i_frame )
                 /* Favor lower POC as a tiebreaker. */
                 COPY2_IF_GT( max, refcount[i], bestref, i );
@@ -514,7 +510,6 @@ void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init )
 int x264_ratecontrol_new( x264_t *h )
 {
     x264_ratecontrol_t *rc;
-    int i, j;
 
     x264_emms();
 
@@ -525,7 +520,7 @@ int x264_ratecontrol_new( x264_t *h )
     rc->b_2pass = h->param.rc.i_rc_method == X264_RC_ABR && h->param.rc.b_stat_read;
 
     /* FIXME: use integers */
-    if(h->param.i_fps_num > 0 && h->param.i_fps_den > 0)
+    if( h->param.i_fps_num > 0 && h->param.i_fps_den > 0 )
         rc->fps = (float) h->param.i_fps_num / h->param.i_fps_den;
     else
         rc->fps = 25.0;
@@ -572,31 +567,31 @@ int x264_ratecontrol_new( x264_t *h )
         rc->last_non_b_pict_type = SLICE_TYPE_I;
     }
 
-    rc->ip_offset = 6.0 * log(h->param.rc.f_ip_factor) / log(2.0);
-    rc->pb_offset = 6.0 * log(h->param.rc.f_pb_factor) / log(2.0);
+    rc->ip_offset = 6.0 * log2f( h->param.rc.f_ip_factor );
+    rc->pb_offset = 6.0 * log2f( h->param.rc.f_pb_factor );
     rc->qp_constant[SLICE_TYPE_P] = h->param.rc.i_qp_constant;
     rc->qp_constant[SLICE_TYPE_I] = x264_clip3( h->param.rc.i_qp_constant - rc->ip_offset + 0.5, 0, 51 );
     rc->qp_constant[SLICE_TYPE_B] = x264_clip3( h->param.rc.i_qp_constant + rc->pb_offset + 0.5, 0, 51 );
     h->mb.ip_offset = rc->ip_offset + 0.5;
 
     rc->lstep = pow( 2, h->param.rc.i_qp_step / 6.0 );
-    rc->last_qscale = qp2qscale(26);
+    rc->last_qscale = qp2qscale( 26 );
     int num_preds = h->param.b_sliced_threads * h->param.i_threads + 1;
     CHECKED_MALLOC( rc->pred, 5 * sizeof(predictor_t) * num_preds );
     CHECKED_MALLOC( rc->pred_b_from_p, sizeof(predictor_t) );
-    for( i = 0; i < 5; i++ )
+    for( int i = 0; i < 5; i++ )
     {
         rc->last_qscale_for[i] = qp2qscale( ABR_INIT_QP );
         rc->lmin[i] = qp2qscale( h->param.rc.i_qp_min );
         rc->lmax[i] = qp2qscale( h->param.rc.i_qp_max );
-        for( j = 0; j < num_preds; j++ )
+        for( int j = 0; j < num_preds; j++ )
         {
             rc->pred[i+j*5].coeff= 2.0;
             rc->pred[i+j*5].count= 1.0;
             rc->pred[i+j*5].decay= 0.5;
             rc->pred[i+j*5].offset= 0.0;
         }
-        for( j = 0; j < 2; j++ )
+        for( int j = 0; j < 2; j++ )
         {
             rc->row_preds[i][j].coeff= .25;
             rc->row_preds[i][j].count= 1.0;
@@ -702,14 +697,15 @@ int x264_ratecontrol_new( x264_t *h )
 
         /* find number of pics */
         p = stats_in;
-        for(i=-1; p; i++)
-            p = strchr(p+1, ';');
-        if(i==0)
+        int num_entries;
+        for( num_entries = -1; p; num_entries++ )
+            p = strchr( p + 1, ';' );
+        if( !num_entries )
         {
             x264_log(h, X264_LOG_ERROR, "empty stats file\n");
             return -1;
         }
-        rc->num_entries = i;
+        rc->num_entries = num_entries;
 
         if( h->param.i_frame_total < rc->num_entries && h->param.i_frame_total > 0 )
         {
@@ -726,18 +722,18 @@ int x264_ratecontrol_new( x264_t *h )
         CHECKED_MALLOCZERO( rc->entry, rc->num_entries * sizeof(ratecontrol_entry_t) );
 
         /* init all to skipped p frames */
-        for(i=0; i<rc->num_entries; i++)
+        for( int i = 0; i < rc->num_entries; i++ )
         {
             ratecontrol_entry_t *rce = &rc->entry[i];
             rce->pict_type = SLICE_TYPE_P;
-            rce->qscale = rce->new_qscale = qp2qscale(20);
+            rce->qscale = rce->new_qscale = qp2qscale( 20 );
             rce->misc_bits = rc->nmb + 10;
             rce->new_qp = 0;
         }
 
         /* read stats */
         p = stats_in;
-        for(i=0; i < rc->num_entries; i++)
+        for( int i = 0; i < rc->num_entries; i++ )
         {
             ratecontrol_entry_t *rce;
             int frame_number;
@@ -748,25 +744,22 @@ int x264_ratecontrol_new( x264_t *h )
             int ref;
 
             next= strchr(p, ';');
-            if(next)
-            {
-                (*next)=0; //sscanf is unbelievably slow on long strings
-                next++;
-            }
-            e = sscanf(p, " in:%d ", &frame_number);
+            if( next )
+                *next++ = 0; //sscanf is unbelievably slow on long strings
+            e = sscanf( p, " in:%d ", &frame_number );
 
-            if(frame_number < 0 || frame_number >= rc->num_entries)
+            if( frame_number < 0 || frame_number >= rc->num_entries )
             {
-                x264_log(h, X264_LOG_ERROR, "bad frame number (%d) at stats line %d\n", frame_number, i);
+                x264_log( h, X264_LOG_ERROR, "bad frame number (%d) at stats line %d\n", frame_number, i );
                 return -1;
             }
             rce = &rc->entry[frame_number];
             rce->direct_mode = 0;
 
-            e += sscanf(p, " in:%*d out:%*d type:%c dur:%d cpbdur:%d q:%f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d d:%c",
+            e += sscanf( p, " in:%*d out:%*d type:%c dur:%d cpbdur:%d q:%f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d d:%c",
                    &pict_type, &rce->i_duration, &rce->i_cpb_duration, &qp, &rce->tex_bits,
                    &rce->mv_bits, &rce->misc_bits, &rce->i_count, &rce->p_count,
-                   &rce->s_count, &rce->direct_mode);
+                   &rce->s_count, &rce->direct_mode );
 
             p = strstr( p, "ref:" );
             if( !p )
@@ -815,21 +808,22 @@ int x264_ratecontrol_new( x264_t *h )
                     break;
                 default:  e = -1; break;
             }
-            if(e < 12)
+            if( e < 12 )
             {
 parse_error:
-                x264_log(h, X264_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e);
+                x264_log( h, X264_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e );
                 return -1;
             }
-            rce->qscale = qp2qscale(qp);
+            rce->qscale = qp2qscale( qp );
             p = next;
         }
 
-        x264_free(stats_buf);
+        x264_free( stats_buf );
 
-        if(h->param.rc.i_rc_method == X264_RC_ABR)
+        if( h->param.rc.i_rc_method == X264_RC_ABR )
         {
-            if(init_pass2(h) < 0) return -1;
+            if( init_pass2( h ) < 0 )
+                return -1;
         } /* else we're using constant quant, so no need to run the bitrate allocation */
     }
 
@@ -878,7 +872,7 @@ parse_error:
         rc->qpbuf_pos = -1;
     }
 
-    for( i=0; i<h->param.i_threads; i++ )
+    for( int i = 0; i<h->param.i_threads; i++ )
     {
         h->thread[i]->rc = rc+i;
         if( i )
@@ -940,7 +934,6 @@ fail:
 static int parse_zones( x264_t *h )
 {
     x264_ratecontrol_t *rc = h->rc;
-    int i;
     if( h->param.rc.psz_zones && !h->param.rc.i_zones )
     {
         char *psz_zones, *p;
@@ -951,7 +944,7 @@ static int parse_zones( x264_t *h )
             h->param.rc.i_zones += (*p == '/');
         CHECKED_MALLOC( h->param.rc.zones, h->param.rc.i_zones * sizeof(x264_zone_t) );
         p = psz_zones;
-        for( i = 0; i < h->param.rc.i_zones; i++ )
+        for( int i = 0; i < h->param.rc.i_zones; i++ )
         {
             int i_tok = strcspn( p, "/" );
             p[i_tok] = 0;
@@ -964,7 +957,7 @@ static int parse_zones( x264_t *h )
 
     if( h->param.rc.i_zones > 0 )
     {
-        for( i = 0; i < h->param.rc.i_zones; i++ )
+        for( int i = 0; i < h->param.rc.i_zones; i++ )
         {
             x264_zone_t z = h->param.rc.zones[i];
             if( z.i_start < 0 || z.i_start > z.i_end )
@@ -992,7 +985,7 @@ static int parse_zones( x264_t *h )
         rc->zones[0].f_bitrate_factor = 1;
         CHECKED_MALLOC( rc->zones[0].param, sizeof(x264_param_t) );
         memcpy( rc->zones[0].param, &h->param, sizeof(x264_param_t) );
-        for( i = 1; i < rc->i_zones; i++ )
+        for( int i = 1; i < rc->i_zones; i++ )
         {
             if( !rc->zones[i].param )
                 rc->zones[i].param = rc->zones[0].param;
@@ -1006,8 +999,7 @@ fail:
 
 static x264_zone_t *get_zone( x264_t *h, int frame_num )
 {
-    int i;
-    for( i = h->rc->i_zones-1; i >= 0; i-- )
+    for( int i = h->rc->i_zones - 1; i >= 0; i-- )
     {
         x264_zone_t *z = &h->rc->zones[i];
         if( frame_num >= z->i_start && frame_num <= z->i_end )
@@ -1032,7 +1024,6 @@ void x264_ratecontrol_summary( x264_t *h )
 void x264_ratecontrol_delete( x264_t *h )
 {
     x264_ratecontrol_t *rc = h->rc;
-    int i;
     int b_regular_file;
 
     if( rc->p_stat_file_out )
@@ -1070,7 +1061,7 @@ void x264_ratecontrol_delete( x264_t *h )
     if( rc->zones )
     {
         x264_free( rc->zones[0].param );
-        for( i=1; i<rc->i_zones; i++ )
+        for( int i = 1; i < rc->i_zones; i++ )
             if( rc->zones[i].param != rc->zones[0].param && rc->zones[i].param->param_free )
                 rc->zones[i].param->param_free( rc->zones[i].param );
         x264_free( rc->zones );
@@ -1180,7 +1171,7 @@ void x264_ratecontrol_start( x264_t *h, int i_force_qp, int overhead )
             if( zone->b_force_qp )
                 q += zone->i_qp - rc->qp_constant[SLICE_TYPE_P];
             else
-                q -= 6*log(zone->f_bitrate_factor)/log(2);
+                q -= 6*log2f( zone->f_bitrate_factor );
         }
     }
 
@@ -1207,7 +1198,7 @@ static double predict_row_size( x264_t *h, int y, int qp )
     /* average between two predictors:
      * absolute SATD, and scaled bit cost of the colocated row in the previous frame */
     x264_ratecontrol_t *rc = h->rc;
-    double pred_s = predict_size( rc->row_pred[0], qp2qscale(qp), h->fdec->i_row_satd[y] );
+    double pred_s = predict_size( rc->row_pred[0], qp2qscale( qp ), h->fdec->i_row_satd[y] );
     double pred_t = 0;
     if( h->sh.i_type == SLICE_TYPE_I || qp >= h->fref0[0]->i_row_qp[y] )
     {
@@ -1217,7 +1208,7 @@ static double predict_row_size( x264_t *h, int y, int qp )
             && (abs(h->fref0[0]->i_row_satd[y] - h->fdec->i_row_satd[y]) < h->fdec->i_row_satd[y]/2))
         {
             pred_t = h->fref0[0]->i_row_bits[y] * h->fdec->i_row_satd[y] / h->fref0[0]->i_row_satd[y]
-                     * qp2qscale(h->fref0[0]->i_row_qp[y]) / qp2qscale(qp);
+                     * qp2qscale( h->fref0[0]->i_row_qp[y] ) / qp2qscale( qp );
         }
         if( pred_t == 0 )
             pred_t = pred_s;
@@ -1226,7 +1217,7 @@ static double predict_row_size( x264_t *h, int y, int qp )
     /* Our QP is lower than the reference! */
     else
     {
-        double pred_intra = predict_size( rc->row_pred[1], qp2qscale(qp), h->fdec->i_row_satds[0][0][y] );
+        double pred_intra = predict_size( rc->row_pred[1], qp2qscale( qp ), h->fdec->i_row_satds[0][0][y] );
         /* Sum: better to overestimate than underestimate by using only one of the two predictors. */
         return pred_intra + pred_s;
     }
@@ -1234,18 +1225,16 @@ static double predict_row_size( x264_t *h, int y, int qp )
 
 static double row_bits_so_far( x264_t *h, int y )
 {
-    int i;
     double bits = 0;
-    for( i = h->i_threadslice_start; i <= y; i++ )
+    for( int i = h->i_threadslice_start; i <= y; i++ )
         bits += h->fdec->i_row_bits[i];
     return bits;
 }
 
 static double predict_row_size_sum( x264_t *h, int y, int qp )
 {
-    int i;
     double bits = row_bits_so_far(h, y);
-    for( i = y+1; i < h->i_threadslice_end; i++ )
+    for( int i = y+1; i < h->i_threadslice_end; i++ )
         bits += predict_row_size( h, i, qp );
     return bits;
 }
@@ -1267,14 +1256,13 @@ void x264_ratecontrol_mb( x264_t *h, int bits )
 
     h->fdec->i_row_qp[y] = rc->qpm;
 
-    update_predictor( rc->row_pred[0], qp2qscale(rc->qpm), h->fdec->i_row_satd[y], h->fdec->i_row_bits[y] );
+    update_predictor( rc->row_pred[0], qp2qscale( rc->qpm ), h->fdec->i_row_satd[y], h->fdec->i_row_bits[y] );
     if( h->sh.i_type == SLICE_TYPE_P && rc->qpm < h->fref0[0]->i_row_qp[y] )
-        update_predictor( rc->row_pred[1], qp2qscale(rc->qpm), h->fdec->i_row_satds[0][0][y], h->fdec->i_row_bits[y] );
+        update_predictor( rc->row_pred[1], qp2qscale( rc->qpm ), h->fdec->i_row_satds[0][0][y], h->fdec->i_row_bits[y] );
 
     /* tweak quality based on difference from predicted size */
     if( y < h->i_threadslice_end-1 )
     {
-        int i;
         int prev_row_qp = h->fdec->i_row_qp[y];
         int i_qp_min = X264_MAX( prev_row_qp - h->param.rc.i_qp_step, h->param.rc.i_qp_min );
         int i_qp_absolute_max = h->param.rc.i_qp_max;
@@ -1294,7 +1282,7 @@ void x264_ratecontrol_mb( x264_t *h, int bits )
         float size_of_other_slices = 0;
         if( h->param.b_sliced_threads )
         {
-            for( i = 0; i < h->param.i_threads; i++ )
+            for( int i = 0; i < h->param.i_threads; i++ )
                 if( h != h->thread[i] )
                     size_of_other_slices += h->thread[i]->rc->frame_size_estimated;
         }
@@ -1366,8 +1354,6 @@ int x264_ratecontrol_slice_type( x264_t *h, int frame_num )
             /* We could try to initialize everything required for ABR and
              * adaptive B-frames, but that would be complicated.
              * So just calculate the average QP used so far. */
-            int i;
-
             h->param.rc.i_qp_constant = (h->stat.i_frame_count[SLICE_TYPE_P] == 0) ? 24
                                       : 1 + h->stat.f_frame_qp[SLICE_TYPE_P] / h->stat.i_frame_count[SLICE_TYPE_P];
             rc->qp_constant[SLICE_TYPE_P] = x264_clip3( h->param.rc.i_qp_constant, 0, 51 );
@@ -1379,7 +1365,7 @@ int x264_ratecontrol_slice_type( x264_t *h, int frame_num )
             if( h->param.i_bframe_adaptive )
                 x264_log(h, X264_LOG_ERROR, "disabling adaptive B-frames\n");
 
-            for( i = 0; i < h->param.i_threads; i++ )
+            for( int i = 0; i < h->param.i_threads; i++ )
             {
                 h->thread[i]->rc->b_abr = 0;
                 h->thread[i]->rc->b_2pass = 0;
@@ -1413,14 +1399,13 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
 {
     x264_ratecontrol_t *rc = h->rc;
     const int *mbs = h->stat.frame.i_mb_count;
-    int i;
 
     x264_emms();
 
     h->stat.frame.i_mb_count_skip = mbs[P_SKIP] + mbs[B_SKIP];
     h->stat.frame.i_mb_count_i = mbs[I_16x16] + mbs[I_8x8] + mbs[I_4x4];
     h->stat.frame.i_mb_count_p = mbs[P_L0] + mbs[P_8x8];
-    for( i = B_DIRECT; i < B_8x8; i++ )
+    for( int i = B_DIRECT; i < B_8x8; i++ )
         h->stat.frame.i_mb_count_p += mbs[i];
 
     h->fdec->f_qp_avg_rc = rc->qpa_rc /= h->mb.i_mb_count;
@@ -1453,7 +1438,7 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
 
         /* Only write information for reference reordering once. */
         int use_old_stats = h->param.rc.b_stat_read && rc->rce->refs > 1;
-        for( i = 0; i < (use_old_stats ? rc->rce->refs : h->i_ref0); i++ )
+        for( int i = 0; i < (use_old_stats ? rc->rce->refs : h->i_ref0); i++ )
         {
             int refcount = use_old_stats         ? rc->rce->refcount[i]
                          : h->param.b_interlaced ? h->stat.frame.i_mb_count_ref[0][i*2]
@@ -1476,9 +1461,8 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
         if( h->param.rc.b_mb_tree && h->fenc->b_kept_as_ref && !h->param.rc.b_stat_read )
         {
             uint8_t i_type = h->sh.i_type;
-            int i;
             /* Values are stored as big-endian FIX8.8 */
-            for( i = 0; i < h->mb.i_mb_count; i++ )
+            for( int i = 0; i < h->mb.i_mb_count; i++ )
                 rc->qp_buffer[0][i] = endian_fix16( h->fenc->f_qp_offset[i]*256.0 );
             if( fwrite( &i_type, 1, 1, rc->p_mbtree_stat_file_out ) < 1 )
                 goto fail;
@@ -1490,12 +1474,12 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
     if( rc->b_abr )
     {
         if( h->sh.i_type != SLICE_TYPE_B )
-            rc->cplxr_sum += bits * qp2qscale(rc->qpa_rc) / rc->last_rceq;
+            rc->cplxr_sum += bits * qp2qscale( rc->qpa_rc ) / rc->last_rceq;
         else
         {
             /* Depends on the fact that B-frame's QP is an offset from the following P-frame's.
              * Not perfectly accurate with B-refs, but good enough. */
-            rc->cplxr_sum += bits * qp2qscale(rc->qpa_rc) / (rc->last_rceq * fabs(h->param.rc.f_pb_factor));
+            rc->cplxr_sum += bits * qp2qscale( rc->qpa_rc ) / (rc->last_rceq * fabs( h->param.rc.f_pb_factor ));
         }
         rc->cplxr_sum *= rc->cbr_decay;
         double frame_duration = (double)h->fenc->i_duration * h->sps->vui.i_num_units_in_tick / h->sps->vui.i_time_scale;
@@ -1505,9 +1489,7 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
     }
 
     if( rc->b_2pass )
-    {
-        rc->expected_bits_sum += qscale2bits( rc->rce, qp2qscale(rc->rce->new_qp) );
-    }
+        rc->expected_bits_sum += qscale2bits( rc->rce, qp2qscale( rc->rce->new_qp ) );
 
     if( h->mb.b_variable_qp )
     {
@@ -1516,7 +1498,7 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
             rc->bframe_bits += bits;
             if( h->fenc->b_last_minigop_bframe )
             {
-                update_predictor( rc->pred_b_from_p, qp2qscale(rc->qpa_rc),
+                update_predictor( rc->pred_b_from_p, qp2qscale( rc->qpa_rc ),
                                   h->fref1[h->i_ref1-1]->i_satd, rc->bframe_bits / rc->bframes );
                 rc->bframe_bits = 0;
             }
@@ -1578,13 +1560,11 @@ fail:
 static double get_qscale(x264_t *h, ratecontrol_entry_t *rce, double rate_factor, int frame_num)
 {
     x264_ratecontrol_t *rcc= h->rc;
-    double q;
     x264_zone_t *zone = get_zone( h, frame_num );
-
-    q = pow( rce->blurred_complexity, 1 - rcc->qcompress );
+    double q = pow( rce->blurred_complexity, 1 - rcc->qcompress );
 
     // avoid NaN's in the rc_eq
-    if(!isfinite(q) || rce->tex_bits + rce->mv_bits == 0)
+    if( !isfinite(q) || rce->tex_bits + rce->mv_bits == 0 )
         q = rcc->last_qscale_for[rce->pict_type];
     else
     {
@@ -1596,7 +1576,7 @@ static double get_qscale(x264_t *h, ratecontrol_entry_t *rce, double rate_factor
     if( zone )
     {
         if( zone->b_force_qp )
-            q = qp2qscale(zone->i_qp);
+            q = qp2qscale( zone->i_qp );
         else
             q /= zone->f_bitrate_factor;
     }
@@ -1642,30 +1622,30 @@ static double get_diff_limited_q(x264_t *h, ratecontrol_entry_t *rce, double q)
     }
 
     /* last qscale / qdiff stuff */
-    if(rcc->last_non_b_pict_type==pict_type
-       && (pict_type!=SLICE_TYPE_I || rcc->last_accum_p_norm < 1))
+    if( rcc->last_non_b_pict_type == pict_type &&
+        (pict_type!=SLICE_TYPE_I || rcc->last_accum_p_norm < 1) )
     {
         double last_q = rcc->last_qscale_for[pict_type];
         double max_qscale = last_q * rcc->lstep;
         double min_qscale = last_q / rcc->lstep;
 
-        if     (q > max_qscale) q = max_qscale;
-        else if(q < min_qscale) q = min_qscale;
+        if     ( q > max_qscale ) q = max_qscale;
+        else if( q < min_qscale ) q = min_qscale;
     }
 
     rcc->last_qscale_for[pict_type] = q;
-    if(pict_type!=SLICE_TYPE_B)
+    if( pict_type != SLICE_TYPE_B )
         rcc->last_non_b_pict_type = pict_type;
-    if(pict_type==SLICE_TYPE_I)
+    if( pict_type == SLICE_TYPE_I )
     {
         rcc->last_accum_p_norm = rcc->accum_p_norm;
         rcc->accum_p_norm = 0;
         rcc->accum_p_qp = 0;
     }
-    if(pict_type==SLICE_TYPE_P)
+    if( pict_type == SLICE_TYPE_P )
     {
         float mask = 1 - pow( (float)rce->i_count / rcc->nmb, 2 );
-        rcc->accum_p_qp   = mask * (qscale2qp(q) + rcc->accum_p_qp);
+        rcc->accum_p_qp   = mask * (qscale2qp( q ) + rcc->accum_p_qp);
         rcc->accum_p_norm = mask * (1 + rcc->accum_p_norm);
     }
     return q;
@@ -1706,7 +1686,7 @@ static int update_vbv( x264_t *h, int bits )
     x264_ratecontrol_t *rct = h->thread[0]->rc;
 
     if( rcc->last_satd >= h->mb.i_mb_count )
-        update_predictor( &rct->pred[h->sh.i_type], qp2qscale(rcc->qpa_rc), rcc->last_satd, bits );
+        update_predictor( &rct->pred[h->sh.i_type], qp2qscale( rcc->qpa_rc ), rcc->last_satd, bits );
 
     if( !rcc->b_vbv )
         return filler;
@@ -1754,8 +1734,7 @@ static void update_vbv_plan( x264_t *h, int overhead )
     if( h->i_thread_frames > 1 )
     {
         int j = h->rc - h->thread[0]->rc;
-        int i;
-        for( i=1; i<h->i_thread_frames; i++ )
+        for( int i = 1; i < h->i_thread_frames; i++ )
         {
             x264_t *t = h->thread[ (j+i)%h->i_thread_frames ];
             double bits = t->rc->frame_size_planned;
@@ -1792,10 +1771,10 @@ static double clip_qscale( x264_t *h, int pict_type, double q )
          * by the end of the lookahead. */
         if( h->param.rc.i_lookahead )
         {
-            int j, iterations, terminate = 0;
+            int terminate = 0;
 
             /* Avoid an infinite loop. */
-            for( iterations = 0; iterations < 1000 && terminate != 3; iterations++ )
+            for( int iterations = 0; iterations < 1000 && terminate != 3; iterations++ )
             {
                 double frame_q[3];
                 double cur_bits = predict_size( &rcc->pred[h->sh.i_type], q, rcc->last_satd );
@@ -1807,7 +1786,7 @@ static double clip_qscale( x264_t *h, int pict_type, double q )
                 frame_q[2] = frame_q[0] / h->param.rc.f_ip_factor;
 
                 /* Loop over the planned future frames. */
-                for( j = 0; buffer_fill_cur >= 0 && buffer_fill_cur <= rcc->buffer_size; j++ )
+                for( int j = 0; buffer_fill_cur >= 0 && buffer_fill_cur <= rcc->buffer_size; j++ )
                 {
                     total_duration += h->fenc->f_planned_cpb_duration[j];
                     buffer_fill_cur += rcc->vbv_max_rate * h->fenc->f_planned_cpb_duration[j];
@@ -1870,13 +1849,13 @@ static double clip_qscale( x264_t *h, int pict_type, double q )
         double bits = predict_size( &rcc->pred[h->sh.i_type], q, rcc->last_satd );
         if( bits > rcc->frame_size_maximum )
             q *= bits / rcc->frame_size_maximum;
+        bits = predict_size( &rcc->pred[h->sh.i_type], q, rcc->last_satd );
 
         /* Check B-frame complexity, and use up any bits that would
          * overflow before the next P-frame. */
         if( h->sh.i_type == SLICE_TYPE_P && !rcc->single_frame_vbv )
         {
             int nb = rcc->bframes;
-            double bits = predict_size( &rcc->pred[h->sh.i_type], q, rcc->last_satd );
             double pbbits = bits;
             double bbits = predict_size( rcc->pred_b_from_p, q * h->param.rc.f_pb_factor, rcc->last_satd );
             double space;
@@ -1902,19 +1881,19 @@ static double clip_qscale( x264_t *h, int pict_type, double q )
             q = X264_MAX( q0, q );
     }
 
-    if(lmin==lmax)
+    if( lmin==lmax )
         return lmin;
-    else if(rcc->b_2pass)
+    else if( rcc->b_2pass )
     {
-        double min2 = log(lmin);
-        double max2 = log(lmax);
+        double min2 = log( lmin );
+        double max2 = log( lmax );
         q = (log(q) - min2)/(max2-min2) - 0.5;
-        q = 1.0/(1.0 + exp(-4*q));
+        q = 1.0/(1.0 + exp( -4*q ));
         q = q*(max2-min2) + min2;
-        return exp(q);
+        return exp( q );
     }
     else
-        return x264_clip3f(q, lmin, lmax);
+        return x264_clip3f( q, lmin, lmax );
 }
 
 // update qscale for 1 frame based on actual bits used so far
@@ -1924,8 +1903,6 @@ static float rate_estimate_qscale( x264_t *h )
     x264_ratecontrol_t *rcc = h->rc;
     ratecontrol_entry_t rce;
     int pict_type = h->sh.i_type;
-    double lmin = rcc->lmin[pict_type];
-    double lmax = rcc->lmax[pict_type];
     int64_t total_bits = 8*(h->stat.i_frame_size[SLICE_TYPE_I]
                           + h->stat.i_frame_size[SLICE_TYPE_P]
                           + h->stat.i_frame_size[SLICE_TYPE_B]);
@@ -1933,10 +1910,10 @@ static float rate_estimate_qscale( x264_t *h )
     if( rcc->b_2pass )
     {
         rce = *rcc->rce;
-        if(pict_type != rce.pict_type)
+        if( pict_type != rce.pict_type )
         {
-            x264_log(h, X264_LOG_ERROR, "slice=%c but 2pass stats say %c\n",
-                     slice_type_to_char[pict_type], slice_type_to_char[rce.pict_type]);
+            x264_log( h, X264_LOG_ERROR, "slice=%c but 2pass stats say %c\n",
+                      slice_type_to_char[pict_type], slice_type_to_char[rce.pict_type] );
         }
     }
 
@@ -1957,16 +1934,16 @@ static float rate_estimate_qscale( x264_t *h )
         if( h->fref1[0]->i_type == X264_TYPE_BREF )
             q1 -= rcc->pb_offset/2;
 
-        if(i0 && i1)
+        if( i0 && i1 )
             q = (q0 + q1) / 2 + rcc->ip_offset;
-        else if(i0)
+        else if( i0 )
             q = q1;
-        else if(i1)
+        else if( i1 )
             q = q0;
         else
             q = (q0*dt1 + q1*dt0) / (dt0 + dt1);
 
-        if(h->fenc->b_kept_as_ref)
+        if( h->fenc->b_kept_as_ref )
             q += rcc->pb_offset/2;
         else
             q += rcc->pb_offset;
@@ -1981,7 +1958,7 @@ static float rate_estimate_qscale( x264_t *h )
         if( rcc->b_vbv )
             rcc->last_satd = x264_rc_analyse_slice( h );
         rcc->qp_novbv = q;
-        return qp2qscale(q);
+        return qp2qscale( q );
     }
     else
     {
@@ -1989,6 +1966,8 @@ static float rate_estimate_qscale( x264_t *h )
 
         if( rcc->b_2pass )
         {
+            double lmin = rcc->lmin[pict_type];
+            double lmax = rcc->lmax[pict_type];
             int64_t diff;
             int64_t predicted_bits = total_bits;
             /* Adjust ABR buffer based on distance to the end of the video. */
@@ -2000,8 +1979,7 @@ static float rate_estimate_qscale( x264_t *h )
                 if( h->i_thread_frames > 1 )
                 {
                     int j = h->rc - h->thread[0]->rc;
-                    int i;
-                    for( i=1; i<h->i_thread_frames; i++ )
+                    for( int i = 1; i < h->i_thread_frames; i++ )
                     {
                         x264_t *t = h->thread[ (j+i)%h->i_thread_frames ];
                         double bits = t->rc->frame_size_planned;
@@ -2028,20 +2006,20 @@ static float rate_estimate_qscale( x264_t *h )
             {
                 /* Adjust quant based on the difference between
                  * achieved and expected bitrate so far */
-                double time = (double)h->fenc->i_frame / rcc->num_entries;
-                double w = x264_clip3f( time*100, 0.0, 1.0 );
+                double cur_time = (double)h->fenc->i_frame / rcc->num_entries;
+                double w = x264_clip3f( cur_time*100, 0.0, 1.0 );
                 q *= pow( (double)total_bits / rcc->expected_bits_sum, w );
             }
             if( rcc->b_vbv )
             {
                 /* Do not overflow vbv */
-                double expected_size = qscale2bits(&rce, q);
+                double expected_size = qscale2bits( &rce, q );
                 double expected_vbv = rcc->buffer_fill + rcc->buffer_rate - expected_size;
-                double expected_fullness =  rce.expected_vbv / rcc->buffer_size;
+                double expected_fullness = rce.expected_vbv / rcc->buffer_size;
                 double qmax = q*(2 - expected_fullness);
                 double size_constraint = 1 + expected_fullness;
-                qmax = X264_MAX(qmax, rce.new_qscale);
-                if (expected_fullness < .05)
+                qmax = X264_MAX( qmax, rce.new_qscale );
+                if( expected_fullness < .05 )
                     qmax = lmax;
                 qmax = X264_MIN(qmax, lmax);
                 while( ((expected_vbv < rce.expected_vbv/size_constraint) && (q < qmax)) ||
@@ -2067,7 +2045,7 @@ static float rate_estimate_qscale( x264_t *h )
              * tradeoff between quality and bitrate precision. But at large
              * tolerances, the bit distribution approaches that of 2pass. */
 
-            double wanted_bits, overflow=1, lmin, lmax;
+            double wanted_bits, overflow = 1;
 
             rcc->last_satd = x264_rc_analyse_slice( h );
             rcc->short_term_cplxsum *= 0.5;
@@ -2123,8 +2101,8 @@ static float rate_estimate_qscale( x264_t *h )
             {
                 /* Asymmetric clipping, because symmetric would prevent
                  * overflow control in areas of rapidly oscillating complexity */
-                lmin = rcc->last_qscale_for[pict_type] / rcc->lstep;
-                lmax = rcc->last_qscale_for[pict_type] * rcc->lstep;
+                double lmin = rcc->last_qscale_for[pict_type] / rcc->lstep;
+                double lmax = rcc->last_qscale_for[pict_type] * rcc->lstep;
                 if( overflow > 1.1 && h->i_frame > 3 )
                     lmax *= rcc->lstep;
                 else if( overflow < 0.9 )
@@ -2136,7 +2114,7 @@ static float rate_estimate_qscale( x264_t *h )
             {
                 q = qp2qscale( ABR_INIT_QP ) / fabs( h->param.rc.f_ip_factor );
             }
-            rcc->qp_novbv = qscale2qp(q);
+            rcc->qp_novbv = qscale2qp( q );
 
             //FIXME use get_diff_limited_q() ?
             q = clip_qscale( h, pict_type, q );
@@ -2163,29 +2141,28 @@ static float rate_estimate_qscale( x264_t *h )
 
 void x264_threads_normalize_predictors( x264_t *h )
 {
-    int i;
     double totalsize = 0;
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
         totalsize += h->thread[i]->rc->slice_size_planned;
     double factor = h->rc->frame_size_planned / totalsize;
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
         h->thread[i]->rc->slice_size_planned *= factor;
 }
 
 void x264_threads_distribute_ratecontrol( x264_t *h )
 {
-    int i, row;
+    int row;
     x264_ratecontrol_t *rc = h->rc;
 
     /* Initialize row predictors */
     if( h->i_frame == 0 )
-        for( i = 0; i < h->param.i_threads; i++ )
+        for( int i = 0; i < h->param.i_threads; i++ )
         {
             x264_ratecontrol_t *t = h->thread[i]->rc;
             memcpy( t->row_preds, rc->row_preds, sizeof(rc->row_preds) );
         }
 
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
     {
         x264_t *t = h->thread[i];
         memcpy( t->rc, rc, offsetof(x264_ratecontrol_t, row_pred) );
@@ -2208,7 +2185,7 @@ void x264_threads_distribute_ratecontrol( x264_t *h )
         if( rc->single_frame_vbv )
         {
             /* Compensate for our max frame error threshold: give more bits (proportionally) to smaller slices. */
-            for( i = 0; i < h->param.i_threads; i++ )
+            for( int i = 0; i < h->param.i_threads; i++ )
             {
                 x264_t *t = h->thread[i];
                 t->rc->max_frame_error = X264_MAX( 0.05, 1.0 / (t->i_threadslice_end - t->i_threadslice_start) );
@@ -2217,29 +2194,28 @@ void x264_threads_distribute_ratecontrol( x264_t *h )
             x264_threads_normalize_predictors( h );
         }
 
-        for( i = 0; i < h->param.i_threads; i++ )
+        for( int i = 0; i < h->param.i_threads; i++ )
             h->thread[i]->rc->frame_size_estimated = h->thread[i]->rc->slice_size_planned;
     }
 }
 
 void x264_threads_merge_ratecontrol( x264_t *h )
 {
-    int i, row;
     x264_ratecontrol_t *rc = h->rc;
     x264_emms();
 
-    for( i = 0; i < h->param.i_threads; i++ )
+    for( int i = 0; i < h->param.i_threads; i++ )
     {
         x264_t *t = h->thread[i];
         x264_ratecontrol_t *rct = h->thread[i]->rc;
         if( h->param.rc.i_vbv_buffer_size )
         {
             int size = 0;
-            for( row = t->i_threadslice_start; row < t->i_threadslice_end; row++ )
+            for( int row = t->i_threadslice_start; row < t->i_threadslice_end; row++ )
                 size += h->fdec->i_row_satd[row];
             int bits = t->stat.frame.i_mv_bits + t->stat.frame.i_tex_bits + t->stat.frame.i_misc_bits;
             int mb_count = (t->i_threadslice_end - t->i_threadslice_start) * h->sps->i_mb_width;
-            update_predictor( &rc->pred[h->sh.i_type+5*i], qp2qscale(rct->qpa_rc/mb_count), size, bits );
+            update_predictor( &rc->pred[h->sh.i_type+5*i], qp2qscale( rct->qpa_rc/mb_count ), size, bits );
         }
         if( !i )
             continue;
@@ -2306,41 +2282,40 @@ static int find_underflow( x264_t *h, double *fills, int *t0, int *t1, int over
     const double buffer_max = .9 * rcc->buffer_size;
     double fill = fills[*t0-1];
     double parity = over ? 1. : -1.;
-    int i, start=-1, end=-1;
-    for(i = *t0; i < rcc->num_entries; i++)
+    int start = -1, end = -1;
+    for( int i = *t0; i < rcc->num_entries; i++ )
     {
         fill += (rcc->entry[i].i_cpb_duration * rcc->vbv_max_rate * h->sps->vui.i_num_units_in_tick / h->sps->vui.i_time_scale -
-                 qscale2bits(&rcc->entry[i], rcc->entry[i].new_qscale)) * parity;
+                 qscale2bits( &rcc->entry[i], rcc->entry[i].new_qscale )) * parity;
         fill = x264_clip3f(fill, 0, rcc->buffer_size);
         fills[i] = fill;
-        if(fill <= buffer_min || i == 0)
+        if( fill <= buffer_min || i == 0 )
         {
-            if(end >= 0)
+            if( end >= 0 )
                 break;
             start = i;
         }
-        else if(fill >= buffer_max && start >= 0)
+        else if( fill >= buffer_max && start >= 0 )
             end = i;
     }
     *t0 = start;
     *t1 = end;
-    return start>=0 && end>=0;
+    return start >= 0 && end >= 0;
 }
 
 static int fix_underflow( x264_t *h, int t0, int t1, double adjustment, double qscale_min, double qscale_max)
 {
     x264_ratecontrol_t *rcc = h->rc;
     double qscale_orig, qscale_new;
-    int i;
     int adjusted = 0;
-    if(t0 > 0)
+    if( t0 > 0 )
         t0++;
-    for(i = t0; i <= t1; i++)
+    for( int i = t0; i <= t1; i++ )
     {
         qscale_orig = rcc->entry[i].new_qscale;
-        qscale_orig = x264_clip3f(qscale_orig, qscale_min, qscale_max);
+        qscale_orig = x264_clip3f( qscale_orig, qscale_min, qscale_max );
         qscale_new  = qscale_orig * adjustment;
-        qscale_new  = x264_clip3f(qscale_new, qscale_min, qscale_max);
+        qscale_new  = x264_clip3f( qscale_new, qscale_min, qscale_max );
         rcc->entry[i].new_qscale = qscale_new;
         adjusted = adjusted || (qscale_new != qscale_orig);
     }
@@ -2351,12 +2326,11 @@ static double count_expected_bits( x264_t *h )
 {
     x264_ratecontrol_t *rcc = h->rc;
     double expected_bits = 0;
-    int i;
-    for(i = 0; i < rcc->num_entries; i++)
+    for( int i = 0; i < rcc->num_entries; i++ )
     {
         ratecontrol_entry_t *rce = &rcc->entry[i];
         rce->expected_bits = expected_bits;
-        expected_bits += qscale2bits(rce, rce->new_qscale);
+        expected_bits += qscale2bits( rce, rce->new_qscale );
     }
     return expected_bits;
 }
@@ -2373,9 +2347,9 @@ static int vbv_pass2( x264_t *h, double all_available_bits )
     double expected_bits = 0;
     double adjustment;
     double prev_bits = 0;
-    int i, t0, t1;
-    double qscale_min = qp2qscale(h->param.rc.i_qp_min);
-    double qscale_max = qp2qscale(h->param.rc.i_qp_max);
+    int t0, t1;
+    double qscale_min = qp2qscale( h->param.rc.i_qp_min );
+    double qscale_max = qp2qscale( h->param.rc.i_qp_max );
     int iterations = 0;
     int adj_min, adj_max;
     CHECKED_MALLOC( fills, (rcc->num_entries+1)*sizeof(double) );
@@ -2388,16 +2362,16 @@ static int vbv_pass2( x264_t *h, double all_available_bits )
         iterations++;
         prev_bits = expected_bits;
 
-        if(expected_bits != 0)
+        if( expected_bits )
         {   /* not first iteration */
             adjustment = X264_MAX(X264_MIN(expected_bits / all_available_bits, 0.999), 0.9);
             fills[-1] = rcc->buffer_size * h->param.rc.f_vbv_buffer_init;
             t0 = 0;
             /* fix overflows */
             adj_min = 1;
-            while(adj_min && find_underflow(h, fills, &t0, &t1, 1))
+            while(adj_min && find_underflow( h, fills, &t0, &t1, 1 ))
             {
-                adj_min = fix_underflow(h, t0, t1, adjustment, qscale_min, qscale_max);
+                adj_min = fix_underflow( h, t0, t1, adjustment, qscale_min, qscale_max );
                 t0 = t1;
             }
         }
@@ -2406,20 +2380,20 @@ static int vbv_pass2( x264_t *h, double all_available_bits )
         t0 = 0;
         /* fix underflows -- should be done after overflow, as we'd better undersize target than underflowing VBV */
         adj_max = 1;
-        while(adj_max && find_underflow(h, fills, &t0, &t1, 0))
-            adj_max = fix_underflow(h, t0, t1, 1.001, qscale_min, qscale_max);
+        while( adj_max && find_underflow( h, fills, &t0, &t1, 0 ) )
+            adj_max = fix_underflow( h, t0, t1, 1.001, qscale_min, qscale_max );
 
-        expected_bits = count_expected_bits(h);
-    } while((expected_bits < .995*all_available_bits) && ((int64_t)(expected_bits+.5) > (int64_t)(prev_bits+.5)) );
+        expected_bits = count_expected_bits( h );
+    } while( (expected_bits < .995*all_available_bits) && ((int64_t)(expected_bits+.5) > (int64_t)(prev_bits+.5)) );
 
-    if (!adj_max)
+    if( !adj_max )
         x264_log( h, X264_LOG_WARNING, "vbv-maxrate issue, qpmax or vbv-maxrate too low\n");
 
     /* store expected vbv filling values for tracking when encoding */
-    for(i = 0; i < rcc->num_entries; i++)
+    for( int i = 0; i < rcc->num_entries; i++ )
         rcc->entry[i].expected_vbv = rcc->buffer_size - fills[i];
 
-    x264_free(fills-1);
+    x264_free( fills-1 );
     return 0;
 fail:
     return -1;
@@ -2429,13 +2403,12 @@ static int init_pass2( x264_t *h )
 {
     x264_ratecontrol_t *rcc = h->rc;
     uint64_t all_const_bits = 0;
-    int i;
     double duration = 0;
-    for( i = 0; i < rcc->num_entries; i++ )
+    for( int i = 0; i < rcc->num_entries; i++ )
         duration += rcc->entry[i].i_duration;
     duration *= (double)h->sps->vui.i_num_units_in_tick / h->sps->vui.i_time_scale;
     uint64_t all_available_bits = h->param.rc.i_bitrate * 1000. * duration;
-    double rate_factor, step, step_mult;
+    double rate_factor, step_mult;
     double qblur = h->param.rc.f_qblur;
     double cplxblur = h->param.rc.f_complexity_blur;
     const int filter_size = (int)(qblur*4) | 1;
@@ -2443,7 +2416,7 @@ static int init_pass2( x264_t *h )
     double *qscale, *blurred_qscale;
 
     /* find total/average complexity & const_bits */
-    for(i=0; i<rcc->num_entries; i++)
+    for( int i = 0; i < rcc->num_entries; i++ )
     {
         ratecontrol_entry_t *rce = &rcc->entry[i];
         all_const_bits += rce->misc_bits;
@@ -2451,8 +2424,8 @@ static int init_pass2( x264_t *h )
 
     if( all_available_bits < all_const_bits)
     {
-        x264_log(h, X264_LOG_ERROR, "requested bitrate is too low. estimated minimum is %d kbps\n",
-                 (int)(all_const_bits * rcc->fps / (rcc->num_entries * 1000.)));
+        x264_log( h, X264_LOG_ERROR, "requested bitrate is too low. estimated minimum is %d kbps\n",
+                 (int)(all_const_bits * rcc->fps / (rcc->num_entries * 1000.)) );
         return -1;
     }
 
@@ -2460,35 +2433,34 @@ static int init_pass2( x264_t *h )
      * We don't blur the QPs directly, because then one very simple frame
      * could drag down the QP of a nearby complex frame and give it more
      * bits than intended. */
-    for(i=0; i<rcc->num_entries; i++)
+    for( int i = 0; i < rcc->num_entries; i++ )
     {
         ratecontrol_entry_t *rce = &rcc->entry[i];
         double weight_sum = 0;
         double cplx_sum = 0;
         double weight = 1.0;
         double gaussian_weight;
-        int j;
         /* weighted average of cplx of future frames */
-        for(j=1; j<cplxblur*2 && j<rcc->num_entries-i; j++)
+        for( int j = 1; j < cplxblur*2 && j < rcc->num_entries-i; j++ )
         {
             ratecontrol_entry_t *rcj = &rcc->entry[i+j];
             weight *= 1 - pow( (float)rcj->i_count / rcc->nmb, 2 );
-            if(weight < .0001)
+            if( weight < .0001 )
                 break;
-            gaussian_weight = weight * exp(-j*j/200.0);
+            gaussian_weight = weight * exp( -j*j/200.0 );
             weight_sum += gaussian_weight;
             cplx_sum += gaussian_weight * (qscale2bits(rcj, 1) - rcj->misc_bits);
         }
         /* weighted average of cplx of past frames */
         weight = 1.0;
-        for(j=0; j<=cplxblur*2 && j<=i; j++)
+        for( int j = 0; j <= cplxblur*2 && j <= i; j++ )
         {
             ratecontrol_entry_t *rcj = &rcc->entry[i-j];
-            gaussian_weight = weight * exp(-j*j/200.0);
+            gaussian_weight = weight * exp( -j*j/200.0 );
             weight_sum += gaussian_weight;
-            cplx_sum += gaussian_weight * (qscale2bits(rcj, 1) - rcj->misc_bits);
+            cplx_sum += gaussian_weight * (qscale2bits( rcj, 1 ) - rcj->misc_bits);
             weight *= 1 - pow( (float)rcj->i_count / rcc->nmb, 2 );
-            if(weight < .0001)
+            if( weight < .0001 )
                 break;
         }
         rce->blurred_complexity = cplx_sum / weight_sum;
@@ -2508,7 +2480,7 @@ static int init_pass2( x264_t *h )
      * The search range is probably overkill, but speed doesn't matter here. */
 
     expected_bits = 1;
-    for(i=0; i<rcc->num_entries; i++)
+    for( int i = 0; i < rcc->num_entries; i++ )
     {
         double q = get_qscale(h, &rcc->entry[i], 1.0, i);
         expected_bits += qscale2bits(&rcc->entry[i], q);
@@ -2517,7 +2489,7 @@ static int init_pass2( x264_t *h )
     step_mult = all_available_bits / expected_bits;
 
     rate_factor = 0;
-    for(step = 1E4 * step_mult; step > 1E-7 * step_mult; step *= 0.5)
+    for( double step = 1E4 * step_mult; step > 1E-7 * step_mult; step *= 0.5)
     {
         expected_bits = 0;
         rate_factor += step;
@@ -2527,37 +2499,36 @@ static int init_pass2( x264_t *h )
         rcc->accum_p_norm = 0;
 
         /* find qscale */
-        for(i=0; i<rcc->num_entries; i++)
+        for( int i = 0; i < rcc->num_entries; i++ )
         {
-            qscale[i] = get_qscale(h, &rcc->entry[i], rate_factor, i);
+            qscale[i] = get_qscale( h, &rcc->entry[i], rate_factor, i );
             rcc->last_qscale_for[rcc->entry[i].pict_type] = qscale[i];
         }
 
         /* fixed I/B qscale relative to P */
-        for(i=rcc->num_entries-1; i>=0; i--)
+        for( int i = rcc->num_entries-1; i >= 0; i-- )
         {
-            qscale[i] = get_diff_limited_q(h, &rcc->entry[i], qscale[i]);
+            qscale[i] = get_diff_limited_q( h, &rcc->entry[i], qscale[i] );
             assert(qscale[i] >= 0);
         }
 
         /* smooth curve */
-        if(filter_size > 1)
+        if( filter_size > 1 )
         {
-            assert(filter_size%2==1);
-            for(i=0; i<rcc->num_entries; i++)
+            assert( filter_size%2 == 1 );
+            for( int i = 0; i < rcc->num_entries; i++ )
             {
                 ratecontrol_entry_t *rce = &rcc->entry[i];
-                int j;
-                double q=0.0, sum=0.0;
+                double q = 0.0, sum = 0.0;
 
-                for(j=0; j<filter_size; j++)
+                for( int j = 0; j < filter_size; j++ )
                 {
                     int index = i+j-filter_size/2;
                     double d = index-i;
-                    double coeff = qblur==0 ? 1.0 : exp(-d*d/(qblur*qblur));
-                    if(index < 0 || index >= rcc->num_entries)
+                    double coeff = qblur==0 ? 1.0 : exp( -d*d/(qblur*qblur) );
+                    if( index < 0 || index >= rcc->num_entries )
                         continue;
-                    if(rce->pict_type != rcc->entry[index].pict_type)
+                    if( rce->pict_type != rcc->entry[index].pict_type )
                         continue;
                     q += qscale[index] * coeff;
                     sum += coeff;
@@ -2567,55 +2538,56 @@ static int init_pass2( x264_t *h )
         }
 
         /* find expected bits */
-        for(i=0; i<rcc->num_entries; i++)
+        for( int i = 0; i < rcc->num_entries; i++ )
         {
             ratecontrol_entry_t *rce = &rcc->entry[i];
-            rce->new_qscale = clip_qscale(h, rce->pict_type, blurred_qscale[i]);
+            rce->new_qscale = clip_qscale( h, rce->pict_type, blurred_qscale[i] );
             assert(rce->new_qscale >= 0);
-            expected_bits += qscale2bits(rce, rce->new_qscale);
+            expected_bits += qscale2bits( rce, rce->new_qscale );
         }
 
-        if(expected_bits > all_available_bits) rate_factor -= step;
+        if( expected_bits > all_available_bits )
+            rate_factor -= step;
     }
 
-    x264_free(qscale);
-    if(filter_size > 1)
-        x264_free(blurred_qscale);
+    x264_free( qscale );
+    if( filter_size > 1 )
+        x264_free( blurred_qscale );
 
-    if(rcc->b_vbv)
+    if( rcc->b_vbv )
         if( vbv_pass2( h, all_available_bits ) )
             return -1;
-    expected_bits = count_expected_bits(h);
+    expected_bits = count_expected_bits( h );
 
-    if(fabs(expected_bits/all_available_bits - 1.0) > 0.01)
+    if( fabs( expected_bits/all_available_bits - 1.0 ) > 0.01 )
     {
         double avgq = 0;
-        for(i=0; i<rcc->num_entries; i++)
+        for( int i = 0; i < rcc->num_entries; i++ )
             avgq += rcc->entry[i].new_qscale;
-        avgq = qscale2qp(avgq / rcc->num_entries);
-
-        if ((expected_bits > all_available_bits) || (!rcc->b_vbv))
-            x264_log(h, X264_LOG_WARNING, "Error: 2pass curve failed to converge\n");
-        x264_log(h, X264_LOG_WARNING, "target: %.2f kbit/s, expected: %.2f kbit/s, avg QP: %.4f\n",
-                 (float)h->param.rc.i_bitrate,
-                 expected_bits * rcc->fps / (rcc->num_entries * 1000.),
-                 avgq);
-        if(expected_bits < all_available_bits && avgq < h->param.rc.i_qp_min + 2)
-        {
-            if(h->param.rc.i_qp_min > 0)
-                x264_log(h, X264_LOG_WARNING, "try reducing target bitrate or reducing qp_min (currently %d)\n", h->param.rc.i_qp_min);
+        avgq = qscale2qp( avgq / rcc->num_entries );
+
+        if( expected_bits > all_available_bits || !rcc->b_vbv )
+            x264_log( h, X264_LOG_WARNING, "Error: 2pass curve failed to converge\n" );
+        x264_log( h, X264_LOG_WARNING, "target: %.2f kbit/s, expected: %.2f kbit/s, avg QP: %.4f\n",
+                  (float)h->param.rc.i_bitrate,
+                  expected_bits * rcc->fps / (rcc->num_entries * 1000.),
+                  avgq );
+        if( expected_bits < all_available_bits && avgq < h->param.rc.i_qp_min + 2 )
+        {
+            if( h->param.rc.i_qp_min > 0 )
+                x264_log( h, X264_LOG_WARNING, "try reducing target bitrate or reducing qp_min (currently %d)\n", h->param.rc.i_qp_min );
             else
-                x264_log(h, X264_LOG_WARNING, "try reducing target bitrate\n");
+                x264_log( h, X264_LOG_WARNING, "try reducing target bitrate\n" );
         }
-        else if(expected_bits > all_available_bits && avgq > h->param.rc.i_qp_max - 2)
+        else if( expected_bits > all_available_bits && avgq > h->param.rc.i_qp_max - 2 )
         {
-            if(h->param.rc.i_qp_max < 51)
-                x264_log(h, X264_LOG_WARNING, "try increasing target bitrate or increasing qp_max (currently %d)\n", h->param.rc.i_qp_max);
+            if( h->param.rc.i_qp_max < 51 )
+                x264_log( h, X264_LOG_WARNING, "try increasing target bitrate or increasing qp_max (currently %d)\n", h->param.rc.i_qp_max );
             else
-                x264_log(h, X264_LOG_WARNING, "try increasing target bitrate\n");
+                x264_log( h, X264_LOG_WARNING, "try increasing target bitrate\n");
         }
-        else if(!(rcc->b_2pass && rcc->b_vbv))
-            x264_log(h, X264_LOG_WARNING, "internal error\n");
+        else if( !(rcc->b_2pass && rcc->b_vbv) )
+            x264_log( h, X264_LOG_WARNING, "internal error\n" );
     }
 
     return 0;
index 13268573d93c31262853f9d06cdc97eae50e2f09..8fa7da0bd18402dcd2ee069ce1723bc9a79de90a 100644 (file)
@@ -200,9 +200,7 @@ static uint64_t x264_rd_cost_subpart( x264_t *h, int i_lambda2, int i4, int i_pi
         i_bits = ( (uint64_t)cabac_tmp.f8_bits_encoded * i_lambda2 + 128 ) >> 8;
     }
     else
-    {
         i_bits = x264_subpartition_size_cavlc( h, i4, i_pixel );
-    }
 
     return (i_ssd<<8) + i_bits;
 }
@@ -243,9 +241,7 @@ uint64_t x264_rd_cost_part( x264_t *h, int i_lambda2, int i4, int i_pixel )
         i_bits = ( (uint64_t)cabac_tmp.f8_bits_encoded * i_lambda2 + 128 ) >> 8;
     }
     else
-    {
         i_bits = x264_partition_size_cavlc( h, i8, i_pixel ) * i_lambda2;
-    }
 
     return (i_ssd<<8) + i_bits;
 }
@@ -267,9 +263,7 @@ static uint64_t x264_rd_cost_i8x8( x264_t *h, int i_lambda2, int i8, int i_mode
         i_bits = ( (uint64_t)cabac_tmp.f8_bits_encoded * i_lambda2 + 128 ) >> 8;
     }
     else
-    {
         i_bits = x264_partition_i8x8_size_cavlc( h, i8, i_mode ) * i_lambda2;
-    }
 
     return (i_ssd<<8) + i_bits;
 }
@@ -289,9 +283,7 @@ static uint64_t x264_rd_cost_i4x4( x264_t *h, int i_lambda2, int i4, int i_mode
         i_bits = ( (uint64_t)cabac_tmp.f8_bits_encoded * i_lambda2 + 128 ) >> 8;
     }
     else
-    {
         i_bits = x264_partition_i4x4_size_cavlc( h, i4, i_mode ) * i_lambda2;
-    }
 
     return (i_ssd<<8) + i_bits;
 }
@@ -315,9 +307,7 @@ static uint64_t x264_rd_cost_i8x8_chroma( x264_t *h, int i_lambda2, int i_mode,
         i_bits = ( (uint64_t)cabac_tmp.f8_bits_encoded * i_lambda2 + 128 ) >> 8;
     }
     else
-    {
         i_bits = x264_i8x8_chroma_size_cavlc( h ) * i_lambda2;
-    }
 
     return (i_ssd<<8) + i_bits;
 }
@@ -333,15 +323,14 @@ static uint64_t x264_rd_cost_i8x8_chroma( x264_t *h, int i_lambda2, int i_mode,
 /* precalculate the cost of coding various combinations of bits in a single context */
 void x264_rdo_init( void )
 {
-    int i_prefix, i_ctx, i;
-    for( i_prefix = 0; i_prefix < 15; i_prefix++ )
+    for( int i_prefix = 0; i_prefix < 15; i_prefix++ )
     {
-        for( i_ctx = 0; i_ctx < 128; i_ctx++ )
+        for( int i_ctx = 0; i_ctx < 128; i_ctx++ )
         {
             int f8_bits = 0;
             uint8_t ctx = i_ctx;
 
-            for( i = 1; i < i_prefix; i++ )
+            for( int i = 1; i < i_prefix; i++ )
                 f8_bits += x264_cabac_size_decision2( &ctx, 1 );
             if( i_prefix > 0 && i_prefix < 14 )
                 f8_bits += x264_cabac_size_decision2( &ctx, 0 );
@@ -351,12 +340,12 @@ void x264_rdo_init( void )
             cabac_transition_unary[i_prefix][i_ctx] = ctx;
         }
     }
-    for( i_ctx = 0; i_ctx < 128; i_ctx++ )
+    for( int i_ctx = 0; i_ctx < 128; i_ctx++ )
     {
         int f8_bits = 0;
         uint8_t ctx = i_ctx;
 
-        for( i = 0; i < 5; i++ )
+        for( int i = 0; i < 5; i++ )
             f8_bits += x264_cabac_size_decision2( &ctx, 1 );
         f8_bits += 1 << CABAC_SIZE_BITS; //sign
 
@@ -406,7 +395,7 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
     uint8_t *cabac_state_last = &h->cabac.state[ last_coeff_flag_offset[b_interlaced][i_ctxBlockCat] ];
     const int f = 1 << 15; // no deadzone
     int i_last_nnz;
-    int i, j;
+    int i;
 
     // (# of coefs) * (# of ctx) * (# of levels tried) = 1024
     // we don't need to keep all of those: (# of coefs) * (# of ctx) would be enough,
@@ -441,8 +430,8 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
     }
 
     /* init trellis */
-    for( i = 1; i < 8; i++ )
-        nodes_cur[i].score = TRELLIS_SCORE_MAX;
+    for( int j = 1; j < 8; j++ )
+        nodes_cur[j].score = TRELLIS_SCORE_MAX;
     nodes_cur[0].score = 0;
     nodes_cur[0].level_idx = 0;
     level_tree[0].abs_level = 0;
@@ -462,7 +451,6 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
     {
         int i_coef = abs_coefs[i];
         int q = ( f + i_coef * (dc?quant_mf[0]>>1:quant_mf[zigzag[i]]) ) >> 16;
-        int abs_level;
         int cost_sig[2], cost_last[2];
         trellis_node_t n;
 
@@ -474,7 +462,7 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
             int sigindex = i_coefs == 64 ? significant_coeff_flag_offset_8x8[b_interlaced][i] : i;
             const uint32_t cost_sig0 = x264_cabac_size_decision_noup2( &cabac_state_sig[sigindex], 0 )
                                      * (uint64_t)i_lambda2 >> ( CABAC_SIZE_BITS - LAMBDA_BITS );
-            for( j = 1; j < 8; j++ )
+            for( int j = 1; j < 8; j++ )
             {
                 if( nodes_cur[j].score != TRELLIS_SCORE_MAX )
                 {
@@ -493,7 +481,7 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
 
         XCHG( trellis_node_t*, nodes_cur, nodes_prev );
 
-        for( j = 0; j < 8; j++ )
+        for( int j = 0; j < 8; j++ )
             nodes_cur[j].score = TRELLIS_SCORE_MAX;
 
         if( i < i_coefs-1 )
@@ -515,7 +503,7 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
         // but it's only around .003 dB, and skipping them ~doubles the speed of trellis.
         // could also try q-2: that sometimes helps, but also sometimes decimates blocks
         // that are better left coded, especially at QP > 40.
-        for( abs_level = q; abs_level >= q-1; abs_level-- )
+        for( int abs_level = q; abs_level >= q-1; abs_level-- )
         {
             int unquant_abs_level = (((dc?unquant_mf[0]<<1:unquant_mf[zigzag[i]]) * abs_level + 128) >> 8);
             int d = i_coef - unquant_abs_level;
@@ -533,7 +521,7 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
             /* FIXME: for i16x16 dc is this weight optimal? */
                 ssd = (int64_t)d*d * (dc?256:coef_weight[i]);
 
-            for( j = 0; j < 8; j++ )
+            for( int j = 0; j < 8; j++ )
             {
                 int node_ctx = j;
                 if( nodes_prev[j].score == TRELLIS_SCORE_MAX )
@@ -588,7 +576,7 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
 
     /* output levels from the best path through the trellis */
     bnode = &nodes_cur[0];
-    for( j = 1; j < 8; j++ )
+    for( int j = 1; j < 8; j++ )
         if( nodes_cur[j].score < bnode->score )
             bnode = &nodes_cur[j];
 
@@ -599,11 +587,11 @@ static ALWAYS_INLINE int quant_trellis_cabac( x264_t *h, int16_t *dct,
         return 0;
     }
 
-    j = bnode->level_idx;
-    for( i = b_ac; j; i++ )
+    int level = bnode->level_idx;
+    for( i = b_ac; level; i++ )
     {
-        dct[zigzag[i]] = level_tree[j].abs_level * signs[i];
-        j = level_tree[j].next;
+        dct[zigzag[i]] = level_tree[level].abs_level * signs[i];
+        level = level_tree[level].next;
     }
     for( ; i < i_coefs; i++ )
         dct[zigzag[i]] = 0;
index 03b707d2f9a951f7c2224917753050c4f38b0226..b759dfb7c374e9ae7c2a7f50ecc73c234362096f 100644 (file)
@@ -33,9 +33,8 @@ static const uint8_t num_clock_ts[10] = { 0, 1, 1, 1, 2, 2, 3, 3, 2, 3 };
 
 static void transpose( uint8_t *buf, int w )
 {
-    int i, j;
-    for( i = 0; i < w; i++ )
-        for( j = 0; j < i; j++ )
+    for( int i = 0; i < w; i++ )
+        for( int j = 0; j < i; j++ )
             XCHG( uint8_t, buf[w*i+j], buf[w*j+i] );
 }
 
@@ -56,7 +55,7 @@ static void scaling_list_write( bs_t *s, x264_pps_t *pps, int idx )
     }
     else
     {
-        int j, run;
+        int run;
         bs_write( s, 1, 1 ); // scaling_list_present_flag
 
         // try run-length compression of trailing values
@@ -66,7 +65,7 @@ static void scaling_list_write( bs_t *s, x264_pps_t *pps, int idx )
         if( run < len && len - run < bs_size_se( (int8_t)-list[zigzag[run]] ) )
             run = len;
 
-        for( j = 0; j < run; j++ )
+        for( int j = 0; j < run; j++ )
             bs_write_se( s, (int8_t)(list[zigzag[j]] - (j>0 ? list[zigzag[j-1]] : 8)) ); // delta
 
         if( run < len )
@@ -417,8 +416,6 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )
 
 void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps )
 {
-    int i, j;
-
     pps->i_id = i_id;
     pps->i_sps_id = sps->i_id;
     pps->b_cabac = param->b_cabac;
@@ -446,11 +443,11 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
     switch( pps->i_cqm_preset )
     {
     case X264_CQM_FLAT:
-        for( i = 0; i < 6; i++ )
+        for( int i = 0; i < 6; i++ )
             pps->scaling_list[i] = x264_cqm_flat16;
         break;
     case X264_CQM_JVT:
-        for( i = 0; i < 6; i++ )
+        for( int i = 0; i < 6; i++ )
             pps->scaling_list[i] = x264_cqm_jvt[i];
         break;
     case X264_CQM_CUSTOM:
@@ -467,8 +464,8 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
         pps->scaling_list[CQM_4PC] = param->cqm_4pc;
         pps->scaling_list[CQM_8IY+4] = param->cqm_8iy;
         pps->scaling_list[CQM_8PY+4] = param->cqm_8py;
-        for( i = 0; i < 6; i++ )
-            for( j = 0; j < (i<4?16:64); j++ )
+        for( int i = 0; i < 6; i++ )
+            for( int j = 0; j < (i < 4 ? 16 : 64); j++ )
                 if( pps->scaling_list[i][j] == 0 )
                     pps->scaling_list[i] = x264_cqm_jvt[i];
         break;
@@ -565,10 +562,10 @@ int x264_sei_version_write( x264_t *h, bs_t *s )
         bs_write( s, 8, 255 );
     bs_write( s, 8, length-i );
 
-    for( i = 0; i < 16; i++ )
-        bs_write( s, 8, uuid[i] );
-    for( i = 0; i < length-16; i++ )
-        bs_write( s, 8, version[i] );
+    for( int j = 0; j < 16; j++ )
+        bs_write( s, 8, uuid[j] );
+    for( int j = 0; j < length-16; j++ )
+        bs_write( s, 8, version[j] );
 
     bs_rbsp_trailing( s );
     bs_flush( s );
@@ -627,11 +624,9 @@ void x264_sei_pic_timing_write( x264_t *h, bs_t *s, int cpb_removal_delay, int d
 
 void x264_filler_write( x264_t *h, bs_t *s, int filler )
 {
-    int i;
-
     bs_realign( s );
 
-    for( i = 0; i < filler; i++ )
+    for( int i = 0; i < filler; i++ )
         bs_write( s, 8, 0xff );
 
     bs_rbsp_trailing( s );
index 9d727ec13b135e6a455e98c2555d4d09e0b5c177..b08406adc7f4baab4970a1e05db8f7f97e6454a0 100644 (file)
@@ -70,15 +70,14 @@ static void x264_weight_get_h264( unsigned int weight_nonh264, int offset, x264_
 
 void x264_weight_plane_analyse( x264_t *h, x264_frame_t *frame )
 {
-    int x,y;
     uint32_t sad = 0;
     uint64_t ssd = 0;
     uint8_t *p = frame->plane[0];
     int stride = frame->i_stride[0];
     int width = frame->i_width[0];
     int height = frame->i_lines[0];
-    for( y = 0; y < height>>4; y++, p += stride*16 )
-        for( x = 0; x < width; x += 16 )
+    for( int y = 0; y < height>>4; y++, p += stride*16 )
+        for( int x = 0; x < width; x += 16 )
         {
             uint64_t res = h->pixf.var[PIXEL_16x16]( p + x, stride );
             sad += (uint32_t)res;
@@ -99,11 +98,10 @@ static NOINLINE uint8_t *x264_weight_cost_init_luma( x264_t *h, x264_frame_t *fe
         int i_lines = fenc->i_lines_lowres;
         int i_width = fenc->i_width_lowres;
         int i_mb_xy = 0;
-        int x,y;
         uint8_t *p = dest;
 
-        for( y = 0; y < i_lines; y += 8, p += i_stride*8 )
-            for( x = 0; x < i_width; x += 8, i_mb_xy++ )
+        for( int y = 0; y < i_lines; y += 8, p += i_stride*8 )
+            for( int x = 0; x < i_width; x += 8, i_mb_xy++ )
             {
                 int mvx = fenc->lowres_mvs[0][ref0_distance][i_mb_xy][0];
                 int mvy = fenc->lowres_mvs[0][ref0_distance][i_mb_xy][1];
@@ -119,7 +117,6 @@ static NOINLINE uint8_t *x264_weight_cost_init_luma( x264_t *h, x264_frame_t *fe
 
 static NOINLINE unsigned int x264_weight_cost( x264_t *h, x264_frame_t *fenc, uint8_t *src, x264_weight_t *w )
 {
-    int x, y;
     unsigned int cost = 0;
     int i_stride = fenc->i_stride_lowres;
     int i_lines = fenc->i_lines_lowres;
@@ -131,8 +128,8 @@ static NOINLINE unsigned int x264_weight_cost( x264_t *h, x264_frame_t *fenc, ui
 
     if( w )
     {
-        for( y = 0; y < i_lines; y += 8, pixoff = y*i_stride )
-            for( x = 0; x < i_width; x += 8, i_mb++, pixoff += 8)
+        for( int y = 0; y < i_lines; y += 8, pixoff = y*i_stride )
+            for( int x = 0; x < i_width; x += 8, i_mb++, pixoff += 8)
             {
                 w->weightfn[8>>2]( buf, 8, &src[pixoff], i_stride, w, 8 );
                 cost += X264_MIN( h->pixf.mbcmp[PIXEL_8x8]( buf, 8, &fenc_plane[pixoff], i_stride ), fenc->i_intra_cost[i_mb] );
@@ -151,8 +148,8 @@ static NOINLINE unsigned int x264_weight_cost( x264_t *h, x264_frame_t *fenc, ui
         cost += numslices * ( 10 + 2 * ( bs_size_ue( w[0].i_denom ) + bs_size_se( w[0].i_scale ) + bs_size_se( w[0].i_offset ) ) );
     }
     else
-        for( y = 0; y < i_lines; y += 8, pixoff = y*i_stride )
-            for( x = 0; x < i_width; x += 8, i_mb++, pixoff += 8 )
+        for( int y = 0; y < i_lines; y += 8, pixoff = y*i_stride )
+            for( int x = 0; x < i_width; x += 8, i_mb++, pixoff += 8 )
                 cost += X264_MIN( h->pixf.mbcmp[PIXEL_8x8]( &src[pixoff], i_stride, &fenc_plane[pixoff], i_stride ), fenc->i_intra_cost[i_mb] );
     x264_emms();
     return cost;
@@ -161,7 +158,7 @@ static NOINLINE unsigned int x264_weight_cost( x264_t *h, x264_frame_t *fenc, ui
 void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int b_lookahead )
 {
     float fenc_mean, ref_mean, fenc_var, ref_var;
-    int i_off, offset_search;
+    int offset_search;
     int minoff, minscale, mindenom;
     unsigned int minscore, origscore;
     int i_delta_index = fenc->i_frame - ref->i_frame - 1;
@@ -210,7 +207,7 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int
     // This gives a slight improvement due to rounding errors but only tests
     // one offset on lookahead.
     // TODO: currently searches only offset +1. try other offsets/multipliers/combinations thereof?
-    for( i_off = offset_search; i_off <= offset_search+!b_lookahead; i_off++ )
+    for( int i_off = offset_search; i_off <= offset_search+!b_lookahead; i_off++ )
     {
         SET_WEIGHT( weights[0], 1, minscale, mindenom, i_off );
         unsigned int s = x264_weight_cost( h, fenc, mcbuf, &weights[0] );
@@ -266,7 +263,6 @@ static int x264_slicetype_mb_cost( x264_t *h, x264_mb_analysis_t *a,
     uint8_t *pix2 = pix1+8;
     x264_me_t m[2];
     int i_bcost = COST_MAX;
-    int l, i;
     int list_used = 0;
 
     h->mb.pic.p_fenc[0] = h->mb.pic.fenc_buf;
@@ -373,7 +369,7 @@ static int x264_slicetype_mb_cost( x264_t *h, x264_mb_analysis_t *a,
         }
     }
 
-    for( l = 0; l < 1 + b_bidir; l++ )
+    for( int l = 0; l < 1 + b_bidir; l++ )
     {
         if( do_search[l] )
         {
@@ -436,7 +432,7 @@ lowres_intra_mb:
             int satds[3];
 
             memcpy( pix-FDEC_STRIDE, src-i_stride, 17 );
-            for( i=0; i<8; i++ )
+            for( int i = 0; i < 8; i++ )
                 pix[i*FDEC_STRIDE] = src[i*i_stride];
             pix++;
 
@@ -444,7 +440,7 @@ lowres_intra_mb:
                 h->pixf.intra_mbcmp_x3_8x8c( h->mb.pic.p_fenc[0], pix, satds );
             else
             {
-                for( i=0; i<3; i++ )
+                for( int i = 0; i < 3; i++ )
                 {
                     h->predict_8x8c[i]( pix );
                     satds[i] = h->pixf.mbcmp[PIXEL_8x8]( pix, FDEC_STRIDE, h->mb.pic.p_fenc[0], FENC_STRIDE );
@@ -458,9 +454,8 @@ lowres_intra_mb:
                 int satd = h->pixf.mbcmp[PIXEL_8x8]( pix, FDEC_STRIDE, h->mb.pic.p_fenc[0], FENC_STRIDE );
                 i_icost = X264_MIN( i_icost, satd );
                 h->predict_8x8_filter( pix, edge, ALL_NEIGHBORS, ALL_NEIGHBORS );
-                for( i=3; i<9; i++ )
+                for( int i = 3; i < 9; i++ )
                 {
-                    int satd;
                     h->predict_8x8[i]( pix, edge );
                     satd = h->pixf.mbcmp[PIXEL_8x8]( pix, FDEC_STRIDE, h->mb.pic.p_fenc[0], FENC_STRIDE );
                     i_icost = X264_MIN( i_icost, satd );
@@ -641,7 +636,6 @@ static int x264_slicetype_frame_cost_recalculate( x264_t *h, x264_frame_t **fram
 
 static void x264_macroblock_tree_finish( x264_t *h, x264_frame_t *frame, int ref0_distance )
 {
-    int mb_index;
     x264_emms();
     float weightdelta = 0.0;
     if( ref0_distance && frame->f_weighted_cost_delta[ref0_distance-1] > 0 )
@@ -650,7 +644,7 @@ static void x264_macroblock_tree_finish( x264_t *h, x264_frame_t *frame, int ref
     /* Allow the strength to be adjusted via qcompress, since the two
      * concepts are very similar. */
     float strength = 5.0f * (1.0f - h->param.rc.f_qcompress);
-    for( mb_index = 0; mb_index < h->mb.i_mb_count; mb_index++ )
+    for( int mb_index = 0; mb_index < h->mb.i_mb_count; mb_index++ )
     {
         int intra_cost = (frame->i_intra_cost[mb_index] * frame->i_inv_qscale_factor[mb_index]+128)>>8;
         if( intra_cost )
@@ -692,9 +686,8 @@ static void x264_macroblock_tree_propagate( x264_t *h, x264_frame_t **frames, in
             {
                 /* Access width-2 bitfield. */
                 int lists_used = (frames[b]->lowres_inter_types[b-p0][p1-b][mb_index>>2] >> ((mb_index&3)*2))&3;
-                int list;
                 /* Follow the MVs to the previous frame(s). */
-                for( list = 0; list < 2; list++ )
+                for( int list = 0; list < 2; list++ )
                     if( (lists_used >> list)&1 )
                     {
                         int x = mvs[list][mb_index][0];
@@ -750,13 +743,13 @@ static void x264_macroblock_tree_propagate( x264_t *h, x264_frame_t **frames, in
 
 static void x264_macroblock_tree( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, int num_frames, int b_intra )
 {
-    int i, idx = !b_intra;
+    int idx = !b_intra;
     int last_nonb, cur_nonb = 1;
     int bframes = 0;
+    int i = num_frames - 1;
     if( b_intra )
         x264_slicetype_frame_cost( h, a, frames, 0, 0, 0, 0 );
 
-    i = num_frames-1;
     while( i > 0 && frames[i]->i_type == X264_TYPE_B )
         i--;
     last_nonb = i;
@@ -851,12 +844,12 @@ static void x264_calculate_durations( x264_t *h, x264_frame_t *cur_frame, x264_f
 
 static void x264_vbv_lookahead( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, int num_frames, int keyframe )
 {
-    int last_nonb = 0, cur_nonb = 1, next_nonb, i, idx = 0;
+    int last_nonb = 0, cur_nonb = 1, idx = 0;
     x264_frame_t *prev_frame = NULL;
     int prev_frame_idx = 0;
     while( cur_nonb < num_frames && frames[cur_nonb]->i_type == X264_TYPE_B )
         cur_nonb++;
-    next_nonb = keyframe ? last_nonb : cur_nonb;
+    int next_nonb = keyframe ? last_nonb : cur_nonb;
 
     if( frames[0]->i_coded_fields_lookahead >= 0 )
     {
@@ -887,7 +880,7 @@ static void x264_vbv_lookahead( x264_t *h, x264_mb_analysis_t *a, x264_frame_t *
             idx++;
         }
         /* Handle the B-frames: coded order */
-        for( i = last_nonb+1; i < cur_nonb; i++, idx++ )
+        for( int i = last_nonb+1; i < cur_nonb; i++, idx++ )
         {
             frames[next_nonb]->i_planned_satd[idx] = x264_vbv_frame_cost( h, a, frames, last_nonb, cur_nonb, i );
             frames[next_nonb]->i_planned_type[idx] = X264_TYPE_B;
@@ -921,7 +914,6 @@ static int x264_slicetype_path_cost( x264_t *h, x264_mb_analysis_t *a, x264_fram
     while( path[loc] )
     {
         int next_p = loc;
-        int next_b;
         /* Find the location of the next P-frame. */
         while( path[next_p] != 'P' )
             next_p++;
@@ -936,13 +928,13 @@ static int x264_slicetype_path_cost( x264_t *h, x264_mb_analysis_t *a, x264_fram
         {
             int middle = cur_p + (next_p - cur_p)/2;
             cost += x264_slicetype_frame_cost( h, a, frames, cur_p, next_p, middle, 0 );
-            for( next_b = loc; next_b < middle && cost < threshold; next_b++ )
+            for( int next_b = loc; next_b < middle && cost < threshold; next_b++ )
                 cost += x264_slicetype_frame_cost( h, a, frames, cur_p, middle, next_b, 0 );
-            for( next_b = middle+1; next_b < next_p && cost < threshold; next_b++ )
+            for( int next_b = middle+1; next_b < next_p && cost < threshold; next_b++ )
                 cost += x264_slicetype_frame_cost( h, a, frames, middle, next_p, next_b, 0 );
         }
         else
-            for( next_b = loc; next_b < next_p && cost < threshold; next_b++ )
+            for( int next_b = loc; next_b < next_p && cost < threshold; next_b++ )
                 cost += x264_slicetype_frame_cost( h, a, frames, cur_p, next_p, next_b, 0 );
 
         loc = next_p + 1;
@@ -959,12 +951,11 @@ static void x264_slicetype_path( x264_t *h, x264_mb_analysis_t *a, x264_frame_t
 {
     char paths[2][X264_LOOKAHEAD_MAX];
     int num_paths = X264_MIN( h->param.i_bframe+1, length );
-    int path;
     int best_cost = COST_MAX;
     int idx = 0;
 
     /* Iterate over all currently possible paths */
-    for( path = 0; path < num_paths; path++ )
+    for( int path = 0; path < num_paths; path++ )
     {
         /* Add suffixes to the current path */
         int len = length - (path + 1);
@@ -1029,11 +1020,10 @@ static int scenecut_internal( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **f
 
 static int scenecut( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, int p0, int p1, int real_scenecut, int num_frames )
 {
-    int curp0, curp1, i, maxp1 = p0 + 1;
-
     /* Only do analysis during a normal scenecut check. */
     if( real_scenecut && h->param.i_bframe )
     {
+        int maxp1 = p0 + 1;
         /* Look ahead to avoid coding short flashes as scenecuts. */
         if( h->param.i_bframe_adaptive == X264_B_ADAPT_TRELLIS )
             /* Don't analyse any more frames than the trellis would have covered. */
@@ -1045,17 +1035,17 @@ static int scenecut( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, in
         /* Where A and B are scenes: AAAAAABBBAAAAAA
          * If BBB is shorter than (maxp1-p0), it is detected as a flash
          * and not considered a scenecut. */
-        for( curp1 = p1; curp1 <= maxp1; curp1++ )
+        for( int curp1 = p1; curp1 <= maxp1; curp1++ )
             if( !scenecut_internal( h, a, frames, p0, curp1, 0 ) )
                 /* Any frame in between p0 and cur_p1 cannot be a real scenecut. */
-                for( i = curp1; i > p0; i-- )
+                for( int i = curp1; i > p0; i-- )
                     frames[i]->b_scenecut = 0;
 
         /* Where A-F are scenes: AAAAABBCCDDEEFFFFFF
          * If each of BB ... EE are shorter than (maxp1-p0), they are
          * detected as flashes and not considered scenecuts.
          * Instead, the first F frame becomes a scenecut. */
-        for( curp0 = p0; curp0 < maxp1; curp0++ )
+        for( int curp0 = p0; curp0 < maxp1; curp0++ )
             if( scenecut_internal( h, a, frames, curp0, maxp1, 0 ) )
                 /* If cur_p0 is the p0 of a scenecut, it cannot be the p1 of a scenecut. */
                     frames[curp0]->b_scenecut = 0;
@@ -1071,7 +1061,7 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
 {
     x264_mb_analysis_t a;
     x264_frame_t *frames[X264_LOOKAHEAD_MAX+3] = { NULL, };
-    int num_frames, orig_num_frames, keyint_limit, idr_frame_type, i, j;
+    int num_frames, orig_num_frames, keyint_limit, idr_frame_type, framecnt;
     int i_mb_count = NUM_MBS;
     int cost1p0, cost2p0, cost1b1, cost2p1;
     int i_max_search = X264_MIN( h->lookahead->next.i_size, X264_LOOKAHEAD_MAX );
@@ -1083,14 +1073,14 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
     if( !h->lookahead->last_nonb )
         return;
     frames[0] = h->lookahead->last_nonb;
-    for( j = 0; j < i_max_search && h->lookahead->next.list[j]->i_type == X264_TYPE_AUTO; j++ )
-        frames[j+1] = h->lookahead->next.list[j];
+    for( framecnt = 0; framecnt < i_max_search && h->lookahead->next.list[framecnt]->i_type == X264_TYPE_AUTO; framecnt++ )
+        frames[framecnt+1] = h->lookahead->next.list[framecnt];
 
-    if( !j )
+    if( !framecnt )
         return;
 
     keyint_limit = h->param.i_keyint_max - frames[0]->i_frame + h->lookahead->i_last_keyframe - 1;
-    orig_num_frames = num_frames = h->param.b_intra_refresh ? j : X264_MIN( j, keyint_limit );
+    orig_num_frames = num_frames = h->param.b_intra_refresh ? framecnt : X264_MIN( framecnt, keyint_limit );
 
     x264_lowres_context_init( h, &a );
     idr_frame_type = frames[1]->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_min ? X264_TYPE_IDR : X264_TYPE_I;
@@ -1100,7 +1090,7 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
      * go down in quality due to being referenced less, despite it being
      * more RD-optimal. */
     if( (h->param.analyse.b_psy && h->param.rc.b_mb_tree) || h->param.rc.i_vbv_buffer_size )
-        num_frames = j;
+        num_frames = framecnt;
     else if( num_frames == 1 )
     {
         frames[1]->i_type = X264_TYPE_P;
@@ -1133,19 +1123,19 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
                 int best_path_index = (num_frames-1) % (X264_BFRAME_MAX+1);
 
                 /* Perform the frametype analysis. */
-                for( j = 2; j < num_frames; j++ )
+                for( int j = 2; j < num_frames; j++ )
                     x264_slicetype_path( h, &a, frames, j, best_paths );
 
                 num_bframes = strspn( best_paths[best_path_index], "B" );
                 /* Load the results of the analysis into the frame types. */
-                for( j = 1; j < num_frames; j++ )
+                for( int j = 1; j < num_frames; j++ )
                     frames[j]->i_type = best_paths[best_path_index][j-1] == 'B' ? X264_TYPE_B : X264_TYPE_P;
             }
             frames[num_frames]->i_type = X264_TYPE_P;
         }
         else if( h->param.i_bframe_adaptive == X264_B_ADAPT_FAST )
         {
-            for( i = 0; i <= num_frames-2; )
+            for( int i = 0; i <= num_frames-2; )
             {
                 cost2p1 = x264_slicetype_frame_cost( h, &a, frames, i+0, i+2, i+2, 1 );
                 if( frames[i+2]->i_intra_mbs[2] > i_mb_count / 2 )
@@ -1172,6 +1162,7 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
                 #define P_SENS_BIAS (50 - h->param.i_bframe_bias)
                 frames[i+1]->i_type = X264_TYPE_B;
 
+                int j;
                 for( j = i+2; j <= X264_MIN( i+h->param.i_bframe, num_frames-1 ); j++ )
                 {
                     int pthresh = X264_MAX(INTER_THRESH - P_SENS_BIAS * (j-i-1), INTER_THRESH/10);
@@ -1191,13 +1182,13 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
         else
         {
             num_bframes = X264_MIN(num_frames-1, h->param.i_bframe);
-            for( j = 1; j < num_frames; j++ )
+            for( int j = 1; j < num_frames; j++ )
                 frames[j]->i_type = (j%(num_bframes+1)) ? X264_TYPE_B : X264_TYPE_P;
             frames[num_frames]->i_type = X264_TYPE_P;
         }
 
         /* Check scenecut on the first minigop. */
-        for( j = 1; j < num_bframes+1; j++ )
+        for( int j = 1; j < num_bframes+1; j++ )
             if( h->param.i_scenecut_threshold && scenecut( h, &a, frames, j, j+1, 0, orig_num_frames ) )
             {
                 frames[j]->i_type = X264_TYPE_P;
@@ -1209,7 +1200,7 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
     }
     else
     {
-        for( j = 1; j <= num_frames; j++ )
+        for( int j = 1; j <= num_frames; j++ )
             frames[j]->i_type = X264_TYPE_P;
         reset_start = !keyframe + 1;
         num_bframes = 0;
@@ -1222,7 +1213,7 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
 
     /* Enforce keyframe limit. */
     if( !h->param.b_intra_refresh )
-        for( j = 0; j < num_frames; j++ )
+        for( int j = 0; j < num_frames; j++ )
         {
             if( ((j-keyint_limit) % h->param.i_keyint_max) == 0 )
             {
@@ -1237,7 +1228,7 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )
         x264_vbv_lookahead( h, &a, frames, num_frames, keyframe );
 
     /* Restore frametypes for all frames that haven't actually been decided yet. */
-    for( j = reset_start; j <= num_frames; j++ )
+    for( int j = reset_start; j <= num_frames; j++ )
         frames[j]->i_type = X264_TYPE_AUTO;
 }
 
@@ -1247,7 +1238,6 @@ void x264_slicetype_decide( x264_t *h )
     x264_frame_t *frm;
     int bframes;
     int brefs;
-    int i;
 
     if( !h->lookahead->next.i_size )
         return;
@@ -1256,7 +1246,7 @@ void x264_slicetype_decide( x264_t *h )
 
     if( h->param.rc.i_rc_method == X264_RC_ABR || h->param.rc.b_stat_write || h->param.rc.i_vbv_buffer_size )
     {
-        for( i = 0; i < h->lookahead->next.i_size; i++ )
+        for( int i = 0; i < h->lookahead->next.i_size; i++ )
         {
             if( h->param.b_vfr_input )
             {
@@ -1286,7 +1276,7 @@ void x264_slicetype_decide( x264_t *h )
     if( h->param.rc.b_stat_read )
     {
         /* Use the frame types from the first pass */
-        for( i = 0; i < h->lookahead->next.i_size; i++ )
+        for( int i = 0; i < h->lookahead->next.i_size; i++ )
             h->lookahead->next.list[i]->i_type =
                 x264_ratecontrol_slice_type( h, h->lookahead->next.list[i]->i_frame );
     }
@@ -1419,7 +1409,7 @@ void x264_slicetype_decide( x264_t *h )
     if( bframes )
     {
         int index[] = { brefs+1, 1 };
-        for( i = 0; i < bframes; i++ )
+        for( int i = 0; i < bframes; i++ )
         {
             int idx = index[h->lookahead->next.list[i]->i_type == X264_TYPE_BREF]++;
             frames[idx] = h->lookahead->next.list[i];
@@ -1430,7 +1420,7 @@ void x264_slicetype_decide( x264_t *h )
         memcpy( h->lookahead->next.list, frames, (bframes+1) * sizeof(x264_frame_t*) );
     }
 
-    for( i = 0; i <= bframes; i++ )
+    for( int i = 0; i <= bframes; i++ )
     {
         h->lookahead->next.list[i]->i_coded = i_coded++;
         if( h->param.rc.i_rc_method == X264_RC_ABR || h->param.rc.b_stat_write || h->param.rc.i_vbv_buffer_size )
@@ -1452,7 +1442,7 @@ void x264_slicetype_decide( x264_t *h )
 
 int x264_rc_analyse_slice( x264_t *h )
 {
-    int p0=0, p1, b;
+    int p0 = 0, p1, b;
     int cost;
     x264_emms();
 
@@ -1491,12 +1481,11 @@ int x264_rc_analyse_slice( x264_t *h )
 
     if( h->param.b_intra_refresh && h->param.rc.i_vbv_buffer_size && h->fenc->i_type == X264_TYPE_P )
     {
-        int x, y;
         int ip_factor = 256 * h->param.rc.f_ip_factor; /* fix8 */
-        for( y = 0; y < h->sps->i_mb_height; y++ )
+        for( int y = 0; y < h->sps->i_mb_height; y++ )
         {
             int mb_xy = y * h->mb.i_mb_stride;
-            for( x = h->fdec->i_pir_start_col; x <= h->fdec->i_pir_end_col; x++, mb_xy++ )
+            for( int x = h->fdec->i_pir_start_col; x <= h->fdec->i_pir_end_col; x++, mb_xy++ )
             {
                 int intra_cost = (h->fenc->i_intra_cost[mb_xy] * ip_factor + 128) >> 8;
                 int inter_cost = h->fenc->lowres_costs[b-p0][p1-b][mb_xy];
index e4653aa6f3efbe628f202eeb4479623285cec236..9e20665bbc97b14d63697311890f251cd2264fd4 100644 (file)
@@ -105,7 +105,7 @@ fail:
 /* generate a filter sequence to try based on the filename extension */
 static void avs_build_filter_sequence( char *filename_ext, const char *filter[AVS_MAX_SEQUENCE+1] )
 {
-    int i=0, j;
+    int i = 0;
     const char *all_purpose[] = { "FFmpegSource2", "DSS2", "DirectShowSource", 0 };
     if( !strcasecmp( filename_ext, "avi" ) )
         filter[i++] = "AVISource";
@@ -113,7 +113,7 @@ static void avs_build_filter_sequence( char *filename_ext, const char *filter[AV
         filter[i++] = "MPEG2Source";
     if( !strcasecmp( filename_ext, "dga" ) )
         filter[i++] = "AVCSource";
-    for( j = 0; all_purpose[j] && i < AVS_MAX_SEQUENCE; j++ )
+    for( int j = 0; all_purpose[j] && i < AVS_MAX_SEQUENCE; j++ )
         filter[i++] = all_purpose[j];
 }
 
@@ -273,16 +273,14 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame )
     avs_hnd_t *h = handle;
     if( i_frame >= h->num_frames )
         return -1;
-    AVS_VideoFrame *frm =
-    p_pic->opaque = h->func.avs_get_frame( h->clip, i_frame );
-    int i;
+    AVS_VideoFrame *frm = p_pic->opaque = h->func.avs_get_frame( h->clip, i_frame );
     const char *err = h->func.avs_clip_get_error( h->clip );
     if( err )
     {
         fprintf( stderr, "avs [error]: %s occurred while reading frame %d\n", err, i_frame );
         return -1;
     }
-    for( i = 0; i < 3; i++ )
+    for( int i = 0; i < 3; i++ )
     {
         /* explicitly cast away the const attribute to avoid a warning */
         p_pic->img.plane[i] = (uint8_t*)avs_get_read_ptr_p( frm, plane[i] );
index a0c39916142dcdbc90bc22607cafbac7314a1673..4a369ee157f732e1d254da8ead7645cf4ba799e3 100644 (file)
@@ -41,11 +41,11 @@ typedef struct
     double last_timecode;
 } timecode_hnd_t;
 
-static inline double sigexp10( double value, double *exp )
+static inline double sigexp10( double value, double *exponent )
 {
     /* This function separates significand and exp10 from double floating point. */
-    *exp = pow( 10, floor( log10( value ) ) );
-    return value / *exp;
+    *exponent = pow( 10, floor( log10( value ) ) );
+    return value / *exponent;
 }
 
 #define DOUBLE_EPSILON 5e-6
@@ -82,10 +82,9 @@ static double correct_fps( double fps, timecode_hnd_t *h )
 
 static int try_mkv_timebase_den( double *fpss, timecode_hnd_t *h, int loop_num )
 {
-    int num;
     h->timebase_num = 0;
     h->timebase_den = MKV_TIMEBASE_DEN;
-    for( num = 0; num < loop_num; num++ )
+    for( int num = 0; num < loop_num; num++ )
     {
         int fps_den;
         double exponent;
index 3e9c9aa703d5dc21edfda2f053af0ef752028a9a..c34f264e16bba68523e7f5c52f835c9bbd6f9f35 100644 (file)
@@ -42,7 +42,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     y4m_hnd_t *h = malloc( sizeof(y4m_hnd_t) );
     int  i, n, d;
     char header[MAX_YUV4_HEADER+10];
-    char *tokstart, *tokend, *header_end;
+    char *tokend, *header_end;
     int colorspace = X264_CSP_NONE;
     int alt_colorspace = X264_CSP_NONE;
     if( !h )
@@ -79,7 +79,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     /* Scan properties */
     header_end = &header[i+1]; /* Include space */
     h->seq_header_len = i+1;
-    for( tokstart = &header[strlen( Y4M_MAGIC )+1]; tokstart < header_end; tokstart++ )
+    for( char *tokstart = &header[strlen( Y4M_MAGIC )+1]; tokstart < header_end; tokstart++ )
     {
         if( *tokstart == 0x20 )
             continue;
index 3e39e07f2276e5c21769557a886466bf8a4396ae..cbed7fc09ab1f2450ebeb77083eec8a170d14ea8 100644 (file)
@@ -39,8 +39,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     if( !opt->resolution )
     {
         /* try to parse the file name */
-        char *p;
-        for( p = psz_filename; *p; p++ )
+        for( char *p = psz_filename; *p; p++ )
             if( *p >= '0' && *p <= '9' && sscanf( p, "%ux%u", &info->width, &info->height ) == 2 )
                 break;
     }
index 89790b7defe32cd663b4fb5c4198e51924805a83..31b62f89658258681092b23f94edea39abcc417f 100644 (file)
@@ -208,16 +208,16 @@ static int mk_close_context( mk_context *c, unsigned *off )
 
 static void mk_destroy_contexts( mk_writer *w )
 {
-    mk_context *cur, *next;
+    mk_context *next;
 
-    for( cur = w->freelist; cur; cur = next )
+    for( mk_context *cur = w->freelist; cur; cur = next )
     {
         next = cur->next;
         free( cur->data );
         free( cur );
     }
 
-    for( cur = w->actlist; cur; cur = next )
+    for( mk_context *cur = w->actlist; cur; cur = next )
     {
         next = cur->next;
         free( cur->data );
index dfe6943f9a213ff74192c6f339bddf3868bbe3a7..cbe9f5c3de39589ea88e19db5bd162ce290f4869 100644 (file)
@@ -46,7 +46,7 @@ typedef struct
 
 static void recompute_bitrate_mp4( GF_ISOFile *p_file, int i_track )
 {
-    u32 i, count, di, timescale, time_wnd, rate;
+    u32 count, di, timescale, time_wnd, rate;
     u64 offset;
     Double br;
     GF_ESD *esd;
@@ -61,7 +61,7 @@ static void recompute_bitrate_mp4( GF_ISOFile *p_file, int i_track )
 
     timescale = gf_isom_get_media_timescale( p_file, i_track );
     count = gf_isom_get_sample_count( p_file, i_track );
-    for( i = 0; i < count; i++ )
+    for( int i = 0; i < count; i++ )
     {
         GF_ISOSample *samp = gf_isom_get_sample_info( p_file, i_track, i+1, &di, &offset );
         if( !samp )
index ebd4e559cd4159d32fca7c1d2cebb320c00e736b..6d64aa1d4b825044aa23caab547691276cf0e750 100644 (file)
@@ -96,13 +96,13 @@ static inline uint32_t read_time(void)
 static bench_t* get_bench( const char *name, int cpu )
 {
     int i, j;
-    for( i=0; benchs[i].name && strcmp(name, benchs[i].name); i++ )
+    for( i = 0; benchs[i].name && strcmp(name, benchs[i].name); i++ )
         assert( i < MAX_FUNCS );
     if( !benchs[i].name )
         benchs[i].name = strdup( name );
     if( !cpu )
         return &benchs[i].vers[0];
-    for( j=1; benchs[i].vers[j].cpu && benchs[i].vers[j].cpu != cpu; j++ )
+    for( j = 1; benchs[i].vers[j].cpu && benchs[i].vers[j].cpu != cpu; j++ )
         assert( j < MAX_CPUS );
     benchs[i].vers[j].cpu = cpu;
     return &benchs[i].vers[j];
@@ -118,41 +118,45 @@ static int cmp_bench( const void *a, const void *b )
     // asciibetical sort except preserving numbers
     const char *sa = ((bench_func_t*)a)->name;
     const char *sb = ((bench_func_t*)b)->name;
-    for(;; sa++, sb++)
+    for( ;; sa++, sb++ )
     {
-        if( !*sa && !*sb ) return 0;
-        if( isdigit(*sa) && isdigit(*sb) && isdigit(sa[1]) != isdigit(sb[1]) )
-            return isdigit(sa[1]) - isdigit(sb[1]);
-        if( *sa != *sb ) return *sa - *sb;
+        if( !*sa && !*sb )
+            return 0;
+        if( isdigit( *sa ) && isdigit( *sb ) && isdigit( sa[1] ) != isdigit( sb[1] ) )
+            return isdigit( sa[1] ) - isdigit( sb[1] );
+        if( *sa != *sb )
+            return *sa - *sb;
     }
 }
 
 static void print_bench(void)
 {
     uint16_t nops[10000] = {0};
-    int i, j, k, nfuncs, nop_time=0;
+    int nfuncs, nop_time=0;
 
-    for( i=0; i<10000; i++ )
+    for( int i = 0; i < 10000; i++ )
     {
         int t = read_time();
         nops[i] = read_time() - t;
     }
     qsort( nops, 10000, sizeof(uint16_t), cmp_nop );
-    for( i=500; i<9500; i++ )
+    for( int i = 500; i < 9500; i++ )
         nop_time += nops[i];
     nop_time /= 900;
     printf( "nop: %d\n", nop_time );
 
-    for( i=0; i<MAX_FUNCS && benchs[i].name; i++ );
-    nfuncs=i;
+    for( nfuncs = 0; nfuncs < MAX_FUNCS && benchs[nfuncs].name; nfuncs++ );
     qsort( benchs, nfuncs, sizeof(bench_func_t), cmp_bench );
-    for( i=0; i<nfuncs; i++ )
-        for( j=0; j<MAX_CPUS && (!j || benchs[i].vers[j].cpu); j++ )
+    for( int i = 0; i < nfuncs; i++ )
+        for( int j = 0; j < MAX_CPUS && (!j || benchs[i].vers[j].cpu); j++ )
         {
+            int k;
             bench_t *b = &benchs[i].vers[j];
-            if( !b->den ) continue;
-            for( k=0; k<j && benchs[i].vers[k].pointer != b->pointer; k++ );
-            if( k<j ) continue;
+            if( !b->den )
+                continue;
+            for( k = 0; k < j && benchs[i].vers[k].pointer != b->pointer; k++ );
+            if( k < j )
+                continue;
             printf( "%s_%s%s: %"PRId64"\n", benchs[i].name,
                     b->cpu&X264_CPU_SSE4 ? "sse4" :
                     b->cpu&X264_CPU_SHUFFLE_IS_FAST ? "fastshuffle" :
@@ -196,9 +200,8 @@ intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... );
     {\
         uint32_t tsum = 0;\
         int tcount = 0;\
-        int ti;\
         call_a1(func, __VA_ARGS__);\
-        for( ti=0; ti<(cpu?BENCH_RUNS:BENCH_RUNS/4); ti++ )\
+        for( int ti = 0; ti < (cpu?BENCH_RUNS:BENCH_RUNS/4); ti++ )\
         {\
             uint32_t t = read_time();\
             func(__VA_ARGS__);\
@@ -239,7 +242,6 @@ static int check_pixel( int cpu_ref, int cpu_new )
     ALIGNED_16( uint8_t edge[33] );
     uint16_t cost_mv[32];
     int ret = 0, ok, used_asm;
-    int i, j;
 
     x264_pixel_init( 0, &pixel_c );
     x264_pixel_init( cpu_ref, &pixel_ref );
@@ -251,7 +253,7 @@ static int check_pixel( int cpu_ref, int cpu_new )
     predict_8x8_filter( buf2+40, edge, ALL_NEIGHBORS, ALL_NEIGHBORS );
 
     // maximize sum
-    for( i=0; i<256; i++ )
+    for( int i = 0; i < 256; i++ )
     {
         int z = i|(i>>4);
         z ^= z>>2;
@@ -259,18 +261,19 @@ static int check_pixel( int cpu_ref, int cpu_new )
         buf3[i] = ~(buf4[i] = -(z&1));
     }
     // random pattern made of maxed pixel differences, in case an intermediate value overflows
-    for( ; i<0x1000; i++ )
+    for( int i = 256; i < 0x1000; i++ )
         buf3[i] = ~(buf4[i] = -(buf1[i&~0x88]&1));
 
 #define TEST_PIXEL( name, align ) \
-    for( i = 0, ok = 1, used_asm = 0; i < 7; i++ ) \
+    ok = 1, used_asm = 0;\
+    for( int i = 0; i < 7; i++ ) \
     { \
         int res_c, res_asm; \
         if( pixel_asm.name[i] != pixel_ref.name[i] ) \
         { \
             set_func_name( "%s_%s", #name, pixel_names[i] ); \
             used_asm = 1; \
-            for( j=0; j<64; j++ ) \
+            for( int j = 0; j < 64; j++ ) \
             { \
                 res_c   = call_c( pixel_c.name[i], buf1, 16, buf2+j*!align, 64 ); \
                 res_asm = call_a( pixel_asm.name[i], buf1, 16, buf2+j*!align, 64 ); \
@@ -281,7 +284,7 @@ static int check_pixel( int cpu_ref, int cpu_new )
                     break; \
                 } \
             } \
-            for( j=0; j<0x1000 && ok; j+=256 ) \
+            for( int j = 0; j < 0x1000 && ok; j += 256 ) \
             { \
                 res_c   = pixel_c  .name[i]( buf3+j, 16, buf4+j, 16 ); \
                 res_asm = pixel_asm.name[i]( buf3+j, 16, buf4+j, 16 ); \
@@ -302,20 +305,21 @@ static int check_pixel( int cpu_ref, int cpu_new )
     TEST_PIXEL( sa8d, 1 );
 
 #define TEST_PIXEL_X( N ) \
-    for( i = 0, ok = 1, used_asm = 0; i < 7; i++ ) \
+    ok = 1; used_asm = 0;\
+    for( int i = 0; i < 7; i++ ) \
     { \
         int res_c[4]={0}, res_asm[4]={0}; \
         if( pixel_asm.sad_x##N[i] && pixel_asm.sad_x##N[i] != pixel_ref.sad_x##N[i] ) \
         { \
             set_func_name( "sad_x%d_%s", N, pixel_names[i] ); \
             used_asm = 1; \
-            for( j=0; j<64; j++) \
+            for( int j = 0; j < 64; j++ ) \
             { \
                 uint8_t *pix2 = buf2+j; \
                 res_c[0] = pixel_c.sad[i]( buf1, 16, pix2, 64 ); \
                 res_c[1] = pixel_c.sad[i]( buf1, 16, pix2+6, 64 ); \
                 res_c[2] = pixel_c.sad[i]( buf1, 16, pix2+1, 64 ); \
-                if(N==4) \
+                if( N == 4 ) \
                 { \
                     res_c[3] = pixel_c.sad[i]( buf1, 16, pix2+10, 64 ); \
                     call_a( pixel_asm.sad_x4[i], buf1, pix2, pix2+6, pix2+1, pix2+10, 64, res_asm ); \
@@ -329,7 +333,7 @@ static int check_pixel( int cpu_ref, int cpu_new )
                              i, res_c[0], res_c[1], res_c[2], res_c[3], \
                              res_asm[0], res_asm[1], res_asm[2], res_asm[3] ); \
                 } \
-                if(N==4) \
+                if( N == 4 ) \
                     call_c2( pixel_c.sad_x4[i], buf1, pix2, pix2+6, pix2+1, pix2+10, 64, res_asm ); \
                 else \
                     call_c2( pixel_c.sad_x3[i], buf1, pix2, pix2+6, pix2+1, 64, res_asm ); \
@@ -376,18 +380,19 @@ static int check_pixel( int cpu_ref, int cpu_new )
         if( res_c != res_asm || ssd_c != ssd_asm )
         {
             ok = 0;
-            fprintf( stderr, "var[%d]: %d != %d or %d != %d [FAILED]\n", i, res_c, res_asm, ssd_c, ssd_asm );
+            fprintf( stderr, "var2_8x8: %d != %d or %d != %d [FAILED]\n", res_c, res_asm, ssd_c, ssd_asm );
         }
     }
 
     report( "pixel var2 :" );
 
-    for( i=0, ok=1, used_asm=0; i<4; i++ )
+    ok = 1; used_asm = 0;
+    for( int i = 0; i < 4; i++ )
         if( pixel_asm.hadamard_ac[i] != pixel_ref.hadamard_ac[i] )
         {
             set_func_name( "hadamard_ac_%s", pixel_names[i] );
             used_asm = 1;
-            for( j=0; j<32; j++ )
+            for( int j = 0; j < 32; j++ )
             {
                 uint8_t *pix = (j&16 ? buf1 : buf3) + (j&15)*256;
                 call_c1( pixel_c.hadamard_ac[i], buf1, 16 );
@@ -413,7 +418,7 @@ static int check_pixel( int cpu_ref, int cpu_new )
         set_func_name( #name );\
         used_asm = 1; \
         memcpy( buf3, buf2, 1024 ); \
-        for( i=0; i<3; i++ ) \
+        for( int i = 0; i < 3; i++ ) \
         { \
             pred[i]( buf3+48, ##__VA_ARGS__ ); \
             res_c[i] = pixel_c.satd( buf1+48, 16, buf3+48, 32 ); \
@@ -449,7 +454,7 @@ static int check_pixel( int cpu_ref, int cpu_new )
         x264_emms();
         res_c = x264_pixel_ssim_wxh( &pixel_c,   buf1+2, 32, buf2+2, 32, 32, 28, buf3 );
         res_a = x264_pixel_ssim_wxh( &pixel_asm, buf1+2, 32, buf2+2, 32, 32, 28, buf3 );
-        if( fabs(res_c - res_a) > 1e-6 )
+        if( fabs( res_c - res_a ) > 1e-6 )
         {
             ok = 0;
             fprintf( stderr, "ssim: %.7f != %.7f [FAILED]\n", res_c, res_a );
@@ -464,9 +469,9 @@ static int check_pixel( int cpu_ref, int cpu_new )
     }
 
     ok = 1; used_asm = 0;
-    for( i=0; i<32; i++ )
+    for( int i = 0; i < 32; i++ )
         cost_mv[i] = i*10;
-    for( i=0; i<100 && ok; i++ )
+    for( int i = 0; i < 100 && ok; i++ )
         if( pixel_asm.ads[i&3] != pixel_ref.ads[i&3] )
         {
             ALIGNED_16( uint16_t sums[72] );
@@ -475,9 +480,9 @@ static int check_pixel( int cpu_ref, int cpu_new )
             int mvn_a, mvn_c;
             int thresh = rand() & 0x3fff;
             set_func_name( "esa_ads" );
-            for( j=0; j<72; j++ )
+            for( int j = 0; j < 72; j++ )
                 sums[j] = rand() & 0x3fff;
-            for( j=0; j<4; j++ )
+            for( int j = 0; j < 4; j++ )
                 dc[j] = rand() & 0x3fff;
             used_asm = 1;
             mvn_c = call_c( pixel_c.ads[i&3], dc, sums, 32, cost_mv, mvs_c, 28, thresh );
@@ -485,13 +490,13 @@ static int check_pixel( int cpu_ref, int cpu_new )
             if( mvn_c != mvn_a || memcmp( mvs_c, mvs_a, mvn_c*sizeof(*mvs_c) ) )
             {
                 ok = 0;
-                printf("c%d: ", i&3);
-                for(j=0; j<mvn_c; j++)
-                    printf("%d ", mvs_c[j]);
-                printf("\na%d: ", i&3);
-                for(j=0; j<mvn_a; j++)
-                    printf("%d ", mvs_a[j]);
-                printf("\n\n");
+                printf( "c%d: ", i&3 );
+                for( int j = 0; j < mvn_c; j++ )
+                    printf( "%d ", mvs_c[j] );
+                printf( "\na%d: ", i&3 );
+                for( int j = 0; j < mvn_a; j++ )
+                    printf( "%d ", mvs_a[j] );
+                printf( "\n\n" );
             }
         }
     report( "esa ads:" );
@@ -505,7 +510,7 @@ static int check_dct( int cpu_ref, int cpu_new )
     x264_dct_function_t dct_ref;
     x264_dct_function_t dct_asm;
     x264_quant_function_t qf;
-    int ret = 0, ok, used_asm, i, j, interlace;
+    int ret = 0, ok, used_asm, interlace;
     ALIGNED_16( int16_t dct1[16][16] );
     ALIGNED_16( int16_t dct2[16][16] );
     ALIGNED_16( int16_t dct4[16][16] );
@@ -525,7 +530,7 @@ static int check_dct( int cpu_ref, int cpu_new )
     h->param.analyse.i_luma_deadzone[0] = 0;
     h->param.analyse.i_luma_deadzone[1] = 0;
     h->param.analyse.b_transform_8x8 = 1;
-    for( i=0; i<6; i++ )
+    for( int i = 0; i < 6; i++ )
         h->pps->scaling_list[i] = x264_cqm_flat16;
     x264_cqm_init( h );
     x264_quant_init( h, 0, &qf );
@@ -560,12 +565,12 @@ static int check_dct( int cpu_ref, int cpu_new )
     // is needed to force the coefs into the right range.
     dct_c.sub16x16_dct( dct4, buf1, buf2 );
     dct_c.sub16x16_dct8( dct8, buf1, buf2 );
-    for( i=0; i<16; i++ )
+    for( int i = 0; i < 16; i++ )
     {
         qf.quant_4x4( dct4[i], h->quant4_mf[CQM_4IY][20], h->quant4_bias[CQM_4IY][20] );
         qf.dequant_4x4( dct4[i], h->dequant4_mf[CQM_4IY], 20 );
     }
-    for( i=0; i<4; i++ )
+    for( int i = 0; i < 4; i++ )
     {
         qf.quant_8x8( dct8[i], h->quant8_mf[CQM_8IY][20], h->quant8_bias[CQM_8IY][20] );
         qf.dequant_8x8( dct8[i], h->dequant8_mf[CQM_8IY], 20 );
@@ -611,9 +616,9 @@ static int check_dct( int cpu_ref, int cpu_new )
         set_func_name( #name );\
         used_asm = 1;\
         uint16_t *p = (uint16_t*)buf1;\
-        for( i=0; i<16 && ok; i++ )\
+        for( int i = 0; i < 16 && ok; i++ )\
         {\
-            for( j=0; j<16; j++ )\
+            for( int j = 0; j < 16; j++ )\
                 dct1[0][j] = !i ? (j^j>>1^j>>2^j>>3)&1 ? 4080 : -4080 /* max dc */\
                            : i<8 ? (*p++)&1 ? 4080 : -4080 /* max elements */\
                            : ((*p++)&0x1fff)-0x1000; /* general case */\
@@ -680,11 +685,11 @@ static int check_dct( int cpu_ref, int cpu_new )
         int16_t dc_a, dc_c; \
         set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
         used_asm = 1; \
-        for( i = 0; i < 2; i++ ) \
+        for( int i = 0; i < 2; i++ ) \
         { \
             memcpy( buf3, buf2, 16*FDEC_STRIDE ); \
             memcpy( buf4, buf2, 16*FDEC_STRIDE ); \
-            for( j = 0; j < 4; j++ ) \
+            for( int j = 0; j < 4; j++ ) \
             { \
                 memcpy( buf3 + j*FDEC_STRIDE, (i?buf1:buf2) + j*FENC_STRIDE, 4 ); \
                 memcpy( buf4 + j*FDEC_STRIDE, (i?buf1:buf2) + j*FENC_STRIDE, 4 ); \
@@ -705,12 +710,12 @@ static int check_dct( int cpu_ref, int cpu_new )
 #define TEST_INTERLEAVE( name, t1, t2, dct, size )   \
     if( zigzag_asm.name != zigzag_ref.name ) \
     { \
-        for( j=0; j<100; j++ ) \
+        for( int j = 0; j < 100; j++ ) \
         { \
             set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
             used_asm = 1; \
             memcpy(dct, buf1, size*sizeof(int16_t));\
-            for( i=0; i<size; i++ ) \
+            for( int i = 0; i < size; i++ ) \
                 dct[i] = rand()&0x1F ? 0 : dct[i]; \
             memcpy(buf3, buf4, 10*sizeof(uint8_t)); \
             call_c( zigzag_c.name, t1, dct, buf3 ); \
@@ -768,7 +773,6 @@ static int check_mc( int cpu_ref, int cpu_new )
     uint8_t *dst1    = buf3;
     uint8_t *dst2    = buf4;
 
-    int dx, dy, i, j, k, w;
     int ret = 0, ok, used_asm;
 
     x264_mc_init( 0, &mc_c );
@@ -782,8 +786,8 @@ static int check_mc( int cpu_ref, int cpu_new )
             const x264_weight_t *weight = weight_none; \
             set_func_name( "mc_luma_%dx%d", w, h );\
             used_asm = 1; \
-            memset(buf3, 0xCD, 1024); \
-            memset(buf4, 0xCD, 1024); \
+            memset( buf3, 0xCD, 1024 ); \
+            memset( buf4, 0xCD, 1024 ); \
             call_c( mc_c.mc_luma, dst1, 32, src2, 64, dx, dy, w, h, weight ); \
             call_a( mc_a.mc_luma, dst2, 32, src2, 64, dx, dy, w, h, weight ); \
             if( memcmp( buf3, buf4, 1024 ) ) \
@@ -799,11 +803,11 @@ static int check_mc( int cpu_ref, int cpu_new )
             const x264_weight_t *weight = weight_none; \
             set_func_name( "get_ref_%dx%d", w, h );\
             used_asm = 1; \
-            memset(buf3, 0xCD, 1024); \
-            memset(buf4, 0xCD, 1024); \
+            memset( buf3, 0xCD, 1024 ); \
+            memset( buf4, 0xCD, 1024 ); \
             call_c( mc_c.mc_luma, dst1, 32, src2, 64, dx, dy, w, h, weight ); \
             ref = (uint8_t*) call_a( mc_a.get_ref, ref, &ref_stride, src2, 64, dx, dy, w, h, weight ); \
-            for( i=0; i<h; i++ ) \
+            for( int i = 0; i < h; i++ ) \
                 if( memcmp( dst1+i*32, ref+i*ref_stride, w ) ) \
                 { \
                     fprintf( stderr, "get_ref[mv(%d,%d) %2dx%-2d]     [FAILED]\n", dx, dy, w, h ); \
@@ -817,13 +821,13 @@ static int check_mc( int cpu_ref, int cpu_new )
         { \
             set_func_name( "mc_chroma_%dx%d", w, h );\
             used_asm = 1; \
-            memset(buf3, 0xCD, 1024); \
-            memset(buf4, 0xCD, 1024); \
+            memset( buf3, 0xCD, 1024 ); \
+            memset( buf4, 0xCD, 1024 ); \
             call_c( mc_c.mc_chroma, dst1, 16, src, 64, dx, dy, w, h ); \
             call_a( mc_a.mc_chroma, dst2, 16, src, 64, dx, dy, w, h ); \
             /* mc_chroma width=2 may write garbage to the right of dst. ignore that. */\
-            for( j=0; j<h; j++ ) \
-                for( i=w; i<4; i++ ) \
+            for( int j = 0; j < h; j++ ) \
+                for( int i = w; i < 4; i++ ) \
                     dst2[i+j*16] = dst1[i+j*16]; \
             if( memcmp( buf3, buf4, 1024 ) ) \
             { \
@@ -832,8 +836,8 @@ static int check_mc( int cpu_ref, int cpu_new )
             } \
         }
     ok = 1; used_asm = 0;
-    for( dy = -8; dy < 8; dy++ )
-        for( dx = -128; dx < 128; dx++ )
+    for( int dy = -8; dy < 8; dy++ )
+        for( int dx = -128; dx < 128; dx++ )
         {
             if( rand()&15 ) continue; // running all of them is too slow
             MC_TEST_LUMA( 20, 18 );
@@ -849,8 +853,8 @@ static int check_mc( int cpu_ref, int cpu_new )
     report( "mc luma :" );
 
     ok = 1; used_asm = 0;
-    for( dy = -1; dy < 9; dy++ )
-        for( dx = -128; dx < 128; dx++ )
+    for( int dy = -1; dy < 9; dy++ )
+        for( int dx = -128; dx < 128; dx++ )
         {
             if( rand()&15 ) continue;
             MC_TEST_CHROMA( 8, 8 );
@@ -866,7 +870,9 @@ static int check_mc( int cpu_ref, int cpu_new )
 #undef MC_TEST_CHROMA
 
 #define MC_TEST_AVG( name, weight ) \
-    for( i = 0, ok = 1, used_asm = 0; i < 10; i++ ) \
+{ \
+    ok = 1, used_asm = 0; \
+    for( int i = 0; i < 10; i++ ) \
     { \
         memcpy( buf3, buf1+320, 320 ); \
         memcpy( buf4, buf1+320, 320 ); \
@@ -884,19 +890,21 @@ static int check_mc( int cpu_ref, int cpu_new )
             call_c2( mc_c.name[i], buf3, 16, buf2+1, 16, buf1+18, 16, weight ); \
             call_a2( mc_a.name[i], buf4, 16, buf2+1, 16, buf1+18, 16, weight ); \
         } \
-    }
-    ok = 1; used_asm = 0;
-    for( w = -63; w <= 127 && ok; w++ )
+    } \
+}
+
+    for( int w = -63; w <= 127 && ok; w++ )
         MC_TEST_AVG( avg, w );
     report( "mc wpredb :" );
 
 #define MC_TEST_WEIGHT( name, weight, aligned ) \
     int align_off = (aligned ? 0 : rand()%16); \
-    for( i = 1, ok = 1, used_asm = 0; i <= 5; i++ ) \
+    ok = 1, used_asm = 0;\
+    for( int i = 1; i <= 5; i++ ) \
     { \
         ALIGNED_16( uint8_t buffC[640] ); \
         ALIGNED_16( uint8_t buffA[640] ); \
-        j = X264_MAX( i*4, 2 ); \
+        int j = X264_MAX( i*4, 2 ); \
         memset( buffC, 0, 640 ); \
         memset( buffA, 0, 640 ); \
         x264_t ha; \
@@ -906,13 +914,12 @@ static int check_mc( int cpu_ref, int cpu_new )
             continue; \
         if( mc_a.name[i] != mc_ref.name[i] ) \
         { \
-            int k; \
             set_func_name( "%s_w%d", #name, j ); \
             used_asm = 1; \
             call_c1( mc_c.weight[i], buffC, 32, buf2+align_off, 32, &weight, 16 ); \
             mc_a.weight_cache(&ha, &weight); \
             call_a1( weight.weightfn[i], buffA, 32, buf2+align_off, 32, &weight, 16 ); \
-            for( k = 0; k < 16; k++ ) \
+            for( int k = 0; k < 16; k++ ) \
                 if( memcmp( &buffC[k*32], &buffA[k*32], j ) ) \
                 { \
                     ok = 0; \
@@ -926,14 +933,13 @@ static int check_mc( int cpu_ref, int cpu_new )
 
     ok = 1; used_asm = 0;
 
-    int s,o,d;
     int align_cnt = 0;
-    for( s = 0; s <= 127 && ok; s++ )
+    for( int s = 0; s <= 127 && ok; s++ )
     {
-        for( o = -128; o <= 127 && ok; o++ )
+        for( int o = -128; o <= 127 && ok; o++ )
         {
             if( rand() & 2047 ) continue;
-            for( d = 0; d <= 7 && ok; d++ )
+            for( int d = 0; d <= 7 && ok; d++ )
             {
                 if( s == 1<<d )
                     continue;
@@ -946,17 +952,18 @@ static int check_mc( int cpu_ref, int cpu_new )
     report( "mc weight :" );
 
     ok = 1; used_asm = 0;
-    s = 1; d = 0;
-    for( o = 0; o <= 127 && ok; o++ )
+    for( int o = 0; o <= 127 && ok; o++ )
     {
+        int s = 1, d = 0;
         if( rand() & 15 ) continue;
         x264_weight_t weight = { .i_scale = 1, .i_denom = 0, .i_offset = o };
         MC_TEST_WEIGHT( offsetadd, weight, (align_cnt++ % 4) );
     }
     report( "mc offsetadd :" );
     ok = 1; used_asm = 0;
-    for( o = -128; o < 0 && ok; o++ )
+    for( int o = -128; o < 0 && ok; o++ )
     {
+        int s = 1, d = 0;
         if( rand() & 15 ) continue;
         x264_weight_t weight = { .i_scale = 1, .i_denom = 0, .i_offset = o };
         MC_TEST_WEIGHT( offsetsub, weight, (align_cnt++ % 4) );
@@ -965,7 +972,7 @@ static int check_mc( int cpu_ref, int cpu_new )
 
     if( mc_a.hpel_filter != mc_ref.hpel_filter )
     {
-        uint8_t *src = buf1+8+2*64;
+        uint8_t *srchpel = buf1+8+2*64;
         uint8_t *dstc[3] = { buf3+8, buf3+8+16*64, buf3+8+32*64 };
         uint8_t *dsta[3] = { buf4+8, buf4+8+16*64, buf4+8+32*64 };
         void *tmp = buf3+49*64;
@@ -973,21 +980,21 @@ static int check_mc( int cpu_ref, int cpu_new )
         ok = 1; used_asm = 1;
         memset( buf3, 0, 4096 );
         memset( buf4, 0, 4096 );
-        call_c( mc_c.hpel_filter, dstc[0], dstc[1], dstc[2], src, 64, 48, 10, tmp );
-        call_a( mc_a.hpel_filter, dsta[0], dsta[1], dsta[2], src, 64, 48, 10, tmp );
-        for( i=0; i<3; i++ )
-            for( j=0; j<10; j++ )
+        call_c( mc_c.hpel_filter, dstc[0], dstc[1], dstc[2], srchpel, 64, 48, 10, tmp );
+        call_a( mc_a.hpel_filter, dsta[0], dsta[1], dsta[2], srchpel, 64, 48, 10, tmp );
+        for( int i = 0; i < 3; i++ )
+            for( int j = 0; j < 10; j++ )
                 //FIXME ideally the first pixels would match too, but they aren't actually used
                 if( memcmp( dstc[i]+j*64+2, dsta[i]+j*64+2, 43 ) )
                 {
                     ok = 0;
                     fprintf( stderr, "hpel filter differs at plane %c line %d\n", "hvc"[i], j );
-                    for( k=0; k<48; k++ )
-                        printf("%02x%s", dstc[i][j*64+k], (k+1)&3 ? "" : " ");
-                    printf("\n");
-                    for( k=0; k<48; k++ )
-                        printf("%02x%s", dsta[i][j*64+k], (k+1)&3 ? "" : " ");
-                    printf("\n");
+                    for( int k = 0; k < 48; k++ )
+                        printf( "%02x%s", dstc[i][j*64+k], (k+1)&3 ? "" : " " );
+                    printf( "\n" );
+                    for( int k = 0; k < 48; k++ )
+                        printf( "%02x%s", dsta[i][j*64+k], (k+1)&3 ? "" : " " );
+                    printf( "\n" );
                     break;
                 }
         report( "hpel filter :" );
@@ -999,24 +1006,24 @@ static int check_mc( int cpu_ref, int cpu_new )
         uint8_t *dsta[4] = { buf4, buf4+1024, buf4+2048, buf4+3072 };
         set_func_name( "lowres_init" );
         ok = 1; used_asm = 1;
-        for( w=40; w<=48; w+=8 )
+        for( int w = 40; w <= 48; w += 8 )
         {
             int stride = (w+8)&~15;
             call_c( mc_c.frame_init_lowres_core, buf1, dstc[0], dstc[1], dstc[2], dstc[3], w*2, stride, w, 16 );
             call_a( mc_a.frame_init_lowres_core, buf1, dsta[0], dsta[1], dsta[2], dsta[3], w*2, stride, w, 16 );
-            for( i=0; i<16; i++)
+            for( int i = 0; i < 16; i++ )
             {
-                for( j=0; j<4; j++)
+                for( int j = 0; j < 4; j++ )
                     if( memcmp( dstc[j]+i*stride, dsta[j]+i*stride, w ) )
                     {
                         ok = 0;
                         fprintf( stderr, "frame_init_lowres differs at plane %d line %d\n", j, i );
-                        for( k=0; k<w; k++ )
+                        for( int k = 0; k < w; k++ )
                             printf( "%d ", dstc[j][k+i*stride] );
-                        printf("\n");
-                        for( k=0; k<w; k++ )
+                        printf( "\n" );
+                        for( int k = 0; k < w; k++ )
                             printf( "%d ", dsta[j][k+i*stride] );
-                        printf("\n");
+                        printf( "\n" );
                         break;
                     }
             }
@@ -1059,21 +1066,21 @@ static int check_mc( int cpu_ref, int cpu_new )
         uint16_t *intra = (uint16_t*)buf4;
         uint16_t *inter = intra+400;
         uint16_t *qscale = inter+400;
-        uint16_t *rand = (uint16_t*)buf2;
+        uint16_t *rnd = (uint16_t*)buf2;
         x264_emms();
-        for( i=0; i<400; i++ )
+        for( int i = 0; i < 400; i++ )
         {
-            intra[i]  = *rand++ & 0x7fff;
+            intra[i]  = *rnd++ & 0x7fff;
             intra[i] += !intra[i];
-            inter[i]  = *rand++ & 0x7fff;
-            qscale[i] = *rand++ & 0x7fff;
+            inter[i]  = *rnd++ & 0x7fff;
+            qscale[i] = *rnd++ & 0x7fff;
         }
         call_c( mc_c.mbtree_propagate_cost, dstc, prop, intra, inter, qscale, 400 );
         call_a( mc_a.mbtree_propagate_cost, dsta, prop, intra, inter, qscale, 400 );
         // I don't care about exact rounding, this is just how close the floating-point implementation happens to be
         x264_emms();
-        for( i=0; i<400; i++ )
-            ok &= abs(dstc[i]-dsta[i]) <= (abs(dstc[i])>512) || fabs((double)dstc[i]/dsta[i]-1) < 1e-6;
+        for( int i = 0; i < 400; i++ )
+            ok &= abs( dstc[i]-dsta[i] ) <= (abs( dstc[i])>512 ) || fabs( (double)dstc[i]/dsta[i]-1 ) < 1e-6;
         report( "mbtree propagate :" );
     }
 
@@ -1088,16 +1095,15 @@ static int check_deblock( int cpu_ref, int cpu_new )
     int ret = 0, ok = 1, used_asm = 0;
     int alphas[36], betas[36];
     int8_t tcs[36][4];
-    int a, c, i, j;
 
     x264_deblock_init( 0, &db_c );
     x264_deblock_init( cpu_ref, &db_ref );
     x264_deblock_init( cpu_new, &db_a );
 
     /* not exactly the real values of a,b,tc but close enough */
-    a = 255; c = 250;
-    for( i = 35; i >= 0; i-- )
+    for( int i = 35; i >= 0; i-- )
     {
+        int a = 255, c = 250;
         alphas[i] = a;
         betas[i] = (i+1)/2;
         tcs[i][0] = tcs[i][2] = (c+6)/10;
@@ -1107,10 +1113,10 @@ static int check_deblock( int cpu_ref, int cpu_new )
     }
 
 #define TEST_DEBLOCK( name, align, ... ) \
-    for( i = 0; i < 36; i++ ) \
+    for( int i = 0; i < 36; i++ ) \
     { \
         int off = 8*32 + (i&15)*4*!align; /* benchmark various alignments of h filter */\
-        for( j = 0; j < 1024; j++ ) \
+        for( int j = 0; j < 1024; j++ ) \
             /* two distributions of random to excersize different failure modes */\
             buf3[j] = rand() & (i&1 ? 0xf : 0xff ); \
         memcpy( buf4, buf3, 1024 ); \
@@ -1155,7 +1161,6 @@ static int check_quant( int cpu_ref, int cpu_new )
     ALIGNED_16( uint8_t cqm_buf[64] );
     int ret = 0, ok, used_asm;
     int oks[2] = {1,1}, used_asms[2] = {0,0};
-    int i, j, i_cqm, qp;
     x264_t h_buf;
     x264_t *h = &h_buf;
     memset( h, 0, sizeof(*h) );
@@ -1165,29 +1170,29 @@ static int check_quant( int cpu_ref, int cpu_new )
     h->param.rc.i_qp_min = 26;
     h->param.analyse.b_transform_8x8 = 1;
 
-    for( i_cqm = 0; i_cqm < 4; i_cqm++ )
+    for( int i_cqm = 0; i_cqm < 4; i_cqm++ )
     {
         if( i_cqm == 0 )
         {
-            for( i = 0; i < 6; i++ )
+            for( int i = 0; i < 6; i++ )
                 h->pps->scaling_list[i] = x264_cqm_flat16;
             h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_FLAT;
         }
         else if( i_cqm == 1 )
         {
-            for( i = 0; i < 6; i++ )
+            for( int i = 0; i < 6; i++ )
                 h->pps->scaling_list[i] = x264_cqm_jvt[i];
             h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_JVT;
         }
         else
         {
             if( i_cqm == 2 )
-                for( i = 0; i < 64; i++ )
+                for( int i = 0; i < 64; i++ )
                     cqm_buf[i] = 10 + rand() % 246;
             else
-                for( i = 0; i < 64; i++ )
+                for( int i = 0; i < 64; i++ )
                     cqm_buf[i] = 1;
-            for( i = 0; i < 6; i++ )
+            for( int i = 0; i < 6; i++ )
                 h->pps->scaling_list[i] = cqm_buf;
             h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_CUSTOM;
         }
@@ -1197,20 +1202,20 @@ static int check_quant( int cpu_ref, int cpu_new )
         x264_quant_init( h, cpu_ref, &qf_ref );
         x264_quant_init( h, cpu_new, &qf_a );
 
-#define INIT_QUANT8() \
+#define INIT_QUANT8(j) \
         { \
             static const int scale1d[8] = {32,31,24,31,32,31,24,31}; \
-            for( i = 0; i < 64; i++ ) \
+            for( int i = 0; i < 64; i++ ) \
             { \
                 unsigned int scale = (255*scale1d[i>>3]*scale1d[i&7])/16; \
                 dct1[i] = dct2[i] = j ? (rand()%(2*scale+1))-scale : 0; \
             } \
         }
 
-#define INIT_QUANT4() \
+#define INIT_QUANT4(j) \
         { \
             static const int scale1d[4] = {4,6,4,6}; \
-            for( i = 0; i < 16; i++ ) \
+            for( int i = 0; i < 16; i++ ) \
             { \
                 unsigned int scale = 255*scale1d[i>>2]*scale1d[i&3]; \
                 dct1[i] = dct2[i] = j ? (rand()%(2*scale+1))-scale : 0; \
@@ -1222,12 +1227,12 @@ static int check_quant( int cpu_ref, int cpu_new )
         { \
             set_func_name( #name ); \
             used_asms[0] = 1; \
-            for( qp = 51; qp > 0; qp-- ) \
+            for( int qp = 51; qp > 0; qp-- ) \
             { \
-                for( j = 0; j < 2; j++ ) \
+                for( int j = 0; j < 2; j++ ) \
                 { \
                     int result_c, result_a; \
-                    for( i = 0; i < 16; i++ ) \
+                    for( int i = 0; i < 16; i++ ) \
                         dct1[i] = dct2[i] = j ? (rand() & 0x1fff) - 0xfff : 0; \
                     result_c = call_c1( qf_c.name, dct1, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
                     result_a = call_a1( qf_a.name, dct2, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
@@ -1248,14 +1253,13 @@ static int check_quant( int cpu_ref, int cpu_new )
         { \
             set_func_name( #qname ); \
             used_asms[0] = 1; \
-            for( qp = 51; qp > 0; qp-- ) \
+            for( int qp = 51; qp > 0; qp-- ) \
             { \
-                for( j = 0; j < 2; j++ ) \
+                for( int j = 0; j < 2; j++ ) \
                 { \
-                    int result_c, result_a; \
-                    INIT_QUANT##w() \
-                    result_c = call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
-                    result_a = call_a1( qf_a.qname, dct2, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
+                    INIT_QUANT##w(j) \
+                    int result_c = call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
+                    int result_a = call_a1( qf_a.qname, dct2, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
                     if( memcmp( dct1, dct2, w*w*2 ) || result_c != result_a ) \
                     { \
                         oks[0] = 0; \
@@ -1280,10 +1284,9 @@ static int check_quant( int cpu_ref, int cpu_new )
         { \
             set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
             used_asms[1] = 1; \
-            j = 1; \
-            for( qp = 51; qp > 0; qp-- ) \
+            for( int qp = 51; qp > 0; qp-- ) \
             { \
-                INIT_QUANT##w() \
+                INIT_QUANT##w(1) \
                 call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
                 memcpy( dct2, dct1, w*w*2 ); \
                 call_c1( qf_c.dqname, dct1, h->dequant##w##_mf[block], qp ); \
@@ -1309,9 +1312,9 @@ static int check_quant( int cpu_ref, int cpu_new )
         { \
             set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
             used_asms[1] = 1; \
-            for( qp = 51; qp > 0; qp-- ) \
+            for( int qp = 51; qp > 0; qp-- ) \
             { \
-                for( i = 0; i < 16; i++ ) \
+                for( int i = 0; i < 16; i++ ) \
                     dct1[i] = rand(); \
                 call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp][0]>>1, h->quant##w##_bias[block][qp][0]>>1 ); \
                 memcpy( dct2, dct1, w*w*2 ); \
@@ -1341,14 +1344,13 @@ static int check_quant( int cpu_ref, int cpu_new )
     ok = 1; used_asm = 0;
     if( qf_a.denoise_dct != qf_ref.denoise_dct )
     {
-        int size;
         used_asm = 1;
-        for( size = 16; size <= 64; size += 48 )
+        for( int size = 16; size <= 64; size += 48 )
         {
             set_func_name( "denoise_dct" );
-            memcpy(dct1, buf1, size*2);
-            memcpy(dct2, buf1, size*2);
-            memcpy(buf3+256, buf3, 256);
+            memcpy( dct1, buf1, size*2 );
+            memcpy( dct2, buf1, size*2 );
+            memcpy( buf3+256, buf3, 256 );
             call_c1( qf_c.denoise_dct, dct1, (uint32_t*)buf3, (uint16_t*)buf2, size );
             call_a1( qf_a.denoise_dct, dct2, (uint32_t*)(buf3+256), (uint16_t*)buf2, size );
             if( memcmp( dct1, dct2, size*2 ) || memcmp( buf3+4, buf3+256+4, (size-1)*sizeof(uint32_t) ) )
@@ -1364,15 +1366,14 @@ static int check_quant( int cpu_ref, int cpu_new )
     { \
         set_func_name( #decname ); \
         used_asm = 1; \
-        for( i = 0; i < 100; i++ ) \
+        for( int i = 0; i < 100; i++ ) \
         { \
-            int result_c, result_a, idx; \
-            for( idx = 0; idx < w*w; idx++ ) \
+            for( int idx = 0; idx < w*w; idx++ ) \
                 dct1[idx] = !(rand()&3) + (!(rand()&15))*(rand()&3); \
             if( ac ) \
                 dct1[0] = 0; \
-            result_c = call_c( qf_c.decname, dct1 ); \
-            result_a = call_a( qf_a.decname, dct1 ); \
+            int result_c = call_c( qf_c.decname, dct1 ); \
+            int result_a = call_a( qf_a.decname, dct1 ); \
             if( X264_MIN(result_c,thresh) != X264_MIN(result_a,thresh) ) \
             { \
                 ok = 0; \
@@ -1393,17 +1394,17 @@ static int check_quant( int cpu_ref, int cpu_new )
     { \
         set_func_name( #lastname ); \
         used_asm = 1; \
-        for( i = 0; i < 100; i++ ) \
+        for( int i = 0; i < 100; i++ ) \
         { \
-            int result_c, result_a, idx, nnz=0; \
+            int nnz = 0; \
             int max = rand() & (w*w-1); \
             memset( dct1, 0, w*w*2 ); \
-            for( idx = ac; idx < max; idx++ ) \
+            for( int idx = ac; idx < max; idx++ ) \
                 nnz |= dct1[idx] = !(rand()&3) + (!(rand()&15))*rand(); \
             if( !nnz ) \
                 dct1[ac] = 1; \
-            result_c = call_c( qf_c.last, dct1+ac ); \
-            result_a = call_a( qf_a.last, dct1+ac ); \
+            int result_c = call_c( qf_c.last, dct1+ac ); \
+            int result_a = call_a( qf_a.last, dct1+ac ); \
             if( result_c != result_a ) \
             { \
                 ok = 0; \
@@ -1425,20 +1426,20 @@ static int check_quant( int cpu_ref, int cpu_new )
     { \
         set_func_name( #name ); \
         used_asm = 1; \
-        for( i = 0; i < 100; i++ ) \
+        for( int i = 0; i < 100; i++ ) \
         { \
             x264_run_level_t runlevel_c, runlevel_a; \
-            int result_c, result_a, idx, nnz=0; \
+            int nnz = 0; \
             int max = rand() & (w*w-1); \
             memset( dct1, 0, w*w*2 ); \
             memcpy( &runlevel_a, buf1+i, sizeof(x264_run_level_t) ); \
             memcpy( &runlevel_c, buf1+i, sizeof(x264_run_level_t) ); \
-            for( idx = ac; idx < max; idx++ ) \
+            for( int idx = ac; idx < max; idx++ ) \
                 nnz |= dct1[idx] = !(rand()&3) + (!(rand()&15))*rand(); \
             if( !nnz ) \
                 dct1[ac] = 1; \
-            result_c = call_c( qf_c.lastname, dct1+ac, &runlevel_c ); \
-            result_a = call_a( qf_a.lastname, dct1+ac, &runlevel_a ); \
+            int result_c = call_c( qf_c.lastname, dct1+ac, &runlevel_c ); \
+            int result_a = call_a( qf_a.lastname, dct1+ac, &runlevel_a ); \
             if( result_c != result_a || runlevel_c.last != runlevel_a.last || \
                 memcmp(runlevel_c.level, runlevel_a.level, sizeof(int16_t)*result_c) || \
                 memcmp(runlevel_c.run, runlevel_a.run, sizeof(uint8_t)*(result_c-1)) ) \
@@ -1462,7 +1463,6 @@ static int check_quant( int cpu_ref, int cpu_new )
 static int check_intra( int cpu_ref, int cpu_new )
 {
     int ret = 0, ok = 1, used_asm = 0;
-    int i;
     ALIGNED_16( uint8_t edge[33] );
     ALIGNED_16( uint8_t edge2[33] );
     struct
@@ -1504,40 +1504,41 @@ static int check_intra( int cpu_ref, int cpu_new )
         {\
             fprintf( stderr, #name "[%d] :  [FAILED]\n", dir );\
             ok = 0;\
-            int j,k;\
-            for(k=-1; k<16; k++)\
-                printf("%2x ", edge[16+k]);\
-            printf("\n");\
-            for(j=0; j<w; j++){\
-                printf("%2x ", edge[14-j]);\
-                for(k=0; k<w; k++)\
-                    printf("%2x ", buf4[48+k+j*32]);\
-                printf("\n");\
+            for( int k = -1; k < 16; k++ )\
+                printf( "%2x ", edge[16+k] );\
+            printf( "\n" );\
+            for( int j = 0; j < w; j++ )\
+            {\
+                printf( "%2x ", edge[14-j] );\
+                for( int k = 0; k < w; k++ )\
+                    printf( "%2x ", buf4[48+k+j*32] );\
+                printf( "\n" );\
             }\
-            printf("\n");\
-            for(j=0; j<w; j++){\
-                printf("   ");\
-                for(k=0; k<w; k++)\
-                    printf("%2x ", buf3[48+k+j*32]);\
-                printf("\n");\
+            printf( "\n" );\
+            for( int j = 0; j < w; j++ )\
+            {\
+                printf( "   " );\
+                for( int k = 0; k < w; k++ )\
+                    printf( "%2x ", buf3[48+k+j*32] );\
+                printf( "\n" );\
             }\
         }\
     }
 
-    for( i = 0; i < 12; i++ )
+    for( int i = 0; i < 12; i++ )
         INTRA_TEST( predict_4x4, i, 4 );
-    for( i = 0; i < 7; i++ )
+    for( int i = 0; i < 7; i++ )
         INTRA_TEST( predict_8x8c, i, 8 );
-    for( i = 0; i < 7; i++ )
+    for( int i = 0; i < 7; i++ )
         INTRA_TEST( predict_16x16, i, 16 );
-    for( i = 0; i < 12; i++ )
+    for( int i = 0; i < 12; i++ )
         INTRA_TEST( predict_8x8, i, 8, edge );
 
     set_func_name("intra_predict_8x8_filter");
     if( ip_a.predict_8x8_filter != ip_ref.predict_8x8_filter )
     {
         used_asm = 1;
-        for( i = 0; i < 32; i++ )
+        for( int i = 0; i < 32; i++ )
         {
             memcpy( edge2, edge, 33 );
             call_c(ip_c.predict_8x8_filter, buf1+48, edge, (i&24)>>1, i&7);
@@ -1557,11 +1558,10 @@ static int check_intra( int cpu_ref, int cpu_new )
 #define DECL_CABAC(cpu) \
 static void run_cabac_##cpu( uint8_t *dst )\
 {\
-    int i;\
     x264_cabac_t cb;\
     x264_cabac_context_init( &cb, SLICE_TYPE_P, 26, 0 );\
     x264_cabac_encode_init( &cb, dst, dst+0xff0 );\
-    for( i=0; i<0x1000; i++ )\
+    for( int i = 0; i < 0x1000; i++ )\
         x264_cabac_encode_decision_##cpu( &cb, buf1[i]>>1, buf1[i]&1 );\
 }
 DECL_CABAC(c)
@@ -1682,7 +1682,6 @@ static int check_all_flags( void )
 int main(int argc, char *argv[])
 {
     int ret = 0;
-    int i;
 
     if( argc > 1 && !strncmp( argv[1], "--bench", 7 ) )
     {
@@ -1700,9 +1699,9 @@ int main(int argc, char *argv[])
         argv++;
     }
 
-    i = ( argc > 1 ) ? atoi(argv[1]) : x264_mdate();
-    fprintf( stderr, "x264: using random seed %u\n", i );
-    srand( i );
+    int seed = ( argc > 1 ) ? atoi(argv[1]) : x264_mdate();
+    fprintf( stderr, "x264: using random seed %u\n", seed );
+    srand( seed );
 
     buf1 = x264_malloc( 0x3e00 + 16*BENCH_ALIGNS );
     if( !buf1 )
@@ -1713,13 +1712,13 @@ int main(int argc, char *argv[])
     buf2 = buf1 + 0xf00;
     buf3 = buf2 + 0xf00;
     buf4 = buf3 + 0x1000;
-    for( i=0; i<0x1e00; i++ )
+    for( int i = 0; i < 0x1e00; i++ )
         buf1[i] = rand() & 0xFF;
     memset( buf1+0x1e00, 0, 0x2000 );
 
     /* 16-byte alignment is guaranteed whenever it's useful, but some functions also vary in speed depending on %64 */
     if( do_bench )
-        for( i=0; i<BENCH_ALIGNS && !ret; i++ )
+        for( int i = 0; i < BENCH_ALIGNS && !ret; i++ )
         {
             buf2 = buf1 + 0xf00;
             buf3 = buf2 + 0xf00;
diff --git a/x264.c b/x264.c
index 43d3035b128b72c9fb909443aacf110d11bf515a..08fd3133cb96df18f41bbff5da656ee7b3853312 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -871,6 +871,28 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename
     return 0;
 }
 
+static int parse_enum_name( const char *arg, const char * const *names, const char **dst )
+{
+    for( int i = 0; names[i]; i++ )
+        if( !strcasecmp( arg, names[i] ) )
+        {
+            *dst = names[i];
+            return 0;
+        }
+    return -1;
+}
+
+static int parse_enum_value( const char *arg, const char * const *names, int *dst )
+{
+    for( int i = 0; names[i]; i++ )
+        if( !strcasecmp( arg, names[i] ) )
+        {
+            *dst = i;
+            return 0;
+        }
+    return -1;
+}
+
 /*****************************************************************************
  * Parse:
  *****************************************************************************/
@@ -888,7 +910,6 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
     int b_user_ref = 0;
     int b_user_fps = 0;
     int b_user_interlaced = 0;
-    int i;
     cli_input_opt_t input_opt;
     char *preset = NULL;
     char *tune = NULL;
@@ -966,24 +987,12 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
                 output_filename = optarg;
                 break;
             case OPT_MUXER:
-                for( i = 0; muxer_names[i] && strcasecmp( muxer_names[i], optarg ); )
-                    i++;
-                if( !muxer_names[i] )
-                {
-                    fprintf( stderr, "x264 [error]: invalid muxer '%s'\n", optarg );
+                if( parse_enum_name( optarg, muxer_names, &muxer ) < 0 )
                     return -1;
-                }
-                muxer = optarg;
                 break;
             case OPT_DEMUXER:
-                for( i = 0; demuxer_names[i] && strcasecmp( demuxer_names[i], optarg ); )
-                    i++;
-                if( !demuxer_names[i] )
-                {
-                    fprintf( stderr, "x264 [error]: invalid demuxer '%s'\n", optarg );
+                if( parse_enum_name( optarg, demuxer_names, &demuxer ) < 0 )
                     return -1;
-                }
-                demuxer = optarg;
                 break;
             case OPT_INDEX:
                 input_opt.index = optarg;
@@ -1015,7 +1024,7 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
                 opt->b_progress = 0;
                 break;
             case OPT_VISUALIZE:
-#ifdef VISUALIZE
+#ifdef HAVE_VISUALIZE
                 param->b_visualize = 1;
                 b_exit_on_ctrl_c = 1;
 #else
@@ -1056,22 +1065,15 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
                 input_opt.timebase = optarg;
                 break;
             case OPT_PULLDOWN:
-                for( i = 0; pulldown_names[i] && strcasecmp( pulldown_names[i], optarg ); )
-                    i++;
-                if( !pulldown_names[i] )
-                {
-                    fprintf( stderr, "x264 [error]: invalid pulldown '%s'\n", optarg );
+                if( parse_enum_value( optarg, pulldown_names, &opt->i_pulldown ) < 0 )
                     return -1;
-                }
-                opt->i_pulldown = i;
                 break;
             default:
 generic_option:
             {
-                int i;
                 if( long_options_index < 0 )
                 {
-                    for( i = 0; long_options[i].name; i++ )
+                    for( int i = 0; long_options[i].name; i++ )
                         if( long_options[i].val == c )
                         {
                             long_options_index = i;
@@ -1244,12 +1246,11 @@ generic_option:
     if( !b_user_ref )
     {
         int mbs = (((param->i_width)+15)>>4) * (((param->i_height)+15)>>4);
-        int i;
-        for( i = 0; x264_levels[i].level_idc != 0; i++ )
+        for( int i = 0; x264_levels[i].level_idc != 0; i++ )
             if( param->i_level_idc == x264_levels[i].level_idc )
             {
-                while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb
-                       && param->i_frame_reference > 1 )
+                while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb &&
+                       param->i_frame_reference > 1 )
                 {
                     param->i_frame_reference--;
                 }