Fix the calculation of palette_pixels

In parent version, palette_pixels tracked the pixels for
which palette mode was chosen. However this tracking was
incorrect as the same was done before mode was finalized.
In this CL, the tracking is done only for final encode in
encode_superblock(). As palette_pixels is used only for
screen content decision, the performance impact is seen
to be marginal and is seen to affect few contents only.

STATS_CHANGED

Change-Id: I21df10c4a6a6a159322b3db9db419bf44052fc84
diff --git a/av1/encoder/palette.c b/av1/encoder/palette.c
index 14c8970..cab15e8 100644
--- a/av1/encoder/palette.c
+++ b/av1/encoder/palette.c
@@ -756,9 +756,6 @@
   if (best_mbmi->palette_mode_info.palette_size[0] > 0) {
     memcpy(color_map, best_palette_color_map,
            block_width * block_height * sizeof(best_palette_color_map[0]));
-    // Gather the stats to determine whether to use screen content tools in
-    // function av1_determine_sc_tools_with_encoding().
-    x->palette_pixels += (block_width * block_height);
   }
   *mbmi = *best_mbmi;
 }
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index c3b667d..19d42b9 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -431,6 +431,11 @@
 
     xd->cfl.store_y = 0;
     if (av1_allow_palette(cm->features.allow_screen_content_tools, bsize)) {
+      // Gather the stats to determine whether to use screen content tools in
+      // function av1_determine_sc_tools_with_encoding().
+      if (mbmi->palette_mode_info.palette_size[0] > 0 &&
+          dry_run == OUTPUT_ENABLED)
+        x->palette_pixels += (block_size_wide[bsize] * block_size_high[bsize]);
       for (int plane = 0; plane < AOMMIN(2, num_planes); ++plane) {
         if (mbmi->palette_mode_info.palette_size[plane] > 0) {
           if (!dry_run) {