shithub: libvpx

Download patch

ref: f6146612425ffc7523930e79ba43a253a7540693
parent: a53586d9d1dfcdf49b418a453f2d69dd230b9088
parent: 8c31484ea1fbac128e31a951a004f6f91bc1ef2f
author: Yaowu Xu <yaowu@google.com>
date: Thu Jul 21 12:05:24 EDT 2011

Merge "fix more merge issues" into experimental

--- a/vp8/common/blockd.h
+++ b/vp8/common/blockd.h
@@ -94,15 +94,15 @@
     MB_MODE_COUNT
 } MB_PREDICTION_MODE;
 
-// Macroblock level features
+/* Macroblock level features */
 typedef enum
 {
-    MB_LVL_ALT_Q = 0,               // Use alternate Quantizer ....
-    MB_LVL_ALT_LF = 1,              // Use alternate loop filter value...
-    MB_LVL_MAX = 2,                 // Number of MB level features supported
+    MB_LVL_ALT_Q = 0,               /* Use alternate Quantizer .... */
+    MB_LVL_ALT_LF = 1,              /* Use alternate loop filter value... */
+    MB_LVL_MAX = 2                  /* Number of MB level features supported */
+
 } MB_LVL_FEATURES;
 
-
 /* Segment Feature Masks */
 #define SEGMENT_ALTQ    0x01
 #define SEGMENT_ALT_LF  0x02
@@ -163,8 +163,9 @@
     MB_PREDICTION_MODE mode, uv_mode;
     MV_REFERENCE_FRAME ref_frame;
     int_mv mv;
+#if CONFIG_SEGMENTATION
     unsigned char segment_flag;
-
+#endif
     unsigned char partitioning;
     unsigned char mb_skip_coeff;                                /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
     unsigned char need_to_clamp_mvs;
@@ -237,11 +238,11 @@
     /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
     unsigned char mb_segement_abs_delta;
 
-    unsigned char temporal_update;
     /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */
     /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */
 #if CONFIG_SEGMENTATION
     vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS + 3];         // Probability Tree used to code Segment number
+    unsigned char temporal_update;
 #else
     vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS];
 #endif
@@ -274,7 +275,6 @@
     vp8_subpix_fn_t  subpixel_predict16x16;
 
     void *current_bc;
-
 
     int corrupted;
 
--- a/vp8/common/coefupdateprobs.h
+++ b/vp8/common/coefupdateprobs.h
@@ -183,8 +183,11 @@
         },
     },
 };
-
-const vp8_prob vp8_coef_update_probs_8x8 [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] =
+#if CONFIG_T8X8
+const vp8_prob vp8_coef_update_probs_8x8 [BLOCK_TYPES]
+                                         [COEF_BANDS]
+                                         [PREV_COEF_CONTEXTS]
+                                         [ENTROPY_NODES] =
 {
     {
       {
@@ -356,3 +359,4 @@
     },
 
 };
+#endif
\ No newline at end of file
--- a/vp8/common/defaultcoefcounts.c
+++ b/vp8/common/defaultcoefcounts.c
@@ -225,6 +225,7 @@
 };
 
 
+#if CONFIG_T8X8
 const unsigned int vp8_default_coef_counts_8x8[BLOCK_TYPES]
                                               [COEF_BANDS]
                                               [PREV_COEF_CONTEXTS]
@@ -400,3 +401,4 @@
       }
     }
   };
+#endif
\ No newline at end of file
--- a/vp8/common/entropy.c
+++ b/vp8/common/entropy.c
@@ -120,14 +120,21 @@
 static const Prob Pcat3[] = { 173, 148, 140};
 static const Prob Pcat4[] = { 176, 155, 140, 135};
 static const Prob Pcat5[] = { 180, 157, 141, 134, 130};
+#if CONFIG_EXTEND_QRANGE
 static const Prob Pcat6[] =
 { 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129};
+#else
+static const Prob Pcat6[] =
+{ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129};
 
+#endif
+
 static vp8_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[22];
 
 void vp8_init_scan_order_mask()
 {
     int i;
+
     for (i = 0; i < 16; i++)
     {
         vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i;
@@ -160,7 +167,11 @@
     init_bit_tree(cat3, 3);
     init_bit_tree(cat4, 4);
     init_bit_tree(cat5, 5);
+#if CONFIG_EXTEND_QRANGE
     init_bit_tree(cat6, 13);
+#else
+    init_bit_tree(cat6, 11);
+#endif
 }
 
 vp8_extra_bit_struct vp8_extra_bits[12] =
@@ -175,7 +186,11 @@
     { cat3, Pcat3, 3, 11},
     { cat4, Pcat4, 4, 19},
     { cat5, Pcat5, 5, 35},
+#if CONFIG_EXTEND_QRANGE
     { cat6, Pcat6, 13, 67},
+#else
+    { cat6, Pcat6, 11, 67},
+#endif
     { 0, 0, 0, 0}
 };
 #include "defaultcoefcounts.h"
@@ -183,6 +198,7 @@
 void vp8_default_coef_probs(VP8_COMMON *pc)
 {
     int h = 0;
+
     do
     {
         int i = 0;
@@ -233,6 +249,7 @@
     while (++h < BLOCK_TYPES);
 #endif
 }
+
 
 void vp8_coef_tree_initialize()
 {
--- a/vp8/common/entropy.h
+++ b/vp8/common/entropy.h
@@ -50,9 +50,12 @@
 #define PROB_UPDATE_BASELINE_COST   7
 
 #define MAX_PROB                255
+#if CONFIG_EXTEND_QRANGE
 #define DCT_MAX_VALUE           8192
+#else
+#define DCT_MAX_VALUE           2048
+#endif
 
-
 /* Coefficients are predicted via a 3-dimensional probability table. */
 
 /* Outside dimension.  0 = Y no DC, 1 = Y2, 2 = UV, 3 = Y with DC */
@@ -104,6 +107,6 @@
 extern short vp8_default_zig_zag_mask_8x8[64];//int64_t
 #endif
 extern const int vp8_mb_feature_data_bits[MB_LVL_MAX];
-void vp8_coef_tree_initialize(void);
 
+void vp8_coef_tree_initialize(void);
 #endif
--- a/vp8/common/idct.h
+++ b/vp8/common/idct.h
@@ -74,6 +74,7 @@
 #endif
 extern prototype_idct_scalar_add(vp8_idct_idct1_scalar_add);
 
+
 #ifndef vp8_idct_iwalsh1
 #define vp8_idct_iwalsh1 vp8_short_inv_walsh4x4_1_c
 #endif
--- a/vp8/common/idctllm.c
+++ b/vp8/common/idctllm.c
@@ -203,7 +203,6 @@
         ip += 4;
         op += 4;
     }
-    //printf("here2\n");
 }
 
 void vp8_short_inv_walsh4x4_1_c(short *input, short *output)
@@ -213,9 +212,9 @@
     short *op = output;
 
 #if !CONFIG_EXTEND_QRANGE
-    a1 = ((input[0] + 3) >> 3);
+    a1 = (input[0] + 3 )>> 3;
 #else
-    a1 = ((input[0] + 1) >> 2);
+    a1 = (input[0] + 1 )>> 2;
 #endif
 
     for (i = 0; i < 4; i++)
--- a/vp8/common/onyx.h
+++ b/vp8/common/onyx.h
@@ -126,7 +126,6 @@
         //(5)=Two Pass - Second Pass Best.  The encoder uses the statistics that were generated in the first
         //    encoding pass to create the compressed output using the highest possible quality, and taking a
         //    longer amount of time to encode.. ( speed setting ignored )
-
         int Mode;               //
 
         // Key Framing Operations
--- a/vp8/common/recon.c
+++ b/vp8/common/recon.c
@@ -12,7 +12,7 @@
 #include "vpx_ports/config.h"
 #include "recon.h"
 #include "blockd.h"
-#include <stdio.h>
+
 void vp8_recon_b_c
 (
     unsigned char *pred_ptr,
@@ -133,7 +133,6 @@
         RECON_INVOKE(rtcd, recon4)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
     }
 #endif
-
 }
 
 void vp8_recon_mb_c(const vp8_recon_rtcd_vtable_t *rtcd, MACROBLOCKD *x)
@@ -172,7 +171,6 @@
         RECON_INVOKE(rtcd, recon4)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
     }
 
-
     for (i = 16; i < 24; i += 2)
     {
         BLOCKD *b = &x->block[i];
@@ -180,5 +178,4 @@
         RECON_INVOKE(rtcd, recon2)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
     }
 #endif
-
 }
--- a/vp8/common/reconinter.c
+++ b/vp8/common/reconinter.c
@@ -464,3 +464,7 @@
         }
     }
 }
+
+
+
+
--- a/vp8/decoder/decodemv.c
+++ b/vp8/decoder/decodemv.c
@@ -18,8 +18,6 @@
 #if CONFIG_DEBUG
 #include <assert.h>
 #endif
-extern int frame_count;
-
 static int vp8_read_bmode(vp8_reader *bc, const vp8_prob *p)
 {
     const int i = vp8_treed_read(bc, vp8_bmode_tree, p);
@@ -62,7 +60,6 @@
         else
             mi->segment_id = (unsigned char)(vp8_read(r, x->mb_segment_tree_probs[1]));
     }
-    //printf("vp8_read_mb_features Segment = %d of frame %d\n", mi->segment_id, frame_count);
 }
 
 static void vp8_kfread_modes(VP8D_COMP *pbi, MODE_INFO *m, int mb_row, int mb_col)
@@ -80,7 +77,6 @@
 
             if (pbi->mb.update_mb_segmentation_map)
                 vp8_read_mb_features(bc, &m->mbmi, &pbi->mb);
-            //printf("vp8_kfread_modes segment = %d\n", m->mbmi.segment_id);
 
             /* Read the macroblock coeff skip flag if this feature is in use, else default to 0 */
             if (pbi->common.mb_no_coeff_skip)
@@ -316,7 +312,6 @@
                     {
                         mbmi->segment_id = pbi->segmentation_map[index];
                         mbmi->segment_flag = 0;
-                        //printf("vp8_read_mb_modes_mv Temporal Update if %d\n", mbmi->segment_id);
                     }
                     else
                     {
@@ -323,7 +318,6 @@
                         vp8_read_mb_features(bc, &mi->mbmi, &pbi->mb);
                         mbmi->segment_flag = 1;
                         pbi->segmentation_map[index] = mbmi->segment_id;
-                        //printf("vp8_read_mb_modes_mv Temporal Update else %d\n", mbmi->segment_id);
                     }
 
                 }
@@ -331,7 +325,6 @@
                 {
                     vp8_read_mb_features(bc, &mi->mbmi, &pbi->mb);
                     pbi->segmentation_map[index] = mbmi->segment_id;
-                    //printf("vp8_read_mb_modes_mv Not Temporal Update %d\n", mbmi->segment_id);
                 }
                 index++;
 #else
--- a/vp8/decoder/decodframe.c
+++ b/vp8/decoder/decodframe.c
@@ -241,13 +241,14 @@
     if (eobtotal == 0 && mode != B_PRED && mode != SPLITMV)
     {
         /* Special case:  Force the loopfilter to skip when eobtotal and
-        * mb_skip_coeff are zero.
-        * */
+         * mb_skip_coeff are zero.
+         * */
         xd->mode_info_context->mbmi.mb_skip_coeff = 1;
 
         skip_recon_mb(pbi, xd);
         return;
     }
+
     if (xd->segmentation_enabled)
         mb_init_dequantizer(pbi, xd);
 
@@ -259,7 +260,7 @@
         if (mode != B_PRED)
         {
             RECON_INVOKE(&pbi->common.rtcd.recon,
-                build_intra_predictors_mby)(xd);
+                         build_intra_predictors_mby)(xd);
         } else {
             vp8_intra_prediction_down_copy(xd);
         }
@@ -275,8 +276,8 @@
         vp8dx_bool_error(xd->current_bc)))
     {
         /* MB with corrupt residuals or corrupt mode/motion vectors.
-        * Better to use the predictor as reconstruction.
-        */
+         * Better to use the predictor as reconstruction.
+         */
         vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
         vp8_conceal_corrupt_mb(xd);
         return;
@@ -290,7 +291,7 @@
         {
             BLOCKD *b = &xd->block[i];
             RECON_INVOKE(RTCD_VTABLE(recon), intra4x4_predict)
-                (b, b->bmi.as_mode, b->predictor);
+                          (b, b->bmi.as_mode, b->predictor);
 
             if (xd->eobs[i] > 1)
             {
@@ -306,6 +307,7 @@
                 ((int *)b->qcoeff)[0] = 0;
             }
         }
+
     }
     else if (mode == SPLITMV)
     {
@@ -366,8 +368,6 @@
 
         else
 #endif
-        {
-            DEQUANT_INVOKE(&pbi->dequant, block)(b);
             if (xd->eobs[24] > 1)
             {
                 IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh16)(&b->dqcoeff[0], b->diff);
@@ -390,7 +390,6 @@
                 (xd->qcoeff, xd->block[0].dequant,
                 xd->predictor, xd->dst.y_buffer,
                 xd->dst.y_stride, xd->eobs, xd->block[24].diff);
-        }
     }
 #if CONFIG_T8X8
     if(xd->mode_info_context->mbmi.segment_id >= 2)
@@ -403,15 +402,13 @@
     }
     else
 #endif
-    {
 
-        DEQUANT_INVOKE (&pbi->dequant, idct_add_uv_block)
-            (xd->qcoeff+16*16, xd->block[16].dequant,
-            xd->predictor+16*16, xd->dst.u_buffer, xd->dst.v_buffer,
-            xd->dst.uv_stride, xd->eobs+16);
-    }
+    DEQUANT_INVOKE (&pbi->dequant, idct_add_uv_block)
+                    (xd->qcoeff+16*16, xd->block[16].dequant,
+                     xd->predictor+16*16, xd->dst.u_buffer, xd->dst.v_buffer,
+                     xd->dst.uv_stride, xd->eobs+16);
 
-    }
+}
 
 
 static int get_delta_q(vp8_reader *bc, int prev, int *q_update)
@@ -749,6 +746,7 @@
     const unsigned char *data = (const unsigned char *)pbi->Source;
     const unsigned char *data_end = data + pbi->source_sz;
     ptrdiff_t first_partition_length_in_bytes;
+
     int mb_row;
     int i, j, k, l;
     const int *const mb_feature_data_bits = vp8_mb_feature_data_bits;
--- a/vp8/decoder/dequantize.c
+++ b/vp8/decoder/dequantize.c
@@ -36,7 +36,7 @@
 
     for (i = 0; i < 16; i++)
     {
-       DQ[i] = Q[i] * DQC[i];
+        DQ[i] = Q[i] * DQC[i];
     }
 }
 
@@ -50,12 +50,12 @@
 
     for (i = 0; i < 16; i++)
     {
-       input[i] = dq[i] * input[i];
-
+        input[i] = dq[i] * input[i];
     }
 
     /* the idct halves ( >> 1) the pitch */
     vp8_short_idct4x4llm_c(input, output, 4 << 1);
+
     vpx_memset(input, 0, 32);
 
     for (r = 0; r < 4; r++)
@@ -88,17 +88,18 @@
     short *diff_ptr = output;
     int r, c;
 
-
     input[0] = (short)Dc;
 
     for (i = 1; i < 16; i++)
     {
-       input[i] = dq[i] * input[i];
+        input[i] = dq[i] * input[i];
     }
 
     /* the idct halves ( >> 1) the pitch */
     vp8_short_idct4x4llm_c(input, output, 4 << 1);
+
     vpx_memset(input, 0, 32);
+
     for (r = 0; r < 4; r++)
     {
         for (c = 0; c < 4; c++)
--- a/vp8/decoder/dequantize.h
+++ b/vp8/decoder/dequantize.h
@@ -42,7 +42,7 @@
              unsigned char *pre, unsigned char *dst_u, \
              unsigned char *dst_v, int stride, char *eobs)
 
-#if 1//CONFIG_T8X8
+#if CONFIG_T8X8
 #define prototype_dequant_dc_idct_add_y_block_8x8(sym) \
     void sym(short *q, short *dq, \
              unsigned char *pre, unsigned char *dst, \
--- a/vp8/decoder/detokenize.c
+++ b/vp8/decoder/detokenize.c
@@ -59,7 +59,7 @@
     UINT8 Probs[14];
 } TOKENEXTRABITS;
 */
-
+#if CONFIG_EXTEND_QRANGE
 DECLARE_ALIGNED(16, static const TOKENEXTRABITS, vp8d_token_extra_bits2[MAX_ENTROPY_TOKENS]) =
 {
     {  0, -1, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },  /* ZERO_TOKEN */
@@ -75,6 +75,23 @@
     { 67, 12, { 129, 130, 133, 140, 153, 177, 196, 230, 243, 249, 252, 254, 254,  0   } }, /* DCT_VAL_CATEGORY6 */
     {  0, -1, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },  /*  EOB TOKEN */
 };
+#else
+DECLARE_ALIGNED(16, static const TOKENEXTRABITS, vp8d_token_extra_bits2[MAX_ENTROPY_TOKENS]) =
+{
+    {  0, -1, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },  /* ZERO_TOKEN */
+    {  1, 0, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },   /* ONE_TOKEN */
+    {  2, 0, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },   /* TWO_TOKEN */
+    {  3, 0, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },   /* THREE_TOKEN */
+    {  4, 0, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },   /* FOUR_TOKEN */
+    {  5, 0, { 159, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },  /* DCT_VAL_CATEGORY1 */
+    {  7, 1, { 145, 165, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } }, /* DCT_VAL_CATEGORY2 */
+    { 11, 2, { 140, 148, 173, 0,  0,  0,  0,  0,  0,  0,  0,  0   } }, /* DCT_VAL_CATEGORY3 */
+    { 19, 3, { 135, 140, 155, 176, 0,  0,  0,  0,  0,  0,  0,  0   } }, /* DCT_VAL_CATEGORY4 */
+    { 35, 4, { 130, 134, 141, 157, 180, 0,  0,  0,  0,  0,  0,  0   } }, /* DCT_VAL_CATEGORY5 */
+    { 67, 10, { 129, 130, 133, 140, 153, 177, 196, 230, 243, 254, 254, 0   } }, /* DCT_VAL_CATEGORY6 */
+    {  0, -1, { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   } },  /*  EOB TOKEN */
+};
+#endif
 
 
 void vp8_reset_mb_tokens_context(MACROBLOCKD *x)
--- a/vp8/decoder/idct_blk.c
+++ b/vp8/decoder/idct_blk.c
@@ -30,14 +30,11 @@
     {
         for (j = 0; j < 4; j++)
         {
-            if (*eobs++ <= 1)
-            {
+            if (*eobs++ > 1)
+                vp8_dequant_dc_idct_add_c (q, dq, pre, dst, 16, stride, dc[0]);
+            else
                 vp8_dc_only_idct_add_c (dc[0], pre, dst, 16, stride);
-            }
 
-            else
-                vp8_dequant_dc_idct_add_c (q, dq, pre, dst, 16, stride, dc[0]);
-
             q   += 16;
             pre += 4;
             dst += 4;
@@ -59,13 +56,14 @@
     {
         for (j = 0; j < 4; j++)
         {
-            if (*eobs++ <= 1)
+            if (*eobs++ > 1)
+                vp8_dequant_idct_add_c (q, dq, pre, dst, 16, stride);
+            else
             {
                 vp8_dc_only_idct_add_c (q[0]*dq[0], pre, dst, 16, stride);
                 ((int *)q)[0] = 0;
             }
-            else
-                vp8_dequant_idct_add_c (q, dq, pre, dst, 16, stride);
+
             q   += 16;
             pre += 4;
             dst += 4;
@@ -86,13 +84,14 @@
     {
         for (j = 0; j < 2; j++)
         {
-            if (*eobs++ <= 1)
+            if (*eobs++ > 1)
+                vp8_dequant_idct_add_c (q, dq, pre, dstu, 8, stride);
+            else
             {
                 vp8_dc_only_idct_add_c (q[0]*dq[0], pre, dstu, 8, stride);
                 ((int *)q)[0] = 0;
             }
-            else
-                vp8_dequant_idct_add_c (q, dq, pre, dstu, 8, stride);
+
             q    += 16;
             pre  += 4;
             dstu += 4;
@@ -106,14 +105,14 @@
     {
         for (j = 0; j < 2; j++)
         {
-            if (*eobs++ <= 1)
+            if (*eobs++ > 1)
+                vp8_dequant_idct_add_c (q, dq, pre, dstv, 8, stride);
+            else
             {
                 vp8_dc_only_idct_add_c (q[0]*dq[0], pre, dstv, 8, stride);
                 ((int *)q)[0] = 0;
             }
 
-            else
-                vp8_dequant_idct_add_c (q, dq, pre, dstv, 8, stride);
             q    += 16;
             pre  += 4;
             dstv += 4;
--- a/vp8/decoder/onyxd_if.c
+++ b/vp8/decoder/onyxd_if.c
@@ -157,7 +157,7 @@
     if (!pbi)
         return;
 #if CONFIG_SEGMENTATION
-    // Delete sementation map
+     // Delete sementation map
     if (pbi->segmentation_map != 0)
         vpx_free(pbi->segmentation_map);
 #endif
@@ -514,9 +514,7 @@
         {
             /* Apply the loop filter if appropriate. */
             vp8_loop_filter_frame(cm, &pbi->mb, cm->filter_level);
-            //vp8_print_yuv_rec_mb(cm, 9, 10);
 
-
             cm->last_frame_type = cm->frame_type;
             cm->last_filter_type = cm->filter_type;
             cm->last_sharpness_level = cm->sharpness_level;
@@ -554,7 +552,6 @@
 
     /*vp8_print_modes_and_motion_vectors( cm->mi, cm->mb_rows,cm->mb_cols, cm->current_video_frame);*/
 
-    //printf("Decoded frame (%d) %d\n", cm->show_frame, cm->current_video_frame);
     if (cm->show_frame)
         cm->current_video_frame++;
 
--- a/vp8/decoder/onyxd_int.h
+++ b/vp8/decoder/onyxd_int.h
@@ -44,6 +44,7 @@
     int size;
 } DATARATE;
 
+#if CONFIG_EXTEND_QRANGE
 typedef struct
 {
     INT16        min_val;
@@ -50,7 +51,14 @@
     INT16        Length;
     UINT8 Probs[14];
 } TOKENEXTRABITS;
-
+#else
+typedef struct
+{
+    INT16        min_val;
+    INT16        Length;
+    UINT8 Probs[12];
+} TOKENEXTRABITS;
+#endif
 typedef struct
 {
     int const *scan;
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -192,10 +192,6 @@
             n--;
             i = 2;
         }
-        if (n == 0) {
-          printf("Fatal Error: n=0\n");
-          fflush(stdout);
-        }
 
         do
         {
@@ -870,8 +866,8 @@
     VP8_COMMON *const pc = & cpi->common;
     vp8_writer *const w = & cpi->bc;
     const MV_CONTEXT *mvc = pc->fc.mvc;
-#if CONFIG_SEGMENTATION
     MACROBLOCKD *xd = &cpi->mb.e_mbd;
+#if CONFIG_SEGMENTATION
     int left_id, above_id;
     int i;
     int sum;
@@ -1136,6 +1132,8 @@
     /* const */
     MODE_INFO *m = c->mi;
 #if CONFIG_SEGMENTATION
+    int left_id, above_id;
+    int i;
     int index = 0;
 #endif
     int mb_row = -1;
@@ -2063,9 +2061,7 @@
         active_section = 1;
 #endif
     }
-#if CONFIG_SEGMENTATION
-    //printf("%d\n",segment_cost);
-#endif
+
     vp8_stop_encode(bc);
 
     oh.first_partition_length_in_bytes = cpi->bc.pos;
--- a/vp8/encoder/dct.c
+++ b/vp8/encoder/dct.c
@@ -16,7 +16,7 @@
 
 
 
-
+#if CONFIG_T8X8
 void vp8_short_fdct8x8_c(short *block, short *coefs, int pitch)
 {
   int j1, i, j, k;
@@ -126,6 +126,7 @@
    op1[8]=ip1[0] - ip1[1] - ip1[4] + ip1[8];
 
 }
+#endif
 void vp8_short_fdct4x4_c(short *input, short *output, int pitch)
 {
     int i;
@@ -176,6 +177,11 @@
     }
 }
 
+void vp8_short_fdct8x4_c(short *input, short *output, int pitch)
+{
+    vp8_short_fdct4x4_c(input,   output,    pitch);
+    vp8_short_fdct4x4_c(input + 4, output + 16, pitch);
+}
 
 void vp8_short_walsh4x4_c(short *input, short *output, int pitch)
 {
@@ -194,7 +200,7 @@
         c1 = ((ip[1] - ip[3])<<2);
         b1 = ((ip[0] - ip[2])<<2);
 
-        op[0] = a1 + d1+ (a1!=0);
+        op[0] = a1 + d1 + (a1!=0);
 #else
         a1 = ((ip[0] + ip[2]));
         d1 = ((ip[1] + ip[3]));
@@ -245,10 +251,4 @@
         ip++;
         op++;
     }
-}
-
-void vp8_short_fdct8x4_c(short *input, short *output, int pitch)
-{
-    vp8_short_fdct4x4_c(input,   output,    pitch);
-    vp8_short_fdct4x4_c(input + 4, output + 16, pitch);
 }
--- a/vp8/encoder/encodeframe.c
+++ b/vp8/encoder/encodeframe.c
@@ -573,6 +573,7 @@
     int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
     int map_index = (mb_row * cpi->common.mb_cols);
 #if CONFIG_SEGMENTATION
+    int left_id, above_id;
     int sum;
 #endif
 #if CONFIG_MULTITHREAD
@@ -585,6 +586,7 @@
     else
         last_row_current_mb_col = &rightmost_col;
 #endif
+
     // reset above block coeffs
     xd->above_context = cm->above_context;
 
@@ -664,14 +666,18 @@
         if (xd->segmentation_enabled)
         {
             // Code to set segment id in xd->mbmi.segment_id for current MB (with range checking)
+#if CONFIG_T8X8
             // Reset segment_id to 0 or 1 so that the default transform mode is 4x4
             if (cpi->segmentation_map[map_index+mb_col] <= 3)
                 xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index+mb_col]&1;
+#else
+            if (cpi->segmentation_map[map_index+mb_col] <= 3)
+                xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index+mb_col];
+#endif
             else
                 xd->mode_info_context->mbmi.segment_id = 0;
 
             vp8cx_mb_init_quantizer(cpi, x);
-
         }
         else
             xd->mode_info_context->mbmi.segment_id = 0;         // Set to Segment 0 by default
@@ -819,6 +825,7 @@
     // this is to account for the border
     xd->mode_info_context++;
     x->partition_info++;
+
 #if CONFIG_MULTITHREAD
     if ((cpi->b_multi_threaded != 0) && (mb_row == cm->mb_rows - 1))
     {
@@ -826,6 +833,7 @@
     }
 #endif
 }
+
 void init_encode_frame_mb_context(VP8_COMP *cpi)
 {
     MACROBLOCK *const x = & cpi->mb;
@@ -922,7 +930,7 @@
     TOKENEXTRA *tp = cpi->tok;
 #if CONFIG_SEGMENTATION
     int segment_counts[MAX_MB_SEGMENTS + SEEK_SEGID];
-    int prob[3] = {255, 255, 255};
+    int prob[3];
     int new_cost, original_cost;
 #else
     int segment_counts[MAX_MB_SEGMENTS];
@@ -1479,10 +1487,10 @@
             x->e_mbd.mode_info_context->mbmi.segment_id |= (vp8_8x8_selection_intra(x) << 1);
 #endif
         vp8_encode_intra16x16mby(IF_RTCD(&cpi->rtcd), x);
-
-        vp8_encode_intra16x16mbuv(IF_RTCD(&cpi->rtcd), x);
-        sum_intra_stats(cpi, x);
-        vp8_tokenize_mb(cpi, &x->e_mbd, t);
+    }
+    vp8_encode_intra16x16mbuv(IF_RTCD(&cpi->rtcd), x);
+    sum_intra_stats(cpi, x);
+    vp8_tokenize_mb(cpi, &x->e_mbd, t);
 #if CONFIG_T8X8
         if( x->e_mbd.mode_info_context->mbmi.segment_id >=2)
             cpi->t8x8_count++;
@@ -1489,10 +1497,8 @@
         else
             cpi->t4x4_count++;
 #endif
-    }
     return rate;
 }
-
 #ifdef SPEEDSTATS
 extern int cnt_pm;
 #endif
@@ -1568,7 +1574,7 @@
     cpi->last_mb_distortion = distortion;
 #endif
 
-    // MB level adjustment to quantizer setup
+    // MB level adjutment to quantizer setup
     if (xd->segmentation_enabled)
     {
         // If cyclic update enabled
--- a/vp8/encoder/encodemb.c
+++ b/vp8/encoder/encodemb.c
@@ -122,6 +122,7 @@
         src_diff_ptr[i] = x->coeff[i * 16];
     }
 }
+#if CONFIG_T8X8
 void vp8_build_dcblock_8x8(MACROBLOCK *x)
 {
     short *src_diff_ptr = &x->src_diff[384];
@@ -135,7 +136,7 @@
     src_diff_ptr[4] = x->coeff[8 * 16];
     src_diff_ptr[8] = x->coeff[12 * 16];
 }
-
+#endif
 void vp8_transform_mbuv(MACROBLOCK *x)
 {
     int i;
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -46,8 +46,6 @@
 #define RTCD(x) NULL
 #endif
 
-#define OUTPUT_YUV_REC
-
 extern void vp8cx_pick_filter_level_fast(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
 extern void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val);
 extern void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
@@ -113,7 +111,7 @@
 
 #if 0
 FILE *framepsnr;
-FILE ikf_list;
+FILE *kf_list;
 FILE *keyfile;
 #endif
 
@@ -139,6 +137,7 @@
 extern unsigned __int64 Sectionbits[500];
 #endif
 #ifdef MODE_STATS
+extern unsigned __int64 Sectionbits[50];
 extern int y_modes[5]  ;
 extern int uv_modes[4] ;
 extern int b_modes[10]  ;
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -32,15 +32,12 @@
 #include "lookahead.h"
 
 //#define SPEEDSTATS 1
-#define MODE_STATS 1
-//#define ENC_DEBUG
-
 #define MIN_GF_INTERVAL             4
 #define DEFAULT_GF_INTERVAL         7
 
 #define KEY_FRAME_CONTEXT 5
 
-#define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)//1:25
+#define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)
 
 #define AF_THRESH   25
 #define AF_THRESH2  100
@@ -477,8 +474,10 @@
     int gf_update_recommended;
     int skip_true_count;
     int skip_false_count;
-    int t4x4_count;
-    int t8x8_count;
+#if CONFIG_T8X8
+    int t4x4_count;
+    int t8x8_count;
+#endif
 
     unsigned char *segmentation_map;
     signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];            // Segment data (can be deltas or absolute values)
@@ -646,7 +645,7 @@
 void vp8_tokenize_mb(VP8_COMP *, MACROBLOCKD *, TOKENEXTRA **);
 
 void vp8_set_speed_features(VP8_COMP *cpi);
-extern void vp8_write_yuv_frame(const char *name, YV12_BUFFER_CONFIG *s);
+
 #if CONFIG_DEBUG
 #define CHECK_MEM_ERROR(lval,expr) do {\
         lval = (expr); \
--- a/vp8/encoder/quantize.c
+++ b/vp8/encoder/quantize.c
@@ -81,10 +81,11 @@
     short *qcoeff_ptr  = d->qcoeff;
     short *dqcoeff_ptr = d->dqcoeff;
     short *dequant_ptr = d->dequant;
+#if CONFIG_T8X8
 
     vpx_memset(qcoeff_ptr, 0, 32);
     vpx_memset(dqcoeff_ptr, 0, 32);
-
+#endif
     eob = -1;
     for (i = 0; i < 16; i++)
     {
@@ -1325,3 +1326,4 @@
         vp8cx_init_quantizer(cpi);
 
 }
+
--- a/vp8/encoder/quantize.h
+++ b/vp8/encoder/quantize.h
@@ -45,7 +45,7 @@
 #define vp8_quantize_fastquantb vp8_fast_quantize_b_c
 #endif
 extern prototype_quantize_block(vp8_quantize_fastquantb);
-
+#if CONFIG_T8X8
 #ifndef vp8_quantize_quantb_8x8
 #define vp8_quantize_quantb_8x8 vp8_regular_quantize_b_8x8
 #endif
@@ -65,8 +65,8 @@
 #define vp8_quantize_fastquantb_2x2 vp8_fast_quantize_b_2x2_c
 #endif
 extern prototype_quantize_block(vp8_quantize_fastquantb_2x2);
+#endif
 
-
 #ifndef vp8_quantize_fastquantb_pair
 #define vp8_quantize_fastquantb_pair vp8_fast_quantize_b_pair_c
 #endif
@@ -77,10 +77,12 @@
     prototype_quantize_block(*quantb);
     prototype_quantize_block_pair(*quantb_pair);
     prototype_quantize_block(*fastquantb);
+#if CONFIG_T8X8
     prototype_quantize_block(*quantb_8x8);
     prototype_quantize_block(*fastquantb_8x8);
     prototype_quantize_block(*quantb_2x2);
     prototype_quantize_block(*fastquantb_2x2);
+#endif
     prototype_quantize_block_pair(*fastquantb_pair);
 } vp8_quantize_rtcd_vtable_t;
 
@@ -106,9 +108,10 @@
 #endif
 
 extern void vp8_strict_quantize_b(BLOCK *b,BLOCKD *d);
+#if CONFIG_T8X8
 extern void vp8_strict_quantize_b_8x8(BLOCK *b,BLOCKD *d);
 extern void vp8_strict_quantize_b_2x2(BLOCK *b,BLOCKD *d);
-
+#endif
 struct VP8_COMP;
 extern void vp8_set_quantizer(struct VP8_COMP *cpi, int Q);
 extern void vp8cx_frame_init_quantizer(struct VP8_COMP *cpi);
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -1051,7 +1051,6 @@
 }
 
 
-
 static const unsigned int segmentation_to_sseshift[4] = {3, 3, 2, 0};
 
 
--- a/vp8/encoder/tokenize.c
+++ b/vp8/encoder/tokenize.c
@@ -11,7 +11,6 @@
 
 #include <math.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include "onyx_int.h"
@@ -598,7 +597,6 @@
 
 # define Comma( X) (X? ",":"")
 
-
     type = 0;
 
     do
@@ -933,7 +931,6 @@
     *a = *l = pt;
 
 }
-
 static __inline
 void stuff1st_order_buv
 (
--- a/vp8/encoder/tokenize.h
+++ b/vp8/encoder/tokenize.h
@@ -38,9 +38,10 @@
 void print_context_counters();
 
 extern _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
+#if CONFIG_T8X8
 extern _int64 context_counters_8x8[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
 #endif
-
+#endif
 extern const int *vp8_dct_value_cost_ptr;
 /* TODO: The Token field should be broken out into a separate char array to
  *  improve cache locality, since it's needed for costing when the rest of the