Wrap palette code inside CONFIG_PALETTE flag.

This flag was already added to aomedia/master, so bringing it back to
webm/nextgenv2, as part of an effort to get the two codebases in sync.

Change-Id: I2b933a6a160e4210d1411a9e7978149eb8553205
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 8707061..e594a32 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -41,7 +41,9 @@
 #include "av1/encoder/encoder.h"
 #include "av1/encoder/hybrid_fwd_txfm.h"
 #include "av1/encoder/mcomp.h"
+#if CONFIG_PALETTE
 #include "av1/encoder/palette.h"
+#endif  // CONFIG_PALETTE
 #include "av1/encoder/quantize.h"
 #include "av1/encoder/ratectrl.h"
 #include "av1/encoder/rd.h"
@@ -415,6 +417,7 @@
   { { INTRA_FRAME, NONE } },
 };
 
+#if CONFIG_EXT_INTRA || CONFIG_PALETTE
 static INLINE int write_uniform_cost(int n, int v) {
   int l = get_unsigned_bits(n), m = (1 << l) - n;
   if (l == 0) return 0;
@@ -423,6 +426,7 @@
   else
     return l * av1_cost_bit(128, 0);
 }
+#endif  // CONFIG_EXT_INTRA || CONFIG_PALETTE
 
 // constants for prune 1 and prune 2 decision boundaries
 #define FAST_EXT_TX_CORR_MID 0.0
@@ -1727,6 +1731,7 @@
   return 0;
 }
 
+#if CONFIG_PALETTE
 static int rd_pick_palette_intra_sby(
     AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int palette_ctx,
     int dc_mode_cost, PALETTE_MODE_INFO *palette_mode_info,
@@ -1871,6 +1876,7 @@
   }
   return rate_overhead;
 }
+#endif  // CONFIG_PALETTE
 
 static int64_t rd_pick_intra4x4block(AV1_COMP *cpi, MACROBLOCK *x, int row,
                                      int col, PREDICTION_MODE *best_mode,
@@ -1902,7 +1908,9 @@
   memcpy(ta, a, num_4x4_blocks_wide * sizeof(a[0]));
   memcpy(tl, l, num_4x4_blocks_high * sizeof(l[0]));
   xd->mi[0]->mbmi.tx_size = TX_4X4;
+#if CONFIG_PALETTE
   xd->mi[0]->mbmi.palette_mode_info.palette_size[0] = 0;
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_AOM_HIGHBITDEPTH
   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
@@ -2258,7 +2266,9 @@
   av1_zero(ext_intra_mode_info);
   mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 1;
   mbmi->mode = DC_PRED;
+#if CONFIG_PALETTE
   mbmi->palette_mode_info.palette_size[0] = 0;
+#endif  // CONFIG_PALETTE
 
   for (mode = 0; mode < FILTER_INTRA_MODES; ++mode) {
     if (skip_mask & (1 << mode)) continue;
@@ -2599,6 +2609,10 @@
   int this_rate, this_rate_tokenonly, s;
   int64_t this_distortion, this_rd;
   TX_SIZE best_tx = TX_4X4;
+#if CONFIG_EXT_INTRA || CONFIG_PALETTE
+  const int rows = 4 * num_4x4_blocks_high_lookup[bsize];
+  const int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
+#endif  // CONFIG_EXT_INTRA || CONFIG_PALETTE
 #if CONFIG_EXT_INTRA
   const int intra_filter_ctx = av1_get_pred_context_intra_interp(xd);
   EXT_INTRA_MODE_INFO ext_intra_mode_info;
@@ -2612,15 +2626,15 @@
 #endif  // CONFIG_EXT_INTRA
   TX_TYPE best_tx_type = DCT_DCT;
   int *bmode_costs;
+#if CONFIG_PALETTE
   PALETTE_MODE_INFO palette_mode_info;
   PALETTE_MODE_INFO *const pmi = &mic->mbmi.palette_mode_info;
   uint8_t *best_palette_color_map =
       cpi->common.allow_screen_content_tools
           ? x->palette_buffer->best_palette_color_map
           : NULL;
-  const int rows = 4 * num_4x4_blocks_high_lookup[bsize];
-  const int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
   int palette_ctx = 0;
+#endif  // CONFIG_PALETTE
   const MODE_INFO *above_mi = xd->above_mi;
   const MODE_INFO *left_mi = xd->left_mi;
   const PREDICTION_MODE A = av1_above_block_mode(mic, above_mi, 0);
@@ -2643,12 +2657,14 @@
 #endif
     angle_estimation(src, src_stride, rows, cols, directional_mode_skip_mask);
 #endif  // CONFIG_EXT_INTRA
+#if CONFIG_PALETTE
   palette_mode_info.palette_size[0] = 0;
   pmi->palette_size[0] = 0;
   if (above_mi)
     palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
   if (left_mi)
     palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
+#endif  // CONFIG_PALETTE
 
   if (cpi->sf.tx_type_search.fast_intra_tx_type_search)
     x->use_default_intra_tx_type = 1;
@@ -2699,9 +2715,11 @@
           cpi->tx_size_cost[max_tx_size - TX_8X8][get_tx_size_context(xd)]
                            [mic->mbmi.tx_size];
     }
+#if CONFIG_PALETTE
     if (cpi->common.allow_screen_content_tools && mic->mbmi.mode == DC_PRED)
       this_rate += av1_cost_bit(
           av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx], 0);
+#endif  // CONFIG_PALETTE
 #if CONFIG_EXT_INTRA
     if (mic->mbmi.mode == DC_PRED && ALLOW_FILTER_INTRA_MODES)
       this_rate += av1_cost_bit(cpi->common.fc->ext_intra_probs[0], 0);
@@ -2741,11 +2759,13 @@
     }
   }
 
+#if CONFIG_PALETTE
   if (cpi->common.allow_screen_content_tools)
     rd_pick_palette_intra_sby(cpi, x, bsize, palette_ctx, bmode_costs[DC_PRED],
                               &palette_mode_info, best_palette_color_map,
                               &best_tx, &best_tx_type, &mode_selected,
                               &best_rd);
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_EXT_INTRA
   if (ALLOW_FILTER_INTRA_MODES && beat_best_rd) {
@@ -2764,7 +2784,9 @@
   if (ext_intra_mode_info.use_ext_intra_mode[0]) {
     mic->mbmi.ext_intra_mode_info.ext_intra_mode[0] =
         ext_intra_mode_info.ext_intra_mode[0];
+#if CONFIG_PALETTE
     palette_mode_info.palette_size[0] = 0;
+#endif  // CONFIG_PALETTE
   }
 #endif  // CONFIG_EXT_INTRA
 
@@ -2775,6 +2797,7 @@
   mic->mbmi.intra_filter = best_filter;
 #endif  // CONFIG_EXT_INTRA
   mic->mbmi.tx_type = best_tx_type;
+#if CONFIG_PALETTE
   pmi->palette_size[0] = palette_mode_info.palette_size[0];
   if (palette_mode_info.palette_size[0] > 0) {
     memcpy(pmi->palette_colors, palette_mode_info.palette_colors,
@@ -2782,6 +2805,7 @@
     memcpy(xd->plane[0].color_index_map, best_palette_color_map,
            rows * cols * sizeof(best_palette_color_map[0]));
   }
+#endif  // CONFIG_PALETTE
 
   return best_rd;
 }
@@ -3565,6 +3589,7 @@
 }
 #endif  // CONFIG_VAR_TX
 
+#if CONFIG_PALETTE
 static void rd_pick_palette_intra_sbuv(
     AV1_COMP *cpi, MACROBLOCK *x, int dc_mode_cost,
     PALETTE_MODE_INFO *palette_mode_info, uint8_t *best_palette_color_map,
@@ -3729,6 +3754,7 @@
     }
   }
 }
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_EXT_INTRA
 // Return 1 if an ext intra mode is selected; return 0 otherwise.
@@ -3747,7 +3773,9 @@
   av1_zero(ext_intra_mode_info);
   mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 1;
   mbmi->uv_mode = DC_PRED;
+#if CONFIG_PALETTE
   mbmi->palette_mode_info.palette_size[1] = 0;
+#endif  // CONFIG_PALETTE
 
   for (mode = 0; mode < FILTER_INTRA_MODES; ++mode) {
     mbmi->ext_intra_mode_info.ext_intra_mode[1] = mode;
@@ -3890,6 +3918,7 @@
   int64_t best_rd = INT64_MAX, this_rd;
   int this_rate_tokenonly, this_rate, s;
   int64_t this_distortion, this_sse;
+#if CONFIG_PALETTE
   const int rows =
       (4 * num_4x4_blocks_high_lookup[bsize]) >> (xd->plane[1].subsampling_y);
   const int cols =
@@ -3897,6 +3926,7 @@
   PALETTE_MODE_INFO palette_mode_info;
   PALETTE_MODE_INFO *const pmi = &xd->mi[0]->mbmi.palette_mode_info;
   uint8_t *best_palette_color_map = NULL;
+#endif  // CONFIG_PALETTE
 #if CONFIG_EXT_INTRA
   int is_directional_mode, rate_overhead, best_angle_delta = 0;
   EXT_INTRA_MODE_INFO ext_intra_mode_info;
@@ -3904,8 +3934,10 @@
   ext_intra_mode_info.use_ext_intra_mode[1] = 0;
   mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 0;
 #endif  // CONFIG_EXT_INTRA
+#if CONFIG_PALETTE
   palette_mode_info.palette_size[1] = 0;
   pmi->palette_size[1] = 0;
+#endif  // CONFIG_PALETTE
   for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
     if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) continue;
 
@@ -3938,10 +3970,12 @@
       continue;
     this_rate = this_rate_tokenonly + cpi->intra_uv_mode_cost[mbmi->mode][mode];
 #endif  // CONFIG_EXT_INTRA
+#if CONFIG_PALETTE
     if (cpi->common.allow_screen_content_tools && mbmi->sb_type >= BLOCK_8X8 &&
         mode == DC_PRED)
       this_rate += av1_cost_bit(
           av1_default_palette_uv_mode_prob[pmi->palette_size[0] > 0], 0);
+#endif  // CONFIG_PALETTE
 
     this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
 
@@ -3958,6 +3992,7 @@
     }
   }
 
+#if CONFIG_PALETTE
   if (cpi->common.allow_screen_content_tools && mbmi->sb_type >= BLOCK_8X8) {
     best_palette_color_map = x->palette_buffer->best_palette_color_map;
     rd_pick_palette_intra_sbuv(
@@ -3965,6 +4000,7 @@
         &palette_mode_info, best_palette_color_map, &mode_selected, &best_rd,
         rate, rate_tokenonly, distortion, skippable);
   }
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_EXT_INTRA
   if (mbmi->sb_type >= BLOCK_8X8 && ALLOW_FILTER_INTRA_MODES) {
@@ -3980,11 +4016,14 @@
   if (ext_intra_mode_info.use_ext_intra_mode[1]) {
     mbmi->ext_intra_mode_info.ext_intra_mode[1] =
         ext_intra_mode_info.ext_intra_mode[1];
+#if CONFIG_PALETTE
     palette_mode_info.palette_size[1] = 0;
+#endif  // CONFIG_PALETTE
   }
   mbmi->angle_delta[1] = best_angle_delta;
 #endif  // CONFIG_EXT_INTRA
   mbmi->uv_mode = mode_selected;
+#if CONFIG_PALETTE
   pmi->palette_size[1] = palette_mode_info.palette_size[1];
   if (palette_mode_info.palette_size[1] > 0) {
     memcpy(pmi->palette_colors + PALETTE_MAX_SIZE,
@@ -3993,6 +4032,7 @@
     memcpy(xd->plane[1].color_index_map, best_palette_color_map,
            rows * cols * sizeof(best_palette_color_map[0]));
   }
+#endif  // CONFIG_PALETTE
 
   return best_rd;
 }
@@ -7972,6 +8012,7 @@
          av1_active_v_edge(cpi, mi_col, cpi->common.mib_size);
 }
 
+#if CONFIG_PALETTE
 static void restore_uv_color_map(AV1_COMP *cpi, MACROBLOCK *x) {
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
@@ -8019,13 +8060,17 @@
   av1_calc_indices(data, centroids, color_map, rows * cols,
                    pmi->palette_size[1], 2);
 }
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_EXT_INTRA
 static void pick_ext_intra_interframe(
     AV1_COMP *cpi, MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, BLOCK_SIZE bsize,
     int *rate_uv_intra, int *rate_uv_tokenonly, int64_t *dist_uv, int *skip_uv,
     PREDICTION_MODE *mode_uv, EXT_INTRA_MODE_INFO *ext_intra_mode_info_uv,
-    PALETTE_MODE_INFO *pmi_uv, int8_t *uv_angle_delta, int palette_ctx,
+    int8_t *uv_angle_delta,
+#if CONFIG_PALETTE
+    PALETTE_MODE_INFO *pmi_uv, int palette_ctx,
+#endif  // CONFIG_PALETTE
     int skip_mask, unsigned int *ref_costs_single, int64_t *best_rd,
     int64_t *best_intra_rd, PREDICTION_MODE *best_intra_mode,
     int *best_mode_index, int *best_skip2, int *best_mode_skippable,
@@ -8036,7 +8081,9 @@
   AV1_COMMON *const cm = &cpi->common;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
+#if CONFIG_PALETTE
   PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
+#endif  // CONFIG_PALETTE
   const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
   int rate2 = 0, rate_y = INT_MAX, skippable = 0, rate_uv, rate_dummy, i;
   int dc_mode_index;
@@ -8069,7 +8116,9 @@
     choose_intra_uv_mode(cpi, x, ctx, bsize, uv_tx, &rate_uv_intra[uv_tx],
                          &rate_uv_tokenonly[uv_tx], &dist_uv[uv_tx],
                          &skip_uv[uv_tx], &mode_uv[uv_tx]);
+#if CONFIG_PALETTE
     if (cm->allow_screen_content_tools) pmi_uv[uv_tx] = *pmi;
+#endif  // CONFIG_PALETTE
     ext_intra_mode_info_uv[uv_tx] = mbmi->ext_intra_mode_info;
     uv_angle_delta[uv_tx] = mbmi->angle_delta[1];
   }
@@ -8078,12 +8127,14 @@
   distortion_uv = dist_uv[uv_tx];
   skippable = skippable && skip_uv[uv_tx];
   mbmi->uv_mode = mode_uv[uv_tx];
+#if CONFIG_PALETTE
   if (cm->allow_screen_content_tools) {
     pmi->palette_size[1] = pmi_uv[uv_tx].palette_size[1];
     memcpy(pmi->palette_colors + PALETTE_MAX_SIZE,
            pmi_uv[uv_tx].palette_colors + PALETTE_MAX_SIZE,
            2 * PALETTE_MAX_SIZE * sizeof(pmi->palette_colors[0]));
   }
+#endif  // CONFIG_PALETTE
   mbmi->angle_delta[1] = uv_angle_delta[uv_tx];
   mbmi->ext_intra_mode_info.use_ext_intra_mode[1] =
       ext_intra_mode_info_uv[uv_tx].use_ext_intra_mode[1];
@@ -8094,9 +8145,11 @@
 
   rate2 = rate_y + intra_mode_cost[mbmi->mode] + rate_uv +
           cpi->intra_uv_mode_cost[mbmi->mode][mbmi->uv_mode];
+#if CONFIG_PALETTE
   if (cpi->common.allow_screen_content_tools && mbmi->mode == DC_PRED)
     rate2 += av1_cost_bit(
         av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx], 0);
+#endif  // CONFIG_PALETTE
 
   if (!xd->lossless[mbmi->segment_id]) {
     // super_block_yrd above includes the cost of the tx_size in the
@@ -8202,7 +8255,9 @@
   SPEED_FEATURES *const sf = &cpi->sf;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
+#if CONFIG_PALETTE
   PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
+#endif  // CONFIG_PALETTE
   MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
   const struct segmentation *const seg = &cm->seg;
   PREDICTION_MODE this_mode;
@@ -8254,7 +8309,9 @@
   int64_t dist_uv[TX_SIZES];
   int skip_uv[TX_SIZES];
   PREDICTION_MODE mode_uv[TX_SIZES];
+#if CONFIG_PALETTE
   PALETTE_MODE_INFO pmi_uv[TX_SIZES];
+#endif  // CONFIG_PALETTE
 #if CONFIG_EXT_INTRA
   EXT_INTRA_MODE_INFO ext_intra_mode_info_uv[TX_SIZES];
   int8_t uv_angle_delta[TX_SIZES], dc_skipped = 1;
@@ -8281,11 +8338,15 @@
   int *mode_map = tile_data->mode_map[bsize];
   const int mode_search_skip_flags = sf->mode_search_skip_flags;
   const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
-  int palette_ctx = 0;
+#if CONFIG_PALETTE || CONFIG_EXT_INTRA
   const int rows = 4 * num_4x4_blocks_high_lookup[bsize];
   const int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
+#endif  // CONFIG_PALETTE || CONFIG_EXT_INTRA
+#if CONFIG_PALETTE
+  int palette_ctx = 0;
   const MODE_INFO *above_mi = xd->above_mi;
   const MODE_INFO *left_mi = xd->left_mi;
+#endif  // CONFIG_PALETTE
 #if CONFIG_MOTION_VAR
 #if CONFIG_AOM_HIGHBITDEPTH
   DECLARE_ALIGNED(16, uint8_t, tmp_buf1[2 * MAX_MB_PLANE * MAX_SB_SQUARE]);
@@ -8327,14 +8388,16 @@
 #endif  // CONFIG_MOTION_VAR
 
   av1_zero(best_mbmode);
-  av1_zero(pmi_uv);
 
+#if CONFIG_PALETTE
+  av1_zero(pmi_uv);
   if (cm->allow_screen_content_tools) {
     if (above_mi)
       palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
     if (left_mi)
       palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
   }
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_EXT_INTRA
   memset(directional_mode_skip_mask, 0,
@@ -8713,8 +8776,10 @@
     mbmi->uv_mode = DC_PRED;
     mbmi->ref_frame[0] = ref_frame;
     mbmi->ref_frame[1] = second_ref_frame;
+#if CONFIG_PALETTE
     pmi->palette_size[0] = 0;
     pmi->palette_size[1] = 0;
+#endif  // CONFIG_PALETTE
 #if CONFIG_EXT_INTRA
     mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 0;
     mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 0;
@@ -8756,8 +8821,6 @@
         if (!angle_stats_ready) {
           const int src_stride = x->plane[0].src.stride;
           const uint8_t *src = x->plane[0].src.buf;
-          const int rows = 4 * num_4x4_blocks_high_lookup[bsize];
-          const int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
 #if CONFIG_AOM_HIGHBITDEPTH
           if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
             highbd_angle_estimation(src, src_stride, rows, cols,
@@ -8797,7 +8860,10 @@
         choose_intra_uv_mode(cpi, x, ctx, bsize, uv_tx, &rate_uv_intra[uv_tx],
                              &rate_uv_tokenonly[uv_tx], &dist_uv[uv_tx],
                              &skip_uv[uv_tx], &mode_uv[uv_tx]);
+#if CONFIG_PALETTE
         if (cm->allow_screen_content_tools) pmi_uv[uv_tx] = *pmi;
+#endif  // CONFIG_PALETTE
+
 #if CONFIG_EXT_INTRA
         ext_intra_mode_info_uv[uv_tx] = mbmi->ext_intra_mode_info;
         uv_angle_delta[uv_tx] = mbmi->angle_delta[1];
@@ -8808,12 +8874,15 @@
       distortion_uv = dist_uv[uv_tx];
       skippable = skippable && skip_uv[uv_tx];
       mbmi->uv_mode = mode_uv[uv_tx];
+#if CONFIG_PALETTE
       if (cm->allow_screen_content_tools) {
         pmi->palette_size[1] = pmi_uv[uv_tx].palette_size[1];
         memcpy(pmi->palette_colors + PALETTE_MAX_SIZE,
                pmi_uv[uv_tx].palette_colors + PALETTE_MAX_SIZE,
                2 * PALETTE_MAX_SIZE * sizeof(pmi->palette_colors[0]));
       }
+#endif  // CONFIG_PALETTE
+
 #if CONFIG_EXT_INTRA
       mbmi->angle_delta[1] = uv_angle_delta[uv_tx];
       mbmi->ext_intra_mode_info.use_ext_intra_mode[1] =
@@ -8826,9 +8895,11 @@
 
       rate2 = rate_y + intra_mode_cost[mbmi->mode] + rate_uv +
               cpi->intra_uv_mode_cost[mbmi->mode][mbmi->uv_mode];
+#if CONFIG_PALETTE
       if (cpi->common.allow_screen_content_tools && mbmi->mode == DC_PRED)
         rate2 += av1_cost_bit(
             av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx], 0);
+#endif  // CONFIG_PALETTE
 
       if (!xd->lossless[mbmi->segment_id]) {
         // super_block_yrd above includes the cost of the tx_size in the
@@ -9421,6 +9492,7 @@
     }
   }
 
+#if CONFIG_PALETTE
   // Only try palette mode when the best mode so far is an intra mode.
   if (cm->allow_screen_content_tools && !is_inter_mode(best_mbmode.mode)) {
     PREDICTION_MODE mode_selected;
@@ -9519,17 +9591,24 @@
     }
   }
 PALETTE_EXIT:
+#endif  // CONFIG_PALETTE
 
 #if CONFIG_EXT_INTRA
   // TODO(huisu): ext-intra is turned off in lossless mode for now to
   // avoid a unit test failure
   if (!xd->lossless[mbmi->segment_id] && ALLOW_FILTER_INTRA_MODES &&
-      mbmi->palette_mode_info.palette_size[0] == 0 && !dc_skipped &&
-      best_mode_index >= 0 && best_intra_rd < (best_rd + (best_rd >> 3))) {
+#if CONFIG_PALETTE
+      mbmi->palette_mode_info.palette_size[0] == 0 &&
+#endif  // CONFIG_PALETTE
+      !dc_skipped && best_mode_index >= 0 &&
+      best_intra_rd < (best_rd + (best_rd >> 3))) {
     pick_ext_intra_interframe(
         cpi, x, ctx, bsize, rate_uv_intra, rate_uv_tokenonly, dist_uv, skip_uv,
-        mode_uv, ext_intra_mode_info_uv, pmi_uv, uv_angle_delta, palette_ctx, 0,
-        ref_costs_single, &best_rd, &best_intra_rd, &best_intra_mode,
+        mode_uv, ext_intra_mode_info_uv, uv_angle_delta,
+#if CONFIG_PALETTE
+        pmi_uv, palette_ctx,
+#endif  // CONFIG_PALETTE
+        0, ref_costs_single, &best_rd, &best_intra_rd, &best_intra_mode,
         &best_mode_index, &best_skip2, &best_mode_skippable,
 #if CONFIG_SUPERTX
         returnrate_nocoef,
@@ -9781,9 +9860,11 @@
   store_coding_context(x, ctx, best_mode_index, best_pred_diff,
                        best_mode_skippable);
 
+#if CONFIG_PALETTE
   if (cm->allow_screen_content_tools && pmi->palette_size[1] > 0) {
     restore_uv_color_map(cpi, x);
   }
+#endif  // CONFIG_PALETTE
 }
 
 void av1_rd_pick_inter_mode_sb_seg_skip(AV1_COMP *cpi, TileDataEnc *tile_data,
@@ -9817,8 +9898,11 @@
 
   assert(segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP));
 
+#if CONFIG_PALETTE
   mbmi->palette_mode_info.palette_size[0] = 0;
   mbmi->palette_mode_info.palette_size[1] = 0;
+#endif  // CONFIG_PALETTE
+
 #if CONFIG_EXT_INTRA
   mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 0;
   mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 0;
@@ -10043,8 +10127,10 @@
     frame_mv[ZEROMV][ref_frame].as_int = 0;
   }
 
+#if CONFIG_PALETTE
   mbmi->palette_mode_info.palette_size[0] = 0;
   mbmi->palette_mode_info.palette_size[1] = 0;
+#endif  // CONFIG_PALETTE
 
   for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) {
     int mode_excluded = 0;