Allintra: Reduce border_in_pixels for frame buffers

For allintra encoding mode, inter-frame motion search is not
applicable and the intraBC motion vectors are restricted within the
tile boundaries. Hence, the border value used in the allocation of
frame buffer is reduced from 160 pixels to 64 pixels in case of
allintra encoding mode.

For AVIF image encode with speed = 9,

             HEAP Memory reduction(%)
Resolution   threads=1    threads=4
640x360        9.00         5.64
768x512        6.92         4.80
832x480        7.20         5.16
1280x720       5.03         4.10

For threads=4, an average encode time reduction of ~3.47% is
observed for 360p-720p resolutions.

HEAP memory reduction was measured using the following command.
$valgrind --tool=massif ./avifenc ...

Change-Id: Ibf690032b4c86a07f7751889de36b21e94544f1c
diff --git a/aom_scale/yv12config.h b/aom_scale/yv12config.h
index 376cb74..c0e0361 100644
--- a/aom_scale/yv12config.h
+++ b/aom_scale/yv12config.h
@@ -29,6 +29,7 @@
 #define AOM_INTERP_EXTEND 4
 #define AOM_BORDER_IN_PIXELS 288
 #define AOM_ENC_NO_SCALE_BORDER 160
+#define AOM_ENC_ALLINTRA_BORDER 64
 #define AOM_DEC_BORDER_IN_PIXELS 64
 
 /*!\endcond */
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index a78c7f9..f4d7823 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1371,10 +1371,14 @@
   oxcf->unit_test_cfg.sb_multipass_unit_test =
       extra_cfg->sb_multipass_unit_test;
 
+  // For allintra encoding mode, inter-frame motion search is not applicable and
+  // the intraBC motion vectors are restricted within the tile boundaries. Hence
+  // a smaller frame border size (AOM_ENC_ALLINTRA_BORDER) is used in this case.
   oxcf->border_in_pixels =
       (resize_cfg->resize_mode || superres_cfg->superres_mode)
           ? AOM_BORDER_IN_PIXELS
-          : AOM_ENC_NO_SCALE_BORDER;
+          : (oxcf->kf_cfg.key_freq_max == 0) ? AOM_ENC_ALLINTRA_BORDER
+                                             : AOM_ENC_NO_SCALE_BORDER;
   memcpy(oxcf->target_seq_level_idx, extra_cfg->target_seq_level_idx,
          sizeof(oxcf->target_seq_level_idx));
   oxcf->tier_mask = extra_cfg->tier_mask;